Commit Graph

517 Commits

Author SHA1 Message Date
Pavel Yaskevich
dba1b3436a [CSBindings] Diagnose leading-dot inference failure when base type is attempted as placeholder
Diagnose base inference failure only if base gets inferred to be
a placeholder, any transitive placeholder inference points to the
problem being elsewhere.
2023-05-01 14:19:14 -07:00
Pavel Yaskevich
53fdeb10b6 [ConstraintSystem] NFC: Print attributes/capabilities only for unbound type variables
Print bound type variables as `$T<Num> as <Type> @ <locator>` and
unbound ones as `$T<Num> [allows bindings to: ...] [attributes: ...] ... @ <locator>`
2023-04-10 19:15:43 -07:00
Pavel Yaskevich
8f2a9a7a9c [CSBindings] NFC: Log binding attempt failures
Currently we end up with an empty scope with no indication about
what actually happened i.e.:

```
(attempting type variable $T0 := Int
)
```
2023-04-06 22:53:53 -07:00
Pavel Yaskevich
c726b00741 [CSBindings] NFC: Format default bindings debug output
Default bindings should be printed as a comma separate list.
2023-03-13 14:01:48 -07:00
John McCall
db4b16e3dd [WIP] Always use PackTypes as the substitutions for type parameter packs
This simplifies the representation and allows clients to handle fewer
cases.  It also removes an ambiguity in the representation which could
lead us to have two canonical types for the same type.

This is definitely not working yet, but I'm not making progress on
it quickly enough to unblock what we need to unblock; it'll have to
be fixed in parallel.
2023-03-06 17:08:35 -08:00
Holly Borla
e6f29f8f93 Merge pull request #64119 from hborla/pack-expansion-shape-crash
[Diagnostics] Diagnose pack element expressions containing a non-pack a subexpression.
2023-03-05 10:11:02 -08:00
Holly Borla
8012e45109 [Diagnostics] Diagnose pack element expressions containing a non-pack subexpression. 2023-03-05 00:11:54 -08:00
Kavon Farvardin
091d63a5c8 revise how the Copyable constraint is added
The _Copyable constraint was implemented as a marker protocol.
That protocol is part of the KnownProtocol's in the compiler.
When `ASTContext::getProtocol(KnownProtocolKind kind)` tries
to find the ProtocolDecl for Copyable, it will look in the
stdlib module (i.e., Swift module), which is where I initially
planned to put it.

That created problems initially when some regression tests
use `-parse-stdlib` failed to do that protocol lookup, which is
essential for adding the constraint (given the current implementation).

That led to believe we need to pull Copyable out of the stdlib, but that's
wrong. In fact, when building the Swift module itself, we do `-parse-stdlib`
but we also include `-module-name Swift`. This causes the _Copyable protocol
defined in the Stdlib to be correctly discovered while building the stdlib
itself (see the test case in this commit). So, the only downside of
having the Copyable protocol in the Stdlib is that `-parse-stdlib` tests
in the compiler can't use move-only types correctly, as they'll be
allowed in generic contexts. No real program would build like this.

Until I have time to do a further refactoring, this is an acceptable trade-off.

fixes rdar://104898230
2023-03-04 11:42:09 -08:00
Pavel Yaskevich
fda7530418 [CSBindings] Relax early conjunction solving rule related to outer declarations
Instead of checking that there are no references to external declarations,
let's check that all of such declarations have their types resolved.
2023-02-15 00:25:44 -08:00
Pavel Yaskevich
5bb9d75e11 [CSBindings] Allow early conjunction solving if all of the contextual parameters are bound
Instead of allowing only disjunctions with no parameters, let's
use a contextual type to determine whether all of the parameters
have been inferred.
2023-02-15 00:24:17 -08:00
Pavel Yaskevich
38f8be1544 [CSBindings] Don't delay solving self-contained of result builder transformed closures
If a result builder transformed closure doesn't rely on any external
type information it could be solved right after it's resolved. We
determine that based on three criteria:

  - Builder type doesn't have any unresolved generic parameters;
  - Closure doesn't have any parameters;
  - The contextual result type is either concrete or opaque type.
2023-02-14 17:34:06 -08:00
Luciano Almeida
6e17e7b2ee [Sema] Record specify contextual type for nil in placeholder context 2023-01-21 01:19:55 -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
Holly Borla
2df72f6bcc [ConstraintSystem] Strip pack expansions off of pack reference types in
getUnopenedTypeOfReference.
2022-12-20 22:13:40 -05:00
Holly Borla
ea68720e12 [CSBindings] Instead of breaking a PackElementOf constraint down into Bind
constraints, vend potential bindings through PotentialBindings::infer.

