ocaml: store max stack ref for perf

This commit is contained in:
Alain Zscheile 2024-02-22 16:15:58 +01:00
parent 98b3f087f9
commit 0765546498

View file

@ -5,6 +5,7 @@ open Tys
type stack_ref = int
type sel_ident = loc_span_full * stack_ref
type max_stack_ref = stack_ref
type 'a record = 'a Record.t
type pattern_mt = Pattern.t * ((loc_span_full * expr) option)
@ -20,18 +21,30 @@ and expr =
| ELiteral of Literal.lit
| Use of sel_ident
| RefOf of sel_ident
| Lambda of lambda
| TyLambda of expr * lambda
| Apply of expr * loc_span_full * expr
| RefTy of stack_ref * expr
| Record of expr record
| TyRecord of expr record
| Lambda of max_stack_ref * lambda
| TyLambda of max_stack_ref * expr * lambda (* note that the first element is the layout of the binders *)
| Apply of max_stack_ref * expr * loc_span_full * expr
| RefTy of max_stack_ref * stack_ref * expr
| Record of max_stack_ref * expr record
| TyRecord of max_stack_ref * expr record
(* parser *)
module FieldsReg = Set.Make(String)
module FieldsReg2 = Map.Make(String)
let msr_of_expr = function
| Infer -> 0
| ELiteral _ -> 0
| Use (_, x) -> x + 1
| RefOf (_, x) -> x + 1
| Lambda (x, _) -> x
| TyLambda (x, _, _) -> x
| Apply (x, _, _, _) -> x
| RefTy (x, _, _) -> x
| Record (x, _) -> x
| TyRecord (x, _) -> x
(* a minimal expression are all parts which are "self contained" enough (e.g. not an apply) *)
let rec parse_minexpr ps =
let (k, s, ps) = next_in_noeof ps XExpression in