Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use C3 linearization for multimethod dispatch #122

Open
Gattag opened this issue May 25, 2023 · 0 comments
Open

Use C3 linearization for multimethod dispatch #122

Gattag opened this issue May 25, 2023 · 0 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@Gattag
Copy link
Contributor

Gattag commented May 25, 2023

Procedure: Method Dispatch

  1. Compute the call signature:

    • Let M be the set of all methods.
    • Let mcs be the method referenced at the call-site.
    • Let scs be the signature of mcs.
    • Let sa be the type signature of the arguments at runtime.
    • The call signature s is obtained by substituting null arguments in sa with the corresponding parameter types from scs.
  2. Collect methods that match the call-site method’s name and number of arguments and have a supertype signiture of the :

    • Let M′ = {m ∈ M ∣ name(m) = name(mcs) ∧ numArgs(m) = numArgs(mcs) ∧ signature(m) :≥ s}.
  3. If M′ is empty, throw an exception as there are no dispatchable
    methods.

    • This condition may occur only when the method is called reflectively.
  4. Reduce the set to methods that are not supertypes of any other method in the set, these are the most specific signatures:

    • Let M″ = {m ∈ M′ ∣ ∀n ∈ M′ ∣ ¬(signature(m):>signature(n))}.
  5. At this point, M″ will have at least one member.

    • If |M″| = 1, dispatch to the single method in M″.
  6. If |M″| > 1, resolve ambiguity using a modified C3 linearization (the MPS variant) with precedence for arguments left to right.

    • Apply the modified C3 linearization algorithm to order the methods in M″ and determine the most preferred method for dispatch.
  7. At this point, the algorithm will always produce one most preferred method to dispatch to.

TODO formalize C3 and left to right precedence

@Gattag Gattag self-assigned this May 27, 2023
@Gattag Gattag added bug Something isn't working enhancement New feature or request labels May 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant