src/Tools/Code/code_thingol.ML
changeset 59543 d3f4ddeaacc3
parent 59542 0a528e3aad28
child 59544 792691e4b311
equal deleted inserted replaced
59542:0a528e3aad28 59543:d3f4ddeaacc3
   676       let
   676       let
   677         fun disjunctive_varnames ts =
   677         fun disjunctive_varnames ts =
   678           let
   678           let
   679             val vs = (fold o fold_varnames) (insert (op =)) ts [];
   679             val vs = (fold o fold_varnames) (insert (op =)) ts [];
   680           in fn pat => null (inter (op =) vs (fold_varnames (insert (op =)) pat [])) end;
   680           in fn pat => null (inter (op =) vs (fold_varnames (insert (op =)) pat [])) end;
       
   681         fun purge_unused_vars_in t =
       
   682           let
       
   683             val vs = fold_varnames (insert (op =)) t [];
       
   684           in
       
   685             map_terms_bottom_up (fn IVar (SOME v) =>
       
   686               IVar (if member (op =) vs v then SOME v else NONE) | t => t)
       
   687           end;
   681         fun collapse_clause vs_map ts body =
   688         fun collapse_clause vs_map ts body =
   682           case body
   689           case body
   683            of IConst { sym = Constant c, ... } => if member (op =) undefineds c
   690            of IConst { sym = Constant c, ... } => if member (op =) undefineds c
   684                 then []
   691                 then []
   685                 else [(ts, body)]
   692                 else [(ts, body)]
   688                   orelse not (exists_var body' v)) clauses
   695                   orelse not (exists_var body' v)) clauses
   689                   andalso forall (disjunctive_varnames ts o fst) clauses
   696                   andalso forall (disjunctive_varnames ts o fst) clauses
   690                 then case AList.lookup (op =) vs_map v
   697                 then case AList.lookup (op =) vs_map v
   691                  of SOME i => maps (fn (pat', body') =>
   698                  of SOME i => maps (fn (pat', body') =>
   692                       collapse_clause (AList.delete (op =) v vs_map)
   699                       collapse_clause (AList.delete (op =) v vs_map)
   693                         (nth_map i (K pat') ts) body') clauses
   700                         (nth_map i (K pat') ts |> map (purge_unused_vars_in body')) body') clauses
   694                   | NONE => [(ts, body)]
   701                   | NONE => [(ts, body)]
   695                 else [(ts, body)]
   702                 else [(ts, body)]
   696             | _ => [(ts, body)];
   703             | _ => [(ts, body)];
   697         fun mk_clause mk tys t =
   704         fun mk_clause mk tys t =
   698           let
   705           let