Skip to content
Snippets Groups Projects

Perf: Implement a new algorithm for pattern matching compilation to reduce code size

Merged Melwyn Saldanha requested to merge melwyn95@compile_pattern_matching_to_decision_tree into dev
4 files
+ 117
87
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -19,7 +19,6 @@ let rec compile_expression : I.expression -> O.expression =
in
match exp.expression_content with
| E_matching { matchee; cases } ->
let () = Decision_tree.test matchee.type_expression cases in
let matchee = self matchee in
compile_matching ~loc:exp.location ~mut:false matchee cases
| E_let_in
@@ -116,6 +115,14 @@ and compile_matching
pattern, matchee_type, body)
in
let var = Value_var.fresh ~loc ~name:"match_" () in
let () =
let cases =
List.map cases ~f:(fun { pattern; body } ->
let body = compile_expression body in
I.Match_expr.{ pattern; body })
in
Decision_tree.test matchee.type_expression cases
in
let match_expr = Pattern_matching.compile_matching var eqs in
let match_expr = if mut then destruct_mut_let_in match_expr else match_expr in
O.e_a_let_in
Loading