Commit Graph

193 Commits

Author SHA1 Message Date
Michael Gottesman
7517391d86 [ownership-verifier] unchecked_trivial_bit_cast always produces trivial types, but accepts any type. 2017-02-05 20:18:24 -08:00
Michael Gottesman
88fc2fed6f [ownership-verifier] Another place I forgot to change getType().isTrivial(Mod) to a check against ValueOwnershipKind::Trivial.
This is needed to handle correctly:

1. non-trivial addresses.
2. trivial enum cases of enums that also have non-trivial payloaded cases.
2017-02-05 20:18:24 -08:00
Michael Gottesman
b0e4c68f61 [ownership-verifier] When we determine the OwnershipKind that select enum forwards, we should not look at the condition operand, just the case operands.
rdar://29791263
2017-02-05 20:18:24 -08:00
Slava Pestov
dca292c652 Serialization: Don't serialize contextual enum argument type
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.
2017-01-30 00:08:53 -08:00
Michael Gottesman
10ad10e8bc [ownership-verifier] mark_uninitialized is a forwarding instruction, not always trivial.
This can be seen in the case of a [rootself] variable.

rdar://29791263
2017-01-26 16:46:42 -08:00
Andrew Trick
1abeddcc5d [SILType] SILFunctionConventions API.
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.
2017-01-26 15:35:48 -08:00
Michael Gottesman
e16f01529e [ownership-verifier] Until we agree on a list of uses that are considered as preserving the lifetime of a mark_dependence, just propagate the mark_dependence into the use set of the base rather than the uses of the value.
rdar://29791263
2017-01-25 18:03:05 -08:00
Michael Gottesman
a9fcfcb272 [ownership-verifier] When verifying forwarded values, make sure to ignore
trivial ownership in aggregates that are non-trivial.

rdar://29791263
2017-01-25 18:03:05 -08:00
Michael Gottesman
74fc8d9067 [ownership-verifier] Allow for trivial enum args to be passed into non-trivial phi nodes.
rdar://29791263
2017-01-25 18:03:05 -08:00
Michael Gottesman
659a93ba99 [ownership-verifier] alloc_ref, alloc_ref_dynamic can have trivial arguments for tail stored data.
rdar://29791263
2017-01-25 18:03:05 -08:00
Michael Gottesman
ad9cd2ade1 [ownership-verifier] project_existential_box takes a non-trivial existential argument, not a trivial argument.
rdar://29791263
2017-01-25 18:03:05 -08:00
Michael Gottesman
cf7e480765 [ownership-verifier] Throw takes in an Error parameter which is an @owned protocol.
rdar://29791263
2017-01-25 18:03:05 -08:00
Michael Gottesman
1ef8ea6bc1 [ownership-verifier] alloc_value_buffer/dealloc_value_buffer have single trivial address operands.
rdar://29791263
2017-01-25 18:03:05 -08:00
Michael Gottesman
7476f16a00 [ownership-verifier] Forwarding instructions only are lifetime ending uses when forwarding owned semantics.
rdar://29791263
2017-01-25 18:03:05 -08:00
Michael Gottesman
c7aa4e294e [ownership-verifier] We accept owned/guaranteed/unowned in unowned positions.
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
2017-01-25 18:03:05 -08:00
Michael Gottesman
f78ffdb941 [ownership-verifier] Ignore type dependent operands when checking for uses since we don't care about them.
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
2017-01-25 18:03:05 -08:00
Michael Gottesman
4c7ec6e4dd [ownership-verifier] switch_enum, checked_cast_br, dynamic_method_br can have trivial and owned operands.
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
2017-01-24 19:38:38 -08:00
Michael Gottesman
adb85df969 [ownership-verifier] Use a check against ValueOwnershipKind::Trivial instead of SILType::isTrivial to determine trivial ownership in isValueAddressOrTrivial.
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
2017-01-24 18:11:02 -08:00
Michael Gottesman
e8ede8b32c [ownership-verifier] We should always stop at the dominating block definition when verifying.
I think this was introduced relatively recently. I added a test so that it does
not happen again.

rdar://29791263
2017-01-24 16:43:27 -08:00
Michael Gottesman
e826d431a9 [ownership-verifier] When verifying a def that is immediately consumed in the same block, do not add the block's predecessors to the worklist for visiting purposes.
rdar://29791263
2017-01-24 16:40:10 -08:00
Michael Gottesman
0a4618e93e [semantic-sil] Implement parsing and printing of ownership attributes on SILArguments.
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
2017-01-22 22:02:31 -08:00
Michael Gottesman
d045f20867 [semantic-sil] Add a new instruction end_borrow_argument.
I need this instruction in order to model the end of life of a guaranteed phi
arguments.

rdar://29791263
2017-01-22 20:46:25 -08:00
Michael Gottesman
f857f2c6bf [ownership-verifier] Add proper subobject borrowing verification.
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
2017-01-21 23:54:33 -08:00
Michael Gottesman
f462d201ab [ownership-verifier] Rename PrintMessageInsteadOfAssert => IsSILOwnershipVerifierTestingEnabled and use it to disable SILInstruction::verifyOperandOwnership
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
2017-01-21 23:54:33 -08:00
Michael Gottesman
df69ada2c1 [semantic-sil] Improve output for FileCheck tests for ownership verifier by printing out the function name first.
This just standardizes the output.

rdar://29791263
2017-01-20 11:52:34 -08:00
Michael Gottesman
49fe60cd41 [ownership-verifier] Instead of dumping the entire block, just dump the block's debug id.
Thanks to Erik for pointing out to me that this is the same value as a block's
printed ID. This makes the output significantly more readable!
2017-01-19 17:40:08 -08:00
Michael Gottesman
2da18c7b47 [semantic-sil] Add special unmanaged_{retain,release}_value instructions for unpaired retain/release operations in semantic sil.
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
2017-01-19 13:23:08 -08:00
Michael Gottesman
d873926108 [semantic-sil] Value projections of a trivial value are trivial. Otherwise, they are guaranteed.
Also added some tests to verify that this behavior does not change.
2017-01-18 16:19:05 -08:00
Michael Gottesman
e33ea6aefc [semantic-sil] Handle verification of guaranteed arguments correctly.
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.
2017-01-18 16:18:16 -08:00
Michael Gottesman
a0b498ca1b [semantic-sil] Print out function name when incompatible ownership is detected.
This makes FileCheck matching easier.
2017-01-18 14:46:54 -08:00
Michael Gottesman
186361c622 [ownership-verifier] Fix a small thinko from a previous refactoring and add a test to be sure I don't break it again...
rdar://29791263
2017-01-17 19:18:40 -08:00
swift-ci
eec18b01cb Merge pull request #6871 from gottesmm/fix_sil_result_info 2017-01-17 19:16:12 -08:00
Michael Gottesman
3950ada6f0 Merge pull request #6872 from gottesmm/assign_store_of_trivial
[ownership-verifier] When checking uses, make sure to treat sources of assign/store that are trivially typed as trivial.
2017-01-17 19:08:42 -08:00
Michael Gottesman
8fde305225 [ownership-verifier] When checking uses, make sure to treat sources of assign/store that are trivially typed as trivial.
Noticed while working through SILGen.

rdar://29791263
2017-01-17 18:05:31 -08:00
Michael Gottesman
4063694e85 [semantic-sil] Change SILResultInfo::getOwnershipKind(SILModule &) to also take a Generic Signature.
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
2017-01-17 18:01:17 -08:00
Michael Gottesman
17b4d05e4e [semantic-sil] Rename EndBorrowInst::get{Src,Dest} => get{BorrowedValue,OriginalValue}.
This is a clearer name that makes it easier to remember what each part of the
end borrow is meant to accomplish.
2017-01-17 17:01:14 -08:00
Hugh Bellamy
2445862e1b FIx recently introduced MSVC control path warnings 2017-01-14 12:40:41 +00:00
Michael Gottesman
d944930591 Remove the deallocating convention.
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.
2017-01-10 17:32:17 -08:00
Michael Gottesman
f23086bfaf [semantic-sil] Change ValueOwnershipKind into a struct enum and change helper functions to be helper methods. 2017-01-08 00:22:54 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Michael Gottesman
d77bcdce57 [sil-ownership-verifier] Fix a few bugs and add a few tests. 2016-12-21 22:28:29 -08:00
Michael Gottesman
4931161929 [semantic-sil] Implement the dataflow checker behind the -enable-semantic-sil flag.
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
2016-12-18 22:55:03 -08:00
Michael Gottesman
ef6462de47 [semantic-sil] Add the SILOwnershipUseVerifier behind the -enable-semantic-sil flag
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
2016-12-18 21:04:26 -08:00