Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(turbopack): Use ResolvedVc<T> for struct fields in extra crates #73451

Merged
merged 6 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions crates/next-core/src/app_segment_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,26 @@ impl NextSegmentConfig {
/// An issue that occurred while parsing the app segment config.
#[turbo_tasks::value(shared)]
pub struct NextSegmentConfigParsingIssue {
ident: Vc<AssetIdent>,
ident: ResolvedVc<AssetIdent>,
detail: ResolvedVc<StyledString>,
source: Vc<IssueSource>,
source: ResolvedVc<IssueSource>,
}

#[turbo_tasks::value_impl]
impl NextSegmentConfigParsingIssue {
#[turbo_tasks::function]
pub fn new(
ident: ResolvedVc<AssetIdent>,
detail: ResolvedVc<StyledString>,
source: ResolvedVc<IssueSource>,
) -> Vc<Self> {
Self {
ident,
detail,
source,
}
.cell()
}
}

#[turbo_tasks::value_impl]
Expand Down Expand Up @@ -333,13 +350,8 @@ fn parse_config_value(
let detail =
StyledString::Text(format!("{detail} Got {explainer}.{hints}").into()).resolved_cell();

NextSegmentConfigParsingIssue {
ident: source.ident(),
detail,
source: issue_source(source, span),
}
.cell()
.emit();
NextSegmentConfigParsingIssue::new(source.ident(), *detail, issue_source(source, span))
.emit();
};

match &*ident.sym {
Expand Down
57 changes: 30 additions & 27 deletions crates/next-core/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,18 @@ impl ValueDefault for NextSourceConfig {
/// An issue that occurred while parsing the page config.
#[turbo_tasks::value(shared)]
pub struct NextSourceConfigParsingIssue {
ident: Vc<AssetIdent>,
ident: ResolvedVc<AssetIdent>,
detail: ResolvedVc<StyledString>,
}

#[turbo_tasks::value_impl]
impl NextSourceConfigParsingIssue {
#[turbo_tasks::function]
pub fn new(ident: ResolvedVc<AssetIdent>, detail: ResolvedVc<StyledString>) -> Vc<Self> {
Self { ident, detail }.cell()
}
}

#[turbo_tasks::value_impl]
impl Issue for NextSourceConfigParsingIssue {
#[turbo_tasks::function]
Expand Down Expand Up @@ -242,13 +250,11 @@ impl Issue for NextSourceConfigParsingIssue {

fn emit_invalid_config_warning(ident: Vc<AssetIdent>, detail: &str, value: &JsValue) {
let (explainer, hints) = value.explain(2, 0);
NextSourceConfigParsingIssue {
NextSourceConfigParsingIssue::new(
ident,
detail: StyledString::Text(format!("{detail} Got {explainer}.{hints}").into())
.resolved_cell(),
}
.resolved_cell()
.emit()
StyledString::Text(format!("{detail} Got {explainer}.{hints}").into()).cell(),
)
.emit();
}

fn parse_route_matcher_from_js_value(
Expand Down Expand Up @@ -409,17 +415,16 @@ pub async fn parse_config_from_source(
Ok(parse_config_from_js_value(*module, &value).cell())
});
} else {
NextSourceConfigParsingIssue {
ident: module.ident(),
detail: StyledString::Text(
NextSourceConfigParsingIssue::new(
module.ident(),
StyledString::Text(
"The exported config object must contain an variable \
initializer."
.into(),
)
.resolved_cell(),
}
.resolved_cell()
.emit()
.cell(),
)
.emit();
}
}
// Or, check if there is segment runtime option
Expand All @@ -428,15 +433,14 @@ pub async fn parse_config_from_source(
.map(|ident| &*ident.sym == "runtime")
.unwrap_or_default()
{
let runtime_value_issue = NextSourceConfigParsingIssue {
ident: module.ident(),
detail: StyledString::Text(
let runtime_value_issue = NextSourceConfigParsingIssue::new(
module.ident(),
StyledString::Text(
"The runtime property must be either \"nodejs\" or \"edge\"."
.into(),
)
.resolved_cell(),
}
.resolved_cell();
.cell(),
);
if let Some(init) = decl.init.as_ref() {
// skipping eval and directly read the expr's value, as we know it
// should be a const string
Expand All @@ -461,17 +465,16 @@ pub async fn parse_config_from_source(
runtime_value_issue.emit();
}
} else {
NextSourceConfigParsingIssue {
ident: module.ident(),
detail: StyledString::Text(
NextSourceConfigParsingIssue::new(
module.ident(),
StyledString::Text(
"The exported segment runtime option must contain an \
variable initializer."
.into(),
)
.resolved_cell(),
}
.resolved_cell()
.emit()
.cell(),
)
.emit();
}
}
}
Expand Down
27 changes: 25 additions & 2 deletions turbopack/crates/turbopack-core/src/issue/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,34 @@ use crate::ident::AssetIdent;
#[turbo_tasks::value(shared)]
pub struct AnalyzeIssue {
pub severity: ResolvedVc<IssueSeverity>,
pub source_ident: Vc<AssetIdent>,
pub source_ident: ResolvedVc<AssetIdent>,
pub title: ResolvedVc<RcStr>,
pub message: ResolvedVc<StyledString>,
pub code: Option<RcStr>,
pub source: Option<Vc<IssueSource>>,
pub source: Option<ResolvedVc<IssueSource>>,
}

#[turbo_tasks::value_impl]
impl AnalyzeIssue {
#[turbo_tasks::function]
pub fn new(
severity: ResolvedVc<IssueSeverity>,
source_ident: ResolvedVc<AssetIdent>,
title: ResolvedVc<RcStr>,
message: ResolvedVc<StyledString>,
code: Option<RcStr>,
source: Option<ResolvedVc<IssueSource>>,
) -> Vc<Self> {
Self {
severity,
source_ident,
title,
message,
code,
source,
}
.cell()
}
}

#[turbo_tasks::value_impl]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,15 +401,14 @@ pub async fn expand_star_exports(
}

fn emit_star_exports_issue(source_ident: Vc<AssetIdent>, message: RcStr) {
AnalyzeIssue {
code: None,
message: StyledString::Text(message).resolved_cell(),
AnalyzeIssue::new(
IssueSeverity::Warning.cell(),
source_ident,
severity: IssueSeverity::Warning.resolved_cell(),
source: None,
title: ResolvedVc::cell("unexpected export *".into()),
}
.cell()
Vc::cell("unexpected export *".into()),
StyledString::Text(message).cell(),
None,
None,
)
.emit();
}

Expand Down
18 changes: 8 additions & 10 deletions turbopack/crates/turbopack-ecmascript/src/references/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,16 +848,14 @@ pub(crate) async fn analyse_ecmascript_module_internal(
.resolved_cell();
analysis.set_async_module(async_module);
} else if let Some(span) = top_level_await_span {
AnalyzeIssue {
code: None,
message: StyledString::Text("top level await is only supported in ESM modules.".into())
.resolved_cell(),
source_ident: source.ident(),
severity: IssueSeverity::Error.resolved_cell(),
source: Some(issue_source(*source, span)),
title: ResolvedVc::cell("unexpected top level await".into()),
}
.cell()
AnalyzeIssue::new(
IssueSeverity::Error.cell(),
source.ident(),
Vc::cell("unexpected top level await".into()),
StyledString::Text("top level await is only supported in ESM modules.".into()).cell(),
None,
Some(issue_source(*source, span)),
)
.emit();
Comment on lines +851 to 859
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks persistent caching as only resolved cells are allows to be emitted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I revert this PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check if inverting to make it resolved is possible.

}

Expand Down
17 changes: 8 additions & 9 deletions turbopack/crates/turbopack-swc-utils/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use swc_core::common::{
SourceMap,
};
use turbo_rcstr::RcStr;
use turbo_tasks::ResolvedVc;
use turbo_tasks::{ResolvedVc, Vc};
use turbopack_core::{
issue::{analyze::AnalyzeIssue, IssueExt, IssueSeverity, IssueSource, StyledString},
source::Source,
Expand All @@ -17,7 +17,7 @@ pub struct IssueEmitter {
pub source: ResolvedVc<Box<dyn Source>>,
pub source_map: Arc<SourceMap>,
pub title: Option<RcStr>,
pub emitted_issues: Vec<ResolvedVc<AnalyzeIssue>>,
pub emitted_issues: Vec<Vc<AnalyzeIssue>>,
}

impl IssueEmitter {
Expand Down Expand Up @@ -83,15 +83,14 @@ impl Emitter for IssueEmitter {
});
// TODO add other primary and secondary spans with labels as sub_issues

let issue = AnalyzeIssue {
severity,
source_ident: self.source.ident(),
title: ResolvedVc::cell(title),
message: StyledString::Text(message.into()).resolved_cell(),
let issue = AnalyzeIssue::new(
*severity,
self.source.ident(),
Vc::cell(title),
StyledString::Text(message.into()).cell(),
code,
source,
}
.resolved_cell();
);

self.emitted_issues.push(issue);

Expand Down
Loading