Skip to content

[4.0] IRGen: EmptyBoxType's representation cannot be nil because of a conflict with extra inhabitant assumption in indirect enums #10403

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

aschwaighofer
Copy link
Contributor

Use a singleton empty heap box representation instead of nil for EmptyBoxTypes. The nil representation that we used is not compatible with assumption we make about extra inhabitant bits we make in enums.

• Explanation: Due to using an incompatible representation of empty box types and single reference enum payloads we can’t distinguish between the first empty payload case and the payload case because both map to 0.

enum Payload {
case c
}

indirect enum Test {
case a
case b(Payload)
}

Test.b(.c) // creates .a

• Scope of Issue: This has not been working since at least Xcode 8.3.f

• Risk: Low. The code path is the same for the rest of the compiler for handling reference counted payloads. This change therefore should not expose other bugs.

• Testing: Existing and added Swift CI tests

…ict with extra inhabitant assumption in indirect enums (swiftlang#10326)

* IRGen: EmptyBoxType's representation cannot be nil because of a conflict with extra inhabitant assumption in indirect enums

We map nil to the .None case of Optional. Instead use a singleton object.

SR-5148
rdar://32618580
…the stubs library (swiftlang#10373)

* Fix layering violation I introduced by putting _EmptyBoxStorage into the stubs library

Should fix the linkage issue on linux
@aschwaighofer
Copy link
Contributor Author

@jckarter Can you review this for the swift-4.0-branch?

@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test

@jckarter
Copy link
Contributor

This seems fine for 4.0. For master, is there any reason not to export the empty box object symbol and open-code references instead of going through a runtime entry point? swift_getEmptyBox might be a better name since it's not allocating anything. Should swift_allocBox return the empty box when given an empty type?

@tkremenek tkremenek merged commit 5289bf3 into swiftlang:swift-4.0-branch Jun 21, 2017
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.

3 participants