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