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

Invoke instance methods for Any overrides #6441

Merged
merged 5 commits into from
Apr 28, 2023
Merged

Conversation

hubertp
Copy link
Collaborator

@hubertp hubertp commented Apr 26, 2023

Pull Request Description

This change modifies method dispatch for methods that override Any's definitions. When an overrided method is invoked statically we call Any's method to stay consistent.
This change primarily addresses the plethora of problems related to to_text invocations. It does not attempt to completely modify method dispatch logic.

Closes #6300.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • All code follows the
    Scala,
    Java,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • All code has been tested:
    • Unit tests have been written where possible.

This change modifies method dispatch for methods that override Any's
definitions. When an overrided method is invoked statically we call Any's
method to stay consistent.
This change primarily addresses the plethora of problems related to
`to_text` invocations. It does not attempt to completely modify method
dispatch logic.

Closes #6300.
@hubertp hubertp force-pushed the wip/hubert/6300-to-text branch from 67c3ffb to 190cdd5 Compare April 26, 2023 16:48
@hubertp hubertp added the CI: No changelog needed Do not require a changelog entry for this PR. label Apr 27, 2023
@hubertp hubertp marked this pull request as ready for review April 27, 2023 12:47
// and the method is invoked statically, i.e. type of self is the eigentype,
// then we want to disambiguate method resolution by always resolved to the one in Any.
if (where instanceof MethodRootNode node && typeCanOverride(node, EnsoContext.get(this))) {
Function anyFun = symbol.getScope().lookupMethodDefinition(EnsoContext.get(this).getBuiltins().any(), symbol.getName());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, we could resolve symbol on Any first and then on selfTpe. That unfortunately leads to more complicated checks (one problematic example is for example is_a that is defined on Any, Error, Meta and who knows what else) so I didn't pursue it further.

Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in tests look good.

Copy link
Member

@radeusgd radeusgd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Awesome

Looks good, I'm glad our error messages will be less painful now.

We have 2 workarounds in the test suite that should now become obsolete, both of the form:

        matcher_text = case matcher.to_text of
            text : Text -> text
            _ -> Meta.meta matcher . to_text

thanks to your fix, we should be able to replace them with just matcher_text = matcher.to_text (earlier we had this Meta.meta to go around this static dispatch issue, it was a brute-force band-aid fix).

Could you please remove these workarounds along this PR?

test/Tests/src/Semantic/Any_Spec.enso Show resolved Hide resolved
@hubertp hubertp added the CI: Ready to merge This PR is eligible for automatic merge label Apr 28, 2023
@mergify mergify bot merged commit ae3f902 into develop Apr 28, 2023
@mergify mergify bot deleted the wip/hubert/6300-to-text branch April 28, 2023 07:18
mergify bot pushed a commit that referenced this pull request May 4, 2023
…hot path (#6536)

Otherwise things can go horribly slow.
Closes #6523. Follow up on #6441.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type.to_text shall invoke instance method
3 participants