Skip to content

Workaround for difference in behavior between optimizer and runtime understanding of casts (2.2) #1990

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 3 commits into from
Apr 1, 2016

Conversation

slavapestov
Copy link
Contributor

@rudkx Is this right?

We have a special rule that Optional<T>.none successfully dynamically casts
to Optional<U>.none for any T and U. However the implementation was incorrect
if the source and destination types had a different size. We would initialize
the source to nil, and then copy to the result.

The correct implementation is to initialize the result using the result
payload type directly, and not call _succeed() at all.

Fixes <https://bugs.swift.org/browse/SR-1056>.
Until we fix the optimizer to produce the same results as runtime
casts, let's inhibit optimizations.
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov
Copy link
Contributor Author

@tkremenek Note that swift-ci Please test doesn't actually run with optimizations, which is why this slipped through in the first place. It would be great if we could fix that.

@tkremenek
Copy link
Member

@swift-ci test

@jckarter
Copy link
Contributor

Yeah, running without optimization bit me too recently.

@slavapestov
Copy link
Contributor Author

@tkremenek Is the 'Please' optional now? :)

@jckarter
Copy link
Contributor

Maybe it has INTERCAL semantics, where it rejects your request if you don't use the right percentage of times.

This is a simple runtime fix for the following case:

func cast<U>(t: Any) -> U {
  return t as! U
}
cast(nil as Int?) as Int?
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov
Copy link
Contributor Author

@tkremenek I'll do one final test run of this and my other 2.2.1 PRs with check-swift-all-optimized -- will update here when its done.

@slavapestov slavapestov added this to the Swift 2.2.x milestone Apr 1, 2016
@rudkx
Copy link
Contributor

rudkx commented Apr 1, 2016

@slavapestov Yes, that's the right _semantic to use to disable specialization of that function (and any optimization within the function).

@slavapestov
Copy link
Contributor Author

@tkremenek Can you merge this one please?

@tkremenek tkremenek merged commit 4a19bc6 into swiftlang:swift-2.2-branch Apr 1, 2016
@slavapestov slavapestov deleted the cast-fix-2.2 branch April 8, 2016 09:51
MaxDesiatov added a commit that referenced this pull request Oct 19, 2020
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.

5 participants