Commit Graph

202 Commits

Author SHA1 Message Date
Brent Royal-Gordon
6a8598a99c [NFC] Remove DeclNameRef staging calls 2019-12-11 00:55:18 -08:00
Brent Royal-Gordon
addbe3e5ed [NFC] Thread DeclNameRef through most of the compiler
This huge commit contains as many of the mechanical changes as possible.
2019-12-11 00:55:18 -08:00
Brent Royal-Gordon
8551b32af2 [NFC] Make EnumElementPattern carry a DeclName
This has the side effect of threading compound name support through more enum pattern code, although it’s still not complete.
2019-12-11 00:45:07 -08:00
Brent Royal-Gordon
a3035eb925 [NFC] Add helpers for unresolved AST node synthesis
This change adds UnresolvedDotExpr::createImplicit() and UnresolvedDeclRefExpr::createImplicit() helpers. These calls simplify several tedious bits of code synthesis that would otherwise become even more tedious with DeclNameRef in the picture.
2019-12-11 00:45:07 -08:00
Robert Widmann
7c46df68c7 Merge pull request #28633 from kitaisreal/classes-equatable-hashable-synthesis-diagnostics
[Type checker]: Classes `Hashable` and `Equatable` synthesis diagnostic
2019-12-09 13:16:18 -08:00
Kita, Maksim
9963fce1f7 SR-11902: Fixed code review issues. Updated tests. 2019-12-07 15:23:31 +03:00
Kita, Maksim
30faac8124 SR-11902: Improve Error Message for Auto-synthesized Equatable Conformance on Classes
1. Added note for 'Hashable' and 'Equatable' protocol synthesis for classes.
2019-12-07 14:09:56 +03:00
Slava Pestov
2cada3bce1 Revert "Eagerly TypeCheck Synthesized Decls"
This reverts commit cab4e9f011.
2019-11-22 17:41:34 -05:00
Robert Widmann
0775808db1 Reject invalid derived Hashable members explicitly
Hashable doesn't quite have the know-how to reject invalid derivation contexts before hand.  Give it a little help by adding a way to retrieve if a decl added to the conformance context was invalid after type checking completes.  Otherwise we'll emit "Hashable is broken".
2019-11-11 11:58:33 -08:00
Robert Widmann
2f2b8afad8 Remove the list of synthesized decls"
This used to be a lot more relevant a long time ago when typeCheckFunctionsAndExternalDecls actually did type check external functions defined in C.  Now, it serves no purpose.

The validation order change from just type checking these things eagerly doesn't seem to affect anything.
2019-11-11 11:33:59 -08:00
Slava Pestov
ae8c85ef80 Sema: Remove some unnecessary (void) getInterfaceType() calls 2019-11-04 14:59:01 -05:00
Robert Widmann
7993f2ffeb Downgrade the TypeChecker in DerivedConformance to an ASTContext 2019-10-30 12:55:42 -07:00
Robert Widmann
b849e51768 Use operator bool to claw back some readability 2019-10-29 16:56:21 -07:00
Robert Widmann
3e1a61f425 [NFC] Fold The Tri-State In Optional<ProtocolConformanceRef>
ProtocolConformanceRef already has an invalid state.  Drop all of the
uses of Optional<ProtocolConformanceRef> and just use
ProtocolConformanceRef::forInvalid() to represent it.  Mechanically
translate all of the callers and callsites to use this new
representation.
2019-10-29 16:55:56 -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
742f6b2102 Drastically Simplify VarDecl Validation
This is an amalgam of simplifications to the way VarDecls are checked
and assigned interface types.

First, remove TypeCheckPattern's ability to assign the interface and
contextual types for a given var decl.  Instead, replace it with the
notion of a "naming pattern".  This is the pattern that semantically
binds a given VarDecl into scope, and whose type will be used to compute
the interface type. Note that not all VarDecls have a naming pattern
because they may not be canonical.

Second, remove VarDecl's separate contextual type member, and force the
contextual type to be computed the way it always was: by mapping the
interface type into the parent decl context.

Third, introduce a catch-all diagnostic to properly handle the change in
the way that circularity checking occurs.  This is also motivated by
TypeCheckPattern not being principled about which parts of the AST it
chooses to invalidate, especially the parent pattern and naming patterns
for a given VarDecl.  Once VarDecls are invalidated along with their
parent patterns, a large amount of this diagnostic churn can disappear.
Unfortunately, if this isn't here, we will fail to catch a number of
obviously circular cases and fail to emit a diagnostic.
2019-10-14 12:06:50 -07:00
Slava Pestov
2e558f8c89 Merge pull request #27594 from slavapestov/circular-validation-cleanups-6
Circular validation cleanups, part 6
2019-10-12 00:59:21 -04:00
Robert Widmann
2516089cb6 Clean up the pseudo-clone-constructor for ParamDecl 2019-10-11 11:51:50 -07:00
Robert Widmann
060cbb293f [NFC] Downgrade The TypeLoc in VarDecl to a TypeRepr
TypeCheckPattern used to splat the interface type into this, and
different parts of the compiler would check one or the other.   There is
now one source of truth: The interface type.  The type repr is now just
a signal that the user has written an explicit type annotation on
a parameter.  For variables, we will eventually be able to just grab
this information from the parent pattern.
2019-10-11 11:15:51 -07:00
Slava Pestov
87cc09c02b AST: Remove some unnecessary calls to setGenericSignature() 2019-10-10 19:54:48 -04:00
Slava Pestov
3dbdc09a4e Sema: Move ParamDecl interface type computation to validateDecl()
This eliminates typeCheckParameterList() altogether.
2019-10-10 15:28:14 -04:00
Slava Pestov
d8b61ff24b Sema: Peel off typeCheckParameterList()'s specifier computation into a request
Since getSpecifier() now kicks off a request instead of always
returning what was previously set, we can't pass a ParamSpecifier
to the ParamDecl constructor anymore. Instead, callers either
call setSpecifier() if the ParamDecl is synthesized, or they
rely on the request, which can compute the specifier in three
specific cases:

