Commit Graph

1034 Commits

Author SHA1 Message Date
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
Robert Widmann
ca728917e1 Merge pull request #32138 from AnthonyLatsis/eliminate-typeloc
Sema: Remove TypeLoc from ExplicitCastExpr (via TypeExpr)
2020-06-10 11:28:50 -07:00
Anthony Latsis
4b4634141f Sema: Remove TypeLoc from ExplicitCast 2020-06-09 15:20:25 +03:00
Doug Gregor
f1febc2d52 [Constraint system] Lift PatternBindingDecl into SolutionApplicationTarget.
Generalize the code used to generate constraints and apply solutions to
PatternBindingDecls so that it is handled directly by the constaint
system and solution, respectively, rather than as part of the function
builder transform. No functionality change, but this is a cleaner
abstraction.
2020-06-05 22:51:18 -07:00
Doug Gregor
7d4da10843 Merge pull request #32200 from DougGregor/single-expression-closure-cleanup
[AST] Clean up handling of single-expression closures
2020-06-05 21:02:58 -07:00
Rintaro Ishizaki
3ec250f701 [CodeCompletion] Wrap base expression with CodeCompletionExpr
For example for:

  funcName(base.<HERE>)

Wrap 'base' with 'CodeCompletionExpr' so that type checker can check
'base' independently without preventing the overload choice of 'funcName'.

This increases the chance of successful type checking.

rdar://problem/63965160
2020-06-05 15:51:07 -07:00
Doug Gregor
836bc57fe5 [AST Walker] Stop visiting the bodies of closures as expressions.
Single-expression closures have always been traversed differently
from multi-statement closures. The former were traversed as if the
expression was their only child, skipping the BraceStmt and implicit
return, while the later was traversed as a normal BraceStmt.
Unify on the latter treatment, so that traversal

There are a few places where we unintentionally relied on this
expression-as-child behavior. Clean those up to work with arbitrary
closures, which is an overall simplification in the logic.
2020-06-04 23:06:32 -07:00
Pavel Yaskevich
2f3a0f0a57 Merge pull request #32159 from xedin/rdar-63510989
[CSGen] Allow `is` patterns to infer type from enclosing context
2020-06-04 11:03:25 -07:00
Doug Gregor
f55e7643fa [Constaint system] Add a predicate for when to check closures in enclosing expr
Introduce a new predicate, shouldTypeCheckInEnclosingExpression(), to
determine when the body of a closure should be checked as part of the
enclosing expression rather than separately, and use it in the various
places where "hasSingleExpressionBody()" was used for that purpose.
2020-06-03 22:48:58 -07:00
Pavel Yaskevich
b14d9655ca [CSGen] Allow is patterns to infer type from enclosing context
Instead of assuming type of its sub-pattern `is` should be able
to infer type from context and then propagate that to the sub-pattern
via conversion. This enables support for patterns like `.foo(_ as Foo)`
where `is` would have a type different from `_` which gets inferred
from associated value of `foo` and converted to `Foo` that becomes
a type of `_` pattern.

Resolves: rdar://problem/63510989
2020-06-03 10:26:27 -07:00
Anthony Latsis
267e32dcd8 Merge pull request #32118 from AnthonyLatsis/post-increment-cleanup
[NFC] Pre- increment and decrement where possible
2020-06-02 20:10:29 +03:00
Varun Gandhi
2419112469 Merge pull request #32080 from varungandhi-apple/vg-tidying-up-without-marie-kondo
Get rid of #includes that do not spark joy
2020-06-01 19:51:01 -07:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Varun Gandhi
c14e934563 [NFC] Remove redundant includes for llvm/ADT/SmallSet.h. 2020-05-31 13:07:45 -07:00
Doug Gregor
451e3cc480 [Constraint system] Move closure type checking to a separate file. 2020-05-29 21:05:02 -07:00
Doug Gregor
6def0303a9 [Constraint system] Separate out constraint generation for closures. 2020-05-29 20:51:17 -07:00
Robert Widmann
afe8f2b63f Drop TypeCheckerDebugConsumer 2020-05-18 22:49:55 -07:00
Pavel Yaskevich
b5568e0c20 [CSGen] Allow closure parameters to become holes by default
That helps when there is no context around a closure and parameters
used in the body are untyped.
2020-05-15 01:13:06 -07:00
Rintaro Ishizaki
b8f6471096 Merge pull request #31774 from rintaro/ide-completion-rdar60982638
[CodeCompletion] Avoid re-typechecking pre-checked expressions
2020-05-14 12:48:12 -07:00
Rintaro Ishizaki
32bd37756e [CodeCompletion] Handle "KeyPath as function" thunk in SanitizeExpr
rdar://problem/60982638
2020-05-13 16:59:06 -07:00
Robert Widmann
2bca013457 Move "isDebugMode" into ConstraintSystem
This eliminates the final source of mutation of the TypeCheckerFlags on the ASTContext.
2020-05-13 09:13:44 -07:00
Luciano Almeida
02c454c976 [Diagnostics] Diagnose that we cannot infer the key path type when binding to a hole 2020-05-11 18:08:40 -03:00
Pavel Yaskevich
4b91ff7f0a Merge pull request #31604 from xedin/rdar-60534522
[ConstraintSystem] Always verify computed/resolved pattern types befo…
2020-05-07 00:05:23 -07:00