Skip to content

SILOptimizer: Fix bug in closure specialization with resilient build #7417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
7 changes: 7 additions & 0 deletions lib/SILOptimizer/IPO/ClosureSpecializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,13 @@ void ClosureSpecializer::gatherCallSites(
if (!ApplyCallee || ApplyCallee->isExternalDeclaration())
continue;

// Don't specialize non-fragile callees if the caller is fragile;
// the specialized callee will have shared linkage, and thus cannot
// be referenced from the fragile caller.
if (Caller->isFragile() &&
!ApplyCallee->hasValidLinkageForFragileInline())
continue;

// Ok, we know that we can perform the optimization but not whether or
// not the optimization is profitable. Find the index of the argument
// corresponding to our partial apply.
Expand Down
19 changes: 19 additions & 0 deletions test/SILOptimizer/closure_specialize_fragile.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: %target-swift-frontend -Xllvm -new-mangling-for-tests %s -emit-sil -O -o - -verify | %FileCheck %s

// Make sure we do not specialize resilientCallee.

// CHECK-LABEL: sil [fragile] [always_inline] @_T026closure_specialize_fragile0C6CalleryyF : $@convention(thin) () -> ()
// CHECK: function_ref @_T026closure_specialize_fragile15resilientCalleeyyyc2fn_tF : $@convention(thin) (@owned @callee_owned () -> ()) -> ()
// CHECK: return

@inline(__always) public func fragileCaller() {
resilientCallee {
print("Hi")
}
}

// CHECK-LABEL: sil @_T026closure_specialize_fragile15resilientCalleeyyyc2fn_tF : $@convention(thin) (@owned @callee_owned () -> ()) -> ()

public func resilientCallee(fn: () -> ()) {
fn()
}