Skip to content

Commit

Permalink
Lazify classes too
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Dec 10, 2024
1 parent b437db9 commit c1b2567
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/compiler/hxb/hxbReader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class hxb_reader
val mutable string_pool = (match string_pool with None -> Array.make 0 "" | Some pool -> pool)
val mutable doc_pool = Array.make 0 ""

val mutable classes = Array.make 0 null_class
val mutable classes = Array.make 0 (Lazy.from_val null_class)
val mutable abstracts = Array.make 0 (Lazy.from_val null_abstract)
val mutable enums = Array.make 0 (Lazy.from_val null_enum)
val mutable typedefs = Array.make 0 (Lazy.from_val null_typedef)
Expand Down Expand Up @@ -761,6 +761,7 @@ class hxb_reader
(mk_type_param { null_class with cl_path = path } TPHUnbound None None).ttp_type
| 10 ->
let c = self#read_class_ref in
let c = Lazy.force c in
c.cl_type
| 11 ->
let en = self#read_enum_ref in
Expand Down Expand Up @@ -836,19 +837,23 @@ class hxb_reader
TFun(args,ret)
| 40 ->
let c = self#read_class_ref in
let c = Lazy.force c in
TInst(c,[])
| 41 ->
let c = self#read_class_ref in
let t1 = self#read_type_instance in
let c = Lazy.force c in
TInst(c,[t1])
| 42 ->
let c = self#read_class_ref in
let t1 = self#read_type_instance in
let t2 = self#read_type_instance in
let c = Lazy.force c in
TInst(c,[t1;t2])
| 49 ->
let c = self#read_class_ref in
let tl = self#read_types in
let c = Lazy.force c in
TInst(c,tl)
| 50 ->
let en = self#read_enum_ref in
Expand Down Expand Up @@ -1300,12 +1305,14 @@ class hxb_reader
| 102 ->
let e1 = loop () in
let c = self#read_class_ref in
let c = Lazy.force c in
let tl = self#read_types in
let cf = self#read_field_ref in
TField(e1,FInstance(c,tl,cf)),None
| 103 ->
let e1 = loop () in
let c = self#read_class_ref in
let c = Lazy.force c in
let cf = self#read_field_ref in
TField(e1,FStatic(c,cf)),None
| 104 ->
Expand All @@ -1315,6 +1322,7 @@ class hxb_reader
| 105 ->
let e1 = loop () in
let c = self#read_class_ref in
let c = Lazy.force c in
let tl = self#read_types in
let cf = self#read_field_ref in
TField(e1,FClosure(Some(c,tl),cf)),None
Expand All @@ -1336,12 +1344,14 @@ class hxb_reader
| 110 ->
let p = read_relpos () in
let c = self#read_class_ref in
let c = Lazy.force c in
let cf = self#read_field_ref in
let e1 = Texpr.Builder.make_static_this c p in
TField(e1,FStatic(c,cf)),None
| 111 ->
let p = read_relpos () in
let c = self#read_class_ref in
let c = Lazy.force c in
let tl = self#read_types in
let cf = self#read_field_ref in
let ethis = mk (TConst TThis) (Option.get fctx.tthis) p in
Expand All @@ -1350,6 +1360,7 @@ class hxb_reader
(* module types 120-139 *)
| 120 ->
let c = self#read_class_ref in
let c = Lazy.force c in
TTypeExpr (TClassDecl c),(Some c.cl_type)
| 121 ->
let en = self#read_enum_ref in
Expand All @@ -1368,6 +1379,7 @@ class hxb_reader
TCast(e1,Some mt),None
| 126 ->
let c = self#read_class_ref in
let c = Lazy.force c in
let tl = self#read_types in
let el = loop_el() in
TNew(c,tl,el),None
Expand Down Expand Up @@ -1567,6 +1579,7 @@ class hxb_reader
infos.mt_params <- Array.to_list type_type_parameters;
infos.mt_using <- self#read_list (fun () ->
let c = self#read_class_ref in
let c = Lazy.force c in
let p = self#read_pos in
(c,p)
)
Expand All @@ -1578,6 +1591,7 @@ class hxb_reader
| 3 -> KGeneric
| 4 ->
let c = self#read_class_ref in
let c = Lazy.force c in
let tl = self#read_types in
KGenericInstance(c,tl)
| 5 -> KMacroType
Expand All @@ -1592,6 +1606,7 @@ class hxb_reader
c.cl_kind <- self#read_class_kind;
let read_relation () =
let c = self#read_class_ref in
let c = Lazy.force c in
let tl = self#read_types in
(c,tl)
in
Expand All @@ -1605,7 +1620,7 @@ class hxb_reader

method read_abstract (a : tabstract) =
self#read_common_module_type (Obj.magic a);
a.a_impl <- self#read_option (fun () -> self#read_class_ref);
a.a_impl <- self#read_option (fun () -> Lazy.force self#read_class_ref);
begin match read_byte ch with
| 0 ->
a.a_this <- TAbstract(a,extract_param_types a.a_params)
Expand Down Expand Up @@ -1713,6 +1728,7 @@ class hxb_reader
let l = read_uleb128 ch in
let a = Array.init l (fun i ->
let c = self#read_class_ref in
let c = Lazy.force c in
let kind = match read_byte ch with
| 0 -> CfrStatic
| 1 -> CfrMember
Expand Down Expand Up @@ -1765,12 +1781,14 @@ class hxb_reader
let l = read_uleb128 ch in
for i = 0 to l - 1 do
let c = classes.(i) in
let c = Lazy.force c in
self#read_class_fields c;
done

method read_exd =
ignore(self#read_list (fun () ->
let c = self#read_class_ref in
let c = Lazy.force c in
self#read_list (fun () ->
let cf = self#read_field_ref in
let length = read_uleb128 ch in
Expand Down Expand Up @@ -1816,6 +1834,7 @@ class hxb_reader
let l = read_uleb128 ch in
for i = 0 to l - 1 do
let c = classes.(i) in
let c = Lazy.force c in
self#read_class c;
done

Expand Down Expand Up @@ -1877,12 +1896,14 @@ class hxb_reader
method read_clr =
let l = read_uleb128 ch in
classes <- (Array.init l (fun i ->
let (pack,mname,tname) = self#read_full_path in
let (pack,mname,tname) = self#read_full_path in
Lazy.from_fun (fun () ->
match self#resolve_type pack mname tname with
| TClassDecl c ->
c
| _ ->
error ("Unexpected type where class was expected: " ^ (s_type_path (pack,tname)))
)
))

method read_abr =
Expand Down

0 comments on commit c1b2567

Please sign in to comment.