Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@tidefield
Copy link
Contributor

@tidefield tidefield commented Nov 25, 2025

Biome's handling for global types has a limitation that makes it very hard to do #5977, write codegen from .d.ts to Rust, and manually add new global types.

The types (which becomes the backbone data structure for the type store) is

let types = vec![
TypeData::Unknown,
TypeData::Undefined,
TypeData::VoidKeyword,
TypeData::Conditional,
TypeData::Number,

Here, the vec indices need to match with type IDs defined in

pub const UNKNOWN_ID: TypeId = TypeId::new(0);
pub const UNDEFINED_ID: TypeId = TypeId::new(1);
pub const VOID_ID: TypeId = TypeId::new(2);
pub const CONDITIONAL_ID: TypeId = TypeId::new(3);
pub const NUMBER_ID: TypeId = TypeId::new(4);

Also, we have to deal with this function where the indices need to match up too.

pub fn global_type_name(id: TypeId) -> &'static str {
match id.index() {
0 => "unknown",
1 => "undefined",
2 => "void",
3 => "conditional",
4 => "number",

From a manual perspective (where we are now), every index, ID, and name strings are manually tracked. It could be error-prone and likely becomes source of breaking changes and merge conflicts. #8166 is how much code needed for RegExp globals.

From a codegen perspective (what we're aiming for), the codegen needs two-pass: one for storing all IDs in memory, and another for unpacking those IDs to generate the types vec.

This PR refactors the unnecessary thinkings (specific ID integers, indices, names, etc) out of globals.rs.

My follow-up PR will implement a codegen to

  1. Get more TypeId coverage for missing global types
  2. Use biome parser's output to generate names and TypeData for global types
  3. Address all the FIXME and TODO comments

Even without the follow-up PR, this PR is meant to leave the codebase in a better place for further manual extensions.

@arendjr I intentionally removed and added back the RegExp globals in d417edd in a separate commit to compare with #8166 that basically does the same thing. That is the recap of what I want to do in this PR.

Related: #5977

@changeset-bot
Copy link

changeset-bot bot commented Nov 25, 2025

⚠️ No Changeset found

Latest commit: 310ff44

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 github-actions bot added L-JavaScript Language: JavaScript and super languages A-Type-Inference Area: type inference labels Nov 25, 2025
@tidefield tidefield force-pushed the feat/global-resolver-builder branch 4 times, most recently from 232b09d to 79f772d Compare November 25, 2025 12:35
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 25, 2025

CodSpeed Performance Report

Merging #8253 will not alter performance

Comparing tidefield:feat/global-resolver-builder (310ff44) with main (59fa146)

Summary

✅ 58 untouched
⏩ 95 skipped1

Footnotes

  1. 95 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.

@tidefield tidefield force-pushed the feat/global-resolver-builder branch from 3ac9cd7 to 638c3b8 Compare November 25, 2025 13:16
@tidefield tidefield changed the title [DRAFT] feat: implement GlobalsResolverBuilder for type system refactoring [DRAFT] chore: implement GlobalsResolverBuilder to refactor global type system Nov 25, 2025
@tidefield tidefield changed the title [DRAFT] chore: implement GlobalsResolverBuilder to refactor global type system chore: implement GlobalsResolverBuilder to refactor global type system Nov 25, 2025
@tidefield tidefield changed the title chore: implement GlobalsResolverBuilder to refactor global type system chore: refactor global type system to accommodate further extensions Nov 25, 2025
@tidefield tidefield marked this pull request as ready for review November 25, 2025 14:12
Copy link
Contributor

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

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

Looks reasonable, at a glance

.collect()
});

pub const UNKNOWN_ID: TypeId = TypeId::new(0);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The IDs and type name strings are moved to global_ids.rs.

TypeData::Conditional,
TypeData::Number,
TypeData::String,
let mut builder = GlobalsResolverBuilder::with_capacity(NUM_PREDEFINED_TYPES);
Copy link
Contributor Author

@tidefield tidefield Nov 25, 2025

Choose a reason for hiding this comment

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

This is the main part of my PR. Basically, instead of initializing the vec with all the TypeData upfront, we just prefill it with None, and then fill it later with set_type_data. That way, we don't care about the order.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 25, 2025

Walkthrough

This PR refactors predefined global-type initialization by adding a new GlobalsResolverBuilder and a new globals_ids module that declares 44 predefined TypeId constants plus ResolvedTypeId wrappers. global_type_name now returns Option<&'static str> and call sites (format_type_info.rs, resolver.rs) use deterministic fallbacks when a name is missing. GlobalsResolver field visibility is widened to pub(crate). The builder API (with_capacity, set_type_data, build, Default) supports forward-referenced reserved slots. Exports are split between globals and globals_ids. Cargo.toml adds paste = "1.0".

Possibly related PRs

  • chore: add regex globals #8166: Modifies the same global-type infrastructure (predefined TypeId constants, NUM_PREDEFINED_TYPES, and global_type_name usages); strong code-level overlap.

Suggested labels

A-Project

Suggested reviewers

  • arendjr
  • Netail
  • ematipico

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main refactoring work: restructuring the global type system to support future extensions and simplify manual additions and code generation.
Description check ✅ Passed The description comprehensively explains the motivation, current limitations, specific changes made, and future plans, clearly relating to the changeset across all modified files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ab2cde2 and 310ff44.

📒 Files selected for processing (1)
  • crates/biome_js_type_info/src/globals_builder.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/biome_js_type_info/src/globals_builder.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (23)
  • GitHub Check: End-to-end tests
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Documentation
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Check Dependencies
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Test Node.js API
  • GitHub Check: Bench (biome_css_parser)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: Bench (biome_graphql_parser)
  • GitHub Check: Bench (biome_graphql_formatter)
  • GitHub Check: Bench (biome_tailwind_parser)
  • GitHub Check: Bench (biome_json_parser)
  • GitHub Check: Bench (biome_module_graph)
  • GitHub Check: Bench (biome_json_formatter)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_json_analyze)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_package)
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Bench (biome_js_formatter)

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/biome_js_type_info/src/globals.rs (1)

336-383: Fix MAP_CALLBACK_ID to match its declared generic signature

The declaration in globals_ids.rs:67 states <U>(item: T) => U, but the implementation at globals.rs:348–361 currently omits the U type parameter and uses GLOBAL_U_ID for the parameter type instead of GLOBAL_T_ID.

Update lines 349–361 to:

TypeData::from(Function {
    is_async: false,
    type_parameters: [GLOBAL_U_ID.into()].into(),
    name: Some(Text::new_static(MAP_CALLBACK_ID_NAME)),
    parameters: [FunctionParameter::Pattern(PatternFunctionParameter {
        ty: GLOBAL_T_ID.into(),
        bindings: Default::default(),
        is_optional: false,
        is_rest: false,
    })]
    .into(),
    return_type: ReturnType::Type(GLOBAL_U_ID.into()),
}),

This aligns the implementation with the declared signature and ensures correct type inference for Array<T>.map<U>(callback: (item: T) => U).

🧹 Nitpick comments (2)
.changeset/giant-shoes-hear.md (1)

1-5: Polish the changeset wording and spelling

To match the changeset guidelines, this should be past tense and fix the typo:

-chore: Refactor global type system to accomodate further extensions
+chore: Refactored global type system to accommodate further extensions

