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 1.1 LST append, binary e-exps in field value position #820

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

zslayton
Copy link
Contributor

@zslayton zslayton commented Aug 22, 2024

Changes:

  • When writing Ion 1.1, Writer now emits an encoding directive instead of a 1.0-style symbol table.
  • The reader now recognizes (symbol_table $ion_encoding ["sym1", "sym2", "sym3"]) syntax as re-exporting the symbols in the current context's table at the head of the new context's table.
  • The raw binary 1.1 reader surfaces e-expressions found in struct field value position.
  • The SymbolTable type now exposes methods for getting its system symbols and its application symbols separately.

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

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 🧭

@@ -1601,7 +1601,7 @@ impl<'data> From<LazyRawFieldExpr<'data, BinaryEncoding_1_1>>
use LazyRawFieldExpr::*;
match binary_field {
NameValue(name, value) => NameValue(name.into(), value.into()),
NameEExp(_, _) => todo!("(name, e-exp) field in binary Ion 1.1"),
NameEExp(name, eexp) => NameEExp(name.into(), eexp.into()),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ Converting a LazyRawFieldExpr<_, v1_1::Binary> to a LazyRawFieldExpr<_, AnyEncoding> for use in the format-agnostic Reader.

Comment on lines -232 to +233
fn peek_value(
fn peek_value_expr(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ Previously the lazy binary struct could only surface fields with a value literal. This method can now return either a ValueLiteral or an EExp.

@@ -279,24 +277,26 @@ impl<'top> RawBinaryStructIterator_1_1<'top> {
return IonResult::incomplete("found field name but no value", after_name.offset());
}

let (value, after_value) = match Self::peek_value(after_name)? {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ All variable renames from here to line 288.

Comment on lines +103 to +106
match E::ion_version() {
IonVersion::v1_0 => self.write_lst_append()?,
IonVersion::v1_1 => self.write_encoding_directive()?,
}
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 Writer now writes either an LST or encoding directive depending on the Ion version of the stream.

let mut symbol_table = directive.sexp_writer()?;
symbol_table
.write_symbol("symbol_table")?
.write_symbol("$ion_encoding")?
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 directive's (symbol_table ...) operation starts with a reference to the $ion_encoding module to re-export its symbols.

@@ -349,6 +349,7 @@ impl<Encoding: Decoder, Input: IonInput> ExpandingReader<Encoding, Input> {
if let Some(new_version) = pending_changes.switch_to_version.take() {
symbol_table.reset_to_version(new_version);
pending_changes.has_changes = false;
pending_changes.is_lst_append = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ Resetting some state in the early-return cases.

Comment on lines +338 to 342
ValueRef::Symbol(symbol) if symbol == "$ion_encoding" => {
let active_symtab = operation.expanded().context.symbol_table();
for symbol in active_symtab.application_symbols() {
symbol_table.add_symbol(symbol.clone());
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ If the reader encounters a $ion_encoding in the (macro_table ...), it copies its application symbols over to the table we're constructing. While symbol.clone() is just bumping a reference count, there's room for optimization here.

}
}
ValueRef::Symbol(symbol) => {
todo!("modules other than $ion_encoding (found symbol '{symbol:?}')")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ Symbols other than $ion_encoding (which would represent other modules with symbols to re-export) are not yet supported.

Comment on lines +27 to +28
// TODO: Update this when the implementation is complete
const NUM_SYSTEM_SYMBOLS_1_1: usize = 10;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ For now, the Ion 1.1 reader and writer use the Ion 1.0 symbol table. We'll set this to 0 once we have the system symbol encoding documented.

@zslayton zslayton marked this pull request as ready for review August 22, 2024 15:50
@zslayton zslayton merged commit 81b5e0e into main Aug 22, 2024
29 of 32 checks passed
@zslayton zslayton deleted the field-value-macros branch August 22, 2024 18:51
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