@@ -334,6 +334,13 @@ hack-section-discharging B B1 :- current-mode (builder-from TheFactory _), !,
334334 B1 = {{ let _ : lp:TheFactoryTy := lp:TheFactory in lp:B }}.
335335hack-section-discharging B B.
336336
337+ pred optimize-body i:term, o:term.
338+ optimize-body (app[global (const C)| Args]) Red :- phant-abbrev _ (const C) _, !,
339+ coq.env.const C (some B) _,
340+ hd-beta B Args HD Stack,
341+ unwind HD Stack Red.
342+ optimize-body X X.
343+
337344main [const-decl Name (some BodySkel) TyWPSkel] :- !, std.do! [
338345 std.assert-ok! (coq.elaborate-arity-skeleton TyWPSkel _ TyWP) "Definition type illtyped",
339346 coq.arity->term TyWP Ty,
@@ -354,10 +361,10 @@ main [const-decl Name (some BodySkel) TyWPSkel] :- !, std.do! [
354361 factory-alias->gref FactoryAlias Factory,
355362 std.assert! (factory-nparams Factory NParams) "Not a factory synthesized by HB",
356363 hack-section-discharging SectionBody SectionBodyHack,
357- if (Name = "_")
358- (TheFactory = SectionBodyHack)
359- ( hb-add-const Name SectionBodyHack _ @transparent! C,
360- TheFactory = (global (const C) )),
364+ optimize-body SectionBodyHack OptimizedBody,
365+ if (Name = "_") (RealName is "HB_unnamed_factory_" ^ {std.any->string {new_int} }) (RealName = Name),
366+ hb-add-const RealName OptimizedBody _ @transparent! C,
367+ TheFactory = (global (const C)),
361368 std.appendR {coq.mk-n-holes NParams} [TheType|_] Args,
362369 with -attributes (main-declare-instance TheType TheFactory Clauses),
363370
0 commit comments