If you want to be extra nice to users, you could also mention that “Biome now makes it easier to extend global types (see #5977)”.

crates/biome_js_type_info/Cargo.toml (1)

25-25: Align paste dependency with workspace conventions

If paste is already declared in the workspace root, it’s better to wire this crate to the shared version:

-paste                     = "1.0"
+paste                     = { workspace = true }

This keeps versions in lockstep across crates.

Please double‑check the root Cargo.toml and adjust to workspace = true if paste is indeed managed there.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 98ca2ae and 4fb63b4.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock and included by **
📒 Files selected for processing (8)
  • .changeset/giant-shoes-hear.md (1 hunks)
  • crates/biome_js_type_info/Cargo.toml (1 hunks)
  • crates/biome_js_type_info/src/format_type_info.rs (1 hunks)
  • crates/biome_js_type_info/src/globals.rs (10 hunks)
  • crates/biome_js_type_info/src/globals_builder.rs (1 hunks)
  • crates/biome_js_type_info/src/globals_ids.rs (1 hunks)
  • crates/biome_js_type_info/src/lib.rs (2 hunks)
  • crates/biome_js_type_info/src/resolver.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/Cargo.toml

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Use workspace dependencies defined in the root Cargo.toml for internal crates, specifying workspace = true in each crate's Cargo.toml. Use path dependencies for dev-dependencies to avoid requiring published versions.

Files:

  • crates/biome_js_type_info/Cargo.toml
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.rs: Use the Rust dbg!() macro for debugging output during test execution, and pass the --show-output flag to cargo test to display debug output.
Use snapshot testing with the insta crate for testing in Rust projects. Accept or reject snapshots using cargo insta accept, cargo insta reject, or cargo insta review.
Write doc comments as doc tests in Rust using code blocks with assertions that will be executed during the testing phase.
Use rustdoc inline documentation for rules, assists, and their options. Create corresponding documentation PRs for other documentation updates against the next branch of the website repository.
Set the version metadata field in linter rule implementations to 'next' for newly created rules. Update this field to the new version number when releasing a minor or major version.

Files:

  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/resolver.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/lib.rs
  • crates/biome_js_type_info/src/globals_ids.rs
  • crates/biome_js_type_info/src/globals.rs
crates/biome_js_type_info/**/*.rs

📄 CodeRabbit inference engine (crates/biome_js_type_info/CONTRIBUTING.md)

crates/biome_js_type_info/**/*.rs: No module may copy or clone data from another module in the module graph, not even behind an Arc
Use TypeReference instead of Arc for types that reference other types to avoid stale cache issues when modules are replaced
Store type data in linear vectors instead of using recursive data structures with Arc for improved data locality and performance
Use TypeReference variants (Qualifier, Resolved, Import, Unknown) to represent different phases of type resolution
Use TypeData::Unknown to indicate when type inference falls short or is not implemented
Distinguish between TypeData::Unknown and TypeData::UnknownKeyword to measure inference effectiveness versus explicit user-provided unknown types
When using ResolvedTypeData, track the ResolverId to ensure subsequent resolver calls use the correct context
Always apply the correct ResolverId when retrieving raw type data from ResolvedTypeData.as_raw_data() to prevent panics during subsequent resolution calls

Files:

  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/resolver.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/lib.rs
  • crates/biome_js_type_info/src/globals_ids.rs
  • crates/biome_js_type_info/src/globals.rs
**/.changeset/*.md

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Changeset descriptions should be user-facing, use past tense for actions taken (e.g., 'Added new feature'), and present tense for Biome behavior (e.g., 'Biome now supports...'). Include issue links, rule links, and code examples where applicable.

Files:

  • .changeset/giant-shoes-hear.md
🧠 Learnings (23)
📓 Common learnings
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Always apply the correct `ResolverId` when retrieving raw type data from `ResolvedTypeData.as_raw_data()` to prevent panics during subsequent resolution calls
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : When using `ResolvedTypeData`, track the `ResolverId` to ensure subsequent resolver calls use the correct context
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:03:52.014Z
Learning: For bugfix/feature PRs visible to Biome toolchain users or affecting published crates, create a changeset using the `just new-changeset` command with appropriate package selection, change type (major/minor/patch), and description.
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.337Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` instead of `Arc` for types that reference other types to avoid stale cache issues when modules are replaced
📚 Learning: 2025-11-24T18:05:20.343Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:20.343Z
Learning: Applies to crates/biome_formatter/**/biome_*_formatter/Cargo.toml : Include development dependencies in `Cargo.toml` for formatter tests: `biome_formatter_test`, `biome_<language>_factory`, `biome_<language>_parser`, `biome_parser`, `biome_service`, `countme`, `iai`, `quickcheck`, `quickcheck_macros`, and `tests_macros`

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
📚 Learning: 2025-11-24T18:05:42.337Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.337Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` instead of `Arc` for types that reference other types to avoid stale cache issues when modules are replaced

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/resolver.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/lib.rs
  • crates/biome_js_type_info/src/globals_ids.rs
  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:03:52.014Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:03:52.014Z
Learning: For bugfix/feature PRs visible to Biome toolchain users or affecting published crates, create a changeset using the `just new-changeset` command with appropriate package selection, change type (major/minor/patch), and description.

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
  • .changeset/giant-shoes-hear.md
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Store type data in linear vectors instead of using recursive data structures with `Arc` for improved data locality and performance

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/lib.rs
  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:03:52.013Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:03:52.013Z
Learning: Applies to **/Cargo.toml : Use workspace dependencies defined in the root `Cargo.toml` for internal crates, specifying `workspace = true` in each crate's Cargo.toml. Use path dependencies for dev-dependencies to avoid requiring published versions.

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Distinguish between `TypeData::Unknown` and `TypeData::UnknownKeyword` to measure inference effectiveness versus explicit user-provided unknown types

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/resolver.rs
  • crates/biome_js_type_info/src/lib.rs
  • crates/biome_js_type_info/src/globals_ids.rs
  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:06:03.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.536Z
Learning: Applies to crates/biome_parser/**/language_kind.rs : Add a new language prefix to the `LANGUAGE_PREFIXES` constant in `language_kind.rs` file

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
📚 Learning: 2025-11-24T18:06:03.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.536Z
Learning: Create two new crates `biome_{language}_syntax` and `biome_{language}_factory` using `cargo new --lib` for new language parsers

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeData::Unknown` to indicate when type inference falls short or is not implemented

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/resolver.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/lib.rs
  • crates/biome_js_type_info/src/globals_ids.rs
  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.337Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.337Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : No module may copy or clone data from another module in the module graph, not even behind an `Arc`

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
📚 Learning: 2025-11-24T18:06:12.017Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_service/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:12.017Z
Learning: Applies to crates/biome_service/src/workspace*.rs : Implement the Workspace trait in the Biome Service to manage internal state of projects, including open documents, project layout instances, and module graph instances

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` variants (`Qualifier`, `Resolved`, `Import`, `Unknown`) to represent different phases of type resolution

Applied to files:

  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/resolver.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/lib.rs
  • crates/biome_js_type_info/src/globals_ids.rs
  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-08-20T16:24:59.781Z
Learnt from: arendjr
Repo: biomejs/biome PR: 7266
File: crates/biome_js_type_info/src/type.rs:94-102
Timestamp: 2025-08-20T16:24:59.781Z
Learning: In crates/biome_js_type_info/src/type.rs, the flattened_union_variants() method returns TypeReference instances that already have the correct module IDs applied to them. These references should be used directly with resolver.resolve_reference() without applying additional module ID transformations, as variant references may originate from nested unions in different modules.

Applied to files:

  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/resolver.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/lib.rs
  • crates/biome_js_type_info/src/globals_ids.rs
  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/scoped_resolver.rs : Implement full inference to resolve `TypeReference::Import` variants across the entire module graph

Applied to files:

  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/resolver.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/lib.rs
  • crates/biome_js_type_info/src/globals_ids.rs
  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Always apply the correct `ResolverId` when retrieving raw type data from `ResolvedTypeData.as_raw_data()` to prevent panics during subsequent resolution calls

Applied to files:

  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/resolver.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/lib.rs
  • crates/biome_js_type_info/src/globals_ids.rs
  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : When using `ResolvedTypeData`, track the `ResolverId` to ensure subsequent resolver calls use the correct context

Applied to files:

  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/resolver.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/lib.rs
  • crates/biome_js_type_info/src/globals_ids.rs
  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/js_module_info/collector.rs : Implement module-level (thin) inference to resolve `TypeReference::Qualifier` variants by looking up declarations in module scopes and handling import statements

Applied to files:

  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/lib.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/flattening.rs : Implement type flattening to simplify `TypeofExpression` variants once all component types are resolved

Applied to files:

  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/resolver.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/lib.rs
  • crates/biome_js_type_info/src/globals_ids.rs
  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:04:57.290Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_diagnostics/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:04:57.290Z
Learning: Applies to crates/biome_diagnostics/**/*.rs : Ensure the type implementing Diagnostic derives Debug

Applied to files:

  • crates/biome_js_type_info/src/resolver.rs
📚 Learning: 2025-11-24T18:04:42.146Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:04:42.146Z
Learning: Applies to crates/biome_analyze/**/biome_*_analyze/lib/src/**/!(mod).rs : Rules that ban functions or variables should use the semantic model to check if the variable is global before reporting, to avoid false positives on locally redeclared variables

Applied to files:

  • crates/biome_js_type_info/src/lib.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/local_inference.rs : Implement local inference in dedicated modules to derive type definitions from expressions without context of surrounding scopes

Applied to files:

  • crates/biome_js_type_info/src/lib.rs
📚 Learning: 2025-09-09T18:10:05.095Z
Learnt from: arendjr
Repo: biomejs/biome PR: 6710
File: crates/biome_js_type_info/src/helpers.rs:102-124
Timestamp: 2025-09-09T18:10:05.095Z
Learning: Global constants like GLOBAL_ARRAY_ID are stored by the global resolver and should never have module IDs applied to them. Module IDs only apply to module resolvers, not global resolvers. When working with global type constants, use them directly without module ID transformations.

Applied to files:

  • crates/biome_js_type_info/src/lib.rs
  • crates/biome_js_type_info/src/globals_ids.rs
  • crates/biome_js_type_info/src/globals.rs
🧬 Code graph analysis (4)
crates/biome_js_type_info/src/format_type_info.rs (4)
crates/biome_js_type_info/src/resolver.rs (7)
  • name (502-504)
  • id (71-73)
  • resolved (742-742)
  • resolved (749-795)
  • resolved (803-817)
  • new (54-56)
  • new (293-298)
crates/biome_js_type_info/src/type_data.rs (5)
  • name (951-953)
  • name (999-1005)
  • new (39-43)
  • new (1436-1440)
  • new (1471-1481)
crates/biome_js_type_info/src/globals.rs (1)
  • global_type_name (47-96)
crates/biome_js_type_info/src/type.rs (1)
  • id (74-76)
crates/biome_js_type_info/src/resolver.rs (1)
crates/biome_js_type_info/src/globals.rs (1)
  • global_type_name (47-96)
crates/biome_js_type_info/src/globals_ids.rs (1)
crates/biome_js_type_info/src/resolver.rs (2)
  • new (54-56)
  • new (293-298)
crates/biome_js_type_info/src/globals.rs (1)
crates/biome_js_type_info/src/globals_builder.rs (2)
  • default (58-60)
  • with_capacity (16-20)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (16)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Check Dependencies
  • GitHub Check: Test Node.js API
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_graphql_formatter)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: autofix
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_css_parser)
  • GitHub Check: Bench (biome_json_formatter)
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Bench (biome_json_parser)
  • GitHub Check: Bench (biome_json_analyze)
🔇 Additional comments (5)
crates/biome_js_type_info/src/globals_ids.rs (1)

1-116: Global ID indices and NUM_PREDEFINED_TYPES look consistent

The define_global_type! usage, ID values (0–43), and NUM_PREDEFINED_TYPES: usize = 44 line up correctly, and the GLOBAL_* aliases wrap them with GLOBAL_LEVEL as expected. This should make further additions much less brittle.

crates/biome_js_type_info/src/resolver.rs (1)

34-45: Debug formatting for global ResolvedTypeId looks good

Using global_type_name when available and then falling back to a stable Global TypeId(...) scheme for predefined vs later globals is a nice improvement for debuggability without changing semantics.

crates/biome_js_type_info/src/lib.rs (1)

7-20: Module split between globals and globals_ids looks sensible

Making globals_ids pub(crate) and re‑exporting only GLOBAL_RESOLVER/GlobalsResolver plus the minimal GLOBAL_UNKNOWN_ID/NUM_PREDEFINED_TYPES pair keeps the external surface compact while giving the crate enough internal access to the new ID machinery.

crates/biome_js_type_info/src/globals_builder.rs (1)

1-61: Builder invariants for globals are well enforced

The one-shot set_type_data contract (bounds + “only set once” asserts) and the panic on unfilled slots in build give nice protection against future refactors quietly forgetting to populate a predefined ID. Defaulting to NUM_PREDEFINED_TYPES keeps it tied to the ID table.

crates/biome_js_type_info/src/globals.rs (1)

20-43: Global members and global_type_name wiring look coherent

GLOBAL_TYPE_MEMBERS iterating from 0..NUM_PREDEFINED_TYPES and using global_type_name(id).unwrap_or("unknown") means every predefined ID has a deterministic, human‑readable member, and the match in global_type_name lines up with the IDs from globals_ids. This should make snapshot output and future codegen much easier to reason about.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
crates/biome_js_type_info/src/format_type_info.rs (1)

591-607: Potential underflow if global_type_name doesn't cover all predefined IDs

The else branch at line 598 computes id.index() - NUM_PREDEFINED_TYPES, assuming global_type_name(id) returning None implies id.index() >= NUM_PREDEFINED_TYPES. If any predefined type ID is missing from the match arms in global_type_name, this will underflow.

The previous review suggested using the raw index for predefined types. Consider adding a guard or using the approach from the Debug impl in resolver.rs.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4fb63b4 and ac770b6.

📒 Files selected for processing (2)
  • crates/biome_js_type_info/src/format_type_info.rs (1 hunks)
  • crates/biome_js_type_info/src/globals.rs (9 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.rs: Use the Rust dbg!() macro for debugging output during test execution, and pass the --show-output flag to cargo test to display debug output.
Use snapshot testing with the insta crate for testing in Rust projects. Accept or reject snapshots using cargo insta accept, cargo insta reject, or cargo insta review.
Write doc comments as doc tests in Rust using code blocks with assertions that will be executed during the testing phase.
Use rustdoc inline documentation for rules, assists, and their options. Create corresponding documentation PRs for other documentation updates against the next branch of the website repository.
Set the version metadata field in linter rule implementations to 'next' for newly created rules. Update this field to the new version number when releasing a minor or major version.

Files:

  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals.rs
crates/biome_js_type_info/**/*.rs

📄 CodeRabbit inference engine (crates/biome_js_type_info/CONTRIBUTING.md)

crates/biome_js_type_info/**/*.rs: No module may copy or clone data from another module in the module graph, not even behind an Arc
Use TypeReference instead of Arc for types that reference other types to avoid stale cache issues when modules are replaced
Store type data in linear vectors instead of using recursive data structures with Arc for improved data locality and performance
Use TypeReference variants (Qualifier, Resolved, Import, Unknown) to represent different phases of type resolution
Use TypeData::Unknown to indicate when type inference falls short or is not implemented
Distinguish between TypeData::Unknown and TypeData::UnknownKeyword to measure inference effectiveness versus explicit user-provided unknown types
When using ResolvedTypeData, track the ResolverId to ensure subsequent resolver calls use the correct context
Always apply the correct ResolverId when retrieving raw type data from ResolvedTypeData.as_raw_data() to prevent panics during subsequent resolution calls

Files:

  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals.rs
🧠 Learnings (13)
📓 Common learnings
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Always apply the correct `ResolverId` when retrieving raw type data from `ResolvedTypeData.as_raw_data()` to prevent panics during subsequent resolution calls
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : When using `ResolvedTypeData`, track the `ResolverId` to ensure subsequent resolver calls use the correct context
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:03:52.014Z
Learning: For bugfix/feature PRs visible to Biome toolchain users or affecting published crates, create a changeset using the `just new-changeset` command with appropriate package selection, change type (major/minor/patch), and description.
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.337Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` instead of `Arc` for types that reference other types to avoid stale cache issues when modules are replaced
Learnt from: arendjr
Repo: biomejs/biome PR: 7266
File: crates/biome_js_type_info/src/type.rs:94-102
Timestamp: 2025-08-20T16:24:59.781Z
Learning: In crates/biome_js_type_info/src/type.rs, the flattened_union_variants() method returns TypeReference instances that already have the correct module IDs applied to them. These references should be used directly with resolver.resolve_reference() without applying additional module ID transformations, as variant references may originate from nested unions in different modules.
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` variants (`Qualifier`, `Resolved`, `Import`, `Unknown`) to represent different phases of type resolution
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/scoped_resolver.rs : Implement full inference to resolve `TypeReference::Import` variants across the entire module graph
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/flattening.rs : Implement type flattening to simplify `TypeofExpression` variants once all component types are resolved
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` variants (`Qualifier`, `Resolved`, `Import`, `Unknown`) to represent different phases of type resolution

Applied to files:

  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-08-20T16:24:59.781Z
Learnt from: arendjr
Repo: biomejs/biome PR: 7266
File: crates/biome_js_type_info/src/type.rs:94-102
Timestamp: 2025-08-20T16:24:59.781Z
Learning: In crates/biome_js_type_info/src/type.rs, the flattened_union_variants() method returns TypeReference instances that already have the correct module IDs applied to them. These references should be used directly with resolver.resolve_reference() without applying additional module ID transformations, as variant references may originate from nested unions in different modules.

Applied to files:

  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.337Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.337Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` instead of `Arc` for types that reference other types to avoid stale cache issues when modules are replaced

Applied to files:

  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/scoped_resolver.rs : Implement full inference to resolve `TypeReference::Import` variants across the entire module graph

Applied to files:

  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : When using `ResolvedTypeData`, track the `ResolverId` to ensure subsequent resolver calls use the correct context

Applied to files:

  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Always apply the correct `ResolverId` when retrieving raw type data from `ResolvedTypeData.as_raw_data()` to prevent panics during subsequent resolution calls

Applied to files:

  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Distinguish between `TypeData::Unknown` and `TypeData::UnknownKeyword` to measure inference effectiveness versus explicit user-provided unknown types

Applied to files:

  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/js_module_info/collector.rs : Implement module-level (thin) inference to resolve `TypeReference::Qualifier` variants by looking up declarations in module scopes and handling import statements

Applied to files:

  • crates/biome_js_type_info/src/format_type_info.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/flattening.rs : Implement type flattening to simplify `TypeofExpression` variants once all component types are resolved

Applied to files:

  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeData::Unknown` to indicate when type inference falls short or is not implemented

Applied to files:

  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Store type data in linear vectors instead of using recursive data structures with `Arc` for improved data locality and performance

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-09-09T18:10:05.095Z
Learnt from: arendjr
Repo: biomejs/biome PR: 6710
File: crates/biome_js_type_info/src/helpers.rs:102-124
Timestamp: 2025-09-09T18:10:05.095Z
Learning: Global constants like GLOBAL_ARRAY_ID are stored by the global resolver and should never have module IDs applied to them. Module IDs only apply to module resolvers, not global resolvers. When working with global type constants, use them directly without module ID transformations.

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (24)
  • GitHub Check: Documentation
  • GitHub Check: Check Dependencies
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: End-to-end tests
  • GitHub Check: Test Node.js API
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_package)
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Bench (biome_json_parser)
  • GitHub Check: Bench (biome_module_graph)
  • GitHub Check: Bench (biome_json_analyze)
  • GitHub Check: Bench (biome_json_formatter)
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: Bench (biome_graphql_parser)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Bench (biome_css_parser)
  • GitHub Check: Bench (biome_graphql_formatter)
  • GitHub Check: autofix
  • GitHub Check: Bench (biome_tailwind_parser)
