Skip to content

Commit 6229938

Browse files
committed
[ownership] Use [ossa] on functions so ownership is controlled locally instead of the global -assume-parsing-unqualified-ownership-sil
1 parent 4ab61db commit 6229938

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

lib/ParseSIL/ParseSIL.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,7 @@ void SILParser::convertRequirements(SILFunction *F,
942942
static bool parseDeclSILOptional(bool *isTransparent,
943943
IsSerialized_t *isSerialized,
944944
bool *isCanonical,
945+
bool *hasOwnershipSSA,
945946
IsThunk_t *isThunk,
946947
IsDynamicallyReplaceable_t *isDynamic,
947948
SILFunction **dynamicallyReplacedFunction,
@@ -976,6 +977,8 @@ static bool parseDeclSILOptional(bool *isTransparent,
976977
*isSerialized = IsSerializable;
977978
else if (isCanonical && SP.P.Tok.getText() == "canonical")
978979
*isCanonical = true;
980+
else if (hasOwnershipSSA && SP.P.Tok.getText() == "ossa")
981+
*hasOwnershipSSA = true;
979982
else if (isThunk && SP.P.Tok.getText() == "thunk")
980983
*isThunk = IsThunk;
981984
else if (isThunk && SP.P.Tok.getText() == "signature_optimized_thunk")
@@ -5148,9 +5151,7 @@ bool SILParser::parseSILBasicBlock(SILBuilder &B) {
51485151

51495152
// If SILOwnership is enabled and we are not assuming that we are
51505153
// parsing unqualified SIL, look for printed value ownership kinds.
5151-
if (!F->getModule()
5152-
.getOptions()
5153-
.AssumeUnqualifiedOwnershipWhenParsing &&
5154+
if (F->hasOwnership() &&
51545155
parseSILOwnership(OwnershipKind))
51555156
return true;
51565157

@@ -5193,7 +5194,7 @@ bool SILParser::parseSILBasicBlock(SILBuilder &B) {
51935194
// Qualification. For more details, see the comment on the
51945195
// FunctionOwnershipEvaluator class.
51955196
SILInstruction *ParsedInst = &*BB->rbegin();
5196-
if (!AssumeUnqualifiedOwnershipWhenParsing &&
5197+
if (BB->getParent()->hasOwnership() &&
51975198
!OwnershipEvaluator.evaluate(ParsedInst)) {
51985199
P.diagnose(ParsedInst->getLoc().getSourceLoc(),
51995200
diag::found_unqualified_instruction_in_qualified_function,
@@ -5228,6 +5229,7 @@ bool SILParserTUState::parseDeclSIL(Parser &P) {
52285229
IsSerialized_t isSerialized = IsNotSerialized;
52295230
bool isCanonical = false;
52305231
IsDynamicallyReplaceable_t isDynamic = IsNotDynamic;
5232+
bool hasOwnershipSSA = false;
52315233
IsThunk_t isThunk = IsNotThunk;
52325234
bool isGlobalInit = false, isWeakLinked = false;
52335235
bool isWithoutActuallyEscapingThunk = false;
@@ -5240,12 +5242,12 @@ bool SILParserTUState::parseDeclSIL(Parser &P) {
52405242
SILFunction *DynamicallyReplacedFunction = nullptr;
52415243
Identifier objCReplacementFor;
52425244
if (parseSILLinkage(FnLinkage, P) ||
5243-
parseDeclSILOptional(&isTransparent, &isSerialized, &isCanonical,
5244-
&isThunk, &isDynamic, &DynamicallyReplacedFunction,
5245-
&objCReplacementFor, &isGlobalInit, &inlineStrategy,
5246-
&optimizationMode, nullptr, &isWeakLinked,
5247-
&isWithoutActuallyEscapingThunk, &Semantics,
5248-
&SpecAttrs, &ClangDecl, &MRK, FunctionState, M) ||
5245+
parseDeclSILOptional(
5246+
&isTransparent, &isSerialized, &isCanonical, &hasOwnershipSSA,
5247+
&isThunk, &isDynamic, &DynamicallyReplacedFunction,
5248+
&objCReplacementFor, &isGlobalInit, &inlineStrategy, &optimizationMode, nullptr,
5249+
&isWeakLinked, &isWithoutActuallyEscapingThunk, &Semantics,
5250+
&SpecAttrs, &ClangDecl, &MRK, FunctionState, M) ||
52495251
P.parseToken(tok::at_sign, diag::expected_sil_function_name) ||
52505252
P.parseIdentifier(FnName, FnNameLoc, diag::expected_sil_function_name) ||
52515253
P.parseToken(tok::colon, diag::expected_sil_type))
@@ -5269,6 +5271,8 @@ bool SILParserTUState::parseDeclSIL(Parser &P) {
52695271
FunctionState.F->setTransparent(IsTransparent_t(isTransparent));
52705272
FunctionState.F->setSerialized(IsSerialized_t(isSerialized));
52715273
FunctionState.F->setWasDeserializedCanonical(isCanonical);
5274+
if (!hasOwnershipSSA)
5275+
FunctionState.F->setOwnershipEliminated();
52725276
FunctionState.F->setThunk(IsThunk_t(isThunk));
52735277
FunctionState.F->setIsDynamic(isDynamic);
52745278
FunctionState.F->setDynamicallyReplacedFunction(
@@ -5457,9 +5461,8 @@ bool SILParserTUState::parseSILGlobal(Parser &P) {
54575461
SILParser State(P);
54585462
if (parseSILLinkage(GlobalLinkage, P) ||
54595463
parseDeclSILOptional(nullptr, &isSerialized, nullptr, nullptr, nullptr,
5460-
nullptr, nullptr, nullptr, nullptr, nullptr, &isLet,
54615464
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
5462-
State, M) ||
5465+
&isLet, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, State, M) ||
54635466
P.parseToken(tok::at_sign, diag::expected_sil_value_name) ||
54645467
P.parseIdentifier(GlobalName, NameLoc, diag::expected_sil_value_name) ||
54655468
P.parseToken(tok::colon, diag::expected_sil_type))
@@ -5507,8 +5510,7 @@ bool SILParserTUState::parseSILProperty(Parser &P) {
55075510
IsSerialized_t Serialized = IsNotSerialized;
55085511
if (parseDeclSILOptional(nullptr, &Serialized, nullptr, nullptr, nullptr,
55095512
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
5510-
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
5511-
SP, M))
5513+
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, SP, M))
55125514
return true;
55135515

55145516
ValueDecl *VD;
@@ -5576,7 +5578,7 @@ bool SILParserTUState::parseSILVTable(Parser &P) {
55765578
IsSerialized_t Serialized = IsNotSerialized;
55775579
if (parseDeclSILOptional(nullptr, &Serialized, nullptr, nullptr, nullptr,
55785580
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
5579-
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
5581+
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
55805582
VTableState, M))
55815583
return true;
55825584

@@ -6112,7 +6114,7 @@ bool SILParserTUState::parseSILWitnessTable(Parser &P) {
61126114
IsSerialized_t isSerialized = IsNotSerialized;
61136115
if (parseDeclSILOptional(nullptr, &isSerialized, nullptr, nullptr, nullptr,
61146116
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
6115-
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
6117+
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
61166118
WitnessState, M))
61176119
return true;
61186120

lib/SIL/SILPrinter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,6 +2345,11 @@ void SILFunction::print(SILPrintContext &PrintCtx) const {
23452345
if (WasDeserializedCanonical && getModule().getStage() == SILStage::Raw)
23462346
OS << "[canonical] ";
23472347

2348+
// If this function is not an external declaration /and/ is in ownership ssa
2349+
// form, print [ossa].
2350+
if (!isExternalDeclaration() && hasOwnership())
2351+
OS << "[ossa] ";
2352+
23482353
printName(OS);
23492354
OS << " : $";
23502355

0 commit comments

Comments
 (0)