doc-src/System/Thy/Sessions.thy
author wenzelm
Mon Jul 30 14:11:29 2012 +0200 (2012-07-30)
changeset 48602 342ca8f3197b
parent 48595 231e6fa96dbb
child 48604 f651323139f0
permissions -rw-r--r--
more uniform usage of "isabelle tool";
wenzelm@48578
     1
theory Sessions
wenzelm@48578
     2
imports Base
wenzelm@48578
     3
begin
wenzelm@48578
     4
wenzelm@48584
     5
chapter {* Isabelle sessions and build management \label{ch:session} *}
wenzelm@48584
     6
wenzelm@48584
     7
text {* An Isabelle \emph{session} consists of a collection of related
wenzelm@48584
     8
  theories that are associated with an optional formal document (see
wenzelm@48584
     9
  also \chref{ch:present}).  There is also a notion of persistent
wenzelm@48584
    10
  \emph{heap image} to capture the state of a session, similar to
wenzelm@48584
    11
  object-code in compiled programming languages.
wenzelm@48578
    12
wenzelm@48584
    13
  Thus the concept of session resembles that of a ``project'' in
wenzelm@48584
    14
  common IDE environments, but our specific name emphasizes the
wenzelm@48584
    15
  connection to interactive theorem proving: the session wraps-up the
wenzelm@48584
    16
  results of user-interaction with the prover in a persistent form.
wenzelm@48584
    17
wenzelm@48584
    18
  \medskip Application sessions are built on a given parent session.
wenzelm@48584
    19
  The resulting hierarchy eventually leads to some major object-logic
wenzelm@48584
    20
  session, notably @{text "HOL"}, which itself is based on @{text
wenzelm@48584
    21
  "Pure"} as the common root.
wenzelm@48584
    22
wenzelm@48584
    23
  Processing sessions may take considerable time.  The tools for
wenzelm@48584
    24
  Isabelle build management help to organize this efficiently,
wenzelm@48584
    25
  including support for parallel build jobs --- in addition to the
wenzelm@48584
    26
  multithreaded theory and proof checking that is already provided by
wenzelm@48584
    27
  the prover process.
wenzelm@48584
    28
*}
wenzelm@48578
    29
wenzelm@48578
    30
section {* Session ROOT specifications \label{sec:session-root} *}
wenzelm@48578
    31
wenzelm@48579
    32
