New Issue: Another problem with instantiation caching for different POIs

18119, "mppf", "Another problem with instantiation caching for different POIs", "2021-07-27T11:18:03Z"

Summary of Problem

Instantiation caching is supposed to use a cached instantiation when the point-of-instantiations are compatible. However, the below program reuses the instantiation of genericfunc(1) when it should not, between nCall and mGenericCall. These should be different because the have different POI-visible callback functions.

(See also PR #16261 and issue #15923.)

Note that as of PR #16158, we have the language design that the next point-of-instantiation scope is only consulted if there are not candidates found. The test below is exercising this behavior with mGenericCall, where M.helper1 should be found because it is in a closer POI than N.helper1.

Steps to Reproduce

Source Code:

module G {
  proc genericfunc(param p) {
    helper1();
    helper2();
    helper3();
  }
}

module M {
  use G;
  proc mCall() {
    writeln("mCall");
    genericfunc(1); // M.helper1, M.call.helper2, M.helper3
    proc helper2() { writeln("M.mCall.helper2"); }
  }
  proc mGenericCall(param p) {
    writeln("mGenericCall");
    genericfunc(p); // this call has POI here, parent POI N
                    // uses M.helper1, N.helper2, M.helper3
                    // -- so used scopes is {M,N}
  }
  proc helper1() { writeln("M.helper1"); }
  proc helper3() { writeln("M.helper3"); }
}

module N {
  use G,M;
  proc nCall() {
    writeln("nCall");
    genericfunc(1); // this call has POI here, no parent POI
                    // uses N.helper1, N.helper2, M.helper3
                    // -- so used scopes is {M,N}
  }
  proc helper1() { writeln("N.helper1"); }
  proc helper2() { writeln("N.helper2"); }

  proc main() {
    nCall();
    mCall();
    mGenericCall(1); // no bug if this call is first
  }
}

Expected output:

nCall
N.helper1
N.helper2
M.helper3
mCall
M.helper1
M.mCall.helper2
M.helper3
mGenericCall
M.helper1
N.helper2
M.helper3

Current output (Note that the difference is in the first line after mGenericCall):

nCall
N.helper1
N.helper2
M.helper3
mCall
M.helper1
M.mCall.helper2
M.helper3
mGenericCall
N.helper1
N.helper2
M.helper3

Associated Future Test(s):

TODO