10000 vine: allow opaque ext fn in pre-reduce by nilscrm · Pull Request #317 · VineLang/vine · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

vine: allow opaque ext fn in pre-reduce #317

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

Merged
merged 3 commits into from
Jul 9, 2025
Merged

vine: allow opaque ext fn in pre-reduce #317

merged 3 commits into from
Jul 9, 2025

Conversation

nilscrm
Copy link
Contributor
@nilscrm nilscrm commented Jul 7, 2025

Currently the Vine compiler assumes exactly the IVM extrinsic functions for the pre-reduce optimization step. This change allows the pre-reduce step to handle arbitrary extrinsic function and is a step towards #257.

@nilscrm nilscrm requested a review from tjjfvi July 7, 2025 11:46
Copy link
Member
@tjjfvi tjjfvi left a comment

Choose a reason for hiding this comment

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

This currently panics if the custom ext fn is called during pre-reduce:

pub fn main(&io: &IO) {
  foo();
  foo();
}

fn foo() {
  custom_ext_fn(1, 2);
}

fn custom_ext_fn(a: N32, b: N32) -> N32 {
  inline_ivy! (a <- a, b <- b) -> N32 { out a = @custom_ext_fn(b out) }
}

Pre-reduce should treat the principal port of an opaque extrinsic function as though it were black_boxed.

I'm also not a fan of passing the Extrinsics as a parameter through everything; it would be much preferable to me if this could be implemented without needing to touch the Extrinsics.

Perhaps we could rename the Inert instruction to InertLink, and add an InertNode instruction that takes a label and three ports, and similarly just adds it to a buffer. Then, instead of creating an actual extrinsic function node, the host can insert an inert node with a label telling it what opaque extrinsic function it represented.

@nilscrm
Copy link
Contributor Author
nilscrm commented Jul 8, 2025

I'm now using InertNodes to implement the opaque extrinsic functions. Let me know if the way I implemented them works with the other parts of the IVM.

Also I have two more questions:

  • Should the Host have an explicit field allow_opaque_ext_fn to only allow them in the pre-reduce step and panic early in all other cases?
  • Should the IO ext fns also be opaque functions in the pre-reduce step, currently only the run-time guarantee that they will never interact with an IO handle makes them correct in the pre-reduce step?

Copy link
Member
@tjjfvi tjjfvi left a comment

Choose a reason for hiding this comment

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

Looking good!

Should the Host have an explicit field allow_opaque_ext_fn to only allow them in the pre-reduce step and panic early in all other cases?

Yeah – there's currently a black_box flag on the serializer which is enabled during pre-reduce, so I think it would make sense to rename this (maybe to allow_inert or similar) and use this flag to control the opaque ext fns as well.

Should the IO ext fns also be opaque functions in the pre-reduce step, currently only the run-time guarantee that they will never interact with an IO handle makes them correct in the pre-reduce step?

IMO this isn't necessary. It might happen eventually if we move some of the IO logic out of the core, but I don't think anything needs to be done for this now.

@nilscrm nilscrm requested a review from tjjfvi July 8, 2025 17:35
@tjjfvi tjjfvi added this pull request to the merge queue Jul 9, 2025
Merged via the queue into main with commit d07aaca Jul 9, 2025
7 checks passed
@tjjfvi tjjfvi deleted the custom-ext-fn branch July 9, 2025 16:46
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
0