From 028ae53b949d70ddf175328d52ca250cf904d43c Mon Sep 17 00:00:00 2001 From: CAIMEO Date: Fri, 9 Oct 2026 14:31:26 +0800 Subject: [PATCH] perf: use ReadOnlyArray --- codegen/gen_mbt_table/gen_mbt_table.mbt | 8 +++++--- tests/compressed_table_test/parser.mbt | 10 +++++----- tests/nonassoc_test/table_array/parser.mbt | 6 +++--- tests/ocaml_jsoncst_test/ocaml.mbt | 10 +++++----- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/codegen/gen_mbt_table/gen_mbt_table.mbt b/codegen/gen_mbt_table/gen_mbt_table.mbt index fbf5e96..29f72af 100644 --- a/codegen/gen_mbt_table/gen_mbt_table.mbt +++ b/codegen/gen_mbt_table/gen_mbt_table.mbt @@ -70,7 +70,7 @@ fn codegen_tokens( ///| fn decompressor() -> @mbt_ast.Item { let int = @mbt_common.named_type("Int", []) - let array = @mbt_common.named_type("FixedArray", [int]) + let array = @mbt_common.named_type("ReadOnlyArray", [int]) let repeated : @mbt_ast.Block = { statements: [ Let( @@ -113,7 +113,7 @@ fn decompressor() -> @mbt_ast.Item { ), ], result: Some( - @mbt_common.call("FixedArray::from_array", [Ident("output")]), + @mbt_common.call("ReadOnlyArray::from_array", [Ident("output")]), ), }, result=array, @@ -248,7 +248,7 @@ fn codegen( } } - let int_array = @mbt_common.named_type("FixedArray", [ + let int_array = @mbt_common.named_type("ReadOnlyArray", [ @mbt_common.named_type("Int", []), ]) items.push( @@ -280,6 +280,8 @@ fn codegen( Global( "yy_prod_act_table", Some( + // New native lowering in v0.10.14+00f066f21 rejects static arrays of + // direct references to named functions. Keep this as FixedArray. @mbt_common.named_type("FixedArray", [ @mbt_common.named_type("YYAction", []), ]), diff --git a/tests/compressed_table_test/parser.mbt b/tests/compressed_table_test/parser.mbt index 3519aa5..79ec739 100644 --- a/tests/compressed_table_test/parser.mbt +++ b/tests/compressed_table_test/parser.mbt @@ -191,16 +191,16 @@ fn yy_input(token : Token, _start_pos : Int, _end_pos : Int) -> ( } ///| -let yy_prod_lhs_table : FixedArray[Int] = [5, 5] +let yy_prod_lhs_table : ReadOnlyArray[Int] = [5, 5] ///| -let yy_prod_len_table : FixedArray[Int] = [1, 3] +let yy_prod_len_table : ReadOnlyArray[Int] = [1, 3] ///| let yy_prod_act_table : FixedArray[YYAction] = [yy_action_0, yy_action_1] ///| -fn yy_decompress(input : FixedArray[Int]) -> FixedArray[Int] { +fn yy_decompress(input : ReadOnlyArray[Int]) -> ReadOnlyArray[Int] { let output = [] let mut last = 0 for val in input { @@ -214,11 +214,11 @@ fn yy_decompress(input : FixedArray[Int]) -> FixedArray[Int] { last = val } } - FixedArray::from_array(output) + ReadOnlyArray::from_array(output) } ///| -let yy_state_table : FixedArray[Int] = yy_decompress( +let yy_state_table : ReadOnlyArray[Int] = yy_decompress( [ 0, 7, 4, 0, -2, 3, 0, 1, 0, -7, 7, 4, 0, -2, 5, 0, -4, 6, 0, -3, 11, 0, -2, 11, 0, -3, 10, 0, -2, 10, 0, -3 diff --git a/tests/nonassoc_test/table_array/parser.mbt b/tests/nonassoc_test/table_array/parser.mbt index 4a31ac2..daaf6b4 100644 --- a/tests/nonassoc_test/table_array/parser.mbt +++ b/tests/nonassoc_test/table_array/parser.mbt @@ -171,10 +171,10 @@ fn yy_input(token : Token, _start_pos : Int, _end_pos : Int) -> ( } ///| -let yy_prod_lhs_table : FixedArray[Int] = [6, 7, 7, 7, 7] +let yy_prod_lhs_table : ReadOnlyArray[Int] = [6, 7, 7, 7, 7] ///| -let yy_prod_len_table : FixedArray[Int] = [1, 1, 3, 3, 3] +let yy_prod_len_table : ReadOnlyArray[Int] = [1, 1, 3, 3, 3] ///| let yy_prod_act_table : FixedArray[YYAction] = [ @@ -182,7 +182,7 @@ let yy_prod_act_table : FixedArray[YYAction] = [ ] ///| -let yy_state_table : FixedArray[Int] = [ +let yy_state_table : ReadOnlyArray[Int] = [ 0, 11, 0, 0, 4, 0, 3, 12, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 4, 0, 0, 5, 0, 0, 0, 9, 7, 0, 6, 0, 0, 0, 22, 0, 22, 22, 0, 22, 0, 0, 0, 0, 11, 0, 0, 4, 0, 0, 8, 0, 16, 0, 0, 0, 0, 16, 0, 0, 0, 0, 11, 0, 0, 4, 0, 0, 10, 0, 15, diff --git a/tests/ocaml_jsoncst_test/ocaml.mbt b/tests/ocaml_jsoncst_test/ocaml.mbt index b7235fa..800c0ce 100644 --- a/tests/ocaml_jsoncst_test/ocaml.mbt +++ b/tests/ocaml_jsoncst_test/ocaml.mbt @@ -19756,7 +19756,7 @@ fn yy_input(token : Token, _start_pos : Int, _end_pos : Int) -> ( } ///| -let yy_prod_lhs_table : FixedArray[Int] = [ +let yy_prod_lhs_table : ReadOnlyArray[Int] = [ 120, 121, 122, 122, 122, 123, 123, 124, 124, 125, 126, 126, 127, 127, 127, 127, 128, 129, 130, 131, 131, 132, 132, 133, 133, 134, 134, 134, 134, 134, 134, 134, 134, 135, 135, 135, 135, 135, 135, 136, 136, 137, 137, 137, 138, @@ -19810,7 +19810,7 @@ let yy_prod_lhs_table : FixedArray[Int] = [ ] ///| -let yy_prod_len_table : FixedArray[Int] = [ +let yy_prod_len_table : ReadOnlyArray[Int] = [ 2, 2, 2, 2, 1, 2, 1, 0, 2, 2, 1, 3, 0, 2, 2, 2, 2, 2, 2, 2, 5, 1, 1, 2, 1, 1, 4, 5, 2, 3, 1, 2, 1, 5, 3, 5, 7, 9, 7, 3, 1, 0, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 4, 2, 4, 2, 5, 1, 2, 6, 5, 1, 4, 5, 3, 3, 5, 3, 1, 2, 0, @@ -19996,7 +19996,7 @@ let yy_prod_act_table : FixedArray[YYAction] = [ ] ///| -fn yy_decompress(input : FixedArray[Int]) -> FixedArray[Int] { +fn yy_decompress(input : ReadOnlyArray[Int]) -> ReadOnlyArray[Int] { let output = [] let mut last = 0 for val in input { @@ -20010,11 +20010,11 @@ fn yy_decompress(input : FixedArray[Int]) -> FixedArray[Int] { last = val } } - FixedArray::from_array(output) + ReadOnlyArray::from_array(output) } ///| -let yy_state_table : FixedArray[Int] = yy_decompress( +let yy_state_table : ReadOnlyArray[Int] = yy_decompress( [ 0, -6, 7, 0, -5, 24, 0, -16, 577, 0, 13, 22, 0, -18, 25, 0, 568, 35, 0, 30, 26, 0, -2, 4, 0, -4, 14, 544, 0, -5, 18, 0, -12, 15, 0, -12, 560, 0, -3, 23,