Commit Graph

1034 Commits

Author SHA1 Message Date
Pavel Yaskevich
4847ec9a6b [AST/TypeChecker] Add more asserts to make sure types don't get into AST 2020-08-27 13:18:45 -07:00
Anthony Latsis
61d86d5fd2 [NFC] CSGen: Clean up some flow in inferClosureType 2020-08-27 22:25:07 +03:00
Anthony Latsis
80560dab25 CSGen: Infer generic arguments in explicit closure result types 2020-08-27 22:17:58 +03:00
Frederick Kellison-Linn
352adc3b5d Remove Argument from UnresolvedMemberExpr
Instead, an expresison like `.foo()` is represented as an `UnresolvedMemberExpr` nested inside a `CallExpr`.
2020-08-26 22:42:30 -04:00
Frederick Kellison-Linn
5de23f5cfc [Sema] Rebase and address feedback for implicit member chains 2020-08-26 22:42:30 -04:00
Frederick Kellison-Linn
0055501670 [Sema] Add FIXME for Optional binding inference bug 2020-08-26 22:42:30 -04:00
Frederick Kellison-Linn
189235678f [Sema] Move member chain transformation into precheck
Move the analysis and transformation of unresolved member chains into the PreCheckExpression pass in order to make sure that contextual types get hooked up properly before we actually begin generating constraints.
2020-08-26 22:42:30 -04:00
Frederick Kellison-Linn
26f0a80599 [Sema] Transfer contextual type info when we inject UnresolvedMemberChainResultExpr
If we create an UnresolvedMemberChainResultExpr at the top level, we may end up losing contextual type information that was already attached to the end of the chain. To avoid this, we fetch any existing contextual type info and transfer it to the newly injected expression.
2020-08-26 22:42:30 -04:00
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