Commit Graph

227 Commits

Author SHA1 Message Date
Doug Gregor
ed1983d9d0 [SIL] Use SubstitutionMap in BuiltinInst. 2018-05-03 00:05:21 -07:00
Andrew Trick
abab49e54c Support exclusivity enforcement of KeyPath read-only access.
Use begin_unpaired_access [no_nested_conflict] for
Builtin.performInstantaneousReadAccess. This can't be optimized away
and is the proper marker to use when the access scope is unknown.

Drop the requirement that
_semantics("optimize.sil.preserve_exclusivity") be @inline(never). We
actually want theses inlined into user code. Verify that the
@_semantic functions are not inlined or otherwise tampered with prior
to serialization.

Make *no* change to propagate @inline(__always) into LLVM. This no longer has
any relationship to this PR and can be investigated seperately.
2018-04-19 22:46:10 -07:00
Joe Groff
62771a0c9d stdlib: Add withUnsafeBytes(of:) and withUnsafePointer(to:) for immutable arguments.
Since the functions produce pointers with tightly-scoped lifetimes there's no formal reason these have to only work on `inout` things.  Now that arguments can be +0, we can even do this without copying values that we already have at +0.
2018-04-18 09:13:45 -07:00
Michael Gottesman
6350397ff2 [Exclusivity] Add builtins needed for dynamic enforcement of exclusivity.
This is chopped off from Devin Coughlin's PR so I can test the actual fix that should
make the rest of his commit work.

rdar://problem/31972680
2018-04-17 13:04:06 -07:00
Michael Gottesman
e567bc9028 [+0-all-args] Enable +0 normal arguments.
rdar://34222540
2018-03-19 20:25:31 -07:00
Michael Gottesman
01c9fe4495 When assigning into memory via builtin assign, be sure that we store a +1 value.
NOTE:

1. This can not happen today with the +1 runtime.
2. This is tested by an updated builtins.swift test for +0 that I am going to
commit in a little bit.
3. We immediately forward the value when we put it into memory.

rdar://34222540
2018-03-08 19:15:14 -08:00
swift-ci
1a08342bb1 Merge pull request #14650 from gottesmm/pr-3ee39de175e9315f1e1b2f4d4e679aac451c9050 2018-02-14 16:28:53 -08:00
Michael Gottesman
2410406f8e [+0-all-arguments] Use SILGenBuilder APIs to ensure we put cleanups on the case result instead of on the cast argument.
Otherwise, we break SILGen tests when they are updated for +0. This breakage
occurs since we use the original cleanup from args[0] instead of forwarding that
cleanup and creating a new cleanup on the result.

rdar://34222540
2018-02-14 15:25:22 -08:00
Michael Gottesman
398f20c506 [+0-all-args] Add SILGenBuilder APIs for createRefToBridgeObject and use it in emitBuiltinCastToBridgeObject to ensure cleanups are on the actual bridge object.
This eliminates a case where we were not moving a cleanup onto a forwarding case
and instead just jammed the original cleanup and the new value into 1 managed
value.

NFC, but helps the ownership verifier.

rdar://34222540
2018-02-14 15:20:42 -08:00
Joe Shajrawi
f732ea66ef Builtins: add ValueToBridgeObject instruction 2018-02-12 13:27:59 +02:00
Chris Lattner
415cd50ba2 Reduce array abstraction on apple platforms dealing with literals (#13665)
* Reduce array abstraction on apple platforms dealing with literals

Part of the ongoing quest to reduce swift array literal abstraction
penalties: make the SIL optimizer able to eliminate bridging overhead
 when dealing with array literals.

Introduce a new classify_bridge_object SIL instruction to handle the
logic of extracting platform specific bits from a Builtin.BridgeObject
value that indicate whether it contains a ObjC tagged pointer object,
or a normal ObjC object. This allows the SIL optimizer to eliminate
these, which allows constant folding a ton of code. On the example
added to test/SILOptimizer/static_arrays.swift, this results in 4x
less SIL code, and also leads to a lot more commonality between linux
and apple platform codegen when passing an array literal.

This also introduces a couple of SIL combines for patterns that occur
in the array literal passing case.
2018-01-02 15:23:48 -08:00
Michael Gottesman
04056ce243 [silgen] When emitting convertBridgeObjectToRef, forward ownership through the instruction rather than unconditionally adding a cleanup.
Otherwise, we may put cleanups on borrowed values.

rdar://34222540
2017-11-19 16:00:45 -08:00
Jordan Rose
b6c28b02d0 [SIL] Remove the builtins related to UnknownObject.
No functionality change; nothing is using them.
2017-10-02 09:05:31 -07:00
Mark Lacey
c0c848d2b3 Add Builtin.type_join* family of functions.
These will be used for unit-testing the Type::join functionality in the
type checker. The result of the join is replaced during constraint
generation with the actual type.

There is currently no checking for whether the arguments can be used to
statically compute the value, so bad things will likely happen if
e.g. they are type variables. Once more of the basic functionality of
Type::join is working I'll make this a bit more bullet-proof in that
regard.

They include:
  // Compute the join of T and U and return the metatype of that type.
  Builtin.type_join<T, U, V>(_: T.Type, _: U.Type) -> V.Type

  // Compute the join of &T and U and return the metatype of that type.
  Builtin.type_join_inout<T, U, V>(_: inout T, _: U.Type) -> V.Type

  // Compute the join of T.Type and U.Type and return that type.
  Builtin.type_join_meta<T, U, V>(_: T.Type, _: U.Type) -> V.Type

I've added a couple simple tests to start off, based on what currently
works (aka doesn't cause an assert, crash, etc.).
2017-09-21 14:43:26 -07:00
Michael Gottesman
e035c93ed9 [silgen][gardening] More gen => SGF. 2017-08-10 21:42:21 -07:00
Michael Gottesman
7cf4cdf9d9 [silgen] Verify that all ManagedValues in all RValues that are loadable are actual loaded (i.e. have object type).
This is already an RValue invariant that used to be enforced upon RValue
construction. We put in a hack to work around a bug where that was not occuring
and changed RValue constructors to instead load stored objects when they needed
to. But the problem is that since then we have added more constructors that
provide other manners to create such an invalid RValue.

I added verification to many parts of RValue and exposed an additional verify
method that we can invoke at the end of emitRValue() eventually to verify our
invariants. This will give me the comfort to make that assumption in other parts
of SILGen without worry.

I also performed a small amount of cleanup of RValue construction.

rdar://33358110
2017-08-08 00:43:33 -07:00
Andrew Trick
4bda810292 [sil-opaque-values] Add support for SILGen emitBuiltinCastReference. 2017-07-17 14:06:27 -07:00
Andrew Trick
1b21d31b96 [sil-opaque-values] Add support for SILGen emitBuiltinReinterpretCast. 2017-07-17 14:06:27 -07:00
Slava Pestov
29cd885996 SILGen: Remove SILGenFunction::ArchetypeOpenings
SILBuilder now tracks data dependencies between instructions
that open existentials and uses of the opened type, so
SILGen's mechanism for this is no longer needed.

In particular, this simplifies ArchetypeCalleeBuilder.
2017-06-02 01:35:11 -07:00
Slava Pestov
c28c420a1f SILGen: Simplify SILGenApply a bit
We were passing around a ton of unused parameters,
just remove them.
2017-06-02 01:35:01 -07:00
Alex Hoppen
8946015d5a [SIL] Preparations for removal of getName on ValueDecl
With the introduction of special decl names, `Identifier getName()` on
`ValueDecl` will be removed and pushed down to nominal declarations
whose name is guaranteed not to be special. Prepare for this by calling
to `DeclBaseName getBaseName()` instead where appropriate.
2017-05-28 19:13:24 -07:00
Michael Gottesman
8f2011b4fa Revert "Revert "[semantic-sil] Fix ownership forwarding in emitCastToReferenceType.""
This reverts commit c3c9ba3a82.
2017-03-26 12:51:19 -07: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
Michael Gottesman
c3c9ba3a82 Revert "[semantic-sil] Fix ownership forwarding in emitCastToReferenceType."
This reverts commit 9f1daaa023.
2017-03-13 16:32:28 -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
Michael Gottesman
9f1daaa023 [semantic-sil] Fix ownership forwarding in emitCastToReferenceType.
rdar://29791263
2017-03-08 15:34:34 -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
Mikio Takeuchi
ad0c27edc5 Handle Unmanaged(Retain|Release)ValueInst as RefCountingInst 2017-02-27 12:25:57 +09:00
Mikio Takeuchi
488d531846 Enhance -assume-single-threaded option (SR-3945) 2017-02-27 12:17:53 +09:00
Michael Gottesman
850e674349 [silgen] Change SILGenBuiltin emission of retain/release/autorelease to use the unmanaged version of those operations.
These builtins are used to opt out of verification by the ownership verifier.

rdar://29791263
2017-02-19 18:21:45 -08:00
Michael Gottesman
dd5120e9f0 [silgen] Create a closure API called bufferForExprResult based on getBufferForExpr/manageBufferForExpr but managing the ownership for the user.
There are many cases where getBufferForExpr and manageBufferForExpr occur right
next to each other. The closure based API expresses this pattern in a more
convenient manner where the user can express his/her intent with one action
instead of two. In these cases, the split is messy and not necessary.
2017-02-19 11:15:01 -08:00
Hugh Bellamy
f001b7562b Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH 2017-02-12 10:47:03 +07:00
swift-ci
bfa3cece06 Merge pull request #7310 from gottesmm/alloc_tail_fix 2017-02-07 15:34:56 -08:00
Michael Gottesman
03b8375d83 [silgen] When emitting BuiltinAllocWithTailElems, be sure to create a cleanup.
This is actually a NFC change since we forward the cleanup in most cases and the
forwarding behavior is tested already by SILGen. But what this /does/ do is
prevent us from creating a ManagedValue that is "owned" but does not have a
cleanup.

rdar://29791263
2017-02-07 12:25:58 -08:00
Slava Pestov
3519e0cd25 AST: Introduce new SubstitutionList type to replace ArrayRef<Substitution>
SubstitutionList is going to be a more compact representation of
a SubstitutionMap, suitable for inline allocation inside another
object.

For now, it's just a typedef for ArrayRef<Substitution>.
2017-02-06 21:36:33 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Joe Groff
66a2b6a0e2 SILGen: Purge misuses of pre-exploded RValue constructor.
The RValue(ArrayRef<ManagedValue>, CanType) constructor was intended as a semi-private interface for building an RValue from a pre-exploded array of elements, but was (understandably) widely being misused as a general ManagedValue-to-RValue constructor, causing crashes when working with tuples in various contexts where RValue's methods expected them to be exploded. Make the constructor private and update most improper uses of it to use the exploding RValue constructor, or to use a new `RValue::withPreExplodedElements` static method that more explicitly communicates the intent of the constructor. Fixes rdar://problem/29500731.
2016-12-05 14:55:59 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Michael Gottesman
34ec32bc14 [semantic-arc] Handle the rest of the unqualified mem opts in SILGen.
Keep in mind that these are approximations that will not impact correctness
since in all cases I ensured that the SIL will be the same after the
OwnershipModelEliminator has run. The cases that I was unsure of I commented
with SEMANTIC ARC TODO. Once we have the verifier any confusion that may have
occurred here will be dealt with.

rdar://28685236
2016-11-09 11:37:52 -08:00
Michael Gottesman
3e5c4326fe [semantic-arc] Remove all uses of SILBuilder::*AndFold in SILGen and TypeLowering.
I am removing these usages of this API since it conflicts with SILGen's want to
hold onto copy_value return values for ownership propagation purposes. If any of
the copy_value are folded, the reference that SILGen holds onto will be
invalid.

rdar://28685236
2016-11-06 23:17:17 -08:00
Michael Gottesman
e2419b75fd [semantic-arc] Qualify most of the stores in SILGen as store [init].
All of these cases were trivially inits since they involved storing into
a newly created temporary allocation.

rdar://28685236
2016-10-31 15:51:26 -07:00
Michael Gottesman
bffa7addaf [semantic-arc] Eliminate default {Load,Store}OwnershipQualification argument to SILBuilder::create{Load,Store}(...)
Today, loads and stores are treated as having @unowned(unsafe) ownership
semantics. This leaves the user to specify ownership changes on the loaded or
stored value independently of the load/store by inserting ARC operations. With
the change to Semantic SIL, this will no longer be true. Instead loads, stores
have ownership semantics that one must reason about such as copy, take, and
trivial.

This change moves us closer to that world by eliminating the default
OwnershipQualification argument from create{Load,Store}. This means that the
compiler developer cannot ignore reasoning about the ownership semantics of the
memory operation that they are creating.

Operationally, this is a NFC change since I have just gone through the compiler
and updated all places where we create loads, stores to pass in the former
default argument ({Load,Store}OwnershipQualifier::Unqualified), to
SILBuilder::create{Load,Store}(...). For now, one can just do that in situations
where one needs to create loads/stores, but over time, I am going to tighten the
semantics up via the verifier.

rdar://28685236
2016-10-30 13:07:06 -07:00
Michael Gottesman
9507093b17 [semantic-arc] Change SILGen to only use copy_value, destroy_value.
rdar://28851920
2016-10-29 20:11:07 -07:00
Erik Eckstein
db00c5e924 SIL: allow alloc_ref_dynamic to allocate tail elements.
It's the same thing as for alloc_ref: the optional [tail_elems ...] attribute specify the tail elements to allocate.
For details see docs/SIL.rst

This feature is needed so that we can allocate a MangedBuffer with alloc_ref_dynamic.
The ManagedBuffer.create() function uses the dynamic self type to create the buffer instance.
2016-10-06 08:46:23 -07:00
Erik Eckstein
d89a21460e Add builtins to generate instructions for tail-allocated arrays in SIL.
Those builtins are: allocWithTailElems_<n>, getTailAddr and projectTailElems
Also rename the "gep" builtin, which indexes raw bytes, to "gepRaw" and add a new "gep" builtin to index in a typed array.
2016-09-16 11:02:19 -07:00
Dmitri Gribenko
fbb3cf35a5 Revert "New SIL instructions to support tail-allocated arrays in SIL." 2016-09-15 00:25:25 -07:00
Erik Eckstein
2a92b84b54 Add builtins to generate instructions for tail-allocated arrays in SIL.
Those builtins are: allocWithTailElems_<n>, getTailAddr and projectTailElems
Also rename the "gep" builtin, which indexes raw bytes, to "gepRaw" and add a new "gep" builtin to index in a typed array.
2016-09-14 14:54:18 -07:00
Luke Larson
74e0498015 Revert "Update master to build with Xcode 8 beta 3, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs."
This reverts commit 62d1fa760c.
2016-07-19 15:18:17 -07:00
Mishal Shah
62d1fa760c Update master to build with Xcode 8 beta 3, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs. 2016-07-19 22:31:34 +02:00