17273, "vasslitvinov", "CG: how to ensure consistent implementation of an interface for a data structure?", "2021-02-25T21:34:05Z"
Main issue: #8629 related: #10802 inspired by https://youtu.be/LIYkT3p5gTs?t=1068
If a data structure is created with one implementation of an interface, how to ensure it is always used with that implementation rather than with some other implementation?
Here is an example where this is violated:
interface Hashable {
proc Self.hash(): int;
}
record hashSet {
type eltType;
...
}
proc populateHashSet(ref hs: hashSet)
where hs.eltType implements Hashable
{ ... }
proc trimHashSet(ref hs: hashSet)
where hs.eltType implements Hashable
{ ... }
var globalHS: hashSet(int);
module M1 {
int implements Hashable;
proc int.hash() return this;
proc doM1() {
populateHashSet(globalHS); // populateHashSet uses M1's int.hash()
}
}
module M2 {
int implements Hashable;
proc int.hash() return this + 1;
proc doM2() {
trimHashSet(globalHS); // trimHashSet uses M2's int.hash()
}
}
proc main {
use M1, M2;
doM1(); doM2(); // globalHS is accessed using different implementations of int.hash()
}