🔇 Additional comments (2)
crates/biome_js_type_info/src/globals.rs (2)

155-409: Builder pattern nicely decouples type registration from index ordering

The refactor to GlobalsResolverBuilder with explicit set_type_data(ID, TypeData) calls eliminates the fragile coupling between vector indices and type ID integers. This makes future additions (manual or generated) considerably less error-prone.


45-96: Name mapping looks complete for current predefined types

The match arms cover all the predefined ID constants used in the builder below. The TODO for codegen is sensible—once implemented, this will stay in sync automatically.

Comment on lines +398 to +407
builder.set_type_data(
REGEXP_EXEC_ID,
TypeData::from(Function {
is_async: false,
type_parameters: Default::default(),
name: Some(Text::new_static(REGEXP_EXEC_ID_NAME)),
parameters: Default::default(),
return_type: ReturnType::Type(GLOBAL_INSTANCEOF_REGEXP_ID.into()),
}),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

RegExp.exec return type appears incorrect

RegExp.prototype.exec() returns RegExpExecArray | null, not a RegExp instance. Line 405 sets the return type to GLOBAL_INSTANCEOF_REGEXP_ID, which would indicate it returns a RegExp.

This is likely a copy-paste artefact. Consider introducing a proper return type (e.g., a union of a match array and null, or Unknown as a placeholder until codegen handles it).

         builder.set_type_data(
             REGEXP_EXEC_ID,
             TypeData::from(Function {
                 is_async: false,
                 type_parameters: Default::default(),
                 name: Some(Text::new_static(REGEXP_EXEC_ID_NAME)),
                 parameters: Default::default(),
-                return_type: ReturnType::Type(GLOBAL_INSTANCEOF_REGEXP_ID.into()),
+                // TODO: Should return RegExpExecArray | null
+                return_type: ReturnType::Type(TypeReference::unknown()),
             }),
         );
📝 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
builder.set_type_data(
REGEXP_EXEC_ID,
TypeData::from(Function {
is_async: false,
type_parameters: Default::default(),
name: Some(Text::new_static(REGEXP_EXEC_ID_NAME)),
parameters: Default::default(),
return_type: ReturnType::Type(GLOBAL_INSTANCEOF_REGEXP_ID.into()),
}),
);
builder.set_type_data(
REGEXP_EXEC_ID,
TypeData::from(Function {
is_async: false,
type_parameters: Default::default(),
name: Some(Text::new_static(REGEXP_EXEC_ID_NAME)),
parameters: Default::default(),
// TODO: Should return RegExpExecArray | null
return_type: ReturnType::Type(TypeReference::unknown()),
}),
);
🤖 Prompt for AI Agents
In crates/biome_js_type_info/src/globals.rs around lines 398 to 407, the builder
currently sets RegExp.prototype.exec return type to GLOBAL_INSTANCEOF_REGEXP_ID
(a RegExp) which is incorrect; change the return_type to a union of the
RegExpExecArray type and null (or use an Unknown placeholder until codegen
supports the specific RegExpExecArray type): locate the TypeData::from(Function
{ ... return_type: ... }) for REGEXP_EXEC_ID and replace
GLOBAL_INSTANCEOF_REGEXP_ID.into() with the appropriate union type identifier
(e.g., REGEXP_EXEC_ARRAY_ID.union_with(NULL_ID).into() or UNKNOWN_ID.into()) so
the signature reflects RegExpExecArray | null.

Copy link
Contributor Author

@tidefield tidefield Nov 25, 2025

Choose a reason for hiding this comment

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

@arendjr I copied what you had in https://github.com/biomejs/biome/pull/8166/files#diff-16f1cf097687c58ae8e671748408950c996a5cb0d8880c9e02daaa9e56e2f7ffR227-R236 and removed the function because it's not reused anywhere. But I think this catch sounds correct?

@tidefield
Copy link
Contributor Author

tidefield commented Nov 25, 2025

@arendjr This is not a complete implementation but it sets a direction for what I want to do. Regardless, It should leave GlobalsResolver better than it was even in case of manual "global type" extensions.

I preserved the old type names to make sure I'm not breaking anything. This approach is not scalable and needs to be reworked as I implement the codegen to for TYPE_ID and TYPE_ID_NAME for all global types. The name can likely inferred from the parser's output.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
crates/biome_js_type_info/src/globals.rs (1)

399-407: RegExp.exec return type is still modelled as RegExp

REGEXP_EXEC_ID is still returning GLOBAL_INSTANCEOF_REGEXP_ID, which implies RegExp.prototype.exec() returns a RegExp instance, whereas the runtime API returns RegExpExecArray | null. Even if you don't want to model RegExpExecArray yet, using an Unknown placeholder (or a TODO union) would avoid encoding an incorrect signature until codegen fills this in.

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

31-43: global_type_name + GLOBAL_TYPE_MEMBERS look good, consider tightening the fallback

The Option‑returning global_type_name plus "unknown" fallback keeps snapshot formatting stable even if a new ID misses a name, which is a reasonable trade‑off for now. As a small follow‑up once codegen lands, you might want a debug assertion that all IDs < NUM_PREDEFINED_TYPES have a name so missing mappings fail loudly during development rather than silently showing "unknown".

Also applies to: 45-97

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ac770b6 and f2920af.

📒 Files selected for processing (3)
  • crates/biome_js_type_info/src/format_type_info.rs (1 hunks)
  • crates/biome_js_type_info/src/globals.rs (9 hunks)
  • crates/biome_js_type_info/src/resolver.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/resolver.rs
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.rs: Use the Rust dbg!() macro for debugging output during test execution, and pass the --show-output flag to cargo test to display debug output.
Use snapshot testing with the insta crate for testing in Rust projects. Accept or reject snapshots using cargo insta accept, cargo insta reject, or cargo insta review.
Write doc comments as doc tests in Rust using code blocks with assertions that will be executed during the testing phase.
Use rustdoc inline documentation for rules, assists, and their options. Create corresponding documentation PRs for other documentation updates against the next branch of the website repository.
Set the version metadata field in linter rule implementations to 'next' for newly created rules. Update this field to the new version number when releasing a minor or major version.

Files:

  • crates/biome_js_type_info/src/globals.rs
crates/biome_js_type_info/**/*.rs

📄 CodeRabbit inference engine (crates/biome_js_type_info/CONTRIBUTING.md)

crates/biome_js_type_info/**/*.rs: No module may copy or clone data from another module in the module graph, not even behind an Arc
Use TypeReference instead of Arc for types that reference other types to avoid stale cache issues when modules are replaced
Store type data in linear vectors instead of using recursive data structures with Arc for improved data locality and performance
Use TypeReference variants (Qualifier, Resolved, Import, Unknown) to represent different phases of type resolution
Use TypeData::Unknown to indicate when type inference falls short or is not implemented
Distinguish between TypeData::Unknown and TypeData::UnknownKeyword to measure inference effectiveness versus explicit user-provided unknown types
When using ResolvedTypeData, track the ResolverId to ensure subsequent resolver calls use the correct context
Always apply the correct ResolverId when retrieving raw type data from ResolvedTypeData.as_raw_data() to prevent panics during subsequent resolution calls

Files:

  • crates/biome_js_type_info/src/globals.rs
🧠 Learnings (13)
📓 Common learnings
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : When using `ResolvedTypeData`, track the `ResolverId` to ensure subsequent resolver calls use the correct context
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Always apply the correct `ResolverId` when retrieving raw type data from `ResolvedTypeData.as_raw_data()` to prevent panics during subsequent resolution calls
Learnt from: arendjr
Repo: biomejs/biome PR: 7266
File: crates/biome_js_type_info/src/type.rs:94-102
Timestamp: 2025-08-20T16:24:59.781Z
Learning: In crates/biome_js_type_info/src/type.rs, the flattened_union_variants() method returns TypeReference instances that already have the correct module IDs applied to them. These references should be used directly with resolver.resolve_reference() without applying additional module ID transformations, as variant references may originate from nested unions in different modules.
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` variants (`Qualifier`, `Resolved`, `Import`, `Unknown`) to represent different phases of type resolution
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/scoped_resolver.rs : Implement full inference to resolve `TypeReference::Import` variants across the entire module graph
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.337Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` instead of `Arc` for types that reference other types to avoid stale cache issues when modules are replaced
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/flattening.rs : Implement type flattening to simplify `TypeofExpression` variants once all component types are resolved
Learnt from: arendjr
Repo: biomejs/biome PR: 6710
File: crates/biome_js_type_info/src/helpers.rs:102-124
Timestamp: 2025-09-09T18:10:05.095Z
Learning: Global constants like GLOBAL_ARRAY_ID are stored by the global resolver and should never have module IDs applied to them. Module IDs only apply to module resolvers, not global resolvers. When working with global type constants, use them directly without module ID transformations.
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Always apply the correct `ResolverId` when retrieving raw type data from `ResolvedTypeData.as_raw_data()` to prevent panics during subsequent resolution calls

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : When using `ResolvedTypeData`, track the `ResolverId` to ensure subsequent resolver calls use the correct context

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.337Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.337Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` instead of `Arc` for types that reference other types to avoid stale cache issues when modules are replaced

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` variants (`Qualifier`, `Resolved`, `Import`, `Unknown`) to represent different phases of type resolution

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-08-20T16:24:59.781Z
Learnt from: arendjr
Repo: biomejs/biome PR: 7266
File: crates/biome_js_type_info/src/type.rs:94-102
Timestamp: 2025-08-20T16:24:59.781Z
Learning: In crates/biome_js_type_info/src/type.rs, the flattened_union_variants() method returns TypeReference instances that already have the correct module IDs applied to them. These references should be used directly with resolver.resolve_reference() without applying additional module ID transformations, as variant references may originate from nested unions in different modules.

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/scoped_resolver.rs : Implement full inference to resolve `TypeReference::Import` variants across the entire module graph

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/flattening.rs : Implement type flattening to simplify `TypeofExpression` variants once all component types are resolved

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Store type data in linear vectors instead of using recursive data structures with `Arc` for improved data locality and performance

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Distinguish between `TypeData::Unknown` and `TypeData::UnknownKeyword` to measure inference effectiveness versus explicit user-provided unknown types

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/js_module_info/collector.rs : Implement module-level (thin) inference to resolve `TypeReference::Qualifier` variants by looking up declarations in module scopes and handling import statements

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-09-09T18:10:05.095Z
Learnt from: arendjr
Repo: biomejs/biome PR: 6710
File: crates/biome_js_type_info/src/helpers.rs:102-124
Timestamp: 2025-09-09T18:10:05.095Z
Learning: Global constants like GLOBAL_ARRAY_ID are stored by the global resolver and should never have module IDs applied to them. Module IDs only apply to module resolvers, not global resolvers. When working with global type constants, use them directly without module ID transformations.

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeData::Unknown` to indicate when type inference falls short or is not implemented

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
🧬 Code graph analysis (1)
crates/biome_js_type_info/src/globals.rs (4)
crates/biome_js_type_info/src/resolver.rs (8)
  • from_level (139-141)
  • new (55-57)
  • new (294-299)
  • name (503-505)
  • from (326-328)
  • from (333-335)
  • from (405-410)
  • from (415-420)
crates/biome_js_type_info/src/type_data.rs (19)
  • new (39-43)
  • new (1436-1440)
  • new (1471-1481)
  • default (168-170)
  • default (810-812)
  • default (1224-1226)
  • name (951-953)
  • name (999-1005)
  • from (174-176)
  • from (180-182)
  • from (186-188)
  • from (192-194)
  • from (198-200)
  • from (204-206)
  • from (210-212)
  • from (216-218)
  • from (222-224)
  • from (228-230)
  • from (234-236)
crates/biome_js_type_info/src/type_data/literal.rs (1)
  • new (34-36)
crates/biome_js_type_info/src/globals_builder.rs (2)
  • default (58-60)
  • with_capacity (16-20)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (23)
  • GitHub Check: Test Node.js API
  • GitHub Check: Bench (biome_tailwind_parser)
  • GitHub Check: Documentation
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Check Dependencies
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Bench (biome_graphql_parser)
  • GitHub Check: autofix
  • GitHub Check: Bench (biome_graphql_formatter)
  • GitHub Check: Bench (biome_package)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_css_parser)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Bench (biome_json_formatter)
  • GitHub Check: Bench (biome_json_analyze)
  • GitHub Check: Bench (biome_json_parser)
  • GitHub Check: Bench (biome_module_graph)
🔇 Additional comments (3)
crates/biome_js_type_info/src/globals.rs (3)

20-23: Nice separation of concerns for globals metadata

Importing GlobalsResolverBuilder and re‑exporting the IDs from globals_ids makes the globals surface much easier to consume and keeps the ID definitions in one place; no issues here.


105-107: GlobalsResolver visibility and helper closures are reasonable

Making types pub(crate) to allow builder‑based initialisation is fine given the crate‑internal scope, and the helper closures using global_type_name(id).unwrap_or("unknown") keep method names consistent with the ID metadata without re‑hardcoding strings. This all fits neatly with the new ID/name separation.

Also applies to: 120-151


156-411: Builder-based initialisation of globals is a solid improvement

The switch to GlobalsResolverBuilder::with_capacity(NUM_PREDEFINED_TYPES) and explicit set_type_data calls removes the brittle dependency on vec indices and keeps all predefined globals in one clearly structured block. The usage of TypeReference and a linear TypeStore for these entries matches the biome_js_type_info guidelines on type storage and references, and the IDs wired here line up with the ones handled in global_type_name, so I don't see any obvious gaps. Based on learnings, this is a good direction for future codegen to extend safely.

Copy link
Contributor

@arendjr arendjr left a comment

Choose a reason for hiding this comment

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

Nice work!

@tidefield tidefield force-pushed the feat/global-resolver-builder branch from 3780260 to 16432a1 Compare November 27, 2025 05:57
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (2)
crates/biome_js_type_info/src/globals_builder.rs (1)

39-44: Tiny readability nit on the Arc::new mapping

The nested line break around Arc::new is a bit awkward; you can make this easier on the eyes without changing behaviour:

-        let types: Vec<Arc<TypeData>> = self
-            .types
-            .into_iter()
-            .map(|opt| Arc::new(
-                opt.unwrap_or(TypeData::Unknown)))
-            .collect();
+        let types: Vec<Arc<TypeData>> = self
+            .types
+            .into_iter()
+            .map(|opt| Arc::new(opt.unwrap_or(TypeData::Unknown)))
+            .collect();
crates/biome_js_type_info/src/globals.rs (1)

385-407: RegExp.prototype.exec return type is still modelled as RegExp, which is incorrect

In JS, RegExp.prototype.exec() returns a match array (commonly RegExpExecArray) or null, not a RegExp instance; modelling it as GLOBAL_INSTANCEOF_REGEXP_ID will give clearly wrong downstream types (e.g. exec() results flowing as RegExp). Until you introduce a proper RegExpExecArray | null type, it would be less misleading to return unknown here.

         builder.set_type_data(
             REGEXP_EXEC_ID,
             TypeData::from(Function {
                 is_async: false,
                 type_parameters: Default::default(),
                 name: Some(Text::new_static(REGEXP_EXEC_ID_NAME)),
                 parameters: Default::default(),
-                return_type: ReturnType::Type(GLOBAL_INSTANCEOF_REGEXP_ID.into()),
+                // TODO: RegExp.prototype.exec() returns RegExpExecArray | null.
+                // Use `unknown` for now until we have a dedicated exec-array type.
+                return_type: ReturnType::Type(TypeReference::unknown()),
             }),
         );
🧹 Nitpick comments (1)
crates/biome_js_type_info/src/globals.rs (1)

31-42: Name table via global_type_name looks reasonable, with only a small footgun

Centralising the ID→name mapping and using Option with an "unknown" fallback for GLOBAL_TYPE_MEMBERS is a nice step towards codegen and keeps snapshots stable; just be mindful that forgetting to add a new ID to global_type_name will now silently show up as "unknown" rather than a hard failure, so a future debug-only check or test around this table might be worth adding once codegen lands.

Also applies to: 44-96

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a1426b and 16432a1.

📒 Files selected for processing (2)
  • crates/biome_js_type_info/src/globals.rs (10 hunks)
  • crates/biome_js_type_info/src/globals_builder.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.rs: Use the Rust dbg!() macro for debugging output during test execution, and pass the --show-output flag to cargo test to display debug output.
Use snapshot testing with the insta crate for testing in Rust projects. Accept or reject snapshots using cargo insta accept, cargo insta reject, or cargo insta review.
Write doc comments as doc tests in Rust using code blocks with assertions that will be executed during the testing phase.
Use rustdoc inline documentation for rules, assists, and their options. Create corresponding documentation PRs for other documentation updates against the next branch of the website repository.
Set the version metadata field in linter rule implementations to 'next' for newly created rules. Update this field to the new version number when releasing a minor or major version.

Files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
crates/biome_js_type_info/**/*.rs

📄 CodeRabbit inference engine (crates/biome_js_type_info/CONTRIBUTING.md)

crates/biome_js_type_info/**/*.rs: No module may copy or clone data from another module in the module graph, not even behind an Arc
Use TypeReference instead of Arc for types that reference other types to avoid stale cache issues when modules are replaced
Store type data in linear vectors instead of using recursive data structures with Arc for improved data locality and performance
Use TypeReference variants (Qualifier, Resolved, Import, Unknown) to represent different phases of type resolution
Use TypeData::Unknown to indicate when type inference falls short or is not implemented
Distinguish between TypeData::Unknown and TypeData::UnknownKeyword to measure inference effectiveness versus explicit user-provided unknown types
When using ResolvedTypeData, track the ResolverId to ensure subsequent resolver calls use the correct context
Always apply the correct ResolverId when retrieving raw type data from ResolvedTypeData.as_raw_data() to prevent panics during subsequent resolution calls

Files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
🧠 Learnings (14)
📓 Common learnings
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : When using `ResolvedTypeData`, track the `ResolverId` to ensure subsequent resolver calls use the correct context
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Always apply the correct `ResolverId` when retrieving raw type data from `ResolvedTypeData.as_raw_data()` to prevent panics during subsequent resolution calls
Learnt from: arendjr
Repo: biomejs/biome PR: 7266
File: crates/biome_js_type_info/src/type.rs:94-102
Timestamp: 2025-08-20T16:24:59.781Z
Learning: In crates/biome_js_type_info/src/type.rs, the flattened_union_variants() method returns TypeReference instances that already have the correct module IDs applied to them. These references should be used directly with resolver.resolve_reference() without applying additional module ID transformations, as variant references may originate from nested unions in different modules.
Learnt from: arendjr
Repo: biomejs/biome PR: 6710
File: crates/biome_js_type_info/src/helpers.rs:102-124
Timestamp: 2025-09-09T18:10:05.095Z
Learning: Global constants like GLOBAL_ARRAY_ID are stored by the global resolver and should never have module IDs applied to them. Module IDs only apply to module resolvers, not global resolvers. When working with global type constants, use them directly without module ID transformations.
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` variants (`Qualifier`, `Resolved`, `Import`, `Unknown`) to represent different phases of type resolution
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/scoped_resolver.rs : Implement full inference to resolve `TypeReference::Import` variants across the entire module graph
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.337Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` instead of `Arc` for types that reference other types to avoid stale cache issues when modules are replaced
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/flattening.rs : Implement type flattening to simplify `TypeofExpression` variants once all component types are resolved
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Always apply the correct `ResolverId` when retrieving raw type data from `ResolvedTypeData.as_raw_data()` to prevent panics during subsequent resolution calls

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : When using `ResolvedTypeData`, track the `ResolverId` to ensure subsequent resolver calls use the correct context

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-11-24T18:05:42.337Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.337Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` instead of `Arc` for types that reference other types to avoid stale cache issues when modules are replaced

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` variants (`Qualifier`, `Resolved`, `Import`, `Unknown`) to represent different phases of type resolution

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-08-20T16:24:59.781Z
Learnt from: arendjr
Repo: biomejs/biome PR: 7266
File: crates/biome_js_type_info/src/type.rs:94-102
Timestamp: 2025-08-20T16:24:59.781Z
Learning: In crates/biome_js_type_info/src/type.rs, the flattened_union_variants() method returns TypeReference instances that already have the correct module IDs applied to them. These references should be used directly with resolver.resolve_reference() without applying additional module ID transformations, as variant references may originate from nested unions in different modules.

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/scoped_resolver.rs : Implement full inference to resolve `TypeReference::Import` variants across the entire module graph

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/flattening.rs : Implement type flattening to simplify `TypeofExpression` variants once all component types are resolved

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Distinguish between `TypeData::Unknown` and `TypeData::UnknownKeyword` to measure inference effectiveness versus explicit user-provided unknown types

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/js_module_info/collector.rs : Implement module-level (thin) inference to resolve `TypeReference::Qualifier` variants by looking up declarations in module scopes and handling import statements

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeData::Unknown` to indicate when type inference falls short or is not implemented

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-09-09T18:10:05.095Z
Learnt from: arendjr
Repo: biomejs/biome PR: 6710
File: crates/biome_js_type_info/src/helpers.rs:102-124
Timestamp: 2025-09-09T18:10:05.095Z
Learning: Global constants like GLOBAL_ARRAY_ID are stored by the global resolver and should never have module IDs applied to them. Module IDs only apply to module resolvers, not global resolvers. When working with global type constants, use them directly without module ID transformations.

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Store type data in linear vectors instead of using recursive data structures with `Arc` for improved data locality and performance

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-11-24T18:05:27.784Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:27.784Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : Use the `dbg_write!` macro to debug formatter output instead of other logging methods

Applied to files:

  • crates/biome_js_type_info/src/globals_builder.rs
🧬 Code graph analysis (1)
crates/biome_js_type_info/src/globals.rs (1)
crates/biome_js_type_info/src/globals_builder.rs (2)
  • default (53-55)
  • with_capacity (16-20)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
  • GitHub Check: Test Node.js API
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Bench (biome_tailwind_parser)
  • GitHub Check: Bench (biome_package)
  • GitHub Check: Bench (biome_json_parser)
  • GitHub Check: Bench (biome_json_analyze)
  • GitHub Check: Bench (biome_css_parser)
  • GitHub Check: Bench (biome_json_formatter)
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Bench (biome_module_graph)
  • GitHub Check: autofix
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_graphql_parser)
  • GitHub Check: Bench (biome_graphql_formatter)
