Commit Graph

133 Commits

Author SHA1 Message Date
Pavel Yaskevich
e604261805 [ConstraintSystem] Track AST depth information directly
Instead of storing information about expression depths in the
solver state (which gets recomputed for salvage) let's track
it directly in constraint system, which also gives solver
access to it when needed e.g. for fixes.
2019-01-23 18:44:53 -08:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Mark Lacey
72ba110e5b [ConstraintSystem] Rework new constraint stat as a FRONTEND_STATISTIC.
In the process, remove the old incrementScopeCounter SWIFT_FUNC_STAT.
2018-10-18 07:18:02 -07:00
Pavel Yaskevich
091a757e5d [CSStep] Allocate component scopes only if siblings didn't fail
If sibling components failed, there is no reason to establish new
scope since remaining containers are not really going to be taken
but fail fast instead.
2018-09-20 11:04:26 -07:00
Pavel Yaskevich
f9452afa4f [CSStep] NFC: Unify type binding attempt logging
Instead of printing `trying` for type variable and `assuming`
for disjunction choices, unify it so `BindingStep` logs
`attempting {type variable, disjunction choice}`.
2018-09-19 18:37:36 -07:00
Pavel Yaskevich
ed9c219492 [CSStep] Add state transition verification
Instead of asserting in the solver loop, let's move all of that
logic into `SolverStep::transitionTo(StepState)` and verify state
transition validity there.
2018-09-19 16:08:01 -07:00
Pavel Yaskevich
8daaf905d6 [CSStep] Switch to use std::unique_ptr for work list
Instead of manually managing lifetime of the steps, let's just
use `std::unique_ptr` instead.
2018-09-19 11:19:15 -07:00
Pavel Yaskevich
de34d9fa6a [CSStep] Extract common type-var/disjunction functionality into BindingStep
Unify `take` implementation and API for type variable
and disjunction via `BindingStep` which accepts a producer.
2018-09-17 15:16:04 -07:00
Pavel Yaskevich
bec3d28407 [CSStep] Add isDebugMode and getDebugLogger methods and refactor logging
Instead of using `TypeChecker` and related APIs directly every time,
let's just abstract it all away to easily check if solver is running
in debug mode and to produce indented logger.
2018-09-15 20:56:47 -07:00
Pavel Yaskevich
f1a53c3f59 [ConstraintSystem] Remove unnecessary forward declarations of the steps
Also move `DisjunctionStep` from being a friend of `ConstraintSystem`
because it's not strictly necessary.
2018-09-15 20:56:47 -07:00
Pavel Yaskevich
6cf11b31f9 [CSStep/TypeVar] Check if loop should be stopped even if current binding has failed
Eagerly check if optimal solution has already been found even if
current binding attempt has failed, because otherwise it might
check too many bindings which would result in ambiguity.
2018-09-15 20:56:47 -07:00
Pavel Yaskevich
4f50710457 [CSStep] Use # of disjunctions directly to determine component ordering 2018-09-15 20:56:47 -07:00
Pavel Yaskevich
198003dd04 [CSStep] Record all of the type vars related to component while creating a split
Before this change some of the type variables, especially the ones
that have been previously bound haven't been associated with any
of the component steps, so it had to be done by scope once per step,
but now such recording is done once per split.
2018-09-15 20:56:47 -07:00
Pavel Yaskevich
58ad04d417 [CSStep] Filter solutions only if component is part of a large split 2018-09-15 20:56:47 -07:00
Pavel Yaskevich
b86aa22fca [CSStep] Try to simplify constraint system before performing split 2018-09-15 20:56:47 -07:00
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
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
af1c03b6c6 [CSStep] Add print(llvm::raw_ostream) method to SolverStep 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
eeea58d887 [CSStep] NFC: Add some more documentation to Splitter and Component steps 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
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