interpreter: suppress the module-miss __spec__ diagnosis on swallowed attribute lookups - #1010
Conversation
|
Warning Review limit reached
Next review available in: 24 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
WalkthroughThe interpreter adds suppressed attribute lookup through shared lookup and module fallback paths. ChangesAttribute lookup behavior
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
@fregataa it makes sense, thank you! other failures seems irrelevant to this change, but could you check about the cargo test failure? |
3895976 to
cc591e7
Compare
|
Looked into the cargo test failure. It was the I believe it's a one-off runner OOM rather than something from this PR:
I've rebased onto current main and repushed, so CI is running again — will report if the failure reproduces. 🤖 Generated with Claude Code |
… attribute lookups A module attribute miss phrases its AttributeError through the __spec__ shadowing diagnosis, whose has_location property getter executes Python. hasattr-style probes paid that cost per call and discarded the result: dunder_import's fast-path __path__ check made `from math import pi, e` in a hot loop ~2.5x slower end-to-end. Mirror CPython's _PyObject_LookupAttr suppress flag: findattr / findattr_result, hasattr, and getattr-with-default still run the full protocol (PEP 562 module __getattr__ included) but keep the plain miss instead of building the diagnosis. Surfaced misses are unchanged. synth/import_from_hot drops from ~100x to 40x/59.6x vs pypy (dynasm/cranelift); its gate tightens 764 -> 180. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
cc591e7 to
a013993
Compare
|
Thank you for confirming! |
Problem
python3 pyre/check.py'ssynth/import_from_hotran ~100x slower than pypy. Profiling showed the compiled loop's residualIMPORT_NAMEcall spending most of its time constructing an AttributeError that is immediately discarded:dunder_import's fast path probes the module for__path__viafindattr_result, and every miss ran the full__spec__shadowing diagnosis — including thehas_locationproperty getter, which executes a Python frame — just to phrase a message nobody sees.Fix
Mirror CPython's
_PyObject_LookupAttr/module_getattro_impl(suppress)semantics: thread asuppressflag throughgetattr_str_impl→module_getattr_fallback→module_getattr_hook_or_err. Suppressed lookups still run the full protocol — the PEP 562 module__getattr__hook is called as before — but a terminal module miss keeps the plain error instead of building the diagnosis.Suppressed callers (all of which swallow the AttributeError, matching CPython's use of the suppressed lookup at each site):
findattr/findattr_result(coversdunder_import's__path__probe)builtin_hasattrbuiltin_getattrwhen a default is suppliedSurfaced misses (
math.nope, explicitModuleType.__getattribute__, from-import failures) are unchanged; verified message parity against CPython, including the PEP 562 hook paths.Results
synth/import_from_hot: 0.57s → 0.23s wall; vs pypy ~100x → 40.0x (dynasm) / 59.6x (cranelift); gate tightenedmax-pypy-ratio=764→180pyre/check.py: ALL PASSED — dynasm 371/371, cranelift 371/371🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
hasattrso missing attributes returnFalsewithout triggering unnecessary module diagnostics.getattrwith a default value while preserving normal error reporting when no default is provided.Chores