Commit Graph

583 Commits

Author SHA1 Message Date
Slava Pestov
dfd172f1f3 Sema: Don't recompute BindingSets quite as much 2026-02-20 21:59:23 -05:00
Slava Pestov
e4339c9890 Sema: Refactor printing in determineBestBindings() to happen after 2026-02-20 21:59:23 -05:00
Slava Pestov
cfb1bacb92 Sema: Track BindingSet dirty state 2026-02-20 21:59:23 -05:00
Slava Pestov
ef9ef052cf Sema: Add BindingSet::operator!= for debugging 2026-02-20 19:34:03 -05:00
Slava Pestov
434b68b354 Sema: Add PotentialBindings::GenerationNumber 2026-02-20 19:32:36 -05:00
Slava Pestov
87550ab409 Sema: Rename hasConversions() to hasProperSubtypes() 2026-02-15 14:00:52 -05:00
Slava Pestov
54789c12c7 Sema: Split off Subtyping.cpp from CSBindings.cpp 2026-02-15 14:00:51 -05:00
Slava Pestov
c8ba1fd652 Sema: This can be a const reference 2026-02-12 13:30:36 -05:00
Slava Pestov
1b717b37d3 Merge pull request #86993 from slavapestov/move-code-around-in-solver
Sema: Move some code around
2026-02-05 16:16:20 -05:00
Pavel Yaskevich
8736860568 Merge pull request #86992 from xedin/dont-propagate-defaults-up
[CSBindings] Don't propagate defaults up the supertype chain
2026-02-05 07:02:14 -08:00
Slava Pestov
9036602aa1 Sema: Split off BindingProducer.h/.cpp 2026-02-05 09:19:01 -05:00
Slava Pestov
7cd06a5088 Sema: Split off TypeVariableType.h/.cpp 2026-02-05 09:19:01 -05:00
Pavel Yaskevich
ebc88a4875 [CSBindings] Don't propagate defaults up the supertype chain
Default bindings are local and shouldn't be moved because
that could lead to incorrect diagnostics.
2026-02-04 13:04:26 -08:00
Pavel Yaskevich
142ab3d017 [CSBindings] Filter leading-dot base types based on member lookup
If the transitively inferred protocol base type doesn't have a member
that was referenced via leading-dot syntax, let's filter it out from
the binding set during normal type-checking.

This helps to make sure that we don't attempt more than necessary
during normal type checking and prevents unrelated types from
interfering with type variable selection. These types are going
to be attempted in diagnostic mode still to make sure that any
typos or other user originated errors are properly diagnosed.

The test-case for this was added by c26ef041b8
2026-02-02 11:12:55 -08:00
Pavel Yaskevich
5fa2942948 Reapply "[CSBindings] PotentialBindings: Track only direct conformance requirements"
This reverts commit 2693a0a5e5.
2026-02-01 20:29:07 -08:00
Pavel Yaskevich
2693a0a5e5 Revert "[CSBindings] PotentialBindings: Track only direct conformance requirements"
This reverts commit f0af9c985c.
2026-01-27 10:55:53 -08:00
Slava Pestov
dfbce49ff7 Sema: Better -debug-constraints output in determineBestBindings() 2026-01-26 21:48:58 +00:00
Slava Pestov
d860523944 Merge pull request #86760 from slavapestov/solver-shuffle
Sema: Add -solver-shuffle-disjunctions= and -solver-shuffle-choices= flags for debugging
2026-01-24 12:30:43 -05:00
elsa
5e9f215f31 Merge pull request #86010 from elsakeirouz/rework-for-each-desugar
Rework ForEachStmt Desugaring
2026-01-24 13:55:51 +00:00
Slava Pestov
b36e17685c Sema: Generalize hasConversions() to getConversionBehavior() 2026-01-23 20:02:21 -05:00
Pavel Yaskevich
3db59a7b36 Merge pull request #86728 from xedin/dedupe-default-bindings
[CSBindings] PotentialBindings: De-duplicate defaults based on type
2026-01-23 13:29:09 -08:00
Pavel Yaskevich
fdcd3cb13c [CSBindings] PotentialBindings: De-duplicate defaults based on type
It's possible to infer the same default type from multiple different
default constraints, especially via transitive inference. Let's
de-duplicate direct and transitive default bindings based on a type
to avoid effects on type variable selection.

Resolves: rdar://168624965
2026-01-23 08:22:00 -08:00
Hamish Knight
d3270fdf1e [CS] Remove ValueWitness constraint
The specialized type-checking for `for` loops was the only client of
this, it's now unused.
2026-01-23 15:17:30 +00:00
Elsa Keirouz
075fa2a8f1 [CS] introduce ForEachElement constraint 2026-01-23 15:17:28 +00:00
Slava Pestov
a74d4c44c0 Sema: Export hasConversions() from CSBindings.cpp 2026-01-21 13:20:40 -05:00
Pavel Yaskevich
154d81e2d7 [CSBindings] Fix LiteralRequirement::isCoveredBy to not produce a type if it wasn't adjusted
Otherwise `determineLiteralCoverage` is going to re-introduce
the same binding if the type didn't actually change.
2026-01-16 16:04:01 -08:00
Pavel Yaskevich
86e88f50e6 [CSBindings] Don't use iterator after calling erase
There are few places where the binding is found, removed
and then re-inserted with a different type. The new
binding should be formed before `erase` is called and
iterator is mutated otherwise using the old iterator
point could lead to corruption.

