Commit Graph

3461 Commits

Author SHA1 Message Date
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
Slava Pestov
66f115f3ea Merge pull request #26364 from theblixguy/fix/emit-vtable-entry-generic-mismatch
[AST] Emit vtable thunk if base method's generic requirements are not satisfied by derived
2019-07-30 19:02:18 -04:00
Slava Pestov
f0c0146801 AST: Clean up findOverridingDecl() and findImplementingMethod()
These are two slightly different operations. Make them share code and
prepare them for when we stop adding accessors to their parent
DeclContext.

Note the FIXMEs; this code could use additional attention.
2019-07-30 15:14:33 -04:00
David Ungar
d236a178ca Merge pull request #26095 from davidungar/parser-changes
[Parser] Fixes for ASTScope lookup
2019-07-29 19:59:00 -07:00
Holly Borla
fd03db42cf Merge remote-tracking branch 'upstream/master' into init-kind-request 2019-07-29 13:39:56 -07:00
Suyash Srijan
41249804d4 [AST] Make parameters 'const' in 'overrideGenericSignatureReqsSatisfied()' and 'getOverrideGenericSignature()' 2019-07-28 20:51:47 +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
Holly Borla
709efbc52c Sema: implement getInitKind using a request evaluator.
Add the request `InitKind` to lazily compute the kind of an initializer
declaration.
2019-07-26 15:55:09 -07:00
Suyash Srijan
f6d22e5ca4 [AST] Adds a new helper method to check whether a method's generic requirements are satisfied 2019-07-26 22:09:23 +01:00
Suyash Srijan
3a2ab9648a [AST] Emit vtable thunk if base method's generic requirements are not satisfied by the derived method 2019-07-26 00:20:21 +01: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
David Ungar
6577e68b6b Fixes for review 2019-07-25 07:50:39 -07:00
David Ungar
8caf6f39e1 Fixes for ASTScope lookup
1. Track real EndLoc of TypeAliasDecl and SubscriptDecl.
2. Ensure TypeAliasDecl gets added to AST when doing completion.
2019-07-25 07:50:38 -07:00
Slava Pestov
e88f0c2a9a Merge pull request #26282 from slavapestov/storage-impl-info-request
Use a request to compute AbstractStorageDecl::getImplInfo()
2019-07-23 21:12:32 -04:00
Holly Borla
10a4e3ef41 Merge pull request #26278 from hborla/existential-type-supported-request
Sema: implement `existentialTypeSupported` using a request evaluator.
2019-07-23 14:05:35 -07: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
4eec522578 Sema: Fix inheritance of @requires_stored_property_inits
Previously we would copy this attribute from a superclass to the
subclass when validating a subclass. However, this is only correct
if the superclass is always guaranteed to have been validated
before the subclass.

Indeed, it appears this assumption is no longer true, so we would
sometimes lose track of the attribute, which would result in SILGen
failing to emit the ivar initializer entry point.

Instead, check for the attribute as part of the superclass walk
in checkAncestry(), ensuring the result is always up to date, correct,
and cached.

As a follow-up, we should also convert checkAncestry() into a
request, but I'm not doing that here to keep the fix short.

Fixes <rdar://problem/50845438>.
2019-07-23 12:23:27 -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
Holly Borla
9f19597f73 Sema: implement existentialTypeSupported using a request evaluator.
Add the request `ExistentialTypeSupportedRequest` to lazily determine
if we are allowed to refer to an existential type conforming to a
protocol.
2019-07-22 15:35:10 -07:00
swift-ci
05d2ef22b8 Merge pull request #26246 from DougGregor/property-wrapper-crash-fixes 2019-07-19 16:21:35 -07:00
Doug Gregor
118a557304 [SE-0258] Check for a NULL type.
Within invalid code, we might encounter expressions without type
information yet. Check for NULL here.

Fixes crash from rdar://problem/53120878.
2019-07-19 10:26:26 -07:00
Doug Gregor
0df29877ed [SE-0258] Fix source locations for implicitly-generated initializer calls.
Fixes rdar://problem/52969503, a crash due to missing source location
information in implicitly-generated calls.
2019-07-19 10:15:28 -07:00
Holly Borla
2225cb2f41 Sema: implement existentialConformsToSelf using a request evaluator.
Add the request `ExistentialConformsToSelfRequest` to lazily determine
if an existential conforming to a protocol can be matched with a
generic type parameter constrained to that protocol.
2019-07-18 17:06:16 -07:00
Holly Borla
71fb2629ac Sema: implement requiresClass using a request evaluator.
Add the request `ProtocolRequiresClassRequest` to lazily determine if a
`ProtocolDecl` requires conforming types to be a class.

Note that using the request evaluator to compute `requiresClass` introduces
cycle errors for protocol declarations, where this computation didn't
previously emit diagnostics. For now, we'll allow duplicate diagnostics in this
case, with the eventual goal of removing explicitly checking for cycles
via `checkCircularity` (instead letting the request evaluator handle cycle
diagnostics).
2019-07-17 16:04:24 -07:00
Slava Pestov
56515ee871 Merge pull request #26119 from slavapestov/stored-properties-request
Re-implement NominalTypeDecl::getStoredProperties() using request evaluator
2019-07-17 09:12:47 -04:00
Joe Groff
ccc70b7442 Merge pull request #26097 from jckarter/opaque-type-redeclaration-collision
Don't allow overloading by opaque types with different constraints.
2019-07-16 20:28:35 -07:00
Slava Pestov
83c90b6b2a AST: Turn NominalTypeDecl::getStoredProperties() into a request
This improves on the previous situation:

