author | wenzelm |
Mon, 14 Oct 2019 19:14:03 +0200 | |
changeset 70861 | cb07f21c9916 |
parent 70860 | f5d0aebfd89c |
child 70862 | a4ccd277e9c4 |
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 |
|
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
9 |
|
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
10 |
object Dump |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
11 |
{ |
68316 | 12 |
/* aspects */ |
13 |
||
14 |
sealed case class Aspect_Args( |
|
68355 | 15 |
options: Options, |
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
16 |
deps: Sessions.Deps, |
68355 | 17 |
progress: Progress, |
69896 | 18 |
output_dir: Path, |
68929 | 19 |
snapshot: Document.Snapshot, |
69534 | 20 |
status: Document_Status.Node_Status) |
68319 | 21 |
{ |
68365 | 22 |
def write(file_name: Path, bytes: Bytes) |
68319 | 23 |
{ |
68929 | 24 |
val path = output_dir + Path.basic(snapshot.node_name.theory) + file_name |
68319 | 25 |
Isabelle_System.mkdirs(path.dir) |
26 |
Bytes.write(path, bytes) |
|
27 |
} |
|
28 |
||
68365 | 29 |
def write(file_name: Path, text: String): Unit = |
30 |
write(file_name, Bytes(text)) |
|
68332 | 31 |
|
68365 | 32 |
def write(file_name: Path, body: XML.Body): Unit = |
33 |
write(file_name, Symbol.encode(YXML.string_of_body(body))) |
|
68319 | 34 |
} |
68316 | 35 |
|
68347 | 36 |
sealed case class Aspect(name: String, description: String, operation: Aspect_Args => Unit, |
37 |
options: List[String] = Nil) |
|
68345 | 38 |
{ |
39 |
override def toString: String = name |
|
40 |
} |
|
68316 | 41 |
|
69521 | 42 |
val known_aspects: List[Aspect] = |
68316 | 43 |
List( |
68365 | 44 |
Aspect("markup", "PIDE markup (YXML format)", |
45 |
{ case args => |
|
46 |
args.write(Path.explode("markup.yxml"), |
|
47 |
args.snapshot.markup_to_XML(Text.Range.full, Markup.Elements.full)) |
|
48 |
}), |
|
68319 | 49 |
Aspect("messages", "output messages (YXML format)", |
50 |
{ case args => |
|
68365 | 51 |
args.write(Path.explode("messages.yxml"), |
52 |
args.snapshot.messages.iterator.map(_._1).toList) |
|
68347 | 53 |
}), |
54 |
Aspect("latex", "generated LaTeX source", |
|
55 |
{ case args => |
|
68365 | 56 |
for (entry <- args.snapshot.exports if entry.name == "document.tex") |
57 |
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
|
58 |
}, options = List("export_document")), |
68347 | 59 |
Aspect("theory", "foundational theory content", |
60 |
{ case args => |
|
61 |
for { |
|
68365 | 62 |
entry <- args.snapshot.exports |
68347 | 63 |
if entry.name.startsWith(Export_Theory.export_prefix) |
68365 | 64 |
} 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
|
65 |
}, options = List("export_theory")) |
68345 | 66 |
).sortBy(_.name) |
68316 | 67 |
|
68 |
def show_aspects: String = |
|
68345 | 69 |
cat_lines(known_aspects.map(aspect => aspect.name + " - " + aspect.description)) |
68316 | 70 |
|
71 |
def the_aspect(name: String): Aspect = |
|
72 |
known_aspects.find(aspect => aspect.name == name) getOrElse |
|
73 |
error("Unknown aspect " + quote(name)) |
|
74 |
||
75 |
||
70856
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
76 |
/* context and session */ |
69538
faf547d2834c
clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents:
69537
diff
changeset
|
77 |
|
69896 | 78 |
sealed case class Args( |
69897 | 79 |
session: Headless.Session, |
80 |
snapshot: Document.Snapshot, |
|
81 |
status: Document_Status.Node_Status) |
|
69896 | 82 |
{ |
83 |
def print_node: String = snapshot.node_name.toString |
|
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
84 |
} |
69896 | 85 |
|
70856
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
86 |
object Context |
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
87 |
{ |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
88 |
def apply( |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
89 |
options: Options, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
90 |
aspects: List[Aspect] = Nil, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
91 |
progress: Progress = No_Progress, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
92 |
dirs: List[Path] = Nil, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
93 |
select_dirs: List[Path] = Nil, |
70856
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
94 |
selection: Sessions.Selection = Sessions.Selection.empty): Context = |
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
95 |
{ |
70856
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
96 |
val session_options: Options = |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
97 |
{ |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
98 |
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
|
99 |
val options1 = |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
100 |
options0 + |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
101 |
"completion_limit=0" + |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
102 |
"ML_statistics=false" + |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
103 |
"parallel_proofs=0" + |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
104 |
"editor_tracing_messages=0" + |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
105 |
"editor_presentation" |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
106 |
(options1 /: aspects)({ case (opts, aspect) => (opts /: aspect.options)(_ + _) }) |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
107 |
} |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
108 |
|
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
109 |
val deps: Sessions.Deps = |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
110 |
Sessions.load_structure(session_options, dirs = dirs, select_dirs = select_dirs). |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
111 |
selection_deps(session_options, selection, progress = progress, |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
112 |
uniform_session = true, loading_sessions = true).check_errors |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
113 |
|
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
114 |
new Context(options, progress, dirs, select_dirs, session_options, deps) |
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
115 |
} |
69896 | 116 |
} |
117 |
||
70856
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
118 |
class Context private( |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
119 |
val options: Options, |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
120 |
val progress: Progress, |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
121 |
val dirs: List[Path], |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
122 |
val select_dirs: List[Path], |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
123 |
val session_options: Options, |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
124 |
val deps: Sessions.Deps) |
69538
faf547d2834c
clarified signature, notably cascade of dump_options, deps, resources, session;
wenzelm
parents:
69537
diff
changeset
|
125 |
{ |
70859
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
126 |
context => |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
127 |
|
70856
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
128 |
def session_dirs: List[Path] = dirs ::: select_dirs |
68926 | 129 |
|
70857 | 130 |
def build_logic(logic: String) |
131 |
{ |
|
132 |
Build.build_logic(options, logic, build_heap = true, progress = progress, |
|
133 |
dirs = session_dirs, strict = true) |
|
134 |
} |
|
135 |
||
70856
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
136 |
def session(logic: String, log: Logger = No_Logger): Session = |
70857 | 137 |
{ |
138 |
build_logic(logic) |
|
70859
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
139 |
new Session(context, logic, log, deps.sessions_structure.imports_topological_order) |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
140 |
} |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
141 |
|
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
142 |
def partition_sessions( |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
143 |
logic: String = default_logic, |
70861 | 144 |
log: Logger = No_Logger): List[Session] = |
70859
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
145 |
{ |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
146 |
val session_graph = deps.sessions_structure.imports_graph |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
147 |
|
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
148 |
val afp_sessions = |
70861 | 149 |
(for ((name, (info, _)) <- session_graph.iterator if info.is_afp) yield name).toSet |
70859
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
150 |
|
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
151 |
val afp_bulky_sessions = |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
152 |
(for (name <- afp_sessions.iterator if deps.sessions_structure(name).is_afp_bulky) |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
153 |
yield name).toList |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
154 |
|
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
155 |
val base_sessions = session_graph.all_preds(List(logic)).reverse |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
156 |
|
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
157 |
val base = |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
158 |
if (logic == isabelle.Thy_Header.PURE) Nil |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
159 |
else List(new Session(context, isabelle.Thy_Header.PURE, log, base_sessions)) |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
160 |
|
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
161 |
val main = |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
162 |
new Session(context, logic, log, |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
163 |
session_graph.topological_order.filterNot(name => |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
164 |
afp_sessions.contains(name) || base_sessions.contains(name))) |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
165 |
|
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
166 |
val afp = |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
167 |
if (afp_sessions.isEmpty) Nil |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
168 |
else { |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
169 |
val (part1, part2) = |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
170 |
{ |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
171 |
val graph = session_graph.restrict(afp_sessions -- afp_bulky_sessions) |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
172 |
val force_partition1 = AFP.force_partition1.filter(graph.defined(_)) |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
173 |
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
|
174 |
graph.keys.partition(a => force_part1(a) || graph.is_isolated(a)) |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
175 |
} |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
176 |
for (part <- List(part1, part2, afp_bulky_sessions) if part.nonEmpty) |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
177 |
yield new Session(context, logic, log, part) |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
178 |
} |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
179 |
|
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
180 |
build_logic(logic) |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
181 |
base ::: List(main) ::: afp |
70857 | 182 |
} |
70856
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
183 |
} |
68926 | 184 |
|
70859
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
185 |
class Session private[Dump]( |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
186 |
context: Context, val logic: String, log: Logger, val selected_sessions: List[String]) |
70856
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
187 |
{ |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
188 |
/* resources */ |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
189 |
|
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
190 |
private val progress = context.progress |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
191 |
|
70859
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
192 |
private val selected_session = selected_sessions.toSet |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
193 |
|
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
194 |
private def selected_theory(name: Document.Node.Name): Boolean = |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
195 |
selected_session(context.deps.sessions_structure.theory_qualifier(name.theory)) |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
196 |
|
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
197 |
val resources: Headless.Resources = |
70856
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
198 |
Headless.Resources.make(context.session_options, logic, progress = progress, log = log, |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
199 |
session_dirs = context.session_dirs, |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
200 |
include_sessions = context.deps.sessions_structure.imports_topological_order) |
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
201 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
202 |
val used_theories: List[Document.Node.Name] = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
203 |
{ |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
204 |
for { |
70856
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
205 |
(name, _) <- |
70859
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
206 |
context.deps.used_theories_condition(context.session_options, |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
207 |
restrict = selected_session, |
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
208 |
progress = progress) |
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
209 |
if !resources.session_base.loaded_theory(name.theory) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
210 |
} yield name |
68926 | 211 |
} |
212 |
||
213 |
||
70856
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
214 |
/* process */ |
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
215 |
|
70856
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
216 |
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
|
217 |
{ |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
218 |
val session = resources.start_session(progress = progress) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
219 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
220 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
221 |
// asynchronous consumer |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
222 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
223 |
object Consumer |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
224 |
{ |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
225 |
sealed case class Bad_Theory( |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
226 |
name: Document.Node.Name, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
227 |
status: Document_Status.Node_Status, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
228 |
errors: List[String]) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
229 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
230 |
private val consumer_bad_theories = Synchronized(List.empty[Bad_Theory]) |
68318 | 231 |
|
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
232 |
private val consumer = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
233 |
Consumer_Thread.fork(name = "dump")( |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
234 |
consume = (args: (Document.Snapshot, Document_Status.Node_Status)) => |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
235 |
{ |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
236 |
val (snapshot, status) = args |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
237 |
val name = snapshot.node_name |
70860 | 238 |
if (selected_theory(name)) { |
239 |
if (status.ok) { |
|
240 |
try { process_theory(Args(session, snapshot, status)) } |
|
241 |
catch { |
|
242 |
case exn: Throwable if !Exn.is_interrupt(exn) => |
|
243 |
val msg = Exn.message(exn) |
|
244 |
progress.echo("FAILED to process theory " + name) |
|
245 |
progress.echo_error_message(msg) |
|
246 |
consumer_bad_theories.change(Bad_Theory(name, status, List(msg)) :: _) |
|
247 |
} |
|
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
248 |
} |
70860 | 249 |
else { |
250 |
val msgs = |
|
251 |
for ((tree, pos) <- snapshot.messages if Protocol.is_error(tree)) |
|
252 |
yield { |
|
253 |
"Error" + Position.here(pos) + ":\n" + |
|
254 |
XML.content(Pretty.formatted(List(tree))) |
|
255 |
} |
|
256 |
progress.echo("FAILED to process theory " + name) |
|
257 |
msgs.foreach(progress.echo_error_message) |
|
258 |
consumer_bad_theories.change(Bad_Theory(name, status, msgs) :: _) |
|
259 |
} |
|
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
260 |
} |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
261 |
true |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
262 |
}) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
263 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
264 |
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
|
265 |
consumer.send((snapshot, status)) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
266 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
267 |
def shutdown(): List[Bad_Theory] = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
268 |
{ |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
269 |
consumer.shutdown() |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
270 |
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
|
271 |
} |
0f8742b5a9e8
more scalable isabelle dump (and derivatives): mark individual theories to share common data in ML;
wenzelm
parents:
70626
diff
changeset
|
272 |
} |
0f8742b5a9e8
more scalable isabelle dump (and derivatives): mark individual theories to share common data in ML;
wenzelm
parents:
70626
diff
changeset
|
273 |
|
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
274 |
|
70653
f7c5b30fc432
load theories in stages, to reduce ML heap requirements;
wenzelm
parents:
70645
diff
changeset
|
275 |
// synchronous body |
68320
1d33697199c1
shutdown ML process before output: Theories_Result is timeless/stateless;
wenzelm
parents:
68319
diff
changeset
|
276 |
|
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
277 |
try { |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
278 |
val use_theories_result = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
279 |
session.use_theories(used_theories.map(_.theory), |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
280 |
unicode_symbols = unicode_symbols, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
281 |
progress = progress, |
70653
f7c5b30fc432
load theories in stages, to reduce ML heap requirements;
wenzelm
parents:
70645
diff
changeset
|
282 |
commit = Some(Consumer.apply _)) |
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
283 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
284 |
val bad_theories = Consumer.shutdown() |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
285 |
val bad_msgs = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
286 |
bad_theories.map(bad => |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
287 |
Output.clean_yxml( |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
288 |
"FAILED theory " + bad.name + |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
289 |
(if (bad.status.consolidated) "" else ": " + bad.status.percentage + "% finished") + |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
290 |
(if (bad.errors.isEmpty) "" else bad.errors.mkString("\n", "\n", "")))) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
291 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
292 |
val pending_msgs = |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
293 |
use_theories_result.nodes_pending match { |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
294 |
case Nil => Nil |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
295 |
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
|
296 |
} |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
297 |
|
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
298 |
val errors = bad_msgs ::: pending_msgs |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
299 |
if (errors.nonEmpty) error(errors.mkString("\n\n")) |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
300 |
} |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
301 |
finally { session.stop() } |
69032
90bb4cabe1e8
clarified errors: no result from forced session.stop, check pending theories;
wenzelm
parents:
69026
diff
changeset
|
302 |
} |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
303 |
} |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
304 |
|
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
305 |
|
69523 | 306 |
/* dump */ |
307 |
||
308 |
val default_output_dir: Path = Path.explode("dump") |
|
70858 | 309 |
val default_logic: String = Thy_Header.PURE |
69523 | 310 |
|
70640
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
311 |
def dump( |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
312 |
options: Options, |
5f4b8a505090
more explicit type Dump.Session, with context information;
wenzelm
parents:
70634
diff
changeset
|
313 |
logic: String, |
69523 | 314 |
aspects: List[Aspect] = Nil, |
315 |
progress: Progress = No_Progress, |
|
316 |
log: Logger = No_Logger, |
|
317 |
dirs: List[Path] = Nil, |
|
318 |
select_dirs: List[Path] = Nil, |
|
319 |
output_dir: Path = default_output_dir, |
|
69535 | 320 |
selection: Sessions.Selection = Sessions.Selection.empty) |
69523 | 321 |
{ |
70856
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
322 |
val context = |
545229df2f82
clarified signature: static Dump.Context vs. dynamic Dump.Session;
wenzelm
parents:
70796
diff
changeset
|
323 |
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
|
324 |
select_dirs = select_dirs, selection = selection) |
69523 | 325 |
|
70861 | 326 |
context.partition_sessions(logic = logic, log = log).foreach(_.process((args: Args) => |
327 |
{ |
|
328 |
progress.echo("Processing theory " + args.print_node + " ...") |
|
329 |
val aspect_args = |
|
330 |
Aspect_Args(context.session_options, context.deps, progress, output_dir, |
|
331 |
args.snapshot, args.status) |
|
332 |
aspects.foreach(_.operation(aspect_args)) |
|
333 |
})) |
|
69523 | 334 |
} |
335 |
||
336 |
||
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
337 |
/* Isabelle tool wrapper */ |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
338 |
|
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
339 |
val isabelle_tool = |
68348 | 340 |
Isabelle_Tool("dump", "dump cumulative PIDE session database", args => |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
341 |
{ |
68345 | 342 |
var aspects: List[Aspect] = known_aspects |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
343 |
var base_sessions: List[String] = Nil |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
344 |
var select_dirs: List[Path] = Nil |
68316 | 345 |
var output_dir = default_output_dir |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
346 |
var requirements = false |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
347 |
var exclude_session_groups: List[String] = Nil |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
348 |
var all_sessions = false |
70859
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
349 |
var logic = default_logic |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
350 |
var dirs: List[Path] = Nil |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
351 |
var session_groups: List[String] = Nil |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
352 |
var options = Options.init() |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
353 |
var verbose = false |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
354 |
var exclude_sessions: List[String] = Nil |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
355 |
|
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
356 |
val getopts = Getopts(""" |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
357 |
Usage: isabelle dump [OPTIONS] [SESSIONS ...] |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
358 |
|
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
359 |
Options are: |
68345 | 360 |
-A NAMES dump named aspects (default: """ + known_aspects.mkString("\"", ",", "\"") + """) |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
361 |
-B NAME include session NAME and all descendants |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
362 |
-D DIR include session directory and select its sessions |
68316 | 363 |
-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
|
364 |
-R operate on requirements of selected sessions |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
365 |
-X NAME exclude sessions from group NAME and all descendants |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
366 |
-a select all sessions |
70859
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
367 |
-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
|
368 |
-d DIR include session directory |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
369 |
-g NAME select session group NAME |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
370 |
-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
|
371 |
-v verbose |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
372 |
-x NAME exclude session NAME and all descendants |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
373 |
|
68348 | 374 |
Dump cumulative PIDE session database, with the following aspects: |
68316 | 375 |
|
376 |
""" + Library.prefix_lines(" ", show_aspects) + "\n", |
|
377 |
"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
|
378 |
"B:" -> (arg => base_sessions = base_sessions ::: List(arg)), |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
379 |
"D:" -> (arg => select_dirs = select_dirs ::: List(Path.explode(arg))), |
68316 | 380 |
"O:" -> (arg => output_dir = Path.explode(arg)), |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
381 |
"R" -> (_ => requirements = true), |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
382 |
"X:" -> (arg => exclude_session_groups = exclude_session_groups ::: List(arg)), |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
383 |
"a" -> (_ => all_sessions = true), |
70859
6e6254bbce1f
split into standard partitions, for improved scalability;
wenzelm
parents:
70858
diff
changeset
|
384 |
"b:" -> (arg => logic = arg), |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
385 |
"d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), |
68741 | 386 |
"g:" -> (arg => session_groups = session_groups ::: List(arg)), |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
387 |
"o:" -> (arg => options = options + arg), |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
388 |
"v" -> (_ => verbose = true), |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
389 |
"x:" -> (arg => exclude_sessions = exclude_sessions ::: List(arg))) |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
390 |
|
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
391 |
val sessions = getopts(args) |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
392 |
|
68951
a7b1fe2d30ad
more uniform Progress, with theory() for batch-build and theory_percentage() for PIDE session;
wenzelm
parents:
68948
diff
changeset
|
393 |
val progress = new Console_Progress(verbose = verbose) |
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
394 |
|
69535 | 395 |
progress.interrupt_handler { |
396 |
dump(options, logic, |
|
397 |
aspects = aspects, |
|
398 |
progress = progress, |
|
399 |
dirs = dirs, |
|
400 |
select_dirs = select_dirs, |
|
401 |
output_dir = output_dir, |
|
402 |
selection = Sessions.Selection( |
|
403 |
requirements = requirements, |
|
404 |
all_sessions = all_sessions, |
|
405 |
base_sessions = base_sessions, |
|
406 |
exclude_session_groups = exclude_session_groups, |
|
407 |
exclude_sessions = exclude_sessions, |
|
408 |
session_groups = session_groups, |
|
409 |
sessions = sessions)) |
|
410 |
} |
|
68308
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
411 |
}) |
119fc05f6b00
support to dump build database produced by PIDE session;
wenzelm
parents:
diff
changeset
|
412 |
} |