Skip to content

Commit

Permalink
add v_meta (and remove snd v_extra to even out memory consumption)
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Oct 18, 2013
1 parent 21d8ba6 commit 23f5f4a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions optimizer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -358,16 +358,16 @@ let rec type_inline ctx cf f ethis params tret config p force =
let force = ref force in
let vars = List.fold_left (fun acc (i,e) ->
let flag = not i.i_force_temp && (match e.eexpr with
| TLocal {v_extra = _,true} -> true
| TLocal v when Meta.has Meta.This v.v_meta -> true
| TLocal _ | TConst _ -> not i.i_write
| TFunction _ -> if i.i_write then error "Cannot modify a closure parameter inside inline method" p; true
| _ -> not i.i_write && i.i_read <= 1
) in
let flag = flag && (not i.i_captured || is_constant e) in
(* force inlining if we modify 'this' *)
if i.i_write && snd i.i_var.v_extra then force := true;
if i.i_write && (Meta.has Meta.This i.i_var.v_meta) then force := true;
(* force inlining of 'this' variable if it is written *)
let flag = if not flag && snd i.i_var.v_extra && i.i_write then begin
let flag = if not flag && (Meta.has Meta.This i.i_var.v_meta) && i.i_write then begin
if not (is_writable e) then error "Cannot modify the abstract value, store it into a local first" p;
true
end else flag in
Expand Down
6 changes: 3 additions & 3 deletions type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ and tvar = {
mutable v_name : string;
mutable v_type : t;
mutable v_capture : bool;
(* snd = true if abstract "this" argument *)
mutable v_extra : (type_params * texpr option) option * bool;
mutable v_extra : (type_params * texpr option) option;
mutable v_meta : metadata;
}

and tfunc = {
Expand Down Expand Up @@ -311,7 +311,7 @@ and decision_tree = {

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,false })
(fun n t -> incr uid; { v_name = n; v_type = t; v_id = !uid; v_capture = false; v_extra = None; v_meta = [] })

let alloc_mid =
let mid = ref 0 in
Expand Down
2 changes: 1 addition & 1 deletion typeload.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ let type_function ctx args ret fmode f do_display p =
| _ -> display_error ctx "Parameter default value should be constant" p; None
) in
let v,c = add_local ctx n t, c in
if n = "this" then v.v_extra <- None,true;
if n = "this" then v.v_meta <- (Meta.This,[],p) :: v.v_meta;
v,c
) args in
let old_ret = ctx.ret in
Expand Down
4 changes: 2 additions & 2 deletions typer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ let rec type_ident_raise ?(imported_enums=true) ctx i p mode =
| _ ->
try
let v = PMap.find i ctx.locals in
(match fst v.v_extra with
(match v.v_extra with
| Some (params,e) ->
let t = monomorphs params v.v_type in
(match e with
Expand Down Expand Up @@ -2876,7 +2876,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
(match v with
| None -> e
| Some v ->
if params <> [] || inline then v.v_extra <- Some (params,if inline then Some e else None),snd v.v_extra;
if params <> [] || inline then v.v_extra <- Some (params,if inline then Some e else None);
let rec loop = function
| Codegen.Block f | Codegen.Loop f | Codegen.Function f -> f loop
| Codegen.Use v2 when v == v2 -> raise Exit
Expand Down

0 comments on commit 23f5f4a

Please sign in to comment.