Skip to content
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

Put Ion 1.1 support behind a feature flag #842

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
# H/T: https://github.com/Dart-Code/Dart-Code/commit/612732d5879730608baa9622bf7f5e5b7b51ae65
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'amazon-ion/ion-rust'
strategy:
fail-fast: false
matrix:
# use the available runner types that were determined by the setup step
os: ${{ fromJSON(needs.setup.outputs.available-runners) }}
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ experimental = [
"experimental-reader-writer",
"experimental-tooling-apis",
"experimental-serde",
"experimental-ion-1-1",
]

# Feature for indicating explicit opt-in to Ion 1.1
experimental-ion-1-1 = [ "experimental-reader-writer" ]

# Access to the streaming Reader and Writer types.
# These APIs are functional and well-tested, but are not yet stable.
experimental-reader-writer = []
Expand Down
2 changes: 1 addition & 1 deletion ion-tests
10 changes: 10 additions & 0 deletions src/lazy/any_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,11 @@ mod tests {

expect_int(context_ref, &mut reader, IonEncoding::Text_1_0, 2)?;

if cfg!(not(feature = "experimental-ion-1-1")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL about the cfg macro.

reader.next(context_ref).expect_err("Ion 1.1 IVM should return an error.");
return Ok(())
}

// This IVM changes the encoding from 1.0 text to 1.1 text
expect_version_change(
context_ref,
Expand Down Expand Up @@ -1922,6 +1927,11 @@ mod tests {

expect_int(context_ref, &mut reader, IonEncoding::Binary_1_0, 2)?;

if cfg!(not(feature = "experimental-ion-1-1")) {
reader.next(context_ref).expect_err("Ion 1.1 IVM should return an error.");
return Ok(())
}

// This IVM changes the encoding from 1.0 binary to 1.1 binary
expect_version_change(
context_ref,
Expand Down
1 change: 1 addition & 0 deletions src/lazy/binary/raw/v1_1/immutable_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,7 @@ pub struct EncodedAnnotations {
pub sequence_length: u16,
}

#[cfg(feature = "experimental-ion-1-1")]
#[cfg(test)]
mod tests {
use rstest::rstest;
Expand Down
1 change: 1 addition & 0 deletions src/lazy/binary/raw/v1_1/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ impl<'top> Iterator for RawBinaryStructIterator_1_1<'top> {
}
}

#[cfg(feature = "experimental-ion-1-1")]
#[cfg(test)]
mod tests {
use crate::{
Expand Down
1 change: 1 addition & 0 deletions src/lazy/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ pub trait RawVersionMarker<'top>: Debug + Copy + Clone + HasSpan<'top> {
fn stream_version_after_marker(&self) -> IonResult<IonVersion> {
match self.major_minor() {
(1, 0) => Ok(IonVersion::v1_0),
#[cfg(feature = "experimental-ion-1-1")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL you could apply #[cfg(...)] annotations to a match arm.

(1, 1) => Ok(IonVersion::v1_1),
(major, minor) => {
IonResult::decoding_error(format!("Ion version {major}.{minor} is not supported"))
Expand Down
1 change: 1 addition & 0 deletions src/lazy/encoder/binary/v1_1/value_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ impl<'value, 'top> BinaryAnnotatedValueWriter_1_1<'value, 'top> {
}

#[cfg(test)]
#[cfg(feature = "experimental-ion-1-1")]
mod tests {
use num_traits::FloatConst;
use rstest::rstest;
Expand Down
1 change: 1 addition & 0 deletions src/lazy/encoder/text/v1_1/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impl<W: Write> LazyRawWriter<W> for LazyRawTextWriter_1_1<W> {
}
}

#[cfg(feature = "experimental-ion-1-1")]
#[cfg(test)]
mod tests {
use crate::lazy::any_encoding::IonVersion;
Expand Down
1 change: 1 addition & 0 deletions src/lazy/encoder/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ impl<S: SequenceWriter> ElementWriter for S {
}
}

#[cfg(feature = "experimental-ion-1-1")]
#[cfg(test)]
mod tests {
use crate::lazy::encoder::value_writer::AnnotatableWriter;
Expand Down
1 change: 1 addition & 0 deletions src/lazy/expanded/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@
};
use crate::lazy::expanded::{EncodingContext, EncodingContextRef};
use crate::{
AnyEncoding, Element, ElementReader, Int, IntoAnnotations, IonResult, Macro, Reader, Symbol,

Check warning on line 1313 in src/lazy/expanded/compiler.rs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, default)

unused imports: `AnyEncoding`, `ElementReader`, `Element`, and `Reader`

Check warning on line 1313 in src/lazy/expanded/compiler.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, default)

unused imports: `AnyEncoding`, `ElementReader`, `Element`, and `Reader`

Check warning on line 1313 in src/lazy/expanded/compiler.rs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, experimental-ion-hash)

unused imports: `AnyEncoding`, `ElementReader`, `Element`, and `Reader`

Check warning on line 1313 in src/lazy/expanded/compiler.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, experimental-ion-hash)

unused imports: `AnyEncoding`, `ElementReader`, `Element`, and `Reader`

Check warning on line 1313 in src/lazy/expanded/compiler.rs

View workflow job for this annotation

GitHub Actions / Build and Test (al2-x86, default)

unused imports: `AnyEncoding`, `ElementReader`, `Element`, and `Reader`

Check warning on line 1313 in src/lazy/expanded/compiler.rs

View workflow job for this annotation

GitHub Actions / Build and Test (al2-arm, default)

unused imports: `AnyEncoding`, `ElementReader`, `Element`, and `Reader`

Check warning on line 1313 in src/lazy/expanded/compiler.rs

View workflow job for this annotation

GitHub Actions / Build and Test (al2-x86, experimental-ion-hash)

unused imports: `AnyEncoding`, `ElementReader`, `Element`, and `Reader`

Check warning on line 1313 in src/lazy/expanded/compiler.rs

View workflow job for this annotation

GitHub Actions / Build and Test (al2-arm, experimental-ion-hash)

unused imports: `AnyEncoding`, `ElementReader`, `Element`, and `Reader`

Check warning on line 1313 in src/lazy/expanded/compiler.rs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, experimental-ion-hash)

unused imports: `AnyEncoding`, `ElementReader`, `Element`, and `Reader`

Check warning on line 1313 in src/lazy/expanded/compiler.rs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, default)

unused imports: `AnyEncoding`, `ElementReader`, `Element`, and `Reader`
};

// XXX: The tests in this module compile inputs and expect a specific output. There is no "correct"
Expand Down Expand Up @@ -1569,6 +1569,7 @@
Ok(())
}

#[cfg(feature = "experimental-ion-1-1")]
#[test]
fn dependent_macros() -> IonResult<()> {
let ion = r#"
Expand Down
3 changes: 3 additions & 0 deletions src/lazy/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ mod tests {
test_fn(reader)
}

#[cfg(feature = "experimental-ion-1-1")]
#[test]
fn expand_binary_template_macro() -> IonResult<()> {
let macro_source = "(macro seventeen () 17)";
Expand All @@ -321,6 +322,7 @@ mod tests {
})
}

#[cfg(feature = "experimental-ion-1-1")]
#[test]
fn expand_binary_template_macro_with_one_arg() -> IonResult<()> {
let macro_source = r#"
Expand Down Expand Up @@ -349,6 +351,7 @@ mod tests {
})
}

#[cfg(feature = "experimental-ion-1-1")]
#[test]
fn expand_binary_template_macro_with_multiple_outputs() -> IonResult<()> {
let macro_source = r#"
Expand Down
3 changes: 3 additions & 0 deletions src/lazy/system_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@

// === Shared Symbol Tables ===

use crate::lazy::encoder::binary::v1_1::writer::LazyRawBinaryWriter_1_1;

Check warning on line 748 in src/lazy/system_reader.rs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, default)

unused import: `crate::lazy::encoder::binary::v1_1::writer::LazyRawBinaryWriter_1_1`

Check warning on line 748 in src/lazy/system_reader.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, default)

unused import: `crate::lazy::encoder::binary::v1_1::writer::LazyRawBinaryWriter_1_1`

Check warning on line 748 in src/lazy/system_reader.rs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, experimental-ion-hash)

unused import: `crate::lazy::encoder::binary::v1_1::writer::LazyRawBinaryWriter_1_1`

Check warning on line 748 in src/lazy/system_reader.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, experimental-ion-hash)

unused import: `crate::lazy::encoder::binary::v1_1::writer::LazyRawBinaryWriter_1_1`

Check warning on line 748 in src/lazy/system_reader.rs

View workflow job for this annotation

GitHub Actions / Build and Test (al2-x86, default)

unused import: `crate::lazy::encoder::binary::v1_1::writer::LazyRawBinaryWriter_1_1`

Check warning on line 748 in src/lazy/system_reader.rs

View workflow job for this annotation

GitHub Actions / Build and Test (al2-arm, default)

unused import: `crate::lazy::encoder::binary::v1_1::writer::LazyRawBinaryWriter_1_1`

Check warning on line 748 in src/lazy/system_reader.rs

View workflow job for this annotation

GitHub Actions / Build and Test (al2-x86, experimental-ion-hash)

unused import: `crate::lazy::encoder::binary::v1_1::writer::LazyRawBinaryWriter_1_1`

Check warning on line 748 in src/lazy/system_reader.rs

View workflow job for this annotation

GitHub Actions / Build and Test (al2-arm, experimental-ion-hash)

unused import: `crate::lazy::encoder::binary::v1_1::writer::LazyRawBinaryWriter_1_1`

Check warning on line 748 in src/lazy/system_reader.rs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, experimental-ion-hash)

unused import: `crate::lazy::encoder::binary::v1_1::writer::LazyRawBinaryWriter_1_1`

Check warning on line 748 in src/lazy/system_reader.rs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, default)

unused import: `crate::lazy::encoder::binary::v1_1::writer::LazyRawBinaryWriter_1_1`
use crate::lazy::encoder::value_writer::AnnotatableWriter;
use crate::{MapCatalog, SharedSymbolTable};

Expand Down Expand Up @@ -1003,6 +1003,7 @@
Ok(())
}

#[cfg(feature = "experimental-ion-1-1")]
#[test]
fn detect_encoding_directive_text() -> IonResult<()> {
let text = r#"
Expand All @@ -1016,6 +1017,7 @@
Ok(())
}

#[cfg(feature = "experimental-ion-1-1")]
#[test]
fn detect_encoding_directive_binary() -> IonResult<()> {
let mut writer = LazyRawBinaryWriter_1_1::new(Vec::new())?;
Expand Down Expand Up @@ -1073,6 +1075,7 @@
Ok(())
}

#[cfg(feature = "experimental-ion-1-1")]
#[test]
fn read_encoding_directive_new_active_module() -> IonResult<()> {
let ion = r#"
Expand Down
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ pub mod v1_0 {
pub use crate::lazy::encoding::{BinaryEncoding_1_0 as Binary, TextEncoding_1_0 as Text};
}

#[cfg(feature = "experimental-ion-1-1")]
pub mod v1_1 {
#[cfg(feature = "experimental-tooling-apis")]
v1_1_tooling_apis!(pub);
Expand All @@ -393,6 +394,21 @@ pub mod v1_1 {
v1_1_reader_writer!(pub(crate));
}

#[cfg(not(feature = "experimental-ion-1-1"))]
pub(crate) mod v1_1 {
#[cfg(feature = "experimental-tooling-apis")]
v1_1_tooling_apis!(pub);

#[cfg(not(feature = "experimental-tooling-apis"))]
v1_1_tooling_apis!(pub(crate));

#[cfg(feature = "experimental-reader-writer")]
v1_1_reader_writer!(pub);

#[cfg(not(feature = "experimental-reader-writer"))]
v1_1_reader_writer!(pub(crate));
}

/// Whether or not the text spacing is generous/human-friendly or something more compact.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Default)]
#[non_exhaustive]
Expand Down
1 change: 1 addition & 0 deletions tests/conformance.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(feature = "experimental-ion-1-1")]

#[cfg(feature = "experimental-reader-writer")]
mod conformance_dsl;
Expand Down
1 change: 1 addition & 0 deletions tests/conformance_dsl/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(feature = "experimental-ion-1-1")]
#![allow(dead_code)]

mod context;
Expand Down
1 change: 1 addition & 0 deletions tests/conformance_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(feature = "experimental-ion-1-1")]
#![cfg(feature = "experimental-reader-writer")]
mod conformance_dsl;
use conformance_dsl::prelude::*;
Expand Down
1 change: 1 addition & 0 deletions tests/detect_incomplete_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
static SKIP_LIST_1_0: LazyLock<HashSet<String>> =
LazyLock::new(|| CANONICAL_FILE_NAMES.iter().cloned().collect());

static SKIP_LIST_1_1: LazyLock<HashSet<String>> = LazyLock::new(|| {

Check warning on line 33 in tests/detect_incomplete_text.rs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, experimental-ion-hash)

static `SKIP_LIST_1_1` is never used

Check warning on line 33 in tests/detect_incomplete_text.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, experimental-ion-hash)

static `SKIP_LIST_1_1` is never used

Check warning on line 33 in tests/detect_incomplete_text.rs

View workflow job for this annotation

GitHub Actions / Build and Test (al2-x86, experimental-ion-hash)

static `SKIP_LIST_1_1` is never used

Check warning on line 33 in tests/detect_incomplete_text.rs

View workflow job for this annotation

GitHub Actions / Build and Test (al2-arm, experimental-ion-hash)

static `SKIP_LIST_1_1` is never used

Check warning on line 33 in tests/detect_incomplete_text.rs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, experimental-ion-hash)

static `SKIP_LIST_1_1` is never used
CANONICAL_FILE_NAMES
.iter()
.map(|file_1_0| file_1_0.replace("iontestdata", "iontestdata_1_1"))
Expand All @@ -42,6 +42,7 @@
incomplete_text_detection_test(&SKIP_LIST_1_0, file_name).unwrap()
}

#[cfg(feature = "experimental-ion-1-1")]
#[test_resources("ion-tests/iontestdata_1_1/good/**/*.ion")]
fn detect_incomplete_input_1_1(file_name: &str) {
incomplete_text_detection_test(&SKIP_LIST_1_1, file_name).unwrap()
Expand Down
1 change: 1 addition & 0 deletions tests/ion_tests_1_1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(feature = "experimental-ion-1-1")]
#![cfg(feature = "experimental-reader-writer")]
/// TODO: When the Ion 1.1 binary reader is complete, update this module to include binary tests
mod ion_tests;
Expand Down
Loading