Skip to content

Commit be95e63

Browse files
committed
[semantic-arc] Add a flag to SILBuilder called isParsing to allow for SILBuilder to ignore invariants while parsing.
I am going to add asserts to SILBuilder to ensure that the leaf level functions that create qualified ownership and unqualified ownership instructions assert if one attempts to create functions with the wrong ownership qualification. This creates problems in the parser though since we apply the ownership qualification heuristic to SILInstructions after we have created the instruction via SILBuilder. I could change the ownership model evaluator to have special methods for various instructions, but I think that would introduce more decentralized code in the Parser which I want to avoid. Instead this commit just introduces a small isParsing flag that is set by SILParser on its SILBuilder that will cause these invariants to be ignored. Since the bool is used in the actual asserts themselves they are at the call site where they have an effect, making it very clear what is going on. rdar://28851920
1 parent de5cad9 commit be95e63

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,20 @@ class SILBuilder {
5151
/// only by SILGen or SIL deserializers.
5252
SILOpenedArchetypesTracker *OpenedArchetypesTracker = nullptr;
5353

54+
/// True if this SILBuilder is being used for parsing.
55+
///
56+
/// This is important since in such a case, we want to not perform any
57+
/// Ownership Verification in SILBuilder. This functionality is very useful
58+
/// for determining if qualified or unqualified instructions are being created
59+
/// in appropriate places, but prevents us from inferring ownership
60+
/// qualification of functions when parsing. The ability to perform this
61+
/// inference is important since otherwise, we would need to update all SIL
62+
/// test cases while bringing up SIL ownership.
63+
bool isParsing = false;
64+
5465
public:
55-
SILBuilder(SILFunction &F) : F(F), BB(0) {}
66+
SILBuilder(SILFunction &F, bool isParsing = false)
67+
: F(F), BB(0), isParsing(isParsing) {}
5668

5769
SILBuilder(SILFunction &F, SmallVectorImpl<SILInstruction *> *InsertedInstrs)
5870
: F(F), BB(0), InsertedInstrs(InsertedInstrs) {}

lib/Parse/ParseSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4103,7 +4103,7 @@ bool Parser::parseDeclSIL() {
41034103
// Parse the basic block list.
41044104
FunctionState.OwnershipEvaluator.reset(FunctionState.F);
41054105
SILOpenedArchetypesTracker OpenedArchetypesTracker(*FunctionState.F);
4106-
SILBuilder B(*FunctionState.F);
4106+
SILBuilder B(*FunctionState.F, /*isParsing*/ true);
41074107
// Track the archetypes just like SILGen. This
41084108
// is required for adding typedef operands to instructions.
41094109
B.setOpenedArchetypesTracker(&OpenedArchetypesTracker);

0 commit comments

Comments
 (0)