Skip to content

Use RuntimeGeneratedFunctions instead of eval#82

Open
dpsanders wants to merge 2 commits into
add-ssa-functionfrom
use-runtime-generated-functions
Open

Use RuntimeGeneratedFunctions instead of eval#82
dpsanders wants to merge 2 commits into
add-ssa-functionfrom
use-runtime-generated-functions

Conversation

@dpsanders

Copy link
Copy Markdown
Member

Summary

  • Replaces the two runtime eval(...) calls that build closures (in gradient and forward_backward_contractor) with @RuntimeGeneratedFunction, so callers can build and invoke a generated function in the same dynamic extent without hitting Julia world-age errors.
  • Adds RuntimeGeneratedFunctions 0.5 as a direct dependency and initializes it in the module.
  • Load-time @evals in reverse_icp.jl (per-operator _rev_* wrappers registered with Symbolics) are left alone — they don't suffer from world-age issues.

Notes

  • RGF doesn't accept destructuring patterns in argument position, so the generated closures now take plain argument symbols (__args, __inputs, __constraint, __params) and destructure on the first line of the body. Calling convention from the user's side is unchanged.
  • Stacked on top of Add SSAFunction type, refactor pipeline to accept SSA input #80 (add-ssa-function).

Benchmarks (median; see commit message / discussion for full numbers)

Operation eval (baseline) RGF
gradient build, 2 vars 907 μs 126 μs (7.2×)
gradient build, 3 vars + transcendentals 2.08 ms 555 μs (3.8×)
forward_backward_contractor build, x²+y² 1.39 ms 89 μs (15.6×)
fwd_bwd_contractor call 479 ns 504 ns (noise)

Steady-state call cost is essentially unchanged in realistic use.

Test plan

  • Pkg.test() passes locally (12/12)
  • Smoke test: build and invoke a generated gradient and contractor inside a single function body (previously would raise a world-age error)

🤖 Generated with Claude Code

@dpsanders dpsanders force-pushed the use-runtime-generated-functions branch from 1fac8f2 to 23a0150 Compare April 19, 2026 18:14
dpsanders and others added 2 commits April 19, 2026 14:29
Avoids world-age issues when building and invoking a generated gradient
or forward-backward contractor in the same dynamic extent.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Patch bump for the RuntimeGeneratedFunctions swap: no changes to the
exported API's calling convention, just a correctness fix (no more
world-age errors) and a substantial build-time speedup.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@dpsanders dpsanders force-pushed the use-runtime-generated-functions branch from 23a0150 to 746ff0c Compare April 19, 2026 19:30
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.

1 participant