Skip to content

Commit e3ac98c

Browse files
committed
FunctionSignatureTransforms: add a semantics attribute to prevent the owned-to-guarantee transformation.
If a function is annotated with @_semantics("optimize.sil.specialize.owned2guarantee.never") its arguments will not be converted from owned to guaranteed.
1 parent 9722578 commit e3ac98c

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

include/swift/AST/SemanticAttrs.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ SEMANTICS_ATTR(OPTIMIZE_SIL_SPECIALIZE_GENERIC_PARTIAL_NEVER,
6767
"optimize.sil.specialize.generic.partial.never")
6868
SEMANTICS_ATTR(OPTIMIZE_SIL_SPECIALIZE_GENERIC_SIZE_NEVER,
6969
"optimize.sil.specialize.generic.size.never")
70+
SEMANTICS_ATTR(OPTIMIZE_SIL_SPECIALIZE_OWNED2GUARANTEE_NEVER,
71+
"optimize.sil.specialize.owned2guarantee.never")
7072

7173
SEMANTICS_ATTR(OSLOG_MESSAGE_INIT_INTERPOLATION, "oslog.message.init_interpolation")
7274
SEMANTICS_ATTR(OSLOG_MESSAGE_INIT_STRING_LITERAL, "oslog.message.init_stringliteral")

lib/SILOptimizer/FunctionSignatureTransforms/OwnedToGuaranteedTransform.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define DEBUG_TYPE "fso-owned-to-guaranteed-transform"
1414
#include "FunctionSignatureOpts.h"
1515
#include "swift/SIL/DebugUtils.h"
16+
#include "swift/AST/SemanticAttrs.h"
1617
#include "llvm/Support/CommandLine.h"
1718

1819
using namespace swift;
@@ -258,6 +259,9 @@ void FunctionSignatureTransform::OwnedToGuaranteedAddResultRelease(
258259
bool FunctionSignatureTransform::OwnedToGuaranteedAnalyze() {
259260
if (FSODisableOwnedToGuaranteed)
260261
return false;
262+
SILFunction *F = TransformDescriptor.OriginalFunction;
263+
if (F->hasSemanticsAttr(semantics::OPTIMIZE_SIL_SPECIALIZE_OWNED2GUARANTEE_NEVER))
264+
return false;
261265

262266
const bool Result = OwnedToGuaranteedAnalyzeResults();
263267
const bool Params = OwnedToGuaranteedAnalyzeParameters();

0 commit comments

Comments
 (0)