🔇 Additional comments (2)
crates/biome_js_type_info/src/globals.rs (1)

107-155: Builder‑based GlobalsResolver::default is a big improvement over index juggling

Switching to GlobalsResolverBuilder::with_capacity(NUM_PREDEFINED_TYPES) and explicitly set_type_data calls for all predefined IDs removes the brittle coupling between ID integers, vector indices, and names; this should make future manual and generated globals much less painful while still aligning with the “linear TypeStore + TypeReference” guidance in CONTRIBUTING.

Also applies to: 168-336, 373-387

crates/biome_js_type_info/src/globals_builder.rs (1)

9-20: Builder design + Unknown fallback match the intended inference story

Using a Vec<Option<TypeData>> with debug‑only bounds/single‑assignment checks in set_type_data, and defaulting missing entries to TypeData::Unknown in build(), gives you forward references without runtime panics and lines up neatly with the CONTRIBUTING guidance to prefer Unknown over crashing when inference data is incomplete. This looks like the right foundation for generated globals.

Also applies to: 22-35, 37-49, 52-56

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
crates/biome_js_type_info/src/globals_builder.rs (2)

9-35: Builder invariants and use of TypeData::Unknown look sound

The overall builder shape (pre-sized Vec<Option<TypeData>>, set_type_data with debug-only checks, and leaving release builds without extra panics) looks solid, and using TypeData::Unknown for unfilled slots matches the guidance to represent “missing/inferred later” global types without blowing up construction. Just make sure call-sites treat these as “inference not available yet” rather than user-authored unknown.

