Class EpsilonClosure
Owns the busy set, the predicate vs non-predicate control split, and
double-buffered intermediate config sets for breadth-first rule-transition
merging. Recursive edge walking stays here so ParserATNSimulator
remains orchestration-focused rather than absorbing more allocation
policy.
PERF: Intermediate config-set buffers and the closure busy set are retained
on this instance. A single ParserATNSimulator (and therefore one
EpsilonClosure) is used by one parser thread at a time during
adaptivePredict, so reuse is safe. Ownership of cleanup is a single
try/finally around each close(org.antlr.v4.runtime.atn.ATNConfigSet, org.antlr.v4.runtime.atn.ATNConfigSet, boolean, boolean, org.antlr.v4.runtime.atn.PredictionContextCache, boolean): drop config-graph
references after the call while retaining set capacity for the next
prediction.
PERF: The busy set is exposed only as Set<ATNConfig> (see
OpenAddressedHashSet) so the protected
ParserATNSimulator.closure(ATNConfig, ATNConfigSet, ATNConfigSet, Set, boolean, boolean, PredictionContextCache, int, boolean)
SPI stays free of HPPC types. Storage remains an open-addressed HPPC table
behind the adapter: right-recursion and EOF* guards avoid
java.util.HashMap.Node<K extends Object, allocation on every insert, and the flat key
array is reused across predictions. Config iteration on the BFS layers is
index-based (ATNConfigSet.get(int)) to avoid
Iterator objects on the hot path.
Package-private: only ParserATNSimulator constructs and uses this
type. Transition target computation is delegated back to the simulator
(ParserATNSimulator.getEpsilonTarget(org.antlr.v4.runtime.atn.ATNConfig, org.antlr.v4.runtime.atn.Transition, boolean, boolean, org.antlr.v4.runtime.atn.PredictionContextCache, boolean)) so semantic-predicate and
rule-transition policy remain in one place.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ATNConfigSetDouble-buffer scratch sets for BFS rule-transition layering whencollectPredicatesisfalse.private ATNConfigSetRetained busy set for right-recursion / EOF* guards.private final ParserATNSimulator -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidclose(ATNConfigSet sourceConfigs, ATNConfigSet configs, boolean collectPredicates, boolean hasMoreContext, PredictionContextCache contextCache, boolean treatEofAsEpsilon) Compute the epsilon closure of every configuration insourceConfigs, adding the resulting non-epsilon (or EOF-as-epsilon) configurations toconfigs.(package private) voidcloseOne(ATNConfig config, ATNConfigSet configs, ATNConfigSet intermediate, Set<ATNConfig> closureBusy, boolean collectPredicates, boolean hasMoreContexts, PredictionContextCache contextCache, int depth, boolean treatEofAsEpsilon) Recursive helper: walk epsilon edges fromconfig, adding leaf configurations toconfigsand optionally deferring rule transitions tointermediatefor breadth-first processing.private voidensureIntermediateBuffers(int intermediateHint) Ensure both intermediate buffers exist.(package private) booleanWhether intermediate BFS buffers have been allocated.(package private) ATNConfigSetIntermediate buffer A after first non-predicate closure, elsenull.(package private) ATNConfigSetIntermediate buffer B after first non-predicate closure, elsenull.Retained busy set (same instance acrossclose(org.antlr.v4.runtime.atn.ATNConfigSet, org.antlr.v4.runtime.atn.ATNConfigSet, boolean, boolean, org.antlr.v4.runtime.atn.PredictionContextCache, boolean)calls).
-
Field Details
-
simulator
-
closureBusy
Retained busy set for right-recursion / EOF* guards. Cleared inclose(org.antlr.v4.runtime.atn.ATNConfigSet, org.antlr.v4.runtime.atn.ATNConfigSet, boolean, boolean, org.antlr.v4.runtime.atn.PredictionContextCache, boolean)'sfinally; capacity is preserved across predictions. Same-package tests may observe identity viaretainedBusy().Typed as
Setso callers and the protected simulator SPI never see HPPC. The concrete instance is anOpenAddressedHashSetthat keys byATNConfig.hashCode()(cached) andATNConfig.equals(java.lang.Object). -
bufferA
Double-buffer scratch sets for BFS rule-transition layering whencollectPredicatesisfalse. Allocated lazily on first non-predicate closure and reused thereafter. -
bufferB
-
-
Constructor Details
-
EpsilonClosure
EpsilonClosure(@NotNull ParserATNSimulator simulator)
-
-
Method Details
-
close
void close(@NotNull ATNConfigSet sourceConfigs, @NotNull ATNConfigSet configs, boolean collectPredicates, boolean hasMoreContext, @NotNull PredictionContextCache contextCache, boolean treatEofAsEpsilon) Compute the epsilon closure of every configuration insourceConfigs, adding the resulting non-epsilon (or EOF-as-epsilon) configurations toconfigs.When
collectPredicatesisfalse(the common path inParserATNSimulator.computeTargetState(org.antlr.v4.runtime.dfa.DFA, org.antlr.v4.runtime.dfa.DFAState, org.antlr.v4.runtime.ParserRuleContext, int, boolean, org.antlr.v4.runtime.atn.PredictionContextCache)), rule transitions are deferred into an intermediate config set and processed breadth-first so configs that enter the same rule via different edges can merge before the rule body is expanded. Intermediate sets use two retained buffers that swap roles each layer —sourceConfigsis never treated as a reusable buffer. WhencollectPredicatesistrue, rule transitions are followed immediately and no intermediate set is written. -
ensureIntermediateBuffers
private void ensureIntermediateBuffers(int intermediateHint) Ensure both intermediate buffers exist. Existing buffers are retained (capacity preserved viaATNConfigSet.clear()); the initial expected-size hint only applies on first allocation. -
hasIntermediateBuffers
boolean hasIntermediateBuffers()Whether intermediate BFS buffers have been allocated. Same-package tests may observe retained-scratch identity. -
retainedBusy
Retained busy set (same instance acrossclose(org.antlr.v4.runtime.atn.ATNConfigSet, org.antlr.v4.runtime.atn.ATNConfigSet, boolean, boolean, org.antlr.v4.runtime.atn.PredictionContextCache, boolean)calls). Typed asSet; the concrete implementation isOpenAddressedHashSet. -
retainedBufferA
Intermediate buffer A after first non-predicate closure, elsenull. -
retainedBufferB
Intermediate buffer B after first non-predicate closure, elsenull. -
closeOne
void closeOne(@NotNull ATNConfig config, @NotNull ATNConfigSet configs, @Nullable ATNConfigSet intermediate, @NotNull Set<ATNConfig> closureBusy, boolean collectPredicates, boolean hasMoreContexts, @NotNull PredictionContextCache contextCache, int depth, boolean treatEofAsEpsilon) Recursive helper: walk epsilon edges fromconfig, adding leaf configurations toconfigsand optionally deferring rule transitions tointermediatefor breadth-first processing.- Parameters:
closureBusy- busy set for right-recursion / EOF* guards; production callers pass the retainedOpenAddressedHashSet, but anySetis accepted so the protected simulator override SPI stays interface-oriented
-