New Issue: how should dynamic dispatch interact with tertiary methods?

16854, “mppf”, “how should dynamic dispatch interact with tertiary methods?”, “2020-12-11T14:39:10Z”

This issue is a spin-off from https://github.com/chapel-lang/chapel/issues/16852#issuecomment-742875588

Other elements of our current direction for method visibility have tertiary methods only available when they are visible (e.g. from use ModuleDefiningTertiaryMethod possibly with only SomeType). However, for methods that are dynamically dispatched, should the visibility of an override proc affect the dynamic dispatch?

Here is an example to think about:

module DefinesParentChild {
  class Parent {
    proc method() {
      writeln("Parent.method()");
    }
  }
  class Child: Parent { }
}

module DefinesOverride {
  use DefinesParentChild;

  override proc Child.method() {
    writeln("Child.method()");
  }
}

module Tests {
  { // case 1
    use DefinesParentChild;
    var child: owned Child = new Child();
    child.method(); // does it run Parent.method or Child.method ?
  }
  { // case 2
    use DefinesParentChild;
    var child: owned Parent = new Child();
    child.method(); // does it run Parent.method or Child.method ?
  }
  { // case 3
    use DefinesParentChild;
    use DefinesOverride;
    var child: owned Child = new Child();
    child.method(); // does it run Parent.method or Child.method ?
  }
  { // case 4
    use DefinesParentChild;
    use DefinesOverride;
    var child: owned Parent = new Child();
    child.method(); // does it run Parent.method or Child.method ?
  }
}

What does it do today?

* case 1 runs Child.method * case 2 runs Child.method * case 3 results in an overload sets error * case 4 runs Child.method

Possible directions than I can think of:

  • it is an error to define a tertiary override proc
  • such an override proc is always called if the dynamic type is compatible
  • the dynamic dispatch uses information about visibility in the call at runtime to more closely match the non-dynamic behavior