Commit fe72e262 authored by Tobias Koppers's avatar Tobias Koppers Committed by Jiachi Liu

Turbopack: remove the streaming hack for improved stability (#85858)

### What?

Remove the hack we use for streaming in turbo-tasks.
We don't use the stream capability and the streaming hack causes some problems.

fixes `Item already exists` error

Closes https://github.com/vercel/next.js/issues/85833
parent b422017d
...@@ -8,7 +8,6 @@ use rustc_hash::FxHashMap; ...@@ -8,7 +8,6 @@ use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{Completion, FxIndexMap, ResolvedVc, Vc}; use turbo_tasks::{Completion, FxIndexMap, ResolvedVc, Vc};
use turbo_tasks_bytes::stream::SingleValue;
use turbo_tasks_env::{CommandLineProcessEnv, ProcessEnv}; use turbo_tasks_env::{CommandLineProcessEnv, ProcessEnv};
use turbo_tasks_fetch::{FetchClientConfig, HttpResponseBody}; use turbo_tasks_fetch::{FetchClientConfig, HttpResponseBody};
use turbo_tasks_fs::{ use turbo_tasks_fs::{
...@@ -768,10 +767,9 @@ async fn get_mock_stylesheet( ...@@ -768,10 +767,9 @@ async fn get_mock_stylesheet(
) )
.await?; .await?;
match &val.try_into_single().await? { match &*val {
SingleValue::Single(val) => { Some(val) => {
let val: FxHashMap<RcStr, Option<RcStr>> = let val: FxHashMap<RcStr, Option<RcStr>> = parse_json_with_source_context(val)?;
parse_json_with_source_context(val.to_str()?)?;
Ok(val Ok(val
.get(&stylesheet_url) .get(&stylesheet_url)
.context("url not found")? .context("url not found")?
......
...@@ -1953,8 +1953,6 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> { ...@@ -1953,8 +1953,6 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
&& !session_dependent && !session_dependent
// Task has no invalidator // Task has no invalidator
&& !task.has_key(&CachedDataItemKey::HasInvalidator {}) && !task.has_key(&CachedDataItemKey::HasInvalidator {})
// This is a hack for the streaming hack.
&& !task.has_key(&CachedDataItemKey::Stateful {})
// Task has no dependencies on collectibles // Task has no dependencies on collectibles
&& count!(task, CollectiblesDependency) == 0 && count!(task, CollectiblesDependency) == 0
{ {
......
...@@ -58,14 +58,11 @@ impl UpdateCellOperation { ...@@ -58,14 +58,11 @@ impl UpdateCellOperation {
let mut task = ctx.task(task_id, TaskDataCategory::All); let mut task = ctx.task(task_id, TaskDataCategory::All);
let is_stateful = task.has_key(&CachedDataItemKey::Stateful {});
// We need to detect recomputation, because here the content has not actually changed (even // We need to detect recomputation, because here the content has not actually changed (even
// if it's not equal to the old content, as not all values implement Eq). We have to // if it's not equal to the old content, as not all values implement Eq). We have to
// assume that tasks are deterministic and pure. // assume that tasks are deterministic and pure.
let assume_unchanged = !ctx.should_track_dependencies() let assume_unchanged =
|| (!task.has_key(&CachedDataItemKey::Dirty {}) !ctx.should_track_dependencies() || !task.has_key(&CachedDataItemKey::Dirty {});
// This is a hack for the streaming hack. Stateful tasks are never recomputed, so this forces invalidation for them in case of this hack.
&& !is_stateful);
let old_content = get!(task, CellData { cell }); let old_content = get!(task, CellData { cell });
......
...@@ -6,7 +6,6 @@ use turbo_tasks::{ ...@@ -6,7 +6,6 @@ use turbo_tasks::{
Completion, Completions, NonLocalValue, ResolvedVc, TaskInput, TryFlatJoinIterExt, Vc, Completion, Completions, NonLocalValue, ResolvedVc, TaskInput, TryFlatJoinIterExt, Vc,
fxindexmap, trace::TraceRawVcs, fxindexmap, trace::TraceRawVcs,
}; };
use turbo_tasks_bytes::stream::SingleValue;
use turbo_tasks_fs::{ use turbo_tasks_fs::{
File, FileContent, FileSystemEntryType, FileSystemPath, json::parse_json_with_source_context, File, FileContent, FileSystemEntryType, FileSystemPath, json::parse_json_with_source_context,
}; };
...@@ -519,7 +518,7 @@ impl PostCssTransformedAsset { ...@@ -519,7 +518,7 @@ impl PostCssTransformedAsset {
}) })
.await?; .await?;
let SingleValue::Single(val) = config_value.try_into_single().await? else { let Some(val) = &*config_value else {
// An error happened, which has already been converted into an issue. // An error happened, which has already been converted into an issue.
return Ok(ProcessPostCssResult { return Ok(ProcessPostCssResult {
content: AssetContent::File(FileContent::NotFound.resolved_cell()).resolved_cell(), content: AssetContent::File(FileContent::NotFound.resolved_cell()).resolved_cell(),
...@@ -527,7 +526,7 @@ impl PostCssTransformedAsset { ...@@ -527,7 +526,7 @@ impl PostCssTransformedAsset {
} }
.cell()); .cell());
}; };
let processed_css: PostCssProcessingResult = parse_json_with_source_context(val.to_str()?) let processed_css: PostCssProcessingResult = parse_json_with_source_context(val)
.context("Unable to deserializate response from PostCSS transform operation")?; .context("Unable to deserializate response from PostCSS transform operation")?;
// TODO handle SourceMap // TODO handle SourceMap
......
...@@ -12,7 +12,6 @@ use turbo_tasks::{ ...@@ -12,7 +12,6 @@ use turbo_tasks::{
Completion, NonLocalValue, OperationValue, OperationVc, ResolvedVc, TaskInput, TryJoinIterExt, Completion, NonLocalValue, OperationValue, OperationVc, ResolvedVc, TaskInput, TryJoinIterExt,
ValueToString, Vc, trace::TraceRawVcs, ValueToString, Vc, trace::TraceRawVcs,
}; };
use turbo_tasks_bytes::stream::SingleValue;
use turbo_tasks_env::ProcessEnv; use turbo_tasks_env::ProcessEnv;
use turbo_tasks_fs::{ use turbo_tasks_fs::{
File, FileContent, FileSystemPath, File, FileContent, FileSystemPath,
...@@ -56,8 +55,7 @@ use crate::{ ...@@ -56,8 +55,7 @@ use crate::{
debug::should_debug, debug::should_debug,
embed_js::embed_file_path, embed_js::embed_file_path,
evaluate::{ evaluate::{
EnvVarTracking, EvaluateContext, EvaluationIssue, JavaScriptEvaluation, EnvVarTracking, EvaluateContext, EvaluationIssue, custom_evaluate, get_evaluate_pool,
JavaScriptStreamSender, compute, custom_evaluate, get_evaluate_pool,
}, },
execution_context::ExecutionContext, execution_context::ExecutionContext,
pool::{FormattingMode, NodeJsPool}, pool::{FormattingMode, NodeJsPool},
...@@ -275,7 +273,7 @@ impl WebpackLoadersProcessedAsset { ...@@ -275,7 +273,7 @@ impl WebpackLoadersProcessedAsset {
}) })
.await?; .await?;
let SingleValue::Single(val) = config_value.try_into_single().await? else { let Some(val) = &*config_value else {
// An error happened, which has already been converted into an issue. // An error happened, which has already been converted into an issue.
return Ok(ProcessWebpackLoadersResult { return Ok(ProcessWebpackLoadersResult {
content: AssetContent::File(FileContent::NotFound.resolved_cell()).resolved_cell(), content: AssetContent::File(FileContent::NotFound.resolved_cell()).resolved_cell(),
...@@ -284,10 +282,8 @@ impl WebpackLoadersProcessedAsset { ...@@ -284,10 +282,8 @@ impl WebpackLoadersProcessedAsset {
} }
.cell()); .cell());
}; };
let processed: WebpackLoadersProcessingResult = parse_json_with_source_context( let processed: WebpackLoadersProcessingResult = parse_json_with_source_context(val)
val.to_str()?, .context("Unable to deserializate response from webpack loaders transform operation")?;
)
.context("Unable to deserializate response from webpack loaders transform operation")?;
// handle SourceMap // handle SourceMap
let source_map = if !transform.source_maps { let source_map = if !transform.source_maps {
...@@ -319,18 +315,10 @@ impl WebpackLoadersProcessedAsset { ...@@ -319,18 +315,10 @@ impl WebpackLoadersProcessedAsset {
#[turbo_tasks::function] #[turbo_tasks::function]
pub(crate) async fn evaluate_webpack_loader( pub(crate) async fn evaluate_webpack_loader(
webpack_loader_context: WebpackLoaderContext, webpack_loader_context: WebpackLoaderContext,
) -> Result<Vc<JavaScriptEvaluation>> { ) -> Result<Vc<Option<RcStr>>> {
custom_evaluate(webpack_loader_context).await custom_evaluate(webpack_loader_context).await
} }
#[turbo_tasks::function]
async fn compute_webpack_loader_evaluation(
webpack_loader_context: WebpackLoaderContext,
sender: Vc<JavaScriptStreamSender>,
) -> Result<Vc<()>> {
compute(webpack_loader_context, sender).await
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
enum LogType { enum LogType {
...@@ -439,12 +427,6 @@ impl EvaluateContext for WebpackLoaderContext { ...@@ -439,12 +427,6 @@ impl EvaluateContext for WebpackLoaderContext {
type ResponseMessage = ResponseMessage; type ResponseMessage = ResponseMessage;
type State = Vec<LogInfo>; type State = Vec<LogInfo>;
async fn compute(self, sender: Vc<JavaScriptStreamSender>) -> Result<()> {
compute_webpack_loader_evaluation(self, sender)
.as_side_effect()
.await
}
fn pool(&self) -> OperationVc<crate::pool::NodeJsPool> { fn pool(&self) -> OperationVc<crate::pool::NodeJsPool> {
get_evaluate_pool( get_evaluate_pool(
self.module_asset, self.module_asset,
......
...@@ -17,7 +17,6 @@ use turbo_tasks::{ ...@@ -17,7 +17,6 @@ use turbo_tasks::{
debug::ValueDebugFormat, fxindexmap, trace::TraceRawVcs, debug::ValueDebugFormat, fxindexmap, trace::TraceRawVcs,
}; };
use turbo_tasks_backend::{BackendOptions, TurboTasksBackend, noop_backing_storage}; use turbo_tasks_backend::{BackendOptions, TurboTasksBackend, noop_backing_storage};
use turbo_tasks_bytes::stream::SingleValue;
use turbo_tasks_env::CommandLineProcessEnv; use turbo_tasks_env::CommandLineProcessEnv;
use turbo_tasks_fs::{ use turbo_tasks_fs::{
DiskFileSystem, FileContent, FileSystem, FileSystemEntryType, FileSystemPath, DiskFileSystem, FileContent, FileSystem, FileSystemEntryType, FileSystemPath,
...@@ -528,12 +527,7 @@ async fn run_test_operation(prepared_test: ResolvedVc<PreparedTest>) -> Result<V ...@@ -528,12 +527,7 @@ async fn run_test_operation(prepared_test: ResolvedVc<PreparedTest>) -> Result<V
) )
.await?; .await?;
let single = res let Some(str) = &*res else {
.try_into_single()
.await
.context("test node result did not emit anything")?;
let SingleValue::Single(bytes) = single else {
return Ok(RunTestResult { return Ok(RunTestResult {
js_result: JsResult { js_result: JsResult {
uncaught_exceptions: vec![], uncaught_exceptions: vec![],
...@@ -549,7 +543,7 @@ async fn run_test_operation(prepared_test: ResolvedVc<PreparedTest>) -> Result<V ...@@ -549,7 +543,7 @@ async fn run_test_operation(prepared_test: ResolvedVc<PreparedTest>) -> Result<V
}; };
Ok(RunTestResult { Ok(RunTestResult {
js_result: JsResult::resolved_cell(parse_json_with_source_context(bytes.to_str()?)?), js_result: JsResult::resolved_cell(parse_json_with_source_context(str)?),
path: path.clone(), path: path.clone(),
} }
.cell()) .cell())
......
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