src/HOL/Tools/Nitpick/nitpick.ML
changeset 54816 10d48c2a3e32
parent 53815 e8aa538e959e
child 55539 0819931d652d
equal deleted inserted replaced
54815:4f6ec8754bf5 54816:10d48c2a3e32
    41      total_consts: bool option,
    41      total_consts: bool option,
    42      needs: term list option,
    42      needs: term list option,
    43      peephole_optim: bool,
    43      peephole_optim: bool,
    44      datatype_sym_break: int,
    44      datatype_sym_break: int,
    45      kodkod_sym_break: int,
    45      kodkod_sym_break: int,
    46      timeout: Time.time option,
    46      timeout: Time.time,
    47      tac_timeout: Time.time option,
    47      tac_timeout: Time.time,
    48      max_threads: int,
    48      max_threads: int,
    49      show_datatypes: bool,
    49      show_datatypes: bool,
    50      show_skolems: bool,
    50      show_skolems: bool,
    51      show_consts: bool,
    51      show_consts: bool,
    52      evals: term list,
    52      evals: term list,
   127    total_consts: bool option,
   127    total_consts: bool option,
   128    needs: term list option,
   128    needs: term list option,
   129    peephole_optim: bool,
   129    peephole_optim: bool,
   130    datatype_sym_break: int,
   130    datatype_sym_break: int,
   131    kodkod_sym_break: int,
   131    kodkod_sym_break: int,
   132    timeout: Time.time option,
   132    timeout: Time.time,
   133    tac_timeout: Time.time option,
   133    tac_timeout: Time.time,
   134    max_threads: int,
   134    max_threads: int,
   135    show_datatypes: bool,
   135    show_datatypes: bool,
   136    show_skolems: bool,
   136    show_skolems: bool,
   137    show_consts: bool,
   137    show_consts: bool,
   138    evals: term list,
   138    evals: term list,
   191   "Nitpick requires the external Java program Kodkodi."
   191   "Nitpick requires the external Java program Kodkodi."
   192 fun kodkodi_too_old_message () = "The installed Kodkodi version is too old."
   192 fun kodkodi_too_old_message () = "The installed Kodkodi version is too old."
   193 val max_unsound_delay_ms = 200
   193 val max_unsound_delay_ms = 200
   194 val max_unsound_delay_percent = 2
   194 val max_unsound_delay_percent = 2
   195 
   195 
   196 fun unsound_delay_for_timeout NONE = max_unsound_delay_ms
   196 fun unsound_delay_for_timeout timeout =
   197   | unsound_delay_for_timeout (SOME timeout) =
   197   Int.max (0, Int.min (max_unsound_delay_ms,
   198     Int.max (0, Int.min (max_unsound_delay_ms,
   198                        Time.toMilliseconds timeout
   199                          Time.toMilliseconds timeout
   199                        * max_unsound_delay_percent div 100))
   200                          * max_unsound_delay_percent div 100))
       
   201 
       
   202 fun passed_deadline NONE = false
       
   203   | passed_deadline (SOME time) = Time.compare (Time.now (), time) <> LESS
       
   204 
   200 
   205 fun none_true assigns = forall (not_equal (SOME true) o snd) assigns
   201 fun none_true assigns = forall (not_equal (SOME true) o snd) assigns
   206 
   202 
   207 fun has_lonely_bool_var (@{const Pure.conjunction}
   203 fun has_lonely_bool_var (@{const Pure.conjunction}
   208                          $ (@{const Trueprop} $ Free _) $ _) = true
   204                          $ (@{const Trueprop} $ Free _) $ _) = true
   256 *)
   252 *)
   257     val print_nt = pprint_nt o K o plazy
   253     val print_nt = pprint_nt o K o plazy
   258     val print_v = pprint_v o K o plazy
   254     val print_v = pprint_v o K o plazy
   259 
   255 
   260     fun check_deadline () =
   256     fun check_deadline () =
   261       if passed_deadline deadline then raise TimeLimit.TimeOut else ()
   257       if Time.compare (Time.now (), deadline) <> LESS then
       
   258         raise TimeLimit.TimeOut
       
   259       else
       
   260         ()
   262 
   261 
   263     val (def_assm_ts, nondef_assm_ts) =
   262     val (def_assm_ts, nondef_assm_ts) =
   264       if assms orelse mode <> Normal then (def_assm_ts, nondef_assm_ts)
   263       if assms orelse mode <> Normal then (def_assm_ts, nondef_assm_ts)
   265       else ([], [])
   264       else ([], [])
   266     val _ =
   265     val _ =
   383     fun is_type_fundamentally_monotonic T =
   382     fun is_type_fundamentally_monotonic T =
   384       (is_datatype ctxt stds T andalso not (is_quot_type ctxt T) andalso
   383       (is_datatype ctxt stds T andalso not (is_quot_type ctxt T) andalso
   385        (not (is_pure_typedef ctxt T) orelse is_univ_typedef ctxt T)) orelse
   384        (not (is_pure_typedef ctxt T) orelse is_univ_typedef ctxt T)) orelse
   386       is_number_type ctxt T orelse is_bit_type T
   385       is_number_type ctxt T orelse is_bit_type T
   387     fun is_type_actually_monotonic T =
   386     fun is_type_actually_monotonic T =
   388       time_limit tac_timeout (formulas_monotonic hol_ctxt binarize T)
   387       TimeLimit.timeLimit tac_timeout (formulas_monotonic hol_ctxt binarize T)
   389                  (nondef_ts, def_ts)
   388                           (nondef_ts, def_ts)
   390       handle TimeLimit.TimeOut => false
   389       handle TimeLimit.TimeOut => false
   391     fun is_type_kind_of_monotonic T =
   390     fun is_type_kind_of_monotonic T =
   392       case triple_lookup (type_match thy) monos T of
   391       case triple_lookup (type_match thy) monos T of
   393         SOME (SOME false) => false
   392         SOME (SOME false) => false
   394       | _ => is_type_actually_monotonic T
   393       | _ => is_type_actually_monotonic T
   577         val kodkod_sat_solver =
   576         val kodkod_sat_solver =
   578           Kodkod_SAT.sat_solver_spec actual_sat_solver |> snd
   577           Kodkod_SAT.sat_solver_spec actual_sat_solver |> snd
   579         val bit_width = if bits = 0 then 16 else bits + 1
   578         val bit_width = if bits = 0 then 16 else bits + 1
   580         val delay =
   579         val delay =
   581           if unsound then
   580           if unsound then
   582             Option.map (fn time => Time.- (time, Time.now ())) deadline
   581             unsound_delay_for_timeout (Time.- (deadline, Time.now ()))
   583             |> unsound_delay_for_timeout
       
   584           else
   582           else
   585             0
   583             0
   586         val settings = [("solver", commas_quote kodkod_sat_solver),
   584         val settings = [("solver", commas_quote kodkod_sat_solver),
   587                         ("bit_width", string_of_int bit_width),
   585                         ("bit_width", string_of_int bit_width),
   588                         ("symmetry_breaking", string_of_int kodkod_sym_break),
   586                         ("symmetry_breaking", string_of_int kodkod_sym_break),
  1073       (print_nt (Pretty.string_of (plazy kodkodi_not_installed_message));
  1071       (print_nt (Pretty.string_of (plazy kodkodi_not_installed_message));
  1074        ("no_kodkodi", state))
  1072        ("no_kodkodi", state))
  1075     else
  1073     else
  1076       let
  1074       let
  1077         val unknown_outcome = (unknownN, state)
  1075         val unknown_outcome = (unknownN, state)
  1078         val deadline = Option.map (curry Time.+ (Time.now ())) timeout
  1076         val deadline = Time.+ (Time.now (), timeout)
  1079         val outcome as (outcome_code, _) =
  1077         val outcome as (outcome_code, _) =
  1080           time_limit (if debug orelse is_none timeout then NONE
  1078           TimeLimit.timeLimit (Time.+ (timeout, timeout_bonus))
  1081                       else SOME (Time.+ (the timeout, timeout_bonus)))
       
  1082               (pick_them_nits_in_term deadline state params mode i n step subst
  1079               (pick_them_nits_in_term deadline state params mode i n step subst
  1083                                       def_assm_ts nondef_assm_ts) orig_t
  1080                                       def_assm_ts nondef_assm_ts) orig_t
  1084           handle TOO_LARGE (_, details) =>
  1081           handle TOO_LARGE (_, details) =>
  1085                  (print_t "% SZS status Unknown";
  1082                  (print_t "% SZS status Unknown";
  1086                   print_nt ("Limit reached: " ^ details ^ "."); unknown_outcome)
  1083                   print_nt ("Limit reached: " ^ details ^ "."); unknown_outcome)