Commit Graph

2416 Commits

Author SHA1 Message Date
Pavel Yaskevich
cc0e621497 [CSFix] NFC: Remove obsolete IgnoreKeyPathContextualMismatch fix 2023-10-06 17:07:41 -07:00
Pavel Yaskevich
6fd6c16bf7 [CSSimplify] Key path should use a default type is contextual type is a placeholder
If there is something wrong with the context, let's assign a default
KeyPath type to the key path literal to avoid propagating placeholder
into the key path inference.
2023-10-06 16:59:53 -07:00
Pavel Yaskevich
4830c5be9a [CSSimplify] Unwrap of key path root can only yield one type
For methods there are two possibilities - force unwrap and
conditional, that's why we need a disjunction with two choices.

This is not the case for key path root type it could only
be force unwrapped.
2023-10-06 16:14:01 -07:00
Pavel Yaskevich
5a6c562b8c [CSSimplify] Adjust locators associated with keypath root/value matching constraints
`tryMatchRootAndValueFromType` anchored both root and value match
constraints directly on the key path expression. That is incorrect
because we have special locators for that.
2023-10-06 10:35:42 -07:00
Pavel Yaskevich
6a1783d48e [CSSimplify] Prevent overly eager solving of key path constraint
If key path literal is passed as an argument to a function/subscript
application its type cannot be resolved until the overload for the
call is selected, otherwise it could prevent a valid keypath-to-function
conversion in cases were argument ends up being a function type.
2023-10-05 17:10:47 -07:00
Pavel Yaskevich
06984b4307 Merge pull request #68964 from xedin/rdar-113675093
[CSSimplify] Determine whether type is know Foundation entity in a sa…
2023-10-05 08:41:15 -07:00
Pavel Yaskevich
b83a73d177 [CSSimplify] Determine whether type is know Foundation entity in a safer way
Instead of trying to get string representation of the type itself,
let's just get it based on the type name, which works well with the
list of types we have.

Resolves: rdar://113675093
2023-10-04 11:56:37 -07:00
Pavel Yaskevich
3ca54ae9da [CSGen] Use OptionalObject constraint to connect element type and result of next()
Previously this wasn't possible because of `one-way` bind constraints
involved in pattern inference but this no longer the case.
2023-09-29 17:33:07 -07:00
Pavel Yaskevich
204d496c36 Merge pull request #63889 from xedin/cache-conformance-checks-in-cs
[ConstraintSystem] Add cache for conformance lookups
2023-09-28 14:00:17 -07:00
Allan Shortlidge
b22b8f0a55 NFC: Removed unused function in CSSimplify.cpp. 2023-09-22 18:04:39 -07:00
Holly Borla
940ab81244 Merge pull request #68685 from hborla/minimize-constraint-system-isolation-checking 2023-09-22 07:31:45 -07:00
Holly Borla
2e9c64d36c [Concurrency] Do not allow actor isolation violations in function conversions
to impact constraint solving.
2023-09-21 19:44:03 -07:00
Kavon Farvardin
f1142d5da4 [nfc] rename or eliminate isPureMoveOnly APIs
I think from SIL's perspective, it should only worry about whether the
type is move-only. That includes MoveOnlyWrapped SILTypes and regular
types that cannot be copied.

Most of the code querying `SILType::isPureMoveOnly` is in SILGen, where
it's very likely that the original AST type is sitting around already.
In such cases, I think it's fine to ask the AST type if it is
noncopyable. The clarity of only asking the ASTType if it's noncopyable
is beneficial, I think.
2023-09-20 15:23:17 -07:00
Pavel Yaskevich
32d265154f [ConstraintSystem] Add cache for conformance lookups
`lookupConformance` request is not cached and constraint solver
performs a lot of them for the same type (i.e. during disjunction
solving), let's try to cache previously performed requests to
see whether additional memory use is worth the performance benefit.
2023-09-20 00:59:22 +01:00
Holly Borla
97f1e617fd [Concurrency] Replace ClosureActorIsolation with ActorIsolation throughout
the isolation query APIs.
2023-09-16 12:21:36 -07:00
Holly Borla
4b23564711 [Concurrency] Rename AbstractClosureExpr::getActorIsolation to
getClosureActorIsolation.

This is preparation for changing AbstractClosureExpr to store
ActorIsolation instead of ClosureActorIsolation, and convert to
ClosureActorIsolation when needed to allow incrementally updating
callers. This change is NFC.
2023-09-16 12:20:53 -07:00
Luciano Almeida
9c3f2aa2c1 Merge pull request #68301 from LucianoPAlmeida/coerce-function 2023-09-06 06:57:52 -03:00
Luciano Almeida
50130b052f [NFC] Adjusting a couple of comments for clarity 2023-09-05 18:18:40 -03:00
Luciano Almeida
0300139257 [Sema][Diagnostics] Improving diagnostics for function type coerce failure 2023-09-03 15:18:04 -03:00
Hamish Knight
c0ae9b950b Move out-of-place ThenStmt checking to constraint generation 2023-09-01 14:32:15 +01:00
Hamish Knight
6ee44f09b4 Introduce then statements
These allow multi-statement `if`/`switch` expression
branches that can produce a value at the end by
saying `then <expr>`. This is gated behind
`-enable-experimental-feature ThenStatements`
pending evolution discussion.
2023-09-01 14:32:14 +01:00
Pavel Yaskevich
ed046e5efe Merge pull request #68215 from xedin/rdar-112426330
[CSSimplify] Rework detection of missing/extraneous arguments in closure
2023-08-31 13:15:52 -07:00
Slava Pestov
361d49a843 AST: Remove DeclContext::getSelfProtocolType() 2023-08-30 15:15:08 -04:00
Pavel Yaskevich
1c8b8d981a [CSSimplify] Rework detection of missing/extraneous arguments in closure
Checking type variables is no longer necessary because constraint
system now stores types of all closures it encountered, this makes
detection logic more reliable as well.

Resolves: rdar://112426330
2023-08-30 10:47:41 -07:00
Pavel Yaskevich
b5b335c499 [CSSimplify] Modernize binary function argument reordering fix
The fix used incorrect locators for attempted argument conversions,
didn't check whether arguments are already re-ordered and allowed
fixes as visible side-effects from checking.

Resolves: rdar://114341979
2023-08-24 17:10:14 -07:00
Amritpan Kaur
71a94a859b [CSSimplify] Add checks for invalid keypath member refs 2023-08-21 13:01:22 -07:00
Pavel Yaskevich
d725e38cd2 Merge pull request #67971 from amritpan/kp-function-application
[ConstraintSystem] Resolve key path function applications via resolveKeyPath
2023-08-16 23:12:44 -07:00
Amritpan Kaur
f4764b32bf [CSSimplify] Attempt tryMatchRootAndValueFromType even if
missing member.
2023-08-16 14:28:05 -07:00
Amritpan Kaur
feb0f34993 [CSSimplify] For function type binding for key path types, add flag
to allow it to go through resolveKeyPath in matchTypesBindTypeVar.
2023-08-16 12:53:54 -07:00
Pavel Yaskevich
b34f9720e4 [CSSimplify] Adjust {Any, Partial}KeyPath bindings right before resolving
A type variable that represents a key path literal cannot be bound
directly to `AnyKeyPath` or `PartialKeyPath`, such types could only
be used for conversions.
It used to be the task of the binding inference to infer `AnyKeyPath`
and `PartiaKeyPath` as a `KeyPath` using previously generated type
variables for a root and value associated with key path literal
(previously stored in the locator).

Recently we switched over to storing key path information in the
constraint system and introduced `resolveKeyPath` method to gain
more control over how key path type variable gets assigned.

Getting information from the constraint system creates a problem
for the inference because "undo" for some bindings would be run
after solver scope has been erased, so instead of modifying bindings
in `inferFromRelational`, let's do that in `resolveKeyPath` right
before the key path type variable gets bound which seems to be a
better place for that logic anyway.

Resolves: rdar://113760727
2023-08-15 13:50:54 -07:00
Pavel Yaskevich
cedbdf920c Merge pull request #67759 from xedin/rdar-112617922
[CSSimplify] Relax `isBindable` requirements for pack expansion variables
2023-08-15 09:00:12 -07:00
Slava Pestov
c26cafc47a AST: Remove bogus PackExpansionType logic in lookupConformance() 2023-08-09 18:28:22 -04:00
Pavel Yaskevich
27413f5624 [CSSimplify] Relax isBindable requirements for pack expansion variables
If type variable we are about to bind represents a pack
expansion type, allow the binding to happen regardless of
what the \c type is, because contextual type is just a hint
in this situation and type variable would be bound to its
opened type instead.

