Commit Graph

2036 Commits

Author SHA1 Message Date
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
Sam Lazarus
bd54febb37 Sema: Change property wrappers fixit to always remove the correct number of '$' 2019-06-28 12:09:50 -07:00
Sam Lazarus
55b17feac1 Sema: Handle storage wrappers correctly in diagnostics 2019-06-28 12:09:49 -07:00
Sam Lazarus
7054fcb270 Sema: Stop anon closure params from being diagnosed like property wrapper decls 2019-06-28 12:09:49 -07:00
Jordan Rose
995667825e Don't compute a protocol's generic environment just for its signature
A protocol's generic signature is trivial; the generic environment is
simple but not free to compute. Avoid the costs of the previous commit
by /not/ computing it if it's never asked for.
2019-06-27 14:53:13 -07:00
Jordan Rose
cce8d2fde0 [Serialization] Deserialize protocol requirement signatures lazily
Always good to do less work, and it's a stepping stone towards
recovering from trying to deserialize a protocol with missing
requirements.
2019-06-27 14:52:47 -07:00
Slava Pestov
10aa1a730d Merge pull request #25742 from slavapestov/se0068-part-2
Clean up some old DynamicSelfType debt now that we have an implementation of SE-0068
2019-06-26 09:37:31 -04:00
Slava Pestov
5826db5d56 AST: Add AbstractFunctionDecl::hasDynamicSelfResult() and use it
This calculates a result directly from the function's result type
instead of checking a bit that was previously set by the type
checker. Also, always returns true for constructors to simplify
some callers.
2019-06-26 01:10:12 -04: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
Slava Pestov
1e1e812768 Sema: Use a request to create lazy property backing storage 2019-06-19 22:12:55 -04:00
Slava Pestov
9ff34e82b0 Sema: Allow AbstractStorageDecl::overwriteImplInfo() to be called before adding any accessors 2019-06-19 22:12:55 -04:00
Slava Pestov
0ec33bfa4a Sema: Use a request to compute AbstractStorageDecl::getOpaqueReadOwnership() 2019-06-19 14:38:43 -04:00
Slava Pestov
4df9543ee8 Sema: Use a request to compute AbstractStorageDecl::is{Getter,Setter}Mutating() 2019-06-19 14:38:43 -04:00
Slava Pestov
7913d30236 Sema: Use a request to compute FuncDecl::getSelfAccessKind() 2019-06-19 14:38:43 -04:00
Slava Pestov
a1b8913edf Sema: Synthesize accessors for computed local and global properties
If a stored property has a didSet/willSet, we currently synthesize
the getter and the setter inside the parser.  I want to get rid of
the parser's code path for doing that and consolidate all accessor
synthesis here in Sema.

Note that the parser did not synthesize a modify. This is now more
explicit in the code.

Also, we have to relax an assertion since addMemberToContextIfNeeded()
now gets called on declarations in local contexts.
2019-06-18 18:35:03 -04:00
Hamish Knight
e1f8af2389 Merge remote-tracking branch 'upstream/master' into a-couple-of-tangents 2019-06-18 19:09:06 +01:00
Doug Gregor
e857852fdc [SE-0258] Rewrite findOriginalPropertyWrapperInitialValue() for composition.
Rewrite findOriginalPropertyWrapperInitialValue() to cope with composition
of property wrappers, making it more robust in the process.

Should fix rdar://problem/51576815.
2019-06-13 22:20:56 -07:00
Doug Gregor
166a6b8042 [SE-0258] Clean up some code repetition involving initialization forms. 2019-06-13 21:44:11 -07:00
Doug Gregor
82ed5e9a02 [SE-0258] Implement basic support for property wrapper composition.
When multiple property wrapper attributes are provided on a declaration,
compose them outside-in to form a composite property wrapper type. For
example,

  @A @B @C var foo = 17

will produce

  var $foo = A(initialValue: B(initialValue: C(initialValue: 17)))

and foo's getter/setter will access "foo.value.value.value".
2019-06-13 18:26:29 -07:00
Hamish Knight
a3ead02902 Merge remote-tracking branch 'upstream/master' into a-couple-of-tangents 2019-06-13 14:46:55 +01:00
swift-ci
69c05c09f2 Merge pull request #25386 from DougGregor/property-wrappers-memberwise-and-default-init 2019-06-12 12:59:12 -07:00
Doug Gregor
5244805b17 [SE-0258] Clean up memberwise initializer / default-initialization interaction
When the backing storage of a wrapped property is default-initialized via the
property wrapper type's init(), don't count that as a direct initialization
of the backing storage for the purposes of constructing the memberwise
initializer. Instead, treat this case the same as if there were no initializer,
keying the form of the memberwise initializer off the presence of
init(initialValue:).
2019-06-12 10:29:54 -07:00
John McCall
952eb9d8f9 Allow function-builder attributes on funcs and computed vars.
rdar://50150690
2019-06-11 17:34:45 -07:00
John McCall
007842261f Rework the requests for getting a parameter's function-builder type.
Turn the generic CustomAttrTypeRequest into a helper function and
introduce a FunctionBuilderTypeRequest that starts from a ParamDecl.
This has better caching characteristics and also means we only need to
do a single cache lookup in order to resolve the type in the normal path.
It also means we don't need as much parameterization in the cache.

In addition, check that the parameter has function type in the request,
not just when late-checking the attribute, and add a check that it isn't
an autoclosure.
2019-06-11 17:34:44 -07:00
John McCall
93b3320196 Make getFunctionBuilderType() return a Type. 2019-06-11 17:34:44 -07:00
John McCall
1e4f5f7750 Add @functionBuilder and check its applications to parameters. 2019-06-11 17:34:44 -07:00