Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d8f0007
Tweak release doc
parrt Feb 20, 2023
681d46a
Update release docs (#4136)
ericvergnaud Feb 23, 2023
89de611
Provide JavaScript port of TokenStreamRewriter (#3560)
eirikur-grid Feb 26, 2023
bc5a76f
export token channel (#4143)
ericvergnaud Feb 26, 2023
60b4e27
added null | string union type (#4147)
sharknoon Feb 28, 2023
29de023
Limit use of Posix threads to Unix (#4140)
hs-apotell Mar 3, 2023
c455b7f
fix: Some code that should have been destined for /v4 was instead put…
Mar 5, 2023
e25d499
Remove redundant source code from go runtime (#4155)
Mar 5, 2023
8ac9c4b
README: Update required Java version (#4129)
Krzmbrzl Mar 5, 2023
60a8a6d
cmake: Fix output dir for Visual Studio generator and for when ANTLR_…
Leo1690 Mar 5, 2023
2f4f85b
Cpp: Remove code duplication (#3995)
Krzmbrzl Mar 5, 2023
21b27df
Changed Parser typings (#4149)
sharknoon Mar 8, 2023
d77766b
fix: Fixes the failing go runtime test suite which was missing the /v…
Mar 9, 2023
4ab43ac
present antlr before versioning (#4156)
ericvergnaud Mar 9, 2023
b0713e2
fix: Prevent use of labels such as start= from generating code that c…
Mar 9, 2023
223c8ae
Feature/gotestfix (#4168)
Mar 10, 2023
c466045
Feature/docclean Greatly improve the godoc comments in the runtime (#…
Mar 10, 2023
ccd0ed4
Feature/fixembedding (#4176)
Mar 13, 2023
7fb762e
fix incorrect prototype (#4184)
ericvergnaud Mar 16, 2023
2ad9ef9
fix: Fixes merge arrays to perform an actual comparison rather than c…
jimidle Mar 15, 2023
f91b21e
doc: Update TODO comment in prediction_context now that #3967 is fixed
jimidle Mar 15, 2023
4a364b2
fix: Unbeliveably, the PredictionContext cache did not work!
jimidle Mar 15, 2023
58121d5
feat: Fix up the parsing cache
jimidle Mar 15, 2023
28ef5b2
fix: Massive performance improvement by fixing comparison functions
jimidle Mar 16, 2023
d0e8f2b
fix: delete commented out code
jimidle Mar 16, 2023
c98ffad
test: Tewmporarilly disable one of the tests programs for the go runtime
jimidle Mar 16, 2023
bf37980
feat: Improve the runtime performance of the go test suite
jimidle Mar 15, 2023
a597aec
fix: Minor updates to address Ivan's PR review
jimidle Mar 16, 2023
76972cb
fix: reverse accidental IntelliJ formatting
jimidle Mar 17, 2023
c4a4442
fix: Change codegen and runtime to eliminate panic() and recover() as…
jimidle Mar 17, 2023
c6bbbd3
feat: Another 50%+ performance improvement
jimidle Mar 18, 2023
76bb3e1
[Typescript] Add missing methods typing declaration (#4145)
hieunguyen2211 Mar 22, 2023
91e2909
do not modify String.prototype in js package (#4200)
jharris4 Mar 22, 2023
f1b8982
Issue #4185: Too many artifacts fail to upload (#4186)
hs-apotell Mar 22, 2023
3a62248
feat: Stop using pointers for INterval class
jimidle Mar 19, 2023
fc38127
feat: Refactor PredictionContexts so that it does not use an interface
jimidle Mar 20, 2023
bb5d674
feat: Remove ocde and structs that are now replaced
jimidle Mar 20, 2023
4196a07
feat: Incorporate predefined variables for empty cache into the one p…
jimidle Mar 20, 2023
7e60bb9
fix: Tiny correct to parent check for singleton context
jimidle Mar 24, 2023
2f396b3
fix: Correct config cache comparators improvie performance
jimidle Mar 28, 2023
84c22a8
fix: Correct comparison functions for PredictionContexts not they are…
jimidle Mar 28, 2023
7a2c3c3
fix: Properly fix the context caching so that it exactly relfects Java
jimidle Mar 28, 2023
62d8439
feat: Stop using interfaces for ATNConfigSets
jimidle Mar 28, 2023
4476b9b
fix: Remove useless Getters and Setters
jimidle Mar 28, 2023
18b5bbf
fix: Get rid of interface for ATNConfig
jimidle Mar 28, 2023
2e93c77
Merge branch 'dev' into feature/performance
Mar 28, 2023
3b923fa
fix: As suspected, merging on GitHub went slightly wrong.
jimidle Mar 28, 2023
86bc5cb
fix: remove new memory handler from this brnach
jimidle Mar 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
349 changes: 174 additions & 175 deletions runtime/Go/antlr/v4/atn_config.go

Large diffs are not rendered by default.

180 changes: 37 additions & 143 deletions runtime/Go/antlr/v4/atn_config_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,21 @@ import (
"fmt"
)

type ATNConfigSet interface {
Hash() int
Equals(o Collectable[ATNConfig]) bool
Add(ATNConfig, *DoubleDict) bool
AddAll([]ATNConfig) bool

GetStates() *JStore[ATNState, Comparator[ATNState]]
GetPredicates() []SemanticContext
GetItems() []ATNConfig

OptimizeConfigs(interpreter *BaseATNSimulator)

Length() int
IsEmpty() bool
Contains(ATNConfig) bool
ContainsFast(ATNConfig) bool
Clear()
String() string

HasSemanticContext() bool
SetHasSemanticContext(v bool)

ReadOnly() bool
SetReadOnly(bool)

GetConflictingAlts() *BitSet
SetConflictingAlts(*BitSet)

Alts() *BitSet

FullContext() bool

GetUniqueAlt() int
SetUniqueAlt(int)

GetDipsIntoOuterContext() bool
SetDipsIntoOuterContext(bool)
}

// BaseATNConfigSet is a specialized set of ATNConfig that tracks information
// ATNConfigSet is a specialized set of ATNConfig that tracks information
// about its elements and can combine similar configurations using a
// graph-structured stack.
type BaseATNConfigSet struct {

// TODO: Is this actually valid? JI
type ATNConfigSet struct {
cachedHash int

// configLookup is used to determine whether two BaseATNConfigSets are equal. We
// configLookup is used to determine whether two ATNConfigSets are equal. We
// need all configurations with the same (s, i, _, semctx) to be equal. A key
// effectively doubles the number of objects associated with ATNConfigs. All
// keys are hashed by (s, i, _, pi), not including the context. Wiped out when
// read-only because a set becomes a DFA state.
configLookup *JStore[ATNConfig, Comparator[ATNConfig]]
configLookup *JStore[*ATNConfig, Comparator[*ATNConfig]]

// configs is the added elements.
configs []ATNConfig
configs []*ATNConfig

// TODO: These fields make me pretty uncomfortable, but it is nice to pack up
// info together because it saves re-computation. Can we track conflicts as they
Expand All @@ -72,7 +31,7 @@ type BaseATNConfigSet struct {

// dipsIntoOuterContext is used by parsers and lexers. In a lexer, it indicates
// we hit a pred while computing a closure operation. Do not make a DFA state
// from the BaseATNConfigSet in this case. TODO: How is this used by parsers?
// from the ATNConfigSet in this case. TODO: How is this used by parsers?
dipsIntoOuterContext bool

// fullCtx is whether it is part of a full context LL prediction. Used to
Expand All @@ -97,19 +56,19 @@ type BaseATNConfigSet struct {
}

// Alts returns the combined set of alts for all the configurations in this set.
func (b *BaseATNConfigSet) Alts() *BitSet {
func (b *ATNConfigSet) Alts() *BitSet {
alts := NewBitSet()
for _, it := range b.configs {
alts.add(it.GetAlt())
}
return alts
}

// NewBaseATNConfigSet creates a new BaseATNConfigSet instance.
func NewBaseATNConfigSet(fullCtx bool) *BaseATNConfigSet {
return &BaseATNConfigSet{
// NewATNConfigSet creates a new ATNConfigSet instance.
func NewATNConfigSet(fullCtx bool) *ATNConfigSet {
return &ATNConfigSet{
cachedHash: -1,
configLookup: NewJStore[ATNConfig, Comparator[ATNConfig]](aConfCompInst),
configLookup: NewJStore[*ATNConfig, Comparator[*ATNConfig]](aConfCompInst),
fullCtx: fullCtx,
}
}
Expand All @@ -120,7 +79,7 @@ func NewBaseATNConfigSet(fullCtx bool) *BaseATNConfigSet {
//
// We use (s,i,pi) as the key.
// Updates dipsIntoOuterContext and hasSemanticContext when necessary.
func (b *BaseATNConfigSet) Add(config ATNConfig, mergeCache *DoubleDict) bool {
func (b *ATNConfigSet) Add(config *ATNConfig, mergeCache *JPCMap) bool {
if b.readOnly {
panic("set is read-only")
}
Expand Down Expand Up @@ -164,7 +123,7 @@ func (b *BaseATNConfigSet) Add(config ATNConfig, mergeCache *DoubleDict) bool {
}

// GetStates returns the set of states represented by all configurations in this config set
func (b *BaseATNConfigSet) GetStates() *JStore[ATNState, Comparator[ATNState]] {
func (b *ATNConfigSet) GetStates() *JStore[ATNState, Comparator[ATNState]] {

// states uses the standard comparator and Hash() provided by the ATNState instance
//
Expand All @@ -177,17 +136,7 @@ func (b *BaseATNConfigSet) GetStates() *JStore[ATNState, Comparator[ATNState]] {
return states
}

// HasSemanticContext returns true if this set contains a semantic context.
func (b *BaseATNConfigSet) HasSemanticContext() bool {
return b.hasSemanticContext
}

// SetHasSemanticContext sets whether this set contains a semantic context.
func (b *BaseATNConfigSet) SetHasSemanticContext(v bool) {
b.hasSemanticContext = v
}

func (b *BaseATNConfigSet) GetPredicates() []SemanticContext {
func (b *ATNConfigSet) GetPredicates() []SemanticContext {
predicates := make([]SemanticContext, 0)

for i := 0; i < len(b.configs); i++ {
Expand All @@ -201,11 +150,7 @@ func (b *BaseATNConfigSet) GetPredicates() []SemanticContext {
return predicates
}

func (b *BaseATNConfigSet) GetItems() []ATNConfig {
return b.configs
}

func (b *BaseATNConfigSet) OptimizeConfigs(interpreter *BaseATNSimulator) {
func (b *ATNConfigSet) OptimizeConfigs(interpreter *BaseATNSimulator) {
if b.readOnly {
panic("set is read-only")
}
Expand All @@ -221,7 +166,7 @@ func (b *BaseATNConfigSet) OptimizeConfigs(interpreter *BaseATNSimulator) {
}
}

func (b *BaseATNConfigSet) AddAll(coll []ATNConfig) bool {
func (b *ATNConfigSet) AddAll(coll []*ATNConfig) bool {
for i := 0; i < len(coll); i++ {
b.Add(coll[i], nil)
}
Expand All @@ -235,8 +180,7 @@ func (b *BaseATNConfigSet) AddAll(coll []ATNConfig) bool {
// only equal if they are in the same order too as Java uses ArrayList.equals(), which requires
// the same order.
//
// TODO: JI - Look to change the way config set is implemented. Improve data structure if possible
func (b *BaseATNConfigSet) Compare(bs *BaseATNConfigSet) bool {
func (b *ATNConfigSet) Compare(bs *ATNConfigSet) bool {
if len(b.configs) != len(bs.configs) {
return false
}
Expand All @@ -249,14 +193,14 @@ func (b *BaseATNConfigSet) Compare(bs *BaseATNConfigSet) bool {
return true
}

func (b *BaseATNConfigSet) Equals(other Collectable[ATNConfig]) bool {
func (b *ATNConfigSet) Equals(other Collectable[ATNConfig]) bool {
if b == other {
return true
} else if _, ok := other.(*BaseATNConfigSet); !ok {
} else if _, ok := other.(*ATNConfigSet); !ok {
return false
}

other2 := other.(*BaseATNConfigSet)
other2 := other.(*ATNConfigSet)
var eca bool
switch {
case b.conflictingAlts == nil && other2.conflictingAlts == nil:
Expand All @@ -273,7 +217,7 @@ func (b *BaseATNConfigSet) Equals(other Collectable[ATNConfig]) bool {
b.Compare(other2)
}

func (b *BaseATNConfigSet) Hash() int {
func (b *ATNConfigSet) Hash() int {
if b.readOnly {
if b.cachedHash == -1 {
b.cachedHash = b.hashCodeConfigs()
Expand All @@ -285,89 +229,41 @@ func (b *BaseATNConfigSet) Hash() int {
return b.hashCodeConfigs()
}

func (b *BaseATNConfigSet) hashCodeConfigs() int {
func (b *ATNConfigSet) hashCodeConfigs() int {
h := 1
for _, config := range b.configs {
h = 31*h + config.Hash()
}
return h
}

func (b *BaseATNConfigSet) Length() int {
return len(b.configs)
}

func (b *BaseATNConfigSet) IsEmpty() bool {
return len(b.configs) == 0
}

func (b *BaseATNConfigSet) Contains(item ATNConfig) bool {
func (b *ATNConfigSet) Contains(item *ATNConfig) bool {
if b.configLookup == nil {
panic("not implemented for read-only sets")
}

return b.configLookup.Contains(item)
}

func (b *BaseATNConfigSet) ContainsFast(item ATNConfig) bool {
func (b *ATNConfigSet) ContainsFast(item *ATNConfig) bool {
if b.configLookup == nil {
panic("not implemented for read-only sets")
}

return b.configLookup.Contains(item) // TODO: containsFast is not implemented for Set
}

func (b *BaseATNConfigSet) Clear() {
func (b *ATNConfigSet) Clear() {
if b.readOnly {
panic("set is read-only")
}

b.configs = make([]ATNConfig, 0)
b.configs = make([]*ATNConfig, 0)
b.cachedHash = -1
b.configLookup = NewJStore[ATNConfig, Comparator[ATNConfig]](atnConfCompInst)
b.configLookup = NewJStore[*ATNConfig, Comparator[*ATNConfig]](aConfCompInst)
}

func (b *BaseATNConfigSet) FullContext() bool {
return b.fullCtx
}

func (b *BaseATNConfigSet) GetDipsIntoOuterContext() bool {
return b.dipsIntoOuterContext
}

func (b *BaseATNConfigSet) SetDipsIntoOuterContext(v bool) {
b.dipsIntoOuterContext = v
}

func (b *BaseATNConfigSet) GetUniqueAlt() int {
return b.uniqueAlt
}

func (b *BaseATNConfigSet) SetUniqueAlt(v int) {
b.uniqueAlt = v
}

func (b *BaseATNConfigSet) GetConflictingAlts() *BitSet {
return b.conflictingAlts
}

func (b *BaseATNConfigSet) SetConflictingAlts(v *BitSet) {
b.conflictingAlts = v
}

func (b *BaseATNConfigSet) ReadOnly() bool {
return b.readOnly
}

func (b *BaseATNConfigSet) SetReadOnly(readOnly bool) {
b.readOnly = readOnly

if readOnly {
b.configLookup = nil // Read only, so no need for the lookup cache
}
}
func (b *ATNConfigSet) String() string {

func (b *BaseATNConfigSet) String() string {
s := "["

for i, c := range b.configs {
Expand Down Expand Up @@ -399,15 +295,13 @@ func (b *BaseATNConfigSet) String() string {
return s
}

type OrderedATNConfigSet struct {
*BaseATNConfigSet
}

func NewOrderedATNConfigSet() *OrderedATNConfigSet {
b := NewBaseATNConfigSet(false)

// This set uses the standard Hash() and Equals() from ATNConfig
b.configLookup = NewJStore[ATNConfig, Comparator[ATNConfig]](aConfEqInst)

return &OrderedATNConfigSet{BaseATNConfigSet: b}
// NewOrderedATNConfigSet creates a config set with a slightly different Hash/Equal pair
// for use in lexers.
func NewOrderedATNConfigSet() *ATNConfigSet {
return &ATNConfigSet{
cachedHash: -1,
// This set uses the standard Hash() and Equals() from ATNConfig
configLookup: NewJStore[*ATNConfig, Comparator[*ATNConfig]](aConfEqInst),
fullCtx: false,
}
}
4 changes: 2 additions & 2 deletions runtime/Go/antlr/v4/atn_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package antlr

var ATNSimulatorError = NewDFAState(0x7FFFFFFF, NewBaseATNConfigSet(false))
var ATNSimulatorError = NewDFAState(0x7FFFFFFF, NewATNConfigSet(false))

type IATNSimulator interface {
SharedContextCache() *PredictionContextCache
Expand All @@ -24,7 +24,7 @@ func (b *BaseATNSimulator) getCachedContext(context *PredictionContext) *Predict
}

// TODO: Should this be guarded by a mutex?
visited := NewJStore[*PredictionContext, Comparator[*PredictionContext]](pContextEqInst)
visited := NewJMap[*PredictionContext, *PredictionContext, Comparator[*PredictionContext]](pContextEqInst)

return getCachedBasePredictionContext(context, b.sharedContextCache, visited)
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/Go/antlr/v4/atn_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type BaseATNState struct {
transitions []Transition
}

func NewBaseATNState() *BaseATNState {
func NewATNState() *BaseATNState {
return &BaseATNState{stateNumber: ATNStateInvalidStateNumber, stateType: ATNStateInvalidType}
}

Expand Down
Loading