Resolves: rdar://112617922
2023-08-04 16:49:20 -07:00
Pavel Yaskevich
3dff3e5a49 [CSSimplify] Avoid eager matching between pack expansion and its contextual type
This is effectively a premature optimization. Contextual type might
not be fully resolved yet, so let's give solver a chance to do it for us.
2023-08-04 11:21:16 -07:00
Pavel Yaskevich
043d2aa3dd [CSSimplify] NFC: Straighten checking of type variable passed to resolvePackExpansion
The type variable should always be one for pack expansion type which
implies that locator always ends at `PackExpansionType`.
2023-08-03 14:11:09 -07:00
Hamish Knight
e22180ba2e [CS] Add missing break 2023-08-03 13:00:12 +01:00
Amritpan Kaur
3604551172 [CSSimplify] Handle keypathvalue constraint locator 2023-07-31 09:50:32 -07:00
Amritpan Kaur
36031f3b3d [CSSimplify] Prevent contextual type failure fix record 2023-07-31 09:50:27 -07:00
Pavel Yaskevich
9b3980573f Merge pull request #67297 from amritpan/build-out-resolve-kp
[ConstraintSystem] Set up keypath expressions typechecking
2023-07-27 09:52:09 -07:00
Amritpan Kaur
3140c12691 [CSSimplify] If keypath is malformed, do not attempt to 2023-07-26 20:32:30 -07:00
Amritpan Kaur
6296be7464 [CSSimplify] If bound type var is more optional
than a binding type var, attempt to match
types and solve.
2023-07-26 20:32:26 -07:00
Amritpan Kaur
5fa54dfc4d [CSSimplify] Delay matchTypes for key path values
until they are directly bound.
2023-07-25 22:16:28 -07:00
Pavel Yaskevich
b8915fa39a [CSSimplify] Repair should ignore situations where assignment source or destination are a hole
If either source or destination type is a hole conversion should
just be ignored because there is no r-value or other mismatch that
could be diagnosed in this case.
2023-07-24 12:09:04 -07:00
Pavel Yaskevich
9e388b40e1 [CSSimplify] Check that raw type is not a hole before checking RawRepresentable conformance
Placeholder types just like type variables are set up to return
a conformance ref which, in this case, would mean that we'd produce
an invalid diagnostic.
2023-07-24 11:15:50 -07:00
Pavel Yaskevich
33a37b9516 Merge pull request #67377 from xedin/rdar-112090069
[CSSimplify] Extend same-shape detection to account for pack archetypes
2023-07-24 10:01:29 -07:00
Pavel Yaskevich
eb86497493 [CSSimplify] Deplay member lookup until single-element tuple with pack expansion is sufficiently resolved
Such tuples should be treated specially because once pack expansion
is sufficiently resolved they'd get exploded and the resulting type
is what member lookup should use as a base.

Resolves: rdar://110721928
2023-07-21 13:10:34 -07:00
Pavel Yaskevich
5a5edcafc3 [CSSimplify] Extend same-shape detection to account for pack archetypes
`same-shape` mismatch detection logic shouldn't expect that types are
always packs because they could be either invalid (i.e. Void) or pack
archetypes too.

Resolves: rdar://112090069
2023-07-20 22:50:22 -07:00
Pavel Yaskevich
59908eeb0d [CSGen] Suppress favoring in presence of non-disfavored variadic generic overloads
Since this type of early favoring checks number of arguments and matches
labels it would always favor non-variadic overloads which is incorrect.
2023-07-20 10:02:59 -07:00
Sophia Poirier
8173c721eb [ConstraintSystem] remove TupleType::isSingleUnlabeledPackExpansion in favor of constraints::getPatternTypeOfSingleUnlabeledPackExpansionTuple 2023-07-19 15:10:40 -07:00
Amritpan Kaur
e7853368db [CSSimplify] Resolve key path expression
by creating a BoundGenericType for the keypath expr
with the keypath base and replacing the value with
the value typeVar that will be resolved when the value
typeVar is directly bound.
2023-07-18 15:16:07 -07:00