Commit Graph

218 Commits

Author SHA1 Message Date
swift-ci
e98a736cbf Merge remote-tracking branch 'origin/master' into master-next 2017-08-24 12:29:44 -07:00
Andrew Trick
0a36f9dee7 Fix SIL ownership for open_existential_value.
CoW existentials means that we can't forward ownership.
2017-08-23 22:15:10 -07:00
Andrew Trick
59d3158981 Allow the SIL ownership verifier to distinguish between guaranteed vs. owned
forwarding.
2017-08-23 22:15:10 -07:00
swift-ci
aa700a9ca8 Merge remote-tracking branch 'origin/master' into master-next 2017-08-23 10:29:34 -07:00
Erik Eckstein
9c6fe76927 SIL, IRGen: add instructions "object" and "global_value” to support statically initialized objects.
This commit contains:
-) adding the new instructions + infrastructure, like parsing, printing, etc.
-) support in IRGen to generate global object-variables (i.e. "heap" objects) which are statically initialized in the data section.
-) IRGen for global_value which lazily initializes the object header and returns a reference to the object.

For details see the documentation of the new instructions in SIL.rst.
2017-08-23 09:15:49 -07:00
Erik Eckstein
1ab582e121 SIL: A new representation of static initializers for global variables.
Static initializers are now represented by a list of literal and aggregate instructions in a SILGlobalVariable.
For details see SIL.rst.

This representation is cleaner than what we did so far (point to the initializer function and do some pattern matching).

One implication of that change is that now (a subset of) instructions not necessarily have a parent function.
Regarding the generated code it's a NFC.
Also the swift module format didn't change because so far we don't serializer global variables.
2017-08-23 09:15:01 -07:00
John McCall
a5d328690d PointerLikeTypeTraits is now a struct, not a class.
We compile with a pedantic warning that complains about these things,
and the massive flood of warnings is actually causing problems for the
build infrastructure.
2017-08-17 17:01:17 -04:00
Michael Gottesman
ec44f55372 [sil-ownership] Reify the lifetime constraint of a use from a bool into UseLifetimeConstraint.
This is the first in a series of commits that cleans up the SILOwnershipVerifier
based off of discussions/feedback with other people who are now using it. The
next step is to split the checker from the declarative computation of what I
call the UseOwnershipRequirement.

rdar://33358110
2017-08-03 19:50:45 -07:00
Michael Gottesman
687aced054 [sil-ownership] When computing if a value is lifetime ending perform exact matching.
Otherwise, one can run into situations where an Any from a SILUndef results in
SSA values having destroying uses. Since we are dealing with an undef value,
from an ownership perspective, we can assume any form of ownership constraints
that we want. Thus we can treat the value as being eternal and thus from the
ownership verifier's perspective like a metatype.

