Skip to content

IRGen: Use an invariant load to load metadata base offset #20956

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
Dec 3, 2018

Conversation

slavapestov
Copy link
Contributor

No description provided.

@slavapestov
Copy link
Contributor Author

@rjmccall Is this correct?

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov slavapestov merged commit 0d9d4a0 into swiftlang:master Dec 3, 2018
@rjmccall
Copy link
Contributor

rjmccall commented Dec 3, 2018

It's not safe, no. The load is invariant as long as it isn't hoisted before something that's guaranteed to trigger class metadata initialization, like fetching the class metadata, but it's conceivable for this load to appear in a function that triggers the class metadata to be initialized during its execution.

For example, there could be a loop like this:

var total = 0
for i in 0..<100 {
  total += MyClass().number
}

invariant.load allows the number to be hoisted outside of the loop, but it's possible for the first iteration of the loop to be what triggers the computation of MyClass's metadata bounds.

@slavapestov
Copy link
Contributor Author

@rjmccall Ok, I'll revert then.

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