Commit Graph

261 Commits

Author SHA1 Message Date
Fedor Isakov dc4f046510 Cleanup and optimize Rule.Tag, drop unused methods 2021-05-18 12:32:03 +02:00
Fedor Isakov 4573764bb4 Reactor: introduce indexed term trie 2021-05-13 15:54:43 +02:00
Fedor Isakov 4d1511d794 Reactor: drop most of incrementality- and preamble-related stuff
Neither incremental evaluation of program or "preamble" features
are useful, but they complicate things and cause major bugs.
2021-04-13 22:57:06 +02:00
Fedor Isakov 207be07df9 Introduce try-tell protocol for invoking predicates
The default tell protocol assumes an exception is to be thrown
in case predicate is not satisfied. This may lead to unnecessary
exceptions being thrown in a situation where a simple failure
status would have been sufficient.
2021-04-08 11:31:29 +02:00
Fedor Isakov c51a984648 Alternative solution for invalidating feedback
Introduce feedback basis to track dependencies on rules.
Index journal chunks by evidence for quick lookup.

The feedback basis is the collection of principal rules tags
from the justifications of the current match.
2021-04-08 08:51:39 +02:00
Grigorii Kirgizov 2504b354f0 Implement fallback from incremental to default processing on unhandled cases (MPSCR-67) 2021-01-29 13:39:31 +03:00
Grigorii Kirgizov 98ee9f4da2 Add new incr stage for rewinding logical unification (MPSCR-67 & MPSCR-21)
For this several notions are introduced.
Logical variable is called "principal" if it is used in principal
occurrences and at some point during evaluation is unified or bound.
Principal occurrence is called "volatile" if it uses principal logicals.

PrincipalObserverDispatcher's task is to track volatile occurrences
by enabling uni observers on all free logicals in principal occ-s.

RewindVolatileOccurrencesStage then on events of incremental usage
of volatile occurrences (e.g. match on it, or continued activation)
resets journal cursor to the position of initial occurrence activation,
where it can be re-evaluated with fresh, unaffected, logicals.
It's the only stage that goes backwards in journal.

