Storing this separately is unnecessary since we already
serialize the enum element's interface type. Also, this
eliminates one of the few remaining cases where we serialize
archetypes during AST serialization.
Separate formal lowered types from SIL types.
The SIL type of an argument will depend on the SIL module's conventions.
The module conventions are determined by the SIL stage and LangOpts.
Almost NFC, but specialized manglings are broken incidentally as a result of
fixes to the way passes handle book-keeping of aruments. The mangler is fixed in
the subsequent commit.
Otherwise, NFC is intended, but quite possible do to rewriting the logic in many
places.
Unowned is a +0 convention that requires the user to "copy" the relevant value
before any side effects occur in the callee. This means that it is safe to pass
owned/guaranteed/unowned to such functions.
rdar://29791263
This also avoids undefined behavior when we try to look up the
ParameterConvention of a type dependent operand. Since type dependent operands
do not have a convention, this causes us to hit an assertion.
rdar://29791263
In the case of switch_enum this is just trivial enums. In the case of
checked_cast_br and dynamic_method_br, the potential trivial arguments are
metatypes.
rdar://29791263
Without this enums with non-trivial cases are always treated as non-trivial even
if a just created enum is trivial. For example the following no payload enum
would be considered non-trivial.
%0 = enum $Optional<Builtin.NativeObject>, #Optional.none!enumelt
rdar://29791263
This is only enabled when semantic sil is enabled /and/ we are not parsing
unqualified SIL.
*NOTE* To properly write tests for this, I had to rework how we verified
Branch/CondBranch insts to be actually correct (instead of pseudo-correct). I
have to put this functionality together in order to write tests.
rdar://29791263
Previously, we would require an end_borrow for guaranteed subobject borrows.
This was not the end design and of course would have triggered asserts since
end_borrow only supports ending borrows of the same type (by design). This
commit finishes the design by:
1. Verifying that subobject borrows do not have an end_borrow. This is done by
asserting that subobject borrows do not have lifetime ending uses.
2. Treating uses of a subobject borrow as normal liveness uses of the base
borrowed object. This means that the verifier will assert if there are
any uses of borrowed subobjects after the base's end_value.
rdar://29791263
The method SILInstruction::verifyOperandOwnership() is used in SILBuilder to
ensure that as instructions are created, if there are any use failures, the
error is caught at the moment the instruction is created. This makes debugging
such failures trivial. *NOTE* This does not cause dataflow verification to
occur.
The problem is that when PrintMessageInsteadOfAssert is enabled, this causes
dataflow failures to have their error messages emitted twice, complicating
FileCheck testing of the verifier.
Thus, this commit disables SILInstruction::verifyOperandOwnership() when
PrintMessageInsteadOfAssert is enabled. PrintMessageInsteadOfAssert is renamed
to 'IsSILOwnershipVerifierTestingEnabled' in light of its expanded role.
rdar://29791263
The reason why I am introducing special instructions is so I can maintain the
qualified ownership API wedge in between qualified SIL and the rest of the ARC
instructions that are pervasively used in the compiler.
These instructions in the future /could/ be extended to just take @sil_unmanaged
operands directly, but I want to maintain flexibility to take regular
non-trivial operands in the short term.
rdar://29791263
This commit makes the following changes:
1. guaranteed arguments will trip the verifier if they have a lifetime ending
use.
2. owned arguments must have a lifetime ending use in a function. We already
would have exposed this as a leak via the dataflow, but exiting early gives us a
better clearer error message.
The way SILResultInfo::getOwnershipKind(SILModule &) was implemented before was
incorrect, resulting in getTypeLowering being called on a lowered type without a
proper generic signature being pushed on the type lowering stack. This commit
fixes that issue locally.
The real fix is in a PR that Slava is preparing that provides a getTypeLowering
that takes a SILType and a GenericSignature so that the user does not need to
perform a push/pop.
rdar://29791263
This is dead code and can be re-added if it is needed. Right now though there
really isnt a ValueOwnershipKind that corresponds to deallocating and I do not
want to add a new ValueOwnershipKind for dead code.
This commit includes the dataflow verifier and plugs in the use checker into the
dataflow verifier.
Some specific checks in the use checker need revision, but I for today
this is good enough. As I go through SILGen I am going to fix them.
rdar://29671437
This is the first verifier for SemanticSIL. The verifier is very simple and
verifies that given a SILValue V, V->getOwnershipKind() returns an ownership
kind compatible with all of V's user instructions.
This is implemented by adding a new method to SILInstruction:
SILInstruction::verifyOperandOwnership()
This method creates an instance of the visitor OwnershipCompatibilityUseChecker
and then has the instance visit this.
The OwnershipCompatibilityUseChecker is a SILInstructionVisitor that for a given
instruction verifies that the given SILInstruction's operand SILValue's produce
ValueOwnershipKind that are compatible with the SILInstruction. The reason why
it is implemented as a visitor is to ensure that a warning is produced if a new
instruction is added and a method on the OwnershipCompatibleUseChecker isn't
added.
Keep in mind that this is just the first verifier and the full verifier (that
also verifies dataflow) is built on top of it. The reason why this separate API
to the use verifier is exposed is that exposing the checker enables us to place
an assert in SILBuilder to diagnose any places where SIL ownership is violated
immediately when the violation occurs allowing for an easy debugging experience
for compiler writers. This assert is a key tool that I am going to be using to
make SILGen conform to the SIL Ownership Model.
Again, this will be behind the -enable-semantic-sil flag, so normal development
will be unaffected by this change.
rdar://29671437