Skip to content
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

[SR-4365] Suboptimal (or broken) enum Layout #46944

Open
dabrahams opened this issue Mar 26, 2017 · 4 comments
Open

[SR-4365] Suboptimal (or broken) enum Layout #46944

dabrahams opened this issue Mar 26, 2017 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@dabrahams
Copy link
Collaborator

Previous ID SR-4365
Radar rdar://problem/31256554
Original Reporter @dabrahams
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Miscompile
Assignee None
Priority Medium

md5: 49d16dcef1a0531c925bdad4aca5b3cc

Issue Description:

This program (build with -Xfrontend -disable-access-control -parse-stdlib) demonstrates that we are not laying out generic enums or enums with ObjC class instance payloads optimally, or that we are claiming more spare bits than we ought to for Builtin.UnknownObject:

import Swift
import Foundation

enum FiveU {
  typealias T = Builtin.UnknownObject
  case a(T), b(T), c(T), d(T), e(T)
}
enum FiveS {
  typealias T = NSString
  case a(T), b(T), c(T), d(T), e(T)
}

enum Five<T> {
  case a(T), b(T), c(T), d(T), e(T)
}
print(MemoryLayout<Five<Builtin.UnknownObject>>.size) // 9
print(MemoryLayout<Five<NSString>>.size)              // 9
print(MemoryLayout<FiveU>.size)                       // 8
print(MemoryLayout<FiveS>.size)                       // 9

FiveU and Five<Builtin.UnknownObject> should have the same size.
Since I can store NSString in Builtin.UnknownObject, FiveU and FiveS should also have the same size.

@slavapestov
Copy link
Member

This looks like a bug. UnknownObject should have the same spare bits as NSString.

@dabrahams
Copy link
Collaborator Author

Bah, too bad.

@belkadan
Copy link
Contributor

FWIW -disable-access-control probably isn't necessary here, just -parse-stdlib.

@dabrahams
Copy link
Collaborator Author

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

3 participants