-
Notifications
You must be signed in to change notification settings - Fork 9
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
[WIP] Upgrade nom to version 4 #5
Conversation
3dcf6d4
to
4fa8896
Compare
Yeah, the travis sees the same error. It comes from the unwrap located here: https://github.com/akubera/alice-rs/blob/upgrade-dep/nom/root-io/src/core/file.rs#L165 |
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.
Thanks again! I am not sure, yet, what is going wrong here. Maybe you could insert at inspect
before it goes south and dump the raw bytes to stdout or have a look with nom
's dbg_dmp! macro?
I hope to find some time to look into this over the holidays. Would you mind rebasing this PR on master
and force-pushing it so that it includes the changes from #4?
malice/src/dataset_rust.rs
Outdated
@@ -32,7 +32,7 @@ pub struct DatasetIntoIter { | |||
impl DatasetIntoIter { | |||
/// Create a new `DatasetIntoIter` from the given `root_io::Tree`. The `Tree` must be a so-called "ESD" tree. | |||
pub fn new(t: &Tree) -> Result<DatasetIntoIter, Error> { | |||
use nom::*; | |||
use nom::{be_u8, be_u16, be_u32, be_u64, be_i8, be_i32, be_f32}; |
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 really was lazy here and those import should just be at the top of the file.
malice/src/dataset_rust.rs
Outdated
@@ -118,17 +117,17 @@ fn parse_trigger_classes(input: &[u8]) -> nom::IResult<&[u8], Vec<String>> { | |||
/// This function reconstructs a float from the exponent and mantissa | |||
/// TODO: Use ByteOrder crate to be cross-platform! | |||
fn parse_custom_mantissa(input: &[u8], nbits: usize) -> nom::IResult<&[u8], f32> { | |||
use nom::*; // cannot use module path in macro | |||
pair!(input, be_u8, be_u16).map(|(exp, man)| { | |||
use nom::{be_u8, be_u16}; |
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 here. Could you move it to the top of the file?
root-io/src/core/tstreamerinfo.rs
Outdated
|
||
use ::core::*; | ||
|
||
use crate::core::{*, Context}; |
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.
Is there a reason why you do the glob import and the Context explicitly? If reasonably possible, it would be better to avoid the glob imports. Also, is crate
a new extension in 1.31 or is it backwards compatible? Would be nice to keep also support older versions, if its so little additional effort.
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.
Yeah there was an error that Context
was ambiguous, so there must be a new one exported by nom.
"crate"-scope may be a new feature. I was initially confused importing from "core" things that were not in rust's core, so I thought I'd make it a little more explicit.
It looks like this particular case I screwed up, because it was use ::core
and not use core
,
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.
yeah, crate scope is new in 1.30
, invented to resolve ambiguities
root-io/src/tree_reader/branch.rs
Outdated
@@ -3,7 +3,9 @@ use std::path::PathBuf; | |||
use nom::*; | |||
|
|||
use core::parsers::*; | |||
use core::types::*; | |||
// use crate::core::types::*; | |||
use crate::core::types::{Raw, Context}; |
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.
Feel free to remove the old code :)
A `Needed::Size(sz)` now only returns additional data needed, not total required
5dd86c0
to
d22ae0d
Compare
Stepping through debugger is didn't really tell me much, unfortunately the macros hide much of the relevant information from LLDB. Removing the
The nom4 upgrading guide says it's "stricter about the behaviour with partial data" and suggests using the CompleteByteSlice. I'll look into working on that sometime... later. |
I think you are on to something with the end of file. Also looking at the error message, it indeed originates from the // Old:
.map(|i| tstreamerinfo(i &context).unwrap().1)
// With dbg:
.map(|i| dbg_dmp!(i, apply!(tstreamerinfo, &context)).unwrap().1) |
It looks like the nom functions like This fails to compile because it expects a named!(
file_header<CompleteByteSlice, FileHeader>,
do_parse!(
tag!("root") >>
version: be_i32 >>
begin: be_i32 >>
... |
Indeed, looking at the nom issue tracker it seems like that feature is not working as smoothly as it should. For the time being, we could just write a custom named!(
#[doc="Succeeds if the input buffer is empty"],
end_of_buf,
verify!(rest, |s: &[u8]| s.is_empty())
); This On the other hand, this actually might point to a design flaw. I added those Alternatively, If there are places where we depend on the parsers failing for too large slices we could use |
Just bumping this. Are you still looking into this or are you stuck with something? |
Ah, no, sorry. I thought I'd work on this again over the holidays, but I didn't and I haven't looked at any of my Rust stuff since. |
It seems like nom is getting close to a version 5 release which comes with changes to Edit: here is a link to the nom 5 roadmap: rust-bakery/nom#903 |
Ah, well I'm glad it wasn't just me. Sorry I haven't looked at this for months, there's been plenty to work on in AliPhysics/AliFemto. |
No problem at all! This is meant to be for fun and learning primarily :) |
Nom 5 is now released it it looks pretty great: Of particular interest to this PR is that |
Yeah, I saw that and thought about closing this. New version looks good with straightforward functions over macros. Congratulations on your publication, by the way. |
I thought I'd update the root-io dependencies.
nom 4 changes the implementation of IResult enum from
nom::IResult<I, O, E>
tostd::Result<(I, O), E>
, so a few closures and matches had to be changed to accept tuples, and removeIResult::Done
references.It compiles but it doesn't pass the
core::file_item::tests::open_simple
&tests::high_level_io::root_file_methods
tests due to reaching the end of file too early.I don't think I changed any logic, so it must be a new nom behavior upon (I'm guessing) reading the last byte.
Any suggestions?
Also, I updated the versions to reflect an update in the dependencies.
Hope all is well,
Andrew