-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Frontend: force order of evaluation #19346
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
@swift-ci please test |
lib/Frontend/Frontend.cpp
Outdated
Context->LoadedModules[MainModule->getName()] = getMainModule(); | ||
|
||
ModuleDecl *mainModule = getMainModule(); | ||
Context->LoadedModules[MainModule->getName()] = mainModule; |
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.
Can you read the name from mainModule
and not the instance variable here as well?
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.
Sure, I can do that, it is trivial enough. Shouldn't AA ensure that the extra load is elided? Or is there another purpose to the change?
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.
If getMainModule
is inlined it probably would, but it still seems like a funny thing to rely on.
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.
It’s not a perf thing, it’s a code smell thing. It’s lazily initialized so all direct access to the instance variable can break the laziness contract - order of evaluation issues aside.
The previous statement happened to work out of sheer luck. `MainModule` is initialized by the call to `getMainModule()`. The expression could be evaluated in any order, and in the Visual Studio case, was evaluated with the index *first*. At this point `MainModule` was uninitialized (fortunately, it was set to NULL). As a result, the `getName` call would fail. Ensure that the `MainModule` is initialized first by using a local variable.
c53b01b
to
597b4ae
Compare
@swift-ci please test |
Build failed |
Build failed |
Build failed |
@swift-ci please test macOS platform |
⛵️ |
The previous statement happened to work out of sheer luck.
MainModule
isinitialized by the call to
getMainModule()
. The expression could be evaluatedin any order, and in the Visual Studio case, was evaluated with the index
first. At this point
MainModule
was uninitialized (fortunately, it was setto NULL). As a result, the
getName
call would fail. Ensure that theMainModule
is initialized first by using a local variable.Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.
Resolves SR-NNNN.