Skip to content

front: resolve an ambiguous name path to None in GraphBodyProvider - #839

Merged
youknowone merged 1 commit into
mainfrom
gc-decouple
Jul 27, 2026
Merged

front: resolve an ambiguous name path to None in GraphBodyProvider#839
youknowone merged 1 commit into
mainfrom
gc-decouple

Conversation

@youknowone

@youknowone youknowone commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Follow-up to #835, from its Codex parity review (section 2).

GraphBodyProvider::source_for_name_path returned the first FunDecl whose
name_path() matched. Two extracted FunDecls can render the same name path,
and in that case the first match binds a body that belongs to a different
funcobj — silently, because the caller sees a perfectly ordinary hit.

bookkeeper.py:361 getdesc(pyobj) keys a descriptor by the function object
itself, so upstream never conflates two functions that happen to share a name.
A Charon name path carries no such identity. GraphBodySource — the
(llbc_index, def_id) pair recorded at registration — is what does, and it is
already what the demand path resolves against; the name lookup is only the
registration-time/test seam.

So the helper now scans the whole corpus and returns None when more than one
FunDecl carries the name. A miss is visible where a wrong body is not.

provider_reproduces_the_eagerly_lowered_body gains a second job for free: it
looks every lowerable funcobj up by name, so a duplicate name path anywhere in
the corpus fixture now fails the test as a lookup miss.

No production behaviour changes — the provider still has no production call
site, as noted in #835.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved function lookup reliability by rejecting ambiguous matches instead of selecting one arbitrarily.
    • Updated error reporting to clearly distinguish missing functions from non-unique matches.
  • Tests

    • Strengthened coverage to verify that lowerable functions have unique name paths.

source_for_name_path returned the first FunDecl whose name_path matched.
Two extracted FunDecls can render the same name path, in which case the
first match binds a body from a different funcobj.

Scan the whole corpus and return None when more than one FunDecl carries
the name. bookkeeper.py:361 getdesc keys a descriptor by the function
object; a name path carries no such identity, and GraphBodySource is what
the demand path resolves against.

provider_reproduces_the_eagerly_lowered_body now also fails on a duplicate
name path in the corpus fixture, as a lookup miss.

Assisted-by: Claude
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 323c160a-b055-4360-a533-cc20815bbb78

📥 Commits

Reviewing files that changed from the base of the PR and between 0f2775f and 86ddf6e.

📒 Files selected for processing (1)
  • majit/majit-translate/src/front/graph_body.rs

Walkthrough

source_for_name_path now requires exactly one matching local function. Ambiguous name paths return None, and the method documentation and related test comments and panic text describe the uniqueness requirement.

Changes

Graph body lookup

Layer / File(s) Summary
Unique name-path resolution
majit/majit-translate/src/front/graph_body.rs
source_for_name_path returns None when multiple functions share a name path, while documentation and test diagnostics reflect the updated contract.

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

Poem

I’m a bunny guarding names in a row,
One match is clear; two must go.
No more guessing through the hay,
Ambiguous paths now fade away.
Hop, hop—tests tell the tale!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: ambiguous name-path lookups in GraphBodyProvider now return None.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch gc-decouple

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.

@github-actions

Copy link
Copy Markdown

🤖 Codex parity review

Static analysis of this diff vs the local RPython/PyPy sources (commit 86ddf6e).
Updated: 2026-07-27T13:21:18.188Z

Files in the reviewed diff
majit/majit-translate/src/front/graph_body.rs

1. Regressions to PyPy parity introduced by this patch

None.

2. Other mismatches introduced by this patch

None.

3. Pre-existing mismatches (already present before this patch)

  • Documentation location is stale: majit/majit-translate/src/front/graph_body.rs:3 ↔ rpython/translator/translator.py:68. The Rust comment says translator.py:55 buildflowgraph(func), but line 55 is configuration setup; buildflowgraph starts at line 68.

  • Documentation location is stale: majit/majit-translate/src/front/graph_body.rs:5 ↔ rpython/annotator/description.py:228. The comment cites description.py:1037 FunctionDesc.cachedgraph, while the local corresponding method begins at line 228.

4. Structural adaptations

  • majit/majit-translate/src/front/graph_body.rs:81-97 ↔ rpython/annotator/bookkeeper.py:361-366. PyPy keys descriptors by Constant(pyobj) and can distinguish same-named function objects; Charon name_path() is not object identity. The patch’s “return None on ambiguity” behavior is a deliberate safe adaptation, avoiding the prior first-match conflation. The actual demand identity remains (llbc_index, def_id) in GraphBodySource, as documented at graph_body.rs:76-77.

@youknowone
youknowone merged commit ca16a8f into main Jul 27, 2026
18 of 19 checks passed
@youknowone
youknowone deleted the gc-decouple branch July 27, 2026 15:48
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