- Ordinary parsed parameters get their specifier from the TypeRepr.

- The 'self' parameter's specifier is based on the self access kind.

- Accessor parameters are either the 'newValue' parameter of a
  setter, or a cloned subscript parameter.

For closure parameters with inferred types, we still end up
calling setSpecifier() twice, once to set the initial defalut
value and a second time when applying the solution in the
case that we inferred an 'inout' specifier. In practice this
should not be a big problem because expression type checking
walks the AST in a pre-determined order anyway.
2019-10-10 15:00:07 -04:00
Slava Pestov
a260d0a445 AST: getInterfaceType() returns ErrorType instead of Type() on circularity 2019-10-08 01:37:09 -04:00
Slava Pestov
6702d38d87 Sema: Remove most calls to Decl::setValidationToChecked() 2019-10-03 17:11:45 -04:00
Robert Widmann
f053f9c480 Port getInterfaceType() patterns in libSema 2019-09-23 16:49:29 -07:00
Slava Pestov
f292c1b240 AST: Remove GenericContext::setGenericEnvironment()
This was a transitional step before converting all callers to
store a generic signature instead of an environment.
2019-09-06 17:16:04 -04:00
Doug Gregor
7ca5abd71c Ensure we have type-checked _hashValue(for:) before we use it.
Otherwise, the standard library won't build ;)
2019-08-30 10:53:35 -07:00
Doug Gregor
02d6075034 [Sema] Synthesize pre-type-checked AST for == on no-associated-value enums 2019-08-29 17:27:11 -07:00
Doug Gregor
67e7ebab7e [Sema] Synthesize pre-type-checked == for uninhabited enums. 2019-08-29 16:44:39 -07:00
Doug Gregor
eb217bfa5a [Sema] Produce a type-checked AST when deriving the hashValue getter.
Should fix rdar://problem/54712316, a case where the non-type-checked
AST was getting processed by SILGen.
2019-08-29 16:27:14 -07:00
Slava Pestov
62f18a52c0 Sema: Move attribute checking to typeCheckDecl() 2019-08-20 14:47:52 -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
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
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
ffb3ec2114 AST: Remove skipInaccessible argument from NominalTypeDecl::getStoredProperties() 2019-07-16 14:26:54 -04: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
4c499fd4ac AST: Stop passing around LazyResolvers in various places 2019-07-06 00:43:22 -04:00
Slava Pestov
3491fecc04 Revert "Sema: Go back to synthesizing hashValue on _StoredBridgedNSError conformers"
This reverts commit 712927c494.
2019-06-11 14:22:48 -07:00
Slava Pestov
5d59600a53 Merge pull request #25350 from slavapestov/object-literal-expr
Convert ObjectLiteralExpr to not use tc.callWitness() or generate a SemanticExpr
2019-06-11 11:41:58 -07:00
Slava Pestov
6ee5774371 Merge pull request #25349 from slavapestov/synthesized-hashValue-abi-break
Sema: Go back to synthesizing hashValue on _StoredBridgedNSError conformers
2019-06-11 11:32:21 -07:00
Slava Pestov
c84aad8bf1 Sema: TypeChecker::conformsToProtocol() is static 2019-06-11 02:47:32 -07:00
Slava Pestov
712927c494 Sema: Go back to synthesizing hashValue on _StoredBridgedNSError conformers
Commit e0bba70 added a default implementation, however this is wrong
for non-imported types.

Instead, synthesize the body as before. Since this is one of the few
derived methods that can appear on an imported type, make sure to
build fully type-checked AST.

Fixes <rdar://problem/51322302>.
2019-06-11 02:46:10 -07:00
Owen Voorhees
e273d05460 [Sema] Add notes to explain why Equatable/Hashable conformance couldn't be synthesized
If a struct/enum cannot have Equatable/Hashable conformance automatically synthesized because a member's type is not Equatable/Hashable, add a note to the existing 'does not conform' diagnostic pointing out the type that blocked synthesis.
2019-06-08 13:02:49 -07:00
Slava Pestov
4551230a8b Sema: Remove ConformanceCheckFlags::Used 2019-05-28 22:08:31 -04:00
Slava Pestov
a08c5630c5 Sema: Tidy up conformance synthesis a little 2019-04-26 21:47:02 -04:00
Slava Pestov
a2049972ca AST: Add ModuleDecl::isResilient()
This cleans up some code. I'm keeping the ResilienceStrategy enum around
though, in case we want to use it to version the ABI in the future.
2019-03-26 18:42:59 -04:00
Michael Gottesman
b50d878f5d [parse/sema] Give all case bodies their own var decls without using those var decls for anything.
This is a step in the direction of fixing the fallthrough bug. Specifically, in
this commit I give case stmts a set of var decls for the bodies of the case
statement. I have not wired them up to anything except the var decl
list/typechecking.

rdar://47467128
2019-03-25 10:30:57 -07:00
Suyash Srijan
8928431cbe [sema] support weak/unowned variables when checking for conformance 2019-01-26 02:57:45 +00:00
Doug Gregor
c8b03fd944 [Type checker] Use Decl::diagnose() in more places
Eliminates an unnecessary dependency on the TypeChecker instance and lets us deal
with references across modules.
2019-01-02 13:55:48 -08:00