# HG changeset patch # User wenzelm # Date 1521844319 -3600 # Node ID 49a34b2fa788b6803878aaead7d152f0e6bc6021 # Parent b4e80f062fbfbc6deef66d269ee67ac2f8d3ca1c added command "purge_theories"; proper documentation: command "use_theories" is asynchronous; diff -r b4e80f062fbf -r 49a34b2fa788 src/Doc/System/Server.thy --- a/src/Doc/System/Server.thy Fri Mar 23 22:53:32 2018 +0100 +++ b/src/Doc/System/Server.thy Fri Mar 23 23:31:59 2018 +0100 @@ -873,7 +873,8 @@ text \ \begin{tabular}{ll} argument: & \use_theories_arguments\ \\ - regular result: & \<^verbatim>\OK\ \use_theories_results\ \\ + immediate result: & \<^verbatim>\OK\ \task\ \\ + regular result: & \<^verbatim>\FINISHED\ \use_theories_results\ \\ \end{tabular} \begin{tabular}{ll} @@ -906,10 +907,11 @@ (\secref{sec:json-types}): the outermost command structure has finished (or failed) and the final \<^theory_text>\end\ command of each theory has been checked. - Already used theories persist in the session until purged explicitly. This - also means that repeated invocations of \<^verbatim>\use_theories\ are idempotent: it - could make sense to do that with different values for \pretty_margin\ or - \unicode_symbols\ to get different formatting for \errors\ or \messages\. + Already used theories persist in the session until purged explicitly + (\secref{sec:command-purge-theories}). This also means that repeated + invocations of \<^verbatim>\use_theories\ are idempotent: it could make sense to do + that with different values for \pretty_margin\ or \unicode_symbols\ to get + different formatting for \errors\ or \messages\. \ @@ -923,11 +925,12 @@ The \theories\ field specifies theory names as in theory \<^theory_text>\imports\ or in ROOT \<^bold>\theories\. - \<^medskip> The \master_dir\ field specifies the master directory of imported - theories: it acts like the ``current working directory'' for locating theory - files. This may be omitted if all entries of \theories\ use a - session-qualified theory name (e.g.\ \<^verbatim>\"HOL-Library.AList"\) or absolute - path name (e.g.\ \<^verbatim>\"~~/src/HOL/ex/Seq"\). + \<^medskip> + The \master_dir\ field specifies the master directory of imported theories: + it acts like the ``current working directory'' for locating theory files. + This may be omitted if all entries of \theories\ use a session-qualified + theory name (e.g.\ \<^verbatim>\"HOL-Library.AList"\) or absolute path name (e.g.\ + \<^verbatim>\"~~/src/HOL/ex/Seq"\). \<^medskip> The \pretty_margin\ field specifies the line width for pretty-printing. The @@ -996,4 +999,61 @@ session_stop {"session_id": ...}\} \ + +subsection \Command \<^verbatim>\purge_theories\ \label{sec:command-purge-theories}\ + +text \ + \begin{tabular}{ll} + argument: & \purge_theories_arguments\ \\ + regular result: & \<^verbatim>\OK\ \purge_theories_result\ \\ + \end{tabular} + + \begin{tabular}{ll} + \<^bold>\type\ \purge_theories_arguments =\ \\ + \quad\{session_id: uuid,\ \\ + \quad~~\theories: [string],\ \\ + \quad~~\master_dir?: string,\ \\ + \quad~~\all?: bool}\ \\[2ex] + \end{tabular} + + \begin{tabular}{ll} + \<^bold>\type\ \purge_theories_result = {purged: [string]}\ \\ + \end{tabular} + + \<^medskip> + The \<^verbatim>\purge_theories\ command updates the identified session by removing + theories that are no longer required: theories that are used in pending + \<^verbatim>\use_theories\ tasks or imported by other theories are retained. +\ + + +subsubsection \Arguments\ + +text \ + The \session_id\ is the identifier provided by the server, when the session + was created (possibly on a different client connection). + + \<^medskip> + The \theories\ field specifies theory names to be purged: imported + dependencies are \<^emph>\not\ completed. Instead it is possible to provide the + already completed import graph returned by \<^verbatim>\use_theories\ as \nodes\ / + \node_name\. + + \<^medskip> + The \master_dir\ field specifies the master directory as in \<^verbatim>\use_theories\; + by passing its \nodes\ / \node_name\ results, the \master_dir\ is redundant. + + \<^medskip> + The \all\ field set to \<^verbatim>\true\ attempts to purge all presently loaded + theories. +\ + + +subsubsection \Results\ + +text \ + The \purged\ field reveals the \node_name\ of each theory that was actually + removed. +\ + end diff -r b4e80f062fbf -r 49a34b2fa788 src/Pure/Tools/server.scala --- a/src/Pure/Tools/server.scala Fri Mar 23 22:53:32 2018 +0100 +++ b/src/Pure/Tools/server.scala Fri Mar 23 23:31:59 2018 +0100 @@ -102,7 +102,12 @@ val session = context.server.the_session(args.session_id) Server_Commands.Use_Theories.command( args, session, id = task.id, progress = task.progress)._1 - }) + }), + }, + "purge_theories" -> + { case (context, Server_Commands.Purge_Theories(args)) => + val session = context.server.the_session(args.session_id) + Server_Commands.Purge_Theories.command(args, session)._1 }) def unapply(name: String): Option[T] = table.get(name) diff -r b4e80f062fbf -r 49a34b2fa788 src/Pure/Tools/server_commands.scala --- a/src/Pure/Tools/server_commands.scala Fri Mar 23 22:53:32 2018 +0100 +++ b/src/Pure/Tools/server_commands.scala Fri Mar 23 23:31:59 2018 +0100 @@ -219,4 +219,31 @@ (result_json, result) } } + + object Purge_Theories + { + sealed case class Args( + session_id: UUID, + theories: List[String] = Nil, + master_dir: String = "", + all: Boolean = false) + + def unapply(json: JSON.T): Option[Args] = + for { + session_id <- JSON.uuid(json, "session_id") + theories <- JSON.list_default(json, "theories", JSON.Value.String.unapply _) + master_dir <- JSON.string_default(json, "master_dir") + all <- JSON.bool_default(json, "all") + } + yield { Args(session_id, theories = theories, master_dir = master_dir, all = all) } + + def command(args: Args, session: Thy_Resources.Session) + : (JSON.Object.T, List[Document.Node.Name]) = + { + val purged = + session.purge_theories( + theories = args.theories, master_dir = args.master_dir, all = args.all) + (JSON.Object("purged" -> purged.map(_.node)), purged) + } + } }