2014-07-14 19:32:44 +00:00
|
|
|
(*
|
|
|
|
* Copyright 2014, NICTA
|
|
|
|
*
|
|
|
|
* This software may be distributed and modified according to the terms of
|
|
|
|
* the BSD 2-Clause license. Note that NO WARRANTY is provided.
|
|
|
|
* See "LICENSE_BSD2.txt" for details.
|
|
|
|
*
|
|
|
|
* @TAG(NICTA_BSD)
|
|
|
|
*)
|
|
|
|
|
|
|
|
(* Miscellaneous Isabelle tools. *)
|
|
|
|
theory NICTATools
|
2017-07-12 05:13:51 +00:00
|
|
|
imports
|
2016-02-16 23:08:58 +00:00
|
|
|
Apply_Trace_Cmd
|
2017-02-15 03:46:39 +00:00
|
|
|
Apply_Debug
|
2018-02-21 15:22:35 +00:00
|
|
|
Find_Names
|
2016-06-21 18:55:45 +00:00
|
|
|
(* Solves_Tac *)
|
2015-07-08 06:59:40 +00:00
|
|
|
Rule_By_Method
|
2015-06-01 04:04:30 +00:00
|
|
|
Eisbach_Methods
|
2018-09-25 02:50:12 +00:00
|
|
|
TSubst
|
2018-04-27 06:42:47 +00:00
|
|
|
Time_Methods_Cmd
|
2018-09-18 10:41:28 +00:00
|
|
|
Try_Attribute
|
2018-08-07 04:29:43 +00:00
|
|
|
Trace_Schematic_Insts
|
2016-02-16 05:25:39 +00:00
|
|
|
Insulin
|
2016-02-16 05:31:14 +00:00
|
|
|
ShowTypes
|
2016-05-16 07:06:08 +00:00
|
|
|
AutoLevity_Hooks
|
2018-11-15 00:18:08 +00:00
|
|
|
Locale_Abbrev
|
2014-07-14 19:32:44 +00:00
|
|
|
begin
|
|
|
|
|
|
|
|
section "Detect unused meta-forall"
|
|
|
|
|
|
|
|
(*
|
|
|
|
* Detect meta-foralls that are unused in "lemma" statements,
|
|
|
|
* and warn the user about them.
|
|
|
|
*
|
|
|
|
* They can sometimes create weird issues, usually due to the
|
|
|
|
* fact that they have the empty sort "'a::{}", which confuses
|
|
|
|
* certain tools, such as "atomize".
|
|
|
|
*)
|
2019-06-05 10:18:48 +00:00
|
|
|
ML \<open>
|
2014-07-14 19:32:44 +00:00
|
|
|
|
|
|
|
(* Return a list of meta-forall variable names that appear
|
|
|
|
* to be unused in the input term. *)
|
2014-08-08 07:29:54 +00:00
|
|
|
fun find_unused_metaall (Const (@{const_name "Pure.all"}, _) $ Abs (n, _, t)) =
|
2014-07-14 19:32:44 +00:00
|
|
|
(if not (Term.is_dependent t) then [n] else []) @ find_unused_metaall t
|
|
|
|
| find_unused_metaall (Abs (_, _, t)) =
|
|
|
|
find_unused_metaall t
|
|
|
|
| find_unused_metaall (a $ b) =
|
|
|
|
find_unused_metaall a @ find_unused_metaall b
|
|
|
|
| find_unused_metaall _ = []
|
|
|
|
|
2015-04-17 15:19:32 +00:00
|
|
|
(* Given a proof state, analyse its assumptions for unused
|
2014-07-14 19:32:44 +00:00
|
|
|
* meta-foralls. *)
|
|
|
|
fun detect_unused_meta_forall _ (state : Proof.state) =
|
|
|
|
let
|
|
|
|
(* Fetch all assumptions and the main goal, and analyse them. *)
|
|
|
|
val {context = lthy, goal = goal, ...} = Proof.goal state
|
|
|
|
val checked_terms =
|
2015-04-17 15:19:32 +00:00
|
|
|
[Thm.concl_of goal] @ map Thm.term_of (Assumption.all_assms_of lthy)
|
2014-07-14 19:32:44 +00:00
|
|
|
val results = List.concat (map find_unused_metaall checked_terms)
|
|
|
|
|
|
|
|
(* Produce a message. *)
|
|
|
|
fun message results =
|
|
|
|
Pretty.paragraph [
|
|
|
|
Pretty.str "Unused meta-forall(s): ",
|
|
|
|
Pretty.commas
|
|
|
|
(map (fn b => Pretty.mark_str (Markup.bound, b)) results)
|
|
|
|
|> Pretty.paragraph,
|
|
|
|
Pretty.str "."
|
|
|
|
]
|
|
|
|
|
|
|
|
(* We use a warning instead of the standard mechanisms so that
|
2014-08-08 07:29:54 +00:00
|
|
|
* we can produce a "warning" icon in Isabelle/jEdit. *)
|
2014-07-14 19:32:44 +00:00
|
|
|
val _ =
|
|
|
|
if length results > 0 then
|
2016-01-12 03:58:16 +00:00
|
|
|
warning (message results |> Pretty.string_of)
|
2014-07-14 19:32:44 +00:00
|
|
|
else ()
|
|
|
|
in
|
2015-04-17 15:19:32 +00:00
|
|
|
(false, ("", []))
|
2014-07-14 19:32:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
(* Setup the tool, stealing the "auto_solve_direct" option. *)
|
|
|
|
val _ = Try.tool_setup ("unused_meta_forall",
|
2014-08-08 07:29:54 +00:00
|
|
|
(1, @{system_option auto_solve_direct}, detect_unused_meta_forall))
|
2019-06-05 10:18:48 +00:00
|
|
|
\<close>
|
2014-07-14 19:32:44 +00:00
|
|
|
|
|
|
|
lemma test_unused_meta_forall: "\<And>x. y \<or> \<not> y"
|
|
|
|
oops
|
|
|
|
|
|
|
|
end
|