Skip to content

Commit

Permalink
Remove the sync suffix from methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bgw committed Feb 1, 2025
1 parent f89cc5b commit c38f7a5
Show file tree
Hide file tree
Showing 61 changed files with 125 additions and 166 deletions.
8 changes: 3 additions & 5 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@ impl AppEndpoint {
.edge_rsc_runtime_entries()
.await?
.clone_value();
let evaluatable = ResolvedVc::try_sidecast_sync(app_entry.rsc_entry)
let evaluatable = ResolvedVc::try_sidecast(app_entry.rsc_entry)
.context("Entry module must be evaluatable")?;
evaluatable_assets.push(evaluatable);
evaluatable_assets.push(server_action_manifest_loader);
Expand Down Expand Up @@ -1675,10 +1675,8 @@ impl AppEndpoint {
.server_utils
.iter()
.map(|m| async move {
Ok(
*ResolvedVc::try_downcast_sync::<Box<dyn ChunkableModule>>(*m)
.context("Expected server utils to be chunkable")?,
)
Ok(*ResolvedVc::try_downcast::<Box<dyn ChunkableModule>>(*m)
.context("Expected server utils to be chunkable")?)
})
.try_join()
.await?;
Expand Down
6 changes: 3 additions & 3 deletions crates/next-api/src/client_references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub async fn map_client_references(
let module = node.module;

if let Some(client_reference_module) =
ResolvedVc::try_downcast_type_sync::<EcmascriptClientReferenceModule>(module)
ResolvedVc::try_downcast_type::<EcmascriptClientReferenceModule>(module)
{
Ok(Some((
module,
Expand All @@ -49,7 +49,7 @@ pub async fn map_client_references(
},
)))
} else if let Some(client_reference_module) =
ResolvedVc::try_downcast_type_sync::<CssClientReferenceModule>(module)
ResolvedVc::try_downcast_type::<CssClientReferenceModule>(module)
{
Ok(Some((
module,
Expand All @@ -58,7 +58,7 @@ pub async fn map_client_references(
)),
)))
} else if let Some(server_component) =
ResolvedVc::try_downcast_type_sync::<NextServerComponentModule>(module)
ResolvedVc::try_downcast_type::<NextServerComponentModule>(module)
{
Ok(Some((
module,
Expand Down
4 changes: 2 additions & 2 deletions crates/next-api/src/dynamic_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub async fn map_next_dynamic(graph: Vc<SingleModuleGraph>) -> Result<Vc<Dynamic
.is_some_and(|layer| &**layer == "app-client" || &**layer == "client")
{
if let Some(dynamic_entry_module) =
ResolvedVc::try_downcast_type_sync::<NextDynamicEntryModule>(*module)
ResolvedVc::try_downcast_type::<NextDynamicEntryModule>(*module)
{
return Ok(Some((
*module,
Expand All @@ -143,7 +143,7 @@ pub async fn map_next_dynamic(graph: Vc<SingleModuleGraph>) -> Result<Vc<Dynamic
// TODO add this check once these modules have the correct layer
// if layer.is_some_and(|layer| &**layer == "app-rsc") {
if let Some(client_reference_module) =
ResolvedVc::try_downcast_type_sync::<EcmascriptClientReferenceModule>(*module)
ResolvedVc::try_downcast_type::<EcmascriptClientReferenceModule>(*module)
{
return Ok(Some((
*module,
Expand Down
7 changes: 3 additions & 4 deletions crates/next-api/src/instrumentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,12 @@ impl InstrumentationEndpoint {
.await?
.clone_value();

let Some(module) =
ResolvedVc::try_downcast_sync::<Box<dyn EcmascriptChunkPlaceable>>(module)
let Some(module) = ResolvedVc::try_downcast::<Box<dyn EcmascriptChunkPlaceable>>(module)
else {
bail!("Entry module must be evaluatable");
};

let Some(evaluatable) = ResolvedVc::try_sidecast_sync(module) else {
let Some(evaluatable) = ResolvedVc::try_sidecast(module) else {
bail!("Entry module must be evaluatable");
};
evaluatable_assets.push(evaluatable);
Expand All @@ -155,7 +154,7 @@ impl InstrumentationEndpoint {
let userland_module = self.core_modules().await?.userland_module;
let module_graph = this.project.module_graph(*userland_module);

let Some(module) = ResolvedVc::try_downcast_sync(userland_module) else {
let Some(module) = ResolvedVc::try_downcast(userland_module) else {
bail!("Entry module must be evaluatable");
};

Expand Down
2 changes: 1 addition & 1 deletion crates/next-api/src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ impl PageEndpoint {
let is_edge = matches!(runtime, NextRuntime::Edge);
if is_edge {
let mut evaluatable_assets = edge_runtime_entries.await?.clone_value();
let evaluatable = ResolvedVc::try_sidecast_sync(ssr_module)
let evaluatable = ResolvedVc::try_sidecast(ssr_module)
.context("could not process page loader entry module")?;
evaluatable_assets.push(evaluatable);

Expand Down
2 changes: 1 addition & 1 deletion crates/next-api/src/versioned_content_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl VersionedContentMap {
};

if let Some(generate_source_map) =
ResolvedVc::try_sidecast_sync::<Box<dyn GenerateSourceMap>>(*asset)
ResolvedVc::try_sidecast::<Box<dyn GenerateSourceMap>>(*asset)
{
Ok(if let Some(section) = section {
generate_source_map.by_section(section)
Expand Down
2 changes: 1 addition & 1 deletion crates/next-api/src/webpack_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ where
continue;
};

if let Some(chunk) = ResolvedVc::try_downcast_type_sync::<EcmascriptDevChunk>(*asset) {
if let Some(chunk) = ResolvedVc::try_downcast_type::<EcmascriptDevChunk>(*asset) {
let chunk_ident = normalize_client_path(&chunk.ident().path().await?.path);
chunks.push(WebpackStatsChunk {
size: asset_len,
Expand Down
2 changes: 1 addition & 1 deletion crates/next-core/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub async fn bootstrap(
.to_resolved()
.await?;

let asset = ResolvedVc::try_sidecast_sync::<Box<dyn EvaluatableAsset>>(asset)
let asset = ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(asset)
.context("internal module must be evaluatable")?;

Ok(*asset)
Expand Down
3 changes: 1 addition & 2 deletions crates/next-core/src/next_client/runtime_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ impl RuntimeEntry {

let mut runtime_entries = Vec::with_capacity(modules.len());
for &module in &modules {
if let Some(entry) = ResolvedVc::try_downcast_sync::<Box<dyn EvaluatableAsset>>(module)
{
if let Some(entry) = ResolvedVc::try_downcast::<Box<dyn EvaluatableAsset>>(module) {
runtime_entries.push(entry);
} else {
bail!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Transition for NextCssClientReferenceTransition {
return Ok(ProcessResult::Ignore.cell());
};

let client_module = ResolvedVc::try_sidecast_sync::<Box<dyn CssChunkPlaceable>>(module)
let client_module = ResolvedVc::try_sidecast::<Box<dyn CssChunkPlaceable>>(module)
.context("css client asset is not css chunk placeable")?;

Ok(ProcessResult::Module(ResolvedVc::upcast(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ impl Transition for NextEcmascriptClientReferenceTransition {
};

let Some(client_module) =
ResolvedVc::try_sidecast_sync::<Box<dyn EcmascriptChunkPlaceable>>(client_module)
ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(client_module)
else {
bail!("client asset is not ecmascript chunk placeable");
};

let Some(ssr_module) =
ResolvedVc::try_sidecast_sync::<Box<dyn EcmascriptChunkPlaceable>>(ssr_module)
ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(ssr_module)
else {
bail!("SSR asset is not ecmascript chunk placeable");
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,8 @@ pub async fn client_reference_graph(
.map(|module| async move {
Ok(VisitClientReferenceNode {
state: if let Some(server_component) =
ResolvedVc::try_downcast_type_sync::<NextServerComponentModule>(
module,
) {
ResolvedVc::try_downcast_type::<NextServerComponentModule>(module)
{
VisitClientReferenceNodeState::InServerComponent {
server_component,
}
Expand Down Expand Up @@ -406,7 +405,7 @@ impl Visit<VisitClientReferenceNode> for VisitClientReference {

let referenced_modules = referenced_modules.iter().map(|module| async move {
if let Some(client_reference_module) =
ResolvedVc::try_downcast_type_sync::<EcmascriptClientReferenceModule>(*module)
ResolvedVc::try_downcast_type::<EcmascriptClientReferenceModule>(*module)
{
return Ok(VisitClientReferenceNode {
state: node.state,
Expand All @@ -423,7 +422,7 @@ impl Visit<VisitClientReferenceNode> for VisitClientReference {
}

if let Some(client_reference_module) =
ResolvedVc::try_downcast_type_sync::<CssClientReferenceModule>(*module)
ResolvedVc::try_downcast_type::<CssClientReferenceModule>(*module)
{
return Ok(VisitClientReferenceNode {
state: node.state,
Expand All @@ -440,7 +439,7 @@ impl Visit<VisitClientReferenceNode> for VisitClientReference {
}

if let Some(server_component_asset) =
ResolvedVc::try_downcast_type_sync::<NextServerComponentModule>(*module)
ResolvedVc::try_downcast_type::<NextServerComponentModule>(*module)
{
return Ok(VisitClientReferenceNode {
state: VisitClientReferenceNodeState::InServerComponent {
Expand All @@ -453,8 +452,7 @@ impl Visit<VisitClientReferenceNode> for VisitClientReference {
});
}

if ResolvedVc::try_downcast_type_sync::<NextServerUtilityModule>(*module).is_some()
{
if ResolvedVc::try_downcast_type::<NextServerUtilityModule>(*module).is_some() {
return Ok(VisitClientReferenceNode {
state: VisitClientReferenceNodeState::InServerUtil,
ty: VisitClientReferenceNodeType::ServerUtilEntry(
Expand Down
6 changes: 3 additions & 3 deletions crates/next-core/src/next_dynamic/dynamic_transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ impl Transition for NextDynamicTransition {

Ok(match &*module.try_into_module().await? {
Some(client_module) => {
let Some(client_module) = ResolvedVc::try_sidecast_sync::<
Box<dyn EcmascriptChunkPlaceable>,
>(*client_module) else {
let Some(client_module) =
ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(*client_module)
else {
bail!("not an ecmascript client_module");
};

Expand Down
2 changes: 1 addition & 1 deletion crates/next-core/src/next_dynamic/visit_dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Visit<VisitDynamicNode> for VisitDynamic {

let referenced_modules = referenced_modules.iter().map(|module| async move {
if let Some(next_dynamic_module) =
ResolvedVc::try_downcast_type_sync::<NextDynamicEntryModule>(*module)
ResolvedVc::try_downcast_type::<NextDynamicEntryModule>(*module)
{
return Ok(VisitDynamicNode::Dynamic(
next_dynamic_module,
Expand Down
3 changes: 1 addition & 2 deletions crates/next-core/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,7 @@ async fn parse_route_matcher_from_js_value(
pub async fn parse_config_from_source(
module: ResolvedVc<Box<dyn Module>>,
) -> Result<Vc<NextSourceConfig>> {
if let Some(ecmascript_asset) =
ResolvedVc::try_sidecast_sync::<Box<dyn EcmascriptParsable>>(module)
if let Some(ecmascript_asset) = ResolvedVc::try_sidecast::<Box<dyn EcmascriptParsable>>(module)
{
if let ParseResult::Ok {
program: Program::Module(module_ast),
Expand Down
4 changes: 2 additions & 2 deletions turbopack/crates/turbo-tasks-testing/tests/resolved_vc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ async fn test_sidecast() -> Result<()> {
run(&REGISTRATION, || async {
let concrete_value = ImplementsAandB.resolved_cell();
let as_a = ResolvedVc::upcast::<Box<dyn TraitA>>(concrete_value);
let as_b = ResolvedVc::try_sidecast_sync::<Box<dyn TraitB>>(as_a);
let as_b = ResolvedVc::try_sidecast::<Box<dyn TraitB>>(as_a);
assert!(as_b.is_some());
let as_c = ResolvedVc::try_sidecast_sync::<Box<dyn TraitC>>(as_a);
let as_c = ResolvedVc::try_sidecast::<Box<dyn TraitC>>(as_a);
assert!(as_c.is_none());
Ok(())
})
Expand Down
9 changes: 4 additions & 5 deletions turbopack/crates/turbo-tasks/src/vc/resolved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,13 @@ impl<T> ResolvedVc<T>
where
T: VcValueTrait + ?Sized,
{
///
/// Returns `None` if the underlying value type does not implement `K`.
///
/// **Note:** if the trait `T` is required to implement `K`, use [`ResolvedVc::upcast`] instead.
/// This provides stronger guarantees, removing the need for a [`Result`] return type.
///
/// See also: [`Vc::try_resolve_sidecast`].
pub fn try_sidecast_sync<K>(this: Self) -> Option<ResolvedVc<K>>
pub fn try_sidecast<K>(this: Self) -> Option<ResolvedVc<K>>
where
K: VcValueTrait + ?Sized,
{
Expand All @@ -241,20 +240,20 @@ where
/// Returns `None` if the underlying value type is not a `K`.
///
/// See also: [`Vc::try_resolve_downcast`].
pub fn try_downcast_sync<K>(this: Self) -> Option<ResolvedVc<K>>
pub fn try_downcast<K>(this: Self) -> Option<ResolvedVc<K>>
where
K: Upcast<T> + VcValueTrait + ?Sized,
{
// this is just a more type-safe version of a sidecast
Self::try_sidecast_sync(this)
Self::try_sidecast(this)
}

/// Attempts to downcast the given `Vc<Box<dyn T>>` to a `Vc<K>`, where `K` is a value type.
///
/// Returns `None` if the underlying value type is not a `K`.
///
/// See also: [`Vc::try_resolve_downcast_type`].
pub fn try_downcast_type_sync<K>(this: Self) -> Option<ResolvedVc<K>>
pub fn try_downcast_type<K>(this: Self) -> Option<ResolvedVc<K>>
where
K: Upcast<T> + VcValueType,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl EcmascriptDevEvaluateChunk {
let module_graph = this.module_graph;
move |entry| async move {
if let Some(placeable) =
ResolvedVc::try_sidecast_sync::<Box<dyn EcmascriptChunkPlaceable>>(*entry)
ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(*entry)
{
Ok(Some(
placeable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl EcmascriptDevChunkListContent {

for (chunk_path, chunk_content) in &self.chunks_contents {
if let Some(mergeable) =
ResolvedVc::try_sidecast_sync::<Box<dyn MergeableVersionedContent>>(*chunk_content)
ResolvedVc::try_sidecast::<Box<dyn MergeableVersionedContent>>(*chunk_content)
{
let merger = mergeable.get_merger().resolve().await?;
by_merger.entry(merger).or_default().push(*chunk_content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub(super) async fn update_chunk_list(

for (chunk_path, chunk_content) in &content.chunks_contents {
if let Some(mergeable) =
ResolvedVc::try_sidecast_sync::<Box<dyn MergeableVersionedContent>>(*chunk_content)
ResolvedVc::try_sidecast::<Box<dyn MergeableVersionedContent>>(*chunk_content)
{
let merger = mergeable.get_merger().to_resolved().await?;
by_merger.entry(merger).or_default().push(*chunk_content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl VersionedContentMerger for EcmascriptDevChunkContentMerger {
.iter()
.map(|content| async move {
if let Some(content) =
ResolvedVc::try_downcast_type_sync::<EcmascriptDevChunkContent>(*content)
ResolvedVc::try_downcast_type::<EcmascriptDevChunkContent>(*content)
{
Ok(content)
} else {
Expand Down
3 changes: 1 addition & 2 deletions turbopack/crates/turbopack-cli-utils/src/runtime_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ impl RuntimeEntry {

let mut runtime_entries = Vec::with_capacity(modules.len());
for &module in &modules {
if let Some(entry) = ResolvedVc::try_sidecast_sync::<Box<dyn EvaluatableAsset>>(module)
{
if let Some(entry) = ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(module) {
runtime_entries.push(entry);
} else {
bail!(
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-cli/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ async fn build_internal(
.map(|entry_module| async move {
Ok(
if let Some(ecmascript) =
ResolvedVc::try_sidecast_sync::<Box<dyn EvaluatableAsset>>(entry_module)
ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(entry_module)
{
match target {
Target::Browser => {
Expand Down
6 changes: 3 additions & 3 deletions turbopack/crates/turbopack-cli/src/dev/web_entry_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ pub async fn create_web_entry_source(
.into_iter()
.map(|module| async move {
if let (Some(chunkable_module), Some(entry)) = (
ResolvedVc::try_sidecast_sync::<Box<dyn ChunkableModule>>(module),
ResolvedVc::try_sidecast_sync::<Box<dyn EvaluatableAsset>>(module),
ResolvedVc::try_sidecast::<Box<dyn ChunkableModule>>(module),
ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(module),
) {
Ok(DevHtmlEntry {
chunkable_module,
Expand All @@ -173,7 +173,7 @@ pub async fn create_web_entry_source(
runtime_entries: Some(runtime_entries.with_entry(*entry).to_resolved().await?),
})
} else if let Some(chunkable_module) =
ResolvedVc::try_sidecast_sync::<Box<dyn ChunkableModule>>(module)
ResolvedVc::try_sidecast::<Box<dyn ChunkableModule>>(module)
{
// TODO this is missing runtime code, so it's probably broken and we should also
// add an ecmascript chunk with the runtime code
Expand Down
4 changes: 2 additions & 2 deletions turbopack/crates/turbopack-core/src/chunk/chunk_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ pub async fn chunk_group_content(
}

let Some(chunkable_module) =
ResolvedVc::try_sidecast_sync::<Box<dyn ChunkableModule>>(node.module)
ResolvedVc::try_sidecast::<Box<dyn ChunkableModule>>(node.module)
else {
return Ok(GraphTraversalAction::Skip);
};
Expand All @@ -337,7 +337,7 @@ pub async fn chunk_group_content(
};

let parent_module =
ResolvedVc::try_sidecast_sync::<Box<dyn ChunkableModule>>(parent_node.module)
ResolvedVc::try_sidecast::<Box<dyn ChunkableModule>>(parent_node.module)
.context("Expected parent module to be chunkable")?;

Ok(match edge {
Expand Down
Loading

0 comments on commit c38f7a5

Please sign in to comment.