Commit Graph

228 Commits

Author SHA1 Message Date
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
e849900a7b [silgen] Add a new API for building switches: SwitchEnumBuilder.
This is a closure based API for creating switches that obey ownership
convensions. The way you use it with objects is as follows:

   SwitchEnumBuilder S(...);

   S.addCase(Decl, Block, [](ManagedValue Arg) -> void {
     ...
   });
   S.addCase(Decl, Block, [](ManagedValue Arg) -> void {
     ...
   });
   S.addDefaultCase(Block, [](ManagedValue Arg) -> void {
     ...
   });
   std::move(S).emit();

What is important is that it sets up the switch_enum destination blocks with the
proper cleanups for code emitted into the destination block and also provides
the default error with the passed in value with the appropriate cleanups.

It does not handle exits from the switch_enum on purpose since diamond
switch_enum APIs form a subset of APIs. It also expects the closure to create
terminators if appropriate.

In the switch_enum_addr case you have to do a bit more work, but it is still a
nicer API than doing it by hand as we do today.

rdar://29791263
2017-03-06 13:58:33 -08:00
Michael Gottesman
786c26b4df [silgen] Add a helper struct to SILGenBuilder for easing the recreation of cleanups for forwarding instructions.
rdar://29791263
2017-03-06 13:18:52 -08:00
Michael Gottesman
87ca878870 [silgen] Fix another tuple explosion -> borrow + copy since we do not have the destructure operation yet.
rdar://29791263
2017-03-05 11:44:11 -08:00
Michael Gottesman
80e297d6aa [silgen] Go through and fix up places where during bringup of load_borrow I just put in load_borrow without any end_borrow cleanups. Now use real cleanups.
rdar://29791263
2017-03-02 19:53:33 -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
Mikio Takeuchi
ad0c27edc5 Handle Unmanaged(Retain|Release)ValueInst as RefCountingInst 2017-02-27 12:25:57 +09:00
Michael Gottesman
5a15f880ee [silgen] Change a bunch of self accesses to use true formal evaluation scopes and formal accesses.
This is in preparation for removing the +0 self hack.

This commit in more detail does the following:

1. It adds Formal Evaluation Scopes to certain places where the scopes were
missing. Specifically:

   a. The SILGenLValue cases are places where we are invoking accessors. In each
      one of these cases, we had a formal evaluation scope in the accessor
      itself, but we did not have a scope that closed over the base access and
      the accessor access. The base access is a formal evaluation in the sense
      that just like with inout bases, we must create a new reference to the
      base and re-destroy the base in a chain of accesses. This is to ensure
      that we do not extend the lifetime of the base inappropriately.

   b. The SILGenPoly case is a place where we have never properly placed a
      Formal Evaluation Scope and have completely been relying on the +0 self
      hack to make sure that archetype callees are properly destroyed
      immediately after a +0 call.

2. It changes all of the places in SILGen that emit self to using formal access
cleanups instead of normal cleanups.

rdar://29791263
2017-02-23 10:36:48 -08:00
Michael Gottesman
784d5d16fc [silgen] Change emitClassConstructorInitializer to use ownership and make calling designated/chaining initializes use proper ownership.
rdar://29791263
2017-02-23 08:48:58 -08:00
Joe Shajrawi
147f844ce4 Merge pull request #7654 from shajrawi/init_opaque
Add support for Init Existentials for opaque value types
2017-02-20 19:37:01 -08:00
Joe Shajrawi
1e521c453b Add support for Init Existentials for opaque value types 2017-02-20 16:40:02 -08:00
Michael Gottesman
26a266b15e [silgen] Cleanup emitPreconditionOptionalHasValue and its uses so that they use proper ownership.
The big change here is that this routine will not emit switch_enum as a +1 value
and create a proper owned argument with cleanup.

rdar://29791263
2017-02-19 22:19:47 -08:00
Michael Gottesman
be50b2a624 [silgen] Add new ownership APIs for enum extraction to SILGenBuilder.
rdar://29791263
2017-02-19 20:43:43 -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
Michael Gottesman
825765a047 [silgen] Change createFormalAccessCopyAddr to take take/init parameters.
Previously, I just refactored one use of this API resulting in these two
parameters being hard coded. In truth these should never be hard coded.
2017-02-19 10:56:23 -08:00
Michael Gottesman
5717eeba67 [silgen] Create a ManagedValue::formalAccessCopy(SILGenFunction &, SILLocation).
This is the same as the current ManagedValue::copy(...) convenience API except
that the cleanups are formal evaluation scoped.

rdar://29791263
2017-02-19 08:03:33 -08:00
Michael Gottesman
0ae6c25238 [silgen] Make SILGenBuilder::createCopyValue a drop in replacement for SILGenFunction::emitManagedRetain.
The only difference is that the copy value API takes a ManagedValue. Hopefully
once we eliminate direct manipulation of SILValue in SILGen, we can get rid of
the emitManagedRetain API in SILGen.

rdar://29791263
2017-02-19 07:58:03 -08:00
Michael Gottesman
d051583378 [semantic-sil] When emitting a base for an accessor use a load_borrow when appropriate.
This builds on 92bf345. I am very pleased that a couple of the cases I needed to
update, a retain/release was eliminated on the base.

rdar://29791263
2017-02-18 00:55:36 -08:00
Michael Gottesman
64ad05bfed [gardening] Standardize variable capitalization in SILGenBuilder to match the rest of SILGen. NFC. 2017-02-17 19:47:43 -08:00
Michael Gottesman
5f226ffc59 [silgen] Perform borrow + tuple_extract + copy for SILGenPoly.
Another case of needing a destructure operation.

rdar://29791263
2017-02-08 16:20:02 -08:00
Michael Gottesman
d153f36e48 [silgen] Handle forwarding of direct tuple args using a borrow + extract + copy triple
Once we have a destructure operation this will not be necessary.

rdar://29791263
2017-02-08 16:00:23 -08: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
Michael Gottesman
9bcbe8c299 [silgen] Add a new API called SILGenBuilder::createOwnedPHIArgument.
This new API creates a new PHI argument in the current insertion block of the
SILBuilder with @owned ownership, creates a new ManagedValue with cleanup and
returns that ManagedValue. This eliminates one case where often times in SILGen
people use SILBuilder APIs on SILGenBuilder and then manage their own ownership
instead of gliding lightly on top of pure ManagedValue APIs.

rdar://29791263
2017-02-04 13:40:26 -08:00
Michael Gottesman
77c1dfcb3a [semantic-sil] Use borrow semantics when emitting a struct_extract sequence.
rdar://29791263
2017-01-26 16:46:42 -08:00
Michael Gottesman
0331400f60 [silgen] Store the relevant SILGenFunction instead of the SILGenModule in SILGenBuilder
We already always associate a SILGenBuilder with one function, just like
SILBuilder, so there really is no reason not to store the SILGenFunction. The
reason why I want to do so here though is that I want access to the ManagedValue
APIs on SILGenFunction so I can begin to add Ownership endowed entry points on
SILBuilder that traffic only in ManagedValue instead of SILValue.

rdar://29791263
2017-01-19 13:40:55 -08:00
Michael Gottesman
1dbabed576 [silgen] Extract SILGenBuilder into its own header/cpp file.
NFC.
2017-01-18 16:46:14 -08:00