Commit Graph

1354 Commits

Author SHA1 Message Date
Pavel Yaskevich
99856ed42c Merge pull request #29655 from xedin/rdar-41416758
[ConstraintSystem] Make variadics work with anonymous closure parameters
2020-02-05 12:10:25 -08:00
Pavel Yaskevich
07a69c425f [ConstraintSystem] Make variadics work with anonymous closure parameters
Since opening closure body is now delayed until contextual type becomes
available it's possible to infer anonymous parameters as being variadic
based on context and propagate that information down to the closure body.

Resolves: rdar://problem/41416758
2020-02-05 09:35:49 -08:00
swift-ci
08dca4666e Merge pull request #29635 from DougGregor/simplify-solution-target 2020-02-04 02:36:15 -08:00
Doug Gregor
bbc0a95723 [Constraint system] Simplify creation of contextual conversion constraint.
We were storing more state than necessary in the constraint system.
2020-02-03 22:38:24 -08:00
Doug Gregor
f8eee50310 [Constraint solver] Fix function builders with single-expression closures
Fix a few related issues involving the interaction with
single-expression closures:

* A single-expression closure can have a "return" in it; in such
cases, disable the function-builder transform.
* Have the function builder constraint generator look through the
"return" statement in a single-expression closure the same way as
solution application does

Fixes rdar://problem/59045763, where we rejected some well-formed code
involving a single-expression closure with a "return" keyword.
2020-02-03 17:52:44 -08:00
swift-ci
8c8f5b1eb1 Merge pull request #29588 from DougGregor/silence-the-listeners 2020-01-31 20:02:13 -08:00
Doug Gregor
4b0e7b2780 [Type checker] Sink logic for @autoclosure default parameters into the solver
Rather than use an ExprTypeCheckListener subclass to introduce the
autoclosure expression, do it at the end of solving.
2020-01-31 18:20:46 -08:00
Pavel Yaskevich
d24537f032 Merge pull request #29024 from xedin/diagnose-shadowing
[Diagnostics] Port name shadowing diagnostics
2020-01-31 10:39:58 -08:00
Pavel Yaskevich
6debe3d3b5 [ConstraintSystem] Don't produce conformance fixes for mismatches associated with function result type
If there are any requirement failures associated with result types
which are part of a function type conversion, let's record general
conversion mismatch in order for it to capture and display complete
function types.
2020-01-30 09:54:33 -08:00
Pavel Yaskevich
2d10a8a9a0 [ConstraintSystem] Extend function type conversion mismatch coverage
Originally type mismatches associated with conversions between
function types were only covered for coercions and assignments
but fix coverage grew since then and now it makes sense
to remove special case and let `repairFailures` take care of it.
2020-01-30 09:45:36 -08:00
Pavel Yaskevich
3fff5dd064 [ConstraintSystem] Extend metatype instance type mismatch coverage
Originally type mismatches associated with metatypes were only covered
for coercions but fix coverage grew since then and now it makes sense
to remove special case and let `repairFailures` take care of it.
2020-01-29 09:40:38 -08:00
Pavel Yaskevich
78fda9ed98 [ConstraintSystem] Use new fix/diagnostic for name shadowing
Stop filtering outer overload choices while trying to pre-check
expression, instead have it always fetch those and use new
fix to only attempt them in diagnostic mode (unless it's min/max
situation with conditional conformances).
2020-01-29 09:14:24 -08:00
Pavel Yaskevich
dd094018de Merge pull request #29528 from xedin/anyobject-conversion-diagnostics
[Diagnostics] Port invalid conversion to AnyObject diagnostic
2020-01-29 08:03:50 -08:00
Pavel Yaskevich
b2083db45d [ConstraintSystem] Add a fix to allow conversion between non-class type and AnyObject 2020-01-29 00:06:57 -08:00
Holly Borla
608b1b4814 [ConstraintSystem] Allow solving same-type requirements for associated types
where the base does not conform to the associated type's protocol.

We can only reach this case when the solver has already applied a fix for
the conformance failure.
2020-01-28 13:17:53 -08:00
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