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

Support for unqualified macro addresses in TDL #883

Merged
merged 2 commits into from
Dec 16, 2024

Conversation

zslayton
Copy link
Contributor

This PR:

  • Allows macro definitions to refer to previously defined macros by their address within the current scope.
  • Adds a completeness test that was missing for length-prefixed e-expressions.
  • Fixes many calls to IonResult::incomplete which provided redundant label text.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link

codecov bot commented Dec 16, 2024

Codecov Report

Attention: Patch coverage is 57.89474% with 24 lines in your changes missing coverage. Please review.

Project coverage is 77.85%. Comparing base (6654ed5) to head (8925aa2).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/lazy/binary/raw/v1_1/immutable_buffer.rs 20.00% 15 Missing and 1 partial ⚠️
src/lazy/expanded/compiler.rs 78.37% 4 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #883      +/-   ##
==========================================
+ Coverage   77.79%   77.85%   +0.06%     
==========================================
  Files         136      136              
  Lines       34677    34670       -7     
  Branches    34677    34670       -7     
==========================================
+ Hits        26978    26994      +16     
+ Misses       5699     5680      -19     
+ Partials     2000     1996       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor Author

@zslayton zslayton left a comment

Choose a reason for hiding this comment

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

🗺️ PR Tour 🧭

@@ -244,7 +244,7 @@ impl<'a> BinaryBuffer<'a> {
};

if self.len() < size_in_bytes {
return IonResult::incomplete("reading a flex_uint value", self.offset());
return IonResult::incomplete("a flex_uint value", self.offset());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🪧 The error text produced by incomplete is:

"ran out of input while reading {label} at offset {position}"

I went through and removed all of the redundant "reading a" and "parsing a" bits from the various callsites.

@@ -51,7 +51,7 @@ pub struct BinaryBuffer<'a> {

impl Debug for BinaryBuffer<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "BinaryBuffer {{")?;
write!(f, "BinaryBuffer @ offset={} {{", self.offset)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🪧 Having the byte offset makes it much easier to debug things with inspect and/or a hex dump.

Comment on lines +1010 to +1012
if self.len() < total_length {
return IonResult::incomplete("a length-prefixed e-expression", self.offset);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🪧 This error happened to be surfaced by the test data I was using, so I went ahead and patched it while I was in here.

@@ -1098,30 +1098,12 @@ impl TemplateCompiler {
Ok(())
}

fn resolve_maybe_macro_id_expr<D: Decoder>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🪧 Turns out this was unused.

Comment on lines 1103 to +1106
fn resolve_macro_id_expr<D: Decoder>(
tdl_context: TdlContext<'_>,
id_expr: LazyValue<'_, D>,
) -> IonResult<Arc<Macro>> {
) -> IonResult<Option<Arc<Macro>>> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🪧 This now returns Ok(None) if reading the expression works but no macro is found with the resulting ID. This allows it to be used in places where not finding a macro ID is a legal possibility.

Self::expect_special_form(tdl_context, operation, expressions)
}

fn expect_special_form(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🪧 I extracted this into a helper method so the logic for special forms was more encapsulated.

@zslayton zslayton marked this pull request as ready for review December 16, 2024 19:45
@zslayton zslayton requested a review from jobarr-amzn December 16, 2024 19:45
@jobarr-amzn jobarr-amzn merged commit 4e0d272 into main Dec 16, 2024
34 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants