Commit Graph

88 Commits

Author SHA1 Message Date
John McCall
978f0e05fe Add unpaired access marker instructions and use them to implement
dynamic access tracking in materializeForSet.
2017-04-22 22:52:13 -04:00
Joe Groff
595e0e4ede Merge branch 'master' into keypaths 2017-04-19 18:38:24 -07:00
Michael Gottesman
aa76c2a5e6 [silgen] (mark_uninitialized (project_box (alloc_box))) -> (project_box (mark_uninitialized (alloc_box)))
I put in a simple fixup pass (MarkUninitializedFixup) for staging purposes. I
don't expect it to be in tree long. I just did not feel comfortable fixing up in
1 commit all of the passes up to DI.

rdar://31521023
2017-04-17 17:45:54 -07:00
Michael Gottesman
e7b8865696 [semantic-sil] Move the ownership model eliminator past no return folding.
rdar://31521023
2017-04-11 11:43:19 -07:00
Arnold Schwaighofer
b167b4475d Add SIL and IRGen support for a ConstantStringLiteral instruction
This supports a utf8 or utf16 encoding.

rdar://30545013
2017-04-11 08:43:47 -07:00
Joe Groff
85ad6b355e Merge branch 'master' into keypaths 2017-04-06 18:02:07 -07:00
Michael Gottesman
dcac8f7d04 [semantic-sil] Compile the verifier also in non assert builds. 2017-04-05 14:35:39 -07:00
Michael Gottesman
e34bbdf2fb [semantic-sil] Create a new higher level API for accessing the ownership checker. It is meant to be used by passes.
rdar://29870610
2017-04-05 14:34:21 -07:00
Michael Gottesman
315157cbb7 [semantic-sil] Refactor the ownership checker to store the list of uses that it finds and provide the ability to provide these to users of the ownership checker.
rdar://29870610
2017-04-05 13:42:57 -07:00
Michael Gottesman
a5825d94b9 [semantic-sil] Refactor the ownership checker's handling on finding an error.
Today the ownership checker has two different behaviors on detecting an error:

1. In normal operating mode, it prints a message to stderr and asserts.
2. In testing mode, it prints a message to stderr and returns false.

This refactoring will allow me to add a third mode:

1. In optimization mode, it does not print a message and just returns false.

This will allow me to use the verifier in an early ARC optimization that I need
to prevent COW copies due to refactoring in SILGenPattern.

rdar://29870610
2017-04-05 13:13:52 -07:00
Joe Groff
d42f2049f7 KeyPaths: Implement in-place instantiation of invariant key paths.
For key paths without generic or subscript parameterization, we can turn the compiler-generated key path pattern into a global object in-place.
2017-04-05 08:46:45 -07:00
Joe Groff
638759ac28 SIL: Add a "keypath" instruction for summoning literal keypath objects. 2017-04-04 11:31:15 -07:00
Doug Gregor
5b3fe49cd0 [SE-0160] Log uses of @objc thunks emitted due to deprecated @objc inference.
Introduce a new runtime entry point,
`swift_objc_swift3ImplicitObjCEntrypoint`, which is called from any
Objective-C method that was generated due to `@objc` inference rules
that were removed by SE-0160. Aside from being a central place where
users can set a breakpoint to catch when this occurs, this operation
provides logging capabilities that can be enabled by setting the
environment variable SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT:

  SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT=0 (default): do not log
  SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT=1: log failed messages
  SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT=2: log failed messages with
  backtrace
  SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT=3: log failed messages with
  backtrace and abort the process.

The log messages look something like:

    ***Swift runtime: entrypoint -[t.MyClass foo] generated by
       implicit @objc inference is deprecated and will be removed in
       Swift 4
2017-03-31 21:22:16 -07:00
John McCall
57ecaa7fae Add begin_access and end_access instructions.
NFC because we're not actually emitting them.
2017-03-26 04:37:05 -04:00
Michael Gottesman
6d7b11c8eb [stdlib] Cleanup usage of Builtin.castToNativeObject(...).
Previously often times when casting a value, we would just pass along the
cleanup of the uncasted value. With semantic SIL this is no longer correct since
the cleanup now needs to be on the cast result.

This caused problems for certain usages of Builtin.castToNativeObject(...) by
the stdlib. Specifically, the stdlib was using this on AnyObject values that
were not necessarily native. Since we were recreating the cleanup on the native
value, a swift native release was being used =><=.

In this commit I solve this problem by:

1. Adding an assert in Builtin.castToNativeObject(...) that ensures that any value
passed to Builtin.castToNativeObject() is known conservatively to use swift
native reference counting.

