Skip to content

Use proper envs for Rust functions #7623

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Use proper envs for Rust functions #7623

wants to merge 1 commit into from

Conversation

nrc
Copy link
Contributor

@nrc nrc commented Jun 27, 2025

Closes #7588

We use a stack for memory management. When a function is called we push a new frame onto the stack (aka a root environment). For efficiency and perhaps to catch some bugs, when we call a Rust function (i.e., a std lib function), we don't push a new frame and set the frame 'pointer' to a dummy value. However, when we call map or similar higher-order functions, the Rust definition calls other functions. This should be OK because we'll push a fresh stack frame for the callee if it is a KCL function and if it is a Rust function, it doesn't need a stack frame. However, when we type check the function call we might need to look up names in memory for which we need a real stack frame.

To fix this issue I considered working around this by special-casing the Rust envs, but it increased complexity for an unproven optimisation (since most Rust calls are leaf functions we mostly only save a single stack frame which is pretty lightweight). Instead I removed the Rust function special case and now we do create a stack frame for all functions, Rust or KCL. This is a simplification and we can optimise if it's shown to be slow.

@nrc nrc requested a review from adamchalmers June 27, 2025 08:14
@nrc nrc requested a review from a team as a code owner June 27, 2025 08:14
Copy link

vercel bot commented Jun 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
modeling-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 27, 2025 8:17am

Copy link

codspeed-hq bot commented Jun 27, 2025

CodSpeed Instrumentation Performance Report

Merging #7623 will not alter performance

Comparing nrc-mem-rust (762fb48) with main (107adc7)

Summary

✅ 85 untouched benchmarks

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.

KCL memory crash
1 participant