src/Pure/Thy/export_theory.scala
changeset 75774 efc25bf4b795
parent 75769 4d27b520622a
child 75790 0ab8a9177e41
equal deleted inserted replaced
75773:11b2bf6f90d8 75774:efc25bf4b795
    23     def theories: List[Theory] =
    23     def theories: List[Theory] =
    24       theory_graph.topological_order.flatMap(theory)
    24       theory_graph.topological_order.flatMap(theory)
    25   }
    25   }
    26 
    26 
    27   def read_session(
    27   def read_session(
    28     store: Sessions.Store,
    28     session_context: Export.Session_Context,
    29     sessions_structure: Sessions.Structure,
       
    30     session_name: String,
       
    31     progress: Progress = new Progress,
    29     progress: Progress = new Progress,
    32     cache: Term.Cache = Term.Cache.make()): Session = {
    30     cache: Term.Cache = Term.Cache.make()
       
    31   ): Session = {
    33     val thys =
    32     val thys =
    34       sessions_structure.build_requirements(List(session_name)).flatMap(session =>
    33       for (theory <- session_context.theory_names()) yield {
    35         using(store.open_database(session)) { db =>
    34         progress.echo("Reading theory " + theory)
    36           val provider = Export.Provider.database(db, store.cache, session)
    35         read_theory(session_context.theory(theory), cache = cache)
    37           for (theory <- provider.theory_names)
    36       }
    38           yield {
       
    39             progress.echo("Reading theory " + theory)
       
    40             read_theory(provider, session, theory, cache = cache)
       
    41           }
       
    42         })
       
    43 
    37 
    44     val graph0 =
    38     val graph0 =
    45       thys.foldLeft(Graph.string[Option[Theory]]) {
    39       thys.foldLeft(Graph.string[Option[Theory]]) {
    46         case (g, thy) => g.default_node(thy.name, Some(thy))
    40         case (g, thy) => g.default_node(thy.name, Some(thy))
    47       }
    41       }
    51           thy.parents.foldLeft(g0) {
    45           thy.parents.foldLeft(g0) {
    52             case (g1, parent) => g1.default_node(parent, None).add_edge_acyclic(parent, thy.name)
    46             case (g1, parent) => g1.default_node(parent, None).add_edge_acyclic(parent, thy.name)
    53           }
    47           }
    54       }
    48       }
    55 
    49 
    56     Session(session_name, graph1)
    50     Session(session_context.session_name, graph1)
    57   }
    51   }
    58 
    52 
    59 
    53 
    60 
    54 
    61   /** theory content **/
    55   /** theory content **/
   105         datatypes.map(_.cache(cache)),
    99         datatypes.map(_.cache(cache)),
   106         spec_rules.map(_.cache(cache)),
   100         spec_rules.map(_.cache(cache)),
   107         (for ((k, xs) <- others.iterator) yield cache.string(k) -> xs.map(_.cache(cache))).toMap)
   101         (for ((k, xs) <- others.iterator) yield cache.string(k) -> xs.map(_.cache(cache))).toMap)
   108   }
   102   }
   109 
   103 
   110   def read_theory_parents(provider: Export.Provider, theory_name: String): Option[List[String]] =
   104   def read_theory_parents(theory_context: Export.Theory_Context): Option[List[String]] =
   111     provider.focus(theory_name)(Export.THEORY_PARENTS)
   105     theory_context.get(Export.THEORY_PARENTS)
   112       .map(entry => Library.trim_split_lines(entry.uncompressed.text))
   106       .map(entry => Library.trim_split_lines(entry.uncompressed.text))
   113 
   107 
   114   def no_theory: Theory =
   108   def no_theory: Theory =
   115     Theory("", Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Map.empty)
   109     Theory("", Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Map.empty)
   116 
   110 
   117   def read_theory(
   111   def read_theory(
   118     provider: Export.Provider,
   112     theory_context: Export.Theory_Context,
   119     session_name: String,
       
   120     theory_name: String,
       
   121     permissive: Boolean = false,
   113     permissive: Boolean = false,
   122     cache: Term.Cache = Term.Cache.none
   114     cache: Term.Cache = Term.Cache.none
   123   ): Theory = {
   115   ): Theory = {
   124     val theory_provider = provider.focus(theory_name)
   116     val session_name = theory_context.session_context.session_name
   125     read_theory_parents(theory_provider, theory_name) match {
   117     val theory_name = theory_context.theory
       
   118     read_theory_parents(theory_context) match {
   126       case None if permissive => no_theory
   119       case None if permissive => no_theory
   127       case None =>
   120       case None =>
   128         error("Missing theory export in session " + quote(session_name) + ": " + quote(theory_name))
   121         error("Missing theory export in session " + quote(session_name) + ": " + quote(theory_name))
   129       case Some(parents) =>
   122       case Some(parents) =>
   130         val theory =
   123         val theory =
   131           Theory(theory_name, parents,
   124           Theory(theory_name, parents,
   132             read_types(theory_provider),
   125             read_types(theory_context),
   133             read_consts(theory_provider),
   126             read_consts(theory_context),
   134             read_axioms(theory_provider),
   127             read_axioms(theory_context),
   135             read_thms(theory_provider),
   128             read_thms(theory_context),
   136             read_classes(theory_provider),
   129             read_classes(theory_context),
   137             read_locales(theory_provider),
   130             read_locales(theory_context),
   138             read_locale_dependencies(theory_provider),
   131             read_locale_dependencies(theory_context),
   139             read_classrel(theory_provider),
   132             read_classrel(theory_context),
   140             read_arities(theory_provider),
   133             read_arities(theory_context),
   141             read_constdefs(theory_provider),
   134             read_constdefs(theory_context),
   142             read_typedefs(theory_provider),
   135             read_typedefs(theory_context),
   143             read_datatypes(theory_provider),
   136             read_datatypes(theory_context),
   144             read_spec_rules(theory_provider),
   137             read_spec_rules(theory_context),
   145             read_others(theory_provider))
   138             read_others(theory_context))
   146         if (cache.no_cache) theory else theory.cache(cache)
   139         if (cache.no_cache) theory else theory.cache(cache)
   147     }
   140     }
   148   }
   141   }
   149 
       
   150   def read_pure[A](store: Sessions.Store, read: (Export.Provider, String, String) => A): A = {
       
   151     val session_name = Thy_Header.PURE
       
   152     val theory_name = Thy_Header.PURE
       
   153 
       
   154     using(store.open_database(session_name)) { db =>
       
   155       val provider = Export.Provider.database(db, store.cache, session_name)
       
   156       read(provider, session_name, theory_name)
       
   157     }
       
   158   }
       
   159 
       
   160   def read_pure_theory(store: Sessions.Store, cache: Term.Cache = Term.Cache.none): Theory =
       
   161     read_pure(store, read_theory(_, _, _, cache = cache))
       
   162 
       
   163   def read_pure_proof(
       
   164       store: Sessions.Store, id: Thm_Id, cache: Term.Cache = Term.Cache.none): Option[Proof] =
       
   165     read_pure(store, (provider, _, _) => read_proof(provider, id, cache = cache))
       
   166 
   142 
   167 
   143 
   168   /* entities */
   144   /* entities */
   169 
   145 
   170   object Kind {
   146   object Kind {
   223         content.map(_.cache(cache)))
   199         content.map(_.cache(cache)))
   224   }
   200   }
   225   type Entity0 = Entity[No_Content]
   201   type Entity0 = Entity[No_Content]
   226 
   202 
   227   def read_entities[A <: Content[A]](
   203   def read_entities[A <: Content[A]](
   228     provider: Export.Provider,
   204     theory_context: Export.Theory_Context,
   229     export_name: String,
   205     export_name: String,
   230     kind: String,
   206     kind: String,
   231     decode: XML.Decode.T[A]
   207     decode: XML.Decode.T[A]
   232   ): List[Entity[A]] = {
   208   ): List[Entity[A]] = {
   233     def decode_entity(tree: XML.Tree): Entity[A] = {
   209     def decode_entity(tree: XML.Tree): Entity[A] = {
   243           val content = if (body.isEmpty) None else Some(decode(body))
   219           val content = if (body.isEmpty) None else Some(decode(body))
   244           Entity(kind, name, xname, pos, id, serial, content)
   220           Entity(kind, name, xname, pos, id, serial, content)
   245         case _ => err()
   221         case _ => err()
   246       }
   222       }
   247     }
   223     }
   248     provider.uncompressed_yxml(export_name).map(decode_entity)
   224     theory_context.uncompressed_yxml(export_name).map(decode_entity)
   249   }
   225   }
   250 
   226 
   251 
   227 
   252   /* approximative syntax */
   228   /* approximative syntax */
   253 
   229 
   279         syntax,
   255         syntax,
   280         args.map(cache.string),
   256         args.map(cache.string),
   281         abbrev.map(cache.typ))
   257         abbrev.map(cache.typ))
   282   }
   258   }
   283 
   259 
   284   def read_types(provider: Export.Provider): List[Entity[Type]] =
   260   def read_types(theory_context: Export.Theory_Context): List[Entity[Type]] =
   285     read_entities(provider, Export.THEORY_PREFIX + "types", Markup.TYPE_NAME,
   261     read_entities(theory_context, Export.THEORY_PREFIX + "types", Markup.TYPE_NAME,
   286       { body =>
   262       { body =>
   287         import XML.Decode._
   263         import XML.Decode._
   288         val (syntax, args, abbrev) =
   264         val (syntax, args, abbrev) =
   289           triple(decode_syntax, list(string), option(Term_XML.Decode.typ))(body)
   265           triple(decode_syntax, list(string), option(Term_XML.Decode.typ))(body)
   290         Type(syntax, args, abbrev)
   266         Type(syntax, args, abbrev)
   307         cache.typ(typ),
   283         cache.typ(typ),
   308         abbrev.map(cache.term),
   284         abbrev.map(cache.term),
   309         propositional)
   285         propositional)
   310   }
   286   }
   311 
   287 
   312   def read_consts(provider: Export.Provider): List[Entity[Const]] =
   288   def read_consts(theory_context: Export.Theory_Context): List[Entity[Const]] =
   313     read_entities(provider, Export.THEORY_PREFIX + "consts", Markup.CONSTANT,
   289     read_entities(theory_context, Export.THEORY_PREFIX + "consts", Markup.CONSTANT,
   314       { body =>
   290       { body =>
   315         import XML.Decode._
   291         import XML.Decode._
   316         val (syntax, (typargs, (typ, (abbrev, propositional)))) =
   292         val (syntax, (typargs, (typ, (abbrev, propositional)))) =
   317           pair(decode_syntax,
   293           pair(decode_syntax,
   318             pair(list(string),
   294             pair(list(string),
   347 
   323 
   348   sealed case class Axiom(prop: Prop) extends Content[Axiom] {
   324   sealed case class Axiom(prop: Prop) extends Content[Axiom] {
   349     override def cache(cache: Term.Cache): Axiom = Axiom(prop.cache(cache))
   325     override def cache(cache: Term.Cache): Axiom = Axiom(prop.cache(cache))
   350   }
   326   }
   351 
   327 
   352   def read_axioms(provider: Export.Provider): List[Entity[Axiom]] =
   328   def read_axioms(theory_context: Export.Theory_Context): List[Entity[Axiom]] =
   353     read_entities(provider, Export.THEORY_PREFIX + "axioms", Markup.AXIOM,
   329     read_entities(theory_context, Export.THEORY_PREFIX + "axioms", Markup.AXIOM,
   354       body => Axiom(decode_prop(body)))
   330       body => Axiom(decode_prop(body)))
   355 
   331 
   356 
   332 
   357   /* theorems */
   333   /* theorems */
   358 
   334 
   359   sealed case class Thm_Id(serial: Long, theory_name: String) {
   335   sealed case class Thm_Id(serial: Long, theory_name: String)
   360     def pure: Boolean = theory_name == Thy_Header.PURE
       
   361   }
       
   362 
   336 
   363   sealed case class Thm(
   337   sealed case class Thm(
   364     prop: Prop,
   338     prop: Prop,
   365     deps: List[String],
   339     deps: List[String],
   366     proof: Term.Proof)
   340     proof: Term.Proof)
   370         prop.cache(cache),
   344         prop.cache(cache),
   371         deps.map(cache.string),
   345         deps.map(cache.string),
   372         cache.proof(proof))
   346         cache.proof(proof))
   373   }
   347   }
   374 
   348 
   375   def read_thms(provider: Export.Provider): List[Entity[Thm]] =
   349   def read_thms(theory_context: Export.Theory_Context): List[Entity[Thm]] =
   376     read_entities(provider, Export.THEORY_PREFIX + "thms", Kind.THM,
   350     read_entities(theory_context, Export.THEORY_PREFIX + "thms", Kind.THM,
   377       { body =>
   351       { body =>
   378         import XML.Decode._
   352         import XML.Decode._
   379         import Term_XML.Decode._
   353         import Term_XML.Decode._
   380         val (prop, deps, prf) = triple(decode_prop, list(string), proof)(body)
   354         val (prop, deps, prf) = triple(decode_prop, list(string), proof)(body)
   381         Thm(prop, deps, prf)
   355         Thm(prop, deps, prf)
   396         cache.term(term),
   370         cache.term(term),
   397         cache.proof(proof))
   371         cache.proof(proof))
   398   }
   372   }
   399 
   373 
   400   def read_proof(
   374   def read_proof(
   401     provider: Export.Provider,
   375     session_context: Export.Session_Context,
   402     id: Thm_Id,
   376     id: Thm_Id,
   403     cache: Term.Cache = Term.Cache.none
   377     cache: Term.Cache = Term.Cache.none
   404   ): Option[Proof] = {
   378   ): Option[Proof] = {
   405     for { entry <- provider.focus(id.theory_name)(Export.PROOFS_PREFIX + id.serial) }
   379     val theory_context = session_context.theory(id.theory_name)
       
   380     for { entry <- theory_context.get(Export.PROOFS_PREFIX + id.serial) }
   406     yield {
   381     yield {
   407       val body = entry.uncompressed_yxml
   382       val body = entry.uncompressed_yxml
   408       val (typargs, (args, (prop_body, proof_body))) = {
   383       val (typargs, (args, (prop_body, proof_body))) = {
   409         import XML.Decode._
   384         import XML.Decode._
   410         import Term_XML.Decode._
   385         import Term_XML.Decode._
   418       if (cache.no_cache) result else result.cache(cache)
   393       if (cache.no_cache) result else result.cache(cache)
   419     }
   394     }
   420   }
   395   }
   421 
   396 
   422   def read_proof_boxes(
   397   def read_proof_boxes(
   423     store: Sessions.Store,
   398     session_context: Export.Session_Context,
   424     provider: Export.Provider,
       
   425     proof: Term.Proof,
   399     proof: Term.Proof,
   426     suppress: Thm_Id => Boolean = _ => false,
   400     suppress: Thm_Id => Boolean = _ => false,
   427     cache: Term.Cache = Term.Cache.none
   401     cache: Term.Cache = Term.Cache.none
   428   ): List[(Thm_Id, Proof)] = {
   402   ): List[(Thm_Id, Proof)] = {
   429     var seen = Set.empty[Long]
   403     var seen = Set.empty[Long]
   437         case Term.AppP(p, q) => boxes(context, p); boxes(context, q)
   411         case Term.AppP(p, q) => boxes(context, p); boxes(context, q)
   438         case thm: Term.PThm if !seen(thm.serial) =>
   412         case thm: Term.PThm if !seen(thm.serial) =>
   439           seen += thm.serial
   413           seen += thm.serial
   440           val id = Thm_Id(thm.serial, thm.theory_name)
   414           val id = Thm_Id(thm.serial, thm.theory_name)
   441           if (!suppress(id)) {
   415           if (!suppress(id)) {
   442             val read =
   416             Export_Theory.read_proof(session_context, id, cache = cache) match {
   443               if (id.pure) Export_Theory.read_pure_proof(store, id, cache = cache)
       
   444               else Export_Theory.read_proof(provider, id, cache = cache)
       
   445             read match {
       
   446               case Some(p) =>
   417               case Some(p) =>
   447                 result += (thm.serial -> (id -> p))
   418                 result += (thm.serial -> (id -> p))
   448                 boxes(Some((thm.serial, p.proof)), p.proof)
   419                 boxes(Some((thm.serial, p.proof)), p.proof)
   449               case None =>
   420               case None =>
   450                 error("Missing proof " + thm.serial + " (theory " + quote (thm.theory_name) + ")" +
   421                 error("Missing proof " + thm.serial + " (theory " + quote (thm.theory_name) + ")" +
   471       Class(
   442       Class(
   472         params.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
   443         params.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
   473         axioms.map(_.cache(cache)))
   444         axioms.map(_.cache(cache)))
   474   }
   445   }
   475 
   446 
   476   def read_classes(provider: Export.Provider): List[Entity[Class]] =
   447   def read_classes(theory_context: Export.Theory_Context): List[Entity[Class]] =
   477     read_entities(provider, Export.THEORY_PREFIX + "classes", Markup.CLASS,
   448     read_entities(theory_context, Export.THEORY_PREFIX + "classes", Markup.CLASS,
   478       { body =>
   449       { body =>
   479         import XML.Decode._
   450         import XML.Decode._
   480         import Term_XML.Decode._
   451         import Term_XML.Decode._
   481         val (params, axioms) = pair(list(pair(string, typ)), list(decode_prop))(body)
   452         val (params, axioms) = pair(list(pair(string, typ)), list(decode_prop))(body)
   482         Class(params, axioms)
   453         Class(params, axioms)
   495         typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
   466         typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
   496         args.map({ case ((name, typ), syntax) => ((cache.string(name), cache.typ(typ)), syntax) }),
   467         args.map({ case ((name, typ), syntax) => ((cache.string(name), cache.typ(typ)), syntax) }),
   497         axioms.map(_.cache(cache)))
   468         axioms.map(_.cache(cache)))
   498   }
   469   }
   499 
   470 
   500   def read_locales(provider: Export.Provider): List[Entity[Locale]] =
   471   def read_locales(theory_context: Export.Theory_Context): List[Entity[Locale]] =
   501     read_entities(provider, Export.THEORY_PREFIX + "locales", Markup.LOCALE,
   472     read_entities(theory_context, Export.THEORY_PREFIX + "locales", Markup.LOCALE,
   502       { body =>
   473       { body =>
   503         import XML.Decode._
   474         import XML.Decode._
   504         import Term_XML.Decode._
   475         import Term_XML.Decode._
   505         val (typargs, args, axioms) =
   476         val (typargs, args, axioms) =
   506           triple(list(pair(string, sort)), list(pair(pair(string, typ), decode_syntax)),
   477           triple(list(pair(string, sort)), list(pair(pair(string, typ), decode_syntax)),
   528 
   499 
   529     def is_inclusion: Boolean =
   500     def is_inclusion: Boolean =
   530       subst_types.isEmpty && subst_terms.isEmpty
   501       subst_types.isEmpty && subst_terms.isEmpty
   531   }
   502   }
   532 
   503 
   533   def read_locale_dependencies(provider: Export.Provider): List[Entity[Locale_Dependency]] =
   504   def read_locale_dependencies(
   534     read_entities(provider, Export.THEORY_PREFIX + "locale_dependencies", Kind.LOCALE_DEPENDENCY,
   505     theory_context: Export.Theory_Context
       
   506   ): List[Entity[Locale_Dependency]] = {
       
   507     read_entities(theory_context, Export.THEORY_PREFIX + "locale_dependencies",
       
   508       Kind.LOCALE_DEPENDENCY,
   535       { body =>
   509       { body =>
   536         import XML.Decode._
   510         import XML.Decode._
   537         import Term_XML.Decode._
   511         import Term_XML.Decode._
   538         val (source, (target, (prefix, (subst_types, subst_terms)))) =
   512         val (source, (target, (prefix, (subst_types, subst_terms)))) =
   539           pair(string, pair(string, pair(list(pair(string, bool)),
   513           pair(string, pair(string, pair(list(pair(string, bool)),
   540             pair(list(pair(pair(string, sort), typ)), list(pair(pair(string, typ), term))))))(body)
   514             pair(list(pair(pair(string, sort), typ)), list(pair(pair(string, typ), term))))))(body)
   541         Locale_Dependency(source, target, prefix, subst_types, subst_terms)
   515         Locale_Dependency(source, target, prefix, subst_types, subst_terms)
   542       })
   516       })
       
   517   }
   543 
   518 
   544 
   519 
   545   /* sort algebra */
   520   /* sort algebra */
   546 
   521 
   547   sealed case class Classrel(class1: String, class2: String, prop: Prop) {
   522   sealed case class Classrel(class1: String, class2: String, prop: Prop) {
   548     def cache(cache: Term.Cache): Classrel =
   523     def cache(cache: Term.Cache): Classrel =
   549       Classrel(cache.string(class1), cache.string(class2), prop.cache(cache))
   524       Classrel(cache.string(class1), cache.string(class2), prop.cache(cache))
   550   }
   525   }
   551 
   526 
   552   def read_classrel(provider: Export.Provider): List[Classrel] = {
   527   def read_classrel(theory_context: Export.Theory_Context): List[Classrel] = {
   553     val body = provider.uncompressed_yxml(Export.THEORY_PREFIX + "classrel")
   528     val body = theory_context.uncompressed_yxml(Export.THEORY_PREFIX + "classrel")
   554     val classrel = {
   529     val classrel = {
   555       import XML.Decode._
   530       import XML.Decode._
   556       list(pair(decode_prop, pair(string, string)))(body)
   531       list(pair(decode_prop, pair(string, string)))(body)
   557     }
   532     }
   558     for ((prop, (c1, c2)) <- classrel) yield Classrel(c1, c2, prop)
   533     for ((prop, (c1, c2)) <- classrel) yield Classrel(c1, c2, prop)
   567     def cache(cache: Term.Cache): Arity =
   542     def cache(cache: Term.Cache): Arity =
   568       Arity(cache.string(type_name), domain.map(cache.sort), cache.string(codomain),
   543       Arity(cache.string(type_name), domain.map(cache.sort), cache.string(codomain),
   569         prop.cache(cache))
   544         prop.cache(cache))
   570   }
   545   }
   571 
   546 
   572   def read_arities(provider: Export.Provider): List[Arity] = {
   547   def read_arities(theory_context: Export.Theory_Context): List[Arity] = {
   573     val body = provider.uncompressed_yxml(Export.THEORY_PREFIX + "arities")
   548     val body = theory_context.uncompressed_yxml(Export.THEORY_PREFIX + "arities")
   574     val arities = {
   549     val arities = {
   575       import XML.Decode._
   550       import XML.Decode._
   576       import Term_XML.Decode._
   551       import Term_XML.Decode._
   577       list(pair(decode_prop, triple(string, list(sort), string)))(body)
   552       list(pair(decode_prop, triple(string, list(sort), string)))(body)
   578     }
   553     }
   585   sealed case class Constdef(name: String, axiom_name: String) {
   560   sealed case class Constdef(name: String, axiom_name: String) {
   586     def cache(cache: Term.Cache): Constdef =
   561     def cache(cache: Term.Cache): Constdef =
   587       Constdef(cache.string(name), cache.string(axiom_name))
   562       Constdef(cache.string(name), cache.string(axiom_name))
   588   }
   563   }
   589 
   564 
   590   def read_constdefs(provider: Export.Provider): List[Constdef] = {
   565   def read_constdefs(theory_context: Export.Theory_Context): List[Constdef] = {
   591     val body = provider.uncompressed_yxml(Export.THEORY_PREFIX + "constdefs")
   566     val body = theory_context.uncompressed_yxml(Export.THEORY_PREFIX + "constdefs")
   592     val constdefs = {
   567     val constdefs = {
   593       import XML.Decode._
   568       import XML.Decode._
   594       list(pair(string, string))(body)
   569       list(pair(string, string))(body)
   595     }
   570     }
   596     for ((name, axiom_name) <- constdefs) yield Constdef(name, axiom_name)
   571     for ((name, axiom_name) <- constdefs) yield Constdef(name, axiom_name)
   614         cache.string(rep_name),
   589         cache.string(rep_name),
   615         cache.string(abs_name),
   590         cache.string(abs_name),
   616         cache.string(axiom_name))
   591         cache.string(axiom_name))
   617   }
   592   }
   618 
   593 
   619   def read_typedefs(provider: Export.Provider): List[Typedef] = {
   594   def read_typedefs(theory_context: Export.Theory_Context): List[Typedef] = {
   620     val body = provider.uncompressed_yxml(Export.THEORY_PREFIX + "typedefs")
   595     val body = theory_context.uncompressed_yxml(Export.THEORY_PREFIX + "typedefs")
   621     val typedefs = {
   596     val typedefs = {
   622       import XML.Decode._
   597       import XML.Decode._
   623       import Term_XML.Decode._
   598       import Term_XML.Decode._
   624       list(pair(string, pair(typ, pair(typ, pair(string, pair(string, string))))))(body)
   599       list(pair(string, pair(typ, pair(typ, pair(string, pair(string, string))))))(body)
   625     }
   600     }
   648         typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
   623         typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
   649         cache.typ(typ),
   624         cache.typ(typ),
   650         constructors.map({ case (term, typ) => (cache.term(term), cache.typ(typ)) }))
   625         constructors.map({ case (term, typ) => (cache.term(term), cache.typ(typ)) }))
   651   }
   626   }
   652 
   627 
   653   def read_datatypes(provider: Export.Provider): List[Datatype] = {
   628   def read_datatypes(theory_context: Export.Theory_Context): List[Datatype] = {
   654     val body = provider.uncompressed_yxml(Export.THEORY_PREFIX + "datatypes")
   629     val body = theory_context.uncompressed_yxml(Export.THEORY_PREFIX + "datatypes")
   655     val datatypes = {
   630     val datatypes = {
   656       import XML.Decode._
   631       import XML.Decode._
   657       import Term_XML.Decode._
   632       import Term_XML.Decode._
   658       list(pair(properties, pair(string, pair(bool, pair(list(pair(string, sort)),
   633       list(pair(properties, pair(string, pair(bool, pair(list(pair(string, sort)),
   659             pair(typ, list(pair(term, typ))))))))(body)
   634             pair(typ, list(pair(term, typ))))))))(body)
   738         args.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
   713         args.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
   739         terms.map({ case (term, typ) => (cache.term(term), cache.typ(typ)) }),
   714         terms.map({ case (term, typ) => (cache.term(term), cache.typ(typ)) }),
   740         rules.map(cache.term))
   715         rules.map(cache.term))
   741   }
   716   }
   742 
   717 
   743   def read_spec_rules(provider: Export.Provider): List[Spec_Rule] = {
   718   def read_spec_rules(theory_context: Export.Theory_Context): List[Spec_Rule] = {
   744     val body = provider.uncompressed_yxml(Export.THEORY_PREFIX + "spec_rules")
   719     val body = theory_context.uncompressed_yxml(Export.THEORY_PREFIX + "spec_rules")
   745     val spec_rules = {
   720     val spec_rules = {
   746       import XML.Decode._
   721       import XML.Decode._
   747       import Term_XML.Decode._
   722       import Term_XML.Decode._
   748       list(
   723       list(
   749         pair(properties, pair(string, pair(decode_rough_classification,
   724         pair(properties, pair(string, pair(decode_rough_classification,
   759 
   734 
   760   sealed case class Other() extends Content[Other] {
   735   sealed case class Other() extends Content[Other] {
   761     override def cache(cache: Term.Cache): Other = this
   736     override def cache(cache: Term.Cache): Other = this
   762   }
   737   }
   763 
   738 
   764   def read_others(provider: Export.Provider): Map[String, List[Entity[Other]]] = {
   739   def read_others(theory_context: Export.Theory_Context): Map[String, List[Entity[Other]]] = {
   765     val kinds =
   740     val kinds =
   766       provider(Export.THEORY_PREFIX + "other_kinds") match {
   741       theory_context.get(Export.THEORY_PREFIX + "other_kinds") match {
   767         case Some(entry) => split_lines(entry.uncompressed.text)
   742         case Some(entry) => split_lines(entry.uncompressed.text)
   768         case None => Nil
   743         case None => Nil
   769       }
   744       }
   770     val other = Other()
   745     val other = Other()
   771     def read_other(kind: String): List[Entity[Other]] =
   746     def read_other(kind: String): List[Entity[Other]] =
   772       read_entities(provider, Export.THEORY_PREFIX + "other/" + kind, kind, _ => other)
   747       read_entities(theory_context, Export.THEORY_PREFIX + "other/" + kind, kind, _ => other)
   773 
   748 
   774     kinds.map(kind => kind -> read_other(kind)).toMap
   749     kinds.map(kind => kind -> read_other(kind)).toMap
   775   }
   750   }
   776 }
   751 }