2. I changed all uses where we do not have a precondition of a native ref
counting type to use Builtin.castToUnknownObject(...).

3. I added a new Builtin called Builtin.unsafeCastToNativeObject(...) that does
not have the compile time check. I used this to rewrite callsites in the stdlib
where we know via preconditions that an AnyObject will dynamically always be
native.

rdar://29791263
2017-03-14 00:10:16 -07:00
Joe Groff
99ea154151 Merge pull request #7965 from jckarter/invariant-load
Add a `loadInvariant` builtin.
2017-03-09 06:39:42 -08:00
Joe Groff
39ecc53a25 Add a loadInvariant builtin.
Lowers to an invariant load in LLVM; probably useful for SIL too at some point too, but NFC at that level yet.
2017-03-08 21:02:03 -08:00
Joe Shajrawi
33b0cf653f Rename unconditional_checked_cast_opaque to unconditional_checked_cast_value 2017-03-07 18:53:52 -08:00
Devin Coughlin
8026026df3 Merge pull request #7925 from devincoughlin/sil_tsan_inout_access_builtin
SIL: Add SIL builtin for Thread Sanitizer inout accesses
2017-03-07 08:10:00 -08:00
Devin Coughlin
6ac36df1e7 SIL: Add SIL builtin for Thread Sanitizer inout accesses
...and IRGen it into a call to __tsan_write1 in compiler-rt. This is
preparatory work for a later patch that will add an experimental
option to treat Swift inout accesses as TSan writes.
2017-03-06 19:13:50 -08:00
Joe Shajrawi
ca77872ba8 Merge CheckedCastValueBranch with new master 2017-03-06 17:32:09 -08:00
Joe Shajrawi
1f626304f1 Add support for conditional checked cast instruction for opaque value types + SILGen support for it 2017-03-06 16:35:27 -08:00
Michael Gottesman
cfb5893663 [silgen] Fix destroying destructor to use proper ownership with its @owned return value.
rdar://29791263
2017-03-02 17:17:17 -08:00
Michael Gottesman
4bc12aedbd [sil] Add end_lifetime.
This is the lifetime ending variant of fix_lifetime. It is a lie to the
ownership verifier that a value is being consumed along a path. Its intention is
to be used to allow for the static verification of ownership in deallocating
deinits which for compatibility with objective-c have weird ownership behavior.
See the commit merged with this commit for more information.
2017-03-01 18:30:23 -08:00
Michael Gottesman
455c126238 [semantic-sil] Pass the uncasted argument as an @owned arg in the failed checked_cast_br cast.
Previously, we would put a destroy_value directly on the value that we tried to
cast. Since checked_cast_br is consuming, this would cause the destroy_value on
the failure path to be flagged as a double consume.

This commit causes SILGen to emit the value consumed by checked_cast_br as an
@owned argument to the failure BB, allowing semantic arc rules to be respected.

As an additional benefit, I also upgraded the ownership_model_eliminator test to
use semantic sil verification.

One issue that did come up though is that I was unable to use the new code in
all locations in the compiler. Specifically, there is one location in
SILGenPattern that uses argument unforwarding. I am going to need to undo
argument unforwarding in SILGenPattern in order to completely eliminate the old
code path.
2017-02-28 17:29:03 -05:00
Joe Shajrawi
16b6cb5e1d Support for deinit of opaque existentials: deinit_existential_opaque instruction + SILGen support 2017-02-27 14:46:43 -08:00
Michael Gottesman
2a75a12fc7 Fix ownership classification of opaque instructions and re-enable opaque_values_silgen test. 2017-02-23 16:49:03 -08:00
Joe Shajrawi
ec1e3ee20e Add support for unconditional checked cast instruction for opaque value types + SILGen support for it 2017-02-22 16:35:46 -08:00
Joe Shajrawi
1e521c453b Add support for Init Existentials for opaque value types 2017-02-20 16:40:02 -08:00
practicalswift
8af31961b2 Merge pull request #7464 from practicalswift/gardening-20170214b
[gardening] Fix recently introduced typos
2017-02-14 21:10:52 +01:00
practicalswift
65b0219f7b [gardening] Fix typos 2017-02-14 20:04:08 +01:00
Michael Gottesman
9a136cfc1e [ownership-verifier] Teach the ownership verifier how to handle control dependent ownership from cond_br.
Rememebering that the verifier ensures that any edge that propagates ownership
along a cond_br can not be critical, we do this by sinking the use by the
cond_br into the destination blocks.

rdar://29791263
2017-02-14 11:03:29 -08:00
Michael Gottesman
ed67bf9f21 [ownership-verifier] Teach the ownership verifier how to handle unreachable code.
There are a few different use cases here:

