@@ -12,7 +12,6 @@ main Ty Args Instance :- std.do! [
12
12
std.assert! (Args = [trm TSkel|FactoriesSkel]) "HB.pack: not enough arguments",
13
13
14
14
get-constructor Class KC,
15
- get-constructor Structure KS,
16
15
17
16
std.assert-ok! (d\
18
17
(coq.elaborate-ty-skeleton TSkel _ T d, d = ok) ;
@@ -29,30 +28,67 @@ main Ty Args Instance :- std.do! [
29
28
(AllFactories = Factories)
30
29
(AllFactories = Factories, Tkey = T), % it's a factory, won't add anything
31
30
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]
33
36
34
37
].
35
38
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
+
36
64
/* ------------------------------------------------------------------------- */
37
65
/* ----------------------------- private code ------------------------------ */
38
66
/* ------------------------------------------------------------------------- */
39
67
40
68
namespace private {
41
69
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 :-
44
72
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 _) _, !,
47
75
synthesis.under-local-canonical-mixins-of.do! Tkey [
48
76
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]
51
77
].
52
- synth-instance Params KC KS T Tkey [] Instance :- std.do! [
78
+ synth-instance Params KC Tkey [] ClassInstance :- std.do! [
53
79
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,
56
92
].
57
93
58
94
pred elab-factories i:list argument, i:term, o:list term.
0 commit comments