Commit Graph

663 Commits

Author SHA1 Message Date
Alex Hoppen
82fc059018 [CodeCompletion] Store ignored arguments as Expr * instead of ConstraintLocators
This avoids the construction of `ConstraintLocator`s.
2022-03-18 15:14:31 +01:00
Alex Hoppen
17ac201b29 Merge pull request #39373 from ahoppen/pr/solver-based-arg-completion
[CodeCompletion] Migrate argument position completion to the solver-based implementation
2022-03-17 22:41:59 +01:00
Alex Hoppen
f538d33e5f [CodeCompletion][Sema] Migrate CallArgurment position completion to the solver-based implementation
This hooks up call argument position completion to the typeCheckForCodeCompletion API to generate completions from all the solutions the constraint solver produces (even those requiring fixes), rather than relying on a single solution being applied to the AST (if any).

Co-authored-by: Nathan Hawes <nathan.john.hawes@gmail.com>
2022-03-17 15:15:54 +01:00
Alex Hoppen
ca9056a275 [TypeChecker] Add method to check whether a type variable represents a code completion token 2022-03-17 09:04:29 +01:00
Pavel Yaskevich
a9e92111fc [ConstraintSystem] Augment condition/ternary simplication to support statements 2022-03-17 00:51:20 -07:00
Doug Gregor
8224335e86 Remove dead find/filter-Constraints functions from the constraint solver 2022-03-08 10:31:35 -08:00
Robert Widmann
d6186c9cfb Add a DeclContext Parameter to Opened Archetype Construction
This ensures that opened archetypes always inherit any outer generic parameters from the context in which they reside. This matters because class bounds may bind generic parameters from these outer contexts, and without the outer context you can wind up with ill-formed generic environments like

<τ_0_0, where τ_0_0 : C<T>, τ_0_0 : P>

Where T is otherwise unbound because there is no entry for it among the generic parameters of the environment's associated generic signature.
2022-03-07 22:54:22 -08:00
Pavel Yaskevich
5ec5ffcfda Merge pull request #41570 from xedin/add-expr-pattern-handling-to-solver
[ConstraintSystem] Add support for expression patterns
2022-02-28 09:39:26 -08:00
Pavel Yaskevich
31b356f30c [ConstraintSystem] Add a dedicated method to pre-check solver targets
Since `SolutionApplicationTarget` could represent whole statement
or pattern with multiple expressions, it makes sense to add a dedicated
method to pre-check everything together.
2022-02-25 15:14:39 -08:00
Pavel Yaskevich
4ba8d4cf94 [ConstraintSystem] Augment solution application target to support expression patterns 2022-02-25 12:48:14 -08:00
Pavel Yaskevich
49d397cd6a [ConstraintSystem] Make it possible to anchor a target on a pattern 2022-02-25 12:06:37 -08:00
Pavel Yaskevich
a6f86c453d [ConstraintSystem] NFC: Extract opening of individual generic parameters into a method 2022-02-21 09:59:53 -08:00
Pavel Yaskevich
eb092c9908 [ConstraintSystem] Make typeCheckParameterDefault a friend
`typeCheckParameterDefault` needs access to `applySolution`
in order to apply a solution found in `inference from defaults` mode.
2022-02-21 09:59:53 -08:00
Pavel Yaskevich
23297c94e6 [ConstraintSystem] NFC: Extract opening of individual requirements into a method
It's a convenient way to use existing logic for default argument inference
because suhc inference cannot open whole signature but only conformance
and layout constraints associated generic parameters used in a particular
parameter position.
2022-02-21 09:59:53 -08:00
Doug Gregor
1e1b3427c3 Experimental support for implicitly opening existential arguments.
When calling a generic function with an argument of existential type,
implicitly "open" the existential type into a concrete archetype, which
can then be bound to the generic type. This extends the implicit
opening that is performed when accessing a member of an existential
type from the "self" parameter to all parameters. For example:

    func unsafeFirst<C: Collection>(_ c: C) -> C.Element { c.first! }

    func g(c: any Collection) {
      unsafeFirst(c)   // currently an error
                       // with this change, succeeds and produces an 'Any'
    }

This avoids many common sources of errors of the form

    protocol 'P' as a type cannot conform to the protocol itself

which come from calling generic functions with an existential, and
allows another way "out" if one has an existention and needs to treat
it generically.

This feature is behind a frontend flag
`-enable-experimental-opened-existential-types`.
2022-02-18 11:22:56 -08:00
Pavel Yaskevich
57ce1d2360 Merge pull request #41282 from xedin/too-complex-with-multistmt-cljs
[ConstraintSystem] Adjust expression complexity computation to account for multi-statement closures
2022-02-10 08:41:40 -08:00
Pavel Yaskevich
f1e602f98d Merge pull request #41189 from xedin/trailing-closures-with-callAsFunction
[ConstraintSystem] Match trailing closures to implicit `.callAsFunction` when necessary
2022-02-08 17:44:55 -08:00
Pavel Yaskevich
1636ee83c3 [CSStep] Conjunction: Give each conjunction step a fresh timer
Original timer cannot be used each expression in the multi-statement
closure is type-checked independently.
2022-02-08 15:23:20 -08:00
Pavel Yaskevich
d0031403cc [ConstraintSystem] ExpressionTimer: Accept locators as timer anchors 2022-02-08 14:33:46 -08:00
Pavel Yaskevich
9d29678316 [ConstraintSystem] ExpressionTimer: Make it possible to access remaining time until threshold 2022-02-08 14:33:46 -08:00
Pavel Yaskevich
e60afb3446 [ConstraintSystem] Augment ExpressionTimer to carry the threshold
Instead of asking callers of `isExpired` to provide the threshold,
let's ask for that upfront. This change also allows us to check how
much time remains in the timer and build timers with different
thresholds without having to safe that information somewhere else.
2022-02-08 14:33:46 -08:00
Pavel Yaskevich
01a4468b32 [ConstraintSystem] Extract creation/recording of implicit .callAsFunction roots 2022-02-03 15:36:18 -08:00
Pavel Yaskevich
b48a064f62 [ConstraintSystem] Add storage for implicitly generated roots of .callAsFunction
Some implicit calls to `.callAsFunction` require that a new root
expression to be created for them in order to record argument list
and resolved overload choice.
2022-02-03 15:35:50 -08:00
Pavel Yaskevich
12497b7145 [CSSimplify] Allow callers to provide argument list to matchCallArguments
This would make it much easier to implement trailing closure splitting
for during callable type construction.
2022-02-03 15:33:28 -08:00
Anthony Latsis
24c19d4ad4 Sema: Enable covariant erasure for dependent member types 2022-02-02 02:10:05 +03:00
Anthony Latsis
b3ee4b0718 AST, Sema: Use the opened archetype's generic signature to determine existential member availability 2022-02-02 02:09:59 +03:00
Anthony Latsis
3206f5ab34 [NFC] Preemptively relocate ProtocolDecl::isAvailableInExistential() and co. 2022-02-01 20:55:46 +03:00
Pavel Yaskevich
9f7d3fccad Merge pull request #40708 from xedin/disable-multi-stmt-inference-inside-result-builder-bodies
[ConstraintSystem] SE-0326: Temporarily prevent multi-statement closure inference in result builder contexts
2022-01-06 01:04:22 -08:00
Doug Gregor
b97ef02d85 Opaque opaque types and compute substitutions in the constraint system
Opaque opaque types and record them within the "opened types" of the
constraint system, then use that information to compute the set of
substitutions needed for the opaque type declaration using the normal
mechanism of the constraint solver. Record these substitutions within
the underlying-to-opaque conversion.

Use the recorded substitutions in the underlying-to-opaque conversion
to set the underlying substitutions for the opaque type declaration
itself, rather than reconstructing the substitutions in an ad hoc manner
that does not account for structural opaque result types.
2021-12-26 20:33:58 -08:00
Pavel Yaskevich
35c24bc200 [ConstraintSystem] Make it possible to determine that closure is in result builder context 2021-12-25 17:07:55 -08:00
Robert Widmann
b3f70c960e Implement Pack Locators 2021-12-16 01:16:45 -08:00
Robert Widmann
d4b8f1df96 Implement TypeBase::isTypeSequenceParameter
Behaves much like isTypeParameter but specifically checks for the type sequence bits. Also, add the type sequence bits as a recursive type property.
2021-12-16 01:16:45 -08:00
Doug Gregor
2b5bcc1062 Merge pull request #40544 from DougGregor/sr-15131-closure-effects
Extend "uses concurrency features" checks for closures currently being type checked
2021-12-14 11:02:03 -08:00
Doug Gregor
cc7904cf52 Use the closure type during type checking for establishing use of new features
When evaluating whether code is within a closure that uses concurrency
features, use the type of the closure as it's known during type checking,
so that contextual information (e.g., it's passed to a `@Sendable` or
`async` parameter of function type) can affect the result. This
corrects the definition for doing strict checking within a minimal
context for the end result of the type-check, rather than it's initial
state, catching more issues.

Fixes SR-15131 / rdar://problem/82535088.
2021-12-14 07:15:49 -08:00
Doug Gregor
c3b6160af8 Generalize and cache the "closure effects" determined from the closure body.
Use this to enable better detection of async contexts when determining
whether to diagnose problems with concurrency.

