@@ -12,7 +12,6 @@ main Ty Args Instance :- std.do! [
1212 std.assert! (Args = [trm TSkel|FactoriesSkel]) "HB.pack: not enough arguments",
1313
1414 get-constructor Class KC,
15- get-constructor Structure KS,
1615
1716 std.assert-ok! (d\
1817 (coq.elaborate-ty-skeleton TSkel _ T d, d = ok) ;
@@ -29,30 +28,67 @@ main Ty Args Instance :- std.do! [
2928 (AllFactories = Factories)
3029 (AllFactories = Factories, Tkey = T), % it's a factory, won't add anything
3130
32- private.synth-instance Params KC KS T Tkey AllFactories Instance,
31+ private.synth-instance Params KC Tkey AllFactories ClassInstance,
32+
33+ get-constructor Structure KS,
34+ std.append Params [T, ClassInstance] InstanceArgs,
35+ Instance = app[global KS | InstanceArgs]
3336
3437].
3538
39+ pred main-use-factories i:term, i:list argument, o:term.
40+ main-use-factories Ty FactoriesSkel ClassInstance :- std.do! [
41+ std.assert! (not(var Ty)) "HB.from: the class cannot be unknown",
42+
43+ factory? {unwind {whd Ty []}} (triple Class Params T),
44+
45+ std.assert! (class-def (class Class _ _)) "HB.from: not a class",
46+
47+ get-constructor Class KC,
48+
49+ private.elab-factories FactoriesSkel T Factories,
50+
51+ if (var T) (coq.error "HB.from: you must pass a type or at least one factory") true,
52+
53+ if2 (T = app[global (const SortProj)|ProjParams], structure-key SortProj ClassProj _)
54+ (AllFactories = [app[global (const ClassProj)|ProjParams] | Factories], Tkey = T) % already existing class on T
55+ (def T _ _ Tkey) % we unfold letins if we can, they may hide constants with CS instances
56+ (AllFactories = Factories)
57+ (AllFactories = Factories, Tkey = T), % it's a factory, won't add anything
58+
59+ private.try-synth-instance Params KC Tkey AllFactories ClassInstance,
60+
61+ ].
62+
63+
3664/* ------------------------------------------------------------------------- */
3765/* ----------------------------- private code ------------------------------ */
3866/* ------------------------------------------------------------------------- */
3967
4068namespace private {
4169
42- pred synth-instance i:list term, i:gref, i:gref, i:term, i: term, i:list term, o:term.
43- synth-instance Params KC KS T Tkey [Factory|Factories] Instance :-
70+ pred synth-instance i:list term, i:gref, i:term, i:list term, o:term.
71+ synth-instance Params KC Tkey [Factory|Factories] ClassInstance :-
4472 synthesis.under-new-mixin-src-from-factory.do! Tkey Factory (_\
45- synth-instance Params KC KS T Tkey Factories Instance ).
46- synth-instance Params KC KS T Tkey [] Instance :- coq.safe-dest-app Tkey (global _) _, !,
73+ synth-instance Params KC Tkey Factories ClassInstance ).
74+ synth-instance Params KC Tkey [] ClassInstance :- coq.safe-dest-app Tkey (global _) _, !,
4775 synthesis.under-local-canonical-mixins-of.do! Tkey [
4876 std.assert-ok! (synthesis.infer-all-args-let Params Tkey KC ClassInstance) "HB.pack: cannot infer the instance",
49- std.append Params [T, ClassInstance] InstanceArgs,
50- Instance = app[global KS | InstanceArgs]
5177].
52- synth-instance Params KC KS T Tkey [] Instance :- std.do! [
78+ synth-instance Params KC Tkey [] ClassInstance :- std.do! [
5379 std.assert-ok! (synthesis.infer-all-args-let Params Tkey KC ClassInstance) "HB.pack: cannot infer the instance",
54- std.append Params [T, ClassInstance] InstanceArgs,
55- Instance = app[global KS | InstanceArgs]
80+ ].
81+
82+ pred try-synth-instance i:list term, i:gref, i:term, i:list term, o:term.
83+ try-synth-instance Params KC Tkey [Factory|Factories] ClassInstance :-
84+ synthesis.under-new-mixin-src-from-factory.do! Tkey Factory (_\
85+ try-synth-instance Params KC Tkey Factories ClassInstance).
86+ try-synth-instance Params KC Tkey [] ClassInstance :- coq.safe-dest-app Tkey (global _) _, !,
87+ synthesis.under-local-canonical-mixins-of.do! Tkey [
88+ synthesis.try-infer-all-args-let Params Tkey KC ClassInstance,
89+ ].
90+ try-synth-instance Params KC Tkey [] ClassInstance :- std.do! [
91+ synthesis.try-infer-all-args-let Params Tkey KC ClassInstance,
5692].
5793
5894pred elab-factories i:list argument, i:term, o:list term.
0 commit comments