src/HOL/Tools/SMT/smt_translate.ML
author blanchet
Wed Sep 17 16:53:39 2014 +0200 (2014-09-17)
changeset 58360 dee1fd1cc631
parent 58061 3d060f43accb
child 58361 7f2b3b6f6ad1
permissions -rw-r--r--
added interface for CVC4 extensions
     1 (*  Title:      HOL/Tools/SMT/smt_translate.ML
     2     Author:     Sascha Boehme, TU Muenchen
     3 
     4 Translate theorems into an SMT intermediate format and serialize them.
     5 *)
     6 
     7 signature SMT_TRANSLATE =
     8 sig
     9   (*intermediate term structure*)
    10   datatype squant = SForall | SExists
    11   datatype 'a spattern = SPat of 'a list | SNoPat of 'a list
    12   datatype sterm =
    13     SVar of int |
    14     SApp of string * sterm list |
    15     SLet of string * sterm * sterm |
    16     SQua of squant * string list * sterm spattern list * sterm
    17 
    18   (*translation configuration*)
    19   type sign = {
    20     logic: string,
    21     sorts: string list,
    22     dtyps: (string * (string * (string * string) list) list) list list,
    23     funcs: (string * (string list * string)) list }
    24   type config = {
    25     logic: term list -> string,
    26     fp_kinds: BNF_Util.fp_kind list,
    27     serialize: (string * string) list -> string list -> sign -> sterm list -> string }
    28   type replay_data = {
    29     context: Proof.context,
    30     typs: typ Symtab.table,
    31     terms: term Symtab.table,
    32     ll_defs: term list,
    33     rewrite_rules: thm list,
    34     assms: (int * thm) list }
    35 
    36   (*translation*)
    37   val add_config: SMT_Util.class * (Proof.context -> config) -> Context.generic -> Context.generic
    38   val translate: Proof.context -> (string * string) list -> string list -> (int * thm) list ->
    39     string * replay_data
    40 end;
    41 
    42 structure SMT_Translate: SMT_TRANSLATE =
    43 struct
    44 
    45 
    46 (* intermediate term structure *)
    47 
    48 datatype squant = SForall | SExists
    49 
    50 datatype 'a spattern = SPat of 'a list | SNoPat of 'a list
    51 
    52 datatype sterm =
    53   SVar of int |
    54   SApp of string * sterm list |
    55   SLet of string * sterm * sterm |
    56   SQua of squant * string list * sterm spattern list * sterm
    57 
    58 
    59 (* translation configuration *)
    60 
    61 type sign = {
    62   logic: string,
    63   sorts: string list,
    64   dtyps: (string * (string * (string * string) list) list) list list,
    65   funcs: (string * (string list * string)) list }
    66 
    67 type config = {
    68   logic: term list -> string,
    69   fp_kinds: BNF_Util.fp_kind list,
    70   serialize: (string * string) list -> string list -> sign -> sterm list -> string }
    71 
    72 type replay_data = {
    73   context: Proof.context,
    74   typs: typ Symtab.table,
    75   terms: term Symtab.table,
    76   ll_defs: term list,
    77   rewrite_rules: thm list,
    78   assms: (int * thm) list }
    79 
    80 
    81 (* translation context *)
    82 
    83 fun add_components_of_typ (Type (s, Ts)) =
    84     cons (Long_Name.base_name s) #> fold_rev add_components_of_typ Ts
    85   | add_components_of_typ (TFree (s, _)) = cons (perhaps (try (unprefix "'")) s)
    86   | add_components_of_typ _ = I;
    87 
    88 fun suggested_name_of_typ T = space_implode "_" (add_components_of_typ T []);
    89 
    90 fun suggested_name_of_term (Const (s, _)) = Long_Name.base_name s
    91   | suggested_name_of_term (Free (s, _)) = s
    92   | suggested_name_of_term _ = Name.uu
    93 
    94 val empty_tr_context = (Name.context, Typtab.empty, Termtab.empty)
    95 val safe_suffix = "$"
    96 
    97 fun add_typ T proper (cx as (names, typs, terms)) =
    98   (case Typtab.lookup typs T of
    99     SOME (name, _) => (name, cx)
   100   | NONE =>
   101       let
   102         val sugg = Name.desymbolize (SOME true) (suggested_name_of_typ T) ^ safe_suffix
   103         val (name, names') = Name.variant sugg names
   104         val typs' = Typtab.update (T, (name, proper)) typs
   105       in (name, (names', typs', terms)) end)
   106 
   107 fun add_fun t sort (cx as (names, typs, terms)) =
   108   (case Termtab.lookup terms t of
   109     SOME (name, _) => (name, cx)
   110   | NONE =>
   111       let
   112         val sugg = Name.desymbolize (SOME false) (suggested_name_of_term t) ^ safe_suffix
   113         val (name, names') = Name.variant sugg names
   114         val terms' = Termtab.update (t, (name, sort)) terms
   115       in (name, (names', typs, terms')) end)
   116 
   117 fun sign_of logic dtyps (_, typs, terms) = {
   118   logic = logic,
   119   sorts = Typtab.fold (fn (_, (n, true)) => cons n | _ => I) typs [],
   120   dtyps = dtyps,
   121   funcs = Termtab.fold (fn (_, (n, SOME ss)) => cons (n,ss) | _ => I) terms []}
   122 
   123 fun replay_data_of ctxt ll_defs rules assms (_, typs, terms) =
   124   let
   125     fun add_typ (T, (n, _)) = Symtab.update (n, T)
   126     val typs' = Typtab.fold add_typ typs Symtab.empty
   127 
   128     fun add_fun (t, (n, _)) = Symtab.update (n, t)
   129     val terms' = Termtab.fold add_fun terms Symtab.empty
   130   in
   131     {context = ctxt, typs = typs', terms = terms', ll_defs = ll_defs, rewrite_rules = rules,
   132      assms = assms}
   133   end
   134 
   135 
   136 (* preprocessing *)
   137 
   138 (** datatype declarations **)
   139 
   140 fun collect_datatypes_and_records (tr_context, ctxt) ts =
   141   let
   142     val (declss, ctxt') =
   143       fold (Term.fold_types (SMT_Datatypes.add_decls BNF_Util.Least_FP)) ts ([], ctxt)
   144 
   145     fun is_decl_typ T = exists (exists (equal T o fst)) declss
   146 
   147     fun add_typ' T proper =
   148       (case SMT_Builtin.dest_builtin_typ ctxt' T of
   149         SOME n => pair n
   150       | NONE => add_typ T proper)
   151 
   152     fun tr_select sel =
   153       let val T = Term.range_type (Term.fastype_of sel)
   154       in add_fun sel NONE ##>> add_typ' T (not (is_decl_typ T)) end
   155     fun tr_constr (constr, selects) =
   156       add_fun constr NONE ##>> fold_map tr_select selects
   157     fun tr_typ (T, cases) = add_typ' T false ##>> fold_map tr_constr cases
   158     val (declss', tr_context') = fold_map (fold_map tr_typ) declss tr_context
   159 
   160     fun add (constr, selects) =
   161       Termtab.update (constr, length selects) #>
   162       fold (Termtab.update o rpair 1) selects
   163     val funcs = fold (fold (fold add o snd)) declss Termtab.empty
   164   in ((funcs, declss', tr_context', ctxt'), ts) end
   165     (* FIXME: also return necessary datatype and record theorems *)
   166 
   167 
   168 (** eta-expand quantifiers, let expressions and built-ins *)
   169 
   170 local
   171   fun eta f T t = Abs (Name.uu, T, f (Term.incr_boundvars 1 t $ Bound 0))
   172 
   173   fun exp f T = eta f (Term.domain_type (Term.domain_type T))
   174 
   175   fun exp2 T q =
   176     let val U = Term.domain_type T
   177     in Abs (Name.uu, U, q $ eta I (Term.domain_type U) (Bound 0)) end
   178 
   179   fun expf k i T t =
   180     let val Ts = drop i (fst (SMT_Util.dest_funT k T))
   181     in
   182       Term.incr_boundvars (length Ts) t
   183       |> fold_rev (fn i => fn u => u $ Bound i) (0 upto length Ts - 1)
   184       |> fold_rev (fn T => fn u => Abs (Name.uu, T, u)) Ts
   185     end
   186 in
   187 
   188 fun eta_expand ctxt funcs =
   189   let
   190     fun exp_func t T ts =
   191       (case Termtab.lookup funcs t of
   192         SOME k => Term.list_comb (t, ts) |> k <> length ts ? expf k (length ts) T
   193       | NONE => Term.list_comb (t, ts))
   194 
   195     fun expand ((q as Const (@{const_name All}, _)) $ Abs a) = q $ abs_expand a
   196       | expand ((q as Const (@{const_name All}, T)) $ t) = q $ exp expand T t
   197       | expand (q as Const (@{const_name All}, T)) = exp2 T q
   198       | expand ((q as Const (@{const_name Ex}, _)) $ Abs a) = q $ abs_expand a
   199       | expand ((q as Const (@{const_name Ex}, T)) $ t) = q $ exp expand T t
   200       | expand (q as Const (@{const_name Ex}, T)) = exp2 T q
   201       | expand (Const (@{const_name Let}, _) $ t $ u) = expand (Term.betapply (u, t))
   202       | expand (Const (@{const_name Let}, T) $ t) =
   203           let val U = Term.domain_type (Term.range_type T)
   204           in Abs (Name.uu, U, Bound 0 $ Term.incr_boundvars 1 t) end
   205       | expand (Const (@{const_name Let}, T)) =
   206           let val U = Term.domain_type (Term.range_type T)
   207           in Abs (Name.uu, Term.domain_type T, Abs (Name.uu, U, Bound 0 $ Bound 1)) end
   208       | expand t =
   209           (case Term.strip_comb t of
   210             (u as Const (c as (_, T)), ts) =>
   211               (case SMT_Builtin.dest_builtin ctxt c ts of
   212                 SOME (_, k, us, mk) =>
   213                   if k = length us then mk (map expand us)
   214                   else if k < length us then chop k (map expand us) |>> mk |> Term.list_comb
   215                   else expf k (length ts) T (mk (map expand us))
   216               | NONE => exp_func u T (map expand ts))
   217           | (u as Free (_, T), ts) => exp_func u T (map expand ts)
   218           | (Abs a, ts) => Term.list_comb (abs_expand a, map expand ts)
   219           | (u, ts) => Term.list_comb (u, map expand ts))
   220 
   221     and abs_expand (n, T, t) = Abs (n, T, expand t)
   222 
   223   in map expand end
   224 
   225 end
   226 
   227 
   228 (** introduce explicit applications **)
   229 
   230 local
   231   (*
   232     Make application explicit for functions with varying number of arguments.
   233   *)
   234 
   235   fun add t i = apfst (Termtab.map_default (t, i) (Integer.min i))
   236   fun add_type T = apsnd (Typtab.update (T, ()))
   237 
   238   fun min_arities t =
   239     (case Term.strip_comb t of
   240       (u as Const _, ts) => add u (length ts) #> fold min_arities ts
   241     | (u as Free _, ts) => add u (length ts) #> fold min_arities ts
   242     | (Abs (_, T, u), ts) => (can dest_funT T ? add_type T) #> min_arities u #> fold min_arities ts
   243     | (_, ts) => fold min_arities ts)
   244 
   245   fun minimize types t i =
   246     let
   247       fun find_min j [] _ = j
   248         | find_min j (U :: Us) T =
   249             if Typtab.defined types T then j else find_min (j + 1) Us (U --> T)
   250 
   251       val (Ts, T) = Term.strip_type (Term.type_of t)
   252     in find_min 0 (take i (rev Ts)) T end
   253 
   254   fun app u (t, T) = (Const (@{const_name fun_app}, T --> T) $ t $ u, Term.range_type T)
   255 
   256   fun apply i t T ts =
   257     let
   258       val (ts1, ts2) = chop i ts
   259       val (_, U) = SMT_Util.dest_funT i T
   260     in fst (fold app ts2 (Term.list_comb (t, ts1), U)) end
   261 in
   262 
   263 fun intro_explicit_application ctxt funcs ts =
   264   let
   265     val (arities, types) = fold min_arities ts (Termtab.empty, Typtab.empty)
   266     val arities' = Termtab.map (minimize types) arities (* FIXME: highly suspicious *)
   267 
   268     fun app_func t T ts =
   269       if is_some (Termtab.lookup funcs t) then Term.list_comb (t, ts)
   270       else apply (the (Termtab.lookup arities' t)) t T ts
   271 
   272     fun in_list T f t = SMT_Util.mk_symb_list T (map f (SMT_Util.dest_symb_list t))
   273 
   274     fun traverse Ts t =
   275       (case Term.strip_comb t of
   276         (q as Const (@{const_name All}, _), [Abs (x, T, u)]) =>
   277           q $ Abs (x, T, in_trigger (T :: Ts) u)
   278       | (q as Const (@{const_name Ex}, _), [Abs (x, T, u)]) =>
   279           q $ Abs (x, T, in_trigger (T :: Ts) u)
   280       | (q as Const (@{const_name Let}, _), [u1, u2 as Abs _]) =>
   281           q $ traverse Ts u1 $ traverse Ts u2
   282       | (u as Const (c as (_, T)), ts) =>
   283           (case SMT_Builtin.dest_builtin ctxt c ts of
   284             SOME (_, k, us, mk) =>
   285               let
   286                 val (ts1, ts2) = chop k (map (traverse Ts) us)
   287                 val U = Term.strip_type T |>> snd o chop k |> (op --->)
   288               in apply 0 (mk ts1) U ts2 end
   289           | NONE => app_func u T (map (traverse Ts) ts))
   290       | (u as Free (_, T), ts) => app_func u T (map (traverse Ts) ts)
   291       | (u as Bound i, ts) => apply 0 u (nth Ts i) (map (traverse Ts) ts)
   292       | (Abs (n, T, u), ts) => traverses Ts (Abs (n, T, traverse (T::Ts) u)) ts
   293       | (u, ts) => traverses Ts u ts)
   294     and in_trigger Ts ((c as @{const trigger}) $ p $ t) = c $ in_pats Ts p $ traverse Ts t
   295       | in_trigger Ts t = traverse Ts t
   296     and in_pats Ts ps =
   297       in_list @{typ "pattern symb_list"} (in_list @{typ pattern} (in_pat Ts)) ps
   298     and in_pat Ts ((p as Const (@{const_name pat}, _)) $ t) = p $ traverse Ts t
   299       | in_pat Ts ((p as Const (@{const_name nopat}, _)) $ t) = p $ traverse Ts t
   300       | in_pat _ t = raise TERM ("bad pattern", [t])
   301     and traverses Ts t ts = Term.list_comb (t, map (traverse Ts) ts)
   302   in map (traverse []) ts end
   303 
   304 val fun_app_eq = mk_meta_eq @{thm fun_app_def}
   305 
   306 end
   307 
   308 
   309 (** map HOL formulas to FOL formulas (i.e., separate formulas froms terms) **)
   310 
   311 local
   312   val is_quant = member (op =) [@{const_name All}, @{const_name Ex}]
   313 
   314   val fol_rules = [
   315     Let_def,
   316     @{lemma "P = True == P" by (rule eq_reflection) simp},
   317     @{lemma "if P then True else False == P" by (rule eq_reflection) simp}]
   318 
   319   exception BAD_PATTERN of unit
   320 
   321   fun wrap_in_if pat t =
   322     if pat then raise BAD_PATTERN () else @{const If (bool)} $ t $ @{const True} $ @{const False}
   323 
   324   fun is_builtin_conn_or_pred ctxt c ts =
   325     is_some (SMT_Builtin.dest_builtin_conn ctxt c ts) orelse
   326     is_some (SMT_Builtin.dest_builtin_pred ctxt c ts)
   327 in
   328 
   329 fun folify ctxt =
   330   let
   331     fun in_list T f t = SMT_Util.mk_symb_list T (map_filter f (SMT_Util.dest_symb_list t))
   332 
   333     fun in_term pat t =
   334       (case Term.strip_comb t of
   335         (@{const True}, []) => t
   336       | (@{const False}, []) => t
   337       | (u as Const (@{const_name If}, _), [t1, t2, t3]) =>
   338           if pat then raise BAD_PATTERN () else u $ in_form t1 $ in_term pat t2 $ in_term pat t3
   339       | (Const (c as (n, _)), ts) =>
   340           if is_builtin_conn_or_pred ctxt c ts then wrap_in_if pat (in_form t)
   341           else if is_quant n then wrap_in_if pat (in_form t)
   342           else Term.list_comb (Const c, map (in_term pat) ts)
   343       | (Free c, ts) => Term.list_comb (Free c, map (in_term pat) ts)
   344       | _ => t)
   345 
   346     and in_pat ((p as Const (@{const_name pat}, _)) $ t) =
   347           p $ in_term true t
   348       | in_pat ((p as Const (@{const_name nopat}, _)) $ t) =
   349           p $ in_term true t
   350       | in_pat t = raise TERM ("bad pattern", [t])
   351 
   352     and in_pats ps =
   353       in_list @{typ "pattern symb_list"} (SOME o in_list @{typ pattern} (try in_pat)) ps
   354 
   355     and in_trigger ((c as @{const trigger}) $ p $ t) = c $ in_pats p $ in_form t
   356       | in_trigger t = in_form t
   357 
   358     and in_form t =
   359       (case Term.strip_comb t of
   360         (q as Const (qn, _), [Abs (n, T, u)]) =>
   361           if is_quant qn then q $ Abs (n, T, in_trigger u)
   362           else in_term false t
   363       | (Const c, ts) =>
   364           (case SMT_Builtin.dest_builtin_conn ctxt c ts of
   365             SOME (_, _, us, mk) => mk (map in_form us)
   366           | NONE =>
   367               (case SMT_Builtin.dest_builtin_pred ctxt c ts of
   368                 SOME (_, _, us, mk) => mk (map (in_term false) us)
   369               | NONE => in_term false t))
   370       | _ => in_term false t)
   371   in
   372     map in_form #>
   373     pair (fol_rules, I)
   374   end
   375 
   376 end
   377 
   378 
   379 (* translation into intermediate format *)
   380 
   381 (** utility functions **)
   382 
   383 val quantifier = (fn
   384     @{const_name All} => SOME SForall
   385   | @{const_name Ex} => SOME SExists
   386   | _ => NONE)
   387 
   388 fun group_quant qname Ts (t as Const (q, _) $ Abs (_, T, u)) =
   389       if q = qname then group_quant qname (T :: Ts) u else (Ts, t)
   390   | group_quant _ Ts t = (Ts, t)
   391 
   392 fun dest_pat (Const (@{const_name pat}, _) $ t) = (t, true)
   393   | dest_pat (Const (@{const_name nopat}, _) $ t) = (t, false)
   394   | dest_pat t = raise TERM ("bad pattern", [t])
   395 
   396 fun dest_pats [] = I
   397   | dest_pats ts =
   398       (case map dest_pat ts |> split_list ||> distinct (op =) of
   399         (ps, [true]) => cons (SPat ps)
   400       | (ps, [false]) => cons (SNoPat ps)
   401       | _ => raise TERM ("bad multi-pattern", ts))
   402 
   403 fun dest_trigger (@{const trigger} $ tl $ t) =
   404       (rev (fold (dest_pats o SMT_Util.dest_symb_list) (SMT_Util.dest_symb_list tl) []), t)
   405   | dest_trigger t = ([], t)
   406 
   407 fun dest_quant qn T t = quantifier qn |> Option.map (fn q =>
   408   let
   409     val (Ts, u) = group_quant qn [T] t
   410     val (ps, p) = dest_trigger u
   411   in (q, rev Ts, ps, p) end)
   412 
   413 fun fold_map_pat f (SPat ts) = fold_map f ts #>> SPat
   414   | fold_map_pat f (SNoPat ts) = fold_map f ts #>> SNoPat
   415 
   416 
   417 (** translation from Isabelle terms into SMT intermediate terms **)
   418 
   419 fun intermediate logic dtyps builtin ctxt ts trx =
   420   let
   421     fun transT (T as TFree _) = add_typ T true
   422       | transT (T as TVar _) = (fn _ => raise TYPE ("bad SMT type", [T], []))
   423       | transT (T as Type _) =
   424           (case SMT_Builtin.dest_builtin_typ ctxt T of
   425             SOME n => pair n
   426           | NONE => add_typ T true)
   427 
   428     fun app n ts = SApp (n, ts)
   429 
   430     fun trans t =
   431       (case Term.strip_comb t of
   432         (Const (qn, _), [Abs (_, T, t1)]) =>
   433           (case dest_quant qn T t1 of
   434             SOME (q, Ts, ps, b) =>
   435               fold_map transT Ts ##>> fold_map (fold_map_pat trans) ps ##>>
   436               trans b #>> (fn ((Ts', ps'), b') => SQua (q, Ts', ps', b'))
   437           | NONE => raise TERM ("unsupported quantifier", [t]))
   438       | (Const (@{const_name Let}, _), [t1, Abs (_, T, t2)]) =>
   439           transT T ##>> trans t1 ##>> trans t2 #>> (fn ((U, u1), u2) => SLet (U, u1, u2))
   440       | (u as Const (c as (_, T)), ts) =>
   441           (case builtin ctxt c ts of
   442             SOME (n, _, us, _) => fold_map trans us #>> app n
   443           | NONE => transs u T ts)
   444       | (u as Free (_, T), ts) => transs u T ts
   445       | (Bound i, []) => pair (SVar i)
   446       | _ => raise TERM ("bad SMT term", [t]))
   447 
   448     and transs t T ts =
   449       let val (Us, U) = SMT_Util.dest_funT (length ts) T
   450       in
   451         fold_map transT Us ##>> transT U #-> (fn Up =>
   452           add_fun t (SOME Up) ##>> fold_map trans ts #>> SApp)
   453       end
   454 
   455     val (us, trx') = fold_map trans ts trx
   456   in ((sign_of (logic ts) dtyps trx', us), trx') end
   457 
   458 
   459 (* translation *)
   460 
   461 structure Configs = Generic_Data
   462 (
   463   type T = (Proof.context -> config) SMT_Util.dict
   464   val empty = []
   465   val extend = I
   466   fun merge data = SMT_Util.dict_merge fst data
   467 )
   468 
   469 fun add_config (cs, cfg) = Configs.map (SMT_Util.dict_update (cs, cfg))
   470 
   471 fun get_config ctxt =
   472   let val cs = SMT_Config.solver_class_of ctxt
   473   in
   474     (case SMT_Util.dict_get (Configs.get (Context.Proof ctxt)) cs of
   475       SOME cfg => cfg ctxt
   476     | NONE => error ("SMT: no translation configuration found " ^
   477         "for solver class " ^ quote (SMT_Util.string_of_class cs)))
   478   end
   479 
   480 fun translate ctxt smt_options comments ithms =
   481   let
   482     val {logic, fp_kinds, serialize} = get_config ctxt
   483 
   484     fun no_dtyps (tr_context, ctxt) ts =
   485       ((Termtab.empty, [], tr_context, ctxt), ts)
   486 
   487     val ts1 = map (Envir.beta_eta_contract o SMT_Util.prop_of o snd) ithms
   488 
   489     val ((funcs, dtyps, tr_context, ctxt1), ts2) =
   490       ((empty_tr_context, ctxt), ts1)
   491       |-> (if member (op =) fp_kinds BNF_Util.Least_FP then collect_datatypes_and_records
   492         else no_dtyps)
   493 
   494     fun is_binder (Const (@{const_name Let}, _) $ _) = true
   495       | is_binder t = Lambda_Lifting.is_quantifier t
   496 
   497     fun mk_trigger ((q as Const (@{const_name All}, _)) $ Abs (n, T, t)) =
   498           q $ Abs (n, T, mk_trigger t)
   499       | mk_trigger (eq as (Const (@{const_name HOL.eq}, T) $ lhs $ _)) =
   500           Term.domain_type T --> @{typ pattern}
   501           |> (fn T => Const (@{const_name pat}, T) $ lhs)
   502           |> SMT_Util.mk_symb_list @{typ pattern} o single
   503           |> SMT_Util.mk_symb_list @{typ "pattern symb_list"} o single
   504           |> (fn t => @{const trigger} $ t $ eq)
   505       | mk_trigger t = t
   506 
   507     val (ctxt2, (ts3, ll_defs)) =
   508       ts2
   509       |> eta_expand ctxt1 funcs
   510       |> rpair ctxt1
   511       |-> Lambda_Lifting.lift_lambdas NONE is_binder
   512       |-> (fn (ts', ll_defs) => fn ctxt' =>
   513           (ctxt', (intro_explicit_application ctxt' funcs (map mk_trigger ll_defs @ ts'), ll_defs)))
   514 
   515     val ((rewrite_rules, builtin), ts4) = folify ctxt2 ts3
   516       |>> apfst (cons fun_app_eq)
   517   in
   518     (ts4, tr_context)
   519     |-> intermediate logic dtyps (builtin SMT_Builtin.dest_builtin) ctxt2
   520     |>> uncurry (serialize smt_options comments)
   521     ||> replay_data_of ctxt2 ll_defs rewrite_rules ithms
   522   end
   523 
   524 end;