scanner: refactor new_plain_scanner to accept file_path, file_base an…#27199
scanner: refactor new_plain_scanner to accept file_path, file_base an…#27199whisky-jb wants to merge 1 commit into
Conversation
|
15 ci errors (master is green now) |
Tried to merge latest master, but still getting errors, unrelated to my change? |
|
1 sanitized job times out on master. Your PR has 13 failing. |
|
I'm unclear why this is not merged, can you provide me some more details? Still learning how to contribute, so some guidance appreciated. |
|
try again |
new_scanner_file now uses new_plain_scanner as its base, eliminating the duplicated Scanner struct initialization.
|
Don't worry, I'll fix your PR myself today. |
|
@medvednikov did you have any chance to look into this? |
|
I did, this change is not as trivial as it seems. I'll post more details a bit later. |
|
The change is relatively simple, I try to avoid twice the similar call to &Scanner with the same parameters. btw. working through a compiler book, that's why I started with the scanner and got stuck there ;-) |
|
I think the tricky part is that these two
So the duplication is not only mechanical duplication. It also makes the provenance mode explicit. Anyway, this is only my personal opinion, and for me the main risk of this PR is exactly there, it may look like a small deduplication, but it touches the scanner source/provenance contract. :) |
Let me disagree! new_plain_scanner is not declared public, so everybody will use either new_scanner_file or new_scanner and for them, the contract stays the same! |
|
Yes, My concern is internal, not external. In V, non-public items are still callable from other files in the same module. The fragile part is that after this change, So the current That is why I think this is more than a public/private API question. It is an internal invariant issue. For example, after this PR, code inside the Again, I am not saying that the current PR path is broken today. As far as I can see, the current |
|
It is obviously possible, that inside the module, one can screw up things, there is no protection against this. On the other hand, we have 2 definitions for the scanner which are almost identical, this is not best practice. So my aim was to get ride of the code duplication. Not sure if there would be better ways of doing it? |
|
Removing the duplicated I think the safer shape would be to deduplicate only the common fields, while keeping the two provenance modes explicit. So For file-backed source, there could be a second small internal helper that receives the already-read That removes the duplicated common initialization, but avoids a scanner state where Names aside, the important part is that Of course, this is only my personal opinion, not something mandatory. |
Refactor scanner, duplicated code consolidated.