-
Notifications
You must be signed in to change notification settings - Fork 90
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
Remove different behaviour when single input #1902
Conversation
Personally, I like the approach. The extra indirection through an import should be entirely inconsequential. I don't see a good reason why tests couldn't be made to work with this either, but I haven't given it much thought. |
Surely tests can be aligned, but I had to lest the issue for other duties, for a while. |
0d4b06f
to
18ca2ed
Compare
The main problem still remains. Snapshots for cli tests now contains Some explicit occurences of |
18ca2ed
to
59e6c28
Compare
Thanks for tackling this, @olorin37. While it sounded like a quick and efficient solution initially, given the tests and the small annoyances coming from having this additional import indirection, I wonder if we shouldn't take a different path. Here is the crux: when importing a file, the import resolver (the cache) parse the file according to its extension. So it selects a format based on the file name. While it's a bit fragile, it's currently still very useful and does the job. However, when loading a file without an import, the cache always parses it as Nickel. I think it doesn't make a lot of sense: if we automatically use the file extension to drive how imported files are parsed, we should probably do the same for the main file as well. I believe it mostly amounts to get rid of all the In a second step, maybe we can add a The last step is to use this new Line 905 in 3b01e62
Overall this change doesn't require any new logic, but just re-organizing the |
Surly I'll try to grasp it, but I am not sure if I'll manage, cause of time:) If not I'll inform you... but first I'll try to do it. |
Great! If you think that would help at some point, we can even schedule a little pair programming session, as it seems we're in the same timezone. Let me know (e.g. on Discord)! |
After the re-organization I got exactly the same problems:
It seems, first layer of imports should be somehow resolved. |
@olorin37 I think you're missing one step, but you're not far. Sorry if that wasn't clear, but my suggestion of going the "get rid of xxx_multi" road is a different direction that your initial take. The idea would thus be to restore the
This should let the cache select the right format automatically now, even for a single program. I think in the long term, we might want to also do your initial simplification - the two aren't mutually exclusive - but we then need to fix the pretty printer, which is making your tests fail. Some tests are checking that |
Right, I missed that you proposal is an alternative to mine. And, yes I actually do what you proposed without understanding how it would help those snapshot tests (with pretty print). So, I'll follow your idea and tips. "Less is more" removing this one unnecessary case from my initial proposition should be done some day I think, unless it does not complicates things even more 🤔 |
1018c7b
to
0726888
Compare
@yannham Thanks for guidance, now it is working. Please, make an review, anything to improve (with this "fast-path" approach)? |
80f7916
to
4298d8f
Compare
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.
The parse_auto
part isn't mandatory, and we can do that in a subsequent PR. However I think we should fix the import issue in ncl_bench_group
before proceeding with this PR.
@@ -194,7 +194,7 @@ macro_rules! ncl_bench_group { | |||
.unwrap() | |||
.transformed_term; | |||
if bench.eval_mode == $crate::bench::EvalMode::TypeCheck { | |||
cache.parse(id).unwrap(); | |||
cache.parse(id, InputFormat::Nickel).unwrap(); |
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 think you should either:
- Use a fully qualified name for
InputFormat
, that isnickel_lang_core::cache::InputFormat
- Import it a few line above, inside the macro, and keep it as
InputFormat
But in any case, the consumers/callers of ncl_bench_group
should (Edit: + NOT) have to import it themselves (as you had to do in various bench files). This leads to code duplication, but more importantly, callers of nlc_bench_group
have to magically guess that they need to do this import (or wait for a compilation error), while the macro should - and can - be self-contained.
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.
Edit: I meant should NOT have to import it themselves.
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, right now I see. I missed that the code I edited was inside a macro, sure it's a mistake. So, I'll import it in macro, and get rid of those imports from benches:)
core/benches/arrays.rs
Outdated
@@ -1,6 +1,7 @@ | |||
use std::rc::Rc; | |||
|
|||
use criterion::{criterion_main, Criterion}; | |||
use nickel_lang_core::cache::InputFormat; |
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.
(See comment in ncl_bench_group
, but example of import that we shouldn't have to do)
@@ -312,7 +312,7 @@ impl<EC: EvalCache> Program<EC> { | |||
pub fn parse(&mut self) -> Result<RichTerm, Error> { | |||
self.vm | |||
.import_resolver_mut() | |||
.parse(self.main_id) | |||
.parse(self.main_id, InputFormat::Nickel) |
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 wonder if those shouldn't guess the format as well, instead of InputFormat::Nickel
. That's why it could be handy to have a parse_auto
(the name isn't great, so feel free to use another if you find some!). However, this one can also be done in a subsequent PR, as the current code at least fixes the original issue.
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.
parse_infer_format
? less concise, but more descriptive ...
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.
@olorin37 right, it's a reasonable suggestion and better than parse_auto
, so go for it 🙂
self.vm.import_resolver_mut().parse(self.main_id)?; | ||
self.vm | ||
.import_resolver_mut() | ||
.parse(self.main_id, InputFormat::Nickel)?; |
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.
Same, I think any parse
from within Program
methods should probably try to guess the format, to have the same behavior as prepare
.
4298d8f
to
01e63c2
Compare
Guess input format based on extension similarly like in multiple input case.
01e63c2
to
c6c6f18
Compare
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.
Looks great, thank you! We've settled (in chat conversations) on implementing this new parse_guess_format
or whatever in a follow-up PR, and not in this one, to get the ball rolling.
Addresses #1901. Proposition.
It could be so simple, but it seems that cli tests rely on specific behaviour for single file input. I'll think about it later, cause it requires grasping the way tests are made... What do you think? Is it good direction?