- The request ensures that the backing storage for lazy properties
  and property wrappers gets synthesized first; previously it was
  only somewhat guaranteed by callers.

- Instead of returning a range this just returns an ArrayRef,
  which simplifies clients.

- Indexing into the ArrayRef is O(1), which addresses some FIXMEs
  in the SIL optimizer.
2019-07-16 16:38:38 -04:00
Slava Pestov
25e4ca9a60 AST: Simplify Optional default initialization behavior 2019-07-16 14:26:54 -04:00
Slava Pestov
96f1b95901 AST: requiresNewVTableEntry() validates the declarations if needed 2019-07-16 14:26:54 -04:00
Slava Pestov
ffb3ec2114 AST: Remove skipInaccessible argument from NominalTypeDecl::getStoredProperties() 2019-07-16 14:26:54 -04:00
Doug Gregor
5ee4b06edb [Type checker] Lazily synthesize body of default constructors. 2019-07-12 14:39:05 -07:00
Doug Gregor
c13872248d [Type checker] Lazily synthesize the empty implicit destructor of a class.
This is more a matter of principle than an optimization, eliminating
unnecessary calls to `AbstractFunctionDecl::setBody()`.
2019-07-12 10:41:48 -07: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
Doug Gregor
015b7c5266 [AST] Use AbstractFunctionDecl::getBodySourceRange() more frequently.
A number of callers to AbstractFunctionDecl::getBody() were only
extracting the source range of the body... which can be retrieved more
efficiently with getBodySourceRange().
2019-07-11 21:31:21 -07:00
Slava Pestov
7786ac8c01 Sema: Move forcing of certain requests from finalizeDecl() to typeCheckDecl()
finalizeDecl() would kick off certain requests. This was necessary
before we had the long-lived type checker to ensure that requests
that required a type checker could be completed in time for SILGen.

It was also necessary to always emit diagnostics for declarations in
primary files.

Since we now have a long lived type checker, the first reason is no
longer valid, so we can move this work from finalizeDecl() to
typeCheckDecl(), where it will run for declarations in primary files
only.

To ensure that @objc selector conflict diagnostics still get emitted,
we also walk the superclass chain and force isObjC() to be computed
for each declaration in each superclass.
2019-07-11 20:55:42 -04:00
Joe Groff
a92fd9defb Don't allow overloading by opaque types with different constraints.
The mangling unfortunately doesn't take the constraints into account, leading to
SR-10725 | rdar://problem/50987172. Changing the mangling at this point is hazardous, so it's probably best
to disallow this for now.
2019-07-11 15:15:24 -07:00
swift-ci
44f85d2090 Merge pull request #26080 from DougGregor/request-evaluator-simpler-cycle 2019-07-10 18:52:40 -07:00
Doug Gregor
052068edb8 [Request-evaluator] Provide defaults for diagnoseCycle/noteCycleStep.
Introduce some template metaprogramming infrastructure to retrieve the
"nearest" source location to the inputs of a request, and use that to
provide default diagnoseCycle and noteCycleStep implementations. This
will help remove a bunch of boilerplate from new requests.
2019-07-10 17:25:51 -07:00
Doug Gregor
9a444242fb [SE-0258] Fixups for various renames of property wrappers. 2019-07-10 15:28:24 -07:00
Doug Gregor
1284878ad8 [SE-0258] Rename init(initialValue:) --> init(wrappedValue:).
Addresses core team decision on acceptance of property wrappers.

Fixes rdar://problem/48871069.
2019-07-10 14:26:53 -07:00
Slava Pestov
4c499fd4ac AST: Stop passing around LazyResolvers in various places 2019-07-06 00:43:22 -04:00
John McCall
faa3e3483f Support opaque result types when applying a function builder to a func. 2019-07-01 17:42:06 -04:00
Jordan Rose
cb6d47ef24 Show 'some' type origins in diagnostics, like 'aka' for sugared types (#25624)
Currently only works for types that are /just/ a 'some' type, not in a
nested position. Also won't show them for opaque types with different
requirements, to avoid noise when it's not strictly necessary. This
does mean that 'some P' vs. 'some P & Q' won't get the origin part.

Part of rdar://problem/50346954
2019-06-28 20:42:47 -07:00
Pavel Yaskevich
e6775a921e Merge pull request #25869 from xedin/access-member-on-wrapper-type-diagnostic
[Diagnostics] Add property wrapper diagnostic for unnecessary $/'_' in member acces
2019-06-28 17:43:01 -07:00
Jordan Rose
02e1a11e35 [Index] Don't index non-public imported declarations (#25865)
Apart from mildly speeding up indexing, this also keeps the compiler
from running into issues with implementation-only imports that may not
be present while we're trying to index.

rdar://problem/52083709
2019-06-28 16:57:29 -07:00