Based on learnings, this aligns with storing type data in linear vectors and using TypeData::Unknown for incomplete inference.


37-47: Consider unwrap_or_else to avoid redundant Unknown construction

Tiny micro-optimisation/idiom point: unwrap_or will construct a TypeData::Unknown for every slot, even when it’s not used. unwrap_or_else avoids that and keeps intent clear:

-        let types: Vec<Arc<TypeData>> = self
-            .types
-            .into_iter()
-            .map(|opt| Arc::new(opt.unwrap_or(TypeData::Unknown)))
-            .collect();
+        let types: Vec<Arc<TypeData>> = self
+            .types
+            .into_iter()
+            .map(|opt| Arc::new(opt.unwrap_or_else(|| TypeData::Unknown)))
+            .collect();

Not critical at this scale, but a bit more idiomatic.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 16432a1 and 6cb3d82.

📒 Files selected for processing (1)
  • crates/biome_js_type_info/src/globals_builder.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.rs: Use the Rust dbg!() macro for debugging output during test execution, and pass the --show-output flag to cargo test to display debug output.
Use snapshot testing with the insta crate for testing in Rust projects. Accept or reject snapshots using cargo insta accept, cargo insta reject, or cargo insta review.
Write doc comments as doc tests in Rust using code blocks with assertions that will be executed during the testing phase.
Use rustdoc inline documentation for rules, assists, and their options. Create corresponding documentation PRs for other documentation updates against the next branch of the website repository.
Set the version metadata field in linter rule implementations to 'next' for newly created rules. Update this field to the new version number when releasing a minor or major version.

Files:

  • crates/biome_js_type_info/src/globals_builder.rs
crates/biome_js_type_info/**/*.rs

📄 CodeRabbit inference engine (crates/biome_js_type_info/CONTRIBUTING.md)

crates/biome_js_type_info/**/*.rs: No module may copy or clone data from another module in the module graph, not even behind an Arc
Use TypeReference instead of Arc for types that reference other types to avoid stale cache issues when modules are replaced
Store type data in linear vectors instead of using recursive data structures with Arc for improved data locality and performance
Use TypeReference variants (Qualifier, Resolved, Import, Unknown) to represent different phases of type resolution
Use TypeData::Unknown to indicate when type inference falls short or is not implemented
Distinguish between TypeData::Unknown and TypeData::UnknownKeyword to measure inference effectiveness versus explicit user-provided unknown types
When using ResolvedTypeData, track the ResolverId to ensure subsequent resolver calls use the correct context
Always apply the correct ResolverId when retrieving raw type data from ResolvedTypeData.as_raw_data() to prevent panics during subsequent resolution calls

Files:

  • crates/biome_js_type_info/src/globals_builder.rs
🧠 Learnings (12)
📓 Common learnings
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : When using `ResolvedTypeData`, track the `ResolverId` to ensure subsequent resolver calls use the correct context
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Always apply the correct `ResolverId` when retrieving raw type data from `ResolvedTypeData.as_raw_data()` to prevent panics during subsequent resolution calls
Learnt from: arendjr
Repo: biomejs/biome PR: 7266
File: crates/biome_js_type_info/src/type.rs:94-102
Timestamp: 2025-08-20T16:24:59.781Z
Learning: In crates/biome_js_type_info/src/type.rs, the flattened_union_variants() method returns TypeReference instances that already have the correct module IDs applied to them. These references should be used directly with resolver.resolve_reference() without applying additional module ID transformations, as variant references may originate from nested unions in different modules.
Learnt from: arendjr
Repo: biomejs/biome PR: 6710
File: crates/biome_js_type_info/src/helpers.rs:102-124
Timestamp: 2025-09-09T18:10:05.095Z
Learning: Global constants like GLOBAL_ARRAY_ID are stored by the global resolver and should never have module IDs applied to them. Module IDs only apply to module resolvers, not global resolvers. When working with global type constants, use them directly without module ID transformations.
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/scoped_resolver.rs : Implement full inference to resolve `TypeReference::Import` variants across the entire module graph
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` variants (`Qualifier`, `Resolved`, `Import`, `Unknown`) to represent different phases of type resolution
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : When using `ResolvedTypeData`, track the `ResolverId` to ensure subsequent resolver calls use the correct context

Applied to files:

  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Always apply the correct `ResolverId` when retrieving raw type data from `ResolvedTypeData.as_raw_data()` to prevent panics during subsequent resolution calls

Applied to files:

  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-11-24T18:05:42.337Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.337Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` instead of `Arc` for types that reference other types to avoid stale cache issues when modules are replaced

Applied to files:

  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` variants (`Qualifier`, `Resolved`, `Import`, `Unknown`) to represent different phases of type resolution

Applied to files:

  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Store type data in linear vectors instead of using recursive data structures with `Arc` for improved data locality and performance

Applied to files:

  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/scoped_resolver.rs : Implement full inference to resolve `TypeReference::Import` variants across the entire module graph

Applied to files:

  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-08-20T16:24:59.781Z
Learnt from: arendjr
Repo: biomejs/biome PR: 7266
File: crates/biome_js_type_info/src/type.rs:94-102
Timestamp: 2025-08-20T16:24:59.781Z
Learning: In crates/biome_js_type_info/src/type.rs, the flattened_union_variants() method returns TypeReference instances that already have the correct module IDs applied to them. These references should be used directly with resolver.resolve_reference() without applying additional module ID transformations, as variant references may originate from nested unions in different modules.

Applied to files:

  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeData::Unknown` to indicate when type inference falls short or is not implemented

Applied to files:

  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Distinguish between `TypeData::Unknown` and `TypeData::UnknownKeyword` to measure inference effectiveness versus explicit user-provided unknown types

Applied to files:

  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-11-24T18:05:42.338Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.338Z
Learning: Applies to crates/biome_js_type_info/**/js_module_info/collector.rs : Implement module-level (thin) inference to resolve `TypeReference::Qualifier` variants by looking up declarations in module scopes and handling import statements

Applied to files:

  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-11-24T18:05:27.784Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:27.784Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : Use the `dbg_write!` macro to debug formatter output instead of other logging methods

Applied to files:

  • crates/biome_js_type_info/src/globals_builder.rs
