| author | wenzelm | 
| Thu, 07 Apr 2016 13:35:08 +0200 | |
| changeset 62899 | 845ed4584e21 | 
| parent 62505 | 9e2a65912111 | 
| child 62983 | ba9072b303a2 | 
| permissions | -rw-r--r-- | 
| 54730 | 1 | (* Title: Pure/Tools/simplifier_trace.ML | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 2 | Author: Lars Hupel | 
| 54730 | 3 | |
| 4 | Interactive Simplifier trace. | |
| 5 | *) | |
| 6 | ||
| 7 | signature SIMPLIFIER_TRACE = | |
| 8 | sig | |
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 9 | val add_term_breakpoint: term -> Context.generic -> Context.generic | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 10 | val add_thm_breakpoint: thm -> Context.generic -> Context.generic | 
| 54730 | 11 | end | 
| 12 | ||
| 13 | structure Simplifier_Trace: SIMPLIFIER_TRACE = | |
| 14 | struct | |
| 15 | ||
| 55552 | 16 | (** context data **) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 17 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 18 | datatype mode = Disabled | Normal | Full | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 19 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 20 | fun merge_modes Disabled m = m | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 21 | | merge_modes Normal Full = Full | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 22 | | merge_modes Normal _ = Normal | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 23 | | merge_modes Full _ = Full | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 24 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 25 | val empty_breakpoints = | 
| 55560 | 26 | (Item_Net.init (op aconv) single, | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 27 | Item_Net.init eq_rrule (single o Thm.full_prop_of o #thm)) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 28 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 29 | fun merge_breakpoints ((term_bs1, thm_bs1), (term_bs2, thm_bs2)) = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 30 | (Item_Net.merge (term_bs1, term_bs2), | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 31 | Item_Net.merge (thm_bs1, thm_bs2)) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 32 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 33 | structure Data = Generic_Data | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 34 | ( | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 35 | type T = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 36 |     {max_depth: int,
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 37 | mode: mode, | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 38 | interactive: bool, | 
| 55390 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 39 | memory: bool, | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 40 | parent: int, | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 41 | breakpoints: term Item_Net.T * rrule Item_Net.T} | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 42 | val empty = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 43 |     {max_depth = 10,
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 44 | mode = Disabled, | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 45 | interactive = false, | 
| 55390 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 46 | memory = true, | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 47 | parent = 0, | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 48 | breakpoints = empty_breakpoints} | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 49 | val extend = I | 
| 55552 | 50 | fun merge | 
| 51 |     ({max_depth = max_depth1, mode = mode1, interactive = interactive1,
 | |
| 52 | memory = memory1, breakpoints = breakpoints1, ...}: T, | |
| 53 |      {max_depth = max_depth2, mode = mode2, interactive = interactive2,
 | |
| 54 | memory = memory2, breakpoints = breakpoints2, ...}: T) = | |
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 55 |     {max_depth = Int.max (max_depth1, max_depth2),
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 56 | mode = merge_modes mode1 mode2, | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 57 | interactive = interactive1 orelse interactive2, | 
| 55390 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 58 | memory = memory1 andalso memory2, | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 59 | parent = 0, | 
| 55335 | 60 | breakpoints = merge_breakpoints (breakpoints1, breakpoints2)}: T | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 61 | ) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 62 | |
| 57592 | 63 | val get_data = Data.get o Context.Proof | 
| 64 | val put_data = Context.proof_map o Data.put | |
| 65 | ||
| 66 | val get_breakpoints = #breakpoints o get_data | |
| 67 | ||
| 68 | fun map_breakpoints f = | |
| 55390 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 69 | Data.map | 
| 57592 | 70 |     (fn {max_depth, mode, interactive, parent, memory, breakpoints} =>
 | 
| 55390 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 71 |       {max_depth = max_depth,
 | 
| 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 72 | mode = mode, | 
| 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 73 | interactive = interactive, | 
| 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 74 | memory = memory, | 
| 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 75 | parent = parent, | 
| 57592 | 76 | breakpoints = f breakpoints}) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 77 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 78 | fun add_term_breakpoint term = | 
| 57592 | 79 | map_breakpoints (apfst (Item_Net.update term)) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 80 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 81 | fun add_thm_breakpoint thm context = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 82 | let | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 83 | val rrules = mk_rrules (Context.proof_of context) [thm] | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 84 | in | 
| 57592 | 85 | map_breakpoints (apsnd (fold Item_Net.update rrules)) context | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 86 | end | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 87 | |
| 57592 | 88 | fun check_breakpoint (term, rrule) ctxt = | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 89 | let | 
| 57592 | 90 | val thy = Proof_Context.theory_of ctxt | 
| 91 | val (term_bs, thm_bs) = get_breakpoints ctxt | |
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 92 | |
| 57592 | 93 | val term_matches = | 
| 94 | filter (fn pat => Pattern.matches thy (pat, term)) | |
| 95 | (Item_Net.retrieve_matching term_bs term) | |
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 96 | |
| 57592 | 97 | val thm_matches = | 
| 98 | exists (eq_rrule o pair rrule) | |
| 99 | (Item_Net.retrieve_matching thm_bs (Thm.full_prop_of (#thm rrule))) | |
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 100 | in | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 101 | (term_matches, thm_matches) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 102 | end | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 103 | |
| 55552 | 104 | |
| 105 | ||
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 106 | (** config and attributes **) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 107 | |
| 55390 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 108 | fun config raw_mode interactive max_depth memory = | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 109 | let | 
| 55552 | 110 | val mode = | 
| 111 | (case raw_mode of | |
| 112 | "normal" => Normal | |
| 113 | | "full" => Full | |
| 114 |       | _ => error ("Simplifier_Trace.config: unknown mode " ^ raw_mode))
 | |
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 115 | |
| 55946 | 116 |     val update = Data.map (fn {parent, breakpoints, ...} =>
 | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 117 |       {max_depth = max_depth,
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 118 | mode = mode, | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 119 | interactive = interactive, | 
| 55390 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 120 | memory = memory, | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 121 | parent = parent, | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 122 | breakpoints = breakpoints}) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 123 | in Thm.declaration_attribute (K update) end | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 124 | |
| 57041 
aceaca232177
consolidate "break_thm" and "break_term" attributes into "simp_break";
 Lars Hupel <lars.hupel@mytum.de> parents: 
56333diff
changeset | 125 | fun breakpoint terms = | 
| 
aceaca232177
consolidate "break_thm" and "break_term" attributes into "simp_break";
 Lars Hupel <lars.hupel@mytum.de> parents: 
56333diff
changeset | 126 | Thm.declaration_attribute (fn thm => add_thm_breakpoint thm o fold add_term_breakpoint terms) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 127 | |
| 55552 | 128 | |
| 129 | ||
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 130 | (** tracing state **) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 131 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 132 | val futures = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 133 | Synchronized.var "Simplifier_Trace.futures" (Inttab.empty: string future Inttab.table) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 134 | |
| 55552 | 135 | |
| 136 | ||
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 137 | (** markup **) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 138 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 139 | fun output_result (id, data) = | 
| 56333 
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
 wenzelm parents: 
55946diff
changeset | 140 | Output.result (Markup.serial_properties id) [data] | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 141 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 142 | val parentN = "parent" | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 143 | val textN = "text" | 
| 55390 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 144 | val memoryN = "memory" | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 145 | val successN = "success" | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 146 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 147 | type payload = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 148 |   {props: Properties.T,
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 149 | pretty: Pretty.T} | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 150 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 151 | fun empty_payload () : payload = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 152 |   {props = [], pretty = Pretty.str ""}
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 153 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 154 | fun mk_generic_result markup text triggered (payload : unit -> payload) ctxt = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 155 | let | 
| 57592 | 156 |     val {mode, interactive, memory, parent, ...} = get_data ctxt
 | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 157 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 158 | val eligible = | 
| 55552 | 159 | (case mode of | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 160 | Disabled => false | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 161 | | Normal => triggered | 
| 55552 | 162 | | Full => true) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 163 | |
| 55553 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55552diff
changeset | 164 | val markup' = | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55552diff
changeset | 165 | if markup = Markup.simp_trace_stepN andalso not interactive | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55552diff
changeset | 166 | then Markup.simp_trace_logN | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55552diff
changeset | 167 | else markup | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 168 | in | 
| 55946 | 169 | if not eligible then NONE | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 170 | else | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 171 | let | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 172 |         val {props = more_props, pretty} = payload ()
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 173 | val props = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 174 | [(textN, text), | 
| 55390 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 175 | (memoryN, Markup.print_bool memory), | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 176 | (parentN, Markup.print_int parent)] | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 177 | val data = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 178 | Pretty.string_of (Pretty.markup (markup', props @ more_props) [pretty]) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 179 | in | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 180 | SOME (serial (), data) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 181 | end | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 182 | end | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 183 | |
| 55552 | 184 | |
| 185 | ||
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 186 | (** tracing output **) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 187 | |
| 57594 
037f3b251df5
regular message to refer to Simplifier Trace panel (unused);
 wenzelm parents: 
57592diff
changeset | 188 | fun see_panel () = | 
| 
037f3b251df5
regular message to refer to Simplifier Trace panel (unused);
 wenzelm parents: 
57592diff
changeset | 189 | let | 
| 
037f3b251df5
regular message to refer to Simplifier Trace panel (unused);
 wenzelm parents: 
57592diff
changeset | 190 | val ((bg1, bg2), en) = | 
| 
037f3b251df5
regular message to refer to Simplifier Trace panel (unused);
 wenzelm parents: 
57592diff
changeset | 191 | YXML.output_markup_elem | 
| 
037f3b251df5
regular message to refer to Simplifier Trace panel (unused);
 wenzelm parents: 
57592diff
changeset | 192 |         (Active.make_markup Markup.simp_trace_panelN {implicit = false, properties = []})
 | 
| 57596 
3a1b1bda702f
refer to Simplifier Trace panel on first invocation;
 wenzelm parents: 
57594diff
changeset | 193 | in "See " ^ bg1 ^ bg2 ^ "simplifier trace" ^ en end | 
| 57594 
037f3b251df5
regular message to refer to Simplifier Trace panel (unused);
 wenzelm parents: 
57592diff
changeset | 194 | |
| 
037f3b251df5
regular message to refer to Simplifier Trace panel (unused);
 wenzelm parents: 
57592diff
changeset | 195 | |
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 196 | fun send_request (result_id, content) = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 197 | let | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 198 | fun break () = | 
| 56333 
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
 wenzelm parents: 
55946diff
changeset | 199 | (Output.protocol_message (Markup.simp_trace_cancel result_id) []; | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 200 | Synchronized.change futures (Inttab.delete_safe result_id)) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 201 | val promise = Future.promise break : string future | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 202 | in | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 203 | Synchronized.change futures (Inttab.update_new (result_id, promise)); | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 204 | output_result (result_id, content); | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 205 | promise | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 206 | end | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 207 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 208 | |
| 55335 | 209 | type data = {term: term, thm: thm, unconditional: bool, ctxt: Proof.context, rrule: rrule}
 | 
| 210 | ||
| 211 | fun step ({term, thm, unconditional, ctxt, rrule}: data) =
 | |
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 212 | let | 
| 57592 | 213 | val (matching_terms, thm_triggered) = check_breakpoint (term, rrule) ctxt | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 214 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 215 |     val {name, ...} = rrule
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 216 | val term_triggered = not (null matching_terms) | 
| 54730 | 217 | |
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 218 | val text = | 
| 55552 | 219 | if unconditional then "Apply rewrite rule?" | 
| 220 | else "Apply conditional rewrite rule?" | |
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 221 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 222 | fun payload () = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 223 | let | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 224 | (* FIXME pretty printing via Proof_Context.pretty_fact *) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 225 | val pretty_thm = Pretty.block | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 226 |           [Pretty.str ("Instance of " ^ name ^ ":"),
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 227 | Pretty.brk 1, | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 228 | Syntax.pretty_term ctxt (Thm.prop_of thm)] | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 229 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 230 | val pretty_term = Pretty.block | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 231 | [Pretty.str "Trying to rewrite:", | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 232 | Pretty.brk 1, | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 233 | Syntax.pretty_term ctxt term] | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 234 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 235 | val pretty_matchings = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 236 | let | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 237 | val items = map (Pretty.item o single o Syntax.pretty_term ctxt) matching_terms | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 238 | in | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 239 | if not (null matching_terms) then | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 240 | [Pretty.block (Pretty.fbreaks (Pretty.str "Matching terms:" :: items))] | 
| 55552 | 241 | else [] | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 242 | end | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 243 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 244 | val pretty = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 245 | Pretty.chunks ([pretty_thm, pretty_term] @ pretty_matchings) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 246 | in | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 247 |         {props = [], pretty = pretty}
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 248 | end | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 249 | |
| 57592 | 250 |     val {max_depth, mode, interactive, memory, breakpoints, ...} = get_data ctxt
 | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 251 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 252 | fun mk_promise result = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 253 | let | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 254 | val result_id = #1 result | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 255 | |
| 57592 | 256 | fun put mode' interactive' = put_data | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 257 |           {max_depth = max_depth,
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 258 | mode = mode', | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 259 | interactive = interactive', | 
| 55390 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 260 | memory = memory, | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 261 | parent = result_id, | 
| 57592 | 262 | breakpoints = breakpoints} ctxt | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 263 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 264 | fun to_response "skip" = NONE | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 265 | | to_response "continue" = SOME (put mode true) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 266 | | to_response "continue_trace" = SOME (put Full true) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 267 | | to_response "continue_passive" = SOME (put mode false) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 268 | | to_response "continue_disable" = SOME (put Disabled false) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 269 | | to_response _ = raise Fail "Simplifier_Trace.step: invalid message" | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 270 | in | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 271 | if not interactive then | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 272 | (output_result result; Future.value (SOME (put mode false))) | 
| 55552 | 273 | else Future.map to_response (send_request result) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 274 | end | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 275 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 276 | in | 
| 55553 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55552diff
changeset | 277 | (case mk_generic_result Markup.simp_trace_stepN text | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55552diff
changeset | 278 | (thm_triggered orelse term_triggered) payload ctxt of | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 279 | NONE => Future.value (SOME ctxt) | 
| 55552 | 280 | | SOME res => mk_promise res) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 281 | end | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 282 | |
| 55946 | 283 | fun recurse text depth term ctxt = | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 284 | let | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 285 | fun payload () = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 286 |       {props = [],
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 287 | pretty = Syntax.pretty_term ctxt term} | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 288 | |
| 57592 | 289 |     val {max_depth, mode, interactive, memory, breakpoints, ...} = get_data ctxt
 | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 290 | |
| 57592 | 291 | fun put result_id = put_data | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 292 |       {max_depth = max_depth,
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 293 | mode = if depth >= max_depth then Disabled else mode, | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 294 | interactive = interactive, | 
| 55390 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 295 | memory = memory, | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 296 | parent = result_id, | 
| 57592 | 297 | breakpoints = breakpoints} ctxt | 
| 298 | in | |
| 299 | (case mk_generic_result Markup.simp_trace_recurseN text true payload ctxt of | |
| 300 | NONE => put 0 | |
| 57596 
3a1b1bda702f
refer to Simplifier Trace panel on first invocation;
 wenzelm parents: 
57594diff
changeset | 301 | | SOME res => | 
| 
3a1b1bda702f
refer to Simplifier Trace panel on first invocation;
 wenzelm parents: 
57594diff
changeset | 302 | (if depth = 1 then writeln (see_panel ()) else (); | 
| 
3a1b1bda702f
refer to Simplifier Trace panel on first invocation;
 wenzelm parents: 
57594diff
changeset | 303 | output_result res; | 
| 
3a1b1bda702f
refer to Simplifier Trace panel on first invocation;
 wenzelm parents: 
57594diff
changeset | 304 | put (#1 res))) | 
| 57592 | 305 | end | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 306 | |
| 55335 | 307 | fun indicate_failure ({term, ctxt, thm, rrule, ...}: data) ctxt' =
 | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 308 | let | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 309 | fun payload () = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 310 | let | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 311 |         val {name, ...} = rrule
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 312 | val pretty_thm = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 313 | (* FIXME pretty printing via Proof_Context.pretty_fact *) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 314 | Pretty.block | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 315 |             [Pretty.str ("In an instance of " ^ name ^ ":"),
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 316 | Pretty.brk 1, | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 317 | Syntax.pretty_term ctxt (Thm.prop_of thm)] | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 318 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 319 | val pretty_term = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 320 | Pretty.block | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 321 | [Pretty.str "Was trying to rewrite:", | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 322 | Pretty.brk 1, | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 323 | Syntax.pretty_term ctxt term] | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 324 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 325 | val pretty = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 326 | Pretty.chunks [pretty_thm, pretty_term] | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 327 | in | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 328 |         {props = [(successN, "false")], pretty = pretty}
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 329 | end | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 330 | |
| 57592 | 331 |     val {interactive, ...} = get_data ctxt
 | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 332 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 333 | fun mk_promise result = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 334 | let | 
| 55552 | 335 | fun to_response "exit" = false | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 336 | | to_response "redo" = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 337 | (Option.app output_result | 
| 55553 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55552diff
changeset | 338 | (mk_generic_result Markup.simp_trace_ignoreN "Ignore" true empty_payload ctxt'); | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 339 | true) | 
| 55552 | 340 | | to_response _ = raise Fail "Simplifier_Trace.indicate_failure: invalid message" | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 341 | in | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 342 | if not interactive then | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 343 | (output_result result; Future.value false) | 
| 55552 | 344 | else Future.map to_response (send_request result) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 345 | end | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 346 | in | 
| 55553 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55552diff
changeset | 347 | (case mk_generic_result Markup.simp_trace_hintN "Step failed" true payload ctxt' of | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 348 | NONE => Future.value false | 
| 55552 | 349 | | SOME res => mk_promise res) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 350 | end | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 351 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 352 | fun indicate_success thm ctxt = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 353 | let | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 354 | fun payload () = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 355 |       {props = [(successN, "true")],
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 356 | pretty = Syntax.pretty_term ctxt (Thm.prop_of thm)} | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 357 | in | 
| 55553 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55552diff
changeset | 358 | Option.app output_result | 
| 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55552diff
changeset | 359 | (mk_generic_result Markup.simp_trace_hintN "Successfully rewrote" true payload ctxt) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 360 | end | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 361 | |
| 55552 | 362 | |
| 363 | ||
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 364 | (** setup **) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 365 | |
| 55390 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 366 | fun simp_apply args ctxt cont = | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 367 | let | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 368 |     val {unconditional: bool, term: term, thm: thm, rrule: rrule} = args
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 369 | val data = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 370 |       {term = term,
 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 371 | unconditional = unconditional, | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 372 | ctxt = ctxt, | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 373 | thm = thm, | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 374 | rrule = rrule} | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 375 | in | 
| 55552 | 376 | (case Future.join (step data) of | 
| 377 | NONE => NONE | |
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 378 | | SOME ctxt' => | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 379 | let val res = cont ctxt' in | 
| 55552 | 380 | (case res of | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 381 | NONE => | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 382 | if Future.join (indicate_failure data ctxt') then | 
| 55390 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 383 | simp_apply args ctxt cont | 
| 55552 | 384 | else NONE | 
| 385 | | SOME (thm, _) => (indicate_success thm ctxt'; res)) | |
| 386 | end) | |
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 387 | end | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 388 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 389 | val _ = Session.protocol_handler "isabelle.Simplifier_Trace$Handler" | 
| 54730 | 390 | |
| 391 | val _ = Theory.setup | |
| 54731 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54730diff
changeset | 392 | (Simplifier.set_trace_ops | 
| 55946 | 393 |     {trace_invoke = fn {depth, term} => recurse "Simplifier invoked" depth term,
 | 
| 55390 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 394 | trace_apply = simp_apply}) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 395 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 396 | val _ = | 
| 55553 
99409ccbe04a
more standard names for protocol and markup elements;
 wenzelm parents: 
55552diff
changeset | 397 | Isabelle_Process.protocol_command "Simplifier_Trace.reply" | 
| 60747 | 398 | (fn [serial_string, reply] => | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 399 | let | 
| 60747 | 400 | val serial = Markup.parse_int serial_string | 
| 401 | val result = | |
| 402 | Synchronized.change_result futures | |
| 403 | (fn tab => (Inttab.lookup tab serial, Inttab.delete_safe serial tab)) | |
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 404 | in | 
| 60747 | 405 | (case result of | 
| 406 | SOME promise => Future.fulfill promise reply | |
| 407 | | NONE => ()) (* FIXME handle protocol failure, just like in active.ML (!?) *) | |
| 62505 | 408 | end handle exn => if Exn.is_interrupt exn then () (*sic!*) else Exn.reraise exn) | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 409 | |
| 55552 | 410 | |
| 411 | ||
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 412 | (** attributes **) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 413 | |
| 55560 | 414 | val mode_parser = | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 415 | Scan.optional | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 416 | (Args.$$$ "mode" |-- Args.$$$ "=" |-- (Args.$$$ "normal" || Args.$$$ "full")) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 417 | "normal" | 
| 54730 | 418 | |
| 55560 | 419 | val interactive_parser = | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 420 | Scan.optional (Args.$$$ "interactive" >> K true) false | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 421 | |
| 55560 | 422 | val memory_parser = | 
| 55390 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 423 | Scan.optional (Args.$$$ "no_memory" >> K false) true | 
| 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 424 | |
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 425 | val depth_parser = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 426 | Scan.optional (Args.$$$ "depth" |-- Args.$$$ "=" |-- Parse.nat) 10 | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 427 | |
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 428 | val config_parser = | 
| 55390 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 429 | (interactive_parser -- mode_parser -- depth_parser -- memory_parser) >> | 
| 
36550a4eac5e
"no_memory" option for the simplifier trace to bypass memoization
 Lars Hupel <lars.hupel@mytum.de> parents: 
55335diff
changeset | 430 | (fn (((interactive, mode), depth), memory) => config mode interactive depth memory) | 
| 54730 | 431 | |
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 432 | val _ = Theory.setup | 
| 57041 
aceaca232177
consolidate "break_thm" and "break_term" attributes into "simp_break";
 Lars Hupel <lars.hupel@mytum.de> parents: 
56333diff
changeset | 433 |   (Attrib.setup @{binding simp_break}
 | 
| 
aceaca232177
consolidate "break_thm" and "break_term" attributes into "simp_break";
 Lars Hupel <lars.hupel@mytum.de> parents: 
56333diff
changeset | 434 | (Scan.repeat Args.term_pattern >> breakpoint) | 
| 
aceaca232177
consolidate "break_thm" and "break_term" attributes into "simp_break";
 Lars Hupel <lars.hupel@mytum.de> parents: 
56333diff
changeset | 435 | "declaration of a simplifier breakpoint" #> | 
| 57591 
8c095aef6769
clarified "simp_trace_new" and corresponding isar-ref section;
 wenzelm parents: 
57041diff
changeset | 436 |    Attrib.setup @{binding simp_trace_new} (Scan.lift config_parser)
 | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
54731diff
changeset | 437 | "simplifier trace configuration") | 
| 54730 | 438 | |
| 439 | end |