Commit Graph

1339 Commits

Author SHA1 Message Date
Pavel Yaskevich
c662a91578 Merge pull request #29490 from xedin/remove-more-code-from-visitapplyexpr
[Diagnostics] Don't re-typecheck function expression associated with various calls
2020-01-28 00:32:05 -08:00
Pavel Yaskevich
dea79e09c6 [ConstraintSystem] Detect that function type has failures before applying arguments
If a type variable representing "function type" is a hole
or it could be bound to some concrete type with a help of
a fix, let's propagate holes to the "input" type. Doing so
provides more information to upcoming argument and result matching.
2020-01-27 16:53:33 -08:00
Pavel Yaskevich
c7c9510366 [ConstraintSystem] Don't re-attempt to bind type variable if it could be a hole
If type variable is allowed to be a hole and it can't be bound to
this particular (full resolved) type, just ignore this binding
instead of re-trying it later.
2020-01-27 16:53:33 -08:00
Doug Gregor
46a65009e3 [Constraint system] Eliminate global flag UnderlyingTypeForOpaqueReturnType
Make this information contextual (per type) rather than global (per
constraint system) so we don’t misapply it.
2020-01-27 15:44:54 -08:00
Doug Gregor
d752f414d3 [Constraint solver] Rework solveImpl(Expr*) to return SolutionResult.
SolutionResult better captures what can happen when solving a constraint
system for the given expression occurs than the ad hoc SolutionKind return
& small vector of Solution results. Also, try to make this logic less
convoluted.
2020-01-26 12:05:43 -08:00
Doug Gregor
5063cb5b79 [Constraint solver] Factor out adding a contextual conversion constraint. 2020-01-26 12:05:43 -08:00
Doug Gregor
133439dcbb [Constraint solver] Request contextual type information per expression.
When requesting information about the contextual type of a constraint
system, do so using a given expression rather than treating it like
the global state that it is.
2020-01-23 11:46:17 -08:00
Holly Borla
7fb27b3c74 [ConstraintSystem] Find solutions for code that contains circular member
references in the new diagnostic infrastructure.
2020-01-22 10:57:52 -08:00
Holly Borla
86cf6dc03e [ConstraintSystem] Finish porting member failure diagnostics.
Remove special cases for AnyObject member and dynamic member lookup
failures - these are now all handled in the new diagnostic
infrastructure.
2020-01-22 10:57:52 -08:00
Luciano Almeida
716e11f575 [Constraint System] Recording SpecifyObjectLiteralTypeImport fix when attempting literal result type variable binding and handle object literal in MissingArgumentsFailure 2020-01-21 20:39:44 -03:00
Luciano Almeida
68e09d64fd [CSFix] Creating object literal module import fix 2020-01-21 11:54:26 -03:00
Pavel Yaskevich
f49d4501f8 [ConstraintSystem] Fix conversion of variadic/inout closure parameters for internal use
Delayed constraint generation for the body of the single-statement
closures regressed variadic parameter handling. Fix it by using
`FunctionType::Param::getParameterType` for "internal" version of
the parameter type which translates variadic/inout correctly.

Resolved: rdar://problem/58647769
2020-01-16 10:37:36 -08:00
Pavel Yaskevich
1c803a7cac [CSFix] Account for special closure handling in invalid trailing closure fix
Since closures don't get the type assigned right away anymore we
have to fetch it before any of the internal type variables could
be marked as holes.
2020-01-14 00:09:32 -08:00
Pavel Yaskevich
65adc18139 [ConstraintSystem] Delay constraint generation from single-statement closure body
Attempt to infer a closure type based on its parameters and body
and put it aside until contextual type becomes available or it
has been determined that there is no context.

Once all appropriate conditions are met, generate constraints for
the body of the closure and bind it the previously inferred type.

Doing so makes it possible to pass single-statement closures as
an argument to a function builder parameter.

Resolves: SR-11628
Resolves: rdar://problem/56340587
2020-01-14 00:09:32 -08:00
Pavel Yaskevich
b868d1cfb7 [ConstraintSystem] Account for unapplied curried self while trying to retrieve function builder type for parameter 2020-01-14 00:09:32 -08:00
Pavel Yaskevich
9257b29465 [ConstraintSystem] Clarify DefaultClosureType constraint and add its own simplify method 2020-01-14 00:09:32 -08:00
Pavel Yaskevich
9dc2dfde98 [ConstraintSystem] Allow single-statement closures be used with function builders
While resolving closure use contextual locator information to
determine whether given contextual type comes from a "function builder"
parameter and if so, use special `applyFunctionBuilder` to open
closure body instead of regular constraint generation.
2020-01-14 00:09:32 -08:00
Pavel Yaskevich
66db166922 [ConstraintSystem] Introduce new DefaultClosureType constraint
This constraint connects type variable representing a closure
expression to its inferred type and behaves just like regular
`Defaultable` constraint expect for type inference where it's
used only if there are no contextual bindings available.
2020-01-14 00:09:32 -08:00
Pavel Yaskevich
b7523d745c [ConstraintSystem] Introduce resolveClosure method to generate constraints for closure body
In preparation to change the way closures are handled in constraint system
let's introduce a special method which is responsible for generation of
constraints for closure body and connecting it to the rest of the
constraint system when contextual type becomes available.
2020-01-14 00:09:32 -08:00
Doug Gregor
946eee9cf8 Merge pull request #29102 from DougGregor/function-builder-via-constraint-system
[Constraint solver] Use a constraint system to apply all function builders
2020-01-09 23:42:32 -08:00
Doug Gregor
5b320992ea [Constraint solver] Use a constraint system to apply all function builders.
When type checking the body of a function declaration that has a function
builder on it (e.g., `@ViewBuilder var body: some View { ... }`), create a
constraint system that is responsible for constraint generation and
application, sending function declarations through the same code paths
used by closures.
2020-01-09 14:38:45 -08:00
Hamish Knight
6f0f16edbc [CS] Tighten up assertions for getCalleeDeclAndArgs (#29077)
[CS] Tighten up assertions for getCalleeDeclAndArgs
2020-01-09 09:15:37 -08:00
Pavel Yaskevich
4c1e2c6ce1 [Diagnostics] Add nullptr check for anchor while fixing function result failures 2020-01-08 17:17:26 -08:00
Doug Gregor
ac24491dae [Constraint system] Generalize function builder application APIs.
Teach the constraint system to handle matching a function builder to a
function as well as a closure.
2020-01-08 16:19:44 -08:00
Hamish Knight
1a8477aea1 [CS] NFC: Inline getCalleeDeclAndArgs 2020-01-08 13:39:00 -08:00
Hamish Knight
c6b6e72aac [CS] Tighten up assertions for getCalleeDeclAndArgs
Assert that we have a correct locator and that we
recorded argument information for it, rather than
returning no information.

In addition, always return the callee locator,
even if there is no callee.
2020-01-08 13:38:59 -08:00
Luciano Almeida
4d982f3430 [CSSimplify] Do not record fix to coerce with existential restriction 2020-01-08 07:07:49 -03:00
Luciano Almeida
fc49af2949 [CSSimplify] Handle coercion to wrong type for function result locator 2020-01-08 07:07:49 -03:00
Luciano Almeida
0e1a03dc61 [CSSimplify] Handle optional wrong type conversion 2020-01-08 07:07:49 -03:00
Luciano Almeida
06201a64be [Sema] Diagnose wrong type coercion involving metatypes 2020-01-08 07:07:49 -03:00
Pavel Yaskevich
9a62701e95 [ConstraintSystem] Use new branch element and fix mismatch between ternary branches 2020-01-07 13:50:09 -08:00
Pavel Yaskevich
36fff23077 Merge pull request #29011 from LucianoPAlmeida/coercion-handle-contextual-mismatch
[Diagnostics] Handle CoerceExpr conversion failure in contextual mismatch
2020-01-06 11:31:12 -08:00
Holly Borla
94bbb8f76e [ConstraintSystem] Finish porting unresolved member reference failures.
This covers member failures where the error is at the declaration, so
the result of member lookup is "already diagnosed".
2020-01-05 11:33:02 -08:00
Luciano Almeida
f145264fc7 [tests] Fix parser recover tests 2020-01-05 00:23:15 -03:00
Luciano Almeida
533d9acf73 [CSSimplify] Fallback to contextual mismatch in repair failures for CoerceExpr 2020-01-04 15:54:46 -03:00
Doug Gregor
bbcaf8c669 [Type checker] Introduce value witness constraints.
Introduce a new kind of constraint, the "value witness" constraint,
which captures a reference to a witness for a specific protocol
conformance. It otherwise acts like a more restricted form of a "value
member" constraint, where the specific member is known (as a
ValueDecl*) in advance.

The constraint is effectively dependent on the protocol
conformance itself; if that conformance fails, mark the type variables
in the resolved member type as "holes", so that the conformance
failure does not cascade.

