Skip to content

Commit a79c41c

Browse files
committed
refactor(turbopack-ecmascript) Use ResolvedVc in EsmExport type
1 parent b405089 commit a79c41c

File tree

7 files changed

+78
-63
lines changed

7 files changed

+78
-63
lines changed

crates/next-core/src/next_dynamic/dynamic_module.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,14 @@ impl ChunkableModule for NextDynamicEntryModule {
9494
impl EcmascriptChunkPlaceable for NextDynamicEntryModule {
9595
#[turbo_tasks::function]
9696
async fn get_exports(&self) -> Result<Vc<EcmascriptExports>> {
97-
let module_reference = Vc::upcast(SingleChunkableModuleReference::new(
98-
Vc::upcast(*self.module),
99-
dynamic_ref_description(),
100-
));
97+
let module_reference = ResolvedVc::upcast(
98+
SingleChunkableModuleReference::new(
99+
Vc::upcast(*self.module),
100+
dynamic_ref_description(),
101+
)
102+
.to_resolved()
103+
.await?,
104+
);
101105

102106
let mut exports = BTreeMap::new();
103107
exports.insert(
@@ -108,7 +112,7 @@ impl EcmascriptChunkPlaceable for NextDynamicEntryModule {
108112
Ok(EcmascriptExports::EsmExports(
109113
EsmExports {
110114
exports,
111-
star_exports: vec![module_reference.to_resolved().await?],
115+
star_exports: vec![module_reference],
112116
}
113117
.resolved_cell(),
114118
)

crates/next-core/src/next_server_component/server_component_module.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,11 @@ impl ChunkableModule for NextServerComponentModule {
114114
impl EcmascriptChunkPlaceable for NextServerComponentModule {
115115
#[turbo_tasks::function]
116116
async fn get_exports(&self) -> Result<Vc<EcmascriptExports>> {
117-
let module_reference = Vc::upcast(NextServerComponentModuleReference::new(Vc::upcast(
118-
*self.module,
119-
)));
117+
let module_reference = ResolvedVc::upcast(
118+
NextServerComponentModuleReference::new(Vc::upcast(*self.module))
119+
.to_resolved()
120+
.await?,
121+
);
120122

121123
let mut exports = BTreeMap::new();
122124
exports.insert(
@@ -127,7 +129,7 @@ impl EcmascriptChunkPlaceable for NextServerComponentModule {
127129
Ok(EcmascriptExports::EsmExports(
128130
EsmExports {
129131
exports,
130-
star_exports: vec![module_reference.to_resolved().await?],
132+
star_exports: vec![module_reference],
131133
}
132134
.resolved_cell(),
133135
)

crates/next-core/src/next_server_utility/server_utility_module.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ impl ChunkableModule for NextServerUtilityModule {
9292
impl EcmascriptChunkPlaceable for NextServerUtilityModule {
9393
#[turbo_tasks::function]
9494
async fn get_exports(&self) -> Result<Vc<EcmascriptExports>> {
95-
let module_reference = Vc::upcast(NextServerUtilityModuleReference::new(Vc::upcast(
96-
*self.module,
97-
)));
95+
let module_reference = ResolvedVc::upcast(
96+
NextServerUtilityModuleReference::new(Vc::upcast(*self.module))
97+
.to_resolved()
98+
.await?,
99+
);
98100

99101
let mut exports = BTreeMap::new();
100102
exports.insert(
@@ -105,7 +107,7 @@ impl EcmascriptChunkPlaceable for NextServerUtilityModule {
105107
Ok(EcmascriptExports::EsmExports(
106108
EsmExports {
107109
exports,
108-
star_exports: vec![module_reference.to_resolved().await?],
110+
star_exports: vec![module_reference],
109111
}
110112
.resolved_cell(),
111113
)

turbopack/crates/turbopack-ecmascript/src/references/esm/export.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::{
3535
magic_identifier,
3636
};
3737

38-
#[derive(Clone, Hash, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs)]
38+
#[derive(Clone, Hash, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)]
3939
pub enum EsmExport {
4040
/// A local binding that is exported (export { a } or export const a = 1)
4141
///
@@ -44,9 +44,9 @@ pub enum EsmExport {
4444
/// An imported binding that is exported (export { a as b } from "...")
4545
///
4646
/// The last bool is true if the binding is a mutable binding
47-
ImportedBinding(Vc<Box<dyn ModuleReference>>, RcStr, bool),
47+
ImportedBinding(ResolvedVc<Box<dyn ModuleReference>>, RcStr, bool),
4848
/// An imported namespace that is exported (export * from "...")
49-
ImportedNamespace(Vc<Box<dyn ModuleReference>>),
49+
ImportedNamespace(ResolvedVc<Box<dyn ModuleReference>>),
5050
/// An error occurred while resolving the export
5151
Error,
5252
}
@@ -427,19 +427,18 @@ async fn emit_star_exports_issue(source_ident: Vc<AssetIdent>, message: RcStr) -
427427
Ok(())
428428
}
429429

430-
#[turbo_tasks::value(shared, local)]
430+
#[turbo_tasks::value(shared)]
431431
#[derive(Hash, Debug)]
432432
pub struct EsmExports {
433433
pub exports: BTreeMap<RcStr, EsmExport>,
434434
pub star_exports: Vec<ResolvedVc<Box<dyn ModuleReference>>>,
435435
}
436436

437-
/// The expanded version of [EsmExports], the `exports` field here includes all
438-
/// exports that could be expanded from `star_exports`.
437+
/// The expanded version of [`EsmExports`], the `exports` field here includes all exports that could
438+
/// be expanded from `star_exports`.
439439
///
440-
/// `star_exports` that could not be (fully) expanded end up in
441-
/// `dynamic_exports`.
442-
#[turbo_tasks::value(shared, local)]
440+
/// [`EsmExports::star_exports`] that could not be (fully) expanded end up in `dynamic_exports`.
441+
#[turbo_tasks::value(shared)]
443442
#[derive(Hash, Debug)]
444443
pub struct ExpandedExports {
445444
pub exports: BTreeMap<RcStr, EsmExport>,
@@ -469,7 +468,11 @@ impl EsmExports {
469468
if !exports.contains_key(export) {
470469
exports.insert(
471470
export.clone(),
472-
EsmExport::ImportedBinding(Vc::upcast(*esm_ref), export.clone(), false),
471+
EsmExport::ImportedBinding(
472+
ResolvedVc::upcast(esm_ref),
473+
export.clone(),
474+
false,
475+
),
473476
);
474477
}
475478
}

turbopack/crates/turbopack-ecmascript/src/references/mod.rs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -653,20 +653,21 @@ pub(crate) async fn analyse_ecmascript_module_internal(
653653
let (webpack_runtime, webpack_entry, webpack_chunks, esm_exports, esm_star_exports) =
654654
set_handler_and_globals(&handler, globals, || {
655655
// TODO migrate to effects
656-
let import_references: Vec<_> = import_references.iter().map(|&rvc| *rvc).collect(); // TODO(ResolvedVc): reinterpret directly
657656
let mut visitor =
658657
ModuleReferencesVisitor::new(eval_context, &import_references, &mut analysis);
659658

660659
for (i, reexport) in eval_context.imports.reexports() {
661660
let import_ref = import_references[i];
662661
match reexport {
663662
Reexport::Star => {
664-
visitor.esm_star_exports.push(Vc::upcast(import_ref));
663+
visitor
664+
.esm_star_exports
665+
.push(ResolvedVc::upcast(import_ref));
665666
}
666667
Reexport::Namespace { exported: n } => {
667668
visitor.esm_exports.insert(
668669
n.as_str().into(),
669-
EsmExport::ImportedNamespace(Vc::upcast(import_ref)),
670+
EsmExport::ImportedNamespace(ResolvedVc::upcast(import_ref)),
670671
);
671672
}
672673
Reexport::Named {
@@ -676,7 +677,7 @@ pub(crate) async fn analyse_ecmascript_module_internal(
676677
visitor.esm_exports.insert(
677678
e.as_str().into(),
678679
EsmExport::ImportedBinding(
679-
Vc::upcast(import_ref),
680+
ResolvedVc::upcast(import_ref),
680681
i.to_string().into(),
681682
false,
682683
),
@@ -700,26 +701,19 @@ pub(crate) async fn analyse_ecmascript_module_internal(
700701
match *export {
701702
EsmExport::LocalBinding(..) => {}
702703
EsmExport::ImportedNamespace(reference) => {
703-
let reference = reference.to_resolved().await?;
704704
analysis.add_reexport_reference(reference);
705705
analysis.add_import_reference(reference);
706706
}
707707
EsmExport::ImportedBinding(reference, ..) => {
708-
let reference = reference.to_resolved().await?;
709708
analysis.add_reexport_reference(reference);
710709
analysis.add_import_reference(reference);
711710
}
712711
EsmExport::Error => {}
713712
}
714713
}
715-
for reference in esm_star_exports
716-
.iter()
717-
.map(|r| r.to_resolved())
718-
.try_join()
719-
.await?
720-
{
721-
analysis.add_reexport_reference(reference);
722-
analysis.add_import_reference(reference);
714+
for reference in &esm_star_exports {
715+
analysis.add_reexport_reference(*reference);
716+
analysis.add_import_reference(*reference);
723717
}
724718

725719
let mut ignore_effect_span = None;
@@ -780,11 +774,7 @@ pub(crate) async fn analyse_ecmascript_module_internal(
780774

781775
let esm_exports = EsmExports {
782776
exports: esm_exports,
783-
star_exports: esm_star_exports
784-
.into_iter()
785-
.map(|v| v.to_resolved())
786-
.try_join()
787-
.await?,
777+
star_exports: esm_star_exports,
788778
}
789779
.cell();
790780

@@ -2880,10 +2870,10 @@ impl StaticAnalyser {
28802870
struct ModuleReferencesVisitor<'a> {
28812871
eval_context: &'a EvalContext,
28822872
old_analyser: StaticAnalyser,
2883-
import_references: &'a [Vc<EsmAssetReference>],
2873+
import_references: &'a [ResolvedVc<EsmAssetReference>],
28842874
analysis: &'a mut AnalyzeEcmascriptModuleResultBuilder,
28852875
esm_exports: BTreeMap<RcStr, EsmExport>,
2886-
esm_star_exports: Vec<Vc<Box<dyn ModuleReference>>>,
2876+
esm_star_exports: Vec<ResolvedVc<Box<dyn ModuleReference>>>,
28872877
webpack_runtime: Option<(RcStr, Span)>,
28882878
webpack_entry: bool,
28892879
webpack_chunks: Vec<Lit>,
@@ -2892,7 +2882,7 @@ struct ModuleReferencesVisitor<'a> {
28922882
impl<'a> ModuleReferencesVisitor<'a> {
28932883
fn new(
28942884
eval_context: &'a EvalContext,
2895-
import_references: &'a [Vc<EsmAssetReference>],
2885+
import_references: &'a [ResolvedVc<EsmAssetReference>],
28962886
analysis: &'a mut AnalyzeEcmascriptModuleResultBuilder,
28972887
) -> Self {
28982888
Self {
@@ -3025,12 +3015,12 @@ impl VisitAstPath for ModuleReferencesVisitor<'_> {
30253015
let esm_ref = self.import_references[index];
30263016
if let Some(export) = export {
30273017
EsmExport::ImportedBinding(
3028-
Vc::upcast(esm_ref),
3018+
ResolvedVc::upcast(esm_ref),
30293019
export,
30303020
is_fake_esm,
30313021
)
30323022
} else {
3033-
EsmExport::ImportedNamespace(Vc::upcast(esm_ref))
3023+
EsmExport::ImportedNamespace(ResolvedVc::upcast(esm_ref))
30343024
}
30353025
} else {
30363026
EsmExport::LocalBinding(binding_name, is_fake_esm)

turbopack/crates/turbopack-ecmascript/src/side_effect_optimization/facade/module.rs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,14 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleFacadeModule {
186186
exports.insert(
187187
name.clone(),
188188
EsmExport::ImportedBinding(
189-
Vc::upcast(EcmascriptModulePartReference::new_part(
190-
*self.module,
191-
ModulePart::locals(),
192-
)),
189+
ResolvedVc::upcast(
190+
EcmascriptModulePartReference::new_part(
191+
*self.module,
192+
ModulePart::locals(),
193+
)
194+
.to_resolved()
195+
.await?,
196+
),
193197
name,
194198
*mutable,
195199
),
@@ -229,10 +233,14 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleFacadeModule {
229233
exports.insert(
230234
"default".into(),
231235
EsmExport::ImportedBinding(
232-
Vc::upcast(EcmascriptModulePartReference::new_part(
233-
*self.module,
234-
ModulePart::exports(),
235-
)),
236+
ResolvedVc::upcast(
237+
EcmascriptModulePartReference::new_part(
238+
*self.module,
239+
ModulePart::exports(),
240+
)
241+
.to_resolved()
242+
.await?,
243+
),
236244
"default".into(),
237245
false,
238246
),
@@ -252,7 +260,11 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleFacadeModule {
252260
exports.insert(
253261
export.await?.clone_value(),
254262
EsmExport::ImportedBinding(
255-
Vc::upcast(EcmascriptModulePartReference::new(*self.module)),
263+
ResolvedVc::upcast(
264+
EcmascriptModulePartReference::new(*self.module)
265+
.to_resolved()
266+
.await?,
267+
),
256268
original_export.clone_value(),
257269
false,
258270
),
@@ -261,9 +273,11 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleFacadeModule {
261273
ModulePart::RenamedNamespace { export } => {
262274
exports.insert(
263275
export.await?.clone_value(),
264-
EsmExport::ImportedNamespace(Vc::upcast(EcmascriptModulePartReference::new(
265-
*self.module,
266-
))),
276+
EsmExport::ImportedNamespace(ResolvedVc::upcast(
277+
EcmascriptModulePartReference::new(*self.module)
278+
.to_resolved()
279+
.await?,
280+
)),
267281
);
268282
}
269283
ModulePart::Evaluation => {
@@ -276,8 +290,8 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleFacadeModule {
276290
exports,
277291
star_exports,
278292
}
279-
.cell();
280-
Ok(EcmascriptExports::EsmExports(exports.to_resolved().await?).cell())
293+
.resolved_cell();
294+
Ok(EcmascriptExports::EsmExports(exports).cell())
281295
}
282296

283297
#[turbo_tasks::function]

turbopack/crates/turbopack-ecmascript/src/side_effect_optimization/locals/module.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleLocalsModule {
9393
exports,
9494
star_exports: vec![],
9595
}
96-
.cell();
97-
Ok(EcmascriptExports::EsmExports(exports.to_resolved().await?).cell())
96+
.resolved_cell();
97+
Ok(EcmascriptExports::EsmExports(exports).cell())
9898
}
9999

100100
#[turbo_tasks::function]

0 commit comments

Comments
 (0)