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

support methods with the VM backend #775

Merged
merged 2 commits into from
Jun 27, 2023

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Jun 27, 2023

Summary

Enable dispatcher generation for the VM backend, which makes method
(including multi-methods) available for the standalone VM target. Note
that this doesn't apply to compile-time execution, where using methods
is still unsupported.

Details

  • move the chckNilDisp compilerproc into the system module and
    replace the == nil with isNil (more on that later)
  • only report errors on method usage from vmgne when not in the
    standalone mode
  • rename the realType procedure to routineSignature
  • generate the method dispatcher prior to generating code in
    vmbackend
  • where possible, enable the method tests for the VM target

The VM code generator (vmgen) previously checked for whether a
procedure returns something by testing for the presence of a procedure's
result AST slot. For methods - where the AST always has a result
slot, regardless of whether they have a return value - this test is
no longer enough, and is replaced with inspecting the return type.

Regarding the == nil -> isNil change: the VM comparison operator for
pointer-like types (which == maps to) requires both operands to be of
same dynamic type, but in chckNilDisp, this is not necessarily the
case (for example, when the dispatched-through type is a ref type).
The proper solution would be for cgmeth.genDispatcher to wrap the
argument in a cast[pointer], but the VM doesn't yet support casting
references to pointers.

Summary
=======

Enable dispatcher generation for the VM backend, which makes `method`
(including multi-methods) available for the standalone VM target. Note
that this doesn't apply to compile-time execution, where using `method`s
is still unsupported.

Details
=======

* move the `chckNilDisp` compilerproc into the `system` module and
  replace the `== nil` with `isNil` (more on that later)
* only report errors on method usage from `vmgne` when not in the
  `standalone` mode
* generate the method dispatcher prior to generating code in `vmbackend`

The VM code generator (`vmgen`) previously checked for whether a
procedure returns something by testing for the presence of a procedure's
`result` AST slot. For methods - where the AST always has a `result`
slot, regardless of whether they have a return value - this test is
no longer enough, and is replaced with inspecting the return type.

Regarding the `== nil` -> `isNil` change: the VM comparison operator for
pointer-like types (which `==` maps to) requires both operands to be of
same dynamic type, but in `chckNilDisp`, this is not necessarily the
case (for example, when the dispatched-through type is a `ref` type).
The proper solution would be for `cgmeth.genDispatcher` to wrap the
argument in a `cast[pointer]`, but the VM doesn't yet support casting
references to pointers.
@zerbina zerbina added enhancement New feature or request compiler/backend Related to backend system of the compiler labels Jun 27, 2023
Copy link
Collaborator

@saem saem left a comment

Choose a reason for hiding this comment

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

the unification is really highlighted as the tests are applied across all backends.

@saem
Copy link
Collaborator

saem commented Jun 27, 2023

/merge

@github-actions
Copy link

Merge requested by: @saem

Contents after the first section break of the PR description has been removed and preserved below:


Notes for Reviewers

@chore-runner chore-runner bot added this pull request to the merge queue Jun 27, 2023
Merged via the queue into nim-works:devel with commit 741ed44 Jun 27, 2023
@zerbina zerbina deleted the method-support-for-vm-backend branch June 27, 2023 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/backend Related to backend system of the compiler enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants