Commit Graph

1645 Commits

Author SHA1 Message Date
Pavel Yaskevich
c7ba055c38 [ConstraintSystem] Handle ambiguities caused by requirement failures
Aggregate all requirement failures (regardless of kind) that belong
to the same locator and diagnose them as an ambiguity (if there is
more than one overload) or as the singular failure if all solutions
point to the same overload.
2023-01-26 15:55:50 -08:00
Hamish Knight
76da268b4b [CS] Debug: Print ASTNode for contextual type
If we don't have an associated TypeRepr for a
contextual type in the constraint system, dump the
ASTNode that it's for instead.

Before:

```
Contextual Type: $T2
```

After:

```
Contextual Type: $T2 at DeclRef@/Users/hamish/src/swift-test-arena/swift-test-arena/main.swift:1493:21
```
2023-01-26 17:21:49 +00:00
Holly Borla
94abc252bf [Macros] Type-check attached macro arguments. 2023-01-22 11:26:02 -08:00
Luciano Almeida
e513d23c0b [Sema] Improving global actor function mismatch diagnostic 2023-01-13 20:47:23 -03:00
Holly Borla
2d893d23bf [GenericEnvironment] For opened pack element environments, only include element type
parameters whose originating packs are in a given shape equivalence class.
2023-01-08 12:59:08 -08:00
Holly Borla
715de13dbf [Sema] Key opened pack element generic on the shape class of the expansion. 2023-01-07 15:07:51 -08:00
Holly Borla
6e28f996ce [ConstraintSystem] Create opened pack element generic environments lazily
in the constraint system.
2023-01-07 09:50:14 -08:00
Anthony Latsis
ad5d55c36e [NFC] AST: Rename IdentTypeReprDeclRefTypeRepr 2023-01-07 07:14:44 +03:00
Anthony Latsis
2113e175f5 [NFC] AST: Remove IdentTypeRepr::ComponentRange 2023-01-07 07:11:30 +03:00
Pavel Yaskevich
2e25c2fc80 Merge pull request #62791 from xedin/rdar-103739206
[Diagnostics] Relax contextual type presence from assertion to a check
2023-01-04 09:47:19 -08:00
Doug Gregor
71ca9c86e6 [Macros] Diagnose when we forget to provide macro arguments.
Unlike functions, you can't curry macros; diagnose when one omits the
arguments in a macro expansion of a macro that has a parameter list.
2023-01-02 21:22:04 -08:00
Doug Gregor
806b5a8777 [Macros] Diagnose errors where a macro is used without the '#'. 2023-01-02 21:22:04 -08:00
Pavel Yaskevich
eaf0532a04 [Diagnostics] Relax contextual type presence from assertion to a check
In some situations `getContextualType` for a contextual type
locator is going to return then empty type. This happens because
e.g. optional-some patterns and patterns with incorrect type don't
have a contextual type for initialization expression but use
a conversion with contextual locator nevertheless to indicate
the purpose. This doesn't affect non-ambiguity diagnostics
because mismatches carry both `from` and `to` types.

Resolves: rdar://problem/103739206
2023-01-02 21:11:07 -08:00
Holly Borla
42ede18fb0 Merge pull request #62713 from hborla/open-pack-element-type-repr
[ConstraintSystem] Enable pack element type reprs in expressions.
2022-12-21 10:48:42 -05:00
Holly Borla
58953567b3 [CSGen] Use PackExpansionExpr::getExpandedPacks to generate ShapeOf constraints
rather than relying on PackElementExprs collected by preCheck.

This handles pack element expressions and pack element type reprs, and enforces that
all packs expanded by a given pack expansion expression all have the same shape.

Once the parser creates PackExpansionExpr directly (based on a dedicated syntax instead
of postfix '...'), the code in preCheck for identifying and creating pack expansions
can simply be deleted.
2022-12-20 22:34:16 -05:00
Holly Borla
2df72f6bcc [ConstraintSystem] Strip pack expansions off of pack reference types in
getUnopenedTypeOfReference.
2022-12-20 22:13:40 -05:00
Holly Borla
454913aeb5 [TypeResolution] Plumb a pack element opener function through type resolution. 2022-12-20 11:36:58 -05:00
Doug Gregor
402ba1492f Set closure descriminators via a request.
Rather than set closure discriminators in both the parser (for explicit
closures) and then later as part of contextualizing closures (for
autoclosures), do so via a request that sets all of the discriminators
for a given context.
2022-12-19 15:23:45 -08:00
Holly Borla
dc941de45e [ConstraintLocator] Add a locator path element that stores an opened pack element
generic signature.
2022-12-14 20:45:51 -08:00
Pavel Yaskevich
850c280df9 Merge pull request #62529 from xedin/fix-participates-in-inference
[ConstraintSystem] Result builder transformed closures always partici…
2022-12-13 12:46:10 -05:00
Alex Hoppen
58aaa4f111 Merge pull request #62522 from ahoppen/ahoppen/rename-completion
[IDE] Rename CodeCompletion to IDEInspection in cases where the code path no longer exclusively applies to code completion
2022-12-13 16:40:28 +01:00
Alex Hoppen
fe2ae72ad2 [IDE] Rename CodeCompletion to IDEInspection in cases where the code path no longer exclusively applies to code completion
The code completio infrastructure is also being used for cursor info now, so it should no longer be called code completion.

