@@ -78,13 +78,20 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [
7878 acc-clauses current Clauses
7979].
8080
81+ % [not-subclass-of X C] holds if C does not inherit from X
82+ pred not-subclass-of i:classname, i:class.
83+ not-subclass-of HasNoInstance (class C _ _) :- not(sub-class C HasNoInstance _ _).
84+
8185% [declare-all T CL MCSTL] given a type T and a list of class definition
8286% CL in topological order (from least dep to most) looks for classes
8387% for which all the dependencies (mixins) were postulated so far and skips the
8488% rest. For each fulfilled class it declares a local constant inhabiting the
8589% corresponding structure and declares it canonical.
8690% Each mixin used in order to fulfill a class is returned together with its name.
8791pred declare-all i:term, i:list class, o:list (pair id constant).
92+ declare-all _ [] [].
93+ declare-all T [class _ Struct _|Rest] L :- has-instance T Struct, !,
94+ declare-all T Rest L.
8895declare-all T [class Class Struct MLwP|Rest] [pr Name CS|L] :-
8996
9097 infer-class T Class Struct MLwP S Name STy Clauses,
@@ -95,19 +102,24 @@ declare-all T [class Class Struct MLwP|Rest] [pr Name CS|L] :-
95102
96103 Clauses => declare-all T Rest L.
97104
98- declare-all T [_|Rest] L :- declare-all T Rest L.
99- declare-all _ [] [].
105+ declare-all T [class HasNoInstance _ _|Rest] L :-
106+ % filter out classes we can't build for sure
107+ std.filter Rest (not-subclass-of HasNoInstance) Rest1,
108+ declare-all T Rest1 L.
100109
101110% for generic types, we need first to instantiate them by giving them holes,
102111% so they can be used to instantiate the classes
103112pred declare-all-on-type-constructor i:term, i:list class, o:list (pair id constant).
104- declare-all-on-type-constructor T [class Class Struct MLwP|Rest] [pr Name CS|L] :-
113+ declare-all-on-type-constructor _ [] [].
114+ declare-all-on-type-constructor TK [class _ Struct _|Rest] L :- saturate-type-constructor TK T, has-instance T Struct, !,
115+ declare-all-on-type-constructor TK Rest L.
116+ declare-all-on-type-constructor TK [class Class Struct MLwP|Rest] [pr Name CS|L] :-
105117
106118 %TODO: compute the arity of the Class subject and saturate up to that point
107119 % there may even be more than one possibility
108- saturate-type-constructor T Ty ,
120+ saturate-type-constructor TK T ,
109121
110- infer-class Ty Class Struct MLwP S Name _STy Clauses,
122+ infer-class T Class Struct MLwP S Name _STy Clauses,
111123
112124 !,
113125
@@ -116,20 +128,23 @@ declare-all-on-type-constructor T [class Class Struct MLwP|Rest] [pr Name CS|L]
116128
117129 decl-const-in-struct Name SC SCTy CS,
118130
119- Clauses => declare-all-on-type-constructor T Rest L.
131+ Clauses => declare-all-on-type-constructor TK Rest L.
120132
121- declare-all-on-type-constructor T [_|Rest] L :- declare-all-on-type-constructor T Rest L.
122- declare-all-on-type-constructor _ [] [].
133+ declare-all-on-type-constructor TK [class HasNoInstance _ _|Rest] L :-
134+ % filter out classes we can't build for sure
135+ std.filter Rest (not-subclass-of HasNoInstance) Rest1,
136+ declare-all-on-type-constructor TK Rest1 L.
123137
124- pred infer-class i:term, i:classname, i:gref, i:factories, o:term, o:string, o:term, o:list prop.
125- infer-class T Class Struct MLwP S Name STy Clauses:- std.do![
126-
127- if (not(has-CS-instance? T Struct))
128- true % we build it
138+ pred has-instance i:term, i:structure.
139+ has-instance T Struct :-
140+ if (has-CS-instance? T Struct)
129141 (if-verbose (coq.say {header} "skipping already existing"
130142 {nice-gref->string Struct} "instance on"
131- {coq.term->string T}),
132- fail),
143+ {coq.term->string T}))
144+ fail. % we build it
145+
146+ pred infer-class i:term, i:classname, i:gref, i:factories, o:term, o:string, o:term, o:list prop.
147+ infer-class T Class Struct MLwP S Name STy Clauses:- std.do![
133148
134149 params->holes MLwP Params,
135150 get-constructor Class KC,
0 commit comments