rdar://33358110
2017-08-03 18:21:48 -07:00
Andrew Trick
314d48f055 Fix ownership of UnconditionalCheckedCastValue. 2017-08-02 16:26:41 -07:00
Kosuke Ogawa
2a18723b55 [gardening] Fix typos (#11245)
* [Gardening] Fix typo: getTopLeveDecls -> getTopLevelDecls

* [Gardening] Fix typo: silModue -> silModule

* [Gardening] Fix typo: Evaludate -> Evaluate

* [Gardening] Fix typo: OptioanlPayload -> OptionalPayload

* [Gardening] Fix typo: confromance -> conformance

* [Gardening] Fix typos

* [Gardening] Fix typo: tpye -> type

* [Gardening] Fix typo: resoved -> resolved

* [Gardening] Fix typo: ahve -> have

* Revert "[Gardening] Fix typo: silModue -> silModule"

This reverts commit ed8c4d0b71.
2017-07-28 10:14:21 -07:00
Andrew Trick
3bc6746840 [sil-opaque-values] Ownership support. open_existential_value forwards ownership.
Just like open_existential_ref.
2017-07-27 11:35:16 -07:00
Andrew Trick
9a770a9528 [sil-opaque-values] OwnershipVerifier support. 2017-07-27 11:35:16 -07:00
Erik Eckstein
6377cc095a SIL: Replace TransitivelyUnreachableBlocks with DeadEndBlocks
We had both utilities doing the same thing.
NFC
2017-07-24 09:50:42 -07:00
Andrew Trick
4db2a46cff Add SIL instruction: open_existential_box_value.
This has the same semantics as open_existential_box, but returns an object value
instead of an address.

This is used in SIL opaque values mode. Attempting to reuse open_existential_box
in this mode causes SIL type inconsistencies that are too difficult to work
around. Adding this instruction allows for consistent handling of opaque values.

The original versions of several of these currently redundant instructions will
be removed once the SIL representation stabilizes.
2017-07-17 23:46:41 -07:00
Andrew Trick
f657ad2d3a Rename *ExistentialOpaque instructions to *ExistentialValue.
These instructions have the same semantics as the *ExistentialAddr instructions
but operate directly on the existential value, not its address.

This is in preparation for adding ExistentialBoxValue instructions.
The previous name would cause impossible confusion with "opaque existentials"
and "opaque existential boxes".
2017-07-17 23:46:41 -07:00
Michael Gottesman
069ae8eed6 [ownership-verifier] The second argument to dealloc_partial_ref is a metatype so it must be trivial.
rdar://31880847
2017-07-12 16:53:01 -07:00
Michael Gottesman
cd7c96c050 [ownership-verifier] store_weak is a liveness use, not a consuming use of a value.
rdar://31880847
2017-07-12 16:51:56 -07:00
Michael Gottesman
1264cfa492 [semantic-sil] Add a semantic attribute "verify.ownership.sil.never".
This semantic attribute allows a user to disable ownership verification on
specific functions.

The intention is that once I turn on the sil ownership verifier for parts of the
stdlib, if an engineer exposes an ownership issue, they can disable ownership
verification on that specific function, file a bug, and continue with their
work.

rdar://31880847
2017-07-10 13:28:06 -07:00
Michael Gottesman
9be606ee29 [semantic-sil] Teach the verifier that an enum return value is a ValueOwnershipKind erasure point.
This means that a trivial enum case of a non-trivial enum can be returned @owned
even though it is trivial. We already follow this pattern with bb arguments.

rdar://31880847
2017-07-09 02:45:48 -07:00
Michael Gottesman
56acc6d82b [sil-ownership-verifier] Allow class_method to take a metatype or a non-trivial type.
rdar://31880847
2017-07-08 22:10:13 -07:00
Michael Gottesman
69393d59c7 [sil-ownership] Allow for checked_cast_br to take a guaranteed parameter.
rdar://31880847
2017-07-05 01:19:23 -07:00
Michael Gottesman
1db06d1154 [sil-ownership] Allow for switch_enum to take a guaranteed parameter.
This is needed to ensure that SILGenPattern propagates values at +0 instead of
+1.

I also improved our handling of terminators in general when it comes to having
"borrowed" arguments. The basic verification requirement is that the
end_borrow_argument is treated as a use of the parent borrow. This ensures that
the borrowed argument can not extend the lifetime of the borrowed value without
the verifier triggering.

rdar://31880847
2017-07-05 01:07:49 -07:00
swift-ci
a0d9f055d4 Merge pull request #10732 from gottesmm/callee_unowned_can_accept_unowned 2017-06-30 14:27:49 -07:00
Michael Gottesman
8750b7856d [sil-ownership-verifier] We can pass unowned, owned, and guaranteed callees to a call site that uses its callee as unowned.
rdar://31880847
2017-06-30 13:57:05 -07:00
Michael Gottesman
9820023d0f [sil-ownership-verifier] Ignore end_borrow that are post-dominated by unreachable code.
rdar://31880847
2017-06-30 13:29:47 -07:00
Robert Widmann
3b202c18d8 Use 'hasAssociatedValues'
Use 'hasAssociatedValues' instead of computing and discarding the
interface type of an enum element decl.  This change has specifically not
been made in conditions that use the presence or absence of the
interface type, only conditions that depend on the presence or absence
of associated values in the enum element decl.
2017-05-22 09:54:47 -07:00
Roman Levenstein
d522618bac Add a new builtin called is_same_metatype for checking the equality between metatypes
Having such a builtin makes it easier for the optimizer to reason about what is actually happening.
I plan to add later some optimizations which can optimize pieces of code dominated by such a check.
2017-05-15 16:21:09 -07:00
Joe Shajrawi
0d0cac357a retain_value_addr and release_value_addr SIL instructions: take as an input an address, load the value inside it and call retain_value and release_value respectively 2017-04-30 10:23:55 -07:00
Joe Shajrawi
d17258cac7 @in_constant calling convention - part of passing large loadable types by address 2017-04-30 10:13:02 -07:00
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