Skip to content

Sr 11159 space engine #26754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2019
Merged

Conversation

AndrewLitteken
Copy link
Contributor

@AndrewLitteken AndrewLitteken commented Aug 20, 2019

Split off of #26741 to separate Enum changes and Space Engine changes, related to #26741

Changes Identifiers to DeclNames so that in checking elements the associated values are taken into account. Other exhaustiveness and redundancy to compare these associated values are taken to make sure the correct message is shown.

Resolves SR-11159.

@CodaFi
Copy link
Contributor

CodaFi commented Aug 20, 2019

Please let's just restrict this to the SpaceEngine changes. The engine should pick up DeclNames by projection, so the rest of this patch isn't needed.

@@ -604,8 +612,9 @@ namespace {
// a disjunction of its sub-spaces because nothing got reduced.
// This is especially helpful when dealing with `unknown` case
// in parameter positions.
if (s1 == reducedSpace)
if (s1 == reducedSpace){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the bracing, but please standardize on the spacing in the rest of this file. If in doubt, run clang-format.

@@ -696,9 +705,9 @@ namespace {
buffer << (getBoolValue() ? "true" : "false");
break;
case SpaceKind::Constructor: {
if (!Head.empty()) {
if (!Head.getBaseIdentifier().empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're going to need to print the labels into the pattern as well.

@@ -1435,6 +1443,11 @@ namespace {
if (!SP) {
// If there's no sub-pattern then there's no further recursive
// structure here. Yield the constructor space.
if(VP->hasUnresolvedOriginalExpr()){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The space engine does not need to concern itself with ill-formed pattern trees. They will have been structurally diagnosed by the rest of pattern type checking, and we should not project them.

@@ -333,7 +334,7 @@ namespace {
return this->isSubspace(or2Space, TC, DC);
}

return true;
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious if this affects any of our tests. I suspect it may close some SRs if this turns out to be salient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the --test with the build script, the tests still passed in those cases.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, let's leave it in and run the broader test suite to see if this catches anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that the validation-test?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's part of it, yes.

Copy link
Contributor

@CodaFi CodaFi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes and the general approach look pretty good. Some feedback inline.

@@ -115,7 +115,7 @@ namespace {

// In type space, we reuse HEAD to help us print meaningful name, e.g.,
// tuple element name in fixits.
Identifier Head;
DeclName Head;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't your bug, but "Head" no longer makes sense under these changes. Perhaps Name or Spine (definitely rooting more for the former than the latter).

@CodaFi
Copy link
Contributor

CodaFi commented Aug 21, 2019

Let's also try to clean up the history a little here. In general, you can run

git pull --rebase upstream master

where upstream points to the Swift remote endpoint. This will keep the merge commits out of your history. An interactive rebase can also help to squash away these intermediate commits. If this is too much trouble, I can also manually squash these in after we run CI.

@AndrewLitteken AndrewLitteken force-pushed the SR-11159-SpaceEngine branch 2 times, most recently from 3a63596 to 6380295 Compare August 21, 2019 19:24
other.Head.getBaseIdentifier())
return false;
if (this->Head.getArgumentNames().size() != 0 &&
other.Head.getArgumentNames().size() != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sequence of checks doesn't make sense to me. To preserve the optimization, we should be checking if the baseIdentifiers are different and the argumentNames differ in number.

Copy link
Contributor Author

@AndrewLitteken AndrewLitteken Aug 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may have misinterpreted some fo the tests. I think this was attempting to take care of the case where if the case statement had no arguments/associated values (i.e. .a) compared to one where it does .a(x:) then it should be considered a subspace.

Should 0 be considered special in these cases?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We pre-expand patterns via lookup to make that impossible. Otherwise we wouldn't be able to detect overlapping patterns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, makes sense

}

if (Spaces.empty()) {
if (Head.getArgumentNames().size() > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the right place to do this. If Spaces is empty then you shouldn't have any argument names to print. The interleave call below this needs to be adjusted to print labels.

}

if (Spaces.empty()) {
return;
}

llvm::SmallVector<std::pair<Identifier, Space>, 4> labelSpaces;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a more llvm-style way to do this? This seemed like the best way to attach the label to the space.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also causes a few of the tests to fail since they produce a label that wasn't there before.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those tests should be updated then.

if (this->Head.getArgumentNames().size() !=
other.Head.getArgumentNames().size()) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, why isn't this still just returning false? When would we have different labels but want to treat the constructors as the same?

Copy link
Contributor Author

@AndrewLitteken AndrewLitteken Aug 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be from when the two pull requests were together, but in the future I think there is a situation where the constructor could just have variable patterns in place of the labels, and in that case they could possibly be a sub space even if the constructors do not match exactly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, but I'm worried that this was a load-bearing optimization. The rest of the code just checks the subspaces, which means it would treat even .x(a: Int) and .x(b: Int) as equivalent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, so should these be removed and other checks be put earlier? Or just removed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just going back to checking the whole DeclName is probably okay for now. Unless that uncovers problems with existing tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be fixed and passes the basic/validation tests from the build script

@AndrewLitteken AndrewLitteken force-pushed the SR-11159-SpaceEngine branch 2 times, most recently from 9a0c25a to 455af70 Compare August 29, 2019 22:00
labelSpaces.push_back(std::pair<Identifier, Space>(*args, param));
args++;
} else
labelSpaces.push_back(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you assert that you always have the same number of argument names in the base identifier as there are subspaces? If that much is true, then you can swap the interleave for the variant of std::transform that takes two input iterators and keep track of placing the commas yourself. Honestly, if it's all the same we can just take this code and you can leave a FIXME behind to come clean this up. I'm not too concerned about printing being efficient since this will only come up when you're diagnosing invalid code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean a full assertion that stops compilation? Or just a check that runs a different path if that is the case?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, just an assert.

Copy link
Contributor Author

@AndrewLitteken AndrewLitteken Sep 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure just having an assertion allows all cases.

For instance, if we check the number of argument names against spaces in the following example:

enum Threepeat {
  case a, b, c
}

func test3(x: Threepeat, y: Threepeat) {
  switch (x, y) { // expected-error {{switch must be exhaustive}}
  // expected-note@-1 {{add missing case: '(.a, .c)'}}
  case (.a, .a):
    ()
  case (.b, _):
    ()
  case (.c, _):
    ()
  case (_, .b):
    ()
  }
}

with the assertion, it fails where it should not.

@AndrewLitteken
Copy link
Contributor Author

AndrewLitteken commented Oct 3, 2019

I added a FIXME to the initial implementation of showing the constructors, I'm not sure that an assertion can cover all the cases needed.

@CodaFi
Copy link
Contributor

CodaFi commented Oct 3, 2019

Looks good.

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Oct 3, 2019

Build failed
Swift Test OS X Platform
Git Sha - 84a7c1379cd57bd470038ee78ef24041f334f451

@swift-ci
Copy link
Contributor

swift-ci commented Oct 3, 2019

Build failed
Swift Test Linux Platform
Git Sha - 84a7c1379cd57bd470038ee78ef24041f334f451

adding full spaceengine changes

using clang-format

adding argument name size comparison

adding space engine changes

adding full spaceengine changes

using clang-format

adding argument printing to interleave function

updating tests for new print formatting

removing extra checks from constructor subspace checking

adding alternate path if the argument and space lenght are the same

clang format

adding FIXME for code performance

adding fixme for showing constructor

switching direction of beginningparenthesis
@AndrewLitteken
Copy link
Contributor Author

Apologies for that bug, the parenthesis should now be in the right direction, which I believe was the cause of the failures

@theblixguy
Copy link
Collaborator

@swift-ci please test

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@AndrewLitteken AndrewLitteken requested a review from CodaFi October 4, 2019 05:18
@CodaFi
Copy link
Contributor

CodaFi commented Oct 4, 2019

Thanks

⛵️

@CodaFi CodaFi merged commit cb3f9e6 into swiftlang:master Oct 4, 2019
@AndrewLitteken AndrewLitteken deleted the SR-11159-SpaceEngine branch January 26, 2020 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants