Commit Graph

1476 Commits

Author SHA1 Message Date
Frederick Kellison-Linn
1e27f26b01 [Sema] Always cache the unresolved chain base
Even when we’ve already visited the expression for constraint generation (signified by the presence of an UnresolvedMemberChainResultExpr) we should still cache the chain base.
2020-08-26 22:42:29 -04:00
Frederick Kellison-Linn
c33ad11ff6 [Sema] Apply clang-format 2020-08-26 22:42:29 -04:00
Frederick Kellison-Linn
4331e26bcd [Sema] Move UnresolvedMemberChainResultExpr creation to walkToExprPre
The old method of generating this placeholder expression caused issues when constraints had to be recursively regenerated during solving. Now, we generate UnresolvedMemberChainResultExprs in walkToExprPre, and use ASTWalker::Parent instead of ConstraintSystem::getParentExpr to find the parent of the chain tail.

This also lets us generate the chain constraints as part of the normal ConstraintGenerator visit, rather than as an extra walkToExprPost step.
2020-08-26 22:42:29 -04:00
Frederick Kellison-Linn
e0e3babcd0 [Sema] Change anchor of unresolved chain result type
Instead of creating the type variable for the unresolved member chain at the location of the last member, we now create it at the associated UnresolvedMemberChainResultExpr.

Previously, when the final element of a chain was a ForceValueExpr, the chain result type got caught up in the logic used to allow ForceValueExprs to properly infer lvalue types. By separating the result type variable from the last member of the chain, we make sure to keep that logic focused only on ForceValueExpr.
2020-08-26 22:42:29 -04:00
Frederick Kellison-Linn
f5845666e6 [AST] Introduce UnresolvedMemberChainResultExpr
Introduce a new expression type for representing the result of an unresolved member chain. Use this expression type instead of an implicit ParenExpr for giving unresolved member chain result types representation in the AST during type checking.
2020-08-26 22:42:29 -04:00
Frederick Kellison-Linn
4e9b7b20db [Sema] Inject implicit ParenExpr for unresolved member chains
In order to give unresolved member chain result types visibility in the AST, we inject an implicit ParenExpr in CSGen that lives only for the duration of type checking, and gets removed during solution application.
2020-08-26 22:42:29 -04:00
Frederick Kellison-Linn
aedde34fec [Sema] Move unresolved base tracking into CSGen
Remove the tracking of unresolved base types from the constraint system, and place it entirely within the generation phase. We have other ways of getting at the base types after generation.
2020-08-26 22:42:29 -04:00
Frederick Kellison-Linn
1069fe280f Fixup diagnostics 2020-08-26 22:42:29 -04:00
Frederick Kellison-Linn
5b5e30b6d7 Implement implicit member chains 2020-08-26 22:42:29 -04:00
Pavel Yaskevich
9bc2819317 Merge pull request #33590 from xedin/fail-on-error-if-single-stmt
[CSGen] Abort constraint generation on error only if closure part…
2020-08-24 11:21:08 -07:00
Pavel Yaskevich
94bf392e0e [CSGen] Abort constraint generation on error only if closure participates in type-check
If reference collection discovered at least `ErrorExpr` in the body
of a closure, let's fail constraint generation only if it's a
single-statement closure, decision about multi-statement closures
should be delayed until body is opened.

This helps code completion because `ErrorExpr` could belong to
a statement unrelated to a completion, so it wouldn't affect
its correctness in any way.
2020-08-21 15:37:12 -07:00
Doug Gregor
471f1ee3af [Constraint solver] Disable pattern type "optimization" involving weak types.
Fix a regression introduced by moving the type checking of closure
captures into the constraint system. The pattern-type optimization for
initializations was causing inference of a double-optional where there
shouldn't be one, manifesting in a failure involving implicitly
unwrapped optionals and `weak self` captures.

Fixes rdar://problem/67351438.
2020-08-18 20:58:39 -07:00
Holly Borla
81d87f9b5d Merge pull request #33412 from hborla/remove-default-literal-favoring
[CSGen] Remove favoring based on literals from computeFavoredTypeForExpr
2020-08-14 12:14:55 -07:00
Holly Borla
cb4782cc94 [CSGen] Remove favoring based on literals from computeFavoredTypeForExpr 2020-08-11 15:58:34 -07:00
Doug Gregor
5dd1bfea8d [Concurrency] Add support for 'async' closures.
Closurea can become 'async' in one of two ways:
* They can be explicitly marked 'async' prior to the 'in'
* They can be inferred as 'async' if they include 'await' in the body
2020-08-11 13:59:59 -07:00
Anthony Latsis
792da10925 Revert "Sema: Make type resolution for EnumElementPattern less eager" 2020-08-10 16:02:28 +03:00
Luciano Almeida
8fc778e5a7 Merge pull request #33355 from LucianoPAlmeida/SR-13262-where-needs-bool
[SR-13262][Sema] Adding contextual type purpose for where clause expression in constraint system
2020-08-07 23:18:36 -03:00
Holly Borla
9e818233f0 Merge pull request #33296 from hborla/merge-joined-literal-typevars
[ConstraintSystem] Add a type variable merging heuristic to addJoinConstraint
2020-08-07 09:07:19 -07:00
Luciano Almeida
50ac9abf96 [Sema] Adding contextual type purpose for where clause expression in constraint system 2020-08-07 09:12:21 -03:00
Holly Borla
43aafcdb8e [CSGen] Use addJoinConstraint for joining array literal element types. 2020-08-06 07:36:46 -07:00
Nathan Hawes
ef6c374516 [Sema/Index] Resolve #keyPath components so they can be indexed
Unlike \keypath expressions, only the property components of #keypath
expressions were being resolved, so index wouldn't pick up references for their
qualifying types.

Also fixes a code completion bug where it was reporting members from the Swift
rather than ObjC side of bridged types.

Resolves rdar://problem/61573935
2020-08-05 15:27:52 -07:00
Doug Gregor
6c3ad1046f [Statement checker] Always wire up case vars with bindSwitchCasePatternVars
bindSwitchCasePatternVars() was introduced as a simpler way to wire up
the "parent" links for case variables with same-named case variables
from the previous case item, and is used in the function builders code
to handle switch statements. It duplicated some logic from the
statement checker that did the same thing using a more complicated
algorithm.

Switch (ha ha) the logic in the statement checker over to using
bindSwitchCasePatternVars(), fixing a bug involving unresolved
patterns along the way, and remove the old code that incrementally
wired up the parent links. The resulting code is simpler and is
unified across the various code paths.
2020-08-04 22:34:23 -07:00
Rintaro Ishizaki
f97d68f3a7 Merge pull request #33290 from apple/revert-33245-index-key-paths
Revert "[Sema/Index] Resolve #keyPath components so they get handled by indexing, semantic highlighting, etc."
2020-08-04 15:48:09 -07:00
Anthony Latsis
78f0259bfb Merge pull request #33283 from AnthonyLatsis/type-locura-2
ASTWalker: Offload TypeLoc
2020-08-05 00:17:33 +03:00
Rintaro Ishizaki
00e4a76ef0 Revert "[Sema/Index] Resolve #keyPath components so they get handled by indexing, semantic highlighting, etc." 2020-08-04 12:51:52 -07:00
Anthony Latsis
b26310ee97 TypeLoc: Offload TypeLoc off the ASTWalker 2020-08-04 18:13:28 +03:00
Nathan Hawes
4c7cd16c3f Merge pull request #33245 from nathawes/index-key-paths
[Sema/Index] Resolve #keyPath components so they get handled by indexing, semantic highlighting, etc.
2020-08-03 10:28:48 -07:00
Anthony Latsis
337501eb7e Merge pull request #33227 from AnthonyLatsis/unbound-thinout-1
Sema: Make type resolution for EnumElementPattern less eager
2020-08-01 16:14:14 +03:00
Nathan Hawes
1d78fe1211 [Sema/Index] Resolve #keyPath components so they can be indexed
Unlike \keypath expressions, only the property components of #keypath
expressions were being resolved, so index wouldn't pick up references for their
qualifying types.

Also fixes a code completion bug where it was reporting members from the Swift
rather than ObjC side of bridged types.

Resolves rdar://problem/61573935
2020-07-31 17:11:23 -07:00
Slava Pestov
45fc0bc4db Sema: Replace some calls to getDeclaredType() with getDeclaredInterfaceType() 2020-07-31 13:39:02 -04:00
Anthony Latsis
9462de1f30 Sema: Make type resolution for EnumElementPattern less eager 2020-07-31 15:26:00 +03:00
Anthony Latsis
c2db918185 CS: Address an outdated OpenUnboundGenericType FIXME 2020-07-31 14:54:29 +03:00
Doug Gregor
f2e8a26c99 Merge pull request #33116 from DougGregor/captures-in-constraint-system
[Constraint solver] Type check captures as part of the constraint system
2020-07-25 12:37:44 -07:00
Doug Gregor
05c4cee9e2 [Constraint solver] Type check captures as part of the constraint system
Rather than type-checking captures as separate declarations during
pre-check, generate constraints and apply solutions to captures in
the same manner as other pattern bindings within a constraint
system.

