Skip to content

fix(path): link regex runtime for matchesGlob dispatch - #6818

Merged
proggeramlug merged 1 commit into
PerryTS:mainfrom
proggeramlug:fix/6787-path-parity
Jul 24, 2026
Merged

fix(path): link regex runtime for matchesGlob dispatch#6818
proggeramlug merged 1 commit into
PerryTS:mainfrom
proggeramlug:fix/6787-path-parity

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • recognize static Win32 matchesGlob HIR when selecting the optional regex runtime
  • recognize dynamically dispatched path[k].matchesGlob(...) even when the method name is wrapped in the lowered HIR debug form
  • add detector coverage for both lowering shapes

Without the regex feature, the runtime fallback made every matchesGlob call return false in 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 crashes

Closes #6787

Summary by CodeRabbit

  • Bug Fixes
    • Fixed path.matchesGlob handling for Windows and dynamically dispatched calls.
    • Ensured the required pattern-matching support is correctly enabled in these scenarios.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The compiler’s regex usage detection is centralized in a helper that recognizes static and dynamic path.matchesGlob HIR representations. Unit tests cover both cases, and the changelog documents the regex-engine linkage fix.

Changes

Regex feature detection

Layer / File(s) Summary
MatchesGlob regex gate
crates/perry/src/commands/compile/collect_modules/feature_detect.rs, changelog.d/6787-path-matches-glob-feature.md
A shared helper detects regex-related HIR patterns, compilation uses it to enable the regex engine, tests cover static and dynamic matchesGlob dispatch, and the fix is documented.

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

Possibly related PRs

  • PerryTS/perry#6663: Updates Windows path and path.posix matchesGlob dispatch, whose HIR representations are handled by this change.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: linking the regex runtime for matchesGlob dispatch.
Description check ✅ Passed The description includes summary, validation, and the linked issue, so it is mostly complete despite missing some template sections.
Linked Issues check ✅ Passed The changes address both failing node:path cases by detecting static and dynamic matchesGlob forms and adding coverage.
Out of Scope Changes check ✅ Passed The only extra edit is a changelog entry, which is related to the fix and not unrelated scope creep.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 20f1975 and f4816c1.

📒 Files selected for processing (2)
  • changelog.d/6787-path-matches-glob-feature.md
  • crates/perry/src/commands/compile/collect_modules/feature_detect.rs

Comment on lines 143 to 145
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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

Suggested change
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.

@proggeramlug
proggeramlug merged commit 2a68962 into PerryTS:main Jul 24, 2026
30 checks passed
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.

[parity] node:path — 2 failing node-suite tests (2026-07-22 baseline)

1 participant