🧬 Code graph analysis (1)
crates/biome_js_type_info/src/globals_builder.rs (3)
crates/biome_js_type_info/src/resolver.rs (5)
  • id (72-74)
  • index (77-79)
  • index (301-303)
  • new (55-57)
  • new (294-299)
crates/biome_js_type_info/src/type_store.rs (1)
  • from_types (35-45)
crates/biome_js_type_info/src/globals.rs (1)
  • default (108-410)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (23)
  • GitHub Check: Documentation
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: End-to-end tests
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Check Dependencies
  • GitHub Check: Test Node.js API
  • GitHub Check: Bench (biome_tailwind_parser)
  • GitHub Check: Bench (biome_json_formatter)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_json_analyze)
  • GitHub Check: Bench (biome_json_parser)
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: Bench (biome_module_graph)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Bench (biome_css_parser)
  • GitHub Check: Bench (biome_graphql_formatter)
  • GitHub Check: Bench (biome_graphql_parser)
  • GitHub Check: Bench (biome_package)

@tidefield tidefield force-pushed the feat/global-resolver-builder branch from 6cb3d82 to ab2cde2 Compare November 27, 2025 10:32
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
crates/biome_js_type_info/src/globals.rs (1)

398-407: RegExp.exec still returns a RegExp instance instead of a match array

This still models RegExp.prototype.exec as returning a RegExp (GLOBAL_INSTANCEOF_REGEXP_ID), whereas the JS signature is effectively RegExpExecArray | null. Even if you’d prefer to keep this refactor behaviour‑preserving, swapping to an unknown placeholder would avoid advertising the wrong return type until you have a proper match‑array type.

         builder.set_type_data(
             REGEXP_EXEC_ID,
             TypeData::from(Function {
                 is_async: false,
                 type_parameters: Default::default(),
                 name: Some(Text::new_static(REGEXP_EXEC_ID_NAME)),
                 parameters: Default::default(),
-                return_type: ReturnType::Type(GLOBAL_INSTANCEOF_REGEXP_ID.into()),
+                // TODO: RegExp.prototype.exec should return RegExpExecArray | null.
+                // Use an unknown placeholder for now until that type is modelled.
+                return_type: ReturnType::Type(TypeReference::unknown()),
             }),
         );
🧹 Nitpick comments (3)
crates/biome_js_type_info/src/format_type_info.rs (1)

575-635: Global type formatting fallback looks correct

Using global_type_name(id) first and only shifting the index in the None case keeps snapshot indices stable and avoids the earlier underflow, given the current exhaustive mapping in global_type_name. You might very lightly rephrase the comment about GLOBAL_TYPE_MEMBERS “ensuring” the invariant, since it currently just consumes the names and the real contract lives in global_type_name / codegen, but functionally this is fine.

crates/biome_js_type_info/src/globals.rs (1)

31-42: Make the “all predefined have names” invariant explicit in debug builds

Right now the invariant that all TypeId < NUM_PREDEFINED_TYPES have a name lives in convention plus this manual match; GLOBAL_TYPE_MEMBERS will quietly fall back to "unknown" if an entry is missed. If you want to lean on that invariant elsewhere (e.g. for safe index shifting in formatting), a tiny debug‑only assertion here would make future additions fail loudly when a name is forgotten, while still defaulting to "unknown" in release.

