Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/SILOptimizer/Utils/Generics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if we could do this for perf annotations too, but that's probably a separate patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I wonder if there is actually anything to fix for perf annotations: (1) The stdlib only has a handful of functions with the "do not specialize" marker and they seem to mostly be slow paths that do cause allocations (and thus are not going to be usable in @noLocks or @noAllocations code anyway). (2) Non-stdlib code probably shouldn't use the "do not specialize" marker as it's an underscored attribute, and arguably it could be considered to be the user's problem if they use the marker and then try to use such a code in a perf-annotated function...

return false;

if (Callee->hasSemanticsAttr(semantics::OPTIMIZE_SIL_SPECIALIZE_GENERIC_NEVER))
return true;

Expand Down
29 changes: 29 additions & 0 deletions test/embedded/specialize-attrs.swift
Original file line number Diff line number Diff line change
@@ -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: T) -> Int {
return 42
}

@_semantics("optimize.sil.specialize.generic.size.never")
func foo2<T>(_ t: T) -> Int {
return 42
}

@main
struct Main {
static func main() {
foo(42)
foo2(42)
print("OK!")
}
}

// CHECK: OK!