Commit Graph

2682 Commits

Author SHA1 Message Date
Joe Groff
fc86f35471 Merge pull request #7750 from jckarter/static-stored-vars-in-concrete-extensions
SILGen: Allow static stored properties in fully-concrete extensions of generic types.
2017-02-24 18:26:55 -08:00
Joe Groff
886c83f6e7 SILGen: Allow static stored properties in fully-concrete extensions of generic types.
There's no need for per-instantiation storage in this case, so we can relax the implementation limitation for them.
2017-02-24 15:25:39 -08:00
Joe Shajrawi
acc33e895b Support load and load of copy for globals in opaque value types 2017-02-24 13:11:21 -08:00
practicalswift
26e07a2870 [gardening] Make sure parameter name in comment match actual name 2017-02-24 09:38:00 +01:00
Joe Groff
49011a323a Merge pull request #7703 from jckarter/switch-join-copy
SILGen: Fix overrelease of pattern bindings shared from multiple patterns.
2017-02-23 11:14:21 -08: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
Michael Gottesman
1820578411 [silgen] When offseting for an lvalue access to ref_element_addr, use a formal access borrow instead of a full borrow to make sure that the borrow ends at the end of the lvalue formal evaluation.
rdar://29791263
2017-02-23 08:48:57 -08:00
Joe Groff
fafe62f33e SILGen: Fix overrelease of pattern bindings shared from multiple patterns.
The `cmv.getValue() == value` check here seems fishy, since the downstream case block should always take ownership of the bound values. Now that `copy_value`s produce new defs, it's also never true when it would've been true using the `retain/release_value` model, leading us to fail to copy values when necessary.
2017-02-22 17:49:57 -08:00
Joe Shajrawi
d1dae72877 Merge pull request #7700 from shajrawi/unconditional_checked_cast
Add support for unconditional checked cast instruction for opaque value types + SILGen support for it
2017-02-22 17:18:07 -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
Slava Pestov
a2c3c67884 SILGen: Fix materializeForSet in preparation for generic subscripts
Subscripts in generic context will soon have a
GenericFunctionType, so get ready to handle that.
2017-02-21 23:52:12 -08:00
practicalswift
6d09574ffb [gardening] Fix likely word processing artefacts. 2017-02-21 14:20:34 +01: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
3d5f979dae [silgen] Perform a borrow when the native inputs require a guaranteed argument for a objc thunk.
In the case where we already have a guaranteed value, the borrow operation will
just return the guaranteed manage value. Thus it is ok to always just perform
the borrow unconditionally.

rdar://29791263
2017-02-19 19:50:42 -08: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
1e17d86836 [silgen] Change one instance of switch_enum{_addr} that were using default for the some case to just use the some case.
This is the first in a series of changes to make SILGen always emit switch_enums
such that payloads are always passed as an arguments to the destination blocks.
This is important since switch_enum today in SILGen is modeled as a consuming
operation. Thus if we follow the model today where we reuse in the destination
blocks the switched upon value, we have created either a use after free or a
double consuming (depending on how the value is used).

There is no reason why we should use a default case here for these optional enums.

rdar://29791263
2017-02-19 17:43:30 -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
5920daa373 [silgen] Refactor getAddressForInPlaceInitialization onto SGFContext(). 2017-02-19 10:58:43 -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
53b777cf9c [silgen] Add an assert that formalAccessCopy is only called in a FormalEvaluationScope.
NFC.
2017-02-19 10:55:32 -08:00
Michael Gottesman
9a96403496 [silgen] Refactor prepareArchetypeCallee to use a builder class instead of iterated closures.
The way iterated closures were used to propagate around state that caused the
flow of data in the program to be confusing to read. This makes the dataflow
explicit by communicating clearly what variables are "global" to the
computation.

Beyond the refactoring this is a NFC.

rdar://29791263
2017-02-19 08:28:37 -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
6b05692d31 [silgen] Remove incorrect assumptions in ManagedValue::copy(SILGenFunction &gen, SILLocation loc).
It was wrongly assumed that no cleanup meant a type must be trivial. This is not
true for shared borrow types.
2017-02-19 08:01:45 -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
bdb4195de8 [silgen] ManagedValue::{formalEvaluationBorrow,formalAccessBorrow}()
NFC.
2017-02-19 07:58:03 -08:00
Michael Gottesman
c6b32aea2c [silgen] Add APIs for creating managed buffers and managed rvalues in a FormalEvaluation context.
Eventually I want to move all of these emit* APIs to SILGenBuilder and make them
private details of SILGenBuilder. But that is a refactoring for another time.

rdar://29791263
2017-02-19 01:41:47 -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
03a926b256 [silgen] When emitting lvalue gets into temporaries, cleanup the temporaries as early as possible.
Previously, we were emitting these cleanups at the end of the lexical scope
instead of at the end of the formal evaluation scope. This change ensures that
we always emit the cleanup immediately at the end of the formal evaluation
scope.

