| author | wenzelm | 
| Tue, 31 Mar 2020 22:27:02 +0200 | |
| changeset 71639 | ec84f542e411 | 
| parent 71601 | 97ccf48c2f0c | 
| child 71666 | e15ca98ffbfe | 
| permissions | -rw-r--r-- | 
| 
68308
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
1  | 
/* Title: Pure/Tools/dump.scala  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
2  | 
Author: Makarius  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
3  | 
|
| 68348 | 4  | 
Dump cumulative PIDE session database.  | 
| 
68308
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
5  | 
*/  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
6  | 
|
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
7  | 
package isabelle  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
8  | 
|
| 71534 | 9  | 
import java.io.{BufferedWriter, FileOutputStream, OutputStreamWriter}
 | 
10  | 
||
| 
68308
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
11  | 
|
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
12  | 
object Dump  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
13  | 
{
 | 
| 68316 | 14  | 
/* aspects */  | 
15  | 
||
16  | 
sealed case class Aspect_Args(  | 
|
| 68355 | 17  | 
options: Options,  | 
| 
70640
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
18  | 
deps: Sessions.Deps,  | 
| 68355 | 19  | 
progress: Progress,  | 
| 69896 | 20  | 
output_dir: Path,  | 
| 68929 | 21  | 
snapshot: Document.Snapshot,  | 
| 69534 | 22  | 
status: Document_Status.Node_Status)  | 
| 68319 | 23  | 
  {
 | 
| 71534 | 24  | 
def write_path(file_name: Path): Path =  | 
| 68319 | 25  | 
    {
 | 
| 68929 | 26  | 
val path = output_dir + Path.basic(snapshot.node_name.theory) + file_name  | 
| 68319 | 27  | 
Isabelle_System.mkdirs(path.dir)  | 
| 71534 | 28  | 
path  | 
| 68319 | 29  | 
}  | 
30  | 
||
| 71534 | 31  | 
def write(file_name: Path, bytes: Bytes): Unit =  | 
32  | 
Bytes.write(write_path(file_name), bytes)  | 
|
33  | 
||
| 68365 | 34  | 
def write(file_name: Path, text: String): Unit =  | 
35  | 
write(file_name, Bytes(text))  | 
|
| 68332 | 36  | 
|
| 68365 | 37  | 
def write(file_name: Path, body: XML.Body): Unit =  | 
| 71534 | 38  | 
using(File.writer(write_path(file_name).file))(  | 
39  | 
writer => YXML.traversal(s => writer.write(Symbol.encode(s)), body))  | 
|
| 68319 | 40  | 
}  | 
| 68316 | 41  | 
|
| 68347 | 42  | 
sealed case class Aspect(name: String, description: String, operation: Aspect_Args => Unit,  | 
43  | 
options: List[String] = Nil)  | 
|
| 68345 | 44  | 
  {
 | 
45  | 
override def toString: String = name  | 
|
46  | 
}  | 
|
| 68316 | 47  | 
|
| 69521 | 48  | 
val known_aspects: List[Aspect] =  | 
| 68316 | 49  | 
List(  | 
| 68365 | 50  | 
      Aspect("markup", "PIDE markup (YXML format)",
 | 
51  | 
        { case args =>
 | 
|
52  | 
            args.write(Path.explode("markup.yxml"),
 | 
|
53  | 
args.snapshot.markup_to_XML(Text.Range.full, Markup.Elements.full))  | 
|
54  | 
}),  | 
|
| 68319 | 55  | 
      Aspect("messages", "output messages (YXML format)",
 | 
56  | 
        { case args =>
 | 
|
| 68365 | 57  | 
            args.write(Path.explode("messages.yxml"),
 | 
58  | 
args.snapshot.messages.iterator.map(_._1).toList)  | 
|
| 68347 | 59  | 
}),  | 
60  | 
      Aspect("latex", "generated LaTeX source",
 | 
|
61  | 
        { case args =>
 | 
|
| 68365 | 62  | 
for (entry <- args.snapshot.exports if entry.name == "document.tex")  | 
63  | 
args.write(Path.explode(entry.name), entry.uncompressed())  | 
|
| 
69533
 
1d2e6a4e073f
clarified options: ensure consolidated Node_Status and thus percentage = 100% for progress;
 
wenzelm 
parents: 
69532 
diff
changeset
 | 
64  | 
        }, options = List("export_document")),
 | 
| 68347 | 65  | 
      Aspect("theory", "foundational theory content",
 | 
66  | 
        { case args =>
 | 
|
67  | 
            for {
 | 
|
| 68365 | 68  | 
entry <- args.snapshot.exports  | 
| 68347 | 69  | 
if entry.name.startsWith(Export_Theory.export_prefix)  | 
| 68365 | 70  | 
} args.write(Path.explode(entry.name), entry.uncompressed())  | 
| 
69533
 
1d2e6a4e073f
clarified options: ensure consolidated Node_Status and thus percentage = 100% for progress;
 
wenzelm 
parents: 
69532 
diff
changeset
 | 
71  | 
        }, options = List("export_theory"))
 | 
| 68345 | 72  | 
).sortBy(_.name)  | 
| 68316 | 73  | 
|
74  | 
def show_aspects: String =  | 
|
| 68345 | 75  | 
cat_lines(known_aspects.map(aspect => aspect.name + " - " + aspect.description))  | 
| 68316 | 76  | 
|
77  | 
def the_aspect(name: String): Aspect =  | 
|
78  | 
known_aspects.find(aspect => aspect.name == name) getOrElse  | 
|
79  | 
      error("Unknown aspect " + quote(name))
 | 
|
80  | 
||
81  | 
||
| 
70856
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
82  | 
/* context and session */  | 
| 
69538
 
faf547d2834c
clarified signature, notably cascade of dump_options, deps, resources, session;
 
wenzelm 
parents: 
69537 
diff
changeset
 | 
83  | 
|
| 69896 | 84  | 
sealed case class Args(  | 
| 69897 | 85  | 
session: Headless.Session,  | 
86  | 
snapshot: Document.Snapshot,  | 
|
87  | 
status: Document_Status.Node_Status)  | 
|
| 69896 | 88  | 
  {
 | 
89  | 
def print_node: String = snapshot.node_name.toString  | 
|
| 
70640
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
90  | 
}  | 
| 69896 | 91  | 
|
| 
70856
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
92  | 
object Context  | 
| 
70640
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
93  | 
  {
 | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
94  | 
def apply(  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
95  | 
options: Options,  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
96  | 
aspects: List[Aspect] = Nil,  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
97  | 
progress: Progress = No_Progress,  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
98  | 
dirs: List[Path] = Nil,  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
99  | 
select_dirs: List[Path] = Nil,  | 
| 
71161
 
ffccc1f346ae
avoid vacuous session Pure -- dump does not read_pure_theory;
 
wenzelm 
parents: 
71159 
diff
changeset
 | 
100  | 
selection: Sessions.Selection = Sessions.Selection.empty,  | 
| 
71573
 
c67076c07fb8
avoid accidental update of base session sources (following documentation in "system" manual);
 
wenzelm 
parents: 
71534 
diff
changeset
 | 
101  | 
pure_base: Boolean = false,  | 
| 
 
c67076c07fb8
avoid accidental update of base session sources (following documentation in "system" manual);
 
wenzelm 
parents: 
71534 
diff
changeset
 | 
102  | 
skip_base: Boolean = false): Context =  | 
| 
70640
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
103  | 
    {
 | 
| 
70856
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
104  | 
val session_options: Options =  | 
| 
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
105  | 
      {
 | 
| 
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
106  | 
val options0 = if (NUMA.enabled) NUMA.policy_options(options) else options  | 
| 
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
107  | 
val options1 =  | 
| 
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
108  | 
options0 +  | 
| 
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
109  | 
"completion_limit=0" +  | 
| 
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
110  | 
"ML_statistics=false" +  | 
| 
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
111  | 
"parallel_proofs=0" +  | 
| 
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
112  | 
"editor_tracing_messages=0" +  | 
| 
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
113  | 
"editor_presentation"  | 
| 
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
114  | 
        (options1 /: aspects)({ case (opts, aspect) => (opts /: aspect.options)(_ + _) })
 | 
| 
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
115  | 
}  | 
| 
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
116  | 
|
| 70869 | 117  | 
val sessions_structure: Sessions.Structure =  | 
| 
70856
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
118  | 
Sessions.load_structure(session_options, dirs = dirs, select_dirs = select_dirs).  | 
| 70869 | 119  | 
selection(selection)  | 
120  | 
||
121  | 
      {
 | 
|
122  | 
val selection_size = sessions_structure.build_graph.size  | 
|
123  | 
        if (selection_size > 1) progress.echo("Loading " + selection_size + " sessions ...")
 | 
|
124  | 
}  | 
|
125  | 
||
126  | 
val deps: Sessions.Deps =  | 
|
127  | 
Sessions.deps(sessions_structure, progress = progress).check_errors  | 
|
| 
70856
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
128  | 
|
| 
71573
 
c67076c07fb8
avoid accidental update of base session sources (following documentation in "system" manual);
 
wenzelm 
parents: 
71534 
diff
changeset
 | 
129  | 
new Context(options, progress, dirs, select_dirs, pure_base, skip_base, session_options, deps)  | 
| 
70640
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
130  | 
}  | 
| 69896 | 131  | 
}  | 
132  | 
||
| 
70856
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
133  | 
class Context private(  | 
| 
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
134  | 
val options: Options,  | 
| 
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
135  | 
val progress: Progress,  | 
| 
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
136  | 
val dirs: List[Path],  | 
| 
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
137  | 
val select_dirs: List[Path],  | 
| 
71161
 
ffccc1f346ae
avoid vacuous session Pure -- dump does not read_pure_theory;
 
wenzelm 
parents: 
71159 
diff
changeset
 | 
138  | 
val pure_base: Boolean,  | 
| 
71573
 
c67076c07fb8
avoid accidental update of base session sources (following documentation in "system" manual);
 
wenzelm 
parents: 
71534 
diff
changeset
 | 
139  | 
val skip_base: Boolean,  | 
| 
70856
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
140  | 
val session_options: Options,  | 
| 
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
141  | 
val deps: Sessions.Deps)  | 
| 
69538
 
faf547d2834c
clarified signature, notably cascade of dump_options, deps, resources, session;
 
wenzelm 
parents: 
69537 
diff
changeset
 | 
142  | 
  {
 | 
| 
70859
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
143  | 
context =>  | 
| 
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
144  | 
|
| 
70856
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
145  | 
def session_dirs: List[Path] = dirs ::: select_dirs  | 
| 68926 | 146  | 
|
| 70857 | 147  | 
def build_logic(logic: String)  | 
148  | 
    {
 | 
|
149  | 
Build.build_logic(options, logic, build_heap = true, progress = progress,  | 
|
150  | 
dirs = session_dirs, strict = true)  | 
|
151  | 
}  | 
|
152  | 
||
| 70864 | 153  | 
def sessions(  | 
| 
70859
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
154  | 
logic: String = default_logic,  | 
| 70861 | 155  | 
log: Logger = No_Logger): List[Session] =  | 
| 
70859
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
156  | 
    {
 | 
| 70869 | 157  | 
/* partitions */  | 
158  | 
||
159  | 
def session_info(session_name: String): Sessions.Info =  | 
|
160  | 
deps.sessions_structure(session_name)  | 
|
161  | 
||
| 
70870
 
877fe56af178
proper build_graph to make session selection work as in "isabelle build";
 
wenzelm 
parents: 
70869 
diff
changeset
 | 
162  | 
val session_graph = deps.sessions_structure.build_graph  | 
| 70869 | 163  | 
val all_sessions = session_graph.topological_order  | 
| 
70859
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
164  | 
|
| 
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
165  | 
val afp_sessions =  | 
| 70869 | 166  | 
(for (name <- all_sessions if session_info(name).is_afp) yield name).toSet  | 
| 
70859
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
167  | 
|
| 
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
168  | 
val afp_bulky_sessions =  | 
| 70869 | 169  | 
(for (name <- all_sessions if session_info(name).is_afp_bulky) yield name).toList  | 
| 
70859
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
170  | 
|
| 70862 | 171  | 
val base_sessions =  | 
172  | 
session_graph.all_preds(List(logic).filter(session_graph.defined)).reverse  | 
|
| 
70859
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
173  | 
|
| 70869 | 174  | 
val proof_sessions =  | 
175  | 
session_graph.all_succs(  | 
|
176  | 
for (name <- all_sessions if session_info(name).record_proofs) yield name)  | 
|
177  | 
||
178  | 
||
179  | 
/* resulting sessions */  | 
|
180  | 
||
181  | 
def make_session(  | 
|
182  | 
selected_sessions: List[String],  | 
|
| 71158 | 183  | 
session_logic: String = logic,  | 
| 71159 | 184  | 
strict: Boolean = false,  | 
| 70869 | 185  | 
record_proofs: Boolean = false): List[Session] =  | 
186  | 
      {
 | 
|
| 71159 | 187  | 
if (selected_sessions.isEmpty && !strict) Nil  | 
| 71158 | 188  | 
else List(new Session(context, session_logic, log, selected_sessions, record_proofs))  | 
| 70869 | 189  | 
}  | 
190  | 
||
| 
71161
 
ffccc1f346ae
avoid vacuous session Pure -- dump does not read_pure_theory;
 
wenzelm 
parents: 
71159 
diff
changeset
 | 
191  | 
val PURE = isabelle.Thy_Header.PURE  | 
| 
 
ffccc1f346ae
avoid vacuous session Pure -- dump does not read_pure_theory;
 
wenzelm 
parents: 
71159 
diff
changeset
 | 
192  | 
|
| 
70859
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
193  | 
val base =  | 
| 
71573
 
c67076c07fb8
avoid accidental update of base session sources (following documentation in "system" manual);
 
wenzelm 
parents: 
71534 
diff
changeset
 | 
194  | 
if ((logic == PURE && !pure_base) || skip_base) Nil  | 
| 
71161
 
ffccc1f346ae
avoid vacuous session Pure -- dump does not read_pure_theory;
 
wenzelm 
parents: 
71159 
diff
changeset
 | 
195  | 
else make_session(base_sessions, session_logic = PURE, strict = logic == PURE)  | 
| 
70859
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
196  | 
|
| 
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
197  | 
val main =  | 
| 70869 | 198  | 
make_session(  | 
| 
70859
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
199  | 
session_graph.topological_order.filterNot(name =>  | 
| 70869 | 200  | 
afp_sessions.contains(name) ||  | 
201  | 
base_sessions.contains(name) ||  | 
|
202  | 
proof_sessions.contains(name)))  | 
|
203  | 
||
| 
71161
 
ffccc1f346ae
avoid vacuous session Pure -- dump does not read_pure_theory;
 
wenzelm 
parents: 
71159 
diff
changeset
 | 
204  | 
val proofs = make_session(proof_sessions, session_logic = PURE, record_proofs = true)  | 
| 
70859
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
205  | 
|
| 
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
206  | 
val afp =  | 
| 
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
207  | 
if (afp_sessions.isEmpty) Nil  | 
| 
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
208  | 
        else {
 | 
| 
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
209  | 
val (part1, part2) =  | 
| 
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
210  | 
          {
 | 
| 
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
211  | 
val graph = session_graph.restrict(afp_sessions -- afp_bulky_sessions)  | 
| 70862 | 212  | 
val force_partition1 = AFP.force_partition1.filter(graph.defined)  | 
| 
70859
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
213  | 
val force_part1 = graph.all_preds(graph.all_succs(force_partition1)).toSet  | 
| 
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
214  | 
graph.keys.partition(a => force_part1(a) || graph.is_isolated(a))  | 
| 
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
215  | 
}  | 
| 70869 | 216  | 
List(part1, part2, afp_bulky_sessions).flatMap(make_session(_))  | 
| 
70859
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
217  | 
}  | 
| 
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
218  | 
|
| 
70874
 
2010397f7c9a
load HOL-Proofs first: it introduces some extra "thm" items that are required later on;
 
wenzelm 
parents: 
70871 
diff
changeset
 | 
219  | 
proofs ::: base ::: main ::: afp  | 
| 70857 | 220  | 
}  | 
| 
70875
 
a62c34770df9
proper guard for process_theory: ensure uniform precedence of results;
 
wenzelm 
parents: 
70874 
diff
changeset
 | 
221  | 
|
| 
 
a62c34770df9
proper guard for process_theory: ensure uniform precedence of results;
 
wenzelm 
parents: 
70874 
diff
changeset
 | 
222  | 
|
| 
 
a62c34770df9
proper guard for process_theory: ensure uniform precedence of results;
 
wenzelm 
parents: 
70874 
diff
changeset
 | 
223  | 
/* processed theories */  | 
| 
 
a62c34770df9
proper guard for process_theory: ensure uniform precedence of results;
 
wenzelm 
parents: 
70874 
diff
changeset
 | 
224  | 
|
| 
 
a62c34770df9
proper guard for process_theory: ensure uniform precedence of results;
 
wenzelm 
parents: 
70874 
diff
changeset
 | 
225  | 
private val processed_theories = Synchronized(Set.empty[String])  | 
| 
 
a62c34770df9
proper guard for process_theory: ensure uniform precedence of results;
 
wenzelm 
parents: 
70874 
diff
changeset
 | 
226  | 
|
| 
 
a62c34770df9
proper guard for process_theory: ensure uniform precedence of results;
 
wenzelm 
parents: 
70874 
diff
changeset
 | 
227  | 
def process_theory(theory: String): Boolean =  | 
| 
 
a62c34770df9
proper guard for process_theory: ensure uniform precedence of results;
 
wenzelm 
parents: 
70874 
diff
changeset
 | 
228  | 
processed_theories.change_result(processed => (!processed(theory), processed + theory))  | 
| 70876 | 229  | 
|
230  | 
||
231  | 
/* errors */  | 
|
232  | 
||
233  | 
private val errors = Synchronized(List.empty[String])  | 
|
234  | 
||
235  | 
def add_errors(more_errs: List[String])  | 
|
236  | 
    {
 | 
|
237  | 
errors.change(errs => errs ::: more_errs)  | 
|
238  | 
}  | 
|
239  | 
||
240  | 
def check_errors  | 
|
241  | 
    {
 | 
|
242  | 
val errs = errors.value  | 
|
243  | 
      if (errs.nonEmpty) error(errs.mkString("\n\n"))
 | 
|
244  | 
}  | 
|
| 
70856
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
245  | 
}  | 
| 68926 | 246  | 
|
| 
70859
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
247  | 
class Session private[Dump](  | 
| 70867 | 248  | 
val context: Context,  | 
249  | 
val logic: String,  | 
|
250  | 
log: Logger,  | 
|
| 70869 | 251  | 
selected_sessions: List[String],  | 
252  | 
record_proofs: Boolean)  | 
|
| 
70856
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
253  | 
  {
 | 
| 
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
254  | 
/* resources */  | 
| 
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
255  | 
|
| 70869 | 256  | 
val options: Options =  | 
257  | 
if (record_proofs) context.session_options + "record_proofs=2"  | 
|
258  | 
else context.session_options  | 
|
| 70866 | 259  | 
|
| 70867 | 260  | 
private def deps = context.deps  | 
261  | 
private def progress = context.progress  | 
|
| 
70856
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
262  | 
|
| 
70640
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
263  | 
val resources: Headless.Resources =  | 
| 70865 | 264  | 
Headless.Resources.make(options, logic, progress = progress, log = log,  | 
| 
70856
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
265  | 
session_dirs = context.session_dirs,  | 
| 70867 | 266  | 
include_sessions = deps.sessions_structure.imports_topological_order)  | 
| 
70640
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
267  | 
|
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
268  | 
val used_theories: List[Document.Node.Name] =  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
269  | 
    {
 | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
270  | 
      for {
 | 
| 70867 | 271  | 
session_name <-  | 
| 
70871
 
2beac4adc565
more complete coverage of sessions: process_theory operation needs to handle duplicate theories;
 
wenzelm 
parents: 
70870 
diff
changeset
 | 
272  | 
deps.sessions_structure.build_graph.restrict(selected_sessions.toSet).topological_order  | 
| 70867 | 273  | 
(name, theory_options) <- deps(session_name).used_theories  | 
| 
70640
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
274  | 
if !resources.session_base.loaded_theory(name.theory)  | 
| 70867 | 275  | 
        if {
 | 
276  | 
def warn(msg: String): Unit =  | 
|
277  | 
            progress.echo_warning("Skipping theory " + name + "  (" + msg + ")")
 | 
|
278  | 
||
279  | 
val conditions =  | 
|
280  | 
            space_explode(',', theory_options.string("condition")).
 | 
|
281  | 
filter(cond => Isabelle_System.getenv(cond) == "")  | 
|
282  | 
          if (conditions.nonEmpty) {
 | 
|
283  | 
            warn("undefined " + conditions.mkString(", "))
 | 
|
284  | 
false  | 
|
285  | 
}  | 
|
286  | 
          else if (options.bool("skip_proofs") && !theory_options.bool("skip_proofs")) {
 | 
|
287  | 
            warn("option skip_proofs")
 | 
|
288  | 
false  | 
|
289  | 
}  | 
|
290  | 
else true  | 
|
291  | 
}  | 
|
| 
70640
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
292  | 
} yield name  | 
| 68926 | 293  | 
}  | 
294  | 
||
295  | 
||
| 
70856
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
296  | 
/* process */  | 
| 
70640
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
297  | 
|
| 
70856
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
298  | 
def process(process_theory: Args => Unit, unicode_symbols: Boolean = false)  | 
| 
70640
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
299  | 
    {
 | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
300  | 
val session = resources.start_session(progress = progress)  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
301  | 
|
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
302  | 
|
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
303  | 
// asynchronous consumer  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
304  | 
|
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
305  | 
object Consumer  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
306  | 
      {
 | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
307  | 
sealed case class Bad_Theory(  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
308  | 
name: Document.Node.Name,  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
309  | 
status: Document_Status.Node_Status,  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
310  | 
errors: List[String])  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
311  | 
|
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
312  | 
private val consumer_bad_theories = Synchronized(List.empty[Bad_Theory])  | 
| 68318 | 313  | 
|
| 
70640
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
314  | 
private val consumer =  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
315  | 
Consumer_Thread.fork(name = "dump")(  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
316  | 
consume = (args: (Document.Snapshot, Document_Status.Node_Status)) =>  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
317  | 
              {
 | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
318  | 
val (snapshot, status) = args  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
319  | 
val name = snapshot.node_name  | 
| 
70871
 
2beac4adc565
more complete coverage of sessions: process_theory operation needs to handle duplicate theories;
 
wenzelm 
parents: 
70870 
diff
changeset
 | 
320  | 
                if (status.ok) {
 | 
| 
70875
 
a62c34770df9
proper guard for process_theory: ensure uniform precedence of results;
 
wenzelm 
parents: 
70874 
diff
changeset
 | 
321  | 
                  try {
 | 
| 
 
a62c34770df9
proper guard for process_theory: ensure uniform precedence of results;
 
wenzelm 
parents: 
70874 
diff
changeset
 | 
322  | 
                    if (context.process_theory(name.theory)) {
 | 
| 
 
a62c34770df9
proper guard for process_theory: ensure uniform precedence of results;
 
wenzelm 
parents: 
70874 
diff
changeset
 | 
323  | 
process_theory(Args(session, snapshot, status))  | 
| 
 
a62c34770df9
proper guard for process_theory: ensure uniform precedence of results;
 
wenzelm 
parents: 
70874 
diff
changeset
 | 
324  | 
}  | 
| 
 
a62c34770df9
proper guard for process_theory: ensure uniform precedence of results;
 
wenzelm 
parents: 
70874 
diff
changeset
 | 
325  | 
}  | 
| 
70871
 
2beac4adc565
more complete coverage of sessions: process_theory operation needs to handle duplicate theories;
 
wenzelm 
parents: 
70870 
diff
changeset
 | 
326  | 
                  catch {
 | 
| 
 
2beac4adc565
more complete coverage of sessions: process_theory operation needs to handle duplicate theories;
 
wenzelm 
parents: 
70870 
diff
changeset
 | 
327  | 
case exn: Throwable if !Exn.is_interrupt(exn) =>  | 
| 
 
2beac4adc565
more complete coverage of sessions: process_theory operation needs to handle duplicate theories;
 
wenzelm 
parents: 
70870 
diff
changeset
 | 
328  | 
val msg = Exn.message(exn)  | 
| 
 
2beac4adc565
more complete coverage of sessions: process_theory operation needs to handle duplicate theories;
 
wenzelm 
parents: 
70870 
diff
changeset
 | 
329  | 
                      progress.echo("FAILED to process theory " + name)
 | 
| 
 
2beac4adc565
more complete coverage of sessions: process_theory operation needs to handle duplicate theories;
 
wenzelm 
parents: 
70870 
diff
changeset
 | 
330  | 
progress.echo_error_message(msg)  | 
| 
 
2beac4adc565
more complete coverage of sessions: process_theory operation needs to handle duplicate theories;
 
wenzelm 
parents: 
70870 
diff
changeset
 | 
331  | 
consumer_bad_theories.change(Bad_Theory(name, status, List(msg)) :: _)  | 
| 
70640
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
332  | 
}  | 
| 
70871
 
2beac4adc565
more complete coverage of sessions: process_theory operation needs to handle duplicate theories;
 
wenzelm 
parents: 
70870 
diff
changeset
 | 
333  | 
}  | 
| 
 
2beac4adc565
more complete coverage of sessions: process_theory operation needs to handle duplicate theories;
 
wenzelm 
parents: 
70870 
diff
changeset
 | 
334  | 
                else {
 | 
| 
 
2beac4adc565
more complete coverage of sessions: process_theory operation needs to handle duplicate theories;
 
wenzelm 
parents: 
70870 
diff
changeset
 | 
335  | 
val msgs =  | 
| 
 
2beac4adc565
more complete coverage of sessions: process_theory operation needs to handle duplicate theories;
 
wenzelm 
parents: 
70870 
diff
changeset
 | 
336  | 
for ((tree, pos) <- snapshot.messages if Protocol.is_error(tree))  | 
| 
 
2beac4adc565
more complete coverage of sessions: process_theory operation needs to handle duplicate theories;
 
wenzelm 
parents: 
70870 
diff
changeset
 | 
337  | 
                    yield {
 | 
| 
 
2beac4adc565
more complete coverage of sessions: process_theory operation needs to handle duplicate theories;
 
wenzelm 
parents: 
70870 
diff
changeset
 | 
338  | 
"Error" + Position.here(pos) + ":\n" +  | 
| 
 
2beac4adc565
more complete coverage of sessions: process_theory operation needs to handle duplicate theories;
 
wenzelm 
parents: 
70870 
diff
changeset
 | 
339  | 
XML.content(Pretty.formatted(List(tree)))  | 
| 
 
2beac4adc565
more complete coverage of sessions: process_theory operation needs to handle duplicate theories;
 
wenzelm 
parents: 
70870 
diff
changeset
 | 
340  | 
}  | 
| 
 
2beac4adc565
more complete coverage of sessions: process_theory operation needs to handle duplicate theories;
 
wenzelm 
parents: 
70870 
diff
changeset
 | 
341  | 
                  progress.echo("FAILED to process theory " + name)
 | 
| 
 
2beac4adc565
more complete coverage of sessions: process_theory operation needs to handle duplicate theories;
 
wenzelm 
parents: 
70870 
diff
changeset
 | 
342  | 
msgs.foreach(progress.echo_error_message)  | 
| 
 
2beac4adc565
more complete coverage of sessions: process_theory operation needs to handle duplicate theories;
 
wenzelm 
parents: 
70870 
diff
changeset
 | 
343  | 
consumer_bad_theories.change(Bad_Theory(name, status, msgs) :: _)  | 
| 
70640
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
344  | 
}  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
345  | 
true  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
346  | 
})  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
347  | 
|
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
348  | 
def apply(snapshot: Document.Snapshot, status: Document_Status.Node_Status): Unit =  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
349  | 
consumer.send((snapshot, status))  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
350  | 
|
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
351  | 
def shutdown(): List[Bad_Theory] =  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
352  | 
        {
 | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
353  | 
consumer.shutdown()  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
354  | 
consumer_bad_theories.value.reverse  | 
| 
70634
 
0f8742b5a9e8
more scalable isabelle dump (and derivatives): mark individual theories to share common data in ML;
 
wenzelm 
parents: 
70626 
diff
changeset
 | 
355  | 
}  | 
| 
 
0f8742b5a9e8
more scalable isabelle dump (and derivatives): mark individual theories to share common data in ML;
 
wenzelm 
parents: 
70626 
diff
changeset
 | 
356  | 
}  | 
| 
 
0f8742b5a9e8
more scalable isabelle dump (and derivatives): mark individual theories to share common data in ML;
 
wenzelm 
parents: 
70626 
diff
changeset
 | 
357  | 
|
| 
70640
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
358  | 
|
| 
70653
 
f7c5b30fc432
load theories in stages, to reduce ML heap requirements;
 
wenzelm 
parents: 
70645 
diff
changeset
 | 
359  | 
// synchronous body  | 
| 
68320
 
1d33697199c1
shutdown ML process before output: Theories_Result is timeless/stateless;
 
wenzelm 
parents: 
68319 
diff
changeset
 | 
360  | 
|
| 
70640
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
361  | 
      try {
 | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
362  | 
val use_theories_result =  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
363  | 
session.use_theories(used_theories.map(_.theory),  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
364  | 
unicode_symbols = unicode_symbols,  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
365  | 
progress = progress,  | 
| 71601 | 366  | 
commit = Some(Consumer.apply))  | 
| 
70640
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
367  | 
|
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
368  | 
val bad_theories = Consumer.shutdown()  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
369  | 
val bad_msgs =  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
370  | 
bad_theories.map(bad =>  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
371  | 
Output.clean_yxml(  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
372  | 
"FAILED theory " + bad.name +  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
373  | 
(if (bad.status.consolidated) "" else ": " + bad.status.percentage + "% finished") +  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
374  | 
                (if (bad.errors.isEmpty) "" else bad.errors.mkString("\n", "\n", ""))))
 | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
375  | 
|
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
376  | 
val pending_msgs =  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
377  | 
          use_theories_result.nodes_pending match {
 | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
378  | 
case Nil => Nil  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
379  | 
            case pending => List("Pending theories: " + commas(pending.map(p => p._1.toString)))
 | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
380  | 
}  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
381  | 
|
| 70876 | 382  | 
context.add_errors(bad_msgs ::: pending_msgs)  | 
| 
70640
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
383  | 
}  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
384  | 
      finally { session.stop() }
 | 
| 
69032
 
90bb4cabe1e8
clarified errors: no result from forced session.stop, check pending theories;
 
wenzelm 
parents: 
69026 
diff
changeset
 | 
385  | 
}  | 
| 
68308
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
386  | 
}  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
387  | 
|
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
388  | 
|
| 69523 | 389  | 
/* dump */  | 
390  | 
||
391  | 
  val default_output_dir: Path = Path.explode("dump")
 | 
|
| 70858 | 392  | 
val default_logic: String = Thy_Header.PURE  | 
| 69523 | 393  | 
|
| 
70640
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
394  | 
def dump(  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
395  | 
options: Options,  | 
| 
 
5f4b8a505090
more explicit type Dump.Session, with context information;
 
wenzelm 
parents: 
70634 
diff
changeset
 | 
396  | 
logic: String,  | 
| 69523 | 397  | 
aspects: List[Aspect] = Nil,  | 
398  | 
progress: Progress = No_Progress,  | 
|
399  | 
log: Logger = No_Logger,  | 
|
400  | 
dirs: List[Path] = Nil,  | 
|
401  | 
select_dirs: List[Path] = Nil,  | 
|
402  | 
output_dir: Path = default_output_dir,  | 
|
| 69535 | 403  | 
selection: Sessions.Selection = Sessions.Selection.empty)  | 
| 69523 | 404  | 
  {
 | 
| 
70856
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
405  | 
val context =  | 
| 
 
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
 
wenzelm 
parents: 
70796 
diff
changeset
 | 
406  | 
Context(options, aspects = aspects, progress = progress, dirs = dirs,  | 
| 
70796
 
2739631ac368
discontinued pointless dump_checkpoint and share_common_data -- superseded by base logic image in Isabelle/MMT;
 
wenzelm 
parents: 
70779 
diff
changeset
 | 
407  | 
select_dirs = select_dirs, selection = selection)  | 
| 69523 | 408  | 
|
| 70864 | 409  | 
context.build_logic(logic)  | 
410  | 
||
| 70865 | 411  | 
    for (session <- context.sessions(logic = logic, log = log)) {
 | 
412  | 
session.process((args: Args) =>  | 
|
413  | 
        {
 | 
|
414  | 
          progress.echo("Processing theory " + args.print_node + " ...")
 | 
|
415  | 
val aspect_args =  | 
|
416  | 
Aspect_Args(session.options, context.deps, progress, output_dir,  | 
|
417  | 
args.snapshot, args.status)  | 
|
418  | 
aspects.foreach(_.operation(aspect_args))  | 
|
419  | 
})  | 
|
420  | 
}  | 
|
| 70876 | 421  | 
|
422  | 
context.check_errors  | 
|
| 69523 | 423  | 
}  | 
424  | 
||
425  | 
||
| 
68308
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
426  | 
/* Isabelle tool wrapper */  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
427  | 
|
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
428  | 
val isabelle_tool =  | 
| 68348 | 429  | 
    Isabelle_Tool("dump", "dump cumulative PIDE session database", args =>
 | 
| 
68308
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
430  | 
    {
 | 
| 68345 | 431  | 
var aspects: List[Aspect] = known_aspects  | 
| 
68308
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
432  | 
var base_sessions: List[String] = Nil  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
433  | 
var select_dirs: List[Path] = Nil  | 
| 68316 | 434  | 
var output_dir = default_output_dir  | 
| 
68308
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
435  | 
var requirements = false  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
436  | 
var exclude_session_groups: List[String] = Nil  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
437  | 
var all_sessions = false  | 
| 
70859
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
438  | 
var logic = default_logic  | 
| 
68308
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
439  | 
var dirs: List[Path] = Nil  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
440  | 
var session_groups: List[String] = Nil  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
441  | 
var options = Options.init()  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
442  | 
var verbose = false  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
443  | 
var exclude_sessions: List[String] = Nil  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
444  | 
|
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
445  | 
      val getopts = Getopts("""
 | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
446  | 
Usage: isabelle dump [OPTIONS] [SESSIONS ...]  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
447  | 
|
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
448  | 
Options are:  | 
| 68345 | 449  | 
    -A NAMES     dump named aspects (default: """ + known_aspects.mkString("\"", ",", "\"") + """)
 | 
| 
68308
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
450  | 
-B NAME include session NAME and all descendants  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
451  | 
-D DIR include session directory and select its sessions  | 
| 68316 | 452  | 
-O DIR output directory for dumped files (default: """ + default_output_dir + """)  | 
| 
68308
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
453  | 
-R operate on requirements of selected sessions  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
454  | 
-X NAME exclude sessions from group NAME and all descendants  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
455  | 
-a select all sessions  | 
| 
70859
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
456  | 
-b NAME base logic image (default """ + isabelle.quote(default_logic) + """)  | 
| 
68308
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
457  | 
-d DIR include session directory  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
458  | 
-g NAME select session group NAME  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
459  | 
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME)  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
460  | 
-v verbose  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
461  | 
-x NAME exclude session NAME and all descendants  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
462  | 
|
| 68348 | 463  | 
Dump cumulative PIDE session database, with the following aspects:  | 
| 68316 | 464  | 
|
465  | 
""" + Library.prefix_lines("    ", show_aspects) + "\n",
 | 
|
| 71601 | 466  | 
      "A:" -> (arg => aspects = Library.distinct(space_explode(',', arg)).map(the_aspect)),
 | 
| 
68308
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
467  | 
"B:" -> (arg => base_sessions = base_sessions ::: List(arg)),  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
468  | 
"D:" -> (arg => select_dirs = select_dirs ::: List(Path.explode(arg))),  | 
| 68316 | 469  | 
"O:" -> (arg => output_dir = Path.explode(arg)),  | 
| 
68308
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
470  | 
"R" -> (_ => requirements = true),  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
471  | 
"X:" -> (arg => exclude_session_groups = exclude_session_groups ::: List(arg)),  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
472  | 
"a" -> (_ => all_sessions = true),  | 
| 
70859
 
6e6254bbce1f
split into standard partitions, for improved scalability;
 
wenzelm 
parents: 
70858 
diff
changeset
 | 
473  | 
"b:" -> (arg => logic = arg),  | 
| 
68308
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
474  | 
"d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))),  | 
| 68741 | 475  | 
"g:" -> (arg => session_groups = session_groups ::: List(arg)),  | 
| 
68308
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
476  | 
"o:" -> (arg => options = options + arg),  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
477  | 
"v" -> (_ => verbose = true),  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
478  | 
"x:" -> (arg => exclude_sessions = exclude_sessions ::: List(arg)))  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
479  | 
|
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
480  | 
val sessions = getopts(args)  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
481  | 
|
| 
68951
 
a7b1fe2d30ad
more uniform Progress, with theory() for batch-build and theory_percentage() for PIDE session;
 
wenzelm 
parents: 
68948 
diff
changeset
 | 
482  | 
val progress = new Console_Progress(verbose = verbose)  | 
| 
68308
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
483  | 
|
| 69535 | 484  | 
      progress.interrupt_handler {
 | 
485  | 
dump(options, logic,  | 
|
486  | 
aspects = aspects,  | 
|
487  | 
progress = progress,  | 
|
488  | 
dirs = dirs,  | 
|
489  | 
select_dirs = select_dirs,  | 
|
490  | 
output_dir = output_dir,  | 
|
491  | 
selection = Sessions.Selection(  | 
|
492  | 
requirements = requirements,  | 
|
493  | 
all_sessions = all_sessions,  | 
|
494  | 
base_sessions = base_sessions,  | 
|
495  | 
exclude_session_groups = exclude_session_groups,  | 
|
496  | 
exclude_sessions = exclude_sessions,  | 
|
497  | 
session_groups = session_groups,  | 
|
498  | 
sessions = sessions))  | 
|
499  | 
}  | 
|
| 
68308
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
500  | 
})  | 
| 
 
119fc05f6b00
support to dump build database produced by PIDE session;
 
wenzelm 
parents:  
diff
changeset
 | 
501  | 
}  |