Note that the resolved overload for this constraint always refers to
the requirement, rather than the witness, so we will end up recording
witness-method references in the AST rather than concrete references,
and leave it up to the optimizers to perform devirtualization. This is
demonstrated by the SIL changes needed in tests, and is part of the
wider resilience issue with conformances described by
rdar://problem/22708391.
2020-01-02 12:06:23 -08:00
Pavel Yaskevich
b03b356bfa Merge pull request #28880 from xedin/port-multi-stmt-closure-diags
[Diagnostics] Diagnose inability to infer (complex) closure return type
2019-12-19 14:17:34 -08:00
Pavel Yaskevich
8bcc192591 [Diagnostics] Diagnose inability to infer (complex) closure return type 2019-12-19 12:16:30 -08:00
Hamish Knight
40d11716f7 [CS] Use custom locator element for callAsFunction
Introduce a `ImplicitCallAsFunction` locator path
element to represent an implicit member reference
to `callAsFunction`. Then adjust CSApply a little
to check whether it's finishing an apply for a
callable type, and if so build the implicit member
access.
2019-12-18 11:43:45 -08:00
Hamish Knight
56265a26bf [CS] Resolve callees for key path dynamic members (#28807)
[CS] Resolve callees for key path dynamic members
2019-12-16 17:52:22 -08:00
Hamish Knight
cefc03f0e2 [CS] Resolve callees for key path dynamic members
Change the locator for the applicable fn
constraint for the inner subscript reference in an
implicit `outer[dynamicMember: \Inner.[0]]` expr
such that it uses the member locator with a
KeyPathDynamicMember element.

Then add a case to `getCalleeLocator` to handle
these locators. We also need to handle this
specially in `getArgumentInfoLocator` due to the
fact that the argument labels for the inner
subscript reference correspond to those written
by the user for the outer subscript reference.

Resolves SR-11933.
Resolves rdar://problem/57824025.
2019-12-16 10:04:24 -08:00
Pavel Yaskevich
d77e34925f [ConstraintSystem] Lift a restriction on fixing of non-function calls on Any/AnyObject
Detect and diagnose situations where call is attempted directly on
`Any` or `AnyObject` or member calls with `AnyObject` base which
didn't match.
2019-12-13 22:50:04 -08:00
Pavel Yaskevich
a9106cafca [ConstraintSystem] Account for missing unwrap(s) in call to optional Objective-C members 2019-12-13 22:50:04 -08:00
Hamish Knight
f1e690c07e Merge pull request #28775 from hamishknight/dynamic-lookup-attr-req
Requestify hasDynamicMemberLookupAttribute for Sema too
2019-12-13 14:40:13 -08:00
Pavel Yaskevich
5ba2e59c63 Merge pull request #28752 from xedin/simplify-potential-binding
[ConstraintSystem] Record originator constraint for each type variable binding
2019-12-13 11:50:02 -08:00
Hamish Knight
36cecb4015 Requestify hasDynamicMemberLookupAttribute for Sema too
Previously we had a request for this in
IDETypeChecking, but this wasn't used for queries
made from Sema. Move the request into Sema, and
move `hasDynamicMemberLookupAttribute` onto
TypeBase.
2019-12-13 11:04:00 -08:00
Pavel Yaskevich
fb764969c0 Merge pull request #28770 from xedin/rdar-57843297
[Diagnostics] Upon keypath result contextual mismatch try to match ob…
2019-12-13 10:12:27 -08:00
Pavel Yaskevich
47c7b9b910 [Diagnostics] Upon keypath result contextual mismatch try to match object types
If there was a mismatch between last component type and contextual
key path result type, let's try to re-match the types with all optionals
stripped off. In cases where the problem is optionality difference
e.g. `[Int] vs. [Int]?` that propagates contextual information to
the last component which facilitates better diagnostics.

Resolves: rdar://problem/57843297
2019-12-13 00:50:54 -08:00
Pavel Yaskevich
f259286bd7 [CSFix] Convert missing explicit @escaping fix to be a contextual mismatch
Sometimes diagnostic needs both sides of the conversion e.g.
when there is an attempt to bind generic argument to non-escaping type.
2019-12-12 12:42:08 -08:00
Holly Borla
3d1ab4da67 Merge pull request #28712 from hborla/function-parameter-mismatch-diagnostics
[ConstraintSystem] Port function parameter type mismatch diagnostics.
2019-12-11 14:33:07 -08:00