Commit Graph

1556 Commits

Author SHA1 Message Date
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
Holly Borla
7dffff79da [Property Wrappers] Let PropertyWrapperBackingPropertyTypeRequest
handle all errors with a property wrapper backing type.
2020-07-02 14:47:45 -07:00
Holly Borla
f555bfefc9 [Property Wrappers] Add new contextual type purposes for property wrappers
to produce better diagnostics when there's a 'wrappedValue' type mismatch.
2020-07-02 14:47:45 -07:00
Holly Borla
2ac8d7ea17 [ConstraintSystem] Add support for type checking an out-of-line
initialized wrapped property via SolutionApplicationTarget.
2020-07-01 18:02:58 -07:00
Pavel Yaskevich
caab4f4ead [CSGen] Handle incorrect patterns (e.g. referencing unknown types)
Currently `generateInitPatternConstraints` assumes that all
patterns have types but it's not the case for patterns that
e.g. reference unknown types or have other structural issues.

Let's fail `generateInitPatternConstraints` if constraint
generation fails.

Resolves: rdar://problem/64157451
2020-06-29 12:06:28 -07:00
Slava Pestov
0232cd00ed Sema: Sink SanitizeExpr down into TypeCheckCodeCompletion.cpp 2020-06-26 07:42:21 -04:00
Slava Pestov
34cebb4b54 Sema: SanitizeExpr doesn't need a ConstraintSystem 2020-06-25 19:36:19 -04:00
Pavel Yaskevich
92271e9ce5 [ConstraintSystem] Rework handling of object literal expressions
Instead of special casing argument-to-parameter matching for
object literal expressions, let's allow constraint system to
lookup a witness initializer and apply it to the given set
of arguments.

This also simplifies constraint application because
`coerceCallArguments` could be used to form type-checked
argument expression.
2020-06-22 10:15:08 -07:00
Holly Borla
392a26323b [Property Wrappers] When generating constraints for composed property
wrappers, equate the former wrappedValue type with the current wrapper
type rather than generating value member constraints.
2020-06-16 13:58:04 -07:00
Pavel Yaskevich
e9b241fc78 Merge pull request #32334 from xedin/use-gettype-for-pd-constraint-gen
[CSGen] Replace `getInterfaceType() -> mapTypeIntoContext()` for VarD…
2020-06-12 11:46:09 -07:00
Robert Widmann
080bea5ef9 Merge pull request #32321 from CodaFi/type-check
[NFC] TypeCheckType No Longer Returns Null
2020-06-11 20:37:33 -07:00
Pavel Yaskevich
ac8dfcf89b [CSGen] Replace getInterfaceType() -> mapTypeIntoContext() for VarDecl with getType
In `ConstraintGenerator::visitDeclRefExpr` instead of using
`getInterfaceType()` for unknown type and later mapping it into
context, let's use `getType()` which does that interally, that
allows to detect presence of error types in resulting type and
abort constraint generation.
2020-06-11 17:03:28 -07:00
Anthony Latsis
86b7e989e7 [NFC] CS: Give the type-transforming openUnboundGenericType method a more accurate name 2020-06-11 23:58:01 +03:00
Robert Widmann
002369565b [NFC] Update calls to assume resolveType never returns null 2020-06-11 13:04:53 -07:00
Robert Widmann
d81f1482c3 [NFC] Fixup TypeChecker::getOptionalType To Not Return Type() 2020-06-11 12:21:35 -07:00
Robert Widmann
4c0c7daf3f [NFC] Fixup TypeChecker::getArraySliceType To Not Return Type() 2020-06-11 10:58:17 -07:00
Robert Widmann
8f065e7a61 Delete TypeChecker::validateType
Inline it into its final user: swift::performTypeLocChecking
2020-06-10 19:33:58 -07:00
Robert Widmann
426d930d10 Merge pull request #32301 from CodaFi/location-location-location
Strip TypeLoc out of Patterns
2020-06-10 19:25:56 -07:00
Rintaro Ishizaki
4205e46959 Merge pull request #32184 from rintaro/ide-completion-rdar63965160
[CodeCompletion] Wrap base expression with CodeCompletionExpr
2020-06-10 16:19:35 -07:00
Robert Widmann
2371e5c260 Strip TypeLoc from EnumElementPattern 2020-06-10 14:22:46 -07:00
Robert Widmann
fc9070c072 Strip TypeLoc from IsPattern 2020-06-10 13:29:39 -07:00