16994, “vasslitvinov”, “CG: semantics of automatic inference of constraints / ‘implements’ declarations”, “2021-01-23T18:00:40Z”
main issue: #8629 whether to infer #16952
If/when we want to infer a constraint / an implements
declaration at a callsite of a CG function according to #16952, what are the rules? In particular:
(equiv) A constraint is satisfied implicitly IFF if we place the corresponding implements
statement with an empty body immediately before the callsite, it would be correct.
interface I {
proc f(arg: Self);
}
proc cgFun(arg: ?Q) where Q implements I {
f(arg);
}
// The below call cgFun(5) resolves IFF
// the following implements-statement would be correct:
//int implements I;
cgFun(5);
(no-shadow) If there is a matching implements
statement that is visible at the callsite, no inference takes place. That is, we do not use any shadowing functions even when they are available. For example:
interface I {
proc f(arg: Self);
}
proc f(arg: int) { writeln("f#1"); }
int implements I; // uses f#1
proc cgFun(arg: ?Q) where Q implements I {
f(arg);
}
{
// f#2 shadows f#1
proc f(arg: int) { writeln("f#2"); }
// If we inferred `int implements I` here,
// it would be implemented with f#2.
// However, since there is a visible implements-statement already,
// we use the implementation that comes with that, which is f#1.
cgFun(5);
}