@@ -143,8 +143,16 @@ let mark_dead_code js =
143143
144144 Take away, it is really hard to change the code while collecting some information..
145145 we should always collect info in a single pass
146+
147+ Note that, we should avoid reuse object, i.e,
148+ {[
149+ let v =
150+ object
151+ end
152+ ]}
153+ Since user may use `osc -c xx.ml xy.ml xz.ml` and we need clean up state
146154 *)
147- let subst_map = object (self )
155+ let subst_map name = object (self )
148156 inherit Js_map. map as super
149157
150158 val mutable substitution = Hashtbl. create 17
@@ -213,9 +221,19 @@ let subst_map = object (self)
213221 begin match Hashtbl. find self#get_substitution id with
214222 | {expression_desc = Array (ls, Immutable ) }
215223 ->
224+ (* user program can be wrong, we should not
225+ turn a runtime crash into compile time crash : )
226+ *)
216227 begin match List. nth ls i with
217228 | {expression_desc = J. Var _ | Number _ | Str _ } as x
218229 -> x
230+ | exception _ ->
231+ begin
232+ Ext_log. err __LOC__ " suspcious code %s when compiling %s@."
233+ (Printf. sprintf " %s/%d" id.name id.stamp)
234+ name ;
235+ super#expression x ;
236+ end
219237 | _ ->
220238 (* * we can do here, however, we should
221239 be careful that it can only be done
266284 there is no need to add another pass
267285 *)
268286
269- let program js =
287+ let program ( js : J.program ) =
270288 js
271- |> subst_map#program
289+ |> ( subst_map js.name ) #program
272290 |> mark_dead_code
273291 (* |> mark_dead_code *)
274292 (* mark dead code twice does have effect in some cases, however, we disabled it
0 commit comments