Commit Graph

188 Commits

Author SHA1 Message Date
Slava Pestov
6d8b55a9f6 Sema: Split up gatherConstraints() into gatherAllConstraints() and gatherNearbyConstraints()
The two GatherKinds no longer share any implementation, so there's
no point keeping the logic together. Doing this also allows removing
the acceptConstraintFn from gatherAllConstraints(), which further
simplifies depthFirstSearch().
2025-03-11 13:55:40 -04:00
Slava Pestov
2500c83332 Sema: Simplify depthFirstSearch() a bit now that it only has one caller 2025-03-11 13:55:39 -04:00
Slava Pestov
94eff70b1d Sema: Remove DependentComponentSplitterStep 2025-03-11 13:55:39 -04:00
Slava Pestov
917173c7f4 Sema: Remove one-way constraint handling from computeConnectedComponents() 2025-03-11 13:55:39 -04:00
Slava Pestov
2cf365fa19 Sema: Fold ConstraintGraph::updateFixedType() into its last caller 2025-02-18 17:53:30 -05:00
Slava Pestov
58fdc4f805 Sema: ConstraintGraph::retractFromInference() doesn't need the new fixed type 2025-02-18 17:52:59 -05:00
Slava Pestov
09f78bfd95 Sema: Remove now-unused ConstraintGraph::inferBindings() 2025-02-04 20:26:12 -05:00
Slava Pestov
fa73be2415 Revert "Sema: Remove one-way constraint handling from computeConnectedComponents()"
This reverts commit dd3e49c3ac.
2025-02-02 00:43:15 -05:00
Slava Pestov
8af183cca8 Revert "Sema: Remove DependentComponentSplitterStep"
This reverts commit 9fb6d9251e.
2025-02-02 00:43:15 -05:00
Slava Pestov
8800c3b630 Revert "Sema: Simplify depthFirstSearch() a bit now that it only has one caller"
This reverts commit 25ad700fb0.
2025-02-02 00:43:15 -05:00
Slava Pestov
99595e615e Revert "Sema: Split up gatherConstraints() into gatherAllConstraints() and gatherNearbyConstraints()"
This reverts commit 2230c3a17e.
2025-02-02 00:43:15 -05:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Slava Pestov
2230c3a17e Sema: Split up gatherConstraints() into gatherAllConstraints() and gatherNearbyConstraints()
The two GatherKinds no longer share any implementation, so there's
no point keeping the logic together. Doing this also allows removing
the acceptConstraintFn from gatherAllConstraints(), which further
simplifies depthFirstSearch().
2025-01-27 10:27:00 -05:00
Slava Pestov
881c4f775b Sema: Ignore inactive type variables in addTypeVariableConstraintsToWorkList()
Fixes a regression from commit 0c128e5db7.

The old depthFirstSearch() walked all adjacencies via the constraint graph,
and thus it would visit type variables that are currently inactive because
we're solving a conjunction element.

This was inconsistent with the new union-find which only formed the
connected components from the currently active type variables; adjacencies
involving inactive type variables are no longer considered.

Fix the inconsistency by changing gatherConstraints(), which used from
addTypeVariableConstraintsToWorkList(), to also skip inactive type
variables.

Fixes rdar://problem/143340082.
2025-01-27 10:26:59 -05:00
Slava Pestov
bed95dd1a4 Sema: Simplify PotentialBindings updates a little 2025-01-15 22:30:34 -05:00
Slava Pestov
1aff26eaa6 Sema: Store BindingSet inside the ConstraintGraphNode
Building the DenseMap in determineBestBindings() is extremely
expensive.

Also rename getCurrentBindings() to getPotentialBindings().
2025-01-15 22:30:32 -05:00
Slava Pestov
25ad700fb0 Sema: Simplify depthFirstSearch() a bit now that it only has one caller 2024-12-21 00:42:13 -08:00
Slava Pestov
9fb6d9251e Sema: Remove DependentComponentSplitterStep 2024-12-21 00:42:13 -08:00
Slava Pestov
dd3e49c3ac Sema: Remove one-way constraint handling from computeConnectedComponents() 2024-12-21 00:42:13 -08:00
Slava Pestov
0c128e5db7 Sema: Optimize ConstraintGraph::computeConnectedComponents()
Instead of starting a depth-first search from each type variable
and marking all type variables that haven't been marked yet,
we can implement this as a union-find.

We can also store the temporary state directly inside the
TypeVariableType::Implementation, instead of creating large
DenseMaps whose keys range over all type variables.
2024-12-18 17:30:43 -05:00
Slava Pestov
45346c8389 Sema: Remove ConstraintGraph::TypeVariables 2024-12-18 17:30:34 -05:00
Slava Pestov
60d34a4162 Sema: Micro-optimize PotentialBindings
PotentialBindings is part of ConstraintGraphNode and there's no need
to store the ConstraintSystem and TypeVariableType twice.

Also it doesn't need to be optional either, because we no longer need
to reset and recompute bindings.
2024-11-20 13:35:22 -05:00
Slava Pestov
1bdf7f0192 Sema: Assert that the constraint graph node is empty before recycling 2024-11-20 13:35:22 -05:00
Slava Pestov
1a18d70f90 Sema: Remove ConstraintSystem::SolverState::isRecordingChanges()
All but two remaining call sites can be changed to just check for a
non-null solverState, because we want to assert if we're inside
of an active undo.

The two places inside binding inference can check isUndoActive()
directly.
2024-11-20 13:35:22 -05:00
Slava Pestov
24de22a078 Sema: Split off ConstraintGraph::addTypeVariable() from ::operator[]
Also, since we add a vertex immediately after introducing a new type
variable, the code path to handle the case where the type variable
had a parent or fixed type was actually dead.
2024-11-20 13:35:21 -05:00
Slava Pestov
b760cfd03d Sema: Fold ConstraintGraph::lookupNode() into ::operator[]
lookupNode() returned a pair but both callers only looked at the
first element of the pair.
2024-11-20 08:23:58 -05:00
Slava Pestov
a19c92a4e0 Sema: Extract duplication from ConstraintGraph::introduceTo/retractFromInference(Type) overloads 2024-11-19 21:24:13 -05:00
Slava Pestov
1a60685292 Sema: Address the FIXME in ConstraintGraph::mergeNodes() 2024-11-19 21:24:12 -05:00
Slava Pestov
5690addb4e Sema: Fix ordering of constraint graph updates vs fixed type assignment 2024-11-19 21:24:12 -05:00
Slava Pestov
0d3d31599f Sema: Remove ConstraintGraph::reintroduceToInference() 2024-11-19 21:24:12 -05:00
Slava Pestov
338ad3062d Sema: Tighten an invariant in ConstraintGraph
These functions are never called while undoing a change; so
we want to assert if we have an active undo instead of
silently not recording the change.
2024-10-22 20:14:43 -04:00
Slava Pestov
3a4de0b953 Sema: Optimize computeConnectedComponents()
If there is only one connected component, we don't actually have
to form the array of components at all. Re-organize the code so
that we can short-circuit this decision as soon as possible.
2024-10-10 17:05:30 -04:00
Slava Pestov
cdc2145ad5 Sema: Use existing utility function 2024-10-09 11:48:08 -04:00
Slava Pestov
892e79cd70 Sema: Use an xmacro to clean up some duplication in CSTrail.cpp 2024-10-07 16:50:46 -04:00
Slava Pestov
31edb86da9 Sema: Remove ConstraintGraphNode::resetBindingSet() 2024-09-30 22:14:09 -04:00
Slava Pestov
186589bd25 Sema: Remove SolverTrail::Change::introducedToInference() 2024-09-30 22:05:41 -04:00
Slava Pestov
c46ee87408 Sema: Simplify ConstraintGraph::addConstraint() and ::removeConstraint() 2024-09-30 22:00:14 -04:00
Slava Pestov
2caf2e001f Sema: Simplify ConstraintGraphNode::truncateEquivalenceClass() 2024-09-30 21:31:43 -04:00
Slava Pestov
6652e34f55 Sema: Add SolverTrail::Change::InferredBindings and ::RetractedBindings 2024-09-30 21:29:59 -04:00
Slava Pestov
b885c29f71 Sema: Split up SolverTrail::Change::AddedConstraint and ::RemovedConstraint 2024-09-30 21:29:59 -04:00
Slava Pestov
ae53c8e7ff Sema: Split up SolverTrail::Change::BoundTypeVariable 2024-09-30 15:09:38 -04:00
Slava Pestov
148033930c Sema: Split off introduceToInference() into its own Change
Previously, retractFromInference() was the last step in
unbindTypeVariable(). This doesn't really make sense,
because bindTypeVariable() doesn't call introduceToInference();
its two callers do it later.

Start untangling this by splitting off introduceToInference()
into its own Change, but for now, record this change at the
incorrect place to maintain the same behavior as before.
2024-09-29 21:46:41 -04:00
Slava Pestov
c0afe3fce1 Sema: Don't create new ConstraintGraphNode during active undo
This messes up the bookkeeping for the trail.
2024-09-27 10:51:47 -04:00
Slava Pestov
4ef30a4b47 Sema: Recycle ConstraintGraphNode 2024-09-27 01:30:13 -04:00
Slava Pestov
cab698216f Sema: Fancier assertions in ConstraintGraph 2024-09-26 23:15:27 -04:00
Slava Pestov
105b6b39a9 Sema: Remove ConstraintGraphScope 2024-09-26 23:15:27 -04:00
Slava Pestov
4cc27c9b20 Sema: Factor out SolverTrail from ConstraintGraph 2024-09-26 23:15:26 -04:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Timofey Solonin
3f366947e4 Improve indentation in debugging output 2022-11-17 23:25:31 +08:00
Amritpan Kaur
a4a72075fd [ConstraintGraph] Correct dis/conjunction indents. 2022-09-13 10:45:15 -07:00