So in this way unification is incrementally cancelled.
link to MPSCR-62 (docs)
2021-01-29 13:39:31 +03:00
Grigorii Kirgizov eb1e646cd4 Minor refactoring: move OccurrenceContractObserver from ConstraintsProcessing into ProcessingStrategy
Rename NonIncrementalProcessing -> DefaultProcessing
Add GroundProcessing as common superclass to handle OccurrenceContractObserver
Add another test for this occurrence contract logic.
2021-01-29 13:39:31 +03:00
Grigorii Kirgizov e73394863e minor: Remove ignored test for not implemented and not needed feature of MatchJournal 2020-12-15 17:59:10 +03:00
Grigorii Kirgizov fd43cc560c refactoring: introduce Rule.Tag instead of several fields (basetag/tag/uniqueTag)
Allows to carry logically connected information in one object.
Needed for subsequent changes to ConstraintOccurrence, which
must have better information on source rule: rule template name.
Used by occurrence cache.
2020-12-15 17:59:05 +03:00
Fedor Isakov f6123273d4 Minor refactoring: drop usages of Program.rulesLists() method. 2020-12-01 21:55:17 +01:00
Fedor Isakov b51d8257ba Ensure runtime exceptions are caught when evaluating predicates.
An exception raised by a predicate solver must not break evaluation.
2020-11-24 13:41:24 +01:00
Grigorii Kirgizov 15d6fe8eae Introduce ProcessingSession for creating session from token & ending it
Introduced to discern incremental strategies: Full,Preamble,Default.
because how SessionToken is used and stored depends on it.
EvaluationSessionImpl now simply dispatches to it.
Also rename 'IncrementalProcessing' to 'ProcessingStrategy'.
2020-11-18 11:36:28 +03:00
Fedor Isakov a403b1a252 Update Idea project in reactor. 2020-10-23 12:26:30 +02:00
dependabot[bot] 7971353f31
Bump junit from 4.12 to 4.13.1 in /reactor/Test
Bumps [junit](https://github.com/junit-team/junit4) from 4.12 to 4.13.1.
- [Release notes](https://github.com/junit-team/junit4/releases)
- [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.12.md)
- [Commits](https://github.com/junit-team/junit4/compare/r4.12...r4.13.1)

Signed-off-by: dependabot[bot] <support@github.com>
2020-10-13 07:03:23 +00:00
Grigorii Kirgizov da27c7ccd4 Fix some tests given changes in Journal
Also enable old incr tests that failed b/of missing features.
Remove old flaky disabled test.
2020-09-01 17:01:06 +03:00
Grigorii Kirgizov 19fa16c731 minor: disable excessive traverse in Journal made for MPSCR-65. breaks 2 tests 2020-09-01 16:20:08 +03:00
Grigorii Kirgizov 96f0a2e037 Provide correct journal position for re-exec in continueReplacedHeads (fixes MPSCR-68)
Also completes MPSCR-65. Another test for it now passes.
2020-09-01 13:37:45 +03:00
Fedor Isakov 38e34b4431 Reinforce RuleIndex.update() to be independent of RuleDiff.
RuleDiff may not be in sync with RuleIndex's state.
2020-08-20 14:20:52 +02:00
Fedor Isakov d619fdf31b Ignore a test that isn't working as it's supposed to.
The test substructuralTS_indirectResourceDependency is not doing what it's intended
to be doing b/c of apparenly wrongly understood contract of the `also()` method.
It is not supposed to pass the result of the computation to the "chained" method.

Compare `T.also(block: (T) -> Unit): T` and `T.let(block: (T) -> R): R`.

After having fixed the code, the test no longer passes.
2020-08-06 17:45:47 +02:00
Fedor Isakov eec84330fc Make RuleIndex incrementally updatable. Drop segments feature. 2020-08-06 17:45:47 +02:00
Grigorii Kirgizov 2a0d4ef076 Observe all unbound logicals inside Occurrence to check contract (MPSCR-66)
Previously only logicals directly used ar occurrence args
were observed. Now terms in occurrence args are traversed
recursively and all contained logicals are observed.

Also clear occurrence contract observers on discarding occ-s.
Introduce a generic way to clear observers in LogicalState.
2020-07-28 18:53:41 +03:00
Grigorii Kirgizov 3ef1c53a85 Move TermWalker from tests package to core.internal to reuse for MPSCR-66
Also convert it to Kotlin
2020-07-28 18:53:41 +03:00
Grigorii Kirgizov 54335cb2fd Introduce incrementality-allowed levels: No, Unsafe, Yes
Instead of simple allowed/not option sometimes Unsafe
is useful. 'Unsafe' status may be present when there're
few "bad" rules.
With this level end code may resolve to go with
incrementality without strict guarantees.
2020-07-28 18:53:41 +03:00
Grigorii Kirgizov 0d0813d352 Add logical incr contract assertions as observers (implements MPSCR-66) 2020-07-22 15:51:56 +03:00
Grigorii Kirgizov f2d1f089ad Use rule match identity as feedback key for TypesIndex instead of rule unique tag
It seems to reflect the exact information needed: there's
one-to-one correspondence between feedback and its match.
While using rule unique tag as feedback key in TypesIndex
relied on several assumptions.
Also there's less use of MatchJournal information with this.
Previously parent principal match was passed to FeedbackConsumer.
2020-07-22 15:27:46 +03:00
Grigorii Kirgizov 53a5d2f489 Disable one test for substructural TS (most general case of MPSCR-65) 2020-07-22 15:27:46 +03:00
Grigorii Kirgizov d9b984aee9 minor: modify expectType test according to fix of MPSCR-64
Fix expands notion of principal rules so that failed rules
are now principal. It's reflected in this change to test.
2020-07-22 15:27:46 +03:00
Grigorii Kirgizov 53d0bd2060 Add tests for substructural typesystems (MPSCR-65) & reproduce MPSCR-64
These typesystems will probably extensively use discarded constraints.
So need more tests for these cases.
2020-07-22 13:09:52 +03:00
Grigorii Kirgizov 8629e5abfc Properly handle non-principal rules with origins in incremental algo
Fixes IncrClassHierarchy.modifyClsHierarchyTypeParams test.

Key point is that changes to rules causing their
regeneration must be reflected in program.
There appeared to be cases when it's not true.
It's a case of non-principal rules with origins.
Such rules are called "weak principal" rules.

Matches of weak principal rules are not recorded
in Journal (as is for principal rules), but instead
they become part of their parent MatchChunk.
(In essense, tags of weak principal rules are
recorded in parent chunk).
With this, when a weak principal rule changes,
matches of all principal rules whose computation
depends on them are correctly invalidated.
(Example rules: findHierarchy_Classifier)

Relevant for MPSCR-62.
2020-07-01 14:36:48 +03:00
Fedor Isakov 8b71274a57 Update Kotlin to 1.3.70 for Reactor lib. 2020-06-25 14:30:31 +02:00
Fedor Isakov 7f37a15f4e IDEA project files update after switch to 2020.1 2020-06-04 12:40:34 +02:00
Fedor Isakov 18933cfcf2 Support trivial bindings in unification results. Minor refactoring.
Trivial substitutions such as [X->X] are optionally available.
May prove usable when discovering variables within a term.
2020-06-04 11:44:07 +02:00
Grigorii Kirgizov 4928daf3fc Add tests related to program execution pattern exhibited by MPSCR-59 2020-04-30 15:38:34 +03:00
Grigorii Kirgizov a2675351b5 Track justifications for all occurrences, but weaken information they carry.
Now Evidence isn't unique for each Chunk: Occurrence Chunks fully
share evidence and justifications with their activating match.
So, less collections of justifications are created, approx. 2 times less.
2020-03-26 13:40:41 +03:00
Grigorii Kirgizov 6a53d15a21 Refactor: move logic related to tracking parent match from ControllerImpl to MatchJournal
Relates to machinery introduced in MPSCR-47.
Previously parent match was maintained in Controller on Java call stack.
Now this stack of parent matches is maintained manually in MatchJournal.

So MatchJournal gains new invariant: parentChunk()
returns correct parent after each logMatch() call.
Several tests fail, also need to maintain this
invariant after logActivation() calls.
2020-03-26 13:40:41 +03:00
Grigorii Kirgizov b10b69545e Refactor: hide mutability of Chunk.entries (both as var and as MutableList). Add a bit of docs. 2020-03-12 18:02:22 +03:00
Fedor Isakov 856c7cc777 Dereference all refs within term on unification.
Method findSolution now walks all refs inside a term.
This guarantees no "hidden" cycles, but also breaks the
"cyclic term" feature.
2020-03-11 12:29:04 +03:00
Grigorii Kirgizov 591865b9cb Small opt: skip traversing journal when there're no rules to invalidate/add 2020-03-10 13:31:34 +03:00
Grigorii Kirgizov 60f838eb28 Add tests for unification of terms with var refs 2020-03-10 12:22:22 +03:00
Grigorii Kirgizov 81721a0067 Ensure MatchJournalImpl.replay is idempotent operation, add test for it
Add another test for replaying inside Chunk.
Doesn't pass for now for the lack of machinery for tracking precise Pos.
2020-03-02 22:03:05 +03:00
Grigorii Kirgizov 5c4b1f8263 Add test that ensures that justifications invariant is preserved by a fix to MPSCR-47
Invariant ensures that retroactively added justifications
(added on past parent chunk, see fix commit) are propagated
for all relevant children of justified parent chunk.
2020-03-02 22:03:05 +03:00
Grigorii Kirgizov 2b92e5df04 minor: rename test method princConstraint to pconstraint 2020-03-02 17:58:05 +03:00
Grigorii Kirgizov ccd3ed6d45 Add tracking of last justifying MatchChunk during program eval to avoid searching for it in Journal
Such machinery is needed inside ControllerImpl.processBody
to provide nearest relevant match to feedback handling.
Also required for a fix for MPSCR-47.
Also enables back one assertion in incremental processing on rm stage.
2020-03-02 17:11:26 +03:00
Grigorii Kirgizov 38924ef64d Add 2 tests on incremental engine, reproduces case of MPSCR-47 2020-03-02 17:11:26 +03:00
Grigorii Kirgizov 8102080809 Refactor: drop unused on MPS level java interfaces 2020-03-01 17:12:15 +03:00
Grigorii Kirgizov 37dd3ee4a8 Refactoring: extract Justified interface and hide lower-level work with Int sets behind it
Make Occurrence a Justified entity and drop .justifications() from
ConstraintOccurrence.java because justifications are used only internally.
A single justification is now called Evidence (typealias to Int),
so Justified entities are justified by Evidence-s.
2020-03-01 17:12:15 +03:00
Fedor Isakov 3193a9c078 Adjust nullability contract in occurrence matcher.
Term's symbol can't be null.
Also guarantee that when processing a match no null
values occur.
2020-02-28 17:42:54 +01:00
Grigorii Kirgizov f61c436809 Add tests to verify expected behavior of repeated expansion of the same occurrence (MPSCR-37)
Tests are structured similar to how occurrences are processes with ExecQueue
and its 'postponedFutureMatches' in incremental processing in ConstraintProcessing.
Also don't ignore one old test.
2020-02-05 18:52:18 +03:00
Grigorii Kirgizov 51ec8973d2 Add test to reproduce MPSCR-35 2020-02-05 12:29:33 +03:00