Skip to content

Commit 341b5c5

Browse files
committed
[sil-inliner] Respect the @inline(__always) and @_transparent even if inlining of generics is disabled
If some functions are explicitly annotated by developers as @inline(__always) or @_transparent, they should always be a subject for the inlining of generics, even if this kind of inlining is not enabled currently for all functions.
1 parent d6b4c3e commit 341b5c5

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

lib/SILOptimizer/Transforms/PerformanceInliner.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -365,15 +365,6 @@ static Optional<bool> shouldInlineGeneric(FullApplySite AI) {
365365
assert(!AI.getSubstitutions().empty() &&
366366
"Expected a generic apply");
367367

368-
if (!EnableSILInliningOfGenerics)
369-
return false;
370-
371-
// If all substitutions are concrete, then there is no need to perform the
372-
// generic inlining. Let the generic specializer create a specialized
373-
// function and then decide if it is beneficial to inline it.
374-
if (!hasArchetypes(AI.getSubstitutions()))
375-
return false;
376-
377368
SILFunction *Callee = AI.getReferencedFunction();
378369

379370
// Do not inline @_semantics functions when compiling the stdlib,
@@ -393,6 +384,17 @@ static Optional<bool> shouldInlineGeneric(FullApplySite AI) {
393384
if (Callee->getInlineStrategy() == AlwaysInline || Callee->isTransparent())
394385
return true;
395386

387+
// All other generic functions should not be inlined if this kind of inlining
388+
// is disabled.
389+
if (!EnableSILInliningOfGenerics)
390+
return false;
391+
392+
// If all substitutions are concrete, then there is no need to perform the
393+
// generic inlining. Let the generic specializer create a specialized
394+
// function and then decide if it is beneficial to inline it.
395+
if (!hasArchetypes(AI.getSubstitutions()))
396+
return false;
397+
396398
// It is not clear yet if this function should be decided or not.
397399
return None;
398400
}

lib/SILOptimizer/Utils/PerformanceInlinerUtils.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,10 @@ SILFunction *swift::getEligibleFunction(FullApplySite AI,
678678
}
679679

680680
if (!EnableSILInliningOfGenerics && AI.hasSubstitutions()) {
681-
// Inlining of generics is not allowed.
682-
return nullptr;
681+
// Inlining of generics is not allowed unless it is an @inline(__always)
682+
// or transparent function.
683+
if (Callee->getInlineStrategy() != AlwaysInline && !Callee->isTransparent())
684+
return nullptr;
683685
}
684686

685687
// IRGen cannot handle partial_applies containing opened_existentials

0 commit comments

Comments
 (0)