Commit Graph

246 Commits

Author SHA1 Message Date
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
taylorswift
87a6ba21a4 Merge remote-tracking branch 'upstream/master' into comparable-enums 2019-09-19 19:32:58 -05:00
taylorswift
c915fb6fc3 support associated values 2019-09-18 20:08:21 -05:00
taylorswift
08aa01f9aa fix compiler crash 2019-09-18 18:46:16 -05: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
taylorswift
210ec69a1b comparable enums 2019-09-01 13:41:16 -05: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
Karoy Lorentey
624135641d Merge pull request #21057 from lorentey/actually-deprecate-hashValue
[Sema] Emit a deprecation warning if a Hashable type only implements hashValue
2018-12-19 22:47:16 +00:00
Slava Pestov
6f243d4ab3 AST: Plumb a 'context' parameter through to AbstractFunctionBody's body synthesizer 2018-12-07 17:10:08 -05:00
Karoy Lorentey
e0495a7e0b [Sema] Emit a deprecation warning when hashValue is provided by hash(into:) isn’t
SE-206 deprecated hashValue as a protocol requirement. We should gently encourage people to migrate to hash(into:), for its more secure, easier and faster hashing.

Emit a compiler warning whenever hashValue has an explicit implementation, but hash(into:) doesn’t.
2018-12-05 18:01:20 +00:00
Slava Pestov
c7338d06ca AST: Remove owning addressors 2018-11-09 20:49:44 -05:00
Harlan
eb75ad80dc [AST] Remove stored TypeLoc from TypedPattern (#19175)
* [AST] Remove stored TypeLoc from TypedPattern

TypedPattern was only using this TypeLoc as a means to a TypeRepr, which
caused it to store the pattern type twice (through the superclass and through
the TypeLoc itself.)

This also fixes a bug where deserializing a TypedPattern doesn't store
the type correctly and generally cleans up TypedPattern initialization.

Resolves rdar://44144435

* Address review comments
2018-09-07 21:14:04 -07:00
Slava Pestov
c360c82850 AST: Automatically create the 'self' parameter when needed
Parsed declarations would create an untyped 'self' parameter;
synthesized, imported and deserialized declarations would get a
typed one.

In reality the type, if any, depends completely on the properties
of the function in question, so we can just lazily create the
'self' parameter when needed.

If the function already has a type, we give it a type right there;
otherwise, we check if a 'self' was already created when we
compute a function's type and set the type of 'self' then.
2018-08-25 10:44:55 -07:00