In the added test-case `determineLiteralCoverage`
would find a "supertypes of" binding and attempt to
remove + re-insert it but it ends up as "subtypes of"
after that because calling `.erase` moves the iterator.
2026-01-16 15:15:18 -08:00
Pavel Yaskevich
fe8a30b119 [CSBindings] PotentialBindings: Track each individual change in the trail
Instead of "catch call" `InferredBindings` that calls `retract` on
`undo`, let's track each mutation of the potential bindings with a
dedicated trail node and undo each individually. This change reduced
the amount of work that `undo` has to make on every scope rollback
and would help helpful for transitive binding inference as well.
2026-01-12 10:36:58 -08:00
Pavel Yaskevich
2ccab72e57 [CSBindings] PotentialBindings: Introduce record* methods to record changes in associations
Instead of adding elements directly, let's encapsulate that in
`record{AdjacentVar, Protocol, Default, ...}` methods and use
them instead, it's staging for the granular dependency tracking.
2026-01-12 09:39:30 -08:00
Pavel Yaskevich
28e0924108 [CSBindings] PotentialBindings: Track constraint system and type variable association
This is going to help record individual property changes (i.e.
defaults, subtype/supertype/equality etc.) in the solver trail.
2026-01-12 09:21:13 -08:00
Pavel Yaskevich
59c1929529 [CSTrail] Define addition/retraction macros for common binding information
`DelayedBy`, `Protocols`, and `Defaults` all operate on constraints
and so could have templated implementation.
2026-01-09 17:06:07 -08:00
Pavel Yaskevich
eda539e0ad [CSTrail] Add a macro that handles binding relation retraction 2026-01-09 15:41:26 -08:00
Pavel Yaskevich
986b1dd6fd [CSBindings] PotentialBindings: Track only direct default and fallback constraints
When a type variable is bound its constraints are introduced to all
of the type variables referenced by the new fixed type. That includes
default/fallback constraints as well, but referenced variables shouldn't
track them, because they apply only to the variable they are associated
with and its supertypes.
2026-01-08 14:12:38 -08:00
Pavel Yaskevich
f0af9c985c [CSBindings] PotentialBindings: Track only direct conformance requirements
When a type variable is bound its constraints are introduced to all
of the type variables referenced by the new fixed type. That includes
conformances as well, but referenced variables shouldn't track
them, because they apply only to the variable they are associated with
and its supertypes.
2026-01-08 13:45:11 -08:00
Pavel Yaskevich
97fd2786dc [CSBindings] PotentialBindings: Track only direct literal requirements
When a type variable is bound its constraints are introduced to all
of the type variables referenced by the new fixed type. That includes
literal conformances as well, but referenced variables shouldn't track
them, because they apply only to the variable they are associated with
and its supertypes.
2026-01-08 13:44:56 -08:00
Pavel Yaskevich
6dece8a817 Merge pull request #86072 from xedin/originator-in-the-binding
[CSBindings] Store the originator type variable in a transitive binding
2025-12-16 09:07:10 -08:00
Pavel Yaskevich
91eefb953e [CSBindings] Store the originator type variable in a transitive binding
Instead of using a flag in `addBinding`, let's record what type variable
does the binding belong to in `PotentialBinding` itself. This is going
to help remove bindings introduced transitively when the inference is
done lazily.
2025-12-15 13:59:36 -08:00
Slava Pestov
9a68d4aabe Sema: De-duplicate defaults in inferTransitiveSupertypeBindings()
This is necessary now that BindingSet::Defaults is a vector and
not a set.
2025-12-14 11:44:45 -05:00
Slava Pestov
77ee3dab7d Sema: Collect LiteralRequirements in PotentialBindings::infer() 2025-12-13 21:16:43 -05:00
Slava Pestov
88f347a000 Sema: Collect defaults in PotentialBindings::infer() 2025-12-13 21:16:43 -05:00
Slava Pestov
74fa1e7f5e Sema: BindingSet::Literals can just be a vector and not a map 2025-12-13 21:16:43 -05:00
Slava Pestov
6c1593a015 Sema: Stash the ProtocolDecl inside the LiteralRequirement 2025-12-13 21:16:43 -05:00
Slava Pestov
88d04b5baa Sema: Extract coalesceIntegerAndFloatLiteralRequirements() from BindingSet::BindingSet, and do it at the end 2025-12-13 21:16:43 -05:00
Slava Pestov
36c7263d26 Sema: Factor out isDirectRequirement() from two places that check this 2025-12-13 21:16:43 -05:00
Slava Pestov
6384c27e8e Sema: BindingSet::Defaults can just be a vector and not a map
The only place where we did a lookup, we also iterated over it anyway,
and all remaining usages are simplified by downgrading it to a vector.
2025-12-13 21:16:43 -05:00
Slava Pestov
01ca51903b Sema: Sink Protocols down from BindingSet into PotentialBindings 2025-12-13 14:50:48 -05:00
Slava Pestov
ba7df4013e Sema: Avoid copying BindingSets
They're stored inside the ConstraintGraphNode now, so returning a
`const BindingSet *` from within determineBestBindings() should
be safe.
2025-12-10 18:48:00 -05:00
Slava Pestov
3c4fef164e Sema: Add some LLVM_DEBUG output to CSBindings.cpp 2025-12-09 09:44:52 -05:00
Slava Pestov
25d9829af9 Sema: Remove incorrect usage of big-O notation from comment 2025-12-09 09:43:22 -05:00
Slava Pestov
563ba95a7d Sema: Move definition of hasConversions() before its first use 2025-12-08 10:12:13 -05:00