Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JavaScript] publish getNumberOfSyntaxErrors method #4240

Closed
wants to merge 109 commits into from

Conversation

killerall
Copy link

Implemented getNumberOfSyntaxErrors for javascript runtime.

parrt and others added 30 commits February 19, 2023 17:31
Signed-off-by: Eric Vergnaud <eric.vergnaud@wanadoo.fr>
Signed-off-by: Josua Frank <josua.frank@daimlertruck.com>
Co-authored-by: Josua Frank <josua.frank@daimlertruck.com>
Posix threads are available only on Unix (and unix like) platforms.
Wrap the dependency accordingly so builds don't fail on other platforms.

Signed-off-by: HS <hs@apotell.com>
… in to the root (pre v4) files (antlr#4154)

- Incorporate an interative tree walker
 - Expose Reset() and String() in lexer/token and add test

Signed-off-by: Jim.Idle <jimi@idle.ws>
* feat: Remove the old version of the source code, as at v4.x.y the source must be under /v4 for modules

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: tidy up old version of go.mod (non v4 version), which is now deprecated

Signed-off-by: Jim.Idle <jimi@idle.ws>

---------

Signed-off-by: Jim.Idle <jimi@idle.ws>
The badge in the README suggests that ANTLR requires Java 7 or higher,
whereas since ANTLR v4.10 Java 11 or higher is required.

Signed-off-by: Robert Adam <dev@robert-adam.de>
(cherry picked from commit 8188dc5)
…BUILD_CPP_TESTS is not set (antlr#4121)

Signed-off-by: Leonardo Sarmiento <leonardo@moduleworks.com>
Co-authored-by: Leonardo Sarmiento <leonardo@moduleworks.com>
* Cpp: Remove code duplication

The same function was defined inside multiple different source files (in
an anonymous namespace).
Not only is this generally bad practice from a maintenance point of
view, but it also break unity builds (which can speed up compilation
times A LOT).

The fix simply consists in introducing a new Utils file that contains
the single implementation and every source file that uses this function
simply has to be linked against that new file (and include the
corresponding header).

Signed-off-by: Robert Adam <dev@robert-adam.de>

* CI: Enable unity builds for cpp targets

This should reduce the build time for those steps significantly

Note: Unity builds are enabled only for cmake-based CI builds

Signed-off-by: Robert Adam <dev@robert-adam.de>

* CI: Perform unity and non-unity cpp builds

Signed-off-by: Robert Adam <dev@robert-adam.de>

---------

Signed-off-by: Robert Adam <dev@robert-adam.de>
Signed-off-by: Josua Frank <josua.frank@daimlertruck.com>
Co-authored-by: Josua Frank <josua.frank@daimlertruck.com>
…4 off the replace option on the go.mod file (antlr#4163)

Arrrgh!

Signed-off-by: Jim.Idle <jimi@idle.ws>
…lashes with builtin funcs (antlr#4161)

Signed-off-by: Jim.Idle <jimi@idle.ws>
* fix: Fixes the failing go runtime test suite which was missing the /v4 off the replace option on the go.mod file

Arrrgh!

Signed-off-by: Jim.Idle <jimi@idle.ws>

* present antlr before versioning (antlr#4156)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Prevent use of labels such as start= from generating code that clashes with builtin funcs (antlr#4161)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Cater for the fact that some test rules use start as a label or rule name

As a fix for other cvode gen errors when start, end, or exception are used as
label names, they are now translated to have a suffix of `_` at code gen time.
However, the runtime tests sometimes use start as a rule name and so we must now
cater for this in the tests.

Signed-off-by: Jim.Idle <jimi@idle.ws>

---------

Signed-off-by: Jim.Idle <jimi@idle.ws>
Co-authored-by: ericvergnaud <eric.vergnaud@wanadoo.fr>
…ntlr#4169)

* doc: Updates to some of the Go doc comments to start a ful ldocumentation cleanup

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: More documentation fixes.

Using this as a method of forcing myself to read every line of code in the runtime, and therefore
discover mistakes in the original implementation. And, of course, actually working docs for the
Go runtime, can only be a good thing.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: More documentation fixes

Also changes the exporet level of a some variables and funcs that were not correct,
even though no user has currently needed them it would seem.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: Many updates to document exported fuctions correctly and reformat the ingerited Java code

It looks like a massive amount of changes, but it is almost all doc or changing exports or renaming
unused paramters etc to make the Go linter happy.

No actual code changes yet.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: More additions and corrections to the Go documentation for the runtime

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: Final clean of exported func and type documentation

There will be more to do here as there are a lot of things that are hidden internal to the antlr
package that probably should not be. There are also a lot of exported funcs and types without
any documentation, that will eventually need to be cleaned up.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* Changed Parser typings (antlr#4149)

Signed-off-by: Josua Frank <josua.frank@daimlertruck.com>
Co-authored-by: Josua Frank <josua.frank@daimlertruck.com>
Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Fixes the failing go runtime test suite which was missing the /v4 off the replace option on the go.mod file (antlr#4163)

Arrrgh!

Signed-off-by: Jim.Idle <jimi@idle.ws>

* present antlr before versioning (antlr#4156)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Prevent use of labels such as start= from generating code that clashes with builtin funcs (antlr#4161)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* Feature/gotestfix (antlr#4168)

* fix: Fixes the failing go runtime test suite which was missing the /v4 off the replace option on the go.mod file

Arrrgh!

Signed-off-by: Jim.Idle <jimi@idle.ws>

* present antlr before versioning (antlr#4156)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Prevent use of labels such as start= from generating code that clashes with builtin funcs (antlr#4161)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Cater for the fact that some test rules use start as a label or rule name

As a fix for other cvode gen errors when start, end, or exception are used as
label names, they are now translated to have a suffix of `_` at code gen time.
However, the runtime tests sometimes use start as a rule name and so we must now
cater for this in the tests.

Signed-off-by: Jim.Idle <jimi@idle.ws>

---------

Signed-off-by: Jim.Idle <jimi@idle.ws>
Co-authored-by: ericvergnaud <eric.vergnaud@wanadoo.fr>
Signed-off-by: Jim.Idle <jimi@idle.ws>

---------

Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Josua Frank <josua.frank@daimlertruck.com>
Co-authored-by: Josua Frank <frank.josua@gmail.com>
Co-authored-by: Josua Frank <josua.frank@daimlertruck.com>
Co-authored-by: ericvergnaud <eric.vergnaud@wanadoo.fr>
* feat: Createa n Init routine for BaseATNConfig so we can embed sructs rather than allocate to pointers

Signed-off-by: Jim.Idle <jimi@idle.ws>

* feat: Change BaseATNConfig to be properly embedded in other structs such as LexerATNConfig instead of by pointer

This is the first of many changes that switches the embedded class structure that was copying
Java class hieracrchy from allocations/new to proper embedding such that any struct is
allocated with one allocation not two or more. Main PR will cover what this means.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* feat: Change embedding for ATNBaseSimulator to true embedding instaed of pointer

Saves an extra allocation and helps the GC

Signed-off-by: Jim.Idle <jimi@idle.ws>

* feat: Switch the use of pointers to embedded ATN states to true embeddding

Saves many allocations and grbage collections

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Correct the way that PredictionContext is compared for merge

Should reduce allocation count by tons.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* Feature/docclean Greatly improve the godoc comments in the runtime (antlr#4169)

* doc: Updates to some of the Go doc comments to start a ful ldocumentation cleanup

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: More documentation fixes.

Using this as a method of forcing myself to read every line of code in the runtime, and therefore
discover mistakes in the original implementation. And, of course, actually working docs for the
Go runtime, can only be a good thing.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: More documentation fixes

Also changes the exporet level of a some variables and funcs that were not correct,
even though no user has currently needed them it would seem.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: Many updates to document exported fuctions correctly and reformat the ingerited Java code

It looks like a massive amount of changes, but it is almost all doc or changing exports or renaming
unused paramters etc to make the Go linter happy.

No actual code changes yet.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: More additions and corrections to the Go documentation for the runtime

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: Final clean of exported func and type documentation

There will be more to do here as there are a lot of things that are hidden internal to the antlr
package that probably should not be. There are also a lot of exported funcs and types without
any documentation, that will eventually need to be cleaned up.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* Changed Parser typings (antlr#4149)

Signed-off-by: Josua Frank <josua.frank@daimlertruck.com>
Co-authored-by: Josua Frank <josua.frank@daimlertruck.com>
Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Fixes the failing go runtime test suite which was missing the /v4 off the replace option on the go.mod file (antlr#4163)

Arrrgh!

Signed-off-by: Jim.Idle <jimi@idle.ws>

* present antlr before versioning (antlr#4156)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Prevent use of labels such as start= from generating code that clashes with builtin funcs (antlr#4161)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* Feature/gotestfix (antlr#4168)

* fix: Fixes the failing go runtime test suite which was missing the /v4 off the replace option on the go.mod file

Arrrgh!

Signed-off-by: Jim.Idle <jimi@idle.ws>

* present antlr before versioning (antlr#4156)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Prevent use of labels such as start= from generating code that clashes with builtin funcs (antlr#4161)

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Cater for the fact that some test rules use start as a label or rule name

As a fix for other cvode gen errors when start, end, or exception are used as
label names, they are now translated to have a suffix of `_` at code gen time.
However, the runtime tests sometimes use start as a rule name and so we must now
cater for this in the tests.

Signed-off-by: Jim.Idle <jimi@idle.ws>

---------

Signed-off-by: Jim.Idle <jimi@idle.ws>
Co-authored-by: ericvergnaud <eric.vergnaud@wanadoo.fr>
Signed-off-by: Jim.Idle <jimi@idle.ws>

---------

Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Josua Frank <josua.frank@daimlertruck.com>
Co-authored-by: Josua Frank <frank.josua@gmail.com>
Co-authored-by: Josua Frank <josua.frank@daimlertruck.com>
Co-authored-by: ericvergnaud <eric.vergnaud@wanadoo.fr>

* feat: Change BaseATNConfig to be properly embedded in other structs such as LexerATNConfig instead of by pointer

This is the first of many changes that switches the embedded class structure that was copying
Java class hieracrchy from allocations/new to proper embedding such that any struct is
allocated with one allocation not two or more. Main PR will cover what this means.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* feat: Change embedding for ATNBaseSimulator to true embedding instaed of pointer

Saves an extra allocation and helps the GC

Signed-off-by: Jim.Idle <jimi@idle.ws>

* fix: Correct the way that PredictionContext is compared for merge

Should reduce allocation count by tons.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* doc: Merge documentation updates

Signed-off-by: Jim.Idle <jimi@idle.ws>

* feat: Rework predictions tructs to use emedding instead of pointers

Signed-off-by: Jim.Idle <jimi@idle.ws>

* feat: more reworking of PredictionContext for embedding

Signed-off-by: Jim.Idle <jimi@idle.ws>

* feat: Ensure that EmptyPredictionContext is correctly initialized

Rework of the variaous PredictionContexts has reduced memory allocations to between
30% and 50% of previous version.

Signed-off-by: Jim.Idle <jimi@idle.ws>

* feat: Change from use of type casting to using stored type

Signed-off-by: Jim.Idle <jimi@idle.ws>

* feat: Convert CommonToken to true emedding rather than pointers

Signed-off-by: Jim.Idle <jimi@idle.ws>

---------

Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Josua Frank <josua.frank@daimlertruck.com>
Co-authored-by: Josua Frank <frank.josua@gmail.com>
Co-authored-by: Josua Frank <josua.frank@daimlertruck.com>
Co-authored-by: ericvergnaud <eric.vergnaud@wanadoo.fr>
Signed-off-by: Eric Vergnaud <eric.vergnaud@wanadoo.fr>
…omparing two pointers!

Fixes: antlr#3967
Closes antlr#3967

 - A small error was made whereby the comparison with a newly created merge `M` of two prediction contexts
  `a` and `b`, was comparing the pointers of `a` and `M` and not using the internal Equals() method.
  The ATN output trace is now equal.

 - Also adds a new testrig internal project (so it won't be used by `go get`) that allows quick setup
   and testing of ATN tracing for a test grammar and test input.

 - Excludes go performance profiles from git

 - Corrects a small error in one of the ATN tracing scripts.

Signed-off-by: Jim.Idle <jimi@idle.ws>
… fixed

Signed-off-by: Jim.Idle <jimi@idle.ws>
 - I missed this on my first evaluation of all the collections used
   by the code I inherited. The PredictionCache was implemented as a
   map using PredictionContext pointers as the key. This meant that
   there would never be a cache hit and the cache woudl just accumulate massive
   numbers of PredictionContext 'objects'!

Bloody hell. Sometimes it is difficult to spot such glaring errors. This change
vastly reduces memory usage. The next commit will fix the visited context look up
which also suffers from the same problem.

Fixes: antlr#3934
It probably also fixes a ton of performance and memory usage problems, which
I have yet to test.

Signed-off-by: Jim.Idle <jimi@idle.ws>
 - Note, I think that this still needs work, but it is a lot better memory wise.

Signed-off-by: Jim.Idle <jimi@idle.ws>
Some of the legacy code that tried to implement comparisons and hashing like Java was
just plain wrong. That stuff is buried deep in there and took a massive effort to
work out what was going wrong.

In the end, while the hash codes were OK for DFAState, the comparisons inherited from
the old code were just plain wrong for certain objects. With those corrected, there
is a massive improvement in performance all around.

I will push a PR for this stuff now, but I already see some massive potential gains
by getting rid of interfaces where we don't need them stopping the use of pointers everywhere
indiscrimiately.

Next task is going to be pure performance improvements until the Go runtime takes
its rightful place as the fastest implementation ;)

Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Jim.Idle <jimi@idle.ws>
 - I will of course fix this in a follow up PR, but the test DropLoopEntryBranchInLRRule_4
   currently hangs. It is also disabled for many other runtimes, so I think it is fine to get
   this PR in and then follow up with a fix for this test.

Signed-off-by: Jim.Idle <jimi@idle.ws>
 - Removes the need to perform a `go mod tidy` for every test. This change
   causes `go mod tidy` to be run once, after which it caches the go.mod and
   go.sum files for use by the remaining tests.

Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Jim.Idle <jimi@idle.ws>
… flowcontrol - 50% performance improvement

  - Prior to this change, a recognition error was tracked by performing a panic(),
    which the generated code for rules would then use recover() to discover. However,
    recover() is not like catch(){} in Java and is expensive to run even if there is
    no panic() to find on the execution stack. Eliminating this and doing a simple check
    at the end of rule execution brings with it a massive performance improvement up to
    50% of CPU execution time. Now that collections and context caching is working correctly
    this is a significant improvement in execution time.

Signed-off-by: Jim.Idle <jimi@idle.ws>
jimidle and others added 29 commits March 28, 2023 16:17
Too much emulation of the Java runtime structure means that many structs
are being called via interfaces, which introduces and extra look up. When
you add that lookup to call via a pointer and then even an extra lookup for
generics, then it becomes significant. This seems like a big commit but
it is all just changing the one type declaration.

This now allows us to get rid of the stupid getters and setters that just
clutter the code and are not idiomatic of Go anyway.

Signed-off-by: Jim.Idle <jimi@idle.ws>
Go does not use Getters and Setters unless there is some very good reason such
as copy on read or write. They can stop the compiler from inlining things so they
are now gone from ANTConfigSet, whihc is no longer an interface.

Signed-off-by: Jim.Idle <jimi@idle.ws>
Like other struct implementations, this was hidden by an
interface that did not need to be there. the only difference between
a lexer and parser config is the Hash/Equals and extra methods that only
the lexer calls.

Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Jim.Idle <jimi@idle.ws>
…f DFA collections

Signed-off-by: Jim.Idle <jimi@idle.ws>
Also corrects the formatting of some of the files as this can create false
compares in git.

Signed-off-by: Jim.Idle <jimi@idle.ws>
…er look

Signed-off-by: Jim.Idle <jimi@idle.ws>
…in some cases

Signed-off-by: Jim.Idle <jimi@idle.ws>
…each run

Signed-off-by: Jim.Idle <jimi@idle.ws>
Another small gain, but for one good parser this goes from 90ms to 64ms (for 16 large files)
so it won't make a lot of difference for poor parser, but good ones will see a nice kick here

Signed-off-by: Jim.Idle <jimi@idle.ws>
  o Uses reflection to check that the tree structure is all correct
  o Disables test that uses superClass as this basically doesn't work/isn't a concept in Go.

Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Ahmad Tameem <ahmad.tameem97@gmail.com>
Signed-off-by: Adrian Jutrowski <adrian.jutrowski@gmail.com>
…mpacted

Signed-off-by: Adrian Jutrowski <adrian.jutrowski@gmail.com>
…require

Signed-off-by: Adrian Jutrowski <adrian.jutrowski@gmail.com>
… be in the repo

Signed-off-by: Jim.Idle <jimi@idle.ws>
  - I will store this in my own repo and direct any future maintainers to there
    this will avoid any confusion.

Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Michael de Hoog <michael.dehoog@coinbase.com>
  - FileStream reader was reading in to bytes, then converting to string, then converting to runes
  - Created a stream that can initialize directly from an io.Reader, which is more idiomatic go
  - Cleaned up InputStream creation

Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Jim.Idle <jimi@idle.ws>
Signed-off-by: Rodrigo Antonio Godinho da Silva <rodrigo.antonio@totvs.com.br>
@killerall killerall closed this Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet