optionally ignore errors during translation of equations; tuned representation of abstraction points
authorhaftmann
Wed Apr 21 15:20:59 2010 +0200 (2010-04-21)
changeset 362724d358c582ffb
parent 36271 2ef9dbddfcb8
child 36273 283c84ee7db9
optionally ignore errors during translation of equations; tuned representation of abstraction points
src/Tools/Code/code_thingol.ML
     1.1 --- a/src/Tools/Code/code_thingol.ML	Wed Apr 21 15:20:57 2010 +0200
     1.2 +++ b/src/Tools/Code/code_thingol.ML	Wed Apr 21 15:20:59 2010 +0200
     1.3 @@ -87,7 +87,7 @@
     1.4        * ((string * stmt) list * (string * stmt) list)) list
     1.5  
     1.6    val read_const_exprs: theory -> string list -> string list * string list
     1.7 -  val consts_program: theory -> string list -> string list * (naming * program)
     1.8 +  val consts_program: theory -> bool -> string list -> string list * (naming * program)
     1.9    val eval_conv: theory
    1.10      -> (naming -> program -> ((string * sort) list * typscheme) * iterm -> string list -> cterm -> thm)
    1.11      -> cterm -> thm
    1.12 @@ -523,50 +523,53 @@
    1.13          |> pair name
    1.14    end;
    1.15  
    1.16 -fun translation_error thy some_thm msg sub_msg =
    1.17 -  let
    1.18 +exception PERMISSIVE of unit;
    1.19 +
    1.20 +fun translation_error thy permissive some_thm msg sub_msg =
    1.21 +  if permissive
    1.22 +  then raise PERMISSIVE ()
    1.23 +  else let
    1.24      val err_thm = case some_thm
    1.25 -     of SOME thm => "\n(in code equation " ^ Display.string_of_thm_global thy thm ^ ")" | NONE => "";
    1.26 +     of SOME thm => "\n(in code equation " ^ Display.string_of_thm_global thy thm ^ ")"
    1.27 +      | NONE => "";
    1.28    in error (msg ^ err_thm ^ ":\n" ^ sub_msg) end;
    1.29  
    1.30 -fun not_wellsorted thy some_thm ty sort e =
    1.31 +fun not_wellsorted thy permissive some_thm ty sort e =
    1.32    let
    1.33      val err_class = Sorts.class_error (Syntax.pp_global thy) e;
    1.34      val err_typ = "Type " ^ Syntax.string_of_typ_global thy ty ^ " not of sort "
    1.35        ^ Syntax.string_of_sort_global thy sort;
    1.36 -  in translation_error thy some_thm "Wellsortedness error" (err_typ ^ "\n" ^ err_class) end;
    1.37 +  in translation_error thy permissive some_thm "Wellsortedness error" (err_typ ^ "\n" ^ err_class) end;
    1.38  
    1.39  
    1.40  (* translation *)
    1.41  
    1.42 -fun ensure_tyco thy algbr eqngr tyco =
    1.43 +fun ensure_tyco thy algbr eqngr permissive tyco =
    1.44    let
    1.45 +    val (vs, cos) = Code.get_type thy tyco;
    1.46      val stmt_datatype =
    1.47 -      let
    1.48 -        val (vs, cos) = Code.get_type thy tyco;
    1.49 -      in
    1.50 -        fold_map (translate_tyvar_sort thy algbr eqngr) vs
    1.51 -        ##>> fold_map (fn (c, tys) =>
    1.52 -          ensure_const thy algbr eqngr c
    1.53 -          ##>> fold_map (translate_typ thy algbr eqngr) tys) cos
    1.54 -        #>> (fn info => Datatype (tyco, info))
    1.55 -      end;
    1.56 +      fold_map (translate_tyvar_sort thy algbr eqngr permissive) vs
    1.57 +      ##>> fold_map (fn (c, tys) =>
    1.58 +        ensure_const thy algbr eqngr permissive c
    1.59 +        ##>> fold_map (translate_typ thy algbr eqngr permissive) tys) cos
    1.60 +      #>> (fn info => Datatype (tyco, info));
    1.61    in ensure_stmt lookup_tyco (declare_tyco thy) stmt_datatype tyco end
    1.62 -and ensure_const thy algbr eqngr c =
    1.63 +and ensure_const thy algbr eqngr permissive c =
    1.64    let
    1.65      fun stmt_datatypecons tyco =
    1.66 -      ensure_tyco thy algbr eqngr tyco
    1.67 +      ensure_tyco thy algbr eqngr permissive tyco
    1.68        #>> (fn tyco => Datatypecons (c, tyco));
    1.69      fun stmt_classparam class =
    1.70 -      ensure_class thy algbr eqngr class
    1.71 +      ensure_class thy algbr eqngr permissive class
    1.72        #>> (fn class => Classparam (c, class));
    1.73      fun stmt_fun cert =
    1.74        let
    1.75          val ((vs, ty), eqns) = Code.equations_of_cert thy cert;
    1.76        in
    1.77 -        fold_map (translate_tyvar_sort thy algbr eqngr) vs
    1.78 -        ##>> translate_typ thy algbr eqngr ty
    1.79 -        ##>> fold_map (translate_eqn thy algbr eqngr) eqns
    1.80 +        fold_map (translate_tyvar_sort thy algbr eqngr permissive) vs
    1.81 +        ##>> translate_typ thy algbr eqngr permissive ty
    1.82 +        ##>> (fold_map (translate_equation thy algbr eqngr permissive) eqns
    1.83 +          #>> map_filter I)
    1.84          #>> (fn info => Fun (c, info))
    1.85        end;
    1.86      val stmt_const = case Code.get_type_of_constr_or_abstr thy c
    1.87 @@ -575,25 +578,25 @@
    1.88           of SOME class => stmt_classparam class
    1.89            | NONE => stmt_fun (Code_Preproc.cert eqngr c))
    1.90    in ensure_stmt lookup_const (declare_const thy) stmt_const c end
    1.91 -and ensure_class thy (algbr as (_, algebra)) eqngr class =
    1.92 +and ensure_class thy (algbr as (_, algebra)) eqngr permissive class =
    1.93    let
    1.94      val superclasses = (Sorts.minimize_sort algebra o Sorts.super_classes algebra) class;
    1.95      val cs = #params (AxClass.get_info thy class);
    1.96      val stmt_class =
    1.97 -      fold_map (fn superclass => ensure_class thy algbr eqngr superclass
    1.98 -        ##>> ensure_classrel thy algbr eqngr (class, superclass)) superclasses
    1.99 -      ##>> fold_map (fn (c, ty) => ensure_const thy algbr eqngr c
   1.100 -        ##>> translate_typ thy algbr eqngr ty) cs
   1.101 +      fold_map (fn superclass => ensure_class thy algbr eqngr permissive superclass
   1.102 +        ##>> ensure_classrel thy algbr eqngr permissive (class, superclass)) superclasses
   1.103 +      ##>> fold_map (fn (c, ty) => ensure_const thy algbr eqngr permissive c
   1.104 +        ##>> translate_typ thy algbr eqngr permissive ty) cs
   1.105        #>> (fn info => Class (class, (unprefix "'" Name.aT, info)))
   1.106    in ensure_stmt lookup_class (declare_class thy) stmt_class class end
   1.107 -and ensure_classrel thy algbr eqngr (subclass, superclass) =
   1.108 +and ensure_classrel thy algbr eqngr permissive (subclass, superclass) =
   1.109    let
   1.110      val stmt_classrel =
   1.111 -      ensure_class thy algbr eqngr subclass
   1.112 -      ##>> ensure_class thy algbr eqngr superclass
   1.113 +      ensure_class thy algbr eqngr permissive subclass
   1.114 +      ##>> ensure_class thy algbr eqngr permissive superclass
   1.115        #>> Classrel;
   1.116    in ensure_stmt lookup_classrel (declare_classrel thy) stmt_classrel (subclass, superclass) end
   1.117 -and ensure_inst thy (algbr as (_, algebra)) eqngr (class, tyco) =
   1.118 +and ensure_inst thy (algbr as (_, algebra)) eqngr permissive (class, tyco) =
   1.119    let
   1.120      val superclasses = (Sorts.minimize_sort algebra o Sorts.super_classes algebra) class;
   1.121      val classparams = these (try (#params o AxClass.get_info thy) class);
   1.122 @@ -604,9 +607,9 @@
   1.123      val arity_typ = Type (tyco, map TFree vs);
   1.124      val arity_typ' = Type (tyco, map (fn (v, sort) => TVar ((v, 0), sort)) vs');
   1.125      fun translate_superarity superclass =
   1.126 -      ensure_class thy algbr eqngr superclass
   1.127 -      ##>> ensure_classrel thy algbr eqngr (class, superclass)
   1.128 -      ##>> translate_dicts thy algbr eqngr NONE (arity_typ, [superclass])
   1.129 +      ensure_class thy algbr eqngr permissive superclass
   1.130 +      ##>> ensure_classrel thy algbr eqngr permissive (class, superclass)
   1.131 +      ##>> translate_dicts thy algbr eqngr permissive NONE (arity_typ, [superclass])
   1.132        #>> (fn ((superclass, classrel), [DictConst (inst, dss)]) =>
   1.133              (superclass, (classrel, (inst, dss))));
   1.134      fun translate_classparam_inst (c, ty) =
   1.135 @@ -616,73 +619,76 @@
   1.136          val c_ty = (apsnd Logic.unvarifyT_global o dest_Const o snd
   1.137            o Logic.dest_equals o Thm.prop_of) thm;
   1.138        in
   1.139 -        ensure_const thy algbr eqngr c
   1.140 -        ##>> translate_const thy algbr eqngr NONE (SOME thm) c_ty
   1.141 +        ensure_const thy algbr eqngr permissive c
   1.142 +        ##>> translate_const thy algbr eqngr permissive (SOME thm) (c_ty, NONE)
   1.143          #>> (fn (c, IConst c_inst) => ((c, c_inst), (thm, true)))
   1.144        end;
   1.145      val stmt_inst =
   1.146 -      ensure_class thy algbr eqngr class
   1.147 -      ##>> ensure_tyco thy algbr eqngr tyco
   1.148 -      ##>> fold_map (translate_tyvar_sort thy algbr eqngr) vs
   1.149 +      ensure_class thy algbr eqngr permissive class
   1.150 +      ##>> ensure_tyco thy algbr eqngr permissive tyco
   1.151 +      ##>> fold_map (translate_tyvar_sort thy algbr eqngr permissive) vs
   1.152        ##>> fold_map translate_superarity superclasses
   1.153        ##>> fold_map translate_classparam_inst classparams
   1.154        #>> (fn ((((class, tyco), arity), superinsts), classparams) =>
   1.155               Classinst ((class, (tyco, arity)), (superinsts, classparams)));
   1.156    in ensure_stmt lookup_instance (declare_instance thy) stmt_inst (class, tyco) end
   1.157 -and translate_typ thy algbr eqngr (TFree (v, _)) =
   1.158 +and translate_typ thy algbr eqngr permissive (TFree (v, _)) =
   1.159        pair (ITyVar (unprefix "'" v))
   1.160 -  | translate_typ thy algbr eqngr (Type (tyco, tys)) =
   1.161 -      ensure_tyco thy algbr eqngr tyco
   1.162 -      ##>> fold_map (translate_typ thy algbr eqngr) tys
   1.163 +  | translate_typ thy algbr eqngr permissive (Type (tyco, tys)) =
   1.164 +      ensure_tyco thy algbr eqngr permissive tyco
   1.165 +      ##>> fold_map (translate_typ thy algbr eqngr permissive) tys
   1.166        #>> (fn (tyco, tys) => tyco `%% tys)
   1.167 -and translate_term thy algbr eqngr some_abs some_thm (Const (c, ty)) =
   1.168 -      translate_app thy algbr eqngr some_abs some_thm ((c, ty), [])
   1.169 -  | translate_term thy algbr eqngr some_abs some_thm (Free (v, _)) =
   1.170 +and translate_term thy algbr eqngr permissive some_thm (Const (c, ty), some_abs) =
   1.171 +      translate_app thy algbr eqngr permissive some_thm (((c, ty), []), some_abs)
   1.172 +  | translate_term thy algbr eqngr permissive some_thm (Free (v, _), some_abs) =
   1.173        pair (IVar (SOME v))
   1.174 -  | translate_term thy algbr eqngr some_abs some_thm (Abs (v, ty, t)) =
   1.175 +  | translate_term thy algbr eqngr permissive some_thm (Abs (v, ty, t), some_abs) =
   1.176        let
   1.177          val (v', t') = Syntax.variant_abs (Name.desymbolize false v, ty, t);
   1.178          val v'' = if member (op =) (Term.add_free_names t' []) v'
   1.179            then SOME v' else NONE
   1.180        in
   1.181 -        translate_typ thy algbr eqngr ty
   1.182 -        ##>> translate_term thy algbr eqngr some_abs some_thm t'
   1.183 +        translate_typ thy algbr eqngr permissive ty
   1.184 +        ##>> translate_term thy algbr eqngr permissive some_thm (t', some_abs)
   1.185          #>> (fn (ty, t) => (v'', ty) `|=> t)
   1.186        end
   1.187 -  | translate_term thy algbr eqngr some_abs some_thm (t as _ $ _) =
   1.188 +  | translate_term thy algbr eqngr permissive some_thm (t as _ $ _, some_abs) =
   1.189        case strip_comb t
   1.190         of (Const (c, ty), ts) =>
   1.191 -            translate_app thy algbr eqngr some_abs some_thm ((c, ty), ts)
   1.192 +            translate_app thy algbr eqngr permissive some_thm (((c, ty), ts), some_abs)
   1.193          | (t', ts) =>
   1.194 -            translate_term thy algbr eqngr some_abs some_thm t'
   1.195 -            ##>> fold_map (translate_term thy algbr eqngr NONE some_thm) ts
   1.196 +            translate_term thy algbr eqngr permissive some_thm (t', some_abs)
   1.197 +            ##>> fold_map (translate_term thy algbr eqngr permissive some_thm o rpair NONE) ts
   1.198              #>> (fn (t, ts) => t `$$ ts)
   1.199 -and translate_eqn thy algbr eqngr ((args, (rhs, some_abs)), (some_thm, proper)) =
   1.200 -  fold_map (fn (arg, some_abs) => translate_term thy algbr eqngr some_abs some_thm arg) args
   1.201 -  ##>> translate_term thy algbr eqngr some_abs some_thm rhs
   1.202 +and translate_eqn thy algbr eqngr permissive ((args, (rhs, some_abs)), (some_thm, proper)) =
   1.203 +  fold_map (translate_term thy algbr eqngr permissive some_thm) args
   1.204 +  ##>> translate_term thy algbr eqngr permissive some_thm (rhs, some_abs)
   1.205    #>> rpair (some_thm, proper)
   1.206 -and translate_const thy algbr eqngr some_abs some_thm (c, ty) =
   1.207 +and translate_equation thy algbr eqngr permissive eqn prgrm =
   1.208 +  prgrm |> translate_eqn thy algbr eqngr permissive eqn |>> SOME
   1.209 +    handle PERMISSIVE () => (NONE, prgrm)
   1.210 +and translate_const thy algbr eqngr permissive some_thm ((c, ty), some_abs) =
   1.211    let
   1.212      val _ = if (case some_abs of NONE => true | SOME abs => not (c = abs))
   1.213          andalso Code.is_abstr thy c
   1.214 -        then translation_error thy some_thm
   1.215 +        then translation_error thy permissive some_thm
   1.216            "Abstraction violation" ("constant " ^ Code.string_of_const thy c)
   1.217        else ()
   1.218      val tys = Sign.const_typargs thy (c, ty);
   1.219      val sorts = Code_Preproc.sortargs eqngr c;
   1.220      val tys_args = (fst o Term.strip_type) ty;
   1.221    in
   1.222 -    ensure_const thy algbr eqngr c
   1.223 -    ##>> fold_map (translate_typ thy algbr eqngr) tys
   1.224 -    ##>> fold_map (translate_dicts thy algbr eqngr some_thm) (tys ~~ sorts)
   1.225 -    ##>> fold_map (translate_typ thy algbr eqngr) tys_args
   1.226 +    ensure_const thy algbr eqngr permissive c
   1.227 +    ##>> fold_map (translate_typ thy algbr eqngr permissive) tys
   1.228 +    ##>> fold_map (translate_dicts thy algbr eqngr permissive some_thm) (tys ~~ sorts)
   1.229 +    ##>> fold_map (translate_typ thy algbr eqngr permissive) tys_args
   1.230      #>> (fn (((c, tys), iss), tys_args) => IConst (c, ((tys, iss), tys_args)))
   1.231    end
   1.232 -and translate_app_const thy algbr eqngr some_abs some_thm (c_ty, ts) =
   1.233 -  translate_const thy algbr eqngr some_abs some_thm c_ty
   1.234 -  ##>> fold_map (translate_term thy algbr eqngr NONE some_thm) ts
   1.235 +and translate_app_const thy algbr eqngr permissive some_thm ((c_ty, ts), some_abs) =
   1.236 +  translate_const thy algbr eqngr permissive some_thm (c_ty, some_abs)
   1.237 +  ##>> fold_map (translate_term thy algbr eqngr permissive some_thm o rpair NONE) ts
   1.238    #>> (fn (t, ts) => t `$$ ts)
   1.239 -and translate_case thy algbr eqngr some_abs some_thm (num_args, (t_pos, case_pats)) (c_ty, ts) =
   1.240 +and translate_case thy algbr eqngr permissive some_thm (num_args, (t_pos, case_pats)) (c_ty, ts) =
   1.241    let
   1.242      fun arg_types num_args ty = (fst o chop num_args o fst o strip_type) ty;
   1.243      val tys = arg_types num_args (snd c_ty);
   1.244 @@ -726,14 +732,15 @@
   1.245                (constrs ~~ ts_clause);
   1.246        in ((t, ty), clauses) end;
   1.247    in
   1.248 -    translate_const thy algbr eqngr some_abs some_thm c_ty
   1.249 -    ##>> fold_map (fn (constr, n) => translate_const thy algbr eqngr some_abs some_thm constr #>> rpair n) constrs
   1.250 -    ##>> translate_typ thy algbr eqngr ty
   1.251 -    ##>> fold_map (translate_term thy algbr eqngr some_abs some_thm) ts
   1.252 +    translate_const thy algbr eqngr permissive some_thm (c_ty, NONE)
   1.253 +    ##>> fold_map (fn (constr, n) => translate_const thy algbr eqngr permissive some_thm (constr, NONE)
   1.254 +      #>> rpair n) constrs
   1.255 +    ##>> translate_typ thy algbr eqngr permissive ty
   1.256 +    ##>> fold_map (translate_term thy algbr eqngr permissive some_thm o rpair NONE) ts
   1.257      #-> (fn (((t, constrs), ty), ts) =>
   1.258        `(fn (_, (naming, _)) => ICase (casify naming constrs ty ts, t `$$ ts)))
   1.259    end
   1.260 -and translate_app_case thy algbr eqngr some_abs some_thm (case_scheme as (num_args, _)) ((c, ty), ts) =
   1.261 +and translate_app_case thy algbr eqngr permissive some_thm (case_scheme as (num_args, _)) ((c, ty), ts) =
   1.262    if length ts < num_args then
   1.263      let
   1.264        val k = length ts;
   1.265 @@ -741,24 +748,24 @@
   1.266        val ctxt = (fold o fold_aterms) Term.declare_term_frees ts Name.context;
   1.267        val vs = Name.names ctxt "a" tys;
   1.268      in
   1.269 -      fold_map (translate_typ thy algbr eqngr) tys
   1.270 -      ##>> translate_case thy algbr eqngr some_abs some_thm case_scheme ((c, ty), ts @ map Free vs)
   1.271 +      fold_map (translate_typ thy algbr eqngr permissive) tys
   1.272 +      ##>> translate_case thy algbr eqngr permissive some_thm case_scheme ((c, ty), ts @ map Free vs)
   1.273        #>> (fn (tys, t) => map2 (fn (v, _) => pair (SOME v)) vs tys `|==> t)
   1.274      end
   1.275    else if length ts > num_args then
   1.276 -    translate_case thy algbr eqngr some_abs some_thm case_scheme ((c, ty), take num_args ts)
   1.277 -    ##>> fold_map (translate_term thy algbr eqngr some_abs some_thm) (drop num_args ts)
   1.278 +    translate_case thy algbr eqngr permissive some_thm case_scheme ((c, ty), take num_args ts)
   1.279 +    ##>> fold_map (translate_term thy algbr eqngr permissive some_thm o rpair NONE) (drop num_args ts)
   1.280      #>> (fn (t, ts) => t `$$ ts)
   1.281    else
   1.282 -    translate_case thy algbr eqngr some_abs some_thm case_scheme ((c, ty), ts)
   1.283 -and translate_app thy algbr eqngr some_abs some_thm (c_ty_ts as ((c, _), _)) =
   1.284 +    translate_case thy algbr eqngr permissive some_thm case_scheme ((c, ty), ts)
   1.285 +and translate_app thy algbr eqngr permissive some_thm (c_ty_ts as ((c, _), _), some_abs) =
   1.286    case Code.get_case_scheme thy c
   1.287 -   of SOME case_scheme => translate_app_case thy algbr eqngr NONE some_thm case_scheme c_ty_ts
   1.288 -    | NONE => translate_app_const thy algbr eqngr some_abs some_thm c_ty_ts
   1.289 -and translate_tyvar_sort thy (algbr as (proj_sort, _)) eqngr (v, sort) =
   1.290 -  fold_map (ensure_class thy algbr eqngr) (proj_sort sort)
   1.291 +   of SOME case_scheme => translate_app_case thy algbr eqngr permissive some_thm case_scheme c_ty_ts
   1.292 +    | NONE => translate_app_const thy algbr eqngr permissive some_thm (c_ty_ts, some_abs)
   1.293 +and translate_tyvar_sort thy (algbr as (proj_sort, _)) eqngr permissive (v, sort) =
   1.294 +  fold_map (ensure_class thy algbr eqngr permissive) (proj_sort sort)
   1.295    #>> (fn sort => (unprefix "'" v, sort))
   1.296 -and translate_dicts thy (algbr as (proj_sort, algebra)) eqngr some_thm (ty, sort) =
   1.297 +and translate_dicts thy (algbr as (proj_sort, algebra)) eqngr permissive some_thm (ty, sort) =
   1.298    let
   1.299      datatype typarg =
   1.300          Global of (class * string) * typarg list list
   1.301 @@ -777,13 +784,13 @@
   1.302        {class_relation = K (Sorts.classrel_derivation algebra class_relation),
   1.303         type_constructor = type_constructor,
   1.304         type_variable = type_variable} (ty, proj_sort sort)
   1.305 -      handle Sorts.CLASS_ERROR e => not_wellsorted thy some_thm ty sort e;
   1.306 +      handle Sorts.CLASS_ERROR e => not_wellsorted thy permissive some_thm ty sort e;
   1.307      fun mk_dict (Global (inst, yss)) =
   1.308 -          ensure_inst thy algbr eqngr inst
   1.309 +          ensure_inst thy algbr eqngr permissive inst
   1.310            ##>> (fold_map o fold_map) mk_dict yss
   1.311            #>> (fn (inst, dss) => DictConst (inst, dss))
   1.312        | mk_dict (Local (classrels, (v, (n, sort)))) =
   1.313 -          fold_map (ensure_classrel thy algbr eqngr) classrels
   1.314 +          fold_map (ensure_classrel thy algbr eqngr permissive) classrels
   1.315            #>> (fn classrels => DictVar (classrels, (unprefix "'" v, (n, length sort))))
   1.316    in fold_map mk_dict typargs end;
   1.317  
   1.318 @@ -796,22 +803,29 @@
   1.319    val empty = (empty_naming, Graph.empty);
   1.320  );
   1.321  
   1.322 -fun invoke_generation thy (algebra, eqngr) f name =
   1.323 +fun cache_generation thy (algebra, eqngr) f name =
   1.324    Program.change_yield thy (fn naming_program => (NONE, naming_program)
   1.325      |> f thy algebra eqngr name
   1.326      |-> (fn name => fn (_, naming_program) => (name, naming_program)));
   1.327  
   1.328 +fun transient_generation thy (algebra, eqngr) f name =
   1.329 +  (NONE, (empty_naming, Graph.empty))
   1.330 +  |> f thy algebra eqngr name
   1.331 +  |-> (fn name => fn (_, naming_program) => (name, naming_program));
   1.332 +
   1.333  
   1.334  (* program generation *)
   1.335  
   1.336 -fun consts_program thy cs =
   1.337 +fun consts_program thy permissive cs =
   1.338    let
   1.339      fun project_consts cs (naming, program) =
   1.340        let
   1.341          val cs_all = Graph.all_succs program cs;
   1.342        in (cs, (naming, Graph.subgraph (member (op =) cs_all) program)) end;
   1.343      fun generate_consts thy algebra eqngr =
   1.344 -      fold_map (ensure_const thy algebra eqngr);
   1.345 +      fold_map (ensure_const thy algebra eqngr permissive);
   1.346 +    val invoke_generation = if permissive
   1.347 +      then transient_generation else cache_generation
   1.348    in
   1.349      invoke_generation thy (Code_Preproc.obtain thy cs []) generate_consts cs
   1.350      |-> project_consts
   1.351 @@ -826,9 +840,9 @@
   1.352      val vs = fold_term_types (K (fold_atyps (insert (eq_fst op =)
   1.353        o dest_TFree))) t [];
   1.354      val stmt_value =
   1.355 -      fold_map (translate_tyvar_sort thy algbr eqngr) vs
   1.356 -      ##>> translate_typ thy algbr eqngr ty
   1.357 -      ##>> translate_term thy algbr eqngr NONE NONE (Code.subst_signatures thy t)
   1.358 +      fold_map (translate_tyvar_sort thy algbr eqngr false) vs
   1.359 +      ##>> translate_typ thy algbr eqngr false ty
   1.360 +      ##>> translate_term thy algbr eqngr false NONE (Code.subst_signatures thy t, NONE)
   1.361        #>> (fn ((vs, ty), t) => Fun
   1.362          (Term.dummy_patternN, ((vs, ty), [(([], t), (NONE, true))])));
   1.363      fun term_value (dep, (naming, program1)) =
   1.364 @@ -849,7 +863,7 @@
   1.365  fun base_evaluator thy evaluator algebra eqngr vs t =
   1.366    let
   1.367      val (((naming, program), (((vs', ty'), t'), deps)), _) =
   1.368 -      invoke_generation thy (algebra, eqngr) ensure_value t;
   1.369 +      cache_generation thy (algebra, eqngr) ensure_value t;
   1.370      val vs'' = map (fn (v, _) => (v, (the o AList.lookup (op =) vs o prefix "'") v)) vs';
   1.371    in evaluator naming program ((vs'', (vs', ty')), t') deps end;
   1.372  
   1.373 @@ -861,19 +875,14 @@
   1.374  
   1.375  fun read_const_exprs thy =
   1.376    let
   1.377 -    fun consts_of some_thyname =
   1.378 -      let
   1.379 -        val thy' = case some_thyname
   1.380 -         of SOME thyname => ThyInfo.the_theory thyname thy
   1.381 -          | NONE => thy;
   1.382 -        val cs = Symtab.fold (fn (c, (_, NONE)) => cons c | _ => I)
   1.383 -          ((snd o #constants o Consts.dest o #consts o Sign.rep_sg) thy') [];
   1.384 -        fun belongs_here c = forall
   1.385 -          (fn thy'' => not (Sign.declared_const thy'' c)) (Theory.parents_of thy')
   1.386 -      in if is_some some_thyname then filter belongs_here cs else cs end;
   1.387 -    fun read_const_expr "*" = ([], consts_of NONE)
   1.388 +    fun consts_of thy' = Symtab.fold (fn (c, (_, NONE)) => cons c | _ => I)
   1.389 +      ((snd o #constants o Consts.dest o #consts o Sign.rep_sg) thy') [];
   1.390 +    fun belongs_here thy' c = forall
   1.391 +      (fn thy'' => not (Sign.declared_const thy'' c)) (Theory.parents_of thy');
   1.392 +    fun consts_of_select thy' = filter (belongs_here thy') (consts_of thy');
   1.393 +    fun read_const_expr "*" = ([], consts_of thy)
   1.394        | read_const_expr s = if String.isSuffix ".*" s
   1.395 -          then ([], consts_of (SOME (unsuffix ".*" s)))
   1.396 +          then ([], consts_of_select (ThyInfo.the_theory (unsuffix ".*" s) thy))
   1.397            else ([Code.read_const thy s], []);
   1.398    in pairself flat o split_list o map read_const_expr end;
   1.399