1. In Raw SIL, no return folding may not have been run yet implying that a call
to a no-return function /can/ have arbitrary control flow after it (consider
mandatory inlined functions). We need to recognize that the region of code that
is strictly post dominated by the no-return function is "transitively
unreachable" and thus leaking is ok from that point. *Footnote 1*.

2. In Canonical and Raw SIL, we must recognize that unreachables and no-return
functions constitute places where we are allowed to leak.

rdar://29791263

----

*Footnote 1*: The reason why this is done is since we want to emit unreachable
code diagnostics when we run no-return folding. By leaving in the relevant code,
we have preserved all of the SILLocations on that code allowing us to create
really nice diagnostics.
2017-02-13 16:36:01 -08:00
Joe Shajrawi
df5297d877 Merge pull request #7349 from shajrawi/open_existential
Support for Open Existentials that do no take an address
2017-02-09 12:39:16 -08:00
Joe Shajrawi
c478828de7 Support for Open Existentials that do no take an address 2017-02-09 11:25:34 -08:00
Michael Gottesman
0bf0acd7f2 [ownership-verifier] Make unchecked_enum_data a propagating instruction.
This allows for an unchecked_enum_data to be either a consumed instruction or a
borrowed instruction. The reason why this makes sense in contrast to other value
projection operations like struct_extract and tuple_extract is that an enum
payload is essentially a tuple. This means that we are extracting the entire
value when we perform a struct_extract. So forwarding is viable from a semantic
perspective since if we destroy the payload, there is nothing left to destroy.

This contrasts with struct_extract and tuple_extract where we may have other
parts of the struct/tuple to destroy.

rdar://29791263
2017-02-08 19:13:54 -08:00
Michael Gottesman
49506557e3 [sil] Change SILResultInfo::getOwnershipKind to always take a CanGenericSignature.
This caused a crasher when running the ownership verifier. I don't have a test
case right now, since it happened several weeks ago.

The bug can not happen again since I eliminated the nullptr default argument.

rdar://29791263
2017-02-08 16:43:38 -08:00
Michael Gottesman
07a71d0518 [ownership-verifier] Implement use checking for builtins.
I implemented the mapping from  SILValue -> ValueOwnershipKind for builtins a
long time ago, but did not implement the stub for what ValueOwnershipKind's can
be accepted by builtins. It is a pretty simple mapping (most things are
trivial).

The only interesting cases are:

1. ErrorInMain, UnexpectedError, WillThrow: These take in an @owned error
parameter, but are just normal uses of the value, not lifetime ending uses.

2. UnsafeGuaranteed. This is a bonafide actual +1 lifetime ending use. It is the
only one in the builtins.

rdar://29791263
2017-02-06 14:59:48 -08:00
Michael Gottesman
6a4368529d [ownership-verifier] Loosen the restrictions on mark_dependence since turns out we can also take a guaranteed argument as the value that is depended upon.
This occurs specifically, when our base is a class and we are performing a
materialize for set on a sub field of the class.

rdar://29791263
2017-02-06 12:58:01 -08:00
Michael Gottesman
9c47c305db [ownership-verifier] Allow for trivial cases of non-trivial enums to be passed as @owned, @unowned, and @guaranteed arguments.
The logic here is that a function argument can be viewed as a PHI node in the
program graph (i.e. cfg for each function + call graph). Just like with normal
PHI nodes, we need to treat enums passed into these PHI nodes as true sum types,
but at the same time, do not want to constrain optimization when we know that
the payloaded type is trivial.

rdar://29791263
2017-02-06 12:50:14 -08:00
Michael Gottesman
88dc60c2ff [ownership-verifier] ValueMetatype has a single argument that can be trivial or @owned... so just make it take anything.
rdar://29791263
2017-02-06 12:43:50 -08:00
Michael Gottesman
554feff463 [semantic-sil] Create unmanaged_autorelease_value.
This is an autorelease for use with Builtin.autorelease that does not need to be
balanced as part of the ownership model.

rdar://29791263
2017-02-06 12:11:46 -08:00
Michael Gottesman
dc8b994fc2 [silgen] ref_element_addr should always take a borrowed operand.
rdar://29791263
2017-02-06 11:45:49 -08:00
Michael Gottesman
0bea544c34 [ownership-verifier] alloc_value_buffer returns a trivial value... 2017-02-05 20:18:24 -08:00
Michael Gottesman
8d570fdfbf [ownership-verifier] existential_metatype can accept addresses as well as objects meaning it can accept also trivial ownership. 2017-02-05 20:18:24 -08:00
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