Permalink
Browse files

[fix] compile, jsimp: Update the exported idents set according to the…

… inlining and sharing
  • Loading branch information...
1 parent cc4cf80 commit 9df2b9c75ed2d2aa739a812c00ac955494296ded @BourgerieQuentin BourgerieQuentin committed Sep 24, 2012
@@ -229,7 +229,26 @@ let compile
let inlining_env =
Imp_Inlining.map_expr_in_env (Imp_Sharing.rewrite_expr sharing_env) inlining_env
in
+ let exported =
+ JsIdentSet.fold
+ (fun i exported ->
+ match Imp_Sharing.get_substitute sharing_env i with
+ | None -> exported
+ | Some s -> JsIdentSet.add s (JsIdentSet.remove i exported)
+ ) exported exported in
save_inlining_env inlining_env;
+ let exported =
+ Imp_Inlining.fold_env
+ (fun i e exported ->
+ if JsIdentSet.mem i exported then
+ JsWalk.Expr.fold
+ (fun exported -> function
+ | JsAst.Je_ident (_, i) -> JsIdentSet.add i exported
+ | _ -> exported
+ ) exported e
+ else exported)
+ inlining_env exported
+ in
#<If:JS_IMP$contains "time"> Printf.printf "code sharing: %fs\n%!" (_chrono.Chrono.read ()); _chrono.Chrono.restart () #<End>;
#<If:JS_IMP$contains "print"> ignore (PassTracker.file ~filename:"js_imp_6_code_sharing" _outputer js_code) #<End>;
let js_code = if options.Qml2jsOptions.cleanup then Imp_CleanUp.clean ~use_shortcut_assignment:true js_code else js_code in
@@ -734,3 +734,12 @@ let map_expr_in_env map env =
| `var e -> `var (map e)
| `fun_ (a, e) -> `fun_ (a, map e))
env.functions }
+
+let fold_env f env acc =
+ JsIdentMap.fold
+ (fun i e acc -> match e with
+ | `var e
+ | `fun_ (_, e) ->
+ f i e acc
+ ) env.functions acc
+
@@ -37,6 +37,9 @@ val global_inline_rewrite_stm : env -> JsAst.statement -> JsAst.statement option
(** [map_expr_in_env f env] Map all JavaScript expression in [env] with [f]. *)
val map_expr_in_env : (JsAst.expr -> JsAst.expr) -> env -> env
+(** [fold_env f env acc] Fold in the inlining [env] with [f]. *)
+val fold_env : (JsAst.ident -> JsAst.expr -> 'a -> 'a) -> env -> 'a -> 'a
+
(**
The interface for separate compilation
*)
@@ -111,3 +111,6 @@ let process_code ~pass code =
let code = rewrite env code in
code, env
+
+
+let get_substitute env i = JsIdentMap.find_opt i env
@@ -32,3 +32,6 @@ val rewrite_expr : env -> JsAst.expr -> JsAst.expr
identical".
*)
val process_code : pass:string -> JsAst.code -> (JsAst.code * env)
+
+(** Get the substitute ident of the given one *)
+val get_substitute : env -> JsIdent.t -> JsIdent.t option

0 comments on commit 9df2b9c

Please sign in to comment.