Skip to content

Conversation

jimidle
Copy link
Collaborator

@jimidle jimidle commented Aug 13, 2022

fix: #3718 Implement generic collections and fiux LA(*) optimizer

o Implements collections using generics to solve has conflicts in previous implementation of
DFAState collections and alt conflict resolution
o Change alt and config to use correct hash and equals as per Java
o Fix LA()*) runtime optimization routine
o A few tidy ups on comments etc

NB: There are now extra hash() and equals() routines that I had to leave there unless I wanted to go through
all the code and rationalize and refactor. Not worth it if we are going to rewrite. The generic collections work for this
purpose but the make up of the currents structs etc, forces a few hacks that won't be needed with better structure.

Sending this PR without tests for the collections as:

o they can't be worse than what is there, that doesn't work
o they are tested with real grammars anyway
o it is Saturday and time to get ready for EPL to start in England - come on Leeds

  o Implement collections with generics to solve hash collisions
  o Fix type casting in LL start parser simulation optimization
  o General minor tidy ups

Acknowledgements to @kaby76 for help with tracing errors

Signed-off-by: Jim.Idle <jimi@gatherstars.com>
@jimidle
Copy link
Collaborator Author

jimidle commented Aug 13, 2022

I will have to remember the DCO. I think some of the builds are failing because the tests are failing. Somebody changed a test somewhere it seems.

@kaby76
Copy link
Contributor

kaby76 commented Aug 13, 2022

Please check that this fixes the original SimpleBoolean.g4, input p15.txt performance. I don't see the perf improvement. Looks like it should.


/** Track the elements as they are added to the set; supports get(i) */
public final ArrayList<ATNConfig> configs = new ArrayList<ATNConfig>(7);
public AbstractConfigHashSet configLo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a mistaken chop chop here :)

@parrt
Copy link
Member

parrt commented Aug 13, 2022

I get 5 failures running the tests:

critter:~/antlr/code/antlr4/runtime-testsuite $ mvn -Dtest=go.** test
...

@parrt
Copy link
Member

parrt commented Aug 13, 2022

@jimidle I changed CI for hosted github actions to 1.19 Go.

@jimidle
Copy link
Collaborator Author

jimidle commented Aug 14, 2022 via email

@parrt
Copy link
Member

parrt commented Aug 14, 2022

No prob. I do crazy stuff like that all the time. Can you check on the go test failures?

@jimidle
Copy link
Collaborator Author

jimidle commented Aug 14, 2022 via email

@parrt
Copy link
Member

parrt commented Aug 14, 2022

Possibly but we have a general test mechanism that gens tests across targets. You can check the antlr doc dir and see testing file

@parrt
Copy link
Member

parrt commented Aug 14, 2022

The checks dialog here should also give the results though I just tuned off all but github hosted CI and circleci

Jim.Idle added 3 commits August 14, 2022 10:19
Signed-off-by: Jim.Idle <jimi@gatherstars.com>
Signed-off-by: Jim.Idle <jimi@gatherstars.com>
With older versions of go, there was no good way to tell the compiler to use your local
development copy of a particular package instead of the one installed in GOPATH/src/...

However, we are now using modules, which allows us to tell the compiler that instead of
a module downloaded to GOPATH/pkg, to use a local copy on disk.

Hence this change removes the need to copy the whole of the go installation to a
tempoorary location, then put the antlr go runtime in to the go installation as if it was
part of the compiler. Hence the execution time for the go tests is now faster than before.

This works because when the generated code is placed in the temporary location, we create
a go.mod file for it, tell the module to replace the online module for the go runtime with
the local copy on disk, then ro a go mod tidy to add the dependencies from the code (which
avoids network access, so it is instant), which adds the ANTLR dependency itself (which is
then replaced at compile time).

All go runtime tests now pass.

Signed-off-by: Jim.Idle <jimi@gatherstars.com>
@jimidle
Copy link
Collaborator Author

