|
|
@@ -320,16 +320,16 @@ let check_unification ctx e t =
|
|
|
end;
|
|
|
e
|
|
|
|
|
|
-let rec fix_return_dynamic_from_void_function ctx return_is_void e =
|
|
|
+let rec fix_return_dynamic_from_void_function return_is_void e =
|
|
|
match e.eexpr with
|
|
|
| TFunction fn ->
|
|
|
let is_void = ExtType.is_void (follow fn.tf_type) in
|
|
|
- let body = fix_return_dynamic_from_void_function ctx is_void fn.tf_expr in
|
|
|
+ let body = fix_return_dynamic_from_void_function is_void fn.tf_expr in
|
|
|
{ e with eexpr = TFunction { fn with tf_expr = body } }
|
|
|
| TReturn (Some return_expr) when return_is_void && t_dynamic == follow return_expr.etype ->
|
|
|
let return_pos = { e.epos with pmax = return_expr.epos.pmin - 1 } in
|
|
|
let exprs = [
|
|
|
- fix_return_dynamic_from_void_function ctx return_is_void return_expr;
|
|
|
+ fix_return_dynamic_from_void_function return_is_void return_expr;
|
|
|
{ e with eexpr = TReturn None; epos = return_pos };
|
|
|
] in
|
|
|
{ e with
|
|
|
@@ -338,7 +338,7 @@ let rec fix_return_dynamic_from_void_function ctx return_is_void e =
|
|
|
mk (TBlock exprs) e.etype e.epos
|
|
|
);
|
|
|
}
|
|
|
- | _ -> Type.map_expr (fix_return_dynamic_from_void_function ctx return_is_void) e
|
|
|
+ | _ -> Type.map_expr (fix_return_dynamic_from_void_function return_is_void) e
|
|
|
|
|
|
let check_abstract_as_value e =
|
|
|
let rec loop e =
|
|
|
@@ -385,10 +385,10 @@ let remove_extern_fields com t = match t with
|
|
|
(* PASS 3 begin *)
|
|
|
|
|
|
(* Checks if a private class' path clashes with another path *)
|
|
|
-let check_private_path ctx t = match t with
|
|
|
+let check_private_path com t = match t with
|
|
|
| TClassDecl c when c.cl_private ->
|
|
|
let rpath = (fst c.cl_module.m_path,"_" ^ snd c.cl_module.m_path) in
|
|
|
- if ctx.com.type_to_module#mem rpath then raise_typing_error ("This private class name will clash with " ^ s_type_path rpath) c.cl_pos;
|
|
|
+ if com.type_to_module#mem rpath then raise_typing_error ("This private class name will clash with " ^ s_type_path rpath) c.cl_pos;
|
|
|
| _ ->
|
|
|
()
|
|
|
|
|
|
@@ -653,10 +653,10 @@ let commit_features com t =
|
|
|
Common.add_feature com k;
|
|
|
) m.m_extra.m_features
|
|
|
|
|
|
-let check_reserved_type_paths ctx t =
|
|
|
+let check_reserved_type_paths com t =
|
|
|
let check path pos =
|
|
|
- if List.mem path ctx.com.config.pf_reserved_type_paths then begin
|
|
|
- warning ctx WReservedTypePath ("Type path " ^ (s_type_path path) ^ " is reserved on this target") pos
|
|
|
+ if List.mem path com.config.pf_reserved_type_paths then begin
|
|
|
+ com.warning WReservedTypePath [] ("Type path " ^ (s_type_path path) ^ " is reserved on this target") pos
|
|
|
end
|
|
|
in
|
|
|
match t with
|
|
|
@@ -671,7 +671,8 @@ let is_cached com t =
|
|
|
m.m_processed <> 0 && m.m_processed < com.compilation_step
|
|
|
|
|
|
let apply_filters_once ctx filters t =
|
|
|
- if not (is_cached ctx.com t) then run_expression_filters None ctx filters t
|
|
|
+ let detail_times = (try int_of_string (Common.defined_value_safe ctx.com ~default:"0" Define.FilterTimes) with _ -> 0) in
|
|
|
+ if not (is_cached ctx.com t) then run_expression_filters ctx detail_times filters t
|
|
|
|
|
|
let iter_expressions fl mt =
|
|
|
match mt with
|
|
|
@@ -686,13 +687,6 @@ let iter_expressions fl mt =
|
|
|
| _ ->
|
|
|
()
|
|
|
|
|
|
-let filter_timer detailed s =
|
|
|
- Timer.timer (if detailed then "filters" :: s else ["filters"])
|
|
|
-
|
|
|
-let timer_label detailed s =
|
|
|
- if detailed then Some ("filters" :: s)
|
|
|
- else None
|
|
|
-
|
|
|
module ForRemap = struct
|
|
|
let apply ctx e =
|
|
|
let rec loop e = match e.eexpr with
|
|
|
@@ -713,43 +707,45 @@ module ForRemap = struct
|
|
|
loop e
|
|
|
end
|
|
|
|
|
|
+open FilterContext
|
|
|
+
|
|
|
let destruction tctx detail_times main locals =
|
|
|
let com = tctx.com in
|
|
|
- let t = filter_timer detail_times ["type 2"] in
|
|
|
- (* PASS 2: type filters pre-DCE *)
|
|
|
- List.iter (fun t ->
|
|
|
- remove_generic_base t;
|
|
|
- remove_extern_fields com t;
|
|
|
- (* check @:remove metadata before DCE so it is ignored there (issue #2923) *)
|
|
|
- check_remove_metadata t;
|
|
|
- ) com.types;
|
|
|
- t();
|
|
|
+ with_timer detail_times "type 2" None (fun () ->
|
|
|
+ (* PASS 2: type filters pre-DCE *)
|
|
|
+ List.iter (fun t ->
|
|
|
+ remove_generic_base t;
|
|
|
+ remove_extern_fields com t;
|
|
|
+ (* check @:remove metadata before DCE so it is ignored there (issue #2923) *)
|
|
|
+ check_remove_metadata t;
|
|
|
+ ) com.types;
|
|
|
+ );
|
|
|
com.stage <- CDceStart;
|
|
|
- let t = filter_timer detail_times ["dce"] in
|
|
|
- (* DCE *)
|
|
|
- let dce_mode = try Common.defined_value com Define.Dce with _ -> "no" in
|
|
|
- let dce_mode = match dce_mode with
|
|
|
- | "full" -> if Common.defined com Define.Interp then Dce.DceNo else DceFull
|
|
|
- | "std" -> DceStd
|
|
|
- | "no" -> DceNo
|
|
|
- | _ -> failwith ("Unknown DCE mode " ^ dce_mode)
|
|
|
- in
|
|
|
- Dce.run com main dce_mode;
|
|
|
- t();
|
|
|
+ with_timer detail_times "dce" None (fun () ->
|
|
|
+ (* DCE *)
|
|
|
+ let dce_mode = try Common.defined_value com Define.Dce with _ -> "no" in
|
|
|
+ let dce_mode = match dce_mode with
|
|
|
+ | "full" -> if Common.defined com Define.Interp then Dce.DceNo else DceFull
|
|
|
+ | "std" -> DceStd
|
|
|
+ | "no" -> DceNo
|
|
|
+ | _ -> failwith ("Unknown DCE mode " ^ dce_mode)
|
|
|
+ in
|
|
|
+ Dce.run com main dce_mode;
|
|
|
+ );
|
|
|
com.stage <- CDceDone;
|
|
|
(* PASS 3: type filters post-DCE *)
|
|
|
List.iter
|
|
|
(run_expression_filters
|
|
|
~ignore_processed_status:true
|
|
|
- (timer_label detail_times [])
|
|
|
tctx
|
|
|
+ detail_times
|
|
|
(* This has to run after DCE, or otherwise its condition always holds. *)
|
|
|
["insert_save_stacks",Exceptions.insert_save_stacks tctx]
|
|
|
)
|
|
|
com.types;
|
|
|
let type_filters = [
|
|
|
Exceptions.patch_constructors tctx; (* TODO: I don't believe this should load_instance anything at this point... *)
|
|
|
- check_private_path tctx;
|
|
|
+ check_private_path com;
|
|
|
apply_native_paths;
|
|
|
add_rtti com;
|
|
|
(match com.platform with | Java | Cs -> (fun _ -> ()) | _ -> (fun mt -> add_field_inits tctx.curclass.cl_path locals com mt));
|
|
|
@@ -757,23 +753,23 @@ let destruction tctx detail_times main locals =
|
|
|
check_void_field;
|
|
|
(match com.platform with | Cpp -> promote_first_interface_to_super | _ -> (fun _ -> ()));
|
|
|
commit_features com;
|
|
|
- (if com.config.pf_reserved_type_paths <> [] then check_reserved_type_paths tctx else (fun _ -> ()));
|
|
|
+ (if com.config.pf_reserved_type_paths <> [] then check_reserved_type_paths com else (fun _ -> ()));
|
|
|
] in
|
|
|
let type_filters = match com.platform with
|
|
|
| Cs -> type_filters @ [ fun t -> InterfaceProps.run t ]
|
|
|
| _ -> type_filters
|
|
|
in
|
|
|
- let t = filter_timer detail_times ["type 3"] in
|
|
|
- List.iter (fun t ->
|
|
|
- begin match t with
|
|
|
- | TClassDecl c ->
|
|
|
- tctx.curclass <- c
|
|
|
- | _ ->
|
|
|
- ()
|
|
|
- end;
|
|
|
- List.iter (fun f -> f t) type_filters
|
|
|
- ) com.types;
|
|
|
- t();
|
|
|
+ with_timer detail_times "type 3" None (fun () ->
|
|
|
+ List.iter (fun t ->
|
|
|
+ begin match t with
|
|
|
+ | TClassDecl c ->
|
|
|
+ tctx.curclass <- c
|
|
|
+ | _ ->
|
|
|
+ ()
|
|
|
+ end;
|
|
|
+ List.iter (fun f -> f t) type_filters
|
|
|
+ ) com.types;
|
|
|
+ );
|
|
|
com.callbacks#run com.callbacks#get_after_filters;
|
|
|
com.stage <- CFilteringDone
|
|
|
|
|
|
@@ -828,10 +824,10 @@ let update_cache_dependencies com t =
|
|
|
()
|
|
|
|
|
|
(* Saves a class state so it can be restored later, e.g. after DCE or native path rewrite *)
|
|
|
-let save_class_state ctx t =
|
|
|
+let save_class_state com t =
|
|
|
(* Update m_processed here. This means that nothing should add a dependency afterwards because
|
|
|
then the module is immediately considered uncached again *)
|
|
|
- (t_infos t).mt_module.m_extra.m_processed <- ctx.com.compilation_step;
|
|
|
+ (t_infos t).mt_module.m_extra.m_processed <- com.compilation_step;
|
|
|
match t with
|
|
|
| TClassDecl c ->
|
|
|
let vars = ref [] in
|
|
|
@@ -915,8 +911,9 @@ let save_class_state ctx t =
|
|
|
a.a_meta <- List.filter (fun (m,_,_) -> m <> Meta.ValueUsed) a.a_meta
|
|
|
)
|
|
|
|
|
|
-let run com tctx main =
|
|
|
- let detail_times = Common.defined com DefineList.FilterTimes in
|
|
|
+let run tctx main =
|
|
|
+ let com = tctx.com in
|
|
|
+ let detail_times = (try int_of_string (Common.defined_value_safe com ~default:"0" Define.FilterTimes) with _ -> 0) in
|
|
|
let new_types = List.filter (fun t ->
|
|
|
let cached = is_cached com t in
|
|
|
begin match t with
|
|
|
@@ -955,10 +952,10 @@ let run com tctx main =
|
|
|
"ForRemap",ForRemap.apply tctx;
|
|
|
"handle_abstract_casts",AbstractCast.handle_abstract_casts tctx;
|
|
|
] in
|
|
|
- List.iter (run_expression_filters (timer_label detail_times ["expr 0"]) tctx filters) new_types;
|
|
|
+ List.iter (run_expression_filters tctx detail_times filters) new_types;
|
|
|
let filters = [
|
|
|
"local_statics",LocalStatic.run tctx;
|
|
|
- "fix_return_dynamic_from_void_function",fix_return_dynamic_from_void_function tctx true;
|
|
|
+ "fix_return_dynamic_from_void_function",fix_return_dynamic_from_void_function true;
|
|
|
"check_local_vars_init",check_local_vars_init tctx;
|
|
|
"check_abstract_as_value",check_abstract_as_value;
|
|
|
"Tre",if defined com Define.AnalyzerOptimize then Tre.run tctx else (fun e -> e);
|
|
|
@@ -977,13 +974,13 @@ let run com tctx main =
|
|
|
filters
|
|
|
| _ -> filters
|
|
|
in
|
|
|
- List.iter (run_expression_filters (timer_label detail_times ["expr 1"]) tctx filters) new_types;
|
|
|
+ List.iter (run_expression_filters tctx detail_times filters) new_types;
|
|
|
(* PASS 1.5: pre-analyzer type filters *)
|
|
|
let filters =
|
|
|
match com.platform with
|
|
|
| Cs ->
|
|
|
[
|
|
|
- check_cs_events tctx.com;
|
|
|
+ check_cs_events com;
|
|
|
DefaultArguments.run com;
|
|
|
]
|
|
|
| Java ->
|
|
|
@@ -993,9 +990,9 @@ let run com tctx main =
|
|
|
| _ ->
|
|
|
[]
|
|
|
in
|
|
|
- let t = filter_timer detail_times ["type 1"] in
|
|
|
- List.iter (fun f -> List.iter f new_types) filters;
|
|
|
- t();
|
|
|
+ with_timer detail_times "type 1" None (fun () ->
|
|
|
+ List.iter (fun f -> List.iter f new_types) filters;
|
|
|
+ );
|
|
|
com.stage <- CAnalyzerStart;
|
|
|
if com.platform <> Cross then Analyzer.Run.run_on_types com new_types;
|
|
|
com.stage <- CAnalyzerDone;
|
|
|
@@ -1005,22 +1002,23 @@ let run com tctx main =
|
|
|
"add_final_return",if com.config.pf_add_final_return then add_final_return else (fun e -> e);
|
|
|
"RenameVars",(match com.platform with
|
|
|
| Eval -> (fun e -> e)
|
|
|
+ | Java when defined com Jvm -> (fun e -> e)
|
|
|
| _ -> (fun e -> RenameVars.run tctx.curclass.cl_path locals e));
|
|
|
"mark_switch_break_loops",mark_switch_break_loops;
|
|
|
] in
|
|
|
- List.iter (run_expression_filters (timer_label detail_times ["expr 2"]) tctx filters) new_types;
|
|
|
- let t = filter_timer detail_times ["callbacks"] in
|
|
|
- com.callbacks#run com.callbacks#get_before_save; (* macros onGenerate etc. *)
|
|
|
- t();
|
|
|
+ List.iter (run_expression_filters tctx detail_times filters) new_types;
|
|
|
+ with_timer detail_times "callbacks" None (fun () ->
|
|
|
+ com.callbacks#run com.callbacks#get_before_save;
|
|
|
+ );
|
|
|
com.stage <- CSaveStart;
|
|
|
- let t = filter_timer detail_times ["save state"] in
|
|
|
- List.iter (fun mt ->
|
|
|
- update_cache_dependencies com mt;
|
|
|
- save_class_state tctx mt
|
|
|
- ) new_types;
|
|
|
- t();
|
|
|
+ with_timer detail_times "save state" None (fun () ->
|
|
|
+ List.iter (fun mt ->
|
|
|
+ update_cache_dependencies com mt;
|
|
|
+ save_class_state com mt
|
|
|
+ ) new_types;
|
|
|
+ );
|
|
|
com.stage <- CSaveDone;
|
|
|
- let t = filter_timer detail_times ["callbacks"] in
|
|
|
- com.callbacks#run com.callbacks#get_after_save; (* macros onGenerate etc. *)
|
|
|
- t();
|
|
|
+ with_timer detail_times "callbacks" None (fun () ->
|
|
|
+ com.callbacks#run com.callbacks#get_after_save;
|
|
|
+ );
|
|
|
destruction tctx detail_times main locals
|