Skip to content

Commit ba4630f

Browse files
committed
feat(rust): oxc-index-vec v4.0
1 parent b3b482a commit ba4630f

File tree

25 files changed

+69
-314
lines changed

25 files changed

+69
-314
lines changed

Cargo.lock

Lines changed: 9 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ unicode-id-start = "1"
158158
javascript-globals = "1"
159159
json-strip-comments = "3"
160160
oxc-browserslist = "2"
161-
oxc_index = "3"
161+
oxc_index = { version = "4", features = ["nonmax", "serde"] }
162162
oxc_resolver = "11"
163163
oxc_sourcemap = "4"
164164

crates/oxc_cfg/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,5 @@ oxc_syntax = { workspace = true }
2626

2727
bitflags = { workspace = true }
2828
itertools = { workspace = true }
29-
nonmax = { workspace = true }
3029
petgraph = { workspace = true, default-features = false, features = ["std", "stable_graph"] }
3130
rustc-hash = { workspace = true }

crates/oxc_cfg/src/dot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl DisplayDot for ControlFlowGraph {
4545
let block = &self.basic_blocks[*node.1];
4646
let mut attrs = Attrs::default().with("label", block.display_dot());
4747

48-
if *node.1 == 0 {
48+
if node.1.index() == 0 {
4949
attrs += ("color", "green");
5050
}
5151
if block.is_unreachable() {

crates/oxc_cfg/src/lib.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ pub mod visit;
66
use std::fmt;
77

88
use itertools::Itertools;
9-
use nonmax::NonMaxU32;
10-
use oxc_index::{Idx, IndexVec};
9+
use oxc_index::{IndexVec, define_nonmax_u32_index_type};
1110
use petgraph::{
1211
Direction,
1312
visit::{Control, DfsEvent, EdgeRef},
@@ -28,20 +27,9 @@ pub use dot::DisplayDot;
2827
use visit::set_depth_first_search;
2928

3029
pub type BlockNodeId = petgraph::stable_graph::NodeIndex;
31-
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
32-
pub struct BasicBlockId(NonMaxU32);
33-
34-
impl Idx for BasicBlockId {
35-
#[expect(clippy::cast_possible_truncation)]
36-
fn from_usize(idx: usize) -> Self {
37-
assert!(idx < u32::MAX as usize);
38-
// SAFETY: We just checked `idx` is valid for `NonMaxU32`
39-
Self(unsafe { NonMaxU32::new_unchecked(idx as u32) })
40-
}
4130

42-
fn index(self) -> usize {
43-
self.0.get() as usize
44-
}
31+
define_nonmax_u32_index_type! {
32+
pub struct BasicBlockId;
4533
}
4634

4735
impl PartialEq<u32> for BasicBlockId {

crates/oxc_codegen/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ bitflags = { workspace = true }
3333
cow-utils = { workspace = true }
3434
dragonbox_ecma = { workspace = true }
3535
itoa = { workspace = true }
36-
nonmax = { workspace = true }
3736
rustc-hash = { workspace = true }
3837

3938
[dev-dependencies]

crates/oxc_codegen/src/sourcemap_builder.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::path::Path;
22

3-
use nonmax::NonMaxU32;
4-
5-
use oxc_index::{Idx, IndexVec};
3+
use oxc_index::{IndexVec, define_nonmax_u32_index_type};
64
use oxc_span::Span;
75
use oxc_syntax::identifier::{LS, PS};
86

@@ -11,21 +9,9 @@ use crate::str::{LS_LAST_2_BYTES, LS_OR_PS_FIRST_BYTE, PS_LAST_2_BYTES};
119
/// Number of lines to check with linear search when translating byte position to line index
1210
const LINE_SEARCH_LINEAR_ITERATIONS: usize = 16;
1311

14-
/// Index into vec of `ColumnOffsets`
15-
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
16-
pub struct ColumnOffsetsId(NonMaxU32);
17-
18-
impl Idx for ColumnOffsetsId {
19-
#[expect(clippy::cast_possible_truncation)]
20-
fn from_usize(idx: usize) -> Self {
21-
assert!(idx < u32::MAX as usize);
22-
// SAFETY: We just checked `idx` is a legal value for `NonMaxU32`
23-
Self(unsafe { NonMaxU32::new_unchecked(idx as u32) })
24-
}
25-
26-
fn index(self) -> usize {
27-
self.0.get() as usize
28-
}
12+
define_nonmax_u32_index_type! {
13+
/// Index into vec of `ColumnOffsets`
14+
struct ColumnOffsetsId;
2915
}
3016

3117
/// Line offset tables.

crates/oxc_linter/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ oxc_codegen = { workspace = true }
3535
oxc_data_structures = { workspace = true, features = ["box_macros"] }
3636
oxc_diagnostics = { workspace = true }
3737
oxc_ecmascript = { workspace = true }
38-
oxc_index = { workspace = true, features = ["serde"] }
38+
oxc_index = { workspace = true }
3939
oxc_macros = { workspace = true, features = ["ruledocs"] }
4040
oxc_parser = { workspace = true }
4141
oxc_regular_expression = { workspace = true }
@@ -59,7 +59,6 @@ json-strip-comments = { workspace = true }
5959
language-tags = { workspace = true }
6060
lazy-regex = { workspace = true }
6161
memchr = { workspace = true }
62-
nonmax = { workspace = true }
6362
papaya = { workspace = true }
6463
phf = { workspace = true, features = ["macros"] }
6564
rayon = { workspace = true }

crates/oxc_linter/src/rules/eslint/no_useless_backreference.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use nonmax::NonMaxU32;
2-
31
use oxc_diagnostics::OxcDiagnostic;
4-
use oxc_index::{Idx, IndexVec};
2+
use oxc_index::{IndexVec, define_nonmax_u32_index_type};
53
use oxc_macros::declare_oxc_lint;
64
use oxc_regular_expression::{
75
ast::LookAroundAssertionKind,
@@ -117,20 +115,8 @@ enum BackRefInfoTarget<'a> {
117115
Name(&'a str),
118116
}
119117

120-
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
121-
pub struct RegexNodeId(NonMaxU32);
122-
123-
impl Idx for RegexNodeId {
124-
#[expect(clippy::cast_possible_truncation)]
125-
fn from_usize(idx: usize) -> Self {
126-
assert!(idx < u32::MAX as usize);
127-
// SAFETY: We just checked `idx` is valid for `NonMaxU32`
128-
Self(unsafe { NonMaxU32::new_unchecked(idx as u32) })
129-
}
130-
131-
fn index(self) -> usize {
132-
self.0.get() as usize
133-
}
118+
define_nonmax_u32_index_type! {
119+
pub struct RegexNodeId;
134120
}
135121

136122
#[derive(Debug)]

crates/oxc_linter/src/rules/jest/max_expects.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use oxc_ast::{AstKind, ast::Expression};
22
use oxc_diagnostics::OxcDiagnostic;
3-
use oxc_index::Idx;
43
use oxc_macros::declare_oxc_lint;
54
use oxc_span::Span;
65
use rustc_hash::FxHashMap;
@@ -500,7 +499,7 @@ fn test() {
500499
(
501500
" test('should pass', async () => {
502501
expect.hasAssertions();
503-
502+
504503
expect(true).toBeDefined();
505504
expect(true).toBeDefined();
506505
expect(true).toBeDefined();

0 commit comments

Comments
 (0)