Commit Graph

2036 Commits

Author SHA1 Message Date
Marc Rasi
6e559ab8fa rename nondiff => noDerivative 2019-11-15 16:36:26 -08:00
Marc Rasi
f5677cbe42 add @nondiff to AnyFunctionType params 2019-11-14 16:49:22 -08:00
Hamish Knight
1be22c5d48 [Sema] Requestify default argument type checking (#27756)
[Sema] Requestify default argument type checking
2019-11-14 14:09:03 -08:00
Hamish Knight
3c05acac15 Address review feedback
Rename getDefaultArgumentInitContextCached,
and have it return an Optional<Initializer *>.
2019-11-14 12:51:04 -08:00
Hamish Knight
cd3ada5abb getInterfaceType() always returns a type (#28210)
getInterfaceType() always returns a type
2019-11-12 13:24:05 -08:00
Hamish Knight
ed77b86c24 getInterfaceType() always returns a type 2019-11-12 07:50:29 -08:00
Slava Pestov
317c0317d4 AST: Cope with invalid inputs better in ExtensionDecl::isConstrainedExtension() 2019-11-11 23:04:09 -05:00
Hamish Knight
01d5c00f9b [Sema] Requestify default arg type checking
This commit introduces a request to type-check a
default argument expression and splits
`getDefaultValue` into 2 accessors:

- `getStructuralDefaultExpr` which retrieves the
potentially un-type-checked default argument
expression.

- `getTypeCheckedDefaultExpr` which retrieves a
fully type-checked default argument expression.

In addition, this commit adds `hasDefaultExpr`,
which allows checking for a default expr without
kicking off a request.
2019-11-11 13:49:06 -08:00
Hamish Knight
7ae3d1f8d3 Requestify default initializer context creation
This commit adds a request that computes
the initializer context for a parameter with a
default expr or stored property default.

This avoids having to compute them for synthesized
decls and is a step towards requestifying default
argument parsing.
2019-11-11 13:49:06 -08:00
Hamish Knight
4d216c7052 [AST] Add swift::getParameterList 2019-11-11 13:49:05 -08:00
Hamish Knight
eacca4ed0c Requestify circular inheritance checking
Add requests for checking whether a class,
protocol, or enum have circular references in
their inheritance lists.
2019-11-11 09:34:56 -08:00
Robert Widmann
dd1b15775d Partially Revert #27862
When SE-110 was being implemented, we accidentally began to accept
closure parameter declarations that had no associated parameter names,
e.g.

foo { ([Int]) in /**/ }

This syntax has never been sanctioned by any version of Swift and should
be banned.  However, the change was made long enough ago and there are
enough clients relying on this, that we cannot accept the source break
at the moment.  For now, add a bit to ParamDecl that marks a parameter
as destructured, and back out setting the invalid bit on the type repr
for these kinds of declarations.

To prevent further spread of this syntax, stub in a warning that offers
to insert an anonymous parameter.

Resolves part of rdar://56673657 and improves QoI for errors like
rdar://56911630
2019-11-10 22:10:53 -08:00
Suyash Srijan
a2d0bf6f9c [PropertyWrappers] When finding the initial value for the property, properly handle the situation where we have multiple attached property wrappers
If a property has multiple property wrappers attached, we'll have multiple nested calls, where each call's argument is a call to construct the next wrapper in the chain. However, when we use multiple wrappers consecutively, we cannot just rely on the call's type matching the innermost wrapper's type, because it will match the first wrapper in the sequence of consective wrappers and we'll end up crashing in SILGen. So, we should check if the call's argument is another call and look into that before checking the types.
2019-11-07 21:27:52 +00:00
Robert Widmann
2b08d1b834 [NFC] ASTContext::getLazyResolver -> ASTContext::getLegacyGlobalTypeChecker 2019-11-05 14:44:41 -08:00
Robert Widmann
a01a6bb01a Remove an erroneous early-exit 2019-11-05 10:29:38 -08:00
Robert Widmann
d4906ac10b Rationalize Implicit Member Synthesis Somewhat
Codable's deep magic currently forces conformance checks in the middle
of name lookup in order to inject CodingKeys into lookup results.  This
is compounded by the fact that this lookup fixup is occuring
incrementally, meaning depending on order of requirements being looked
up, Decl::getMembers() will give you a different answer.

Compounding this, NameLookup relied on the LazyResolver to formalize
this layering violation, and relied on implicit laziness to guard
against re-entrancy.

The approach is multi-pronged:
1) Shift the layering violation into the request evaluator
2) Spell out the kinds of resolution we support explicitly (make them
easier to find and kill)
3) Remove the LazyResolver entrypoint this was relying on
4) Split off the property wrappers part into its own utility
2019-11-05 09:10:13 -08:00
Hamish Knight
40231991ae [Sema] Diagnose unsound pointer conversions (#27695)
[Sema] Diagnose unsound pointer conversions
2019-11-04 17:18:57 -08:00
Slava Pestov
dad642c9da Merge pull request #28040 from slavapestov/dont-force-the-issue
Don't unnecessarily force InterfaceTypeRequest
2019-11-04 18:27:30 -05:00
Slava Pestov
3b7a0b24f5 AST: Remove some unnecessary (void) getInterfaceType() calls 2019-11-04 14:59:01 -05:00
Robert Widmann
3b8f3b53be Remove a double-checked invariant
Now that isInvalid() is a semantic property, drop the assertion for this
invariant in the ASTVerifier.  This should also remove the last client
that wasn't registering the lazy resolver and expecting to pull any old
interface type out, so change a hack to an assertion to hopefully catch
future callers before we remove the LazyResolver entirely.
2019-11-04 11:44:11 -08:00
Hamish Knight
92c42ec791 [AST] Add @_nonEphemeral parameter attribute
This non-user-facing attribute is used to denote pointer parameters
which do not accept pointers produced from temporary pointer conversions
such as array-to-pointer, string-to-pointer, and in some cases
inout-to-pointer.
2019-11-03 08:40:59 -08:00
Slava Pestov
35cc303c78 AST: Be more careful about calls to ErrorType::get()
It's nice to be able to set a breakpoint on this method when
debugging the type checker, but recently we started unconditionally
calling it to get the circularity sentinel before kicking off a
request.

Instead, let's only call it when we're in the failure path.
2019-11-01 18:55:16 -04:00
Robert Widmann
8a69f886ad Merge pull request #27955 from AnthonyLatsis/bracestmt_cleanup
NFC: Solidify and tidy up the BraceStmt interface
2019-10-31 13:48:40 -07:00
Hamish Knight
16cff49e65 [Sema] Requestify inheritsSuperclassInitializers (#27936)
* [Sema] Factor out shouldAttemptInitializerSynthesis

This makes sure we don't attempt to synthesize
a memberwise or default initializer for an invalid
decl, or one in a module interface.

* [Sema] Requesify inheritsSuperclassInitializers

This commit introduces a request for computing
whether a class inherits both designated and
convenience initializers from its superclass.

The shared logic of finding initializers which the
subclass hasn't overriden has been factored out
into `collectNonOveriddenSuperclassInits`.

* Cleanup addImplicitInheritedConstructorsToClass

This commit removes some code that's no longer
needed. In addition, now that we've requestified
`inheritsSuperclassInitializers`, we can directly
diagnose on non-inherited required convenience
inits within the loop.

* Inherited init synthesis no longer deals with clang decls

Now that the computation of
`inheritsSuperclassInitializers` has been split off
into a request, we can avoid calling
`addImplicitInheritedConstructorsToClass` for clang
decls.

* Address review feedback

Continue to cache the InheritsSuperclassInits bit
on the AST.
2019-10-31 11:07:06 -07:00
Robert Widmann
4996858c4d Re-implement isInvalid for ValueDecls 2019-10-30 15:09:14 -07:00
Anthony Latsis
6325915b4b NFC: Solidify and tidy up the BraceStmt interface 2019-10-30 16:43:59 +03:00
Hamish Knight
961c16a2cc [Sema] Requestify default init synthesis
This commit adds two requests, one to compute
whether or not a decl should have a default
initializer, and another to synthesize it.

This then allows us to remove the default constructor
synthesis from addImplicitConstructorsToClass as
well as completely eliminate addImplicitConstructorsToStruct.
For now, we can just force the requests in
addImplicitConstructors.
2019-10-25 11:23:28 -07:00
Hamish Knight
ffd5a9cfd6 [Sema] Requestify memberwise init synthesis
This commit adds two requests, one to compute
whether or not a decl should have a memberwise
initializer, and another to synthesize it.
2019-10-25 11:20:39 -07:00
Robert Widmann
497a2227ba [NFC] Remove AbstractFunctionDecl::computeType()
Its functionality is entirely subsumed by InterfaceTypeRequest.
2019-10-21 12:15:50 -07:00
Robert Widmann
48b8ba3614 Remove DeclValidationRAII
The last real client was precedence group validation.
2019-10-18 11:19:58 -07:00
Robert Widmann
6bb0e49eab Move precedence group cycle checking into requests
Use the request evaluator to get the easier in-module precedence group cycles.   Unfortunately, cross-module precedence group cycles are still a possibility, and do not actually cause cyclic request evaluation, so we cannot completely erase the old diagnostics machinery.

Move the machinery itself into the type checker and shift the request into that zone as well to appease the linker.
2019-10-18 11:19:25 -07:00
Saleem Abdulrasool
5fe38b6e76 AST: repair Windows build after #27764
Avoid the use of the GNU extension for the collapsed ternary and use the
explicit expansion.  This should repair the Windows build.
2019-10-18 08:01:47 -07:00
Robert Widmann
464aab67ec Define InterfaceTypeRequest
The moment you've all been waiting for...

Define InterfaceTypeRequest and use it to, well, compute the interface
type.  This naturally widens the few cycles that we pick up with the
request evaluator.

There is still a lot of work to get done here, mostly around scaling
back all of the ad-hoc circularity checks around the interface type
computation.  It would also be great to improve the circularity
diagnostics.
2019-10-17 16:01:56 -07:00
Robert Widmann
3b829943af Uniformly iterate over the pattern binding entry indices
Clarify a bunch of C-style for loops and remove a ton of references to getPatternList().
2019-10-17 13:39:07 -07:00
Robert Widmann
56b6e53dae Remove raw references to PatternBindingEntry APIs
Switch most callers to explicit indices.  The exceptions lie in things that needs to manipulate the parsed output directly including the Parser and components of the ASTScope.  These are included as friend class exceptions.
2019-10-17 13:31:14 -07:00
Robert Widmann
55047cd3bb Start hiding the interface to PatternBindingEntry
Force callers to go through the pattern binding decl so we can control the API surface more effectively.
2019-10-17 13:28:28 -07:00
Robert Widmann
c849652fa2 Merge pull request #27731 from CodaFi/validate-patterns
Requestify Pattern Validation
2019-10-17 13:26:46 -07:00
Robert Widmann
69bd40cafd Replace the cycle breaker for pattern bindings 2019-10-17 10:55:13 -07:00
Robert Widmann
198601dbd4 Bitpack the transitional API 2019-10-17 09:40:45 -07:00
Robert Widmann
8c73b7db58 Define NamingPatternRequest
Use it to provide an idealized API for the VarDecl case in validateDecl.

In reality, a lot of work is needed to rationalize the dependency
structure of this request.  To start, the callers of
typeCheckPatternBinding must be eliminated piecemeal.  Once that is
done, the AST should introduce pattern binding decls along all the
places where getParentStmt() used to apply.
2019-10-17 09:40:45 -07:00
Jordan Rose
0f071e28ea Simplify getPrepositionKind to isPreposition
No one was distinguishing directional and non-directional prepositions
anymore. No functionality change.
2019-10-16 19:55:46 -07:00
Xi Ge
1698884100 AST: avoid looking up serialized locations when decl is context-free 2019-10-16 14:29:46 -07:00
Xi Ge
52e8f3da0f AST: unblock linux build by providing explicit constructor 2019-10-16 11:59:00 -07:00
Xi Ge
c8e18d4c19 AST: use a static allocated NullLocs to indicate no serialized source locations for a Decl, NFC 2019-10-15 16:48:20 -07:00
Xi Ge
c6035f68f0 AST: cache serialized source locations in Decl 2019-10-15 16:05:28 -07:00
Xi Ge
1e22e7c8aa AST: teach Decl::getLoc() to return serialized source loc.
When Decl::getLoc() is called upon a serialized AST and the
serialized source location is available, we lazily open the
external buffer and return a valid SourceLoc instance pointing
into the buffer.
2019-10-15 16:05:28 -07:00
Suyash Srijan
e18a49a2ca [AST] Remove old code in emitLetToVarNoteIfSimple() that prevented the fix-it from being applied in some cases 2019-10-15 01:35:46 +01:00
Suyash Srijan
70d77e9fe2 Revert "Revert "Merge pull request #27057 from theblixguy/unrevert/SR-11298""
This reverts commit 7725818275.
2019-10-15 01:35:46 +01:00
Robert Widmann
3bd45c8135 Merge pull request #27648 from CodaFi/unbounded-progress
Drastically Simplify VarDecl Validation
2019-10-14 16:54:57 -07:00
Robert Widmann
0082ba5abc Remove VarDecl::markInvalid
Inline the interface type reset into its callers and make sure they're
also setting the invalid bit - which this was not doing before.
Unfortunately, this is not enough to be able to simplify any part of var
decl validation.
2019-10-14 12:46:39 -07:00