Part of SR-15131 / rdar://problem/82535088.
2021-12-13 21:32:28 -08:00
Alex Hoppen
1739c23a9b Merge pull request #40158 from ahoppen/pr/cancel-code-completion
[SourceKit] Support cancellation of code completion like requests
2021-12-07 17:10:05 +01:00
Pavel Yaskevich
0e6e058e7c [TypeChecker] Fix constraint solver to respect LeaveClosureBodyUnchecked flag 2021-12-03 10:54:07 -08:00
Pavel Yaskevich
46ff410a23 [ConstraintSystem] Warn about discarded expressions found in multi-statement closures 2021-12-03 10:53:50 -08:00
Alex Hoppen
9042536323 [SourceKit] Move the cancellation flag from TypeCheckerOptions to ASTContext
We need to modify the pointer pointing to the cancellation flag when reusing an ASTContext for code completion. This is not possible by the previous design because `TypeCheckerOptions` was `const`. Moving the cancellation flag to `ASTContext` will also allow other stages of the compiler to honor a cancellation request.
2021-12-02 12:57:34 +01:00
Pavel Yaskevich
bc54bc6bb7 Revert "[TypeChecker] SE-0326: Enable multi-statement closure inference by default" 2021-11-29 17:26:08 -08:00
Anthony Latsis
3c17d35f34 CS: Use TypeResolutionStage::Interface for applying generic arguments in 'openUnboundGenericType' 2021-11-19 16:44:07 +03:00
Hamish Knight
237338b504 Merge pull request #40224 from hamishknight/super-tuple-shuffle 2021-11-18 09:50:09 +00:00
Hamish Knight
da36a2cb88 [CS] Restore a type variable for compatibility with rdar://85263844
Despite being otherwise disconnected from the
constraint system, it's possible for it to affect
how we type-check tuple matches in certain cases.

This is due to the fact that:
- It can have a lower type variable ID than an
opened generic parameter type, so becomes the
representative when merged with it. And because it
has a different locator, this can influence
binding prioritization.
- Tuple subtyping is broken, as it's currently a
*weaker* relationship than conversion.

Therefore, temporarily restore this bit of logic
for language versions < 6. If possible, we should
try and fix tuple subtying in Swift 6 mode to not
accept label mismatches, so that it's not more
permissive than tuple conversion.

rdar://85263844
2021-11-17 17:06:19 +00:00
Pavel Yaskevich
83033198c3 [TypeChecker] Fix constraint solver to respect LeaveClosureBodyUnchecked flag 2021-11-15 16:42:05 -08:00
Pavel Yaskevich
3927f56dbd [ConstraintSystem] Warn about discarded expressions found in multi-statement closures 2021-11-15 16:42:04 -08:00
Pavel Yaskevich
0b4ec1c31e [ConstraintSystem] Add accessor to check whether target represents async let init 2021-11-12 12:41:29 -08:00
Pavel Yaskevich
4799acfb20 [CSBindings] Attempt a type variable early if it's constrained by a struct/enum type
If a type variable has a subtype binding which came from a conversion/subtype/equality
constraint to a struct or enum (expect to `AnyHashable`, `Unsafe{Mutable}RawPointer`),
attempt it early because that type is the only choice which is not going to fail such
constraint.

For example, in cases like `$T argument convertible to Int` type variable could
only be bound to `Int`, `Int!`, or `@lvalue Int` to satisfy that constraint, so
it would make sense to attempt to bind it to `Int` early if it doesn't represent
a result of a member lookup (that's how IUO and/or `@lvalue` could be inferred)`
and doesn't have any direct disjunction associated with it e.g. for coercion or
optional matching.
2021-11-08 13:51:23 -08:00
Pavel Yaskevich
0c70f5650f Merge pull request #39592 from Jumhyn/contextual-placeholder-followup
Remove default argument from getContextualType
2021-11-08 10:00:36 -08:00
Hamish Knight
fb3796971e [CS] Simplify getAlternativeLiteralTypes
Caching the result here feels a little overkill as
it's only useful for one protocol, and the
`TypeChecker::getDefaultType` computation is
cached by the request evaluator.
2021-11-02 13:55:04 +00:00
Alexis Laferrière
1a3f28500b [Sema] Don't check availability in assigned properties initializers
For a non-public property where the type is defined by an assignment, like
`internal var internalAssigned = NewStruct()`, type-checking the type's
availability is done via checking the initializer expression.

In -check-api-availaiblity-only mode, pass down a flag to not check
availability in expressions for initializer expressions of such
non-public properties.

rdar://84389825
2021-10-25 13:46:53 -07:00