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
07e10789
Unverified
Commit
07e10789
authored
Jan 13, 2025
by
Benjamin Woodruff
Committed by
GitHub
Jan 13, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(turbopack-ecmascript): Use ResolvedVc in CodeGen type (#74709)
parent
b7d4e14a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
22 deletions
+42
-22
code_gen.rs
turbopack/crates/turbopack-ecmascript/src/code_gen.rs
+23
-4
mod.rs
turbopack/crates/turbopack-ecmascript/src/references/mod.rs
+19
-18
No files found.
turbopack/crates/turbopack-ecmascript/src/code_gen.rs
View file @
07e10789
use
anyhow
::
Result
;
use
serde
::{
Deserialize
,
Serialize
};
use
swc_core
::
ecma
::{
ast
::
Stmt
,
visit
::{
AstParentKind
,
VisitMut
},
};
use
turbo_rcstr
::
RcStr
;
use
turbo_tasks
::{
debug
::
ValueDebugFormat
,
trace
::
TraceRawVcs
,
ResolvedVc
,
Vc
};
use
turbo_tasks
::{
debug
::
ValueDebugFormat
,
trace
::
TraceRawVcs
,
NonLocalValue
,
ResolvedVc
,
Vc
};
use
turbopack_core
::
chunk
::{
AsyncModuleInfo
,
ChunkingContext
};
/// impl of code generation inferred from a ModuleReference.
...
...
@@ -106,13 +107,31 @@ pub trait CodeGenerateableWithAsyncModuleInfo {
)
->
Vc
<
CodeGeneration
>
;
}
#[derive(Clone,
Copy,
PartialEq,
Eq,
Serialize,
Deserialize,
TraceRawVcs,
ValueDebugFormat)]
pub
enum
CodeGen
{
pub
enum
UnresolvedCodeGen
{
CodeGenerateable
(
Vc
<
Box
<
dyn
CodeGenerateable
>>
),
CodeGenerateableWithAsyncModuleInfo
(
Vc
<
Box
<
dyn
CodeGenerateableWithAsyncModuleInfo
>>
),
}
impl
UnresolvedCodeGen
{
pub
async
fn
to_resolved
(
&
self
)
->
Result
<
CodeGen
>
{
Ok
(
match
self
{
Self
::
CodeGenerateable
(
vc
)
=>
CodeGen
::
CodeGenerateable
(
vc
.to_resolved
()
.await
?
),
Self
::
CodeGenerateableWithAsyncModuleInfo
(
vc
)
=>
{
CodeGen
::
CodeGenerateableWithAsyncModuleInfo
(
vc
.to_resolved
()
.await
?
)
}
})
}
}
#[derive(
Clone,
Copy,
PartialEq,
Eq,
Serialize,
Deserialize,
TraceRawVcs,
ValueDebugFormat,
NonLocalValue,
)]
pub
enum
CodeGen
{
CodeGenerateable
(
ResolvedVc
<
Box
<
dyn
CodeGenerateable
>>
),
CodeGenerateableWithAsyncModuleInfo
(
ResolvedVc
<
Box
<
dyn
CodeGenerateableWithAsyncModuleInfo
>>
),
}
#[turbo_tasks
::
value(transparent
,
local
)]
#[turbo_tasks
::
value(transparent)]
pub
struct
CodeGenerateables
(
Vec
<
CodeGen
>
);
pub
fn
path_to
(
...
...
turbopack/crates/turbopack-ecmascript/src/references/mod.rs
View file @
07e10789
...
...
@@ -126,7 +126,9 @@ use crate::{
ConstantNumber
,
ConstantString
,
JsValueUrlKind
,
RequireContextValue
,
},
chunk
::
EcmascriptExports
,
code_gen
::{
CodeGen
,
CodeGenerateable
,
CodeGenerateableWithAsyncModuleInfo
,
CodeGenerateables
},
code_gen
::{
CodeGenerateable
,
CodeGenerateableWithAsyncModuleInfo
,
CodeGenerateables
,
UnresolvedCodeGen
,
},
magic_identifier
,
parse
::
parse
,
references
::{
...
...
@@ -167,7 +169,9 @@ pub struct AnalyzeEcmascriptModuleResultBuilder {
local_references
:
FxIndexSet
<
ResolvedVc
<
Box
<
dyn
ModuleReference
>>>
,
reexport_references
:
FxIndexSet
<
ResolvedVc
<
Box
<
dyn
ModuleReference
>>>
,
evaluation_references
:
FxIndexSet
<
ResolvedVc
<
Box
<
dyn
ModuleReference
>>>
,
code_gens
:
Vec
<
CodeGen
>
,
// Many of these `code_gens` are accumulated inside of a synchronous SWC visitor, so we don't
// resolve them until `build()`.
code_gens
:
Vec
<
UnresolvedCodeGen
>
,
exports
:
EcmascriptExports
,
async_module
:
ResolvedVc
<
OptionAsyncModule
>
,
successful
:
bool
,
...
...
@@ -235,18 +239,18 @@ impl AnalyzeEcmascriptModuleResultBuilder {
C
:
Upcast
<
Box
<
dyn
CodeGenerateable
>>
,
{
self
.code_gens
.push
(
CodeGen
::
CodeGenerateable
(
Vc
::
upcast
(
code_gen
)));
.push
(
Unresolved
CodeGen
::
CodeGenerateable
(
Vc
::
upcast
(
code_gen
)));
}
/// Adds a codegen to the analysis result.
#[allow(dead_code)]
pub
fn
add_code_gen_with_availability_info
<
C
>
(
&
mut
self
,
code_gen
:
Resolved
Vc
<
C
>
)
pub
fn
add_code_gen_with_availability_info
<
C
>
(
&
mut
self
,
code_gen
:
Vc
<
C
>
)
where
C
:
Upcast
<
Box
<
dyn
CodeGenerateableWithAsyncModuleInfo
>>
,
{
self
.code_gens
.push
(
CodeGen
::
CodeGenerateableWithAsyncModuleInfo
(
Resolved
Vc
::
upcast
(
code_gen
),
.push
(
Unresolved
CodeGen
::
CodeGenerateableWithAsyncModuleInfo
(
Vc
::
upcast
(
code_gen
),
));
}
...
...
@@ -274,8 +278,7 @@ impl AnalyzeEcmascriptModuleResultBuilder {
self
.successful
=
successful
;
}
/// Builds the final analysis result. Resolves internal Vcs for performance
/// in using them.
/// Builds the final analysis result. Resolves internal Vcs.
pub
async
fn
build
(
mut
self
,
track_reexport_references
:
bool
,
...
...
@@ -301,14 +304,6 @@ impl AnalyzeEcmascriptModuleResultBuilder {
.into_iter
()
.flatten
()
.collect
();
for
c
in
self
.code_gens
.iter_mut
()
{
match
c
{
CodeGen
::
CodeGenerateable
(
c
)
=>
{
*
c
=
c
.resolve
()
.await
?
;
}
CodeGen
::
CodeGenerateableWithAsyncModuleInfo
(
..
)
=>
{}
}
}
let
source_map
=
if
let
Some
(
source_map
)
=
self
.source_map
{
source_map
...
...
@@ -321,7 +316,13 @@ impl AnalyzeEcmascriptModuleResultBuilder {
local_references
:
ResolvedVc
::
cell
(
local_references
),
reexport_references
:
ResolvedVc
::
cell
(
reexport_references
),
evaluation_references
:
ResolvedVc
::
cell
(
evaluation_references
),
code_generation
:
ResolvedVc
::
cell
(
self
.code_gens
),
code_generation
:
ResolvedVc
::
cell
(
self
.code_gens
.iter
()
.map
(
UnresolvedCodeGen
::
to_resolved
)
.try_join
()
.await
?
,
),
exports
:
self
.exports
.resolved_cell
(),
async_module
:
self
.async_module
,
successful
:
self
.successful
,
...
...
@@ -2976,7 +2977,6 @@ impl VisitAstPath for ModuleReferencesVisitor<'_> {
export
:
&
'ast
NamedExport
,
ast_path
:
&
mut
AstNodePath
<
AstParentNodeRef
<
'r
>>
,
)
{
let
path
=
Vc
::
cell
(
as_parent_path
(
ast_path
));
// We create mutable exports for fake ESMs generated by module splitting
let
is_fake_esm
=
export
.with
...
...
@@ -3032,6 +3032,7 @@ impl VisitAstPath for ModuleReferencesVisitor<'_> {
}
}
let
path
=
Vc
::
cell
(
as_parent_path
(
ast_path
));
self
.analysis
.add_code_gen
(
EsmModuleItem
::
new
(
path
));
export
.visit_children_with_ast_path
(
self
,
ast_path
);
}
...
...
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