From 2138fe18ce1c8c820821fa9313d418e0359fd19b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 28 Nov 2024 16:13:07 +0900 Subject: [PATCH 1/2] next-core: `ResolvedVc` --- crates/next-core/src/app_segment_config.rs | 70 ++++++++++++--------- crates/next-core/src/app_structure.rs | 14 +++-- crates/next-core/src/next_font/local/mod.rs | 5 +- 3 files changed, 52 insertions(+), 37 deletions(-) diff --git a/crates/next-core/src/app_segment_config.rs b/crates/next-core/src/app_segment_config.rs index 8d3f8f27be55e..1e81842f65fd8 100644 --- a/crates/next-core/src/app_segment_config.rs +++ b/crates/next-core/src/app_segment_config.rs @@ -166,9 +166,9 @@ impl NextSegmentConfig { /// An issue that occurred while parsing the app segment config. #[turbo_tasks::value(shared)] pub struct NextSegmentConfigParsingIssue { - ident: Vc, + ident: ResolvedVc, detail: ResolvedVc, - source: Vc, + source: ResolvedVc, } #[turbo_tasks::value_impl] @@ -315,49 +315,54 @@ fn issue_source(source: Vc>, span: Span) -> Vc { IssueSource::from_swc_offsets(source, span.lo.to_usize(), span.hi.to_usize()) } -fn parse_config_value( +async fn parse_config_value( source: Vc>, config: &mut NextSegmentConfig, ident: &Ident, init: &Expr, eval_context: &EvalContext, -) { +) -> Result<()> { let span = init.span(); let invalid_config = |detail: &str, value: &JsValue| { let (explainer, hints) = value.explain(2, 0); let detail = StyledString::Text(format!("{detail} Got {explainer}.{hints}").into()).resolved_cell(); - NextSegmentConfigParsingIssue { - ident: source.ident(), - detail, - source: issue_source(source, span), + async move { + NextSegmentConfigParsingIssue { + ident: source.ident().to_resolved().await?, + detail, + source: issue_source(source, span).to_resolved().await?, + } + .cell() + .emit(); + + anyhow::Ok(()) } - .cell() - .emit(); }; match &*ident.sym { "dynamic" => { let value = eval_context.eval(init); let Some(val) = value.as_str() else { - invalid_config("`dynamic` needs to be a static string", &value); - return; + invalid_config("`dynamic` needs to be a static string", &value).await?; + return Ok(()); }; config.dynamic = match serde_json::from_value(Value::String(val.to_string())) { Ok(dynamic) => Some(dynamic), Err(err) => { - invalid_config(&format!("`dynamic` has an invalid value: {}", err), &value); - return; + invalid_config(&format!("`dynamic` has an invalid value: {}", err), &value) + .await?; + return Ok(()); } }; } "dynamicParams" => { let value = eval_context.eval(init); let Some(val) = value.as_bool() else { - invalid_config("`dynamicParams` needs to be a static boolean", &value); - return; + invalid_config("`dynamicParams` needs to be a static boolean", &value).await?; + return Ok(()); }; config.dynamic_params = Some(val); @@ -385,8 +390,8 @@ fn parse_config_value( "fetchCache" => { let value = eval_context.eval(init); let Some(val) = value.as_str() else { - invalid_config("`fetchCache` needs to be a static string", &value); - return; + invalid_config("`fetchCache` needs to be a static string", &value).await?; + return Ok(()); }; config.fetch_cache = match serde_json::from_value(Value::String(val.to_string())) { @@ -395,23 +400,25 @@ fn parse_config_value( invalid_config( &format!("`fetchCache` has an invalid value: {}", err), &value, - ); - return; + ) + .await?; + return Ok(()); } }; } "runtime" => { let value = eval_context.eval(init); let Some(val) = value.as_str() else { - invalid_config("`runtime` needs to be a static string", &value); - return; + invalid_config("`runtime` needs to be a static string", &value).await?; + return Ok(()); }; config.runtime = match serde_json::from_value(Value::String(val.to_string())) { Ok(runtime) => Some(runtime), Err(err) => { - invalid_config(&format!("`runtime` has an invalid value: {}", err), &value); - return; + invalid_config(&format!("`runtime` has an invalid value: {}", err), &value) + .await?; + return Ok(()); } }; } @@ -432,7 +439,9 @@ fn parse_config_value( invalid_config( "Values of the `preferredRegion` array need to static strings", &item, - ); + ) + .await?; + return Ok(()); } } regions @@ -441,8 +450,9 @@ fn parse_config_value( invalid_config( "`preferredRegion` needs to be a static string or array of static strings", &value, - ); - return; + ) + .await?; + return Ok(()); } }; @@ -459,14 +469,16 @@ fn parse_config_value( "experimental_ppr" => { let value = eval_context.eval(init); let Some(val) = value.as_bool() else { - invalid_config("`experimental_ppr` needs to be a static boolean", &value); - return; + invalid_config("`experimental_ppr` needs to be a static boolean", &value).await?; + return Ok(()); }; config.experimental_ppr = Some(val); } _ => {} } + + Ok(()) } #[turbo_tasks::function] diff --git a/crates/next-core/src/app_structure.rs b/crates/next-core/src/app_structure.rs index 0cab3a0586b2a..6fb3a68433bb6 100644 --- a/crates/next-core/src/app_structure.rs +++ b/crates/next-core/src/app_structure.rs @@ -538,14 +538,14 @@ fn match_parallel_route(name: &str) -> Option<&str> { name.strip_prefix('@') } -fn conflict_issue( +async fn conflict_issue( app_dir: Vc, - e: &OccupiedEntry, + e: &'_ OccupiedEntry<'_, AppPath, Entrypoint>, a: &str, b: &str, value_a: &AppPage, value_b: &AppPage, -) { +) -> Result<()> { let item_names = if a == b { format!("{}s", a) } else { @@ -553,7 +553,7 @@ fn conflict_issue( }; DirectoryTreeIssue { - app_dir, + app_dir: app_dir.to_resolved().await?, message: StyledString::Text( format!( "Conflicting {} at {}: {a} at {value_a} and {b} at {value_b}", @@ -567,6 +567,8 @@ fn conflict_issue( } .cell() .emit(); + + Ok(()) } fn add_app_page( @@ -1419,7 +1421,7 @@ pub async fn get_global_metadata( #[turbo_tasks::value(shared)] struct DirectoryTreeIssue { pub severity: ResolvedVc, - pub app_dir: Vc, + pub app_dir: ResolvedVc, pub message: ResolvedVc, } @@ -1442,7 +1444,7 @@ impl Issue for DirectoryTreeIssue { #[turbo_tasks::function] fn file_path(&self) -> Vc { - self.app_dir + *self.app_dir } #[turbo_tasks::function] diff --git a/crates/next-core/src/next_font/local/mod.rs b/crates/next-core/src/next_font/local/mod.rs index 1b28bc4741e93..3221134f348dc 100644 --- a/crates/next-core/src/next_font/local/mod.rs +++ b/crates/next-core/src/next_font/local/mod.rs @@ -109,6 +109,7 @@ impl BeforeResolvePlugin for NextFontLocalResolvePlugin { let font_fallbacks = get_font_fallbacks(lookup_path, options_vc); let properties = get_font_css_properties(options_vc, font_fallbacks).await; + let lookup_path = lookup_path.to_resolved().await?; if let Err(e) = &properties { for source_error in e.chain() { if let Some(FontError::FontFileNotFound(font_path)) = @@ -319,7 +320,7 @@ async fn font_file_options_from_query_map( #[turbo_tasks::value(shared)] struct FontResolvingIssue { font_path: ResolvedVc, - origin_path: Vc, + origin_path: ResolvedVc, } #[turbo_tasks::value_impl] @@ -331,7 +332,7 @@ impl Issue for FontResolvingIssue { #[turbo_tasks::function] fn file_path(&self) -> Vc { - self.origin_path + *self.origin_path } #[turbo_tasks::function] From d221f2409c7fc49a3682275ea3035fadaff22999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Sat, 30 Nov 2024 05:48:18 +0900 Subject: [PATCH 2/2] complex cases --- crates/next-core/src/app_segment_config.rs | 73 ++++++++++------------ crates/next-core/src/app_structure.rs | 13 ++-- 2 files changed, 38 insertions(+), 48 deletions(-) diff --git a/crates/next-core/src/app_segment_config.rs b/crates/next-core/src/app_segment_config.rs index 1e81842f65fd8..46105345e52cf 100644 --- a/crates/next-core/src/app_segment_config.rs +++ b/crates/next-core/src/app_segment_config.rs @@ -166,9 +166,11 @@ impl NextSegmentConfig { /// An issue that occurred while parsing the app segment config. #[turbo_tasks::value(shared)] pub struct NextSegmentConfigParsingIssue { - ident: ResolvedVc, + // no-resolved-vc(kdy1): I'll resolve this later because it's a complex case. + ident: Vc, detail: ResolvedVc, - source: ResolvedVc, + // no-resolved-vc(kdy1): I'll resolve this later because it's a complex case. + source: Vc, } #[turbo_tasks::value_impl] @@ -315,54 +317,49 @@ fn issue_source(source: Vc>, span: Span) -> Vc { IssueSource::from_swc_offsets(source, span.lo.to_usize(), span.hi.to_usize()) } -async fn parse_config_value( +fn parse_config_value( source: Vc>, config: &mut NextSegmentConfig, ident: &Ident, init: &Expr, eval_context: &EvalContext, -) -> Result<()> { +) { let span = init.span(); let invalid_config = |detail: &str, value: &JsValue| { let (explainer, hints) = value.explain(2, 0); let detail = StyledString::Text(format!("{detail} Got {explainer}.{hints}").into()).resolved_cell(); - async move { - NextSegmentConfigParsingIssue { - ident: source.ident().to_resolved().await?, - detail, - source: issue_source(source, span).to_resolved().await?, - } - .cell() - .emit(); - - anyhow::Ok(()) + NextSegmentConfigParsingIssue { + ident: source.ident(), + detail, + source: issue_source(source, span), } + .cell() + .emit(); }; match &*ident.sym { "dynamic" => { let value = eval_context.eval(init); let Some(val) = value.as_str() else { - invalid_config("`dynamic` needs to be a static string", &value).await?; - return Ok(()); + invalid_config("`dynamic` needs to be a static string", &value); + return; }; config.dynamic = match serde_json::from_value(Value::String(val.to_string())) { Ok(dynamic) => Some(dynamic), Err(err) => { - invalid_config(&format!("`dynamic` has an invalid value: {}", err), &value) - .await?; - return Ok(()); + invalid_config(&format!("`dynamic` has an invalid value: {}", err), &value); + return; } }; } "dynamicParams" => { let value = eval_context.eval(init); let Some(val) = value.as_bool() else { - invalid_config("`dynamicParams` needs to be a static boolean", &value).await?; - return Ok(()); + invalid_config("`dynamicParams` needs to be a static boolean", &value); + return; }; config.dynamic_params = Some(val); @@ -390,8 +387,8 @@ async fn parse_config_value( "fetchCache" => { let value = eval_context.eval(init); let Some(val) = value.as_str() else { - invalid_config("`fetchCache` needs to be a static string", &value).await?; - return Ok(()); + invalid_config("`fetchCache` needs to be a static string", &value); + return; }; config.fetch_cache = match serde_json::from_value(Value::String(val.to_string())) { @@ -400,25 +397,23 @@ async fn parse_config_value( invalid_config( &format!("`fetchCache` has an invalid value: {}", err), &value, - ) - .await?; - return Ok(()); + ); + return; } }; } "runtime" => { let value = eval_context.eval(init); let Some(val) = value.as_str() else { - invalid_config("`runtime` needs to be a static string", &value).await?; - return Ok(()); + invalid_config("`runtime` needs to be a static string", &value); + return; }; config.runtime = match serde_json::from_value(Value::String(val.to_string())) { Ok(runtime) => Some(runtime), Err(err) => { - invalid_config(&format!("`runtime` has an invalid value: {}", err), &value) - .await?; - return Ok(()); + invalid_config(&format!("`runtime` has an invalid value: {}", err), &value); + return; } }; } @@ -439,9 +434,8 @@ async fn parse_config_value( invalid_config( "Values of the `preferredRegion` array need to static strings", &item, - ) - .await?; - return Ok(()); + ); + return; } } regions @@ -450,9 +444,8 @@ async fn parse_config_value( invalid_config( "`preferredRegion` needs to be a static string or array of static strings", &value, - ) - .await?; - return Ok(()); + ); + return; } }; @@ -469,16 +462,14 @@ async fn parse_config_value( "experimental_ppr" => { let value = eval_context.eval(init); let Some(val) = value.as_bool() else { - invalid_config("`experimental_ppr` needs to be a static boolean", &value).await?; - return Ok(()); + invalid_config("`experimental_ppr` needs to be a static boolean", &value); + return; }; config.experimental_ppr = Some(val); } _ => {} } - - Ok(()) } #[turbo_tasks::function] diff --git a/crates/next-core/src/app_structure.rs b/crates/next-core/src/app_structure.rs index 6fb3a68433bb6..a51b4864eb751 100644 --- a/crates/next-core/src/app_structure.rs +++ b/crates/next-core/src/app_structure.rs @@ -538,14 +538,14 @@ fn match_parallel_route(name: &str) -> Option<&str> { name.strip_prefix('@') } -async fn conflict_issue( +fn conflict_issue( app_dir: Vc, e: &'_ OccupiedEntry<'_, AppPath, Entrypoint>, a: &str, b: &str, value_a: &AppPage, value_b: &AppPage, -) -> Result<()> { +) { let item_names = if a == b { format!("{}s", a) } else { @@ -553,7 +553,7 @@ async fn conflict_issue( }; DirectoryTreeIssue { - app_dir: app_dir.to_resolved().await?, + app_dir, message: StyledString::Text( format!( "Conflicting {} at {}: {a} at {value_a} and {b} at {value_b}", @@ -567,8 +567,6 @@ async fn conflict_issue( } .cell() .emit(); - - Ok(()) } fn add_app_page( @@ -1421,7 +1419,8 @@ pub async fn get_global_metadata( #[turbo_tasks::value(shared)] struct DirectoryTreeIssue { pub severity: ResolvedVc, - pub app_dir: ResolvedVc, + // no-resolved-vc(kdy1): I'll resolve this later because it's a complex case. + pub app_dir: Vc, pub message: ResolvedVc, } @@ -1444,7 +1443,7 @@ impl Issue for DirectoryTreeIssue { #[turbo_tasks::function] fn file_path(&self) -> Vc { - *self.app_dir + self.app_dir } #[turbo_tasks::function]