src/Pure/Tools/dump.scala
changeset 70856 545229df2f82
parent 70796 2739631ac368
child 70857 822f5cbfc5b6
equal deleted inserted replaced
70855:8a43ce639d85 70856:545229df2f82
    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 */
    76   /* context and session */
    77 
    77 
    78   sealed case class Args(
    78   sealed case class Args(
    79     session: Headless.Session,
    79     session: Headless.Session,
    80     snapshot: Document.Snapshot,
    80     snapshot: Document.Snapshot,
    81     status: Document_Status.Node_Status)
    81     status: Document_Status.Node_Status)
    82   {
    82   {
    83     def print_node: String = snapshot.node_name.toString
    83     def print_node: String = snapshot.node_name.toString
    84   }
    84   }
    85 
    85 
    86   object Session
    86   object Context
    87   {
    87   {
    88     def apply(
    88     def apply(
    89       options: Options,
    89       options: Options,
    90       logic: String,
       
    91       aspects: List[Aspect] = Nil,
    90       aspects: List[Aspect] = Nil,
    92       progress: Progress = No_Progress,
    91       progress: Progress = No_Progress,
    93       log: Logger = No_Logger,
       
    94       dirs: List[Path] = Nil,
    92       dirs: List[Path] = Nil,
    95       select_dirs: List[Path] = Nil,
    93       select_dirs: List[Path] = Nil,
    96       selection: Sessions.Selection = Sessions.Selection.empty): Session =
    94       selection: Sessions.Selection = Sessions.Selection.empty): Context =
    97     {
    95     {
    98       new Session(options, logic, aspects, progress, log, dirs, select_dirs, selection)
    96       val session_options: Options =
       
    97       {
       
    98         val options0 = if (NUMA.enabled) NUMA.policy_options(options) else options
       
    99         val options1 =
       
   100           options0 +
       
   101             "completion_limit=0" +
       
   102             "ML_statistics=false" +
       
   103             "parallel_proofs=0" +
       
   104             "editor_tracing_messages=0" +
       
   105             "editor_presentation"
       
   106         (options1 /: aspects)({ case (opts, aspect) => (opts /: aspect.options)(_ + _) })
       
   107       }
       
   108 
       
   109       val deps: Sessions.Deps =
       
   110         Sessions.load_structure(session_options, dirs = dirs, select_dirs = select_dirs).
       
   111           selection_deps(session_options, selection, progress = progress,
       
   112             uniform_session = true, loading_sessions = true).check_errors
       
   113 
       
   114       new Context(options, progress, dirs, select_dirs, session_options, deps)
    99     }
   115     }
   100   }
   116   }
   101 
   117 
   102   class Session private(
   118   class Context private(
   103     options: Options,
   119     val options: Options,
   104     logic: String,
   120     val progress: Progress,
   105     aspects: List[Aspect],
   121     val dirs: List[Path],
   106     progress: Progress,
   122     val select_dirs: List[Path],
   107     log: Logger,
   123     val session_options: Options,
   108     dirs: List[Path],
   124     val deps: Sessions.Deps)
   109     select_dirs: List[Path],
   125   {
   110     selection: Sessions.Selection)
   126     def session_dirs: List[Path] = dirs ::: select_dirs
   111   {
   127 
   112     /* context */
   128     def session(logic: String, log: Logger = No_Logger): Session =
   113 
   129       new Session(this, logic, log)
   114     Build.build_logic(options, logic, build_heap = true, progress = progress,
   130   }
   115       dirs = dirs ::: select_dirs, strict = true)
   131 
   116 
   132   class Session private[Dump](context: Context, logic: String, log: Logger)
   117     val dump_options: Options =
   133   {
   118     {
   134     /* resources */
   119       val options0 = if (NUMA.enabled) NUMA.policy_options(options) else options
   135 
   120       val options1 =
   136     private val progress = context.progress
   121         options0 +
   137 
   122           "completion_limit=0" +
   138     Build.build_logic(context.options, logic, build_heap = true, progress = progress,
   123           "ML_statistics=false" +
   139       dirs = context.session_dirs, strict = true)
   124           "parallel_proofs=0" +
       
   125           "editor_tracing_messages=0" +
       
   126           "editor_presentation"
       
   127       (options1 /: aspects)({ case (opts, aspect) => (opts /: aspect.options)(_ + _) })
       
   128     }
       
   129 
       
   130     val deps: Sessions.Deps =
       
   131       Sessions.load_structure(dump_options, dirs = dirs, select_dirs = select_dirs).
       
   132         selection_deps(dump_options, selection, progress = progress,
       
   133           uniform_session = true, loading_sessions = true).check_errors
       
   134 
   140 
   135     val resources: Headless.Resources =
   141     val resources: Headless.Resources =
   136       Headless.Resources.make(dump_options, logic, progress = progress, log = log,
   142       Headless.Resources.make(context.session_options, logic, progress = progress, log = log,
   137         session_dirs = dirs ::: select_dirs,
   143         session_dirs = context.session_dirs,
   138         include_sessions = deps.sessions_structure.imports_topological_order)
   144         include_sessions = context.deps.sessions_structure.imports_topological_order)
   139 
   145 
   140     val used_theories: List[Document.Node.Name] =
   146     val used_theories: List[Document.Node.Name] =
   141     {
   147     {
   142       for {
   148       for {
   143         (name, _) <- deps.used_theories_condition(dump_options, progress = progress)
   149         (name, _) <-
       
   150           context.deps.used_theories_condition(context.session_options, progress = progress)
   144         if !resources.session_base.loaded_theory(name.theory)
   151         if !resources.session_base.loaded_theory(name.theory)
   145       } yield name
   152       } yield name
   146     }
   153     }
   147 
   154 
   148 
   155 
   149     /* run */
   156     /* process */
   150 
   157 
   151     def run(process_theory: Args => Unit, unicode_symbols: Boolean = false)
   158     def process(process_theory: Args => Unit, unicode_symbols: Boolean = false)
   152     {
   159     {
   153       val session = resources.start_session(progress = progress)
   160       val session = resources.start_session(progress = progress)
   154 
   161 
   155 
   162 
   156       // asynchronous consumer
   163       // asynchronous consumer
   249     dirs: List[Path] = Nil,
   256     dirs: List[Path] = Nil,
   250     select_dirs: List[Path] = Nil,
   257     select_dirs: List[Path] = Nil,
   251     output_dir: Path = default_output_dir,
   258     output_dir: Path = default_output_dir,
   252     selection: Sessions.Selection = Sessions.Selection.empty)
   259     selection: Sessions.Selection = Sessions.Selection.empty)
   253   {
   260   {
   254     val session =
   261     val context =
   255       Session(options, logic, aspects = aspects, progress = progress, log = log, dirs = dirs,
   262       Context(options, aspects = aspects, progress = progress, dirs = dirs,
   256         select_dirs = select_dirs, selection = selection)
   263         select_dirs = select_dirs, selection = selection)
   257 
   264 
   258     session.run((args: Args) =>
   265     context.session(logic, log = log).process((args: Args) =>
   259       {
   266       {
   260         progress.echo("Processing theory " + args.print_node + " ...")
   267         progress.echo("Processing theory " + args.print_node + " ...")
   261         val aspect_args =
   268         val aspect_args =
   262           Aspect_Args(session.dump_options, session.deps, progress, output_dir,
   269           Aspect_Args(context.session_options, context.deps, progress, output_dir,
   263             args.snapshot, args.status)
   270             args.snapshot, args.status)
   264         aspects.foreach(_.operation(aspect_args))
   271         aspects.foreach(_.operation(aspect_args))
   265       })
   272       })
   266   }
   273   }
   267 
   274