From 9a59cb8cdcf8ddd14f94c982bd0d1089b53d079f Mon Sep 17 00:00:00 2001 From: Zack Slayton Date: Wed, 11 Dec 2024 16:11:05 -0500 Subject: [PATCH] Restacked the symbol table --- src/constants.rs | 218 +++++++++---------- src/lazy/binary/raw/v1_1/immutable_buffer.rs | 2 +- src/lazy/binary/raw/v1_1/reader.rs | 4 +- src/lazy/encoder/writer.rs | 12 +- 4 files changed, 116 insertions(+), 120 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index 7b1583c98..99ead56c4 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -69,55 +69,53 @@ pub(crate) mod v1_1 { "macro_table", // $14 "symbol_table", // $15 "module", // $16 - "", // $17 (see: ion-docs#345) - "export", // $18 - "", // $19 (see: ion-docs#345) - "import", // $20 - "", // $21 (empty text) - "literal", // $22 - "if_none", // $23 - "if_some", // $24 - "if_single", // $25 - "if_multi", // $26 - "for", // $27 - "default", // $28 - "values", // $29 - "annotate", // $30 - "make_string", // $31 - "make_symbol", // $32 - "make_blob", // $33 - "make_decimal", // $34 - "make_timestamp", // $35 - "make_list", // $36 - "make_sexp", // $37 - "make_struct", // $38 - "parse_ion", // $39 - "repeat", // $40 - "delta", // $41 - "flatten", // $42 - "sum", // $43 - "set_symbols", // $44 - "add_symbols", // $45 - "set_macros", // $46 - "add_macros", // $47 - "use", // $48 - "meta", // $49 - "flex_symbol", // $50 - "flex_int", // $51 - "flex_uint", // $52 - "uint8", // $53 - "uint16", // $54 - "uint32", // $55 - "uint64", // $56 - "int8", // $57 - "int16", // $58 - "int32", // $59 - "int64", // $60 - "float16", // $61 - "float32", // $62 - "float64", // $63 - "none", // $64 - "make_field", // $65 + "export", // $17 + "import", // $18 + "flex_symbol", // $19 + "flex_int", // $20 + "flex_uint", // $21 + "uint8", // $22 + "uint16", // $23 + "uint32", // $24 + "uint64", // $25 + "int8", // $26 + "int16", // $27 + "int32", // $28 + "int64", // $29 + "float16", // $30 + "float32", // $31 + "float64", // $32 + "", // $33 (empty text) + "for", // $34 + "literal", // $35 + "if_none", // $36 + "if_some", // $37 + "if_single", // $38 + "if_multi", // $39 + "none", // $40 + "values", // $41 + "default", // $42 + "meta", // $43 + "repeat", // $44 + "flatten", // $45 + "delta", // $46 + "sum", // $47 + "annotate", // $48 + "make_string", // $49 + "make_symbol", // $50 + "make_decimal", // $51 + "make_timestamp", // $52 + "make_blob", // $53 + "make_list", // $54 + "make_sexp", // $55 + "make_field", // $56 + "make_struct", // $57 + "parse_ion", // $58 + "set_symbols", // $59 + "add_symbols", // $60 + "set_macros", // $61 + "add_macros", // $62 + "use", // $63 ]; pub mod system_symbols { @@ -127,80 +125,78 @@ pub(crate) mod v1_1 { pub const ENCODING: SystemSymbol_1_1 = SystemSymbol_1_1::new_unchecked(10); pub const SYMBOL_TABLE: SystemSymbol_1_1 = SystemSymbol_1_1::new_unchecked(15); pub const MODULE: SystemSymbol_1_1 = SystemSymbol_1_1::new_unchecked(16); - pub const EMPTY_TEXT: SystemSymbol_1_1 = SystemSymbol_1_1::new_unchecked(21); - pub const ADD_SYMBOLS: SystemSymbol_1_1 = SystemSymbol_1_1::new_unchecked(45); - pub const ADD_MACROS: SystemSymbol_1_1 = SystemSymbol_1_1::new_unchecked(47); + pub const EMPTY_TEXT: SystemSymbol_1_1 = SystemSymbol_1_1::new_unchecked(33); + pub const ADD_SYMBOLS: SystemSymbol_1_1 = SystemSymbol_1_1::new_unchecked(60); + pub const ADD_MACROS: SystemSymbol_1_1 = SystemSymbol_1_1::new_unchecked(62); } /// A static, read-only map of text to Ion v1.1 system symbol addresses. /// Because the set of string keys is known at compile time, this map is able to use a /// perfect hashing function (PHF) to optimize lookup operations for those keys. pub(crate) static SYSTEM_SYMBOL_TEXT_TO_ID: phf::Map<&str, usize> = phf_map! { - "$ion" => 1, - "$ion_1_0" => 2, - "$ion_symbol_table" => 3, - "name" => 4, - "version" => 5, - "imports" => 6, - "symbols" => 7, - "max_id" => 8, - "$ion_shared_symbol_table" => 9, - "$ion_encoding" => 10, + "$ion" => 1, + "$ion_1_0" => 2, + "$ion_symbol_table" => 3, + "name" => 4, + "version" => 5, + "imports" => 6, + "symbols" => 7, + "max_id" => 8, + "$ion_shared_symbol_table" => 9, + "encoding" => 10, "$ion_literal" => 11, "$ion_shared_module" => 12, "macro" => 13, "macro_table" => 14, "symbol_table" => 15, "module" => 16, - // ion-docs#345 => 17, - "export" => 18, - // ion-docs#345 => 19, - "import" => 20, - "" => 21, - "literal" => 22, - "if_none" => 23, - "if_some" => 24, - "if_single" => 25, - "if_multi" => 26, - "for" => 27, - "default" => 28, - "values" => 29, - "annotate" => 30, - "make_string" => 31, - "make_symbol" => 32, - "make_blob" => 33, - "make_decimal" => 34, - "make_timestamp" => 35, - "make_list" => 36, - "make_sexp" => 37, - "make_struct" => 38, - "parse_ion" => 39, - "repeat" => 40, - "delta" => 41, - "flatten" => 42, - "sum" => 43, - "set_symbols" => 44, - "add_symbols" => 45, - "set_macros" => 46, - "add_macros" => 47, - "use" => 48, - "meta" => 49, - "flex_symbol" => 50, - "flex_int" => 51, - "flex_uint" => 52, - "uint8" => 53, - "uint16" => 54, - "uint32" => 55, - "uint64" => 56, - "int8" => 57, - "int16" => 58, - "int32" => 59, - "int64" => 60, - "float16" => 61, - "float32" => 62, - "float64" => 63, - "none" => 64, - "make_field" => 65, + "export" => 17, + "import" => 18, + "flex_symbol" => 19, + "flex_int" => 20, + "flex_uint" => 21, + "uint8" => 22, + "uint16" => 23, + "uint32" => 24, + "uint64" => 25, + "int8" => 26, + "int16" => 27, + "int32" => 28, + "int64" => 29, + "float16" => 30, + "float32" => 31, + "float64" => 32, + "" => 33, + "for" => 34, + "literal" => 35, + "if_none" => 36, + "if_some" => 37, + "if_single" => 38, + "if_multi" => 39, + "none" => 40, + "values" => 41, + "default" => 42, + "meta" => 43, + "repeat" => 44, + "flatten" => 45, + "delta" => 46, + "sum" => 47, + "annotate" => 48, + "make_string" => 49, + "make_symbol" => 50, + "make_decimal" => 51, + "make_timestamp" => 52, + "make_blob" => 53, + "make_list" => 54, + "make_sexp" => 55, + "make_field" => 56, + "make_struct" => 57, + "parse_ion" => 58, + "set_symbols" => 59, + "add_symbols" => 60, + "set_macros" => 61, + "add_macros" => 62, + "use" => 63, }; pub fn address_for_text(text: &str) -> Option { diff --git a/src/lazy/binary/raw/v1_1/immutable_buffer.rs b/src/lazy/binary/raw/v1_1/immutable_buffer.rs index d14643fdc..5bdc12919 100644 --- a/src/lazy/binary/raw/v1_1/immutable_buffer.rs +++ b/src/lazy/binary/raw/v1_1/immutable_buffer.rs @@ -1275,7 +1275,7 @@ mod tests { RawSymbolRef::SymbolId(0), RawSymbolRef::Text("encoding"), ])] - #[case::three_flex_syms_with_system_symbols(AnnotationsEncoding::FlexSym, &[0xE9, 0x0D, 0x01, 0x60, 0x01, 0x6A, 0x01, 0xA1], 2, 6, &[ + #[case::three_flex_syms_with_system_symbols(AnnotationsEncoding::FlexSym, &[0xE9, 0x0D, 0x01, 0x60, 0x01, 0x6A, 0x01, 0x98], 2, 6, &[ RawSymbolRef::SymbolId(0), RawSymbolRef::Text("encoding"), RawSymbolRef::Text("make_field"), diff --git a/src/lazy/binary/raw/v1_1/reader.rs b/src/lazy/binary/raw/v1_1/reader.rs index b684a79f5..a69ec37c1 100644 --- a/src/lazy/binary/raw/v1_1/reader.rs +++ b/src/lazy/binary/raw/v1_1/reader.rs @@ -349,8 +349,8 @@ mod tests { // System symbols 0xEE, 0x0A, // encoding 0xEE, 0x0E, // macro_table - 0xEE, 0x15, // empty text - 0xEE, 0x41, // make_field + 0xEE, 0x21, // empty text + 0xEE, 0x38, // make_field ]; let empty_context = EncodingContext::empty(); let context = empty_context.get_ref(); diff --git a/src/lazy/encoder/writer.rs b/src/lazy/encoder/writer.rs index 04b0a3351..6f945135a 100644 --- a/src/lazy/encoder/writer.rs +++ b/src/lazy/encoder/writer.rs @@ -833,7 +833,7 @@ mod tests { (Text("$ion_symbol_table"), &[0xE1, 0x03]), (Text("name"), &[0xE1, 0x04]), (SymbolId(6), &[0xE1, 0x06]), // SIDs are written as-is - (Text("foo"), &[0xE1, 0x42]), // Text is added to the symbol table and encoded as a SID + (Text("foo"), &[0xE1, 0x40]), // Text is added to the symbol table and encoded as a SID ], ) } @@ -916,7 +916,7 @@ mod tests { 0x07, // FlexSym SID $3 0x09, // FlexSym SID $4 0x0D, // FlexSym SID $6 - 0x0A, 0x01, // FlexSym SID $66 + 0x02, 0x01, // FlexSym SID $64 ], ) } @@ -1010,12 +1010,12 @@ mod tests { FieldNameEncoding::WriteAsSymbolIds, &[ // New symbols - (RawSymbolRef::Text("foo"), &[0x85]), // FlexUInt SID $66, - (RawSymbolRef::Text("bar"), &[0x87]), // FlexUInt SID $67, - (RawSymbolRef::Text("baz"), &[0x89]), // FlexUInt SID $68, + (RawSymbolRef::Text("foo"), &[0x81]), // FlexUInt SID $64, + (RawSymbolRef::Text("bar"), &[0x83]), // FlexUInt SID $65, + (RawSymbolRef::Text("baz"), &[0x85]), // FlexUInt SID $66, // Symbols that are already in the symbol table (RawSymbolRef::Text("name"), &[0x09]), // FlexUInt SID $4, - (RawSymbolRef::Text("foo"), &[0x85]), // FlexUInt SID $66, + (RawSymbolRef::Text("foo"), &[0x81]), // FlexUInt SID $64, ], ) }