fix(path): link regex runtime for matchesGlob dispatch - #6818
Conversation
📝 WalkthroughWalkthroughThe compiler’s regex usage detection is centralized in a helper that recognizes static and dynamic ChangesRegex feature detection
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/collect_modules/feature_detect.rs`:
- Around line 143-145: Update the HIR serialization used by the regex detection
in the relevant feature-detection function to include hir_module.classes
alongside init and functions, so regex usage inside class or static-method HIR
sets ctx.uses_regex. Add a regression case covering class-contained matchesGlob
dispatch.
🪄 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: 421906bf-bf57-42be-9070-c33d10ab8a9e
📒 Files selected for processing (2)
changelog.d/6787-path-matches-glob-feature.mdcrates/perry/src/commands/compile/collect_modules/feature_detect.rs
| let hir_debug: String = format!("{:?}{:?}", &hir_module.init, &hir_module.functions); | ||
| if hir_debug.contains("RegExp") // RegExp / RegExpDynamic / RegExpTest / RegExpExec / RegExpEscape / RegExpReplaceFn / RegExpExec{Index,Groups} | ||
| || hir_debug.contains("StringMatch") // dedicated .match / .matchAll variants | ||
| || hir_debug.contains("PathMatchesGlob") | ||
| || hir_debug.contains("property: \"search\"") | ||
| || hir_debug.contains("property: \"match\"") | ||
| || hir_debug.contains("property: \"matchAll\"") | ||
| || hir_debug.contains("property: \"glob\"") | ||
| || hir_debug.contains("property: \"globSync\"") | ||
| { | ||
| if debug_hir_uses_regex(&hir_debug) { | ||
| ctx.uses_regex = true; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Include class HIR in regex detection.
The serialized input excludes hir_module.classes, so a matchesGlob call lowered inside a class or static method can leave ctx.uses_regex unset and omit perry-runtime/regex-engine. Include the classes in this format and add a regression case for class-contained dispatch.
Suggested fix
- let hir_debug: String = format!("{:?}{:?}", &hir_module.init, &hir_module.functions);
+ let hir_debug: String =
+ format!("{:?}{:?}{:?}", &hir_module.init, &hir_module.functions, &hir_module.classes);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| let hir_debug: String = format!("{:?}{:?}", &hir_module.init, &hir_module.functions); | |
| if hir_debug.contains("RegExp") // RegExp / RegExpDynamic / RegExpTest / RegExpExec / RegExpEscape / RegExpReplaceFn / RegExpExec{Index,Groups} | |
| || hir_debug.contains("StringMatch") // dedicated .match / .matchAll variants | |
| || hir_debug.contains("PathMatchesGlob") | |
| || hir_debug.contains("property: \"search\"") | |
| || hir_debug.contains("property: \"match\"") | |
| || hir_debug.contains("property: \"matchAll\"") | |
| || hir_debug.contains("property: \"glob\"") | |
| || hir_debug.contains("property: \"globSync\"") | |
| { | |
| if debug_hir_uses_regex(&hir_debug) { | |
| ctx.uses_regex = true; | |
| let hir_debug: String = | |
| format!("{:?}{:?}{:?}", &hir_module.init, &hir_module.functions, &hir_module.classes); | |
| if debug_hir_uses_regex(&hir_debug) { | |
| ctx.uses_regex = true; |
🤖 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/collect_modules/feature_detect.rs` around
lines 143 - 145, Update the HIR serialization used by the regex detection in the
relevant feature-detection function to include hir_module.classes alongside init
and functions, so regex usage inside class or static-method HIR sets
ctx.uses_regex. Add a regression case covering class-contained matchesGlob
dispatch.
Summary
matchesGlobHIR when selecting the optional regex runtimepath[k].matchesGlob(...)even when the method name is wrapped in the lowered HIR debug formWithout the regex feature, the runtime fallback made every
matchesGlobcall returnfalsein size-optimized binaries.Validation
cargo build --release -p perry./run_parity_tests.sh --suite node-suite --module path --filter method-dispatch— 1/1./run_parity_tests.sh --suite node-suite --module path --filter win32-separators— 1/1./run_parity_tests.sh --suite node-suite --module path— 92/92, zero failures or crashesCloses #6787
Summary by CodeRabbit
path.matchesGlobhandling for Windows and dynamically dispatched calls.