Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
f68fc84e
Commit
f68fc84e
authored
Mar 06, 2026
by
Matt Mastracci
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Inert/sync
parent
9ff61b82
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
22 deletions
+31
-22
linker.rs
turbopack/crates/turbopack-ecmascript/src/analyzer/linker.rs
+18
-13
mod.rs
turbopack/crates/turbopack-ecmascript/src/analyzer/mod.rs
+12
-3
mod.rs
turbopack/crates/turbopack-ecmascript/src/references/mod.rs
+1
-6
No files found.
turbopack/crates/turbopack-ecmascript/src/analyzer/linker.rs
View file @
f68fc84e
...
@@ -2,13 +2,13 @@ use std::{collections::hash_map::Entry, fmt::Display, future::Future, sync::Arc}
...
@@ -2,13 +2,13 @@ use std::{collections::hash_map::Entry, fmt::Display, future::Future, sync::Arc}
use
anyhow
::
Result
;
use
anyhow
::
Result
;
use
parking_lot
::
Mutex
;
use
parking_lot
::
Mutex
;
use
rustc_hash
::{
FxHashMap
,
FxHashSet
};
use
rustc_hash
::{
Fx
BuildHasher
,
Fx
HashMap
,
FxHashSet
};
use
swc_core
::
ecma
::
ast
::
Id
;
use
swc_core
::
ecma
::
ast
::
Id
;
use
super
::{
JsValue
,
graph
::
VarGraph
};
use
super
::{
JsValue
,
graph
::
VarGraph
};
use
crate
::
analyzer
::
graph
::
VarMeta
;
use
crate
::
analyzer
::
graph
::
VarMeta
;
pub
async
fn
link
<
'a
,
B
,
RB
,
F
,
RF
>
(
pub
async
fn
link
<
'a
,
B
,
F
,
RF
>
(
graph
:
&
VarGraph
,
graph
:
&
VarGraph
,
mut
val
:
JsValue
,
mut
val
:
JsValue
,
early_visitor
:
&
B
,
early_visitor
:
&
B
,
...
@@ -17,11 +17,17 @@ pub async fn link<'a, B, RB, F, RF>(
...
@@ -17,11 +17,17 @@ pub async fn link<'a, B, RB, F, RF>(
var_cache
:
&
Mutex
<
FxHashMap
<
Id
,
JsValue
>>
,
var_cache
:
&
Mutex
<
FxHashMap
<
Id
,
JsValue
>>
,
)
->
Result
<
(
JsValue
,
u32
)
>
)
->
Result
<
(
JsValue
,
u32
)
>
where
where
RB
:
'a
+
Future
<
Output
=
Result
<
(
JsValue
,
bool
)
>>
+
Send
,
B
:
Fn
(
&
mut
JsValue
)
->
bool
+
Sync
,
B
:
'a
+
Fn
(
JsValue
)
->
RB
+
Sync
,
RF
:
'a
+
Future
<
Output
=
Result
<
(
JsValue
,
bool
)
>>
+
Send
,
RF
:
'a
+
Future
<
Output
=
Result
<
(
JsValue
,
bool
)
>>
+
Send
,
F
:
'a
+
Fn
(
JsValue
)
->
RF
+
Sync
,
F
:
'a
+
Fn
(
JsValue
)
->
RF
+
Sync
,
{
{
// Fast path: values that are already fully resolved and will pass through
// both visitors unchanged. These have no children, no placeholders, and
// the visitor catch-all is a no-op for them.
if
val
.is_inert
()
{
return
Ok
((
val
,
0
));
}
val
.normalize
();
val
.normalize
();
let
(
val
,
steps
)
=
link_internal_iterative
(
let
(
val
,
steps
)
=
link_internal_iterative
(
graph
,
graph
,
...
@@ -75,7 +81,7 @@ impl Display for Step {
...
@@ -75,7 +81,7 @@ impl Display for Step {
}
}
// If a variable was already visited in this linking call, don't visit it again.
// If a variable was already visited in this linking call, don't visit it again.
pub
(
crate
)
async
fn
link_internal_iterative
<
'a
,
B
,
RB
,
F
,
RF
>
(
pub
(
crate
)
async
fn
link_internal_iterative
<
'a
,
B
,
F
,
RF
>
(
graph
:
&
'a
VarGraph
,
graph
:
&
'a
VarGraph
,
val
:
JsValue
,
val
:
JsValue
,
early_visitor
:
&
'a
B
,
early_visitor
:
&
'a
B
,
...
@@ -84,22 +90,21 @@ pub(crate) async fn link_internal_iterative<'a, B, RB, F, RF>(
...
@@ -84,22 +90,21 @@ pub(crate) async fn link_internal_iterative<'a, B, RB, F, RF>(
var_cache
:
&
Mutex
<
FxHashMap
<
Id
,
JsValue
>>
,
var_cache
:
&
Mutex
<
FxHashMap
<
Id
,
JsValue
>>
,
)
->
Result
<
(
JsValue
,
u32
)
>
)
->
Result
<
(
JsValue
,
u32
)
>
where
where
RB
:
'a
+
Future
<
Output
=
Result
<
(
JsValue
,
bool
)
>>
+
Send
,
B
:
Fn
(
&
mut
JsValue
)
->
bool
+
Sync
,
B
:
'a
+
Fn
(
JsValue
)
->
RB
+
Sync
,
RF
:
'a
+
Future
<
Output
=
Result
<
(
JsValue
,
bool
)
>>
+
Send
,
RF
:
'a
+
Future
<
Output
=
Result
<
(
JsValue
,
bool
)
>>
+
Send
,
F
:
'a
+
Fn
(
JsValue
)
->
RF
+
Sync
,
F
:
'a
+
Fn
(
JsValue
)
->
RF
+
Sync
,
{
{
let
initial_capacity
=
(
val
.total_nodes
()
as
usize
)
.min
(
64
);
// Tracks the number of nodes in the queue and done combined
let
mut
total_nodes
=
val
.total_nodes
();
let
initial_capacity
=
(
total_nodes
as
usize
)
.min
(
64
);
let
mut
work_queue_stack
:
Vec
<
Step
>
=
Vec
::
with_capacity
(
initial_capacity
*
2
);
let
mut
work_queue_stack
:
Vec
<
Step
>
=
Vec
::
with_capacity
(
initial_capacity
*
2
);
let
mut
done
:
Vec
<
JsValue
>
=
Vec
::
with_capacity
(
initial_capacity
);
let
mut
done
:
Vec
<
JsValue
>
=
Vec
::
with_capacity
(
initial_capacity
);
// Tracks the number of nodes in the queue and done combined
let
mut
cycle_stack
:
FxHashSet
<
Id
>
=
FxHashSet
::
with_capacity_and_hasher
(
initial_capacity
,
FxBuildHasher
::
default
());
let
mut
total_nodes
=
0
;
let
mut
cycle_stack
:
FxHashSet
<
Id
>
=
FxHashSet
::
default
();
let
mut
fun_args_depth
:
u32
=
0
;
let
mut
fun_args_depth
:
u32
=
0
;
// Tracks the number linking steps so far
// Tracks the number linking steps so far
let
mut
steps
=
0
;
let
mut
steps
=
0
;
total_nodes
+=
val
.total_nodes
();
work_queue_stack
.push
(
Step
::
Enter
(
val
));
work_queue_stack
.push
(
Step
::
Enter
(
val
));
while
let
Some
(
step
)
=
work_queue_stack
.pop
()
{
while
let
Some
(
step
)
=
work_queue_stack
.pop
()
{
...
@@ -269,7 +274,7 @@ where
...
@@ -269,7 +274,7 @@ where
continue
;
continue
;
}
}
let
(
mut
val
,
visit_modified
)
=
early_visitor
(
val
)
.await
?
;
let
visit_modified
=
early_visitor
(
&
mut
val
)
;
val
.debug_assert_total_nodes_up_to_date
();
val
.debug_assert_total_nodes_up_to_date
();
if
visit_modified
&&
val
.total_nodes
()
>
LIMIT_NODE_SIZE
{
if
visit_modified
&&
val
.total_nodes
()
>
LIMIT_NODE_SIZE
{
total_nodes
+=
1
;
total_nodes
+=
1
;
...
...
turbopack/crates/turbopack-ecmascript/src/analyzer/mod.rs
View file @
f68fc84e
...
@@ -1145,6 +1145,16 @@ impl JsValue {
...
@@ -1145,6 +1145,16 @@ impl JsValue {
// Methods regarding node count
// Methods regarding node count
impl
JsValue
{
impl
JsValue
{
/// Returns true if this value is fully resolved and will not be transformed
/// by the linker's visitors. These are leaf values with no placeholders and
/// no operations — the visitors' catch-all paths are no-ops for them.
pub
fn
is_inert
(
&
self
)
->
bool
{
matches!
(
self
,
JsValue
::
Constant
(
_
)
|
JsValue
::
Url
(
_
,
_
)
|
JsValue
::
Unknown
{
..
}
)
}
pub
fn
has_children
(
&
self
)
->
bool
{
pub
fn
has_children
(
&
self
)
->
bool
{
self
.total_nodes
()
>
1
self
.total_nodes
()
>
1
}
}
...
@@ -3804,9 +3814,8 @@ pub mod test_utils {
...
@@ -3804,9 +3814,8 @@ pub mod test_utils {
utils
::
module_value_to_well_known_object
,
utils
::
module_value_to_well_known_object
,
};
};
pub
async
fn
early_visitor
(
mut
v
:
JsValue
)
->
Result
<
(
JsValue
,
bool
)
>
{
pub
fn
early_visitor
(
v
:
&
mut
JsValue
)
->
bool
{
let
m
=
early_replace_builtin
(
&
mut
v
);
early_replace_builtin
(
v
)
Ok
((
v
,
m
))
}
}
/// Visitor that replaces well known functions and objects with their
/// Visitor that replaces well known functions and objects with their
...
...
turbopack/crates/turbopack-ecmascript/src/references/mod.rs
View file @
f68fc84e
...
@@ -490,7 +490,7 @@ impl AnalysisState<'_> {
...
@@ -490,7 +490,7 @@ impl AnalysisState<'_> {
Ok
(
link
(
Ok
(
link
(
self
.var_graph
,
self
.var_graph
,
value
,
value
,
&
early_value_visitor
,
&
|
v
:
&
mut
JsValue
|
early_replace_builtin
(
v
)
,
&
|
value
|
{
&
|
value
|
{
value_visitor
(
value_visitor
(
*
self
.origin
,
*
self
.origin
,
...
@@ -3367,11 +3367,6 @@ fn require_resolve(path: FileSystemPath) -> String {
...
@@ -3367,11 +3367,6 @@ fn require_resolve(path: FileSystemPath) -> String {
format!
(
"/ROOT/{}"
,
path
.path
.as_str
())
format!
(
"/ROOT/{}"
,
path
.path
.as_str
())
}
}
async
fn
early_value_visitor
(
mut
v
:
JsValue
)
->
Result
<
(
JsValue
,
bool
)
>
{
let
modified
=
early_replace_builtin
(
&
mut
v
);
Ok
((
v
,
modified
))
}
async
fn
value_visitor
(
async
fn
value_visitor
(
origin
:
Vc
<
Box
<
dyn
ResolveOrigin
>>
,
origin
:
Vc
<
Box
<
dyn
ResolveOrigin
>>
,
v
:
JsValue
,
v
:
JsValue
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment