Compile functions with $-prefixed parameters instead of bailing - #58
Merged
Conversation
$-params bind through ctx.dyn (dynamically scoped) rather than a slot, but every reference to one inside a body already compiled to Op::LoadDyn regardless of scope visibility -- the only missing piece was binding. compileFunctionLike now skips declareLocal for a $-param instead of bailing compilation of the whole function (and, since it's shared, the whole containing declaration for a closure's own $-param too). bindCompiledArgs/runCompiledFunctionFromBound route a matched $-param to childCtx.dyn instead of a slot, for both positional and named binding, with defaults applied the same way. No tail-call-specific handling needed: every hop rebinds arguments through the same helper as a genuine call, and dyn already threads correctly across tail hops.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
$-prefixed parameters (e.g.function f($fn) = ...) used to bail compilation of the whole containing declaration; they now compile, binding throughctx.dyninstead of a slot since every reference already compiled toOp::LoadDynregardless.FunctionLiteralclosure with its own$-param, sincecompileFunctionLikeis shared between plain functions and closures.ctx.dynconsistently for$-params, mirroring the interpreter's existingbindCallArgsInto/applyDefaultsbehavior.$-var dynamic scoping already threads correctly across hops.Test plan
DollarPrefixedParameterCompiles,ClosureWithDollarParameterNowCompilesToo) to instead prove compilation via the file's existing fast-continue stop-count technique (one of the old assertions turned out to be unreliable regardless of the fix --nulloptfast-continue forces interpretation for every function, not just the one under test).DollarParameterThreadsThroughCompiledTailRecursion-- a$fnparameter threaded through 50,000 compiled tail-recursive hops.🤖 Generated with Claude Code