Commit Graph

339 Commits

Author SHA1 Message Date
Hamish Knight
db2a9a470b Merge pull request #60803 from hamishknight/part-and-partial 2022-08-31 14:57:53 +01:00
Holly Borla
ca08b56fd3 Merge pull request #60844 from hborla/generic-result-builder
[ConstraintSystem] Before applying the result builder transform to a function body, map the result builder type into context.
2022-08-30 08:06:58 -07:00
swift-ci
a66951aa3d Merge pull request #60521 from kavon/preconcurrency-var-access
Add missing function conversion for member access to preconcurrency vardecl.
2022-08-30 00:58:49 -07:00
Holly Borla
8ba51888c6 [ConstraintSystem] Before applying the result builder transform to a
function body, map the result builder type into context.

This was already done for inferred result builder attributes; now,
the constraint system will map the builder type into context for all
result builder attributes applied to computed properties/functions.
2022-08-29 22:13:13 -07:00
Kavon Farvardin
e70fbbc738 [ConstraintSystem] correct the @preconcurrency adjustment of var references
We intended to introduce AST conversions that strip concurrency
attributes off of types associated with `@preconcurrency` decls.
But for VarDecl references, we stripped it too early, leading to
things like a MemberVarDecl that doesn't have `@Sendable` in its
result type, but the VarDecl it refers to does have it.

That caused crashes in SIL where types didn't match up. This patch
fixes things by delaying the stripping until the right point.

resolves rdar://98018067
2022-08-29 20:58:25 -07:00
Hamish Knight
cebcbb0767 [CS] Improve diagnostics when buildPartialBlock is unavailable
If `buildBlock` is also unavailable, or the
builder itself is unavailable, continue to solve
using `buildPartialBlock` to get better
diagnostics.

This behavior technically differs from what is
specified in SE-0348, but only affects the invalid
case where no builder methods are available to use.

In particular, this improves diagnostics for
RegexComponentBuilder when the deployment target
is too low. Previously we would try to solve using
`buildBlock` (as `buildPartialBlock` is unavailable),
but RegexComponentBuilder only defines `buildBlock`
for the empty body case, leading to unhelpful
diagnostics that ultimately preferred not to use
the result builder at all.

rdar://97533700
2022-08-26 19:45:03 +01:00
Hamish Knight
dd1da22b16 [CS] Separate availability checking from SupportedOps cache
Previously we would cache the result of the first
query, with any further query of
`ResultBuilder::supports` ignoring the
`checkAvailability` parameter. Separate out the
availability checking such that we compute the
information up front, and adjust the result
depending on `checkAvailability`.
2022-08-26 19:45:02 +01:00
Amritpan Kaur
51281c54c4 [CSBindings] Move binding printing out of determineBestBindings and check that bindings exist before printing. 2022-08-22 16:26:45 -07:00
Pavel Yaskevich
d1271d67c3 Merge pull request #60584 from xedin/rdar-98304482
[ConstraintSystem] Don't produce argument info object for extraneous …
2022-08-17 09:09:54 -07:00
Pavel Yaskevich
3fd9037ee9 [ConstraintSystem] Don't produce argument info object for extraneous arguments
An extraneous argument doesn't have a corresponding parameter so the
information object for such an argument is not safe to produce.

Resolves: https://github.com/apple/swift/issues/60436
Resolves: rdar://98304482
2022-08-16 16:22:02 -07:00
Pavel Yaskevich
389cfe7f65 [ConstraintSystem] NFC: Check whether opened type has a binding before printing
In some circumstances opened type might not have a fixed binding.
A good example could be dependent sub-component produced for
result builder transformed code (connected via one-way constraints),
in such a case `OpenedTypes` would have outer generic parameters
but they might not be bound yet, so they have to be printed as
type variables.
2022-08-12 17:29:29 -07:00
Amritpan Kaur
fd41a39294 [ConstraintSystem] Refactor solver state depth to its own function for easier indent editing in future. 2022-08-10 13:29:02 -07:00
Pavel Yaskevich
42135e27c4 Merge pull request #60387 from amritpan/improve-solution-printing
[ConstraintSystem] Improve solution printing in the type inference algorithm debug output
2022-08-10 09:03:29 -07:00
Amritpan Kaur
95e5440d66 [ConstraintSystem] Edit ScoreKind descriptions and print ScoreKind increase values. 2022-08-09 14:10:15 -07:00
Amritpan Kaur
d07d39045d [ConstraintSystem] Move getScoreKindName to ConstraintSystem for use across CS and create new function for printing non-zero ScoreKinds.
You are currently editing a commit while rebasing branch 'improve-solution-printing' on '538ee30efb5'.
2022-08-09 14:10:15 -07:00
Pavel Yaskevich
186bf0ab3b [BuilderTransform] Cache previously applied transforms
Since result builder is just an AST transformation, the result
of a successful transform could be cache and reused with a different
`$__builderSelf` type.
2022-08-02 11:59:03 -07:00
Pavel Yaskevich
04952fdc0a [TypeChecker] Implement result builder transform via AST modification
The transform changes closure body into a multi-statement closure
with all of the implicit result builder calls and type-checks it
like a regular closure.

