Unverified Commit a48eee28 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: pass RcStr to AnalyzeIssue (#99166)

These were only ever `StyledString::Text` anyway. So just store the
RcStr directly

Simplify the code to fix these lint errors
```
➜  next.js-other git:(canary) ✗ pnpm sg scan
error[no-map-async-cell]: Using `.map(async |...| { ...cell() })` causes non-deterministic cell order
    ┌─ turbopack/crates/turbopack-core/src/module_graph/mod.rs:766:33
    │    
722 │ ╭               modules
723 │ │                   .iter()
724 │ │                   .map(async |m| {
    │ │ ╭──────────────────────'
    · │ │
766 │ │ │                                 Vc::cell(rcstr!("Module graph is missing an entry point")),
    │ │ │                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    · │ │
798 │ │ │                 })
    │ ╰─│──────────────────'
    │   ╰─────────────────'
    │    
    = You probably want to first try_join() the async computations before wrapping them in a cell.

error[no-map-async-cell]: Using `.map(async |...| { ...cell() })` causes non-deterministic cell order
    ┌─ turbopack/crates/turbopack-core/src/module_graph/mod.rs:767:33
    │      
722 │   ╭               modules
723 │   │                   .iter()
724 │   │                   .map(async |m| {
    │   │ ╭──────────────────────'
    ·   │ │
767 │ ╭ │ │                                 StyledString::Text(rcstr!(
    · │ │ │
771 │ │ │ │                                 .cell(),
    │ ╰─│─│───────────────────────────────────────^
    ·   │ │
798 │   │ │                 })
    │   ╰─│──────────────────'
    │     ╰─────────────────'
    │      
    = You probably want to first try_join() the async computations before wrapping them in a cell.

Error: 2 error(s) found in code.
Help: Scan succeeded and found error level diagnostics in the codebase.

➜  next.js-other git:(canary) ✗ 
```
parent f5649162
......@@ -11,8 +11,8 @@ use crate::ident::AssetIdent;
pub struct AnalyzeIssue {
pub severity: IssueSeverity,
pub source_ident: ResolvedVc<AssetIdent>,
pub title: ResolvedVc<RcStr>,
pub message: ResolvedVc<StyledString>,
pub title: RcStr,
pub message: RcStr,
pub code: Option<RcStr>,
pub source: Option<IssueSource>,
}
......@@ -23,8 +23,8 @@ impl AnalyzeIssue {
pub fn new(
severity: IssueSeverity,
source_ident: ResolvedVc<AssetIdent>,
title: ResolvedVc<RcStr>,
message: ResolvedVc<StyledString>,
title: RcStr,
message: RcStr,
code: Option<RcStr>,
source: Option<IssueSource>,
) -> Vc<Self> {
......@@ -48,15 +48,14 @@ impl Issue for AnalyzeIssue {
}
async fn title(&self) -> Result<StyledString> {
let title = &*self.title.await?;
Ok(if let Some(code) = self.code.as_ref() {
StyledString::Line(vec![
StyledString::Strong(code.clone()),
StyledString::Text(rcstr!(" ")),
StyledString::Text(title.clone()),
StyledString::Text(self.title.clone()),
])
} else {
StyledString::Text(title.clone())
StyledString::Text(self.title.clone())
})
}
......@@ -69,7 +68,7 @@ impl Issue for AnalyzeIssue {
}
async fn description(&self) -> Result<Option<StyledString>> {
Ok(Some((*self.message.await?).clone()))
Ok(Some(StyledString::Text(self.message.clone())))
}
fn source(&self) -> Option<IssueSource> {
......
......@@ -27,10 +27,7 @@ use turbo_tasks_fs::FileSystemPath;
use crate::{
chunk::{AsyncModuleInfo, ChunkingContext, ChunkingType, TracedMode},
issue::{
ImportTracer, ImportTraces, Issue, IssueExt, IssueSeverity, StyledString,
analyze::AnalyzeIssue,
},
issue::{ImportTracer, ImportTraces, Issue, IssueExt, IssueSeverity, analyze::AnalyzeIssue},
module::Module,
module_graph::{
async_module_info::{AsyncModulesInfo, compute_async_module_info},
......@@ -763,12 +760,11 @@ impl ImportTracer for ModuleGraphImportTracer {
AnalyzeIssue::new(
IssueSeverity::Bug,
module.ident(),
Vc::cell(rcstr!("Module graph is missing an entry point")),
StyledString::Text(rcstr!(
rcstr!("Module graph is missing an entry point"),
rcstr!(
"The module cannot reach any of the explicit entry points in \
its module graph."
))
.cell(),
),
None,
None,
)
......
......@@ -588,12 +588,7 @@ async fn parse_file_content(
if parser_handler.has_errors() {
let messages = if let Some(error) = collector_parse.last_emitted_issue() {
// The emitter created in here only uses StyledString::Text
if let StyledString::Text(xx) = &*error.await?.message.await? {
Some(vec![xx.clone()])
} else {
None
}
Some(vec![error.await?.message.clone()])
} else {
None
};
......
......@@ -18,7 +18,7 @@ use turbo_tasks::{FxIndexMap, NonLocalValue, ResolvedVc, TryFlatJoinIterExt, Vc,
use turbopack_core::{
chunk::{ChunkingContext, ModuleChunkItemIdExt},
ident::AssetIdent,
issue::{IssueExt, IssueSeverity, StyledString, analyze::AnalyzeIssue},
issue::{IssueExt, IssueSeverity, analyze::AnalyzeIssue},
module::{Module, ModuleSideEffects},
module_graph::binding_usage_info::ModuleExportUsageInfo,
reference::ModuleReference,
......@@ -521,8 +521,8 @@ async fn emit_star_exports_issue(source_ident: Vc<AssetIdent>, message: RcStr) -
AnalyzeIssue::new(
IssueSeverity::Warning,
source_ident,
Vc::cell(rcstr!("unexpected export *")),
StyledString::Text(message).cell(),
rcstr!("unexpected export *"),
message,
None,
None,
)
......
......@@ -78,7 +78,7 @@ use turbopack_core::{
InputRelativeConstant,
},
environment::Rendering,
issue::{IssueExt, IssueSeverity, IssueSource, StyledString, analyze::AnalyzeIssue},
issue::{IssueExt, IssueSeverity, IssueSource, analyze::AnalyzeIssue},
module::Module,
reference::{ModuleReference, ModuleReferences},
reference_type::{CommonJsReferenceSubType, InnerAssets},
......@@ -849,9 +849,8 @@ async fn analyze_ecmascript_module_internal(
AnalyzeIssue::new(
IssueSeverity::Error,
source.ident(),
Vc::cell(rcstr!("unexpected top level await")),
StyledString::Text(rcstr!("top level await is only supported in ESM modules."))
.cell(),
rcstr!("unexpected top level await"),
rcstr!("top level await is only supported in ESM modules."),
None,
Some(issue_source(source, span)),
)
......
......@@ -10,7 +10,7 @@ use swc_core::common::{
use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, Vc};
use turbopack_core::{
issue::{IssueExt, IssueSeverity, IssueSource, StyledString, analyze::AnalyzeIssue},
issue::{IssueExt, IssueSeverity, IssueSource, analyze::AnalyzeIssue},
source::Source,
};
......@@ -34,8 +34,8 @@ impl IssueCollector {
issue.severity
},
issue.source.ident(),
Vc::cell(issue.title),
issue.message.cell(),
issue.title,
issue.message,
issue.code,
issue.issue_source,
)
......@@ -52,8 +52,8 @@ impl IssueCollector {
AnalyzeIssue::new(
issue.severity,
issue.source.ident(),
Vc::cell(issue.title.clone()),
issue.message.clone().cell(),
issue.title.clone(),
issue.message.clone(),
issue.code.clone(),
issue.issue_source,
)
......@@ -68,7 +68,7 @@ struct PlainAnalyzeIssue {
severity: IssueSeverity,
source: ResolvedVc<Box<dyn Source>>,
title: RcStr,
message: StyledString,
message: RcStr,
code: Option<RcStr>,
issue_source: Option<IssueSource>,
}
......@@ -162,7 +162,7 @@ impl Emitter for IssueEmitter {
severity,
source: self.source,
title,
message: StyledString::Text(message.into()),
message: message.into(),
code,
issue_source: source,
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment