Commit Graph

3168 Commits

Author SHA1 Message Date
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
Slava Pestov
c86b5ae427 AST: Header file gardening - include what you use 2017-01-19 20:07:06 -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
eeckstein
b861853f53 Merge pull request #6912 from eeckstein/dead-conf-elim
Remove dead witness tables, including dead witness functions.
2017-01-19 14:11:12 -08:00
swift-ci
0e8dc4443d Merge pull request #6916 from gottesmm/unmanaged_retainrelease_value 2017-01-19 14:05: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
Roman Levenstein
d308ae527f Merge pull request #6797 from swiftix/wip-partial-pre-specializations-wip-specialize-attribute
New syntax and semantics of the @_specialize attribute
2017-01-19 10:26:02 -08:00
Erik Eckstein
44f35b9160 Remove dead witness tables, including dead witness functions.
A witness table is dead if it is not used outside the module (private/internal) and it’s not used by any instruction or other witness table in the module.
Also the meta-type of the conforming type must not escape, because it’s possible to test any opaque type if it conforms to a protocol.

rdar://problem/23026019
2017-01-19 09:41:09 -08:00
Erik Eckstein
89c9ff5ca0 SIL: ConformanceCollector utility for collecting all conformances which are used by a SIL instruction.
Also verify the correctness of ConformanceCollector in IRGen by checking if IRGen does not use a conformance which is not collected by the utility.
2017-01-19 09:41:09 -08:00
Erik Eckstein
cb0ebae078 Derive the SIL linkage of a witness table from the minimum of the protocol’s and conforming type’s visibility.
For example, if an internal type conforms to a public protocol, the witness table should get internal linkage.
Previously we only considered the visibility of the protocol.

Fragile witness tables still have to get public symbol linkage. This is now handled in IRGen (like we do it for functions).
2017-01-19 07:58:10 -08:00
Roman Levenstein
99698c63fa Define AST level and SIL level representations of the @_specialize attribute.
This also includes serialization/deserialization and printing of this attribute.
2017-01-18 16:42:10 -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
Bob Wilson
24a61b5b5d Merge branch 'master-next'
This merge contains the changes to accompany the switch to the new stable
branches of llvm, clang, and compiler-rt that are based on swift-4.0-branch.
2017-01-18 09:22:52 -08:00
Michael Gottesman
042e6481c3 [ownership-verifier] store_borrow has a result which is trivial. Treat it as such.
Originally, we were going to use the result to enforce end_borrow lifetimes for
store_borrow. But with Andy's changes, this should no longer be necessary since
@in_guaranteed and @guaranteed will both take values.

rdar://29791263
2017-01-17 19:18:40 -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
Bob Wilson
eeb0f08988 Merge remote-tracking branch 'origin/master' into master-next 2017-01-17 10:45:44 -08:00
Michael Gottesman
2f9a90d124 [semantic-sil] objc_{existential_,}metatype_to_object should be treated as owned.
Metatypes in SIL are trivial, until we conver them to objects (mainly for cases
where one converts the metatype to an object for use in objc). Thus these
conversion functions must be treated as returning an @owned value.
2017-01-15 17:54:19 -08:00
Michael Gottesman
8a7e535b18 [semantic-sil] Fix semantics of unchecked_bitwise_cast for SILValue::getOwnershipKind().
This is used in SILGen in a few different cases:

1. trivial -> non-trivial. This should have unowned semantics since one should
retain before use.
2. non-trivial -> trivial. This should have trivial semantics.
3. trivial -> trivial. This should have trivial semantics.
4. non-trivial -> non-trivial. This should have forwarding semantics.
2017-01-15 17:46:34 -08:00
Bob Wilson
34514513fd Merge remote-tracking branch 'origin/master' into master-next 2017-01-15 17:34:17 -08:00
Michael Gottesman
8ede336cd2 [semantic-sil] thin_to_thick_function should be treated as returning an @owned value. 2017-01-15 17:23:28 -08:00
Hugh Bellamy
2445862e1b FIx recently introduced MSVC control path warnings 2017-01-14 12:40:41 +00:00
Bob Wilson
c765d5e3a5 Merge remote-tracking branch 'origin/master' into master-next 2017-01-12 15:58:19 -08:00
Slava Pestov
5c0afe93bc Merge pull request #5954 from hughbe/sil-msvc
Fix errors and warnings building swift/SIL on Windows using MSVC
2017-01-11 15:41:51 -08:00
Michael Gottesman
ea1f804207 [semantic-sil] Eliminate ValueOwnershipKind::Any from SILPHIArguments in Semantic SIL.
Most of this involved sprinkling ValueOwnershipKind::Owned in many places. In
some of these places, I am sure I was too cavalier and I expect some of them to
be trivial. The verifier will help me to track those down.

