Skip to content

Commit

Permalink
Restacked the symbol table
Browse files Browse the repository at this point in the history
  • Loading branch information
zslayton committed Dec 11, 2024
1 parent d0df476 commit 9a59cb8
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 120 deletions.
218 changes: 107 additions & 111 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,55 +69,53 @@ pub(crate) mod v1_1 {
"macro_table", // $14
"symbol_table", // $15
"module", // $16
"<REMOVE>", // $17 (see: ion-docs#345)
"export", // $18
"<REMOVE>", // $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 {
Expand All @@ -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<usize> {
Expand Down
2 changes: 1 addition & 1 deletion src/lazy/binary/raw/v1_1/immutable_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
4 changes: 2 additions & 2 deletions src/lazy/binary/raw/v1_1/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions src/lazy/encoder/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
],
)
}
Expand Down Expand Up @@ -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
],
)
}
Expand Down Expand Up @@ -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,
],
)
}
Expand Down

0 comments on commit 9a59cb8

Please sign in to comment.