-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Speculative PrintAsObjC crasher fix #38902
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
Speculative PrintAsObjC crasher fix #38902
Conversation
Before printing the top-level decls in the generated header, PrintAsObjC sorts them to ensure they will be printed in a stable order. This sort starts by evaluating several criteria which ought to distinguish any ValueDecls, then includes extra criteria to sort ExtensionDecls on the same type. Apple has received a number of automated crash reports on this extension-only part of the sort comparison. Unfortunately, nobody has filed a bug report about this crash and we have not been able to devise a reproducer, but the crash reports are consistent with the comparison misinterpreting other declaration kinds as ExtensionDecls. In theory, the code above this point ought to always return when it isn't processing two ExtensionDecls, but in practice it seems like it doesn't. Without a reproducer for this bug, we cannot fully fix it, but we can at least make the code more defensive by adding an explicit check that it is only handling `ExtensionDecl`s. This will cause declarations to be printed in the header in a nondeterministic order, so we will emit a warning soliciting a bug report to gather more information about this problem. Hopefully fixes rdar://81811616, at least to the point of no longer crashing. No new tests because we don't know how to cause this crash.
@swift-ci please test |
Build failed |
@swift-ci smoke test |
From the crashlogs these may be triggered by allowing modules with errors. @bnbarham do you think these could be an expected invalid state during such builds? |
Allowing modules with errors does still output the ObjectiveC header. I have a reproducer based on Becca's comments:
I can look into fixing this one if you'd like @beccadax - it sounds like it may be better to completely drop the duplicate declaration? |
Oh, of course allowing compiler errors could reproduce this. 🤦♀️ Do we mark one of the decls invalid? If so, it should be easy to modify In any case, @bnbarham, I'm happy to let you take the bug if you can fix it properly. |
I was thinking of dropping much earlier, but setting it to invalid is probably a better idea. Thanks so much for investigating this enough to come to the conclusion that duplicate decls could cause it! I'll have a look at fixing this one today/tomorrow. |
Closing in favor of #38923. |
Before printing the top-level decls in the generated header, PrintAsObjC sorts them to ensure they will be printed in a stable order. This sort starts by evaluating several criteria which ought to distinguish any ValueDecls, then includes extra criteria to sort ExtensionDecls on the same type.
Apple has received a number of automated crash reports on this extension-only part of the sort comparison. Unfortunately, nobody has filed a bug report about this crash and we have not been able to devise a reproducer, but the crash reports are consistent with the comparison misinterpreting other declaration kinds as ExtensionDecls. In theory, the code above this point ought to always return when it isn't processing two ExtensionDecls, but in practice it seems like it doesn't.
Without a reproducer for this bug, we cannot fully fix it, but we can at least make the code more defensive by adding an explicit check that it is only handling
ExtensionDecl
s. This will cause declarations to be printed in the header in a nondeterministic order, so we will emit a warning soliciting a bug report to gather more information about this problem.Hopefully fixes rdar://81811616, at least to the point of no longer crashing. No new tests because we don't know how to cause this crash.