jimidle commented Aug 15, 2022

Please check that this fixes the original SimpleBoolean.g4, input p15.txt performance. I don't see the perf improvement. Looks like it should.

It does, but you need to make sure you are actually compiling with this code. You cannot do a go get with my fork because of the way go get works - it is defect in using fork with go code. You have to clone my repo, then either use GOWORK, which is my preference, to tell the compiler to use that code for your build, or use a replace in the go mod for the test code. Or just wait for Ter to merge the PR and use:

go get -u github.com/antlr/antlr4/runtime/Go/antlr@dev

But let me double check - I am using the project that was supplied in github at the top of the original report. I will see if what you are pointing to is actually the same thing.

OK - I double checked - the grammar is exactly the same and the input I am using actually has a couple of extra 1 EQ 2 OR statements.

@jimidle
Copy link
Collaborator Author

jimidle commented Aug 15, 2022

Hmmm - seems to be a syntax error in the push - not sure how that happened... ah, it didn't, the go compiler being used for that test is too old. Easy fix I presume Ter.

@jimidle
Copy link
Collaborator Author

jimidle commented Aug 15, 2022

Ah - the ci go testing the runtime is using a go compiler that is too old. That test also needs updating to use go 1.18 or go 1.19 (preferable).

@jimidle
Copy link
Collaborator Author

jimidle commented Aug 15, 2022

@jimidle I changed CI for hosted github actions to 1.19 Go.

Also needs changing for the ci test of the go runtime using the test suite. That is failing because the compiler is too old

@kaby76
Copy link
Contributor

kaby76 commented Aug 15, 2022

This isn't fixing the Go performance problem for me.

Someone else, please verify.

@jimidle
Copy link
Collaborator Author

jimidle commented Aug 15, 2022 via email

@kaby76
Copy link
Contributor

kaby76 commented Aug 15, 2022

You're right. It does fix the perf problem. I upgraded to 1.18.3, "learned" about workspaces, and tried it out. I modeled the changes after this, and it works great.

(I do not understand yet how a go build finds all the workspace code because go.work can in theory have "use" to Go modules anywhere on the entire file system. But, those modules do not have pointers back to the go.work file to pick up all the modified modules in the workspace. If it's relative, then what happens if I copy a stray go.work into "~"?)

@parrt
Copy link
Member

parrt commented Aug 15, 2022

Also needs changing for the ci test of the go runtime using the test suite. That is failing because the compiler is too old

I'm not sure where are you mean by ci as the dev branch shows for hosted CI:

    - name: Setup Go 1.19
      if: matrix.target == 'go'
      uses: actions/setup-go@v3
      with:
        go-version: '^1.19'

Do you mean something in our test rig (Java) code for antlr itself refers to a Go version?

Oh, sorry. CIRCLE ci. Let me check

@parrt parrt merged commit ef65951 into antlr:dev Aug 15, 2022
@parrt
Copy link
Member

parrt commented Aug 15, 2022

I think master works but dev doesn't for go on circlei, though we might be able to dump circleci now that github hosted CI works.

Thanks for all the hard work, @jimidle !!!

@jimidle
Copy link
Collaborator Author

jimidle commented Aug 16, 2022

I think master works but dev doesn't for go on circlei, though we might be able to dump circleci now that github hosted CI works.

Thanks for all the hard work, @jimidle !!!

Yes - sorry I was not sure which build test were running where. You are correct that it was the circleci that was trying to use the old compiler and hence that trigger failed.

I will delete this branch once I verify that the dev branch is in sync

@jimidle
Copy link
Collaborator Author

jimidle commented Oct 11, 2022 via email

@jimidle
Copy link
Collaborator Author

jimidle commented Oct 11, 2022 via email

@parrt
Copy link
Member

parrt commented Oct 13, 2022

This one has been merged... Maybe you meant to comment on a different PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants