Commit Graph

594 Commits

Author SHA1 Message Date
Fedor Isakov 05adef15f9 Respect the template (group) name in rule tag 2022-05-25 12:47:27 +02:00
Fedor Isakov f91170aec0 Fix invalid reporting of trace events 2022-05-25 12:46:19 +02:00
Fedor Isakov a6f56d4193 Use EvaluationFailureException to indicate failure 2022-05-09 13:33:33 +02:00
Fedor Isakov 8af9467831 Deprecate obsolete methods 2022-05-09 13:32:49 +02:00
Fedor Isakov 3b7eb7c210 Ensure failures has non-null message 2022-05-03 10:26:43 +02:00
Fedor Isakov a2dacdd75a Update reactor version to reflect major changes
Dropped all "incremental" stuff.
Occurrences and rules are no longer divided into "principal"
and others.
2022-04-25 12:14:22 +02:00
Fedor Isakov f965c6636d Drop obsolete incremental and principal stuff 2022-04-20 12:42:20 +02:00
Fedor Isakov 735c88cdba Drop unused code, cleanup and simplify code 2022-04-19 14:36:08 +02:00
Fedor Isakov e1f285ed35 Bump up reactor version 2022-03-15 12:10:48 +01:00
Fedor Isakov bcad14d2a5 Introduce support for undo activate/discard trace events
In case evaluation fails and the state of activated occurrences is
reset to some previously stored state, the trace view does not
get updated and contains some stale information. This patch fixes it.
2022-03-14 18:35:17 +01:00
Fedor Isakov c90382ec8f Cleanup code, drop obsolete classes 2022-03-14 18:10:43 +01:00
Fedor Isakov ef3aec13d5 Drop obsolete features, cleanup code 2022-03-14 11:24:22 +01:00
Fedor Isakov c4a55446b5 Refactor and cleanup code for better readability 2022-03-12 16:50:12 +01:00
Fedor Isakov d8eedd0c44 Cleanup code 2022-03-12 12:49:55 +01:00
Fedor Isakov 357560f11f Drop unused obsolete stuff 2022-03-08 15:44:18 +01:00
Fedor Isakov 945088f72e Drop obsolete deprecated class, simplify code 2022-03-07 19:16:05 +01:00
Fedor Isakov cf4e9b2b33 Drop obsolete interface and its usages 2022-03-05 15:44:29 +01:00
Fedor Isakov f30a560073 Revert accidentally committed change
TMP Reuse Profiler instance to collect statistics

This reverts commit 56267a68955fd94ba36f79ce526fd198a8c630a2.
2022-02-17 17:17:17 +01:00
Fedor Isakov c44e4b2080 Update coderules plugin desc, fix release number 2022-02-16 12:23:38 +01:00
Fedor Isakov dc4f046510 Cleanup and optimize Rule.Tag, drop unused methods 2021-05-18 12:32:03 +02:00
Fedor Isakov f76f81af50 Switch RuleIndex to IndexedTermTrie 2021-05-13 15:54:43 +02:00
Fedor Isakov 4573764bb4 Reactor: introduce indexed term trie 2021-05-13 15:54:43 +02:00
Fedor Isakov 16e0fdf9dd Reactor: fix wrong match on reactivation in propagation rule
A propagaition rule must ignore reactivated occurrence.
Although it is possible that other occurrences are waiting,
and they can be erroneously selected if precautions are not taken.
2021-05-04 11:07:14 +02:00
Fedor Isakov dbbb37384f Fix and optimizate ClassicTermTrie
Implement cleanup on removing value.
2021-04-28 08:54:25 +02:00
Fedor Isakov a812e2a9bb Make InvalidConstraintException a RuntimeException 2021-04-19 22:55:09 +02:00
Fedor Isakov 7722327958 Reactor: fix session token not being used 2021-04-19 22:46:45 +02:00
Fedor Isakov 19da8e26eb Reactor: optimize Dispatcher
Switch to lazy initialization of RuleMatcher and RuleMatchingProbe.
2021-04-19 22:41:56 +02:00
Fedor Isakov 205c01ae45 Reactor: optimize and cleanup ClassicTermTrie
Also drop obsolete implementation of TermTrie.
2021-04-19 22:37:23 +02:00
Fedor Isakov 96ac2b3160 Reactor: optimize and fix RuleIndex
Implement missing method ArgumentRuleIndex.clear().
General code cleanup and optimization.
2021-04-19 10:27:24 +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 54b8d42e52 Drop obsolete RuleMatcher implementation 2021-04-13 12:23:17 +02:00
Fedor Isakov db7fbfc748 Minor optimization: precompute hash value 2021-04-12 12:50:31 +02:00
Fedor Isakov 8a00024658 Turn back on incremental rebuilding of RuleIndex 2021-04-12 12:49:58 +02:00
Fedor Isakov 0cef5ad298 Introduce method isBasis to Rule class, use that for feedback
Feedback basis are calculated for rules in history that
are marked as "basis" instead of "principal".
2021-04-12 12:47:44 +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 aaa6e5e2f9 Refactoring: simplify RewindStage & related logic (MPSCR-21). Add docs, some renames.
ProcessingSession -> SessionManager
RewindVolatileOccurrencesStage -> RewindStage
2021-01-29 13:39:35 +03: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 273d4dc4db Change a bit behavior of MatchJournal.reset* methods
Now after MatchJournal.reset(pos) cursor points before
the `pos`, not at it. So cursor.next will return 'pos'
It's required for MPSCR-67
2021-01-29 13:39:31 +03:00
Fedor Isakov 2c3bcf04ea Auto-updated files 2021-01-18 10:59:03 +01: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 bd25263eac Fix leak of LogicalState in Occurrence observers: properly terminate occ-s 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
Grigorii Kirgizov 4a342437f0 Introduce processing strategy for reusing occurrences from cache
CachedOccurrencesProcessing simply activates occurrences
passed to it as input before proceeding with 'main'.
Use it instead of PreambleProcessing (that works with journal).