Previously in most cases we got away with this due to the +0 self
hack. Basically we would emit a get for a self parameter and then immediately
use that self parameter as a guaranteed parameter. Then the hack would insert
the destroy value forwarding the lexical scope level cleanup at the same time.

rdar://29791263
2017-02-17 23:26:13 -08:00
Michael Gottesman
503a2c558b [silgen] Add a FormalEvaluationScope when calling an addressor accessor in preparation for MaterializeForSet.
This ensures that any formal access cleanups associated with the base of the
addressor call are properly emitted right after the call.

rdar://29791263
2017-02-17 23:19:16 -08:00
Michael Gottesman
c345f417c9 [silgen] Add CleanupManager::dump(CleanupHandle) to ease debugging.
We already have CleanupManager::dump() that dumps the entire cleanup
stack. Sometimes though when debugging you want to dump a specific cleanup. This
API provides such functionality.
2017-02-17 23:19:16 -08:00
Michael Gottesman
fdcc5ad899 [gardening] Eliminate an unneeded closure. 2017-02-17 22:49:29 -08:00
Michael Gottesman
99f61ca94b [gardening] Fix doxygen file header in lib/SILGen/RValue.h 2017-02-17 22:49:18 -08:00
swift-ci
be3f74e581 Merge pull request #7584 from gottesmm/fix_silgenbuilder_names 2017-02-17 20:13:38 -08:00
swift-ci
c5bd8abc16 Merge pull request #7583 from gottesmm/formal_access_rename 2017-02-17 20:06:19 -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
78a514cdb1 [silgen] Use the name FormalAccess to refer to state related to accesses in a single formal evaluation context. 2017-02-17 19:19:35 -08:00
Joe Groff
6752266798 Merge pull request #7534 from jckarter/covariant-self-init-delegation
Sema: Type-check initializer delegation as a covariant expression.
2017-02-17 17:32:03 -08:00
Joe Shajrawi
b5bb43cc3f Merge pull request #7573 from shajrawi/for_each_result_plan
Opaque values: fix a bug in ResultPlanBuilder + support for-each loops
2017-02-17 15:20:55 -08:00
Joe Shajrawi
935a54bace Opaque values: fix a bug in ResultPlanBuilder + support for-each loops 2017-02-17 14:50:15 -08:00
Doug Gregor
da39d9b17b [GenericSig Builder] Rework RequirementSource to describe requirement path.
Reimplement the RequirementSource class, which captures how
a particular requirement is satisfied by a generic signature. The
primary goal of this rework is to keep the complete path one follows
in a generic signature to get from some explicit requirement in the
generic signature to some derived requirement or type, e.g.,

1) Start at an explicit requirement "C: Collection"
2) Go to the inherited protocol Sequence,
3) Get the "Iterator" associated type
4) Get its conformance to "IteratorProtocol"
5) Get the "Element" associated type

We don't currently capture all of the information we want in the path,
but the basic structure is there, and should also allow us to capture
more source-location information, find the "optimal" path, etc. There are
are a number of potential uses:

* IRGen could eventually use this to dig out the witness tables and
  type metadata it needs, instead of using its own fulfillment
  strategy
* SubstitutionMap could use this to lookup conformances, rather than
  it's egregious hacks
* The canonical generic signature builder could use this to lookup
  conformances as needed, e.g., for the recursive-conformances case.

... and probably more simplifications, once we get this right.
2017-02-17 13:50:51 -08:00
Joe Shajrawi
831769b446 Opaques: initialize optionals by-value under new opaque value mode 2017-02-17 11:06:48 -08:00
Joe Shajrawi
8fff9095de Opaque values: avoid some temporary allocations / fix a bug that caused returning a pointer to opaque values 2017-02-16 16:47:08 -08:00
Joe Groff
8fc40ba578 SILGen: Use unchecked_ref_cast to adjust covariant returns in thunks.
Previously, we would blindly upcast, leading to SIL verifier errors. Fixes SR-3920.
2017-02-16 13:31:06 -08:00
swift-ci
cca3398543 Merge pull request #7517 from gottesmm/revert_cmake_changes 2017-02-15 23:51:44 -08:00
Joe Shajrawi
9178030d92 Merge pull request #7514 from shajrawi/store_opaque_values
support stores of non-loadable types under opaque mode
2017-02-15 23:32:48 -08:00
Michael Gottesman
8437819b5a [CMake] Revert recent changes.
These changes caused a number of issues:

1. No debug info is emitted when a release-debug info compiler is built.
2. OS X deployment target specification is broken.
3. Swift options were broken without any attempt any recreating that
functionality. The specific option in question is --force-optimized-typechecker.

Such refactorings should be done in a fashion that does not break existing
users and use cases.

This reverts commit e6ce2ff388.
This reverts commit e8645f3750.
This reverts commit 89b038ea7e.
This reverts commit 497cac64d9.
This reverts commit 953ad094da.
This reverts commit e096d1c033.

rdar://30549345
2017-02-15 22:26:06 -08:00