This allows for bidirectional binding inference from the pack type to the
element type and vice versa.
2022-12-14 20:45:51 -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
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
Hamish Knight
f2404feb91 [CS] Factor out BindingSet::favoredOverConjunction
And refactor the way we select the next step for
a ComponentStep. This should be NFC.
2022-11-14 20:03:41 +00:00
Pavel Yaskevich
9b6ecf92ee [CSBindings] Fix early return condition in TypeVariableBinding::attempt
When `reportHole()` returns `true` it indicates a failure and
`attempt` has to return `false` right away.
2022-11-04 10:54:28 -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
Amritpan Kaur
daed9dfdf8 [CSBindings] Fix missing binding type vars. 2022-09-20 13:17:56 -07:00
Pavel Yaskevich
4edbaa4c1a Merge pull request #61103 from amritpan/format-fixes
[ConstraintSystem] Format fixes to the type inference debug output.
2022-09-15 09:28:28 -07:00
Pavel Yaskevich
164fa9c45d Revert "[ConstraintSystem] NFC: Remove obsolete ValueWitness constraint"
This reverts commit ef0523fe29.
2022-09-14 11:35:27 -07:00
Amritpan Kaur
254bd8262a [CSStep] Fix type variable printing inconsistency. 2022-09-12 13:07:37 -07:00
Amritpan Kaur
e7600fecb8 [CSBindings] Fix spacing issues in potential bindings.
Reformat direct bindings and default literal bindings to print as a list.
2022-09-02 08:16:32 -07:00
Amritpan Kaur
fefd952fe4 [CSBindings] Create struct to print Bindings/Literals. 2022-09-01 20:44:06 -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
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
Amritpan Kaur
d750d382fa [CSBindings] Consolidate BindingSet dump into single function. 2022-08-21 09:27:28 -07:00
Amritpan Kaur
6acae62c0c [NFC] Remove vector not in use. 2022-08-18 16:20:46 -07:00
Amritpan Kaur
cc1a835d9b [CSBindings] Add potential bindings that are inferred from literals to type variable and binding printing. 2022-08-18 16:20:44 -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
ac89df5c12 [CSFix] Generalize a fix for unresolved pattern decl
The fix should support both named (i.e. `test(a)` and "any" patterns
i.e. `test(_)`.
2022-08-03 15:50:33 -07:00
Amritpan Kaur
e9f18fe8d3 [CSBindings] Fix spacing issues with printing attributes. 2022-07-28 20:26:32 -07:00
Pavel Yaskevich
5a5c90478f Merge pull request #60205 from amritpan/add-atom-kind
[ConstraintSystem] Specify atom and collection literal kinds for type variable attributes.
2022-07-28 09:27:38 -07:00
Amritpan Kaur
3ae85ab0d2 [CSBindings] Print collection type in type variable attributes. 2022-07-27 10:04:25 -07:00
Amritpan Kaur
49a852b2e1 [CSBindings] Refactor getting KnownProtocolKind into new function for reuse when printing LiteralBindingKind::Collection type. 2022-07-26 19:33:20 -07:00
Amritpan Kaur
b43086b619 [ConstraintSystem] Convert collection literal kinds to string for printing. 2022-07-26 16:16:48 -07:00
Amritpan Kaur
66e34b7c2d [CSBindings] Print the specific atomic ExprKind in place of LiteralBindingKind::Atom. 2022-07-26 16:12:31 -07:00
Amritpan Kaur
0b9312d74b [ConstraintSystem] Convert atomic literal kinds to string for printing. 2022-07-26 16:08:26 -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
eba95bacbd [CS] Delay type resolution of variables for variables in named pattern 2022-07-20 09:46:14 +02:00
Amritpan Kaur
35b03463ff [CSBindings] Reformat defaults, defaultable, and involves-type-vars to match changes. 2022-07-12 15:19:28 -07:00
Amritpan Kaur
e80ca436cb [CSBindings] Reformat bindings list. 2022-07-12 15:19:28 -07:00
Amritpan Kaur
b416fa928b [CSBindings] Reformat type attributes. 2022-07-12 15:19:25 -07:00
Pavel Yaskevich
ef0523fe29 [ConstraintSystem] NFC: Remove obsolete ValueWitness constraint 2022-05-30 23:17:41 -07:00