Fix hash and equals contract and align the simulator with Java - #44
Merged
Conversation
Merged
Values that compare equal now hash equally for ATN configs, prediction contexts and bit sets, so sets and maps stop degrading into linear scans. MurmurHash matches Java bit for bit, using PHP's native murmur3a when available with a pure PHP fallback. ATNState::hashCode() returns the state number as in Java and C#. The anonymous Equivalence class in ATNConfigSet is now a named class so the set can be serialized. setTrace(false) clears the tracer so isTrace() reports the right value. The lexer decodes its input once instead of on every read, and the hot loops in both simulators avoid repeated method calls.
marcospassos
force-pushed
the
fix/runtime-alignment
branch
from
August 15, 2026 19:44
19f40b0 to
222f990
Compare
marcospassos
force-pushed
the
fix/runtime-alignment
branch
from
August 15, 2026 19:46
222f990 to
4db05a9
Compare
This was referenced Aug 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes correctness issues found by running this runtime and the Java reference over the same grammars and inputs and comparing the output.
Changes
murmur3awhen available and falls back to a pure PHP implementation otherwise.ATNState::hashCode()returns the state number, as in Java and C#.Equivalenceclass inATNConfigSetis now a named class, so the set can be serialized.setTrace(false)clears the tracer, soisTrace()reports the right value. Enabling twice no longer attaches two listeners.These also make the runtime faster, but the gain varies too much per grammar to quote a single figure here.
Verification
PHP.stg, not from this repository.Closes #33
Closes #36
Closes #12
Supersedes #28 and #34, which this replaces.
No tests in this PR. They come in a follow up.