Commit Graph

359 Commits

Author SHA1 Message Date
Timofey Solonin
3f366947e4 Improve indentation in debugging output 2022-11-17 23:25:31 +08:00
Robert Widmann
394d0645d9 Tidy Up The C AST Bridging File A Bit 2022-10-27 11:11:12 -07:00
Robert Widmann
822fd47b8a Add Utilities to Retrieve the (Opened) Type of a Macro Reference 2022-10-27 11:11:11 -07:00
Slava Pestov
731d903a43 Sema: Add ConstraintKind::ShapeOf 2022-10-25 12:55:04 -04:00
Holly Borla
032c511754 [ConstraintSystem] Add a PackElementOf constraint to delay mapping opened
element pattern types to pattern archetypes until after type variables are
resolved.
2022-10-24 19:46:44 -07:00
Slava Pestov
46d5fa68f9 Sema: Introduce ConstraintKind::SubclassOf 2022-10-21 22:17:38 -04:00
Slava Pestov
4e70f4fb19 Sema: Simplify matching logic for PackExpansionType 2022-10-17 23:23:09 -04:00
Slava Pestov
55210f6cae Sema: Introduce TVO_CanBindToPack type variable flag 2022-10-16 21:37:25 -04:00
Slava Pestov
0dfdf1ca02 Sema: Remove unused function prototype 2022-10-16 21:37:25 -04:00
Slava Pestov
9ae9c369a5 Sema: Remove unnecessary overload of computeTupleShuffle() 2022-10-16 21:37:24 -04:00
Holly Borla
c4b946195e [AST] Replace the "type sequence" terminology with "parameter pack". 2022-10-10 16:28:13 -07:00
Amritpan Kaur
3f03712788 [ConstraintSystem] Nest simplification result inside new block.
Nest failed, added, and removed constraints inside block called
`simplification result`.
2022-09-16 09:17:22 -07:00
Amritpan Kaur
d8943c3105 [Constraint] Add indentations to conj/disjunction printing.
This indents added/removed conj/disjunction constraints
and AST printed with conjunctions.
2022-09-16 09:17:22 -07:00
Amritpan Kaur
a4320d1bad [ConstraintSystem] Print added/removed constraints. 2022-09-16 09:17:22 -07:00
Pavel Yaskevich
164fa9c45d Revert "[ConstraintSystem] NFC: Remove obsolete ValueWitness constraint"
This reverts commit ef0523fe29.
2022-09-14 11:35:27 -07:00
Hamish Knight
4716f61fba [AST] Introduce explicit actions for ASTWalker
Replace the use of bool and pointer returns for
`walkToXXXPre`/`walkToXXXPost`, and instead use
explicit actions such as `Action::Continue(E)`,
`Action::SkipChildren(E)`, and `Action::Stop()`.
There are also conditional variants, e.g
`Action::SkipChildrenIf`, `Action::VisitChildrenIf`,
and `Action::StopIf`.

There is still more work that can be done here, in
particular:

- SourceEntityWalker still needs to be migrated.
- Some uses of `return false` in pre-visitation
methods can likely now be replaced by
`Action::Stop`.
- We still use bool and pointer returns internally
within the ASTWalker traversal, which could likely
be improved.

But I'm leaving those as future work for now as
this patch is already large enough.
2022-09-13 10:35:29 +01:00
Pavel Yaskevich
e8b840c5ce Merge pull request #60927 from amritpan/update-score-labels
[ConstraintSystem] Update score labels
2022-09-02 16:54:55 -07:00
Pavel Yaskevich
7f08d408ef Merge pull request #60443 from amritpan/improve-solver-step-printing
[ConstraintSystem] Improve solver step printing in the type inference algorithm debug output
2022-09-02 15:53:23 -07:00
Amritpan Kaur
d3e9eaa805 [ConstraintSystem] Add labels to ScoreKinds types and local Score value. 2022-09-01 20:47:00 -07:00
Amritpan Kaur
7c3cb4f570 [CSBindings] Fix double printing of type variables.
Fix spacing when printing initial Type Variables. Add
line break to bindings that print under Potential Bindings.
2022-09-01 20:44:04 -07:00
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