Skip to content

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

Merged
merged 1 commit into from
Sep 19, 2018
Merged

Conversation

compnerd
Copy link
Member

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.

Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.

Resolves SR-NNNN.

@compnerd
Copy link
Member Author

CC: @jrose-apple @davidungar

@compnerd
Copy link
Member Author

@swift-ci please test

Context->LoadedModules[MainModule->getName()] = getMainModule();

ModuleDecl *mainModule = getMainModule();
Context->LoadedModules[MainModule->getName()] = mainModule;
Copy link
Contributor

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?

Copy link
Member Author

@compnerd compnerd Sep 17, 2018

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?

Copy link
Contributor

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.

Copy link
Contributor

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.
@compnerd
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - c53b01baf9a1bc0566686b131bdb956b096e984e

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - c53b01baf9a1bc0566686b131bdb956b096e984e

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - c53b01baf9a1bc0566686b131bdb956b096e984e

@compnerd
Copy link
Member Author

@swift-ci please test macOS platform

@CodaFi
Copy link
Contributor

CodaFi commented Sep 19, 2018

⛵️

@CodaFi CodaFi merged commit 4624858 into swiftlang:master Sep 19, 2018
@compnerd compnerd deleted the frontend-order branch October 4, 2018 22:37
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.

4 participants