Skip to content

Commit d253bce

Browse files
authored
Merge pull request #522 from Tragicus/uniq-mixin
2 parents 7b41a5d + 5019966 commit d253bce

3 files changed

Lines changed: 28 additions & 18 deletions

File tree

HB/common/synthesis.elpi

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,22 @@ assert!-infer-mixin T M B :-
8686

8787
% Given TheType it looks all canonical structure instances on it and makes
8888
% all their mixins available for inference
89-
pred under-local-canonical-mixins-of.do! i:term, i:list prop.
90-
under-local-canonical-mixins-of.do! T P :- std.do! [
89+
pred local-canonical-mixins-of.aux i:term, i:list structure, o:list prop.
90+
local-canonical-mixins-of.aux _ [] [].
91+
local-canonical-mixins-of.aux T [S|Ss] MSL'' :- std.do! [
92+
private.structure-instance->mixin-srcs T S MSL,
93+
MSL => local-canonical-mixins-of.aux T Ss MSL',
94+
std.append MSL MSL' MSL'',
95+
].
96+
97+
pred local-canonical-mixins-of i:term, o:list prop.
98+
local-canonical-mixins-of T MSL :- std.do! [
9199
get-canonical-structures T CS,
92-
std.map CS (private.structure-instance->mixin-srcs T) MSLL,
93-
std.flatten MSLL MSL,
94-
MSL => std.do! P
95-
].
100+
std.map CS (s\c\ sigma w\ class-def (class c s w)) Cl,
101+
toposort-classes Cl ClSorted,
102+
std.map ClSorted (c\s\ sigma w\ class-def (class c s w)) CSSorted,
103+
local-canonical-mixins-of.aux T CSSorted MSL,
104+
].
96105

97106
% Given TheType and a factory instance (on it), makes all the mixins provided by
98107
% the factory available for inference.
@@ -298,7 +307,7 @@ structure-instance->mixin-srcs.aux2 Params T Class (some P) M :-
298307
coq.mk-app (global (const P)) {std.append Params [T,Class]} M.
299308
structure-instance->mixin-srcs.aux T F CL :-
300309
factory-instance->new-mixins [] F ML,
301-
std.map ML (m\c\ c = mixin-src T m F) CL.
310+
std.map-filter ML (m\c\ not (mixin-src T m _), c = mixin-src T m F) CL.
302311

303312
% [factory-instance->new-mixins OldMixins FI MSL] find all the mixins
304313
% which can be generated by the factory instance FI which are not part of

HB/instance.elpi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,9 @@ declare-canonical-instances-from-factory Factory T F ClausesHas CFL CSL :- std.d
391391
% priority must be given to canonical mixins
392392
% as they are the ones which guarantee forgetful inheritance
393393
% hence we add these clauses last.
394+
synthesis.local-canonical-mixins-of T MLCano,
394395
synthesis.under-mixin-src-from-factory.do! T F [
395-
synthesis.under-local-canonical-mixins-of.do! T [
396+
MLCano => std.do! [
396397
list-w-params_list {factory-provides Factory} ML,
397398
add-all-mixins T Factory ML tt Clauses CFL,
398399
std.map-filter Clauses (mixin-src->has-mixin-instance ) ClausesHas,

HB/pack.elpi

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,21 @@ main Ty Args Instance :- std.do! [
3939

4040
namespace private {
4141

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 :-
42+
pred synth-instance.aux i:list term, i:gref, i:gref, i:term, i:term, i:list term, i:list prop, o:term.
43+
synth-instance.aux Params KC KS T Tkey [Factory|Factories] MLCano Instance :-
4444
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 _) _, !,
47-
synthesis.under-local-canonical-mixins-of.do! Tkey [
45+
synth-instance.aux Params KC KS T Tkey Factories MLCano Instance).
46+
synth-instance.aux Params KC KS T Tkey [] MLCano Instance :-
47+
MLCano => std.do! [
4848
std.assert-ok! (synthesis.infer-all-args-let Params Tkey KC ClassInstance) "HB.pack: cannot infer the instance",
4949
std.append Params [T, ClassInstance] InstanceArgs,
5050
Instance = app[global KS | InstanceArgs]
5151
].
52-
synth-instance Params KC KS T Tkey [] Instance :- std.do! [
53-
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]
56-
].
52+
53+
pred synth-instance i:list term, i:gref, i:gref, i:term, i:term, i:list term, o:term.
54+
synth-instance Params KC KS T Tkey Factories Instance :-
55+
if (coq.safe-dest-app Tkey (global _) _) (synthesis.local-canonical-mixins-of Tkey MLCano) (MLCano = []),
56+
synth-instance.aux Params KC KS T Tkey Factories MLCano Instance.
5757

5858
pred elab-factories i:list argument, i:term, o:list term.
5959
elab-factories [] _ [].

0 commit comments

Comments
 (0)