Commit Graph

19 Commits

Author SHA1 Message Date
Pavel Yaskevich
a2ba0021c3 [CSStep] Rework how orphaned constraints are handled by splitter/component steps
Orphaned constraints can be re-introduced to the system by `setup`
of the component, and all of them could be returned back by
`SplitterStep::resume` there so no need to use destructor for that.

Also, orphan constraints have to be registered as regular constraints
by components as well as marked as "orphaned".
2018-09-15 20:56:47 -07:00
Pavel Yaskevich
a6682ec5f2 [CSStep] Include related and bound type variables as "in scope"
Re-introduce all type variables which either belong to the given
component or are already bound.
2018-09-15 20:56:47 -07:00
Pavel Yaskevich
0d3c804c18 [DisjunctionStep] Start remembering choices when requested
Extract choice attempting logic into `DisjunctionStep::attemptChoice`
and start recording taken choices in constraint system when
requested by disjunction.
2018-09-15 20:56:47 -07:00
Pavel Yaskevich
0930cb9e37 [CSStep] If previous step before split failed don't do anything 2018-09-15 20:56:46 -07:00
Pavel Yaskevich
ac13752550 [CSStep] Restore original best score after component is done 2018-09-15 20:56:46 -07:00
Pavel Yaskevich
97b157f9fb [CSStep] Make sure that components are sorter before execution
Execute components with fewer disjunction constraints first,
to make sure that if one of the components fails we do the
smallest amount of work possible.
2018-09-15 20:56:46 -07:00
Pavel Yaskevich
f9fcd271e7 [CSStep] Rework how splitter handles component steps
First of all, let the splitter transfer constraints from inactive
work-list to associated components. Also start tracking components
to reinstate constraints back to constraint system when everything
is done, this allows to execute component steps in any desirable order.
2018-09-15 20:56:46 -07:00
Pavel Yaskevich
64c4d0e072 [CSStep] Fix a bug in DisjunctionStep::resume caused by was discarding active choice too early 2018-09-15 20:56:46 -07:00
Pavel Yaskevich
cdc9810f00 [CSStep] Split SolverStep::take(bool) into setup, take and resume
Introduce a notion of `StepState` with some valid transitions,
and split monolithic `take(bool)` into three phases - `setup`, `take`, and
`resume`.

* `setup` - is preliminary state before the step has been taken
            for the first time.

* `take` - represents actual logic of the step, results in either
           step being done or suspended.

* `resume` - `take` might split steps into smaller ones to make
             incremental progress towards the target, which means
             that the main step has to be suspended. `resume` is
             triggered when all of the "follow-up" steps have been
             executed and are "done".
2018-09-15 20:56:46 -07:00
Pavel Yaskevich
f66592e0a7 [CSStep] Don't allocate scope if there is only one component
If "split" step produced a single component, there is no reason
to allocate a scope for it and modify constraint system,
because all of the existing type variables and constraints
are related to it anyway, so scope would just end up doing
useless work.
2018-09-15 20:56:46 -07:00
Pavel Yaskevich
da4871d476 [CSStep] Implement TypeVariable step
Similar to `DisjunctionStep` `TypeVariableStep` attempts
its choices one-by-one, and if any of the choices match
it makes type variable as a whole successfully solved.

Since type variable attempts choices it means that it
can only produce "split" steps as a follow-up.
2018-09-15 20:56:46 -07:00
Pavel Yaskevich
d50a3e804e [CSStep] Add License header to CSStep.cpp 2018-09-15 20:56:46 -07:00
Pavel Yaskevich
c9bf47cb39 [CSStep] Add Disjunction step
`DisjunctionStep` attempts all of the viable choices,
at least one of the choices has to succeed for disjunction
to be considered a success.

`DisjunctionStep` attempts each choice and generates followup
`SplitterStep` to see if applying choice to constraint system
resulted in any simplification.
2018-09-15 20:56:46 -07:00
Pavel Yaskevich
64415c81ff [CSStep] Rename advance to take(bool) and propagate failures
Failure propagation is crucial for splitter and component steps
because that's the only signal for them to figure out if they
could be completely solved or have to fail.

For example, if one of the component steps created by "split"
fails it would cascade to the rest of the pending component steps
receiving "fail" signal and ultimately result in failure of the
"split" when it's re-taken.
2018-09-15 20:56:46 -07:00
Pavel Yaskevich
7723487b18 [CSStep] Add StepResult container 2018-09-15 20:56:46 -07:00
Pavel Yaskevich
60581da15e [ConstraintSystem] Add Splitter, Component and binding steps
* `SplitterStep` is responsible for running connected components
  algorithm to determine how many independent sub-systems there are.
  Once that's done it would create one `ComponentStep` per such
  sub-system, and move to try to solve each and then merge partial
  solutions produced by components into complete solution(s).

* `ComponentStep` represents a set of type variables and related
  constraints which could be solved independently. It's further
  simplified into "binding" steps which attempt type variable and
  disjunction choices.

* "Binding" steps such as `TypeVariableStep` and `DisjunctionStep`
  are responsible for trying type binding choices in attempt to
  simplify the system and produce a solution. After attempting each
  choice they introduce a new "split" step to compute more work.
2018-09-15 20:56:46 -07:00
Pavel Yaskevich
0dda1af94d [CSStep] Implement computeFollowupSteps 2018-09-15 20:56:46 -07:00
Pavel Yaskevich
86c442cc39 [CSStep] Implement mergePartialSolutions 2018-09-15 20:56:46 -07:00
Pavel Yaskevich
daf4c2f3b5 [CSSolver] Add skeleton of iterative solve
The idea so to split solving into non-recursive steps,
represented by `SolverStep`, each of the steps is resposible
for a unit of work e.g. attempting type variable or
disjunction bindings/choices.

Each step could produce more work via "follow-up" steps,
complete "partial" solution when it's done, or error which
terminates solver loop.
2018-09-15 20:56:46 -07:00