Skip to content
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

[AST] Avoid tripping assertion in IsNonUserModuleRequest #77636

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bnbarham
Copy link
Contributor

Not entirely sure when this can happen, but we have been seeing reports of crashes in IsNonUserModuleRequest due to the runtime assertion in getFiles. Use the equivalent const method that doesn't assert - it's not an issue if we just return false here.

Resolves rdar://137769081.

Not entirely sure when this can happen, but we have been seeing reports
of crashes in `IsNonUserModuleRequest` due to the runtime assertion in
`getFiles`. Use the equivalent const method that doesn't assert - it's
not an issue if we just return `false` here.

Resolves rdar://137769081.
@bnbarham
Copy link
Contributor Author

@swift-ci please test

@hamishknight
Copy link
Contributor

hamishknight commented Nov 15, 2024

Could the issue here actually be that the ModuleDecl is null? Looks like SwiftInterfaceGenContext::createForSwiftSource can create interfaces with IsModule set to true and no ModuleDecl

Edit: Hmm nevermind, I see that ASSERT_failure is actually being called. I do wonder if createForSwiftSource ought to be fixed though

Comment on lines +4020 to +4021
ArrayRef<const FileUnit *> modFiles = mod->getFiles();
if (modFiles.empty())
Copy link
Contributor

Choose a reason for hiding this comment

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

Worth adding a comment given the subtlety of the fix? This all stems from the fact that I missed that there was another overload of getFiles when I originally added the assert 😅

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 remember what you added it for? Honestly I kind of hate this and am tempted to just remove the assert instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC it was added to help enforce that getFiles isn't called before the files are added to the module, the ultimate goal is to replace addFile with a setFiles method that can only be called once (or giving ModuleDecl a lambda constructor with which to populate the files)

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's try this #77666

@bnbarham
Copy link
Contributor Author

Hmm nevermind, I see that ASSERT_failure is actually being called

Yeah, we're definitely asserting here. The particular crashes I see are when retrieving cursor info, so it's likely this is due to invalid code. My preference would be fixing everywhere to never have a module with no files, but it's unclear to me where that's happening 😅

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.

2 participants