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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please simplify:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
But, I bet there are other places like this. For example, these two statements are very similar to this bug, with parameters of type
Ref<> &
.antlr4/runtime/Cpp/runtime/src/atn/ATNConfig.h
Line 39 in aa1f1f1
antlr4/runtime/Cpp/runtime/src/atn/PredictionContextCache.cpp
Line 55 in aa1f1f1
People make changes that "fix" a tiny little problem, but don't read the damn code. @parrt what about these occurrences?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's why I'm opposed to refactoring for refactoring sake. It can introduce all sorts of subtle bugs.
We have to be careful here for example because the real solution is that context objects should never be null... There is a sentinel that indicates empty stack. That is why I didn't simply add the null checks... There's a larger bug and we shouldn't paint over it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then, these should be at least assert()'s so that it crashes with a message.
Is there a method that anyone wrote that checks the integrity of the data structure so I can percolate the check around and snuff this bug out? Someone is creating an array with a null pointer at the end of the array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I was hoping to do with the Data dump from the ATN simulator... We could use it to compare how the different targets work.
BTW, here is the start of me trying to fix C++ by refracturing the complex code: #3863
I gave up trying to debug when a print statement exploded all over my screen with compile errors.
Here is my attempt to start a tracer for ATN: #3817
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think your assumption that there cannot be null parents in an array of PredicateContext may be wrong. Many ports violate that assumption.
I wrote a Check() function that checks the integrity of the ArrayPredictionContext and it led to this code in the Cpp target. The code creates a "parents" array containing a null pointer.
antlr4/runtime/Cpp/runtime/src/atn/PredictionContext.cpp
Line 319 in 16cfc6b
Compare this with CSharp, Java, PHP, and Python3.
CSharp:
antlr4/runtime/CSharp/src/Atn/PredictionContext.cs
Line 391 in 16cfc6b
Java:
antlr4/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContext.java
Line 324 in 16cfc6b
PHP:
https://github.com/antlr/antlr-php-runtime/blob/64fd1e2e8ca6fd80b57f53a0729e74b984bd767f/src/PredictionContexts/PredictionContext.php#L371
Python3:
antlr4/runtime/Python3/src/antlr4/PredictionContext.py
Line 420 in 16cfc6b
For Dart, null pointers are disallowed (I think??). In any case, the code looks like it never creates a "parents" array with a null pointer.
antlr4/runtime/Dart/lib/src/prediction_context.dart
Line 247 in 16cfc6b
For Go, I think it too was written without using null pointers:
antlr4/runtime/Go/antlr/prediction_context.go
Line 534 in 16cfc6b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, dang. You're right. Hmm...yeah, touching the ATN simulation is really risky as I don't remember the details well. :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I can relate to forgetting details. It definitely is concerning that a couple of the targets don't have nulls in the parents array. I think to be "safe", I should test this against the regression tests of grammars-v4 for Cpp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love to do a comparison of the java target against other targets. I have good trust in java behavior.