partiql / partiql-lang-rust

PartiQL libraries and tools in Rust.
https://partiql.org/
Apache License 2.0
65 stars 9 forks source link

`pest2ion` Tool Cannot Generate Pretty/Compact Text for PartiQL Grammar #43

Closed almann closed 1 month ago

almann commented 3 years ago

This is probably an upstream bug with ion-rs/ion-c-sys, but when serializing the PartiQL grammar, we get an unexpected EOF:

Binary:

❯ cargo run --package pest-ion --bin pest2ion -- partiql-parser/src/peg/partiql.pest -b | wc -c
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running `target/debug/pest2ion partiql-parser/src/peg/partiql.pest -b`
14897

Text:

❯ RUST_BACKTRACE=1 cargo run --package pest-ion --bin pest2ion -- partiql-parser/src/peg/partiql.pest -t | wc -c
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running `target/debug/pest2ion partiql-parser/src/peg/partiql.pest -t`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: IonCError { code: 20, message: "IERR_UNEXPECTED_EOF", additional: "iERR Result" }', /home/ANT.AMAZON.COM/almann/.cargo/registry/src/github.com-1ecc6299db9ec823/ion-c-sys-0.4.10/src/writer.rs:612:50
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/core/src/panicking.rs:92:14
   2: core::option::expect_none_failed
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/core/src/option.rs:1329:5
   3: core::result::Result<T,E>::unwrap
             at /home/ANT.AMAZON.COM/almann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:1037:23
   4: <ion_c_sys::writer::IonCWriterHandle as core::ops::drop::Drop>::drop
             at /home/ANT.AMAZON.COM/almann/.cargo/registry/src/github.com-1ecc6299db9ec823/ion-c-sys-0.4.10/src/writer.rs:612:13
   5: core::ptr::drop_in_place<ion_c_sys::writer::IonCWriterHandle>
             at /home/ANT.AMAZON.COM/almann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:187:1
   6: core::ptr::drop_in_place<ion_rs::value::writer::IonCSliceElementWriter>
             at /home/ANT.AMAZON.COM/almann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:187:1
   7: pest2ion::main
             at ./pest-ion/src/bin/pest2ion/main.rs:82:1
   8: core::ops::function::FnOnce::call_once
             at /home/ANT.AMAZON.COM/almann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
0

The problem seems to be around the cleanup of the writer handle (the panic is happening during the cleanup of the Ion C writer.

almann commented 3 years ago

Using the ion-cli:

❯ cargo install ion-cli && cargo run --package pest-ion --bin pest2ion -- partiql-parser/src/peg/partiql.pest -b | ion dump -f pretty | tail
    Updating crates.io index
     Ignored package `ion-cli v0.1.1` is already installed, use --force to override
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running `target/debug/pest2ion partiql-parser/src/peg/partiql.pest -b`
{
  error_type: WRITE,
  message: "/home/ANT.AMAZON.COM/almann/.cargo/registry/src/github.com-1ecc6299db9ec823/ion-cli-0.1.1/ion-c/tools/events/ion_event_stream.cpp:1181 : IERR_NO_MEMORY",
  location: "stdin",
  event_index: 1688
}
                                                                        choice
                                                                        (
                                                                          choice
                                                                          (
                                                                            choice
                                                                            (
                                                                              choice
                                                                              (
                                                                                choice
                                                                                %  

Looks like Ion C's writer is getting hung up on the very deeply nested choice nodes. #37 should alleviate this, but there is still a bug in Ion C here.