rdar://103251187
2022-12-13 11:41:05 +01:00
Pavel Yaskevich
a7c66ee849 [ConstraintSystem] Result builder transformed closures always participate in inference 2022-12-12 11:00:08 -08:00
Pavel Yaskevich
7166f193b5 [ConstraintSystem] Reject property wrapper transform on func parameters in pattern context
The transform is not currently supported on anything but regular calls.
2022-12-09 15:47:57 -05: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
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
Timofey Solonin
3f366947e4 Improve indentation in debugging output 2022-11-17 23:25:31 +08:00
Holly Borla
72d87b5ca5 [ConstraintSystem] Add a locator path element for the pattern of a pack expansion. 2022-11-16 09:06:58 -08:00
Holly Borla
5218a0d77a [ConstraintSystem] Add a locator path element for pack shapes, and use it for
type variables representing pack shapes.
2022-11-15 21:33:17 -08:00
Doug Gregor
bdf7762f55 [Macros] Start threading argument labels through macros. 2022-11-13 14:38:07 -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
Doug Gregor
5ab6b72604 [Macros] Turn Macro into a declaration node.
Although the declaration of macros doesn't appear in Swift source code
that uses macros, they still operate as declarations within the
language. Rework `Macro` as `MacroDecl`, a generic value declaration,
which appropriate models its place in the language.

The vast majority of this change is in extending all of the various
switches on declaration kinds to account for macros.
2022-11-13 12:21:29 -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
Allan Shortlidge
429f19a4b6 Revert "[ConstraintSystem] Extend availability check to cover unavailable extensions."
This reverts commit 6de6de2e3a.
2022-11-01 17:00:33 -07:00
Robert Widmann
0fc80dc498 Refactor Macro Context Lookup Into a Request 2022-10-27 11:11:12 -07: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
Doug Gregor
4932c021f4 Avoid concurrency-related adjustments during witness matching
We were only applying this logic for some declaration types, not all,
which is silly. Fixes https://github.com/apple/swift/issues/61602 /
rdar://101243966.
2022-10-26 21:43:25 -07:00
Slava Pestov
731d903a43 Sema: Add ConstraintKind::ShapeOf 2022-10-25 12:55:04 -04:00
Slava Pestov
f3fcc44d17 Sema: Handle PackElement locator in repairFailures() 2022-10-21 22:17:38 -04:00
Slava Pestov
afbf844b83 Sema: Implement support for projecting member types from PackType in simplifyType() 2022-10-21 22:17:38 -04:00
Slava Pestov
55210f6cae Sema: Introduce TVO_CanBindToPack type variable flag 2022-10-16 21:37:25 -04:00
Holly Borla
67fb143f0e [AST] Remove ReifyPackExpr. 2022-10-10 16:25:26 -07:00
Holly Borla
38a2c8218b [Requirement] Rename RequirementKind::SameCount to SameShape. 2022-10-06 20:48:40 -07:00
Hamish Knight
bca941b152 [AST] NFC: Rename IfExpr -> TernaryExpr
This matches what we call it in SwiftSyntax, and
is just generally clearer.
2022-09-28 10:33:31 +01:00
Allan Shortlidge
6de6de2e3a [ConstraintSystem] Extend availability check to cover unavailable extensions.
Instead of checking for unavailability attributes directly in the solver, use `AvailableAttr::isUnavailable` which checks the enclosing extension too, if necessary.

Resolves rdar://92364955
2022-09-21 18:26:57 -07:00
Luciano Almeida
be25419bc3 [Sema] Accept IgnoreCollectionElementContextualMismatch in conflict generic diagnostics 2022-09-20 21:24:16 -03: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
Slava Pestov
67d3ede5c7 Sema: Teach the solver to find members of tuples 2022-09-10 00:26:42 -04: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