Skip to content

Commit

Permalink
completely rewrote compiler priority passes system
Browse files Browse the repository at this point in the history
  • Loading branch information
ncannasse committed Sep 7, 2012
1 parent 8fbad36 commit 52434b4
Show file tree
Hide file tree
Showing 5 changed files with 455 additions and 314 deletions.
18 changes: 9 additions & 9 deletions codegen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ let make_generic ctx ps pt p =
in
let name =
String.concat "_" (List.map2 (fun (s,_) t ->
let path = (match follow t with
let path = (match follow t with
| TInst (ct,_) -> ct.cl_path
| TEnum (e,_) -> e.e_path
| TAbstract (a,_) when has_meta ":runtime_value" a.a_meta -> a.a_path
Expand Down Expand Up @@ -489,17 +489,17 @@ let build_instance ctx mtype p =
r := (fun() -> t);
unify_raise ctx (build_generic ctx c p pl) t p;
t
) in
delay ctx (fun() -> ignore ((!r)()));
) "build_generic" in
delay ctx PForce (fun() -> ignore ((!r)()));
TLazy r
| KMacroType ->
let r = exc_protect ctx (fun r ->
let t = mk_mono() in
r := (fun() -> t);
unify_raise ctx (build_macro_type ctx pl p) t p;
t
) in
delay ctx (fun() -> ignore ((!r)()));
) "macro_type" in
delay ctx PForce (fun() -> ignore ((!r)()));
TLazy r
| _ ->
TInst (c,pl)
Expand Down Expand Up @@ -567,7 +567,7 @@ let remove_generic_base ctx t = match t with
(try
let (_,_,prec) = get_meta ":?genericRec" c.cl_meta in
(try
let (_,_,pnew) = get_meta ":?genericT" c.cl_meta in
let (_,_,pnew) = get_meta ":?genericT" c.cl_meta in
display_error ctx ("Class " ^ (s_type_path c.cl_path) ^ " was used recursively and cannot use its type parameter") prec;
error "Type parameter usage was here" pnew
with Not_found _ ->
Expand Down Expand Up @@ -603,7 +603,7 @@ let apply_native_paths ctx t =
()

(* Adds the __rtti field if required *)
let add_rtti ctx t =
let add_rtti ctx t =
let has_rtti c =
let rec has_rtti_new c =
has_meta ":rttiInfos" c.cl_meta || match c.cl_super with None -> false | Some (csup,_) -> has_rtti_new csup
Expand Down Expand Up @@ -1563,10 +1563,10 @@ let rec create_dumpfile acc = function
| [] -> assert false
| d :: [] ->
let ch = open_out (String.concat "/" (List.rev (d :: acc)) ^ ".dump") in
let buf = Buffer.create 0 in
let buf = Buffer.create 0 in
buf, (fun () ->
output_string ch (Buffer.contents buf);
close_out ch)
close_out ch)
| d :: l ->
let dir = String.concat "/" (List.rev (d :: acc)) in
if not (Sys.file_exists dir) then Unix.mkdir dir 0o755;
Expand Down
36 changes: 26 additions & 10 deletions type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ let alloc_var =
let uid = ref 0 in
(fun n t -> incr uid; { v_name = n; v_type = t; v_id = !uid; v_capture = false; v_extra = None })

let alloc_mid =
let alloc_mid =
let mid = ref 0 in
(fun() -> incr mid; !mid)

Expand Down Expand Up @@ -320,7 +320,7 @@ let mk_class m path pos =
cl_restore = (fun() -> ());
}

let module_extra file sign time kind =
let module_extra file sign time kind =
{
m_file = file;
m_sign = sign;
Expand All @@ -335,6 +335,20 @@ let module_extra file sign time kind =
m_macro_calls = [];
}


let mk_field name t p = {
cf_name = name;
cf_type = t;
cf_pos = p;
cf_doc = None;
cf_meta = [];
cf_public = true;
cf_kind = Var { v_read = AccNormal; v_write = AccNormal };
cf_expr = None;
cf_params = [];
cf_overloads = [];
}

let null_module = {
m_id = alloc_mid();
m_path = [] , "";
Expand All @@ -347,6 +361,8 @@ let null_class =
c.cl_private <- true;
c

let null_field = mk_field "" t_dynamic Ast.null_pos

let add_dependency m mdep =
if m != null_module && m != mdep then m.m_extra.m_deps <- PMap.add mdep.m_id mdep m.m_extra.m_deps

Expand Down Expand Up @@ -567,7 +583,7 @@ let rec is_nullable ?(no_lazy=false) = function
(*
Type parameters will most of the time be nullable objects, so we don't want to make it hard for users
to have to specify Null<T> all over the place, so while they could be a basic type, let's assume they will not.
This will still cause issues with inlining and haxe.rtti.Generic. In that case proper explicit Null<T> is required to
work correctly with basic types. This could still be fixed by redoing a nullability inference on the typed AST.
Expand Down Expand Up @@ -854,10 +870,10 @@ let rec raw_class_field build_type c i =
| _ ->
loop ctl
in
loop tl
loop tl
| _ ->
if not c.cl_interface then raise Not_found;
(*
(*
an interface can implements other interfaces without
having to redeclare its fields
*)
Expand Down Expand Up @@ -924,14 +940,14 @@ let rec unify a b =
unify_types a b tl1 tl2
| TAbstract (a1,tl1) , TAbstract (a2,tl2) when a1 == a2 ->
unify_types a b tl1 tl2
| TAbstract (a1,tl1) , TAbstract (a2,tl2) ->
| TAbstract (a1,tl1) , TAbstract (a2,tl2) ->
if not (List.exists (fun t ->
let t = apply_params a1.a_types tl1 t in
try unify t b; true with Unify_error _ -> false
) a1.a_super) && not (List.exists (fun t ->
let t = apply_params a2.a_types tl2 t in
try unify a t; true with Unify_error _ -> false
) a2.a_sub) then error [cannot_unify a b]
) a2.a_sub) then error [cannot_unify a b]
| TInst (c1,tl1) , TInst (c2,tl2) ->
let rec loop c tl =
if c == c2 then begin
Expand All @@ -943,7 +959,7 @@ let rec unify a b =
loop cs (List.map (apply_params c.cl_types tl) tls)
) || List.exists (fun (cs,tls) ->
loop cs (List.map (apply_params c.cl_types tl) tls)
) c.cl_implements
) c.cl_implements
|| (match c.cl_kind with
| KTypeParameter pl -> List.exists (fun t -> match follow t with TInst (cs,tls) -> loop cs (List.map (apply_params c.cl_types tl) tls) | _ -> false) pl
| _ -> false)
Expand Down Expand Up @@ -987,7 +1003,7 @@ let rec unify a b =
PMap.iter (fun n f2 ->
try
let f1 = PMap.find n a1.a_fields in
if not (unify_kind f1.cf_kind f2.cf_kind) then
if not (unify_kind f1.cf_kind f2.cf_kind) then
(match !(a1.a_status), f1.cf_kind, f2.cf_kind with
| Opened, Var { v_read = AccNormal; v_write = AccNo }, Var { v_read = AccNormal; v_write = AccNormal } ->
f1.cf_kind <- f2.cf_kind;
Expand Down Expand Up @@ -1088,7 +1104,7 @@ let rec unify a b =
and unify_types a b tl1 tl2 =
List.iter2 (fun t1 t2 ->
try
type_eq EqRightDynamic t1 t2
type_eq EqRightDynamic t1 t2
with Unify_error l ->
let err = cannot_unify a b in
error (try unify t1 t2; (err :: (Invariant_parameter (t1,t2)) :: l) with _ -> err :: l)
Expand Down
Loading

0 comments on commit 52434b4

Please sign in to comment.