ATN serialization improvements#3556
Conversation
|
Hi. can you remind me what the primary purposes of shuffling code? as usual I don't like creating new files unless we have to. could you help me understand the excess serialization going on? thanks! |
|
I've moved
|
haha! Yes, I see that now. It's only for debugging/testing I think. A better name is maybe summarize() or describe() as decode sounds like deserialize. Not sure we need separate class/file for a function. Why not just put decode() into TestATNSerialization.java? |
|
can you remind me what the excess serialization stuff you're referring to? thanks. looks like there is an API change internally that causes fairly widespread changes. |
Ok.
Because it's already quite a big class and
I've encountered it during debugging. I've noticed the ATN is being serialized (call of |
Yes, big is bad but on the other hand so it is making a class with one method and introducing a new file. I think I would prefer just dumping the decode method into the test class. Hmm... looks like some of the targets have implemented decode() like C++ (ATNSerializer.h):
Ah. Hmm...let me pull in your branch and use a good difference tool instead of the website see what the changes really look like. |
| content.append("\n"); | ||
|
|
||
| IntegerList serializedATN = ATNSerializer.getSerialized(g.atn, g.getLanguage()); | ||
| // Uncomment if you'd like to write out histogram info on the numbers of |
There was a problem hiding this comment.
seems like we should leave this in
| public ParserFile parserFile(String fileName) { return null; } | ||
|
|
||
| @Override | ||
| public Parser parser(ParserFile file) { return null; } |
There was a problem hiding this comment.
at first glance it looks strange that lexer() function below does not also need an ATN.
There was a problem hiding this comment.
Yes, because lexer works a bit differently and gets atnData from somewhere else. I'll take a look if it's possible to unify the parameter.
There was a problem hiding this comment.
It depends on this code: https://github.com/antlr/antlr4/blob/dev/tool/src/org/antlr/v4/codegen/OutputModelController.java#L140-L152 There is no call to lexer method from OutputModelController but call to constructor directly.
|
|
||
| public Lexer(OutputModelFactory factory, LexerFile file) { | ||
| super(factory); | ||
| this.file = file; // who contains us? |
There was a problem hiding this comment.
seems like that's a useful comment
There was a problem hiding this comment.
Maybe renamed file to containingFile instead of using such a comment? I prefer getting rid of comments if possible.
|
|
||
| public Parser(OutputModelFactory factory, ParserFile file) { | ||
| super(factory); | ||
| this.file = file; // who contains us? |
|
|
||
| ruleNames = g.rules.keySet(); | ||
| rules = g.rules.values(); | ||
| atn = new SerializedATN(factory, g.atn); |
There was a problem hiding this comment.
I'm not a fan of flipping all of these IF to ?:. I don't think they are is easy to read.
There was a problem hiding this comment.
you're doing all sorts of code revisions that are not really needed but are costing my time to review.
There was a problem hiding this comment.
not a problem. You are a valuable contributor and a hardcore tech guy!! I just think maybe we need to synchronize better :) your instincts seem very good but I have to fit that into my limited focus time.
| errMgr.toolError(ErrorType.CANNOT_WRITE_FILE, ioe); | ||
| } | ||
| } | ||
| IntegerList atnData = gencode && g.tool.getNumErrors()==0 |
There was a problem hiding this comment.
not sure I like passing this ATN everywhere. A widespread change for a worthy goal but not sure it's worth this particular solution. Why not simply move this code that writes out the interp file to the "if gencode" section? then we are reusing and not recomputing it right?
There was a problem hiding this comment.
Unfortunately, it's not so simple. Code generator uses atnData deeply internally during generation. StringTemplate library uses the serialized field from SerializedATN.
Stack trace:
atnData for interp file is being calculated in Tool.java. It should be passed to the code generator somehow.
|
I will close this as it is superseded by the big PR I just pulled in. |


Uh oh!
There was an error while loading. Please reload this page.