Skip to content

SILGen: When transforming to AnyHashable materialize the value in a temporary #17928

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

Conversation

aschwaighofer
Copy link
Contributor

emitAnyHashable expects an address value.

rdar://40583597

…emporary

emitAnyHashable expects an address value.

rdar://40583597
@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test and merge

aschwaighofer added a commit to aschwaighofer/swift that referenced this pull request Jul 13, 2018
…in a temporary

emitAnyHashable expects an address value.

Cherry-pick from swiftlang#17928.

Explanation: When transforming values to AnyHashable we sometimes (e.g
tuples of strings) omit converting the value to an address type by
storing it to the stack leading to a compiler crash.
The fix is to store the value to the stack if it is not already
available as an in memory value.

Scope: Affects only conversions to AnyHashable. The code seems to stem
from 2016.

Risk: Low. Code is added that checks that the value expected by
emitAnyHashable is already in memory if it is not we store it to memory.

Testing: A Swift CI test was added.

rdar://40583597
@swift-ci swift-ci merged commit 0155720 into swiftlang:master Jul 13, 2018
@slavapestov
Copy link
Contributor

@rudkx While the fix is correct, I'm surprised the test case in question emits a function conversion. Any ideas why we wrap the closure literal in a function conversion here, instead of coercing the argument types?

// CHECK: apply [[CVT]]<String>(%0, [[ADDR]])
func dontCrash() {
let userInfo = ["hello": "world"]
let d = [AnyHashable: Any](uniqueKeysWithValues: userInfo.map { ($0.key, $0.value) })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aschwaighofer I would prefer an explicit function conversion test case, like the rest of the file. It's kind of odd that the type checker picks a function conversion here, instead of converting $0.key and $0.value, and if we fix that the test will no longer be testing the problematic code path.

@rudkx
Copy link
Contributor

rudkx commented Jul 18, 2018

@slavapestov The argument is a (String, String) but the result is an (AnyHashable, Any). I don't know exactly how we end up managing to produce that result, but it is an interesting result since we don't generally support tuple conversions like that at this time.

@slavapestov
Copy link
Contributor

@rudkx it sounds like we're converting a function instead of the argument inside the function. However as you mentioned the tuple conversion won't work either...

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