Skip to content

Preserve names of runtime interpreted functions and classes - #11008

Closed
proggeramlug wants to merge 2 commits into
mainfrom
fix/10676-dynamic-function-name
Closed

proggeramlug wants to merge 2 commits into
mainfrom
fix/10676-dynamic-function-name

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Preserve .name on named function declarations, function expressions, and class expressions evaluated by the runtime new Function interpreter. The interpreter already retained the parsed name for lexical self references, but it never installed the name on the returned closure.

Use the existing closure name setter after allocation while the closure is rooted. Literal source and the outer Function constructor keep their existing names.

Fixes #10676.

Testing

  • The new compiled fixture fails on untouched main with FUNCTION Literal and an empty CLASS name; the patched build prints FUNCTION Literal Named, CLASS Widget, and CONSTRUCTOR anonymous.
  • cargo test -p perry-runtime --lib interpreted_functions_and_classes_keep_their_declared_names
  • cargo test -p perry --test issue_10676_dynamic_function_names
  • cargo fmt --all -- --check, git diff --check, and scripts/check_file_size.sh

Summary by CodeRabbit

  • Bug Fixes

    • Fixed the .name property for named functions and classes created at runtime, including dynamically assembled sources.
    • Runtime-created function declarations, function expressions, and class expressions now retain their declared names.
    • Anonymous constructor functions continue to remain unnamed.
  • Tests

    • Added coverage for function and class names across literal and dynamically generated source code.

@coderabbitai

coderabbitai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 802df1e6-143f-4898-83cb-3b4d3b0d767b

📥 Commits

Reviewing files that changed from the base of the PR and between c7cbc3c and 83e6ffd.

📒 Files selected for processing (4)
  • changelog.d/11008-dynamic-function-names.md
  • crates/perry-runtime/src/dyn_eval/interp.rs
  • crates/perry-runtime/src/dyn_eval/tests.rs
  • crates/perry/tests/issue_10676_dynamic_function_names.rs

Included review availability: Your plan provides up to 8 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The interpreter now assigns declared names to named functions and classes created from runtime-generated new Function sources. Unit and integration tests verify names from literal and dynamically assembled sources.

Changes

Dynamic function and class names

Layer / File(s) Summary
Closure name assignment
crates/perry-runtime/src/dyn_eval/interp.rs
Named function expression closures and named class constructor closures now receive their declared names through set_bound_native_closure_name.
Name preservation validation
crates/perry-runtime/src/dyn_eval/tests.rs, crates/perry/tests/issue_10676_dynamic_function_names.rs, changelog.d/11008-dynamic-function-names.md
Unit and end-to-end tests verify names for interpreted functions, classes, constructors, and dynamically assembled sources. The changelog records the fix.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 83e6f

The change exposes declared names on dynamically created functions and classes, with no concrete production failure identified; it is ready to merge after normal checks.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preserving names for runtime-interpreted functions and classes.
Description check ✅ Passed The description explains the change, motivation, linked issue, implementation approach, and test commands. It does not use the template's separate Changes, Related issue, or Test plan headings and omi…
Linked Issues check ✅ Passed Issue [#10676] requires .name preservation for functions and classes created by the runtime new Function interpreter when source text is assembled at runtime. The implementation assigns the parsed…
Out of Scope Changes check ✅ Passed The changes stay within issue [#10676]. Runtime changes implement closure naming. Unit and integration tests verify the required behavior. The changelog fragment documents the fix. No unrelated produc…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. (1 skipped: 1 …
✨ Finishing Touches 💡 1
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proggeramlug

Copy link
Copy Markdown
Contributor Author

Landed on main in merge train 257 (#11039, v0.5.1640), main 990b3eeada.

Carried at head 83e6ffd77a. CI on the train head passed every job except the known public-baseline lint step: all 6 gap shards, cargo-test, e2e-scoped, gc-stress, check, warnings and security-audit green.

This train was split by blast radius after an earlier 35-PR assembly hit five gap regressions: it carries only PRs touching no lowering path. Trains rebase-merge, so commits get new SHAs and GitHub cannot mark this merged. Closed as landed.

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.

Dynamically-interpreted function/class .name is empty when the new Function source is built by concatenation rather than a literal

1 participant