Commit Graph

672 Commits

Author SHA1 Message Date
Erik Eckstein
d89c6b2d70 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-01 07:48:51 +01:00
Pavel Yaskevich
6b3776456c Merge pull request #62053 from abdulowork/improve-type-checker-debugging-indentation
Improve indentation in type checker debugging output
2022-11-30 12:11:27 -08:00
swift-ci
1acf8b039b Merge remote-tracking branch 'origin/main' into rebranch 2022-11-29 10:14:02 -08:00
Doug Gregor
8adee85cb6 [Macros] Add support for explicit generic arguments of macros.
Enable type checking support for explicitly specifying generic arguments to
a macro, e.g., `#stringify<Double>(1 + 2)`. To do so, introduce a new
kind of constraint that performs explicit argument matching against the
generic parameters of a macro only after the overload is chosen.
2022-11-28 18:32:43 -08:00
swift-ci
efef52a86e Merge remote-tracking branch 'origin/main' into rebranch 2022-11-28 09:33:40 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Rintaro Ishizaki
d458c8b74a Merge remote-tracking branch 'origin/main' into rebranch
Conflicts:
	include/swift/Sema/ConstraintSystem.h
	include/swift/Syntax/AbsoluteRawSyntax.h
	include/swift/Syntax/Syntax.h
	include/swift/Syntax/SyntaxData.h
	lib/DependencyScan/ModuleDependencyCacheSerialization.cpp
	lib/Syntax/SyntaxFactory.cpp.gyb
	lib/Syntax/SyntaxNodes.cpp.gyb
	tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp
	tools/swift-syntax-test/swift-syntax-test.cpp
2022-11-18 09:37:38 -08:00
Timofey Solonin
3f366947e4 Improve indentation in debugging output 2022-11-17 23:25:31 +08:00
Angela Laar
b4549d63f0 [Constraint System] Refactor generateConstraints
We don't need a separate generateConstraints function for closures.
2022-11-15 16:13:58 -08:00
swift-ci
c6a647ae06 Merge remote-tracking branch 'origin/main' into rebranch 2022-11-13 20:33:41 -08:00
Doug Gregor
1aa907500f [Macros] Use the macro recorded in the constraint system for expansion.
Rather than lookup up the macro by name again during constraint
application, use the overload choice for the macro as recorded in the
constraint system to apply the correct macro.
2022-11-13 13:46:42 -08:00
swift-ci
e65fa9c45d Merge remote-tracking branch 'origin/main' into rebranch 2022-11-11 22:52:44 -08:00
Doug Gregor
16f81fbad5 Introduce a Macro AST type and use it to describe the macros we find 2022-11-11 15:24:37 -08:00
Erik Eckstein
54fe1304a1 replace LLVM_NODISCARD -> [[nodiscard]]
This is possible because we are now compiling with the C++17 standard.
2022-11-04 20:44:18 +01: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