Skip to content

[ownership] Eliminate -assume-parsing-unqualified-ownership-sil now that it is a no-op. #21439

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
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 0 additions & 3 deletions include/swift/AST/SILOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ class SILOptions {
/// If set to true, compile with the SIL Ownership Model enabled.
bool EnableSILOwnership = false;

/// When parsing SIL, assume unqualified ownership.
bool AssumeUnqualifiedOwnershipWhenParsing = false;

/// Assume that code will be executed in a single-threaded environment.
bool AssumeSingleThreaded = false;

Expand Down
3 changes: 0 additions & 3 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,6 @@ def disable_guaranteed_normal_arguments : Flag<["-"], "disable-guaranteed-normal
def enable_mandatory_semantic_arc_opts : Flag<["-"], "enable-mandatory-semantic-arc-opts">,
HelpText<"Enable the mandatory semantic arc optimizer">;

def assume_parsing_unqualified_ownership_sil : Flag<["-"], "assume-parsing-unqualified-ownership-sil">,
HelpText<"Assume unqualified SIL ownership when parsing SIL">;

def suppress_static_exclusivity_swap : Flag<["-"], "suppress-static-exclusivity-swap">,
HelpText<"Suppress static violations of exclusive access with swap()">;

Expand Down
99 changes: 35 additions & 64 deletions include/swift/SIL/SILBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,6 @@ class SILBuilderContext {
/// only by SILGen or SIL deserializers.
SILOpenedArchetypesTracker *OpenedArchetypesTracker = nullptr;

/// True if this SILBuilder is being used for parsing.
///
/// This is important since in such a case, we want to not perform any
/// Ownership Verification in SILBuilder. This functionality is very useful
/// for determining if qualified or unqualified instructions are being created
/// in appropriate places, but prevents us from inferring ownership
/// qualification of functions when parsing. The ability to perform this
/// inference is important since otherwise, we would need to update all SIL
/// test cases while bringing up SIL ownership.
bool isParsing = false;

public:
explicit SILBuilderContext(
SILModule &M, SmallVectorImpl<SILInstruction *> *InsertedInstrs = 0)
Expand Down Expand Up @@ -130,10 +119,6 @@ class SILBuilder {
/// can store the SILGlobalVariable here as well.
SILFunction *F;

/// If the current block that we are inserting into must assume that
/// the current context we are in has ownership.
bool hasOwnership;

/// If this is non-null, the instruction is inserted in the specified
/// basic block, at the specified InsertPt. If null, created instructions
/// are not auto-inserted.
Expand All @@ -143,21 +128,17 @@ class SILBuilder {
Optional<SILLocation> CurDebugLocOverride = None;

public:
explicit SILBuilder(SILFunction &F, bool isParsing = false)
: TempContext(F.getModule()), C(TempContext), F(&F),
hasOwnership(F.hasOwnership()), BB(0) {
C.isParsing = isParsing;
}
explicit SILBuilder(SILFunction &F)
: TempContext(F.getModule()), C(TempContext), F(&F), BB(nullptr) {}

SILBuilder(SILFunction &F, SmallVectorImpl<SILInstruction *> *InsertedInstrs)
: TempContext(F.getModule(), InsertedInstrs), C(TempContext), F(&F),
hasOwnership(F.hasOwnership()), BB(0) {}
BB(nullptr) {}

explicit SILBuilder(SILInstruction *I,
SmallVectorImpl<SILInstruction *> *InsertedInstrs = 0)
: TempContext(I->getFunction()->getModule(), InsertedInstrs),
C(TempContext), F(I->getFunction()),
hasOwnership(F->hasOwnership()) {
C(TempContext), F(I->getFunction()) {
setInsertionPoint(I);
}

Expand All @@ -168,8 +149,7 @@ class SILBuilder {
explicit SILBuilder(SILBasicBlock *BB,
SmallVectorImpl<SILInstruction *> *InsertedInstrs = 0)
: TempContext(BB->getParent()->getModule(), InsertedInstrs),
C(TempContext), F(BB->getParent()),
hasOwnership(F->hasOwnership()) {
C(TempContext), F(BB->getParent()) {
setInsertionPoint(BB);
}

Expand All @@ -179,8 +159,7 @@ class SILBuilder {
SILBuilder(SILBasicBlock *BB, SILBasicBlock::iterator InsertPt,
SmallVectorImpl<SILInstruction *> *InsertedInstrs = 0)
: TempContext(BB->getParent()->getModule(), InsertedInstrs),
C(TempContext), F(BB->getParent()),
hasOwnership(F->hasOwnership()) {
C(TempContext), F(BB->getParent()) {
setInsertionPoint(BB, InsertPt);
}

Expand All @@ -189,8 +168,7 @@ class SILBuilder {
///
/// SILBuilderContext must outlive this SILBuilder instance.
SILBuilder(SILInstruction *I, const SILDebugScope *DS, SILBuilderContext &C)
: TempContext(C.getModule()), C(C), F(I->getFunction()),
hasOwnership(F->hasOwnership()) {
: TempContext(C.getModule()), C(C), F(I->getFunction()) {
assert(DS && "instruction has no debug scope");
setCurrentDebugScope(DS);
setInsertionPoint(I);
Expand All @@ -201,8 +179,7 @@ class SILBuilder {
///
/// SILBuilderContext must outlive this SILBuilder instance.
SILBuilder(SILBasicBlock *BB, const SILDebugScope *DS, SILBuilderContext &C)
: TempContext(C.getModule()), C(C), F(BB->getParent()),
hasOwnership(F->hasOwnership()) {
: TempContext(C.getModule()), C(C), F(BB->getParent()) {
assert(DS && "block has no debug scope");
setCurrentDebugScope(DS);
setInsertionPoint(BB);
Expand Down Expand Up @@ -260,15 +237,13 @@ class SILBuilder {
return SILDebugLocation(overriddenLoc, Scope);
}

/// Allow for users to override has ownership if necessary.
///
/// This is only used in the SILParser since it sets whether or not ownership
/// is qualified after the SILBuilder is constructed due to the usage of
/// AssumeUnqualifiedOwnershipWhenParsing.
///
/// TODO: Once we start printing [ossa] on SILFunctions to indicate ownership
/// and get rid of this global option, this can go away.
void setHasOwnership(bool newHasOwnership) { hasOwnership = newHasOwnership; }
/// If we have a SILFunction, return SILFunction::hasOwnership(). If we have a
/// SILGlobalVariable, just return false.
bool hasOwnership() const {
if (F)
return F->hasOwnership();
return false;
}

//===--------------------------------------------------------------------===//
// Insertion Point Management
Expand Down Expand Up @@ -683,7 +658,7 @@ class SILBuilder {
LoadInst *createTrivialLoadOr(SILLocation Loc, SILValue LV,
LoadOwnershipQualifier Qualifier,
bool SupportUnqualifiedSIL = false) {
if (SupportUnqualifiedSIL && !getFunction().hasOwnership()) {
if (SupportUnqualifiedSIL && !hasOwnership()) {
assert(
Qualifier != LoadOwnershipQualifier::Copy &&
"In unqualified SIL, a copy must be done separately form the load");
Expand All @@ -699,11 +674,9 @@ class SILBuilder {
LoadInst *createLoad(SILLocation Loc, SILValue LV,
LoadOwnershipQualifier Qualifier) {
assert((Qualifier != LoadOwnershipQualifier::Unqualified) ||
!getFunction().hasOwnership() &&
"Unqualified inst in qualified function");
!hasOwnership() && "Unqualified inst in qualified function");
assert((Qualifier == LoadOwnershipQualifier::Unqualified) ||
getFunction().hasOwnership() &&
"Qualified inst in unqualified function");
hasOwnership() && "Qualified inst in unqualified function");
assert(LV->getType().isLoadableOrOpaque(getModule()));
return insert(new (getModule())
LoadInst(getSILDebugLocation(Loc), LV, Qualifier));
Expand Down Expand Up @@ -757,7 +730,7 @@ class SILBuilder {
SILValue DestAddr,
StoreOwnershipQualifier Qualifier,
bool SupportUnqualifiedSIL = false) {
if (SupportUnqualifiedSIL && !getFunction().hasOwnership()) {
if (SupportUnqualifiedSIL && !hasOwnership()) {
assert(
Qualifier != StoreOwnershipQualifier::Assign &&
"In unqualified SIL, assigns must be represented via 2 instructions");
Expand All @@ -773,11 +746,9 @@ class SILBuilder {
StoreInst *createStore(SILLocation Loc, SILValue Src, SILValue DestAddr,
StoreOwnershipQualifier Qualifier) {
assert((Qualifier != StoreOwnershipQualifier::Unqualified) ||
!getFunction().hasOwnership() &&
"Unqualified inst in qualified function");
!hasOwnership() && "Unqualified inst in qualified function");
assert((Qualifier == StoreOwnershipQualifier::Unqualified) ||
getFunction().hasOwnership() &&
"Qualified inst in unqualified function");
hasOwnership() && "Qualified inst in unqualified function");
return insert(new (getModule()) StoreInst(getSILDebugLocation(Loc), Src,
DestAddr, Qualifier));
}
Expand Down Expand Up @@ -1128,22 +1099,22 @@ class SILBuilder {

RetainValueInst *createRetainValue(SILLocation Loc, SILValue operand,
Atomicity atomicity) {
assert(C.isParsing || !getFunction().hasOwnership());
assert(!hasOwnership());
assert(operand->getType().isLoadableOrOpaque(getModule()));
return insert(new (getModule()) RetainValueInst(getSILDebugLocation(Loc),
operand, atomicity));
}

RetainValueAddrInst *createRetainValueAddr(SILLocation Loc, SILValue operand,
Atomicity atomicity) {
assert(C.isParsing || !getFunction().hasOwnership());
assert(!hasOwnership());
return insert(new (getModule()) RetainValueAddrInst(
getSILDebugLocation(Loc), operand, atomicity));
}

ReleaseValueInst *createReleaseValue(SILLocation Loc, SILValue operand,
Atomicity atomicity) {
assert(C.isParsing || !getFunction().hasOwnership());
assert(!hasOwnership());
assert(operand->getType().isLoadableOrOpaque(getModule()));
return insert(new (getModule()) ReleaseValueInst(getSILDebugLocation(Loc),
operand, atomicity));
Expand All @@ -1152,15 +1123,15 @@ class SILBuilder {
ReleaseValueAddrInst *createReleaseValueAddr(SILLocation Loc,
SILValue operand,
Atomicity atomicity) {
assert(C.isParsing || !getFunction().hasOwnership());
assert(!hasOwnership());
return insert(new (getModule()) ReleaseValueAddrInst(
getSILDebugLocation(Loc), operand, atomicity));
}

UnmanagedRetainValueInst *createUnmanagedRetainValue(SILLocation Loc,
SILValue operand,
Atomicity atomicity) {
assert(getFunction().hasOwnership());
assert(hasOwnership());
assert(operand->getType().isLoadableOrOpaque(getModule()));
return insert(new (getModule()) UnmanagedRetainValueInst(
getSILDebugLocation(Loc), operand, atomicity));
Expand All @@ -1169,7 +1140,7 @@ class SILBuilder {
UnmanagedReleaseValueInst *createUnmanagedReleaseValue(SILLocation Loc,
SILValue operand,
Atomicity atomicity) {
assert(getFunction().hasOwnership());
assert(hasOwnership());
assert(operand->getType().isLoadableOrOpaque(getModule()));
return insert(new (getModule()) UnmanagedReleaseValueInst(
getSILDebugLocation(Loc), operand, atomicity));
Expand Down Expand Up @@ -1201,21 +1172,21 @@ class SILBuilder {
unsigned NumBaseElements) {
return insert(ObjectInst::create(getSILDebugLocation(Loc), Ty, Elements,
NumBaseElements, getModule(),
hasOwnership));
hasOwnership()));
}

StructInst *createStruct(SILLocation Loc, SILType Ty,
ArrayRef<SILValue> Elements) {
assert(Ty.isLoadableOrOpaque(getModule()));
return insert(StructInst::create(getSILDebugLocation(Loc), Ty, Elements,
getModule(), hasOwnership));
getModule(), hasOwnership()));
}

TupleInst *createTuple(SILLocation Loc, SILType Ty,
ArrayRef<SILValue> Elements) {
assert(Ty.isLoadableOrOpaque(getModule()));
return insert(TupleInst::create(getSILDebugLocation(Loc), Ty, Elements,
getModule(), hasOwnership));
getModule(), hasOwnership()));
}

TupleInst *createTuple(SILLocation loc, ArrayRef<SILValue> elts);
Expand Down Expand Up @@ -1296,7 +1267,7 @@ class SILBuilder {
assert(Ty.isLoadableOrOpaque(getModule()));
return insert(SelectEnumInst::create(
getSILDebugLocation(Loc), Operand, Ty, DefaultValue, CaseValues,
getModule(), CaseCounts, DefaultCount, hasOwnership));
getModule(), CaseCounts, DefaultCount, hasOwnership()));
}

SelectEnumAddrInst *createSelectEnumAddr(
Expand All @@ -1314,7 +1285,7 @@ class SILBuilder {
ArrayRef<std::pair<SILValue, SILValue>> CaseValuesAndResults) {
return insert(SelectValueInst::create(getSILDebugLocation(Loc), Operand, Ty,
DefaultResult, CaseValuesAndResults,
getModule(), hasOwnership));
getModule(), hasOwnership()));
}

TupleExtractInst *createTupleExtract(SILLocation Loc, SILValue Operand,
Expand Down Expand Up @@ -1501,7 +1472,7 @@ class SILBuilder {
OpenExistentialRefInst *
createOpenExistentialRef(SILLocation Loc, SILValue Operand, SILType Ty) {
auto *I = insert(new (getModule()) OpenExistentialRefInst(
getSILDebugLocation(Loc), Operand, Ty, hasOwnership));
getSILDebugLocation(Loc), Operand, Ty, hasOwnership()));
if (C.OpenedArchetypesTracker)
C.OpenedArchetypesTracker->registerOpenedArchetypes(I);
return I;
Expand Down Expand Up @@ -1637,13 +1608,13 @@ class SILBuilder {

StrongRetainInst *createStrongRetain(SILLocation Loc, SILValue Operand,
Atomicity atomicity) {
assert(C.isParsing || !getFunction().hasOwnership());
assert(!hasOwnership());
return insert(new (getModule()) StrongRetainInst(getSILDebugLocation(Loc),
Operand, atomicity));
}
StrongReleaseInst *createStrongRelease(SILLocation Loc, SILValue Operand,
Atomicity atomicity) {
assert(C.isParsing || !getFunction().hasOwnership());
assert(!hasOwnership());
return insert(new (getModule()) StrongReleaseInst(
getSILDebugLocation(Loc), Operand, atomicity));
}
Expand Down
2 changes: 0 additions & 2 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,6 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
Opts.DisableSILPartialApply |=
Args.hasArg(OPT_disable_sil_partial_apply);
Opts.EnableSILOwnership |= Args.hasArg(OPT_enable_sil_ownership);
Opts.AssumeUnqualifiedOwnershipWhenParsing
|= Args.hasArg(OPT_assume_parsing_unqualified_ownership_sil);
Opts.EnableMandatorySemanticARCOpts |=
Args.hasArg(OPT_enable_mandatory_semantic_arc_opts);
Opts.EnableLargeLoadableTypes |= Args.hasArg(OPT_enable_large_loadable_types);
Expand Down
8 changes: 1 addition & 7 deletions lib/ParseSIL/ParseSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5180,13 +5180,7 @@ bool SILParser::parseSILBasicBlock(SILBuilder &B) {
F->getBlocks().remove(BB);
F->getBlocks().push_back(BB);

bool AssumeUnqualifiedOwnershipWhenParsing =
F->getModule().getOptions().AssumeUnqualifiedOwnershipWhenParsing;
if (AssumeUnqualifiedOwnershipWhenParsing) {
F->setOwnershipEliminated();
}
B.setInsertionPoint(BB);
B.setHasOwnership(F->hasOwnership());
do {
if (parseSILInstruction(B))
return true;
Expand Down Expand Up @@ -5317,7 +5311,7 @@ bool SILParserTUState::parseDeclSIL(Parser &P) {
// Parse the basic block list.
FunctionState.OwnershipEvaluator.reset(FunctionState.F);
SILOpenedArchetypesTracker OpenedArchetypesTracker(FunctionState.F);
SILBuilder B(*FunctionState.F, /*isParsing*/ true);
SILBuilder B(*FunctionState.F);
// Track the archetypes just like SILGen. This
// is required for adding typedef operands to instructions.
B.setOpenedArchetypesTracker(&OpenedArchetypesTracker);
Expand Down
2 changes: 1 addition & 1 deletion lib/SIL/SILBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ using namespace swift;
SILBuilder::SILBuilder(SILGlobalVariable *GlobVar,
SmallVectorImpl<SILInstruction *> *InsertedInstrs)
: TempContext(GlobVar->getModule(), InsertedInstrs), C(TempContext),
F(nullptr), hasOwnership(false) {
F(nullptr) {
setInsertionPoint(&GlobVar->StaticInitializerBlock);
}

Expand Down
2 changes: 1 addition & 1 deletion test/ClangImporter/static_inline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// RUN: %target-swift-frontend -parse-as-library -module-name=static_inline -emit-sil %S/Inputs/static_inline.swift -enable-objc-interop -import-objc-header %S/Inputs/static_inline.h -o %t/static_inline.sil
// RUN: %FileCheck < %t/static_inline.sil %s
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -parse-as-library -module-name=static_inline -O -emit-ir %t/static_inline.sil -enable-objc-interop -import-objc-header %S/Inputs/static_inline.h | %FileCheck --check-prefix=CHECK-IR %s
// RUN: %target-swift-frontend -parse-as-library -module-name=static_inline -O -emit-ir %t/static_inline.sil -enable-objc-interop -import-objc-header %S/Inputs/static_inline.h | %FileCheck --check-prefix=CHECK-IR %s

// CHECK: sil shared [serializable] [clang c_inline_func] @c_inline_func : $@convention(c) (Int32) -> Int32

Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/UseObjCMethod.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -import-objc-header %S/Inputs/StaticInline.h %s -emit-ir | %FileCheck %s
// RUN: %target-swift-frontend -import-objc-header %S/Inputs/StaticInline.h %s -emit-ir | %FileCheck %s

// REQUIRES: objc_interop
import Foundation
Expand Down
4 changes: 2 additions & 2 deletions test/IRGen/abi_v7k.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -emit-ir -primary-file %s -module-name test_v7k | %FileCheck %s
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -S -primary-file %s -module-name test_v7k | %FileCheck -check-prefix=V7K %s
// RUN: %target-swift-frontend -emit-ir -primary-file %s -module-name test_v7k | %FileCheck %s
// RUN: %target-swift-frontend -S -primary-file %s -module-name test_v7k | %FileCheck -check-prefix=V7K %s

// REQUIRES: CPU=armv7k
// REQUIRES: OS=watchos
Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/access_control.sil
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -emit-ir %s | %FileCheck %s
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s

import Builtin
import Swift
Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/access_markers.sil
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -swift-version 4 -enforce-exclusivity=checked -assume-parsing-unqualified-ownership-sil %s -emit-ir | %FileCheck %s --check-prefix=CHECK
// RUN: %target-swift-frontend -swift-version 4 -enforce-exclusivity=checked %s -emit-ir | %FileCheck %s --check-prefix=CHECK

import Builtin
import Swift
Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/alignment.sil
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -emit-ir %s | %FileCheck %s
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s

import Swift

Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/alloc_stack.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -primary-file %s -emit-ir | %FileCheck %s
// RUN: %target-swift-frontend -primary-file %s -emit-ir | %FileCheck %s

// REQUIRES: CPU=x86_64

Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/argument_attrs.sil
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -emit-ir %s | %FileCheck %s
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s

import Builtin

Expand Down
Loading