There are a couple of result builder specific changes mentioned below,
otherwise the logic to generate constraints and apply solutions is
unchanged:

- Placeholder variable: A variable declaration that doesn't have a
  type deduced and infers it from its first use. If such a variable
  has an initializer, it would be type-checked during solution application.

- TypeJoinExpr - an implicit expression that refers to a "join" variable
  and a set of expressions that should all produce the same type that
  becomes a type of a "join" variable.
2022-08-02 11:59:03 -07:00
Pavel Yaskevich
22ab6ec13a [ConstraintSystem] Augment AppliedBuilderTransform to reference transformed body
If result builder AST transform is enabled, let builder transform descriptor
carry tranformed body for ease of access during solution application.
2022-08-02 11:41:40 -07:00
Pavel Yaskevich
96e6952104 [CSClosure] Teach syntactic element constraint generator about result builders
Closures and functions that have result builder transform applied have to be
handled specially by the constraint generator because transformed body is
associated with the context (function or closure) only during solution application.
2022-08-02 11:41:40 -07:00
Pavel Yaskevich
432ce1cf4e [ConstraintSystem] Allow placeholder vars to have initializer and nested holes
Initializers of such variables are going to be type-checked post factum,
when the type of the variable itself has been determined by the solver.
2022-08-02 11:41:40 -07:00
Pavel Yaskevich
a0693f3dbe [ConstraintSystem] Switch applySolutionToBody to accept AnyFunctionRef
Result builder body could be either a closure or function e.g. accessor,
which means that solution application needs to handle both.
2022-08-02 11:41:40 -07:00
Pavel Yaskevich
319668dca2 [ConstraintSystem] Make it possible to storage AnyFunctionRef targets 2022-08-02 11:03:26 -07:00
Pavel Yaskevich
0457a72fdf Merge pull request #60222 from xedin/rdar-97396399
[ConstraintSystem] Retrieve contextual type from a solution for ambiguities
2022-07-28 09:28:09 -07:00
Hamish Knight
fe7c1f4b9b Refactor callable lookup
Move off `Type` based requests and onto `Decl`
based requests, utilizing name lookup's
`extractDirectlyReferencedNominalTypes` utility.
This allows us to better cache the results, and
avoids the need to guard against type variable
inputs when deciding whether or not to cache.
2022-07-25 22:03:55 +01:00
Pavel Yaskevich
b07c887e02 [ConstraintSystem] Retrieve contextual from a solution for ambiguities
In ambiguity scenarios solutions are not applied back to the constraint
system, so it might not always have contextual type information when it
was recorded e.g. for a multi-statement closure.

Resolves: rdar://97396399
2022-07-25 09:28:22 -07:00
Jonathan Penn
be5babf28c Add experimental flag to turn on just opaque type erasure (#60172)
This was already enabled as part of `-enable-implicit-dynamic` but this
new flag allows turning on opaque type erasure all by itself whether or
not `dynamic` is added explicitly.

rdar://97375478
2022-07-22 23:43:22 -04:00
Pavel Yaskevich
b23e5dcb93 Merge pull request #60164 from amritpan/fix-conjunction-indentations
[ConstraintSystem] Fix indentations of AST in Conjunction Steps.
2022-07-22 09:32:42 -07:00
Amritpan Kaur
64800d576e [Constraint] Pass solverState indents to ASTPrinter's dump so that AST printed during conjunction attempts are indented correctly. 2022-07-21 13:34:22 -07:00
Alex Hoppen
f623440f01 [CS] Disfavor solutions that were unable to infer the variable type inside a named pattern
We need this to resolve a test failure in optional.swift.
2022-07-20 09:47:16 +02:00
Alex Hoppen
944c3b5a39 Merge pull request #59915 from ahoppen/pr/solutionapplicationtarget-dump
[Sema] Add dump function to dump SolutionApplicationTargetsKey
2022-07-14 15:46:31 +02:00
Amritpan Kaur
ff2507be24 [ConstraintSystem] Convert TypeVariableOptions enum to String for use in printing. 2022-07-12 14:26:02 -07:00
Anthony Latsis
d74384cfcf Merge pull request #59931 from AnthonyLatsis/close-issues-3
Add regression tests to close several issues p. 3
2022-07-12 15:11:52 +03:00
Anthony Latsis
0a2293fd41 CSRanking: Check for timeouts during solution comparisons, which are time-consuming 2022-07-12 02:33:48 +03:00
Doug Gregor
db14ab140f Sink concurrency constraint fix behavior logic into "attempt" functions.
This is a cleaner pattern for the solver, thanks Pavel!
2022-07-08 13:33:14 -07:00
Doug Gregor
4fc4bd79e8 [Constraint solver] Track "isolated by preconcurrency" in the solver.
Rather than only setting the isolated-by-preconcurrency bit during
constraint application, track the closures it will be set for as part
of the constraint system and solution. Then, use that bit when
performing "strict concurrency context" checks and type adjustments,
so we don't treat an inferred-to-by-`@Sendable`-by-preconcurrency
closure in the solver as if it weren't related to preconcurrency.

Fixes the spurious warning from
https://github.com/apple/swift/issues/59910.
2022-07-07 23:46:30 -07:00
Doug Gregor
2e3aa67c02 [Constraint solver] Treat downgraded errors as "disfavored overloads".
This allows us to still maintain them in the score kind, but not treat
them as being as severe as an error requiring a fix.
2022-07-07 18:12:56 -07:00
Alex Hoppen
da07d2deb2 [Sema] Add dump function to dump SolutionApplicationTargetsKey 2022-07-07 09:58:48 +02:00
Holly Borla
48ada412b7 Merge pull request #59821 from hborla/remove-reuse-prechecked-type
[ConstraintSystem] Remove `ConstraintSystemFlags::ReusePrecheckedType`.
2022-07-01 08:12:47 -07:00
Doug Gregor
248b72bbff Track the pre-adjusted "reference" type for declaration reference. 2022-06-30 17:00:32 -07:00
Doug Gregor
1063e8126e [Constraint system] Track the original opened type for a selected overload. 2022-06-30 17:00:31 -07:00
Doug Gregor
045df94bca Delay @preconcurrency-related type adjustments until the last moment.
This allows us to retain the full opened type before adjustment when
needed, but should otherwise not change anything.
2022-06-30 16:59:54 -07:00
Holly Borla
38d81584e0 [ConstraintSystem] Remove ConstraintSystemFlags::ReusePrecheckedType. 2022-06-30 13:30:58 -07:00
Pavel Yaskevich
3fd3ff0637 [TypeChecker] Adjust Double<->CGFloat conversion to always preserve its location
Unfortunately current approach of making a conversion independent of location
doesn't work when conversion is required for multiple arguments to the
same call because solver expects that either there are no Double<->CGFloat
conversions, or one of them has already been applied which is not the case.

The reason why locations weren't preserved in the first place is due to
how a solution is applied to AST - AST is mutated first and then, if there
are any conversions, they are applied to the already mutated version of
original AST. This creates a problem for Double<->CGFloat which depends
on an overload choice of injected call and it's impossible to find it based
on the mutated AST. But it turns out that this is only an issue in two
specific cases - conversions against contextual type and after optional injection.
This situations could be mitigated by dropping parts of the locator which are
unimportant for the Double<->CGFloat conversion - anchor in case of contextual
and `OptionalPayload` element(s) in case of optional injection.

Resolves: https://github.com/apple/swift/issues/59374
2022-06-28 13:47:47 -07:00
Pavel Yaskevich
ef0523fe29 [ConstraintSystem] NFC: Remove obsolete ValueWitness constraint 2022-05-30 23:17:41 -07:00
Pavel Yaskevich
b7860ea055 [TypeChecker] Split for-in sequence into parsed and type-checked versions 2022-05-30 23:17:41 -07:00
Pavel Yaskevich
86165291aa [TypeChecker] Change the way for-in statement in type-checked
Instead of asking SILGen to build calls to `makeIterator` and
`$generator.next()`, let's synthesize and type-check them
together with the rest of for-in preamble. This greatly simplifies
interaction between Sema and SILGen for for-in statements.
2022-05-30 23:17:41 -07:00
Pavel Yaskevich
3327559758 [TypeChecker] IDE: Adjust typeCheckForCodeCompletion to support all targets
The dependency on target being an expression is artificial,
`typeCheckForCodeCompletion` is capable of type-checking any
type of target.
2022-05-30 23:17:41 -07:00
Pavel Yaskevich
22daa865b5 [ConstraintSystem] Make for-in solution application target standalone
Previously for-in target was actually an expression target, which means
certain type-checking behavior. These changes make it a standalone target
with custom behavior which would allow solver to introduce implicit
`makeIterator` and `next` calls and move some logic from SILGen.
2022-05-30 23:17:41 -07:00
Pavel Yaskevich
2c140bdf4d Merge pull request #58503 from xedin/rdar-92366212
[ConstraintSystem] Fail `~=` synthesis if constraint generation fails
2022-04-29 10:19:01 -07:00
Pavel Yaskevich
b0f7aefb8e [ConstraintSystem] NFC: Warn if result of generate* is unused
Not checking success of constraint generation could lead to crashes
e.g. when follow-up code accesses something that hasn't been processed
due to error.
2022-04-28 18:02:08 -07:00