Skip to content

Commit 3669b90

Browse files
authored
Merge pull request #70810 from kubamracek/embedded-specialize-attr
[embedded] Ignore 'do not specialize' @_semantics attributes in embedded Swift mode
2 parents a1b31b1 + 62e8dc7 commit 3669b90

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

lib/SILOptimizer/Utils/Generics.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,11 @@ static bool createsInfiniteSpecializationLoop(ApplySite Apply) {
500500

501501
static bool shouldNotSpecialize(SILFunction *Callee, SILFunction *Caller,
502502
SubstitutionMap Subs = {}) {
503+
// Ignore "do not specialize" markers in embedded Swift -- specialization is
504+
// mandatory.
505+
if (Callee->getModule().getOptions().EmbeddedSwift)
506+
return false;
507+
503508
if (Callee->hasSemanticsAttr(semantics::OPTIMIZE_SIL_SPECIALIZE_GENERIC_NEVER))
504509
return true;
505510

test/embedded/specialize-attrs.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// 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
2+
// 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
3+
// 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
4+
5+
// REQUIRES: swift_in_compiler
6+
// REQUIRES: executable_test
7+
// REQUIRES: optimized_stdlib
8+
// REQUIRES: OS=macosx
9+
10+
@_semantics("optimize.sil.specialize.generic.never")
11+
func foo<T>(_ t: T) -> Int {
12+
return 42
13+
}
14+
15+
@_semantics("optimize.sil.specialize.generic.size.never")
16+
func foo2<T>(_ t: T) -> Int {
17+
return 42
18+
}
19+
20+
@main
21+
struct Main {
22+
static func main() {
23+
foo(42)
24+
foo2(42)
25+
print("OK!")
26+
}
27+
}
28+
29+
// CHECK: OK!

0 commit comments

Comments
 (0)