Skip to content

Simplify Condition Resolution #6547

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

Conversation

CodaFi
Copy link
Contributor

@CodaFi CodaFi commented Jan 4, 2017

This reverts the major content of #5778, the Condition Resolution pass, and replaces it with a far simpler implementation of condition resolution along with canImport. When combined with the optimizations in #6279 we get the best of both worlds with a performance win and a simpler implementation.

This is one of two ways towards a stable implementation of this feature. The concern here is that even with optimizations Parse will have to hit the disk at least once per canImport statement which could potentially slow down a very hot path. On the other hand, that cost cannot simply be deferred to Sema without significantly complicating DeclRef resolution, semantic analysis, and condition resolution.

⚠️ Do Not Merge ⚠️

@benlangmuir, @jrose-apple thoughts?

Resolves SR-3438, SR-3544, and SR-3546

@CodaFi CodaFi force-pushed the i-have-a-little-shadow-that-goes-in-and-out-with-me branch from b71ea2b to 588a5d5 Compare January 5, 2017 20:03
@CodaFi
Copy link
Contributor Author

CodaFi commented Jan 5, 2017

@swift-ci please test.

@swift-ci
Copy link
Contributor

swift-ci commented Jan 5, 2017

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 588a5d5c2a787a6a3854495392bab3457e017262
Test requested by - @CodaFi

@swift-ci
Copy link
Contributor

swift-ci commented Jan 5, 2017

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 588a5d5c2a787a6a3854495392bab3457e017262
Test requested by - @CodaFi

@CodaFi
Copy link
Contributor Author

CodaFi commented Jan 6, 2017

@swift-ci please smoke test.

@CodaFi CodaFi force-pushed the i-have-a-little-shadow-that-goes-in-and-out-with-me branch 2 times, most recently from 06322f5 to 3490a88 Compare January 6, 2017 02:02
@CodaFi
Copy link
Contributor Author

CodaFi commented Jan 6, 2017

@swift-ci please test.

@CodaFi
Copy link
Contributor Author

CodaFi commented Jan 6, 2017

There. @jrose-apple given the recent spate of issues, this is the version of this patch I'm most comfortable with.

@@ -5,6 +5,6 @@
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// RUN: not --crash %target-swift-frontend %s -emit-ir
// RUN: not %target-swift-frontend %s -emit-ir
// REQUIRES: asserts
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for the REQUIRES: asserts.

@jrose-apple
Copy link
Contributor

I guess this is the best we can do. Would still like @benlangmuir's opinion as well—it's annoying that we've added a language feature that means we can't parse without search paths set up. Maybe we can recover this later by taking @DougGregor's idea—the contents of active conditional blocks not having to be splatted into their parent. But the first priority is to restore source compat.

@benlangmuir
Copy link
Contributor

I still strongly disagree with making parsing depend on (a) search paths, and (b) what is on disk in those search paths. Not only is this a performance issue for syntax-only parsing, but also leaves us unable to reliably reproduce syntax-only SourceKit bugs without knowing the state of the filesystem or command-line argument, both of which are harder to find out and are less likely to be provided in bug reports than the source code. We are stuck with that for semantic issues, but we shouldn't have to be for parsing.

@jrose-apple
Copy link
Contributor

Then we're stuck with parse-only producing a slightly different AST for now. Or we turn the feature back off for 3.1 and give ourselves a little more time to plan.

@CodaFi
Copy link
Contributor Author

CodaFi commented Jan 6, 2017

Trouble is we're also stuck with it for Parse issues. Parse depends on being able to have total knowledge of DeclRefs, classes introduced that depend on Foundation, and local type declarations in addition to structure in general. Condition Resolution demonstrated that at least the last two could be shifted to Sema, but without ASTScope or NameLookup taking the first Parse is going to wire up nonsense. Modeling conditions dynamically would make querying compound parts of the AST have to go through condition resolution which is still subject to at least one of the linked SRs (the one about deinitializers being especially concerning).

@jrose-apple
Copy link
Contributor

The deinitializer one isn't so bad; the syntax-only parsing doesn't need to include members synthesized on demand. Sema can take care of that. We also don't actually care about resolving decl refs at all in a syntax-only parse.

But we're out of time. If @benlangmuir isn't happy with this approach, we should…well, we should still take this patch, so that we go back to what we had before, but we should disable the support for canImport until after Branch Day, and then think this through from the start again.

@benlangmuir
Copy link
Contributor

we should…well, we should still take this patch, so that we go back to what we had before, but we should disable the support for canImport until after Branch Day, and then think this through from the start again.

SGTM

@CodaFi
Copy link
Contributor Author

CodaFi commented Jan 6, 2017

OK, I'm going to remove support for the canImport feature, but add a requires annotation to the tests that are here for when we can work this out in the future.

@jrose-apple
Copy link
Contributor

Thanks, Robert. I feel really bad that you've put all this work in (multiple implementations, effectively!) and we can't ship it yet. Ben and I talked a little more about what we think the syntax-only parser wants out of this and I'll send you and swift-dev an email on it later.

@CodaFi
Copy link
Contributor Author

CodaFi commented Jan 6, 2017

Don't worry about it, I'm most concerned about keeping the compiler and language stable around the feature change.

CodaFi added 3 commits January 6, 2017 16:16
This reverts the contents of swiftlang#5778 and replaces it with a far simpler
implementation of condition resolution along with canImport.  When
combined with the optimizations in swiftlang#6279 we get the best of both worlds
with a performance win and a simpler implementation.
@CodaFi CodaFi force-pushed the i-have-a-little-shadow-that-goes-in-and-out-with-me branch from 3490a88 to d2570cb Compare January 6, 2017 23:17
@CodaFi
Copy link
Contributor Author

CodaFi commented Jan 6, 2017

@swift-ci please smoke test.

@CodaFi
Copy link
Contributor Author

CodaFi commented Jan 7, 2017

Due to #6631

@swift-ci please smoke test and merge.

@jrose-apple jrose-apple changed the title [DO NOT MERGE] Simplify Condition Resolution Simplify Condition Resolution Jan 7, 2017
@CodaFi
Copy link
Contributor Author

CodaFi commented Jan 7, 2017

I can't find the test anywhere, so

@swift-ci please smoke test Linux platform.

@CodaFi
Copy link
Contributor Author

CodaFi commented Jan 7, 2017

⛵️

@CodaFi CodaFi merged commit cd8360c into swiftlang:master Jan 7, 2017
@CodaFi CodaFi deleted the i-have-a-little-shadow-that-goes-in-and-out-with-me branch January 7, 2017 03:01
ematejska pushed a commit to ematejska/swift that referenced this pull request Jan 12, 2017
ematejska pushed a commit that referenced this pull request Jan 12, 2017
benrimmington added a commit to swiftlang/swift-evolution that referenced this pull request Sep 3, 2017
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.

4 participants