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

remove low-level subroutines #17

Merged
merged 8 commits into from
Aug 18, 2024
Merged

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Aug 17, 2024

Summary

Remove subroutine support from the VM and L3-0. This significantly
simplifies the VM and brings the target languages closer together, thus
reducing future work and simplifying the overall compiler architecture.

Details

  • remove the subroutine-related VM instructions
  • simplify the VM's exception handling; the dedicated EH code is
    obsolete and thus removed
  • adjust the err_goto grammar and associated tests
  • remove the Subroutine grammar from L3-0
  • remove the now-unused Subroutine and List node kinds
  • remove tests for subroutines

Motivation

The motivation behind removing low-level subroutines is two-fold:

  1. they only exist for the VM target - asm.js, Wasm, and C don't have
    them -, which complicates the compiler architecture
  2. they have a fairly high implementation complexity in the VM

Number 1 is the main reason for the removal. Languages without low-
level subroutines need a local + Select dispatcher to emulate them.

This lowering would be best be implemented at a higher-level, so that
the optimization passed can take the locals' data-flow into account,
but this requires all ILs below to support two dialects: one with and
one without subroutines.

Alternatively, the lowering could be done at a lower level, but this
would result in the same dialect problem as the other approach
(although to a lesser degree), and it'd also result in worse code
generation.

Since low-level subroutines are only an optimization, and the VM is the
only target out of the planned ones to support it, removing them is the
overall better choice, as it reduced the surface area of ILs and the
VM, as well as making lowering passes from subroutines into dispatchers
unnecessary.

* remove the subroutine-related instruction
* remove the subroutine-related handling from the VM
* simplify exception handling; the dedicated EH code is obsolete
* `ehTable` now maps instructions directly to instructions
* a straightforward removal, for the most part
* validation of the EH table is adjusted
* remove the `Subroutine` grammar
* remove the code generation related to subroutines
They're unused now. Should they be needed again, they can be re-added.
* remove the subroutine-related tests
* update `t04_except` to the new `err_goto` grammar
@zerbina
Copy link
Collaborator Author

zerbina commented Aug 17, 2024

The removal of low-level subroutines doesn't mean that subroutines become impossible to implement, just that they don't have a specialized implementation when using the VM. Whether the specialized implementation was actually more efficient than manual branching is also questionable, since it complicated exception handling in the VM significantly.

@saem saem merged commit 6ef36e1 into nim-works:main Aug 18, 2024
5 checks passed
@zerbina zerbina deleted the vm-remove-subroutines branch August 18, 2024 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants