Commit Graph

174 Commits

Author SHA1 Message Date
Pavel Yaskevich
166c41d89f [ConstraintGraph] Extract logic related to fixed types into dedicated methods on graph node 2021-03-01 10:52:29 -08:00
Pavel Yaskevich
bcb3da069e [ConstraintGraph] NFC: Refactor {un}bindTypeVariable to remove unnecessary nesting 2021-02-24 12:57:49 -08:00
Pavel Yaskevich
5c623ebe04 [ConstraintGraph] NFC: Clarify names of inference APIs and add comments 2021-02-24 12:45:21 -08:00
Pavel Yaskevich
1de0764b04 [ConstraintGraph] Make binding inference more incremental and stop resetting bindings 2021-02-24 10:38:31 -08:00
Pavel Yaskevich
fbc11f410a [ConstraintSystem] Implement incremental binding computation 2021-02-24 10:37:20 -08:00
Pavel Yaskevich
9372215012 [ConstraintGraph] Track constraint graph and type variable belonging to the node 2021-02-24 10:25:09 -08:00
Pavel Yaskevich
f9b58a79a3 [ConstraintGraph] NFC: Add a equivalence class truncation callback to graph node
This dedicated method would be useful for upcoming incremental binding
computation.
2021-02-24 10:25:09 -08:00
Pavel Yaskevich
3e45980ba8 [ConstraintGraph] Track bound type variables regardless of presence of other vars 2021-02-24 10:25:09 -08:00
Pavel Yaskevich
202a9de47c [ConstraintGraph] Start inferring bindings incrementally
Associate potential bindings with a constraint graph node and
start keeping track of added and removed constraints.

This is not a complete implementation because the ability to
infer bindings transitively is missing.
2021-02-24 10:25:09 -08:00
Pavel Yaskevich
8137c7b96a [ConstraintGraph] Split fixed binding storage into referenced by/from
Binding inference requires constraint propagation through to referenced
type variables, in current "fixed bindings" storage mode it is impossible
to figure out whether tracked type variables are referenced by or from
a type variable.

Splitting storage for referenced by/from also helps to provide more
meaningful debug output and make sure there are no attempts to insert
duplicate references.
2021-02-19 12:41:07 -08:00
Pavel Yaskevich
4ef7a2d626 [CSBindings] NFC: Refactor some of the repetitive uses of type variable in graph node 2021-02-16 17:21:44 -08:00
Pavel Yaskevich
b03dc63634 [AST] Adjust TypeBase::getTypeVariables to accept a set
Currently the pattern is to collect the type variables and then unique
them. Instead of asking clients to do uniquing, let's just accept a set
as an argument.
2021-01-26 18:13:34 -08:00
Slava Pestov
e675bee26c AST: Split off DependencyCollector.h from EvaluatorDependencies.h
Also remove some unnecessary #includes from DependencyCollector.h,
which necessitated adding #includes in various other files.
2020-12-23 00:00:25 -05:00
Pavel Yaskevich
094ca8077d Merge pull request #34737 from xedin/potential-bindings-refactor
[ConstraintSystem] Infer some of the bindings attributes on demand
2020-11-16 13:28:21 -08:00
Pavel Yaskevich
6a7cc79f83 [ConstraintSystem] Determine whether type variable is a hole on demand 2020-11-11 15:31:24 -08:00
Luciano Almeida
72b594b3fd [NFC][ConstraintGraph] Address fixme and switch CG::Component dependencies type to SmallVector<unsigned> 2020-11-09 19:49:29 -03:00
Pavel Yaskevich
461eafff54 [ConstraintSystem] NFC: Move ConstraintSystem.h to include/swift/Sema 2020-10-08 10:45:47 -07:00
Pavel Yaskevich
ab951c208a [ConstraintSystem] NFC: Move ConstraintGraph{Scope}.h to include/swift/Sema 2020-10-08 10:42:58 -07:00
Doug Gregor
fb95c7d75c [Constraint system] Limit edge contraction to BindParam.
Edge contraction was being performed for Bind, Equal,
BindToPointerType, and BindParam constraints. However, it's behavior
on everything but BindParam is the same as what matchTypes() already
does, so only look at BindParam constraints. This simplifies the code
but shouldn't change its behavior.
2020-07-21 17:39:47 -07:00
Pavel Yaskevich
7622993083 [ConstraintSystem] Add a new endpoint to infer bindings for a given type variable
Since bindings now require finalization we need a new endpoint
which perform all of the required actions before returning complete
`PotentialBindings` object when they are requested for a particular
type variable without any other context.
2020-07-15 20:50:50 -07:00
Hamish Knight
23e797422a [CS] Avoid checking RHS of one-way constraint for reactivation
Previously we would only gather one-way constraints
if they were found through a type variable in their
right hand side. However we would incorrectly check
this against the type variable that we started the
search at. This meant that if the constraint was
found through a fixed binding, we would never
return it, and could therefore fail to re-activate
it, leaving it unsolved.

Fix this issue by simply removing the check for
the RHS, and letting the constraint system handle
it instead.

Resolves rdar://64890308.
2020-07-02 13:16:56 -07:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Robert Widmann
afe8f2b63f Drop TypeCheckerDebugConsumer 2020-05-18 22:49:55 -07:00
Pavel Yaskevich
2f91f213ec [ConstraintSystem] Don't contract edges with type holes
Holes couldn't be contracted instead solving of the constraint
has to be delayed until one of the sides is bound to a type,
otherwise there is a risk to loose contextual information.
2020-05-15 01:13:06 -07:00
Robert Widmann
2bca013457 Move "isDebugMode" into ConstraintSystem
This eliminates the final source of mutation of the TypeCheckerFlags on the ASTContext.
2020-05-13 09:13:44 -07:00
Hamish Knight
41083524dd [CS] Remove ConstraintGraph::removeEdge
The only caller was `contractEdges`, which would
only call it with constraints from either the
active or inactive list. The implementation can
therefore be replaced by
`ConstraintSystem::retireConstraint`, and
`removeGeneratedConstraint` can also be removed.
2020-04-20 08:50:55 -07:00
Michael Forster
fae87c96d7 Move interleave(...) to the llvm namespace
This simplifies fixing the master-next build. Upstream LLVM already
has a copy of this function, so on master-next we only need to delete
the Swift copy, reducing the potential for merge conflicts.
2020-04-17 11:20:50 +02:00
Hamish Knight
6c7d695492 Revert "[Constraint graph] Reinstate the adjacencies of constraint graph nodes."
This reverts commit cf1732cce2.
With `gatherConstraints` no longer visiting
adjacencies, we no longer need to maintain the
adjacency info.
2020-04-10 10:16:07 -07:00
Hamish Knight
47541d86f7 [CS] Visit all fixed bindings for constraint re-activation
Start visiting transitive fixed bindings for type
variables, and stop visiting adjacencies for
`gatherConstraint`'s `AllMentions` mode.

This improves performance and fixes a correctness
issue with the old implementation where we could
fail to re-activate a coercion constraint, and
then let invalid code get past Sema, causing
either miscompiles or crashes later down the
pipeline.

Unfortunately this change requires us to
temporarily drop the non-ephemeral fix for a couple
of fairly obscure cases where the overload hasn't
yet been resolved. The logic was previously relying
on stale adjacency state in order to re-activate
the fix when the overload is bound, but it's not
connected on the constraint graph. We need to find
a way to connect constraints to unresolved
overloads they depend on.

Resolves SR-12369.
2020-04-10 10:16:07 -07:00
Hamish Knight
0df444920e [CS] NFC: Move depthFirstSearch up slightly 2020-04-10 10:16:06 -07:00
Hamish Knight
e71d921e43 [CS] Re-introduce some assertions
These FIXMEs appear to now be outdated.

This commit also adds an additional assertion in
`bindTypeVariable`.
2020-03-22 22:58:48 -07:00
Robert Widmann
de72824b04 [Gardening] Canonicalize usages of ASTContext::Stats 2020-02-27 17:12:58 -08:00
Doug Gregor
77da6bd3a7 [Constraint graph] Don't drop unidirectional constraints.
Ye olde "break should have been continue" bug. This undoubtedly has
problems elsewhere, but I don't have a specific case until the next
commit.
2020-02-03 17:51:54 -08:00
Pavel Yaskevich
86fa82d163 [ConstraintGraph] NFC: Adjustency list and equivalence class printing should respect printing flags 2019-11-22 16:26:35 -08:00
Pavel Yaskevich
1945ee2639 [ConstraintSystem] NFC: Fix type variable printing in connected compoents and constraint system state 2019-11-18 13:57:51 -08:00
Robert Widmann
d890b8ad41 Remove some save-and-restores
An awful pattern we use throughout the compiler is to save and restore global flags just for little things.  In this case, it was just to turn on some extra options in AST printing for type variables. The kicker is that the ASTDumper doesn't even respect this flag. Add this as a PrintOption and remove the offending save-and-restores.

