Skip to content

Add dedicated hostcall for inner PVM module compilation - #530

Open
koute wants to merge 12 commits into
gavofyork:mainfrom
koute:main_compile_host_call
Open

Add dedicated hostcall for inner PVM module compilation#530
koute wants to merge 12 commits into
gavofyork:mainfrom
koute:main_compile_host_call

Conversation

@koute

@koute koute commented May 28, 2026

Copy link
Copy Markdown
Collaborator

This PR adds a dedicated hostcall to compile inner PVM modules.

  • The new compile hostcall which can compile a new PVM module from outer PVM's memory, or directly from a preimage in the database (this avoids the need to first fetch and copy the module's bytecode into the outer PVM's memory; it's essentially a historical_lookup + compiling from memory call merged into one)
  • machine now accepts a handle returned by the compile hostcalls (this makes it much cheaper to instantiate multiple VMs provided they use the same module)
  • expunge hostcall can now also destroy a compiled module handle, and accepts an extra argument which determines the type of handle that was passed
  • There's a maximum limit of 128 modules that can be kept in memory at the same time (this is subject to change if necessary)
  • The compiled modules are reference counted, so if there exists a live VM instance which uses a given PVM module then that module is also considered alive, even if it was expunged

Arguments to the compile hostcall are as follows:

  • φ7 (m) -> mode of operation, with 0 being from memory and 1 from a preimage
  • φ8 (p) -> pointer to the blob (memory mode) or a hash of the blob (preimage mode)
  • φ9 (l) -> length of the blob (memory mode) or maximum length of the blob used (preimage mode)
  • φ10 (f) -> offset in the blob (preimage mode only)
  • φ11 (i) -> service ID (preimage mode only)

Arguments to the expunge hostcall are:

  • φ7 (m) -> mode of operation, with 0 being an expunge of a VM instance, and 1 being an expunge of a program module
  • φ8 (n) -> handle to expunge

Rendered PDF.

@gavofyork

Copy link
Copy Markdown
Owner

There's no precedent on using multi-character subscripts in the $$\Omega$ formulations. I'd prefer to keep to single characters.

@gavofyork

Copy link
Copy Markdown
Owner

I also wonder how bad it would be to have the two compile_ variants be folded into a unified compile host-call? This is the convention thus far. I'd really like to keep the conceptual dictionary as minimal as possible.

@koute

koute commented May 29, 2026

Copy link
Copy Markdown
Collaborator Author

Sure, I'll change the subscripts to be single letter.

I can also try to unify both compile_ hostcalls into one, and we can see how it looks like.

If you'd like we could also unify expunge with drop by having only expunge, and pass the type of the handle as an argument.

@koute

koute commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator Author

I've merged the two hostcalls into one. I've also merged drop into expunge while I was at it (let me know if you'd like them separate, in which case I can revert the change).

Also updated the PR description to describe the current state of the PR.

@koute koute changed the title Add dedicated hostcalls for inner PVM module compilation Add dedicated hostcall for inner PVM module compilation Jun 1, 2026
@gavofyork

Copy link
Copy Markdown
Owner

Yeah, looks good. Needs resolving...

@koute

koute commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator Author

Aligned with the newest changes on main.

@gavofyork

Copy link
Copy Markdown
Owner

Will need re-resolving again:) @koute

@koute

koute commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator Author

Done. Should aligned with what's on main now.

zdave-parity
zdave-parity previously approved these changes Jul 22, 2026

@zdave-parity zdave-parity left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, few trivial nits.

Comment thread preamble.tex Outdated
Comment thread text/pvm_invocations.tex Outdated
Comment thread text/pvm_invocations.tex Outdated
Comment thread text/pvm_invocations.tex Outdated
Comment thread preamble.tex Outdated
Comment thread preamble.tex Outdated
%%%%%%%%%%%%
% PVM-SPECIFIC ITEMS

\newcommand*{\pvm¬instance}{\mathbb{I}}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

pvm¬instance should stay where it was? The pattern in the "Named types" section is that you have the "named type" (eg pvm¬instance) followed by the names of the type's fields (for pvm¬instance these are pg¬code, pg¬ram, etc).

@koute koute Jul 28, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hm, well, \pvm¬instance (\mathbb{I}) is the type of the instance, and \pvm¬module (\mathbb{B}) is the type of the module. To me it makes sense to keep them together? I can split them, but that seems to be somewhat confusing, considering they're inherently related (you create an instance from a module).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I guess as \pvm¬module is a type it makes sense in the "Named types" section, but I found it confusing placed between the definition of \pvm¬instance and its fields. Anyway it doesn't really matter that much so I'll shut up now!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Heh, okay, well, in general I'm fine with whatever you prefer. (:

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.

3 participants