Skip to content

Commit e7eb9db

Browse files
committed
Don't inline non-ossa function into an ossa function in the new mandatory performance opts
Update the new inliner with this check. Inlining non-ossa into ossa can causes unexpected consequences.
1 parent 36d333c commit e7eb9db

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/ModulePasses/MandatoryPerformanceOptimizations.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,17 @@ private func shouldInline(apply: FullApplySite, callee: Function, alreadyInlined
123123
if callee.isTransparent {
124124
return true
125125
}
126+
127+
if apply.parentFunction.hasOwnership && !callee.hasOwnership {
128+
// Cannot inline a non-ossa function into an ossa function
129+
return false
130+
}
131+
126132
if apply is BeginApplyInst {
127133
// Avoid co-routines because they might allocate (their context).
128134
return true
129135
}
136+
130137
if apply.parentFunction.isGlobalInitOnceFunction && callee.inlineStrategy == .always {
131138
// Some arithmetic operations, like integer conversions, are not transparent but `inline(__always)`.
132139
// Force inlining them in global initializers so that it's possible to statically initialize the global.

lib/SILOptimizer/Utils/SILInliner.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ SILInliner::inlineFunction(SILFunction *calleeFunction, FullApplySite apply,
360360
PrettyStackTraceSILFunction callerTraceRAII("...into", apply.getFunction());
361361
assert(canInlineApplySite(apply)
362362
&& "Asked to inline function that is unable to be inlined?!");
363-
363+
assert(!apply.getFunction()->hasOwnership() ||
364+
calleeFunction->hasOwnership());
364365
SILInlineCloner cloner(calleeFunction, apply, FuncBuilder, IKind, ApplySubs,
365366
deleter);
366367
cloner.cloneInline(appliedArgs);

0 commit comments

Comments
 (0)