On the other hand, I do expect there to be some places where we are willing to
accept guaranteed+trivial or owned+trivial. In those cases, I am going to
provide an aggregate ValueOwnershipKind that will then tell SILArgument that it
should disambiguate using the type. This will eliminate the ackwardness from
such code.

I am going to use a verifier to fix such cases.

This commit also begins the serialization of ValueOwnershipKind of arguments,
but does not implement parsing of value ownership kinds. That and undef are the
last places that we still use ValueOwnershipKind::Any.

rdar://29791263
2017-01-10 20:05:23 -08:00
Michael Gottesman
e2273ce9dc [semantic-sil] Ensure that all function arguments have the correct ownership kind and create a verifier check that this is preserved.
rdar://29791263
2017-01-10 20:05:22 -08:00
Michael Gottesman
5dea7ea07f [semantic-sil] Move ValueOwnershipKind -> SILArgument and have subclasses pass in said value.
This in the case of insertFunctionArgument requires a ValueOwnershipKind to be
specified since we use that for transformations of function argument lists that
are only correct after the transformation is complete. This only occurs in
FunctionSignatureOptimizations.

On the other hand, createFunctionArgument is only used to construct completely
new argument lists, so we can instead just rely on the function we are in rather
than require the user to pass it in.

rdar://29791263
2017-01-10 20:04:41 -08:00
swift-ci
6acd2610a7 Merge pull request #6716 from gottesmm/eliminate_deallocating_convention 2017-01-10 20:02:51 -08: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
Bob Wilson
cf3a0458f2 Merge remote-tracking branch 'origin/master' into master-next 2017-01-10 09:05:23 -08:00
Slava Pestov
99903c0146 SIL: Fix type lowering and generic inlining with DynamicSelfType
If a generic parameter was substituted for Self, we have to be careful
to not erase Self.Type down to a concrete metatype.

Also, teach the devirtualizer that a metatype of Self type does not
have an exact static type.
2017-01-09 20:53:28 -08:00
Hugh Bellamy
36100bf21c Fix errors and warnings building swift/SIL on Windows using MSVC 2017-01-09 09:11:20 +00:00
Saleem Abdulrasool
3b9608338a Adjust for SVN r290708
The introduction of `llvm.memcpy.element.atomic` would cause an
ambiguity when we did the lookup with the trailing `.` for the type
parameters.  The intrinsic itself is not necessarily suffixed with the
type in the identifier.  Look up the identifier by explicit name.
2017-01-08 17:18:52 -08:00
Bob Wilson
37e7d1c627 Merge remote-tracking branch 'origin/master' into master-next 2017-01-08 17:07:46 -08:00
Robert Widmann
f9df986fa3 Merge pull request #6654 from modocache/ast-finish-renaming-module-to-moduledecl
[AST] Completely replace Module with ModuleDecl
2017-01-08 15:04:00 -07:00
Michael Gottesman
f3603c4b87 [semantic-sil] Remove SILBasicBlock::replaceFunctionArgument. It is dead. 2017-01-08 00:22:54 -08:00
Michael Gottesman
6b9aba8d2c [semantic-sil] Add a constructor for making a ValueOwnershipKind from a SILArgumentConvention. 2017-01-08 00:22:54 -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
Brian Gesiak
663b92ece9 [AST] Completely replace Module with ModuleDecl
The typedef `swift::Module` was a temporary solution that allowed
`swift::Module` to be renamed to `swift::ModuleDecl` without requiring
every single callsite to be modified.

Modify all the callsites, and get rid of the typedef.
2017-01-08 00:36:08 -05:00
Erik Eckstein
1eb3a0532b DeadFunctionElimination: don’t eliminate public methods which are called via a thunk.
For this we need to store the linkage of the “original” method implementation in the vtable.
Otherwise DeadFunctionElimination thinks that the method implementation is not public but private (which is the linkage of the thunk).

The big part of this change is to extend SILVTable to store the linkage (+ serialization, printing, etc.).

fixes rdar://problem/29841635
2017-01-06 16:06:32 -08:00
practicalswift
f3b9f91239 [gardening] Remove unused method hasAtMostOneOpenedArchetype 2017-01-06 16:44:07 +01:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00