Skip to content

Put freestanding init decls in a test into a type. #94

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
Nov 22, 2019

Conversation

allevato
Copy link
Member

Even though these aren't semantically valid Swift, these parse correctly
with the 9/26 snapshot we're currently on. At a more recent commit we
noticed that these inits seem to be hitting a code path that causes an
assertion in the parser:

assertion failed in swift::Type swift::ValueDecl::getInterfaceType() const:
ctx.getLegacyGlobalTypeChecker() && "The type checker must be installed to
make semantic queries!"

We should try to pinpoint this crash, but for now I'm patching this so
that the test is more "correct" and it unblocks some of our internal work.

Even though these aren't semantically valid Swift, these parse correctly
with the 9/26 snapshot we're currently on. At a more recent commit we
noticed that these `init`s seem to be hitting a code path that causes an
assertion in the parser:

    assertion failed in swift::Type swift::ValueDecl::getInterfaceType() const:
    ctx.getLegacyGlobalTypeChecker() && "The type checker must be installed to
    make semantic queries!"

We should try to pinpoint this crash, but for now I'm patching this so
that the test is more "correct" and it unblocks some of our internal work.
@allevato allevato merged commit 94482c3 into swiftlang:master Nov 22, 2019
@allevato allevato deleted the fix-freestanding-inits branch November 22, 2019 20:53
@akyrtzi
Copy link
Contributor

akyrtzi commented Nov 22, 2019

\cc @nathawes could you take a look?

@nathawes
Copy link

@allevato Are you still seeing this after the changes in swiftlang/swift#28226? That fixed several cases where we were hitting this assertion in SourceKit's syntactic requests so might fix this too.

@allevato
Copy link
Member Author

@nathawes Thanks for the link. I first wanted to grab the 2019-11-11 trunk snapshot (the snapshot that Swift for TensorFlow's branch was last rebased on, before your patch) to verify failure, but I wasn't able to reproduce my issue using either SwiftSyntax or -frontend -emit-syntax from the command line.

Digging a little deeper, I think this might be a result of a subtlety in Google's internal Bazel build for libswiftSyntaxParser; we're not defining SWIFT_BUILD_ONLY_SYNTAXPARSERLIB because we can't change configurations for the same build targets based on who depends on them, so the parser we build ends up with some real code paths in libAST instead of the #if SWIFT_BUILD_ONLY_SYNTAXPARSERLIB-guarded early-returns that are there. I'm wondering if one of those code paths was triggering the assertion.

Since this might be related to our weird setup, I'll have to wait until Swift for TensorFlow rebases on top of your change and see if the old inits still fail, and look into addressing the issue with our build targets so that we define the proper preprocessor symbols to avoid this again (if that is indeed the problem).

@akyrtzi
Copy link
Contributor

akyrtzi commented Nov 22, 2019

Actually the SWIFT_BUILD_ONLY_SYNTAXPARSERLIB is not defined in any of the builds that Swift CI produces, currently we only use that internally.

@allevato
Copy link
Member Author

So much for that theory then! Indeed, I just tried defining that symbol universally in our internal build as a quick test and it didn't make the issue go away, so I'm glad I'm wrong because it means I don't have to rearrange all those build targets.

Anyway, @nathawes' patch was small enough that I could apply it on top of our internal copy of the toolchain and I can verify that that did fix the issue; the tests passed again with the surrounding type removed from the initializers. Thanks!

aaditya-chandrasekhar pushed a commit to val-verde/swift-format that referenced this pull request May 20, 2021
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.

3 participants