text {* Session specifications reside in files called @{verbatim ROOT}
wenzelm@48579
    33
  within certain directories, such as the home locations of registered
wenzelm@48579
    34
  Isabelle components or additional project directories given by the
wenzelm@48579
    35
  user.
wenzelm@48579
    36
wenzelm@48579
    37
  The ROOT file format follows the lexical conventions of the
wenzelm@48579
    38
  \emph{outer syntax} of Isabelle/Isar, see also
wenzelm@48579
    39
  \cite{isabelle-isar-ref}.  This defines common forms like
wenzelm@48579
    40
  identifiers, names, quoted strings, verbatim text, nested comments
wenzelm@48579
    41
  etc.  The grammar for a single @{syntax session_entry} is given as
wenzelm@48579
    42
  syntax diagram below; each ROOT file may contain multiple session
wenzelm@48579
    43
  specifications like this.
wenzelm@48579
    44
wenzelm@48582
    45
  Isabelle/jEdit (\secref{sec:tool-jedit}) includes a simple editing
wenzelm@48582
    46
  mode @{verbatim "isabelle-root"} for session ROOT files.
wenzelm@48579
    47
wenzelm@48579
    48
  @{rail "
wenzelm@48579
    49
    @{syntax_def session_entry}: @'session' spec '=' (@{syntax name} '+')? body
wenzelm@48579
    50
    ;
wenzelm@48579
    51
    body: description? options? ( theories * ) files?
wenzelm@48579
    52
    ;
wenzelm@48579
    53
    spec: @{syntax name} '!'? groups? dir?
wenzelm@48579
    54
    ;
wenzelm@48579
    55
    groups: '(' (@{syntax name} +) ')'
wenzelm@48579
    56
    ;
wenzelm@48579
    57
    dir: @'in' @{syntax name}
wenzelm@48579
    58
    ;
wenzelm@48579
    59
    description: @'description' @{syntax text}
wenzelm@48579
    60
    ;
wenzelm@48579
    61
    options: @'options' opts
wenzelm@48579
    62
    ;
wenzelm@48579
    63
    opts: '[' ( (@{syntax name} '=' @{syntax name} | @{syntax name}) + ',' ) ']'
wenzelm@48579
    64
    ;
wenzelm@48579
    65
    theories: @'theories' opts? ( @{syntax name} + )
wenzelm@48579
    66
    ;
wenzelm@48579
    67
    files: @'files' ( @{syntax name} + )
wenzelm@48579
    68
    "}
wenzelm@48579
    69
wenzelm@48579
    70
  \begin{description}
wenzelm@48579
    71
wenzelm@48579
    72
  \item \isakeyword{session}~@{text "A = B + body"} defines a new
wenzelm@48579
    73
  session @{text "A"} based on parent session @{text "B"}, with its
wenzelm@48579
    74
  content given in @{text body} (theories and auxiliary source files).
wenzelm@48579
    75
  Note that a parent (like @{text "HOL"}) is mandatory in practical
wenzelm@48579
    76
  applications: only Isabelle/Pure can bootstrap itself from nothing.
wenzelm@48579
    77
wenzelm@48579
    78
  All such session specifications together describe a hierarchy (tree)
wenzelm@48579
    79
  of sessions, with globally unique names.  By default, names are
wenzelm@48579
    80
  derived from parent ones by concatenation, i.e.\ @{text "B\<dash>A"}
wenzelm@48579
    81
  above.  Cumulatively, this leads to session paths of the form @{text
wenzelm@48579
    82
  "X\<dash>Y\<dash>Z\<dash>W"}.  Note that in the specification,
wenzelm@48579
    83
  @{text B} is already such a fully-qualified name, while @{text "A"}
wenzelm@48579
    84
  is the new base name.
wenzelm@48579
    85
wenzelm@48579
    86
  \item \isakeyword{session}~@{text "A! = B"} indicates a fresh start
wenzelm@48579
    87
  in the naming scheme: the session is called just @{text "A"} instead
wenzelm@48579
    88
  of @{text "B\<dash>A"}.  Here the name @{text "A"} should be
wenzelm@48579
    89
  sufficiently long to stand on its own in a potentially large
wenzelm@48579
    90
  library.
wenzelm@48579
    91
wenzelm@48579
    92
  \item \isakeyword{session}~@{text "A (groups)"} indicates a
wenzelm@48579
    93
  collection of groups where the new session is a member.  Group names
wenzelm@48579
    94
  are uninterpreted and merely follow certain conventions.  For
wenzelm@48579
    95
  example, the Isabelle distribution tags some important sessions by
wenzelm@48579
    96
  the group name @{text "main"}.  Other projects may invent their own
wenzelm@48579
    97
  conventions, which requires some care to avoid clashes within this
wenzelm@48579
    98
  unchecked name space.
wenzelm@48579
    99
wenzelm@48579
   100
  \item \isakeyword{session}~@{text "A"}~\isakeyword{in}~@{text "dir"}
wenzelm@48579
   101
  specifies an explicit directory for this session.  By default,
wenzelm@48579
   102
  \isakeyword{session}~@{text "A"} abbreviates
wenzelm@48579
   103
  \isakeyword{session}~@{text "A"}~\isakeyword{in}~@{text "A"}.  This
wenzelm@48579
   104
  accommodates the common scheme where some base directory contains
wenzelm@48579
   105
  several sessions in sub-directories of corresponding names.  Another
wenzelm@48579
   106
  common scheme is \isakeyword{session}~@{text
wenzelm@48579
   107
  "A"}~\isakeyword{in}~@{verbatim "\".\""} to refer to the current
wenzelm@48579
   108
  directory of the ROOT file.
wenzelm@48579
   109
wenzelm@48579
   110
  All theories and auxiliary source files are located relatively to
wenzelm@48579
   111
  the session directory.  The prover process is run within the same as
wenzelm@48579
   112
  its current working directory.
wenzelm@48579
   113
wenzelm@48579
   114
  \item \isakeyword{description}~@{text "text"} is a free-form
wenzelm@48579
   115
  annotation for this session.
wenzelm@48579
   116
wenzelm@48579
   117
  \item \isakeyword{options}~@{text "[x = a, y = b, z]"} defines
wenzelm@48579
   118
  separate options that are used when processing this session, but
wenzelm@48579
   119
  \emph{without} propagation to child sessions; see also
wenzelm@48579
   120
  \secref{sec:system-options}.  Note that @{text "z"} abbreviates
wenzelm@48579
   121
  @{text "z = true"} for Boolean options.
wenzelm@48579
   122
wenzelm@48579
   123
  \item \isakeyword{theories}~@{text "options names"} specifies a
wenzelm@48579
   124
  block of theories that are processed within an environment that is
wenzelm@48579
   125
  augmented further by the given options, in addition to the global
wenzelm@48579
   126
  session options given before.  Any number of blocks of
wenzelm@48579
   127
  \isakeyword{theories} may be given.  Options are only active for
wenzelm@48579
   128
  each \isakeyword{theories} block separately.
wenzelm@48579
   129
wenzelm@48579
   130
  \item \isakeyword{files}~@{text "files"} lists additional source
wenzelm@48579
   131
  files that are somehow involved in the processing of this session.
wenzelm@48579
   132
  This should cover anything outside the formal content of the theory
wenzelm@48579
   133
  sources, say some auxiliary {\TeX} files that are required for
wenzelm@48579
   134
  document processing.  In contrast, files that are specified in
wenzelm@48579
   135
  formal theory headers as @{keyword "uses"} need not be declared
wenzelm@48579
   136
  again.
wenzelm@48579
   137
wenzelm@48579
   138
  \end{description}
wenzelm@48580
   139
*}
wenzelm@48579
   140
wenzelm@48580
   141
subsubsection {* Examples *}
wenzelm@48580
   142
wenzelm@48580
   143
text {* See @{file "~~/src/HOL/ROOT"} for a diversity of practically
wenzelm@48580
   144
  relevant situations. *}
wenzelm@48578
   145
wenzelm@48578
   146
wenzelm@48578
   147
section {* System build options \label{sec:system-options} *}
wenzelm@48578
   148
wenzelm@48580
   149
text {* See @{file "~~/etc/options"} for the main defaults provided by
wenzelm@48582
   150
  the Isabelle distribution.  Isabelle/jEdit (\secref{sec:tool-jedit})
wenzelm@48582
   151
  includes a simple editing mode @{verbatim "isabelle-options"} for
wenzelm@48582
   152
  this file-format.
wenzelm@48580
   153
*}
wenzelm@48578
   154
wenzelm@48578
   155
wenzelm@48578
   156
section {* Invoking the build process \label{sec:tool-build} *}
wenzelm@48578
   157
wenzelm@48602
   158
text {* The @{tool_def build} tool invokes the build process for
wenzelm@48578
   159
  Isabelle sessions.  It manages dependencies between sessions,
wenzelm@48578
   160
  related sources of theories and auxiliary files, and target heap
wenzelm@48578
   161
  images.  Accordingly, it runs instances of the prover process with
wenzelm@48578
   162
  optional document preparation.  Its command-line usage
wenzelm@48578
   163
  is:\footnote{Isabelle/Scala provides the same functionality via
wenzelm@48578
   164
  \texttt{isabelle.Build.build}.}
wenzelm@48602
   165
\begin{ttbox}
wenzelm@48602
   166
Usage: isabelle build [OPTIONS] [SESSIONS ...]
wenzelm@48578
   167
wenzelm@48578
   168
  Options are:
wenzelm@48578
   169
    -a           select all sessions
wenzelm@48578
   170
    -b           build heap images
wenzelm@48595
   171
    -c           clean build
wenzelm@48578
   172
    -d DIR       include session directory with ROOT file
wenzelm@48578
   173
    -g NAME      select session group NAME
wenzelm@48578
   174
    -j INT       maximum number of parallel jobs (default 1)
wenzelm@48578
   175
    -n           no build -- test dependencies only
wenzelm@48578
   176
    -o OPTION    override session configuration OPTION
wenzelm@48578
   177
                 (via NAME=VAL or NAME)
wenzelm@48578
   178
    -s           system build mode: produce output in ISABELLE_HOME
wenzelm@48578
   179
    -v           verbose
wenzelm@48578
   180
wenzelm@48578
   181
  Build and manage Isabelle sessions, depending on implicit
wenzelm@48578
   182
  ISABELLE_BUILD_OPTIONS="..."
wenzelm@48578
   183
wenzelm@48578
   184
  ML_PLATFORM="..."
wenzelm@48578
   185
  ML_HOME="..."
wenzelm@48578
   186
  ML_SYSTEM="..."
wenzelm@48578
   187
  ML_OPTIONS="..."
wenzelm@48578
   188
\end{ttbox}
wenzelm@48578
   189
wenzelm@48578
   190
  \medskip Isabelle sessions are defined via session ROOT files as
wenzelm@48578
   191
  described in (\secref{sec:session-root}).  The totality of sessions
wenzelm@48578
   192
  is determined by collecting such specifications from all Isabelle
wenzelm@48578
   193
  component directories (\secref{sec:components}), augmented by more
wenzelm@48578
   194
  directories given via options @{verbatim "-d"}~@{text "DIR"} on the
wenzelm@48578
   195
  command line.  Each such directory may contain a session
wenzelm@48578
   196
  \texttt{ROOT} file and an additional catalog file @{verbatim
wenzelm@48578
   197
  "etc/sessions"} with further sub-directories (list of lines).  Note
wenzelm@48578
   198
  that a single \texttt{ROOT} file usually defines many sessions;
haftmann@48591
   199
  catalogs are only required for extra scalability and modularity
wenzelm@48578
   200
  of large libraries.
wenzelm@48578
   201
wenzelm@48578
   202
  \medskip The subset of sessions to be managed is selected via
wenzelm@48578
   203
  individual @{text "SESSIONS"} given as command-line arguments, or
wenzelm@48578
   204
  session groups that are specified via one or more options @{verbatim
wenzelm@48578
   205
  "-g"}~@{text "NAME"}.  Option @{verbatim "-a"} selects all sessions.
wenzelm@48578
   206
  The build tool takes the hierarchy of sessions into account: the
wenzelm@48578
   207
  selected set of sessions is completed by including all ancestors
wenzelm@48578
   208
  according to the dependency structure.
wenzelm@48578
   209
wenzelm@48578
   210
  \medskip The build process depends on additional options that are
wenzelm@48578
   211
  passed to the prover session eventually, see also
wenzelm@48578
   212
  (\secref{sec:system-options}).  The settings variable @{setting_ref
wenzelm@48578
   213
  ISABELLE_BUILD_OPTIONS} allows to provide additional defaults.
wenzelm@48578
   214
  Moreover, the environment of system build options may be augmented
wenzelm@48578
   215
  on the command line via @{verbatim "-o"}~@{text "NAME=VALUE"} or
wenzelm@48578
   216
  @{verbatim "-o"}~@{text "NAME"}, which abbreviates @{verbatim
wenzelm@48578
   217
  "-o"}~@{text "NAME=true"} for Boolean options.  Multiple occurrences
wenzelm@48578
   218
  of @{verbatim "-o"} on the command-line are applied in the given
wenzelm@48578
   219
  order.
wenzelm@48578
   220
wenzelm@48578
   221
  \medskip Option @{verbatim "-b"} ensures that heap images are
wenzelm@48578
   222
  produced for all selected sessions.  By default, images are only
wenzelm@48578
   223
  saved for inner nodes of the hierarchy of sessions, as required for
wenzelm@48578
   224
  other sessions to continue later on.
wenzelm@48578
   225
wenzelm@48595
   226
  \medskip Option @{verbatim "-c"} cleans all descendants of the
wenzelm@48595
   227
  selected sessions before performing the specified build operation.
wenzelm@48595
   228
wenzelm@48595
   229
  \medskip Option @{verbatim "-n"} omits the actual build process
wenzelm@48595
   230
  after the preparatory stage (including optional cleanup).  Note that
wenzelm@48595
   231
  the return code always indicates the status of the set of selected
wenzelm@48595
   232
  sessions.
wenzelm@48595
   233
wenzelm@48578
   234
  \medskip Option @{verbatim "-j"} specifies the maximum number of
wenzelm@48578
   235
  parallel build jobs (prover processes).  Note that each process is
wenzelm@48578
   236
  subject to a separate limit of parallel threads, cf.\ system option
wenzelm@48578
   237
  @{system_option_ref threads}.
wenzelm@48578
   238
wenzelm@48578
   239
  \medskip Option @{verbatim "-s"} enables \emph{system mode}, which
wenzelm@48578
   240
  means that resulting heap images and log files are stored in
wenzelm@48578
   241
  @{verbatim "$ISABELLE_HOME/heaps"} instead of the default location
wenzelm@48578
   242
  @{setting ISABELLE_OUTPUT} (which is normally in @{setting
wenzelm@48578
   243
  ISABELLE_HOME_USER}, i.e.\ the user's home directory).
wenzelm@48578
   244
wenzelm@48578
   245
  \medskip Option @{verbatim "-v"} enables verbose mode.
wenzelm@48578
   246
*}
wenzelm@48578
   247
wenzelm@48578
   248
subsubsection {* Examples *}
wenzelm@48578
   249
wenzelm@48578
   250
text {*
wenzelm@48578
   251
  Build a specific logic image:
wenzelm@48578
   252
\begin{ttbox}
wenzelm@48578
   253
isabelle build -b HOLCF
wenzelm@48578
   254
\end{ttbox}
wenzelm@48578
   255
wenzelm@48595
   256
  \smallskip Build the main group of logic images (as determined by
wenzelm@48595
   257
  the session ROOT specifications of the Isabelle distribution):
wenzelm@48578
   258
\begin{ttbox}
wenzelm@48578
   259
isabelle build -b -g main
wenzelm@48578
   260
\end{ttbox}
wenzelm@48578
   261
wenzelm@48595
   262
  \smallskip Provide a general overview of the status of all Isabelle
wenzelm@48595
   263
  sessions, without building anything:
wenzelm@48578
   264
\begin{ttbox}
wenzelm@48578
   265
isabelle build -a -n -v
wenzelm@48578
   266
\end{ttbox}
wenzelm@48578
   267
wenzelm@48595
   268
  \smallskip Build all sessions with HTML browser info and PDF
wenzelm@48595
   269
  document preparation:
wenzelm@48578
   270
\begin{ttbox}
wenzelm@48578
   271
isabelle build -a -o browser_info -o document=pdf
wenzelm@48578
   272
\end{ttbox}
wenzelm@48578
   273
wenzelm@48595
   274
  \smallskip Build all sessions with a maximum of 8 prover processes
wenzelm@48595
   275
  and 4 threads each (on a machine with many cores):
wenzelm@48578
   276
\begin{ttbox}
wenzelm@48578
   277
isabelle build -a -j8 -o threads=4
wenzelm@48578
   278
\end{ttbox}
wenzelm@48595
   279
wenzelm@48595
   280
  \smallskip Build some session images with cleanup of their
wenzelm@48595
   281
  descendants, while retaining their ancestry:
wenzelm@48595
   282
\begin{ttbox}
wenzelm@48595
   283
isabelle build -b -c HOL-Boogie HOL-SPARK
wenzelm@48595
   284
\end{ttbox}
wenzelm@48595
   285
wenzelm@48595
   286
  \smallskip Clean all sessions without building anything:
wenzelm@48595
   287
\begin{ttbox}
wenzelm@48595
   288
isabelle build -a -n -c
wenzelm@48595
   289
\end{ttbox}
wenzelm@48578
   290
*}
wenzelm@48578
   291
wenzelm@48578
   292
end