Commit Graph

465 Commits

Author SHA1 Message Date
Slava Pestov
2eb31facf7 Sema: Don't overwrite parameter types in createDesignatedInitOverride() 2019-08-13 19:34:46 -04:00
Slava Pestov
9dd835c71b Sema: Replace the finalizeDecl() mechanism with ClassDecl::getEmittedMembers()
The only thing remaining in finalizeDecl() is synthesis of
certain class members. Let's turn that into a request.
2019-08-09 19:08:47 -04:00
Slava Pestov
c3b6fd1d55 Sema: Move constructor synthesis code from TypeCheckDecl.cpp to CodeSynthesis.cpp
This was split between the two files; consolidate it in CodeSynthesis.cpp.
2019-08-06 21:36:08 -04:00
Slava Pestov
18ddb959f2 Sema: Move some code to a new file TypeCheckStorage.cpp 2019-08-06 21:20:26 -04:00
Slava Pestov
a4bb3101ea Sema: Remove addExpectedOpaqueAccessorsToStorage() 2019-08-06 16:30:13 -04:00
Slava Pestov
2be7573aa0 Sema: Remove synthesizeWitnessAccessorsForStorage()
We can lazily synthesize accessor witnesses from SILGen now.
2019-08-02 19:34:43 -04:00
Slava Pestov
0c5d52d860 AST: Introduce AbstractStorageDecl::get{Parsed,Opaque}Accessor()
Also, change visitOpaqueAccessors() to call getOpaqueAccessor() instead of
asserting if the expected accessor does not exist.
2019-08-02 19:34:43 -04:00
Slava Pestov
64c32c695b AST: Remove a few utility methods from AbstractStorageDecl
Since the return value of getAccessor() depends on mutable state, it
does not make sense in the request evaluator world. Let's begin by
removing some utility methods derived from getAccessor(), replacing
calls to them with calls to getAccessor().
2019-08-01 18:31:58 -04:00
Slava Pestov
c68cf85061 Sema: Cope with stored properties that haven't been validated yet 2019-07-31 21:22:22 -04:00
Slava Pestov
28d1466577 Sema: Add request to synthesize opaque accessors
For now, this just serves to clean up some code; we still eagerly trigger
synthesis in the same places as before.
2019-07-31 14:54:57 -04:00
Slava Pestov
41bb473acd Sema: Refactor away triggerAccessorSynthesis()
This function was called on storage in primary files only. The only
remaining difference between this and addExpectedOpaqueAcessorsToStorage()
was setting the body synthesizer callback, but that's cheap so just do it
unconditionally when we synthesize an accessor.
2019-07-31 14:54:57 -04:00
Slava Pestov
e41760e44f Sema: Add request to compute if an AccessorDecl is transparent
Implicit accessors are sometimes transparent for performance reasons.
Previously this was done in Sema by maybeMarkTransparent(), which would
add a TransparentAttr. Replace this with a request.
2019-07-31 14:54:57 -04:00
Slava Pestov
37f0d6a613 Sema: Refactor away maybeAddAccessorsToStorage()
This centralizes the decision to add or not to add accessors in one place.
2019-07-31 14:54:57 -04:00
Slava Pestov
714f14603e Sema: Add request to compute if an AbstractStorageDecl requires an opaque modify coroutine 2019-07-31 14:54:57 -04:00
Slava Pestov
6922d976fd Sema: Add request to compute if an AbstractStorageDecl requires opaque accessors 2019-07-31 14:54:57 -04:00
Joe Groff
4db3938f78 Merge pull request #26408 from davezarzycki/simplify_code_synth_diag
[CodeSynth] NFC: Simplify diagnostic output
2019-07-31 08:26:34 -07:00
Slava Pestov
1ee2db4520 AST: Accessors no longer appear as members of their parent DeclContext
Accessors logically belong to their storage and can be synthesized
on the fly, so removing them from the members list eliminates one
source of mutability (but doesn't eliminate it; there are also
witnesses for derived conformances, and implicit constructors).

Since a few ASTWalker implementations break in non-trivial ways when
the traversal is changed to visit accessors as children of the storage
rather than peers, I hacked up the ASTWalker to optionally preserve
the old traversal order for now. This is ugly and needs to be cleaned up,
but I want to avoid breaking _too_ much with this commit.
2019-07-30 15:56:00 -04:00
Arnold Schwaighofer
090b740550 Sema: Don't mark the accessors of the storage wrapper transparent if its
backing var has lower visibility than the var