This should help if 'main' doesn't lead to duplicate activations
of these occurrences. So coderules program must be aware of
occurrence cache and should not include rules for cached occ-s.
2020-12-15 17:51:27 +03:00
Grigorii Kirgizov 4292709c3b Fix incremental clearing of Dispatcher state
It wasn't complete. Now `DispatchingFront.forget(occ)`
additionally triggers removal of invalid ReteNodes.
2020-12-15 17:51:27 +03:00
Grigorii Kirgizov 35335e3d15 Avoid storing DispatchingFront in SessionParts -- it can be stale
ConstraintsProcessing can reassign front internally,
so SessionParts can store a stale one.
2020-12-15 17:51:27 +03:00
Grigorii Kirgizov 88067571d0 Provide as eval result tags of invalidated rules. for MPSCR-82
Relevant for Incremental strategy.
Allows to more precisely track invalidated types of nodes.
Type of node is invalidated if rules with this origin
were invalidated during incremental processing.
2020-12-15 17:51:23 +03:00
Fedor Isakov da9814a18d Deprecate RulesDiff, introduce replacement methods in Program. 2020-12-06 19:00:43 +01:00
Fedor Isakov dcfe56c004 Deprecate RulesList, prepare to drop the class. 2020-12-03 20:17:47 +01:00
Fedor Isakov f6123273d4 Minor refactoring: drop usages of Program.rulesLists() method. 2020-12-01 21:55:17 +01:00
Fedor Isakov ac6972106b Fix memleak in LogicalState. Ensure processing machinery gets properly shut down on session end.
Clearing the controller field in LogicalState is not enough,
apparently some instances are leaked before the session
gets terminated.
2020-11-27 11:13:38 +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 8ac38578ef minor: add docs to incremental stages 2020-11-18 11:36:28 +03: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 0df40a65f1 Refactor incremental logic in ConstraintsProcessing into separate facade (MPSCR-71)
Relations between stages and entry points into incremental
algorithm are now much clearer.
2020-09-01 17:01:06 +03: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 5790a83471 Refactor MatchJournal traverse & modification logic (MPSCR-71)
Now journal's internal class Cursor is responsible for it.
2020-09-01 17:01:06 +03:00
Grigorii Kirgizov 1bcf80a9b2 Introduce IncrementalStage-s (MPSCR-71)
Incremental algorithm is stricter now in relation to
how it reads MatchJournal and operates on it.
Previously each incremental stage required full traversal.
Now all stages run on each chunk in a single traversal.

Separate journal traversal from incremental logic required for each Chunk.
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 4e89325d47 Reactor: enable to reuse RuleIndex from token in non-incremental mode. 2020-08-20 14:20:51 +02:00
Fedor Isakov 7666c64507 Make use of RuleIndex update in incremental mode. 2020-08-06 17:45:47 +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
Fedor Isakov a003211a2c Minor optimization of term trie. 2020-08-06 17:45:47 +02:00
Fedor Isakov c282911a3c Provide support for tracking usages number of MutableLogical. 2020-07-30 17:14:40 +02:00
Grigorii Kirgizov 43e39ca4a1 Clear LogicalState for occurrences dropped during incremental invalidation 2020-07-28 18:53:41 +03: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 3093b4678c Implement incremental handling of discarded principal occurrences (MPSCR-65)
Matches which discard principal occurrences must be handled specially
on incremental execution. Imagine such match inserted in journal
before other matches with the same occurrence in head.
Because inserted match discards the occurrence, following matches
can't match on it. They must be invalidated. (Relevant for MPSCR-62)
See tests for substructuralTS.

Commit refactors machinery of `dropDiscardingMatchesFor` in
ConstraintsProcessing that was incomplete, as revealed by MPSCR-64.

Relaxes small memory opt introduced in commit a2675351:
Now justifications in Occurrences are not shared with their
activating matches. See JustifiedOccurrenceCreator.
Introduced machinery requires that Occurrences had their own
Evidence (because `dropDiscarding` invalidates by Occurrences).
Previously algorithm was invalidating Chunks only by Evidence
from rule matches, that's why only RuleMatches had to have
unique Evidence, while Occurrences could bear less info.
2020-07-22 13:09:52 +03:00
Grigorii Kirgizov 8cb6aa72d3 minor refactorings in engine (some moves & renames) 2020-07-22 13:09:52 +03:00
Grigorii Kirgizov 3bdc1123ad Incr engine: refine reexecution position for reactivated occurrences
In short, this change restricts information algo needs from journal.
It restricts how far invalidation stage goes into journal.
Previously it fed ExecQueue with position arbitrarily far in 'past',
whereas now it feeds the closest valid position (the 'present').
2020-07-22 13:09:52 +03:00
Grigorii Kirgizov 76b37c3f3e minor refactorings in engine
Refine interface of RuleMatchEx to use Occurrence,
move one of its function as ext fun (as in TODO).
Fix duplication of extension functions for IncrSpec.
Ensure some contracts in ExecutionQueue.
2020-07-22 13:09:52 +03:00
Grigorii Kirgizov ef7f66dd3e Minor fix: always reset journal in incremental session.
Without it in certain cases ConcurrentModificationException
(on internal journal linked list) could arise.
2020-07-22 13:09:52 +03:00
Grigorii Kirgizov f402ce33c8 Don't clear Dispatcher state for discarded match heads: it's unnecessary 2020-07-22 13:09:52 +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 5ebac30e07 minor: remove unused functionality in ExecQueue according to 'fixme' 2020-07-01 14:36:48 +03:00
Grigorii Kirgizov 693cfbb15d Fix incorrect Dispatcher state clear on incremental invalidation
Some constraints could be missed: those which
are activated and discarded in the same Chunk.

Dispatcher weren't cleared from them
and stale matches could remain in its state.
Through these matches their invalidated heads
could get into incremental execution queue
which led to assert violation in MatchJournalImpl.reset
2020-07-01 14:36:48 +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
Grigorii Kirgizov af3170e428 Remove invalid assert from incremental processing
Some time ago "mixed" matches (with both principal and non-principal heads)
were allowed and are handled by Journal. So now principal constraints
can lead to non-principal matches, which renders assert invalid.
(Relevant for MPSCR-62)
2020-06-08 19:02:20 +03:00
Fedor Isakov 7f37a15f4e IDEA project files update after switch to 2020.1 2020-06-04 12:40:34 +02:00
Fedor Isakov c24f4f75a4 Optimize and refactor TermGraphUnifier. Beautify the code.
Avoid internalizing a (sub-)term that has not been unified with
 a variable, thus saving on unnecessary accounting.
2020-06-04 11:44:07 +02:00
Fedor Isakov 202b83b984 Fix typo in Profiler -- enable to trace parent site frequencies. 2020-06-04 11:44:07 +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
Fedor Isakov c5d9e798a3 Introduce DataProvider. Allow predicates to access Supervisor.
DataProvider is an abstract way to associate any data with the
runtime object, such as Supervisor.
Predicate solvers that ought to be stateful may make use of
DataProvider to access the internal state.
2020-06-04 11:44:06 +02:00
Grigorii Kirgizov e1ff37b815 Document RuleMatchingProbe (most importantly, its matches() contract). 2020-04-30 15:38:34 +03:00
Grigorii Kirgizov 8447081b26 Return from Probe only matches relevant to last expanded Occurrence. Fixes MPSCR-59 2020-04-30 15:38:34 +03: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 49d8507eed Avoid duplicate subscription of Occurrences on LogicalState
Previously it was done twice: at Occurence creation
and in ConstraintsProcessing.processActivated.
Occurrences now constructed in 'dead' state (without observers).
2020-04-30 15:38:34 +03:00