This doesn't quite get them all: we appear to have productized this pattern in the REPL.
2019-11-13 07:37:12 -08:00
Robert Widmann
f4d333d066 Sink a bunch of semantic options into TypeCheckerOptions
Sink
- DebugConstraintSolver
- DebugConstraintSolverAttempt
- DebugConstraintSolverOnLines
- DebugGenericSignatures
- DebugForbidTypecheckPrefix
- SolverMemoryThreshold
- SolverBindingThreshold
- SolverShrinkUnsolvedThreshold
- SolverDisableShrink
- EnableOperatorDesignatedTypes
- DisableConstraintSolverPerformanceHacks
- SolverEnableOperatorDesignatedTypes
2019-11-12 22:39:49 -08:00
Brent Royal-Gordon
17169fc1fe Merge pull request #27950 from brentdax/dumpster-fire
[NFC] Standardize dump() methods in frontend
2019-10-31 20:36:26 -07:00
Brent Royal-Gordon
ffbe53e290 [NFC] Eliminate const_casts in constraint system dumpers 2019-10-31 18:41:11 -07:00
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -07:00
Robert Widmann
972e755e9b Give ConstraintSystem's outlet to the ASTContext
Make it less tempting to ask for the type checker embedded into
ConstraintSystem by using the accessor to the ASTContext.
2019-10-30 12:55:42 -07:00
Jordan Rose
171ff440fc Remove swift::reversed in favor of llvm::reverse (#27610)
The former predates the latter, but we don't need it anymore! The
latter has more features anyway.

No functionality change.
2019-10-10 17:16:09 -07:00
Doug Gregor
34a7515aee [Constraint graph] Use adjacency info for constraint gathering.
This reinstates the use of direct adjacency information when gathering
constraints, effectively reverting
54bdd7b840.
Fixes the regression that commit caused, which is tracked by
rdar://problem/54274245.
2019-08-22 10:15:54 -07:00
Doug Gregor
cf1732cce2 [Constraint graph] Reinstate the adjacencies of constraint graph nodes.
Reinstate the list of adjacencies in each constraint graph node,
effectively reverting
dfdd352d3d. Exclude one-way constraints
from this computation; we'll handle them separately.
2019-08-22 09:38:21 -07:00
Doug Gregor
17ea39accd [Constraint solver] Simplify one-way constraints to Equal, not Bind.
One-way constraint expressions, which are the only things that
introduce one-way constraints at this point, want to look through
lvalue types to produce values. Rename OneWayBind to OneWayEqual, map
it down to an Equal constraint when it is simplified (to drop
lvalue-ness), and apply that coercion during constraint application.

Part of rdar://problem/50150793.
2019-08-16 14:13:21 -07:00
Doug Gregor
da267bf7ca [Constraint system] Switch TypeVariables to a SetVector.
There were a few places where we wanted fast testing to see whether a
particular type variable is currently of interest. Instead of building
local hash tables in those places, keep type variables in a SetVector
for efficient testing.
2019-08-16 14:13:15 -07:00
Doug Gregor
aaf479642f [Constraint graph] Fix gathering of one-way constraints.
We only care about gathering a one-way constraint if (1) the left-hand
side is in the set of type variables we care about now, and (2) the
type variable we started from is in the right-hand side.
2019-08-16 14:13:04 -07:00
Doug Gregor
73e5a64bd1 [Constraint graph] Collapse cycles in the one-way component graph.
When we encounter a cycle in the one-way component graph due to constraints
that (e.g.) tie together the outputs of two one-way constraints, collapse
the components along the cycle into a single connected component, because
all of those type variables must be solved together.
2019-08-14 13:51:24 -07:00
Doug Gregor
f19016b94b [Constraint graph] Add preVisit hook for depth-first search.
Refactoring so we can use this in a moment.
2019-08-14 11:49:14 -07:00
Doug Gregor
0b7ef3445e [Constraint graph] Make sure we print type variables when dumping components.
Helps with debugging the constraint graph.
2019-08-14 09:20:41 -07:00