diff --git a/lib/SILOptimizer/Utils/Generics.cpp b/lib/SILOptimizer/Utils/Generics.cpp index 4569a393de5b5..18746799ba3f0 100644 --- a/lib/SILOptimizer/Utils/Generics.cpp +++ b/lib/SILOptimizer/Utils/Generics.cpp @@ -500,6 +500,11 @@ static bool createsInfiniteSpecializationLoop(ApplySite Apply) { static bool shouldNotSpecialize(SILFunction *Callee, SILFunction *Caller, SubstitutionMap Subs = {}) { + // Ignore "do not specialize" markers in embedded Swift -- specialization is + // mandatory. + if (Callee->getModule().getOptions().EmbeddedSwift) + return false; + if (Callee->hasSemanticsAttr(semantics::OPTIMIZE_SIL_SPECIALIZE_GENERIC_NEVER)) return true; diff --git a/test/embedded/specialize-attrs.swift b/test/embedded/specialize-attrs.swift new file mode 100644 index 0000000000000..693f16b0e8aae --- /dev/null +++ b/test/embedded/specialize-attrs.swift @@ -0,0 +1,29 @@ +// RUN: %target-run-simple-swift(%S/Inputs/print.swift -parse-as-library -Onone -enable-experimental-feature Embedded -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop -Xlinker -dead_strip) | %FileCheck %s +// RUN: %target-run-simple-swift(%S/Inputs/print.swift -parse-as-library -O -enable-experimental-feature Embedded -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop -Xlinker -dead_strip) | %FileCheck %s +// RUN: %target-run-simple-swift(%S/Inputs/print.swift -parse-as-library -Osize -enable-experimental-feature Embedded -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop -Xlinker -dead_strip) | %FileCheck %s + +// REQUIRES: swift_in_compiler +// REQUIRES: executable_test +// REQUIRES: optimized_stdlib +// REQUIRES: OS=macosx + +@_semantics("optimize.sil.specialize.generic.never") +func foo(_ t: T) -> Int { + return 42 +} + +@_semantics("optimize.sil.specialize.generic.size.never") +func foo2(_ t: T) -> Int { + return 42 +} + +@main +struct Main { + static func main() { + foo(42) + foo2(42) + print("OK!") + } +} + +// CHECK: OK!