Fixes SR-3186 / rdar://problem/64647232.
2020-07-25 00:20:05 -07:00
Pavel Yaskevich
182683af32 Merge pull request #33083 from xedin/rdar-50819554
[CSGen] Add a null check to prevent using invalid superclass type
2020-07-24 10:56:16 -07:00
Pavel Yaskevich
8f73ff4b68 [CSGen] Add a null check to prevent using invalid superclass type
While generating constraints for `SuperRefExpr` generator has to figure out
a type of superclass associated with a current reference. Doing so might
produce an empty type (aka `Type()`) when resolution fails, so `getSuperType`
needs to check whether type is valid before attempting to wrap it into `MetatypeType`.

Resolves: rdar://problem/50819554
2020-07-23 15:21:35 -07:00
Holly Borla
71b3ac4d81 [CSGen] Remove literal type variable tracking from LinkedTypeInfo. 2020-07-22 17:32:04 -07:00
Holly Borla
c8e9018c4d [CSGen] Don't merge type variables for literals in computeFavoredTypeForExpr 2020-07-22 14:43:05 -07:00
Holly Borla
bd03c47506 Merge pull request #33025 from hborla/repair-via-unwrap-typevar
[Property Wrappers] Fix property wrapper initialization type checking when `wrappedValue` is an optional of a generic parameter.
2020-07-22 11:54:17 -07:00
Holly Borla
3b917729dc [Property Wrappers] Always anchor the equality constraint between
the property type and wrapped value type at the wrapped VarDecl.
2020-07-21 15:23:24 -07:00
Doug Gregor
b6bac0b6b8 [Linked expression analyzer] Stop tracking anonymous closure params.
A given instance of an anonymous closure parameter will always have
the same type (or type variable). This wasn't true when the linked
expression analyzer was implemented, but it is guaranteed now.
2020-07-21 14:46:32 -07:00
Michael Gottesman
d2f986739c Merge pull request #32940 from gottesmm/pr-8414ddbc369ed5bb8c0622162de920b962426cf1
[ast] Rename VarPattern -> BindingPattern.
2020-07-18 20:47:21 -07:00
Brent Royal-Gordon
4394e92c3f Merge pull request #32700 from brentdax/magical-and-evolutionary
Revise #file changes from SE-0274
2020-07-17 01:57:23 -07:00
Michael Gottesman
092edd6621 [ast] Rename VarPattern -> BindingPattern.
VarPattern is today used to implement both 'let' and 'var' pattern bindings, so
today is already misleading. The reason why the name Var was chosen was done b/c
it is meant to represent a pattern that performs 'variable binding'. Given that
I am going to add a new 'inout' pattern binding to this, it makes sense to
give it now a better fitting name before I make things more confusing.
2020-07-16 18:56:01 -07:00
Robert Widmann
53505c7ef4 Fix a Source Break With Function Builders
Before 09db2902d2, the function builder
transform used to try to detect when the builder type wasn't fully
resolved. In such a case, rather than fail the solution set as we do
currently, it would construct a null TypeLoc, then stash the type-
variable-laden builder type inside of a TypeExpr and rely on CSGen
to reinterpret that as a request to read the stashed type as it was
constructing the rest of the system. This used to rely on the ability to construct
an implicit TypeExpr node with a null type but now such a thing is
banned by the TypeExpr interface.

Instead, we have to detect this case and construct an *explicit*
TypeExpr node pointing to all the usual fake data. This node's type will
be used to resolve the build* member, but the final applied type of the
node will be the builder type we stashed earlier - hopefully with
outstanding type variables solved.

rdar://65116204
2020-07-16 18:44:54 -07:00
Brent Royal-Gordon
acc01aea03 [NFC] Add MagicIdentifierKinds.def
Extracts the list of magic identifier literal kinds into a separate file and updates a lot of code to use macro metaprogramming instead of naming half a dozen cases manually. This is a complicated change, but it should be NFC.
2020-07-13 14:05:13 -07:00
Rintaro Ishizaki
eb84f5e23c Merge pull request #32748 from rintaro/index-rdar64636688
[Index] Fast path for getting value member
2020-07-08 10:10:40 -07:00
Anthony Latsis
2133fe27df Sema: Have TypeResolution accept an unbound generic type opener function 2020-07-08 13:39:34 +03:00
Holly Borla
063d420e50 Merge pull request #32672 from hborla/property-wrapper-diagnostics
[Property Wrappers] Improve diagnostics for property wrappers initialized out-of-line
2020-07-07 19:07:55 -07:00
Rintaro Ishizaki
026904990c [Index] Fast path for getting value member
Avoid solving constraint system if there's only one viable overload.
This should also avoids a crash we are seeing in
'candidates.size() == 1' branch in the constraint system.

rdar://problem/64636688
2020-07-07 15:01:22 -07:00