-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Frontend] Clean Up Usage of UnifiedStatsReporter #30109
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
[Frontend] Clean Up Usage of UnifiedStatsReporter #30109
Conversation
@swift-ci please test |
And because Windows is pretty good at surfacing use-after-moves: @swift-ci please test Windows platform |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, very nice! The change I would really like is the use of a NullablePtr
instead of a plain pointer to a stats structure that may or may not be null.
The lifetime of the UnifiedStatsReporter was not entirely clear from context. Stick it in the CompilerInstance instead so it can live as long as the compile job. It is critical that its lifetime be extended beyond that of the ASTContext, as the context may be torn down by the time code generation happens, but additional statistics are recorded during LLVM codegen.
The only non-trivial bit is making the DiagnosticEngine parameter to swift::performLLVM required. No callers were taking advantage of this parameter allowing NULL.
Now that the CompilerInstance owns the stats reporter, use that instead.
Centralize part of the routine that selects which resources to free. Then, add an additional condition for -dump-api-path. Before, if this option were specified along with -emit-llvm or -c, the compiler would try to rebuild the torn-down ModuleDecl and crash trying to access the torn-down ASTContext.
05fb938
to
a6651a9
Compare
@swift-ci smoke test |
@swift-ci test Windows platform |
Build failed |
Build failed |
Glad my thoughts made sense. Thanks for using them. |
@swift-ci please test Windows platform |
@swift-ci smoke test Linux platform |
1 similar comment
@swift-ci smoke test Linux platform |
Windows seems out for maintenance. ⛵️ |
This patch does a bunch of NFC things, and one particularly not NFC thing to fix a gigantic use-after-free in frontend jobs that pass
-dump-api-path
.NFC Stuff:
Not-so-NFC Stuff:
-dump-api-path
and codegen with single primaries.The routine that frees up some memory by releasing the ASTContext and SILModules conditionally could potentially be run which would destroy the resources needed by that frontend action. See the last commit.