src/Pure/Tools/dump.scala
changeset 69523 9403ff523825
parent 69522 9457d85204f5
child 69524 fa94f2b2a877
equal deleted inserted replaced
69522:9457d85204f5 69523:9403ff523825
    71   def the_aspect(name: String): Aspect =
    71   def the_aspect(name: String): Aspect =
    72     known_aspects.find(aspect => aspect.name == name) getOrElse
    72     known_aspects.find(aspect => aspect.name == name) getOrElse
    73       error("Unknown aspect " + quote(name))
    73       error("Unknown aspect " + quote(name))
    74 
    74 
    75 
    75 
       
    76   /* session */
       
    77 
       
    78   def session(dump_options: Options, logic: String,
       
    79     consume: (Sessions.Deps, Document.Snapshot, Document_Status.Node_Status) => Unit,
       
    80     progress: Progress = No_Progress,
       
    81     log: Logger = No_Logger,
       
    82     dirs: List[Path] = Nil,
       
    83     select_dirs: List[Path] = Nil,
       
    84     system_mode: Boolean = false,
       
    85     selection: Sessions.Selection = Sessions.Selection.empty): Boolean =
       
    86   {
       
    87     /* dependencies */
       
    88 
       
    89     val deps =
       
    90       Sessions.load_structure(dump_options, dirs = dirs, select_dirs = select_dirs).
       
    91         selection_deps(selection)
       
    92 
       
    93     val include_sessions =
       
    94       deps.sessions_structure.imports_topological_order
       
    95 
       
    96     val use_theories =
       
    97       for { (_, name) <- deps.used_theories_condition(dump_options, progress.echo_warning) }
       
    98       yield name.theory
       
    99 
       
   100 
       
   101     /* dump aspects asynchronously */
       
   102 
       
   103     object Consumer
       
   104     {
       
   105       private val consumer_ok = Synchronized(true)
       
   106 
       
   107       private val consumer =
       
   108         Consumer_Thread.fork(name = "dump")(
       
   109           consume = (args: (Document.Snapshot, Document_Status.Node_Status)) =>
       
   110             {
       
   111               val (snapshot, node_status) = args
       
   112               if (node_status.ok) consume(deps, snapshot, node_status)
       
   113               else {
       
   114                 consumer_ok.change(_ => false)
       
   115                 for ((tree, pos) <- snapshot.messages if Protocol.is_error(tree)) {
       
   116                   val msg = XML.content(Pretty.formatted(List(tree)))
       
   117                   progress.echo_error_message("Error" + Position.here(pos) + ":\n" + msg)
       
   118                 }
       
   119               }
       
   120               true
       
   121             })
       
   122 
       
   123       def apply(snapshot: Document.Snapshot, node_status: Document_Status.Node_Status): Unit =
       
   124         consumer.send((snapshot, node_status))
       
   125 
       
   126       def shutdown(): Boolean =
       
   127       {
       
   128         consumer.shutdown()
       
   129         consumer_ok.value
       
   130       }
       
   131     }
       
   132 
       
   133 
       
   134     /* run session */
       
   135 
       
   136     val session =
       
   137       Headless.start_session(dump_options, logic, session_dirs = dirs ::: select_dirs,
       
   138         include_sessions = include_sessions, progress = progress, log = log)
       
   139 
       
   140     val use_theories_result =
       
   141       session.use_theories(use_theories, progress = progress, commit = Some(Consumer.apply _))
       
   142 
       
   143     session.stop()
       
   144 
       
   145     val consumer_ok = Consumer.shutdown()
       
   146 
       
   147     use_theories_result.nodes_pending match {
       
   148       case Nil =>
       
   149       case pending => error("Pending theories " + commas_quote(pending.map(p => p._1.toString)))
       
   150     }
       
   151 
       
   152     use_theories_result.ok && consumer_ok
       
   153   }
       
   154 
       
   155 
    76   /* dump */
   156   /* dump */
    77 
   157 
    78   val default_output_dir: Path = Path.explode("dump")
   158   val default_output_dir: Path = Path.explode("dump")
    79 
   159 
    80   def make_options(options: Options, aspects: List[Aspect]): Options =
   160   def make_options(options: Options, aspects: List[Aspect] = Nil): Options =
    81   {
   161   {
    82     val options0 = if (NUMA.enabled) NUMA.policy_options(options) else options
   162     val options0 = if (NUMA.enabled) NUMA.policy_options(options) else options
    83     val options1 =
   163     val options1 =
    84       options0 + "completion_limit=0" + "ML_statistics=false" +
   164       options0 + "completion_limit=0" + "ML_statistics=false" +
    85         "parallel_proofs=0" + "editor_tracing_messages=0"
   165         "parallel_proofs=0" + "editor_tracing_messages=0"
    99     if (Build.build_logic(options, logic, build_heap = true, progress = progress,
   179     if (Build.build_logic(options, logic, build_heap = true, progress = progress,
   100       dirs = dirs ::: select_dirs, system_mode = system_mode) != 0) error(logic + " FAILED")
   180       dirs = dirs ::: select_dirs, system_mode = system_mode) != 0) error(logic + " FAILED")
   101 
   181 
   102     val dump_options = make_options(options, aspects)
   182     val dump_options = make_options(options, aspects)
   103 
   183 
   104 
   184     def consume(
   105     /* dependencies */
   185       deps: Sessions.Deps,
   106 
   186       snapshot: Document.Snapshot,
   107     val deps =
   187       node_status: Document_Status.Node_Status)
   108       Sessions.load_structure(dump_options, dirs = dirs, select_dirs = select_dirs).
   188     {
   109         selection_deps(selection)
   189       val aspect_args = Aspect_Args(dump_options, progress, deps, output_dir, snapshot, node_status)
   110 
   190       aspects.foreach(_.operation(aspect_args))
   111     val include_sessions =
   191     }
   112       deps.sessions_structure.imports_topological_order
   192 
   113 
   193     session(dump_options, logic, consume _,
   114     val use_theories =
   194       progress = progress, log = log, dirs = dirs, select_dirs = select_dirs, selection = selection)
   115       for { (_, name) <- deps.used_theories_condition(dump_options, progress.echo_warning) }
       
   116       yield name.theory
       
   117 
       
   118 
       
   119     /* dump aspects asynchronously */
       
   120 
       
   121     object Consumer
       
   122     {
       
   123       private val consumer_ok = Synchronized(true)
       
   124 
       
   125       private val consumer =
       
   126         Consumer_Thread.fork(name = "dump")(
       
   127           consume = (args: (Document.Snapshot, Document_Status.Node_Status)) =>
       
   128             {
       
   129               val (snapshot, node_status) = args
       
   130               if (node_status.ok) {
       
   131                 val aspect_args =
       
   132                   Aspect_Args(dump_options, progress, deps, output_dir, snapshot, node_status)
       
   133                 aspects.foreach(_.operation(aspect_args))
       
   134               }
       
   135               else {
       
   136                 consumer_ok.change(_ => false)
       
   137                 for ((tree, pos) <- snapshot.messages if Protocol.is_error(tree)) {
       
   138                   val msg = XML.content(Pretty.formatted(List(tree)))
       
   139                   progress.echo_error_message("Error" + Position.here(pos) + ":\n" + msg)
       
   140                 }
       
   141               }
       
   142               true
       
   143             })
       
   144 
       
   145       def apply(snapshot: Document.Snapshot, node_status: Document_Status.Node_Status): Unit =
       
   146         consumer.send((snapshot, node_status))
       
   147 
       
   148       def shutdown(): Boolean =
       
   149       {
       
   150         consumer.shutdown()
       
   151         consumer_ok.value
       
   152       }
       
   153     }
       
   154 
       
   155 
       
   156     /* session */
       
   157 
       
   158     val session =
       
   159       Headless.start_session(dump_options, logic, session_dirs = dirs ::: select_dirs,
       
   160         include_sessions = include_sessions, progress = progress, log = log)
       
   161 
       
   162     val use_theories_result =
       
   163       session.use_theories(use_theories, progress = progress, commit = Some(Consumer.apply _))
       
   164 
       
   165     session.stop()
       
   166 
       
   167     val consumer_ok = Consumer.shutdown()
       
   168 
       
   169     use_theories_result.nodes_pending match {
       
   170       case Nil =>
       
   171       case pending => error("Pending theories " + commas_quote(pending.map(p => p._1.toString)))
       
   172     }
       
   173 
       
   174     use_theories_result.ok && consumer_ok
       
   175   }
   195   }
   176 
   196 
   177 
   197 
   178   /* Isabelle tool wrapper */
   198   /* Isabelle tool wrapper */
   179 
   199