Refactor imported class construction#6265
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe compiler centralizes ChangesImported class metadata
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/perry/src/commands/compile/run_pipeline.rs`:
- Line 2496: Preserve the namespace-visible alias when importing re-exported
classes. In both class-import branches around imported_class_from_hir, resolve
the class using the visible re-export key (such as PublicChild) and pass
Some(export_name.clone()) when it differs from class.name, otherwise None, so
generated metadata uses the exported alias.
- Line 3639: The transitive closure worklist currently uses a non-canonical
module prefix when importing parent classes, causing re-exported classes to
reference barrel modules. In the closure branch around imported_classes.push and
imported_class_from_hir, replace compute_module_prefix(&src_path) with
canonical_class_source_prefix(...) using the resolved class/source context,
matching the direct import paths.
In `@crates/perry/tests/functional_batch2_regressions.rs`:
- Around line 217-242: The regression test does not access the computed static
field declared on Child. In the main.ts test source, alongside the existing
LocalChild.plain assertion, add an assertion reading
LocalChild["not-a-static-global"] and verify it produces "computed".
- Around line 234-242: Update the regression fixture around the namespace import
test so it does not first import `PublicChild` as `LocalChild`; add a separate
namespace-only entry point or fixture that imports `* as barrel` and performs
the `barrel.PublicChild` construction/`instanceof` assertion independently. Keep
the existing named-import coverage separate, ensuring namespace metadata
registration is validated without prior registration by `LocalChild`.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 2f42b10d-40b3-47a6-bd36-8252e0803136
📒 Files selected for processing (2)
crates/perry/src/commands/compile/run_pipeline.rscrates/perry/tests/functional_batch2_regressions.rs
| .collect(), | ||
| source_class_id: Some(class.id), | ||
| }); | ||
| imported_classes.push(imported_class_from_hir(class, class_prefix, alias)); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate relevant symbols and surrounding context
rg -n "exported_classes|canonical_class_source_prefix|compute_module_prefix|imported_class_from_hir|closure import|imported_classes.push" crates/perry/src/commands/compile/run_pipeline.rs
# Show a focused slice around the reported line
sed -n '3560,3665p' crates/perry/src/commands/compile/run_pipeline.rs
# Find definitions/usages in the repo
rg -n "fn canonical_class_source_prefix|canonical_class_source_prefix\(|fn compute_module_prefix|compute_module_prefix\(|fn imported_class_from_hir|imported_class_from_hir\(" crates/perry/srcRepository: PerryTS/perry
Length of output: 12800
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Read the helper and nearby tests for canonical prefix selection
sed -n '90,150p' crates/perry/src/commands/compile/helpers.rs
sed -n '230,340p' crates/perry/src/commands/compile/helpers.rs
# Read the surrounding import-creation helpers in run_pipeline
sed -n '1,80p' crates/perry/src/commands/compile/run_pipeline.rs
sed -n '2470,2965p' crates/perry/src/commands/compile/run_pipeline.rs
sed -n '3048,3505p' crates/perry/src/commands/compile/run_pipeline.rsRepository: PerryTS/perry
Length of output: 50369
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Find where ImportedClass.source_prefix is consumed in codegen
rg -n "source_prefix" crates/perry/src crates/perry_codegen/src
# Read the relevant ImportedClass definition and its consumers
sed -n '1,220p' crates/perry_codegen/src/lib.rs
sed -n '1,260p' crates/perry_codegen/src/imported_class.rs 2>/dev/null || true
sed -n '1,260p' crates/perry_codegen/src/*.rs 2>/dev/null | sed -n '1,260p'Repository: PerryTS/perry
Length of output: 4342
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate every use of ImportedClass.source_prefix
rg -n "source_prefix" crates/perry/src crates/perry_codegen/src
# Show the ImportedClass definition if present
rg -n "struct ImportedClass|pub struct ImportedClass" crates/perry_codegen/src crates/perry/src
# Read the files that consume imported classes in codegen (narrowed by search hits)
rg -n "ImportedClass|imported_class_names|class_prefix|source_prefix" crates/perry_codegen/src crates/perry/src/commands/compile -g '*.rs'Repository: PerryTS/perry
Length of output: 4342
🏁 Script executed:
#!/bin/bash
set -euo pipefail
sed -n '600,625p' crates/perry/src/commands/compile/run_pipeline.rs
sed -n '3608,3650p' crates/perry/src/commands/compile/run_pipeline.rs
sed -n '2482,2502p' crates/perry/src/commands/compile/run_pipeline.rs
sed -n '2726,2746p' crates/perry/src/commands/compile/run_pipeline.rs
sed -n '2912,2958p' crates/perry/src/commands/compile/run_pipeline.rsRepository: PerryTS/perry
Length of output: 9583
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the surrounding comment and the exact closure-import block
sed -n '3520,3650p' crates/perry/src/commands/compile/run_pipeline.rs
# Find any helper or comment that explicitly says closure imports should canonicalize
rg -n "closure|canonical_class_source_prefix|barrel|re-export" crates/perry/src/commands/compile/run_pipeline.rs crates/perry/src/commands/compile/helpers.rs
# Find all places where imported_class_from_hir is called with compute_module_prefix vs canonical_class_source_prefix
rg -n "imported_class_from_hir\(class, (compute_module_prefix|canonical_class_source_prefix)" crates/perry/src/commands/compile/run_pipeline.rsRepository: PerryTS/perry
Length of output: 18160
Use the canonical class prefix in the transitive closure path. The closure-worklist branch still stamps imported parents with compute_module_prefix(&src_path). If the lookup lands on a re-export/barrel entry, the emitted method/static symbols point at the barrel module instead of the defining module and can fail at link time. Use canonical_class_source_prefix(...) here, as in the direct import paths.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@crates/perry/src/commands/compile/run_pipeline.rs` at line 3639, The
transitive closure worklist currently uses a non-canonical module prefix when
importing parent classes, causing re-exported classes to reference barrel
modules. In the closure branch around imported_classes.push and
imported_class_from_hir, replace compute_module_prefix(&src_path) with
canonical_class_source_prefix(...) using the resolved class/source context,
matching the direct import paths.
Summary
ImportedClassconstruction behind one helperValidation
cargo fmt --allCARGO_INCREMENTAL=0 cargo check -p perry-codegenCARGO_INCREMENTAL=0 cargo check -p perry --no-default-features --features compile-cliCARGO_INCREMENTAL=0 cargo test -p perry-codegen --lib(156 passed)The new Perry integration test could not be linked locally because the workspace volume ran out of disk space.
Summary by CodeRabbit
Bug Fixes
import * as ...) imports.instanceofacross module boundaries.Tests