-
Notifications
You must be signed in to change notification settings - Fork 128
Description
The SWIFT_ENABLE_OPAQUE_TYPE_ERASURE is causing some issue on our debug build using Xcode. More specificity, it seems be to associated with -Onone optimization level(which means Debug configuration + a non -Onone will also not add -enable-experimental-feature OpaqueTypeErasure).
The default value in swift-build repo shows it is false. And when invoking xcode by swift package --disable-sandbox launch-xcode to build the project, it is indeed not passing -enable-experimental-feature OpaqueTypeErasure.
However for normal Xcode build and we use -Onone as optimization level, the -enable-experimental-feature OpaqueTypeErasure is always passed.
My question is "Is there any way to disable SWIFT_ENABLE_OPAQUE_TYPE_ERASURE explicitly for a xcodeproj?"
Add --disable-experimental-feature xx does not work since swift compile does not recognize it.
@_typeEraser(AnyAnimal)
protocol Animal {
var name: String { get }
}
struct AnyAnimal: Animal {
let name: String
init(name: String) {
self.name = name
}
public init<V>(erasing v: V) where V: Animal {
self.name = v.name
}
}
func makeAnimal() -> some Animal {
Cat()
}
struct Cat: Animal {
var name: String { "cat" }
}
let animal = makeAnimal()
print(type(of: animal))
// "Default": Cat
// -enable-experimental-feature OpaqueTypeErasure: AnyAnimalReproducible repo
https://github.com/Kyle-Ye/SwiftOpaqueTypeErasureDemo
Other info
swift-build/Sources/SWBUniversalPlatform/Specs/Swift.xcspec
Lines 1229 to 1241 in ff0b14a
| { | |
| Name = "SWIFT_ENABLE_OPAQUE_TYPE_ERASURE"; | |
| Type = Boolean; | |
| // rdar://143344956 (Disable opaque type erasure for debug builds) | |
| DefaultValue = NO; | |
| CommandLineArgs = { | |
| YES = ( | |
| "-enable-experimental-feature", | |
| "OpaqueTypeErasure", | |
| ); | |
| NO = (); | |
| }; | |
| }, |