rdar://53574404
2019-07-30 09:28:03 -07:00
David Zarzycki
2734fe55cc [CodeSynth] NFC: Simplify diagnostic output 2019-07-30 11:40:46 +01:00
Joe Groff
61261fcddf Merge pull request #26326 from jckarter/property-wrapper-composition-mutatiness
Sema: Correct composition of property wrappers.
2019-07-27 10:16:44 -07:00
Joe Groff
fa4dd15612 Sema: Correct composition of property wrappers.
Fixes rdar://problem/53407949 | SR-11138. Previously, we'd only look at the outermost property wrapper to decide whether the wrapped property's getter and setter were `mutating` (or exist at all). In reality, this requires considering the semantics of the composed accesses of each wrapper layer's
`wrappedValue` property. Fixing this systematically addresses a number of issues:

- As SR-11138 reported, composing a nonmutating-get-set wrapper ought to produce a composed wrapper
  that's nonmutating.

- We would previously allow a property wrapper with a mutating getter to be nested inside one with
  only a getter, even though the resulting implementation was unsound (because there's no mutable
  context for the inner wrapper to execute its get on.)

- Similarly, we would construct unsound setters in cases where the setter can't exist, such as when
  the nested wrapper isn't settable but the outer wrapper is.
2019-07-26 16:09:54 -07:00
Joe Groff
0c13a4b759 Check default init before synthesizing wrapper backing properties.
Fixes a regression where the compiler would reject something like:

  @State var x: Int?

as not having an initializer, even though an Int? property ought to default to nil.
rdar://problem/53504653
2019-07-25 15:17:03 -07:00
Slava Pestov
3e45b327de Parse: Remove some bogus error recovery code for 'lazy' 2019-07-23 22:00:31 -04:00
Slava Pestov
8047ddae82 Sema: Move finishStorageImplInfo() to StorageImplInfoRequest evaluation
This merges Sema's special logic for updating the ImplInfo of lazy properties
and property wrappers with the StorageImplInfoRequest.

I had to move some code from the parser into the StorageImplInfoRequest, to
avoid request cycles caused by hasStorage() calls; this is the right thing to
do anyway.

Since hasStorage() now answers false for lazy properties and property wrappers,
we have to move some diagnostic checks from checkDeclAttributesEarly() to
the StorageImplInfoRequest implementation itself.

Over time, I expect all of the checks currently in checkDeclAttributesEarly()
and checkDeclAttributes() to either migrate to requests, or typeCheckDecl().
2019-07-23 22:00:31 -04:00
Slava Pestov
60e1dfe8b9 Sema: Use a request to compute AbstractStorageDecl::getImplInfo()
This just moves the code from the parser into a request. Sema will
still overwrite the ImplInfo field for lazy properties and
property wrappers; refactoring that is next.
2019-07-23 16:13:28 -04:00
Slava Pestov
ac9a3bf34a Sema: Add counters for synthesized accessors 2019-07-23 16:13:28 -04:00
Slava Pestov
454281b226 AST: Split off StorageImplInfo from AbstractStorageDecl::AccessorRecord
We want to compute the former independently of the latter.
It's only 16 bits so storing it inside the Decl is fine;
it also allows us to eliminate the 'compact' representation
where an AbstractStorageDecl without an accessor record is
assumed to be stored.
2019-07-22 20:19:09 -04:00
Slava Pestov
a532a325e1 AST: Move a few methods from VarDecl down to ParamDecl 2019-07-22 20:19:09 -04:00
Slava Pestov
4fa48473bc Sema: Stop finalizing struct and enum members
Since getStoredProperties() is a request that lowers lazy properties
and property wrappers to their underlying storage, and SIL can validate
stored property and enum element types, there's no longer any need for
Sema to explicitly finalize members of structs and enums. SILGen can
trigger any necessary type checkin work just by lowering a struct or
enum type.

Now the only remaining reason we need finalizeDecl() is adding implicit
methods to classes, and synthesizing accessors for storage in classes
and protocols.
2019-07-17 18:07:03 -04:00
Slava Pestov
d0240cc22d Sema: Simplify finalizeType() by using getStoredProperties()
Continue gutting finalizeType() by using our new request to
synthesize the backing storage for lazy properties and
property wrappers.
2019-07-16 16:38:39 -04:00
Slava Pestov
b0e18e81ac Sema: Simplify synthesizeWitnessAccessorsForStorage() 2019-07-16 16:38:38 -04:00
Slava Pestov
8b287f20fa Sema: Refactor maybeAddAccessorsToStorage()
The idea here is to split up the logic into three parts:

- computation of the final ImplInfo for lazy, property wrappers
  and @NSManaged

- deciding if we should add accessors or not

- actually adding the accessors
2019-07-16 14:24:35 -04:00
Doug Gregor
690409d04f Merge pull request #26105 from DougGregor/more-lazy-body-synthesis
More lazy body synthesis
2019-07-12 10:07:54 -07:00
Doug Gregor
8117849d46 [AST] Make function body synthesizers less stateful.
Instead of requiring that function body synthesizers will always call
setBody(), which is annoyingly stateful, have function body synthesizers
always return the synthesized brace statement along with a bit that
indicates whether the body was already type-checked. This takes us a
step closer to centralizing the mutation of the body of a function.
2019-07-11 21:31:21 -07:00
Slava Pestov
ecc9e32f13 Sema: Remove validateAbstractStorageDecl()
Validating a variable or subscript no longer forces accessor synthesis.
2019-07-11 20:55:42 -04:00
Slava Pestov
15a831614e Sema: Remove finalizeAbstractStorageDecl()
Also since we're lazier about validating accessors now, relax some
checks in the ASTVerifier so that it can tolerate implicit accessors
without interface types. All other declarations must still have
interface types in verifyChecked().

ASTVerifier: Tolerate implicit accessors without interface types
2019-07-11 20:55:42 -04:00
Doug Gregor
ee52e7317c [SE-0258] Don't ask for the nominal type decl of an unresolved property wrapper
Generic type aliases break this query; don't use it.
Fixes rdar://problem/51989272
2019-07-09 16:36:19 -07:00
Doug Gregor
a66a5ff0a4 [SE-0258] Properly contextualize closures in property wrapper initialization.
Fixes SR-11061 / rdar://problem/52593304 / rdar://problem/52220881.
2019-07-08 16:39:49 -07:00
Doug Gregor
bc2e605b31 [Property wrappers] Improve enclosing-self subscript handling.
Extend handling of enclosing-self subscripts by differentiating
between the original wrapped property (which now goes through
`subscript(_enclosingInstance:wrapped:storage:)`) and the projected
property (which goes through
`subscript(_enclosingInstance:projected:storage:)`). The new middle
argument provides a key path to the property that was accessed,
allowing one to distinguish the property being updated.
2019-06-29 23:22:01 -07:00
Doug Gregor
8c54db727b [Property wrappers] Prototype support for enclosing self-based access
Allow property wrapper types to support a second access pattern for
instance properties of classes. When supported, the property wrapper's
static subscript(_enclosingInstance:storage:) is provided with the
enclosing "self" and a reference-writable key path referring to the
backing storage property.

Implements rdar://problem/52222560.
2019-06-29 00:08:49 -07:00
Doug Gregor
ef17b38106 [SE-0258] Trigger synthesis of _foo/$foo from name lookup.
Fix a bug with cross-file uses of the synthesized _foo/$foo for
properties with attached wrappers by implicitly triggering the
appropriate synthesis during name lookup.

Fixes rdar://problem/51725203.
2019-06-27 00:08:31 -07:00
Doug Gregor
db5440bdef [SE-0258] Rename wrapperValue to projectedValue. 2019-06-26 07:39:01 -07:00
Doug Gregor
7bb01c743b [SE-0258] Promote projection variables ($foo) to the original property access
When the outermost property wrapper associated with a property has a
`wrapperValue`, create the projection property (with the `$` prefix)
at the same access level as the original property. This puts the
wrapped-value interface and the projection interface at the same level.

The newly-introduced @_projectionValueProperty attribute is implicitly
created to establish the link between the original property and the
projection value within module interfaces, where both properties will
be explicitly written out.
2019-06-26 07:39:01 -07:00
Doug Gregor
446d0b3953 [SE-0258] Rename backing storage property to _foo.
In anticipation of upcoming changes to the property wrapper proposal,
rename the backing storage for a wrapped property to "foo", unconditionally.
2019-06-26 07:39:01 -07:00
Doug Gregor
22e40fedf5 [SE-0258] Enable default argument for wrapped property going through init().
My recent refactoring of default arguments for the memberwise initializer
accidentally dropped support for getting a default argument when the
attached property wrapper has an init(). Reinstate that support,
fixing rdar://problem/52116923.
2019-06-25 10:03:15 -07:00
Doug Gregor
7d0357c7b5 [Property wrappers] Validate wrappedValue before using it.
Fixes SR-10984.
2019-06-24 23:42:23 -07:00
Doug Gregor
592887cb53 [Type checker] Fix multi-file crasher for property wrapper backing storage.
Fixes rdar://problem/51810057
2019-06-24 22:35:51 -07:00
Slava Pestov
02bad9a479 Sema: Clean up lazy properties and related code 2019-06-19 22:12:55 -04:00
Slava Pestov
1e1e812768 Sema: Use a request to create lazy property backing storage 2019-06-19 22:12:55 -04:00
Slava Pestov
7913d30236 Sema: Use a request to compute FuncDecl::getSelfAccessKind() 2019-06-19 14:38:43 -04:00