-        .map(|id| {
-            let name = global_type_name(id).unwrap_or("unknown");
+        .map(|id| {
+            let name = global_type_name(id).unwrap_or_else(|| {
+                debug_assert!(
+                    false,
+                    "Missing global_type_name for predefined TypeId index {}",
+                    id.index()
+                );
+                "unknown"
+            });

Also applies to: 44-96

crates/biome_js_type_info/src/globals_ids.rs (1)

13-76: Macro-based global ID table is fine as a temporary bridge

The sequential indices and names all line up with global_type_name and the builder, and NUM_PREDEFINED_TYPES = 44 matches the highest index of 43. Given this is explicitly a stopgap until codegen, I’m fine with the paste dependency; if you ever want to keep it longer‑term, you might consider dropping #[macro_export] so define_global_type! doesn’t leak into the public API unnecessarily.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6cb3d82 and ab2cde2.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock and included by **
📒 Files selected for processing (7)
  • crates/biome_js_type_info/Cargo.toml (1 hunks)
  • crates/biome_js_type_info/src/format_type_info.rs (1 hunks)
  • crates/biome_js_type_info/src/globals.rs (10 hunks)
  • crates/biome_js_type_info/src/globals_builder.rs (1 hunks)
  • crates/biome_js_type_info/src/globals_ids.rs (1 hunks)
  • crates/biome_js_type_info/src/lib.rs (2 hunks)
  • crates/biome_js_type_info/src/resolver.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • crates/biome_js_type_info/src/resolver.rs
  • crates/biome_js_type_info/src/lib.rs
🧰 Additional context used
📓 Path-based instructions (3)
**/Cargo.toml

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Use workspace dependencies defined in the root Cargo.toml for internal crates, specifying workspace = true in each crate's Cargo.toml. Use path dependencies for dev-dependencies to avoid requiring published versions.

Files:

  • crates/biome_js_type_info/Cargo.toml
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.rs: Use the Rust dbg!() macro for debugging output during test execution, and pass the --show-output flag to cargo test to display debug output.
Use snapshot testing with the insta crate for testing in Rust projects. Accept or reject snapshots using cargo insta accept, cargo insta reject, or cargo insta review.
Write doc comments as doc tests in Rust using code blocks with assertions that will be executed during the testing phase.
Use rustdoc inline documentation for rules, assists, and their options. Create corresponding documentation PRs for other documentation updates against the next branch of the website repository.
Set the version metadata field in linter rule implementations to 'next' for newly created rules. Update this field to the new version number when releasing a minor or major version.

Files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals_ids.rs
crates/biome_js_type_info/**/*.rs

📄 CodeRabbit inference engine (crates/biome_js_type_info/CONTRIBUTING.md)

crates/biome_js_type_info/**/*.rs: No module may copy or clone data from another module in the module graph, not even behind an Arc
Use TypeReference instead of Arc for types that reference other types to avoid stale cache issues when modules are replaced
Store type data in linear vectors instead of using recursive data structures with Arc for improved data locality and performance
Use TypeReference variants (Qualifier, Resolved, Import, Unknown) to represent different phases of type resolution
Use TypeData::Unknown to indicate when type inference falls short or is not implemented
Distinguish between TypeData::Unknown and TypeData::UnknownKeyword to measure inference effectiveness versus explicit user-provided unknown types
When using ResolvedTypeData, track the ResolverId to ensure subsequent resolver calls use the correct context
Always apply the correct ResolverId when retrieving raw type data from ResolvedTypeData.as_raw_data() to prevent panics during subsequent resolution calls

Files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals_ids.rs
🧠 Learnings (24)
📓 Common learnings
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : When using `ResolvedTypeData`, track the `ResolverId` to ensure subsequent resolver calls use the correct context
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Always apply the correct `ResolverId` when retrieving raw type data from `ResolvedTypeData.as_raw_data()` to prevent panics during subsequent resolution calls
Learnt from: arendjr
Repo: biomejs/biome PR: 7266
File: crates/biome_js_type_info/src/type.rs:94-102
Timestamp: 2025-08-20T16:24:59.781Z
Learning: In crates/biome_js_type_info/src/type.rs, the flattened_union_variants() method returns TypeReference instances that already have the correct module IDs applied to them. These references should be used directly with resolver.resolve_reference() without applying additional module ID transformations, as variant references may originate from nested unions in different modules.
Learnt from: arendjr
Repo: biomejs/biome PR: 6710
File: crates/biome_js_type_info/src/helpers.rs:102-124
Timestamp: 2025-09-09T18:10:05.095Z
Learning: Global constants like GLOBAL_ARRAY_ID are stored by the global resolver and should never have module IDs applied to them. Module IDs only apply to module resolvers, not global resolvers. When working with global type constants, use them directly without module ID transformations.
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` variants (`Qualifier`, `Resolved`, `Import`, `Unknown`) to represent different phases of type resolution
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/scoped_resolver.rs : Implement full inference to resolve `TypeReference::Import` variants across the entire module graph
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` instead of `Arc` for types that reference other types to avoid stale cache issues when modules are replaced
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/flattening.rs : Implement type flattening to simplify `TypeofExpression` variants once all component types are resolved
📚 Learning: 2025-11-24T18:05:20.371Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:20.371Z
Learning: Applies to crates/biome_formatter/**/biome_*_formatter/Cargo.toml : Include development dependencies in `Cargo.toml` for formatter tests: `biome_formatter_test`, `biome_<language>_factory`, `biome_<language>_parser`, `biome_parser`, `biome_service`, `countme`, `iai`, `quickcheck`, `quickcheck_macros`, and `tests_macros`

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` instead of `Arc` for types that reference other types to avoid stale cache issues when modules are replaced

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals_ids.rs
📚 Learning: 2025-11-24T18:03:52.024Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:03:52.024Z
Learning: For bugfix/feature PRs visible to Biome toolchain users or affecting published crates, create a changeset using the `just new-changeset` command with appropriate package selection, change type (major/minor/patch), and description.

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
  • crates/biome_js_type_info/src/format_type_info.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Store type data in linear vectors instead of using recursive data structures with `Arc` for improved data locality and performance

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/format_type_info.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Distinguish between `TypeData::Unknown` and `TypeData::UnknownKeyword` to measure inference effectiveness versus explicit user-provided unknown types

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals_ids.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/language_kind.rs : Add a new language prefix to the `LANGUAGE_PREFIXES` constant in `language_kind.rs` file

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
📚 Learning: 2025-11-24T18:03:52.024Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:03:52.024Z
Learning: Applies to **/Cargo.toml : Use workspace dependencies defined in the root `Cargo.toml` for internal crates, specifying `workspace = true` in each crate's Cargo.toml. Use path dependencies for dev-dependencies to avoid requiring published versions.

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeData::Unknown` to indicate when type inference falls short or is not implemented

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals_ids.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Create two new crates `biome_{language}_syntax` and `biome_{language}_factory` using `cargo new --lib` for new language parsers

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/language_kind.rs : Add a new variant to `LanguageKind` enum in `language_kind.rs` file and implement all methods for the new language variant

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
📚 Learning: 2025-11-24T18:06:12.048Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_service/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:12.048Z
Learning: Applies to crates/biome_service/src/workspace*.rs : Implement the Workspace trait in the Biome Service to manage internal state of projects, including open documents, project layout instances, and module graph instances

Applied to files:

  • crates/biome_js_type_info/Cargo.toml
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Always apply the correct `ResolverId` when retrieving raw type data from `ResolvedTypeData.as_raw_data()` to prevent panics during subsequent resolution calls

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals_ids.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : When using `ResolvedTypeData`, track the `ResolverId` to ensure subsequent resolver calls use the correct context

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals_ids.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` variants (`Qualifier`, `Resolved`, `Import`, `Unknown`) to represent different phases of type resolution

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals_ids.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/scoped_resolver.rs : Implement full inference to resolve `TypeReference::Import` variants across the entire module graph

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals_ids.rs
📚 Learning: 2025-08-20T16:24:59.781Z
Learnt from: arendjr
Repo: biomejs/biome PR: 7266
File: crates/biome_js_type_info/src/type.rs:94-102
Timestamp: 2025-08-20T16:24:59.781Z
Learning: In crates/biome_js_type_info/src/type.rs, the flattened_union_variants() method returns TypeReference instances that already have the correct module IDs applied to them. These references should be used directly with resolver.resolve_reference() without applying additional module ID transformations, as variant references may originate from nested unions in different modules.

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals_ids.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/flattening.rs : Implement type flattening to simplify `TypeofExpression` variants once all component types are resolved

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_builder.rs
  • crates/biome_js_type_info/src/format_type_info.rs
  • crates/biome_js_type_info/src/globals_ids.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/js_module_info/collector.rs : Implement module-level (thin) inference to resolve `TypeReference::Qualifier` variants by looking up declarations in module scopes and handling import statements

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/format_type_info.rs
📚 Learning: 2025-11-24T18:04:42.160Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:04:42.160Z
Learning: Applies to crates/biome_analyze/**/biome_*_analyze/lib/src/**/!(mod).rs : Rules that ban functions or variables should use the semantic model to check if the variable is global before reporting, to avoid false positives on locally redeclared variables

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
📚 Learning: 2025-09-09T18:10:05.095Z
Learnt from: arendjr
Repo: biomejs/biome PR: 6710
File: crates/biome_js_type_info/src/helpers.rs:102-124
Timestamp: 2025-09-09T18:10:05.095Z
Learning: Global constants like GLOBAL_ARRAY_ID are stored by the global resolver and should never have module IDs applied to them. Module IDs only apply to module resolvers, not global resolvers. When working with global type constants, use them directly without module ID transformations.

Applied to files:

  • crates/biome_js_type_info/src/globals.rs
  • crates/biome_js_type_info/src/globals_ids.rs
📚 Learning: 2025-11-24T18:05:27.810Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:27.810Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : Use the `dbg_write!` macro to debug formatter output instead of other logging methods

Applied to files:

  • crates/biome_js_type_info/src/globals_builder.rs
📚 Learning: 2025-11-24T18:05:27.810Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:27.810Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : When formatting AST nodes, use mandatory tokens from the AST instead of hardcoding token strings (e.g., use `node.l_paren_token().format()` instead of `token("(")`)

Applied to files:

  • crates/biome_js_type_info/src/format_type_info.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/local_inference.rs : Implement local inference in dedicated modules to derive type definitions from expressions without context of surrounding scopes

Applied to files:

  • crates/biome_js_type_info/src/format_type_info.rs
🧬 Code graph analysis (3)
crates/biome_js_type_info/src/globals_builder.rs (2)
crates/biome_js_type_info/src/type_store.rs (1)
  • from_types (35-45)
crates/biome_js_type_info/src/globals.rs (1)
  • default (108-410)
crates/biome_js_type_info/src/format_type_info.rs (1)
crates/biome_js_type_info/src/globals.rs (1)
  • global_type_name (46-96)
crates/biome_js_type_info/src/globals_ids.rs (1)
crates/biome_js_type_info/src/resolver.rs (2)
  • new (55-57)
  • new (294-299)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (24)
  • GitHub Check: Test Node.js API
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Documentation
  • GitHub Check: Bench (biome_json_analyze)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Bench (biome_json_formatter)
  • GitHub Check: autofix
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: End-to-end tests
  • GitHub Check: Bench (biome_json_parser)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Check Dependencies
  • GitHub Check: Bench (biome_graphql_formatter)
  • GitHub Check: Bench (biome_graphql_parser)
  • GitHub Check: Bench (biome_module_graph)
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: Bench (biome_css_parser)
  • GitHub Check: Bench (biome_tailwind_parser)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Bench (biome_package)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_js_analyze)
🔇 Additional comments (4)
crates/biome_js_type_info/Cargo.toml (1)

25-25: Based on the verification results, I can now rewrite the review comment. The web search confirms that paste is a standard external crate used for compile-time macro identifier concatenation. However, I found an important distinction: the original review conflates internal workspace crates (which use workspace = true) with external crates (which should use workspace.dependencies).

Ensure paste dependency is defined in root workspace.dependencies.

The external dependency paste = "1.0" should be managed at the workspace level rather than declared individually in each crate's Cargo.toml. Per Cargo best practices for workspaces, move this to the root Cargo.toml under [workspace.dependencies] and reference it in this crate with paste = { workspace = true }. This prevents version duplication and ensures all crates in the workspace use the same paste version.

⛔ Skipped due to learnings
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:03:52.024Z
Learning: Applies to **/Cargo.toml : Use workspace dependencies defined in the root `Cargo.toml` for internal crates, specifying `workspace = true` in each crate's Cargo.toml. Use path dependencies for dev-dependencies to avoid requiring published versions.
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_service/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:12.048Z
Learning: Applies to crates/biome_service/src/workspace*.rs : Implement the Workspace trait in the Biome Service to manage internal state of projects, including open documents, project layout instances, and module graph instances
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:20.371Z
Learning: Applies to crates/biome_formatter/**/biome_*_formatter/Cargo.toml : Include development dependencies in `Cargo.toml` for formatter tests: `biome_formatter_test`, `biome_<language>_factory`, `biome_<language>_parser`, `biome_parser`, `biome_service`, `countme`, `iai`, `quickcheck`, `quickcheck_macros`, and `tests_macros`
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_service/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:12.048Z
Learning: Applies to crates/biome_service/src/workspace/watcher.tests.rs : Implement watcher tests for workspace methods in watcher.tests.rs and end-to-end tests in LSP tests
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` instead of `Arc` for types that reference other types to avoid stale cache issues when modules are replaced
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:04:42.160Z
Learning: Applies to crates/biome_analyze/**/biome_*_analyze/lib/src/**/!(mod).rs : Multi-file documentation snippets should use 'file=<path>' property to create an in-memory file system for testing cross-file rule behavior
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:04:42.160Z
Learning: Applies to crates/biome_analyze/**/biome_*_analyze/lib/src/**/!(mod).rs : The 'declare_lint_rule!' macro must include a 'version' field set to 'next' to allow flexibility for the actual release version
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:04:42.160Z
Learning: Applies to crates/biome_analyze/**/biome_*_analyze/lib/src/**/!(mod).rs : Rules ported from other ecosystems should include a 'sources' field in the 'declare_lint_rule!' macro with RuleSource metadata (e.g., '::ESLint')
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:04:42.160Z
Learning: Applies to crates/biome_analyze/**/biome_*_analyze/lib/src/**/!(mod).rs : The first paragraph of rule documentation must be a single line and serves as the brief description for the rule overview page
crates/biome_js_type_info/src/globals_builder.rs (1)

1-56: GlobalsResolverBuilder design matches the intended storage model

The builder + Option<TypeData> layout cleanly decouples ID ordering from construction, and the TypeData::Unknown default for unfilled slots is a sensible (and documented) fallback for missing definitions. The debug assertions give you safety in debug without affecting release, so this looks good to ship as the base for future codegen.

crates/biome_js_type_info/src/globals.rs (1)

98-409: Builder‑based GlobalsResolver initialisation is a nice clean‑up

Switching the globals initialisation to GlobalsResolverBuilder removes the fragile dependence on Vec ordering, keeps everything in a single linear TypeStore, and uses the GLOBAL_* resolved IDs consistently for cross‑links. This is a solid base for the planned codegen and should make extending the global set much less error‑prone.

crates/biome_js_type_info/src/globals_ids.rs (1)

78-116: ResolvedTypeId globals are wired consistently

The GLOBAL_* resolved IDs here match the corresponding TypeIds and the way they’re consumed in globals.rs (array, promise, typeof string literals, fetch, RegExp, etc.), all at GLOBAL_LEVEL. Nothing stands out as inconsistent.

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Thank you @tidefield !

@ematipico ematipico merged commit 2a229e4 into biomejs:main Nov 27, 2025
28 checks passed
l0ngvh pushed a commit to l0ngvh/biome that referenced this pull request Dec 21, 2025
…iomejs#8253)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Arend van Beelen jr. <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Type-Inference Area: type inference L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants