Skip to content

refactor(inference): add structural type mapping - #11004

Merged
ematipico merged 5 commits into
mainfrom
12-add-structural-type-mapping
Jul 22, 2026
Merged

refactor(inference): add structural type mapping#11004
ematipico merged 5 commits into
mainfrom
12-add-structural-type-mapping

Conversation

@ematipico

@ematipico ematipico commented Jul 20, 2026

Copy link
Copy Markdown
Member

Summary

This PR adds some plumbing to substitute generics inside a graph of types. Generics are called "slots".

There's also some plumbing for:

  • transformation
  • substitutions

Both work using a DFS iterator.

The new implementation:

  • Extracts immediate type slots with TypeDataSlots and rebuilds their original parent through TypeDataSlotRebuilder.
  • Uses TypeDataSlotReplacements to validate replacement counts and ensure every replacement is consumed.
  • Adds an iterative TypeDataTransformer with a shared step limit and protection against recursive types.
  • Adds TypeSubstitution, TypeTransformResult, and TypeTransformError.
  • Exposes semantic substitution through TypeData::substitute_type and TypeData::substitute_type_in_root_body.
  • Preserves generic binder boundaries and generic declaration identity during substitution.
  • Updates inference consumers to handle incomplete transformations conservatively.

The generic transformation machinery remains private; callers use the semantic substitution APIs.

Test Plan

Added structural mapping unit tests and passed type-info tests and all-target clippy.

Docs

N/A

This PR was created with AI assistance (OpenCode).

@changeset-bot

changeset-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 52605ce

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

Copy link
Copy Markdown
Contributor

✅ Organic activity

No automation signals detected in the analyzed events.

View full analysis →

This is an automated analysis by AgentScan

@ematipico
ematipico force-pushed the 12-add-structural-type-mapping branch from ab00d23 to b2ab727 Compare July 21, 2026 12:17
@ematipico
ematipico force-pushed the graphite-base/11004 branch from 0eed23e to de8c2af Compare July 21, 2026 12:17
@ematipico
ematipico changed the base branch from graphite-base/11004 to main July 21, 2026 12:17
@ematipico
ematipico marked this pull request as ready for review July 21, 2026 12:17
@ematipico ematipico closed this Jul 21, 2026
@ematipico ematipico reopened this Jul 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Mixed activity

Activity patterns show a mix of organic and automated signals.

View full analysis →

This is an automated analysis by AgentScan

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 53410220-f4bb-453f-bc5e-8a848228b5db

📥 Commits

Reviewing files that changed from the base of the PR and between 2370747 and 52605ce.

📒 Files selected for processing (2)
  • crates/biome_js_type_info/src/interned_types.rs
  • crates/biome_js_type_info/src/type_transform.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • crates/biome_js_type_info/src/type_transform.rs
  • crates/biome_js_type_info/src/interned_types.rs

Walkthrough

The PR adds bounded slot-based TypeData transformation and fallible generic substitution. Generic replacement collection now reports step-limit failures, while module-graph inference propagates failed transformations as Unknown. Tests cover traversal limits, result errors, slot replacement semantics, and reconstruction round trips.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and matches the main change: adding structural type mapping for inference.
Description check ✅ Passed The description clearly matches the implemented type-slot substitution and transformation changes.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 12-add-structural-type-mapping

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
crates/biome_js_type_info/src/interned_types.rs (1)

671-675: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Tidy up the duplicated region markers.

Lines 671–673 open and immediately close an empty // #region Structural construction, and line 675 opens a second region with the same label. Looks like a copy/paste leftover — dropping the empty block keeps the section headers meaningful.

🧹 Suggested tidy-up
-    // `#region` Structural construction
-
-    // `#endregion`
-
     // `#region` Structural construction

As per coding guidelines: "Write comments only when they convey information not recoverable from code".

🤖 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/biome_js_type_info/src/interned_types.rs` around lines 671 - 675,
Remove the empty duplicated `// `#region` Structural construction` block in
`interned_types.rs`, keeping only the subsequent meaningful region marker and
its contents.

Source: Coding guidelines

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

Nitpick comments:
In `@crates/biome_js_type_info/src/interned_types.rs`:
- Around line 671-675: Remove the empty duplicated `// `#region` Structural
construction` block in `interned_types.rs`, keeping only the subsequent
meaningful region marker and its contents.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1b124294-ee72-4f21-9c70-31e3e5a1e783

📥 Commits

Reviewing files that changed from the base of the PR and between de8c2af and b2ab727.

📒 Files selected for processing (7)
  • crates/biome_js_type_info/src/interned_types.rs
  • crates/biome_js_type_info/src/lib.rs
  • crates/biome_js_type_info/src/resolved.rs
  • crates/biome_js_type_info/src/type_transform.rs
  • crates/biome_module_graph/src/db/queries/type_inference.rs
  • crates/biome_module_graph/src/db/type_inference/expressions.rs
  • crates/biome_module_graph/src/db/type_inference/lookup.rs

@codspeed-hq

codspeed-hq Bot commented Jul 21, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 17.24%

❌ 2 (👁 2) regressed benchmarks
✅ 77 untouched benchmarks
⏩ 192 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
👁 bench_normalize_local_alias 33.1 µs 40.2 µs -17.62%
👁 bench_normalize_terminal_type 21.1 µs 25.4 µs -16.85%

Comparing 12-add-structural-type-mapping (52605ce) with main (de8c2af)

Open in CodSpeed

Footnotes

  1. 192 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@ematipico
ematipico merged commit 67fa4b7 into main Jul 22, 2026
30 checks passed
@ematipico
ematipico deleted the 12-add-structural-type-mapping branch July 22, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Project Area: project A-Type-Inference Area: type inference agentscan:mixed-signals L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant