Skip to content

How to disable SWIFT_ENABLE_OPAQUE_TYPE_ERASURE explicitly for Debug build #211

@Kyle-Ye

Description

@Kyle-Ye

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: AnyAnimal

Reproducible repo

https://github.com/Kyle-Ye/SwiftOpaqueTypeErasureDemo

Other info

{
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 = ();
};
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions