@@ -532,6 +532,7 @@ type globals =
532532 ; mutable is_const : bool array
533533 ; mutable is_exported : bool array
534534 ; mutable named_value : string option array
535+ ; mutable cache_ids : Var .t list
535536 ; constants : Code .constant array
536537 ; primitives : string array
537538 }
@@ -541,6 +542,7 @@ let make_globals size constants primitives =
541542 ; is_const = Array. make size false
542543 ; is_exported = Array. make size false
543544 ; named_value = Array. make size None
545+ ; cache_ids = []
544546 ; constants
545547 ; primitives
546548 }
@@ -818,8 +820,6 @@ let tagged_blocks = ref Addr.Map.empty
818820
819821let compiled_blocks : (_ * instr list * last) Addr.Map.t ref = ref Addr.Map. empty
820822
821- let method_cache_id = ref 1
822-
823823let clo_offset_3 = 3
824824
825825type compile_info =
@@ -2353,34 +2353,29 @@ and compile infos pc state (instrs : instr list) =
23532353 (Let (x, Prim (Ult , [ Pv z; Pv y ])) :: instrs)
23542354 | GETPUBMET ->
23552355 let n = gets32 code (pc + 1 ) in
2356- let cache = ! method_cache_id in
2357- incr method_cache_id;
23582356 let obj = State. accu state in
23592357 let state = State. push state in
2360- let tag, state = State. fresh_var state in
2358+ let cache_id = Var. fresh_n " cache_id" in
2359+ state.globals.cache_ids < - cache_id :: state.globals.cache_ids;
23612360 let m, state = State. fresh_var state in
2362-
2363- if debug_parser () then Format. printf " %a = %ld@." Var. print tag n;
23642361 if debug_parser ()
23652362 then
23662363 Format. printf
2367- " %a = caml_get_public_method (%a, %a )@."
2364+ " %a = caml_get_cached_method (%a, %ld )@."
23682365 Var. print
23692366 m
23702367 Var. print
23712368 obj
2372- Var. print
2373- tag;
2369+ n;
23742370 compile
23752371 infos
23762372 (pc + 3 )
23772373 state
23782374 (Let
23792375 ( m
23802376 , Prim
2381- ( Extern " caml_get_public_method"
2382- , [ Pv obj; Pv tag; Pc (Int (Targetint. of_int_exn cache)) ] ) )
2383- :: Let (tag, const32 n)
2377+ ( Extern " caml_get_cached_method"
2378+ , [ Pv obj; Pc (Int (Targetint. of_int32_exn n)); Pv cache_id ] ) )
23842379 :: instrs)
23852380 | GETDYNMET ->
23862381 let tag = State. accu state in
@@ -2401,12 +2396,7 @@ and compile infos pc state (instrs : instr list) =
24012396 infos
24022397 (pc + 1 )
24032398 state
2404- (Let
2405- ( m
2406- , Prim
2407- ( Extern " caml_get_public_method"
2408- , [ Pv obj; Pv tag; Pc (Int Targetint. zero) ] ) )
2409- :: instrs)
2399+ (Let (m, Prim (Extern " caml_get_public_method" , [ Pv obj; Pv tag ])) :: instrs)
24102400 | GETMETHOD ->
24112401 let lab = State. accu state in
24122402 let obj = State. peek 0 state in
@@ -2537,7 +2527,12 @@ let parse_bytecode code globals debug_data =
25372527 in
25382528 compiled_blocks := Addr.Map. empty;
25392529 tagged_blocks := Addr.Map. empty;
2540- Code. compact p
2530+ let p = Code. compact p in
2531+ let body =
2532+ List. fold_left globals.cache_ids ~init: [] ~f: (fun body cache_id ->
2533+ Let (cache_id, Prim (Extern " caml_oo_cache_id" , [] )) :: body)
2534+ in
2535+ Code. prepend p body
25412536
25422537module Toc : sig
25432538 type t
0 commit comments