src/HOL/Tools/Predicate_Compile/predicate_compile_core.ML
changeset 39201 234e6ef4ff67
parent 39194 c8406125193b
child 39273 92aa2a0f7399
equal deleted inserted replaced
39200:bb93713b0925 39201:234e6ef4ff67
   377   in
   377   in
   378     fold print (all_modes_of compilation ctxt) ()
   378     fold print (all_modes_of compilation ctxt) ()
   379   end
   379   end
   380 
   380 
   381 (* validity checks *)
   381 (* validity checks *)
   382 (* EXPECTED MODE and PROPOSED_MODE are largely the same; define a clear semantics for those! *)
       
   383 
   382 
   384 fun check_expected_modes preds options modes =
   383 fun check_expected_modes preds options modes =
   385   case expected_modes options of
   384   case expected_modes options of
   386     SOME (s, ms) => (case AList.lookup (op =) modes s of
   385     SOME (s, ms) => (case AList.lookup (op =) modes s of
   387       SOME modes =>
   386       SOME modes =>
   395           else ()
   394           else ()
   396         end
   395         end
   397       | NONE => ())
   396       | NONE => ())
   398   | NONE => ()
   397   | NONE => ()
   399 
   398 
   400 fun check_proposed_modes preds options modes extra_modes errors =
   399 fun check_proposed_modes preds options modes errors =
   401   case proposed_modes options of
   400   case proposed_modes options of
   402     SOME (s, ms) => (case AList.lookup (op =) modes s of
   401     SOME (s, ms) => (case AList.lookup (op =) modes s of
   403       SOME inferred_ms =>
   402       SOME inferred_ms =>
   404         let
   403         let
   405           val preds_without_modes = map fst (filter (null o snd) (modes @ extra_modes))
   404           val preds_without_modes = map fst (filter (null o snd) modes)
   406           val modes' = map snd inferred_ms
   405           val modes' = map snd inferred_ms
   407         in
   406         in
   408           if not (eq_set eq_mode (ms, modes')) then
   407           if not (eq_set eq_mode (ms, modes')) then
   409             error ("expected modes were not inferred:\n"
   408             error ("expected modes were not inferred:\n"
   410             ^ "  inferred modes for " ^ s ^ ": " ^ commas (map string_of_mode modes')  ^ "\n"
   409             ^ "  inferred modes for " ^ s ^ ": " ^ commas (map string_of_mode modes')  ^ "\n"
  2693     val preds = map (fn c => Const (c, Sign.the_const_type thy c)) prednames
  2692     val preds = map (fn c => Const (c, Sign.the_const_type thy c)) prednames
  2694     val (preds, intrs) = unify_consts thy preds intrs
  2693     val (preds, intrs) = unify_consts thy preds intrs
  2695     val ([preds, intrs], _) = fold_burrow (Variable.import_terms false) [preds, intrs] ctxt
  2694     val ([preds, intrs], _) = fold_burrow (Variable.import_terms false) [preds, intrs] ctxt
  2696     val preds = map dest_Const preds
  2695     val preds = map dest_Const preds
  2697     val all_vs = terms_vs intrs
  2696     val all_vs = terms_vs intrs
       
  2697     fun generate_modes s T =
       
  2698       if member (op =) (no_higher_order_predicate options) s then
       
  2699         all_smodes_of_typ T
       
  2700       else
       
  2701         all_modes_of_typ T
  2698     val all_modes = 
  2702     val all_modes = 
  2699       map (fn (s, T) =>
  2703       map (fn (s, T) =>
  2700         (s,
  2704         (s, case (proposed_modes options) of
  2701             (if member (op =) (no_higher_order_predicate options) s then
  2705             SOME (s', ms) => if s = s' then ms else generate_modes s T
  2702                (all_smodes_of_typ T)
  2706           | NONE => generate_modes s T)) preds
  2703             else (all_modes_of_typ T)))) preds
       
  2704     val params =
  2707     val params =
  2705       case intrs of
  2708       case intrs of
  2706         [] =>
  2709         [] =>
  2707           let
  2710           let
  2708             val T = snd (hd preds)
  2711             val T = snd (hd preds)
  2846       Output.cond_timeit (!Quickcheck.timing) "Infering modes"
  2849       Output.cond_timeit (!Quickcheck.timing) "Infering modes"
  2847       (fn _ => infer_modes mode_analysis_options
  2850       (fn _ => infer_modes mode_analysis_options
  2848         options compilation preds all_modes param_vs clauses thy)
  2851         options compilation preds all_modes param_vs clauses thy)
  2849     val modes = map (fn (p, mps) => (p, map fst mps)) moded_clauses
  2852     val modes = map (fn (p, mps) => (p, map fst mps)) moded_clauses
  2850     val _ = check_expected_modes preds options modes
  2853     val _ = check_expected_modes preds options modes
  2851     (*val _ = check_proposed_modes preds options modes (fst extra_modes) errors*)
  2854     val _ = check_proposed_modes preds options modes errors
  2852     val _ = print_modes options modes
  2855     val _ = print_modes options modes
  2853     val _ = print_step options "Defining executable functions..."
  2856     val _ = print_step options "Defining executable functions..."
  2854     val thy'' =
  2857     val thy'' =
  2855       Output.cond_timeit (!Quickcheck.timing) "Defining executable functions..."
  2858       Output.cond_timeit (!Quickcheck.timing) "Defining executable functions..."
  2856       (fn _ => fold (#define_functions (dest_steps steps) options preds) modes thy'
  2859       (fn _ => fold (#define_functions (dest_steps steps) options preds) modes thy'