Unverified Commit e7fbab4d authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: Make tasks deterministic (#85524)

### What?

Fix Equal implementation on a bunch of structs.
Make tasks deterministic
parent e58657f6
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{ use turbo_tasks::{
Completion, Completions, ResolvedVc, TryJoinIterExt, Vc, Completion, Completions, ResolvedVc, TryJoinIterExt, Vc,
graph::{GraphTraversal, NonDeterministic}, graph::{AdjacencyMap, GraphTraversal, NonDeterministic},
}; };
use crate::{ use crate::{
...@@ -32,13 +32,13 @@ pub async fn get_referenced_modules( ...@@ -32,13 +32,13 @@ pub async fn get_referenced_modules(
pub async fn any_content_changed_of_module( pub async fn any_content_changed_of_module(
root: ResolvedVc<Box<dyn Module>>, root: ResolvedVc<Box<dyn Module>>,
) -> Result<Vc<Completion>> { ) -> Result<Vc<Completion>> {
let completions = NonDeterministic::new() let completions = AdjacencyMap::new()
.skip_duplicates() .skip_duplicates()
.visit([root], get_referenced_modules) .visit([root], get_referenced_modules)
.await .await
.completed()? .completed()?
.into_inner() .into_inner()
.into_iter() .into_postorder_topological()
.map(|m| content_changed(*ResolvedVc::upcast(m))) .map(|m| content_changed(*ResolvedVc::upcast(m)))
.map(|v| v.to_resolved()) .map(|v| v.to_resolved())
.try_join() .try_join()
......
...@@ -330,7 +330,6 @@ impl CssChunkItem for CssModuleChunkItem { ...@@ -330,7 +330,6 @@ impl CssChunkItem for CssModuleChunkItem {
if let FinalCssResult::Ok { if let FinalCssResult::Ok {
output_code, output_code,
source_map, source_map,
..
} = &*result } = &*result
{ {
Ok(CssChunkItemContent { Ok(CssChunkItemContent {
......
...@@ -2,7 +2,7 @@ use std::sync::{Arc, RwLock}; ...@@ -2,7 +2,7 @@ use std::sync::{Arc, RwLock};
use anyhow::{Result, bail}; use anyhow::{Result, bail};
use lightningcss::{ use lightningcss::{
css_modules::{CssModuleExport, CssModuleExports, Pattern, Segment}, css_modules::{CssModuleExport, Pattern, Segment},
stylesheet::{MinifyOptions, ParserOptions, PrinterOptions, StyleSheet, ToCssResult}, stylesheet::{MinifyOptions, ParserOptions, PrinterOptions, StyleSheet, ToCssResult},
targets::{BrowserslistConfig, Features, Targets}, targets::{BrowserslistConfig, Features, Targets},
traits::ToCss, traits::ToCss,
...@@ -193,27 +193,18 @@ pub enum CssWithPlaceholderResult { ...@@ -193,27 +193,18 @@ pub enum CssWithPlaceholderResult {
NotFound, NotFound,
} }
#[turbo_tasks::value(shared, serialization = "none", eq = "manual")] #[turbo_tasks::value(shared, serialization = "none")]
pub enum FinalCssResult { pub enum FinalCssResult {
Ok { Ok {
#[turbo_tasks(trace_ignore)] #[turbo_tasks(trace_ignore)]
output_code: String, output_code: String,
#[turbo_tasks(trace_ignore)]
exports: Option<CssModuleExports>,
source_map: ResolvedVc<OptionStringifiedSourceMap>, source_map: ResolvedVc<OptionStringifiedSourceMap>,
}, },
Unparsable, Unparsable,
NotFound, NotFound,
} }
impl PartialEq for FinalCssResult {
fn eq(&self, _: &Self) -> bool {
false
}
}
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn process_css_with_placeholder( pub async fn process_css_with_placeholder(
parse_result: ResolvedVc<ParseCssResult>, parse_result: ResolvedVc<ParseCssResult>,
...@@ -327,7 +318,6 @@ pub async fn finalize_css( ...@@ -327,7 +318,6 @@ pub async fn finalize_css(
Ok(FinalCssResult::Ok { Ok(FinalCssResult::Ok {
output_code: result.code, output_code: result.code,
exports: result.exports,
source_map: ResolvedVc::cell(srcmap), source_map: ResolvedVc::cell(srcmap),
} }
.cell()) .cell())
......
...@@ -21,6 +21,7 @@ use crate::{ ...@@ -21,6 +21,7 @@ use crate::{
}; };
#[turbo_tasks::value(eq = "manual", serialization = "none", shared)] #[turbo_tasks::value(eq = "manual", serialization = "none", shared)]
#[derive(PartialEq)]
pub enum ImportAttributes { pub enum ImportAttributes {
LightningCss { LightningCss {
#[turbo_tasks(trace_ignore)] #[turbo_tasks(trace_ignore)]
...@@ -32,11 +33,7 @@ pub enum ImportAttributes { ...@@ -32,11 +33,7 @@ pub enum ImportAttributes {
}, },
} }
impl PartialEq for ImportAttributes { impl Eq for ImportAttributes {}
fn eq(&self, _: &Self) -> bool {
false
}
}
impl ImportAttributes { impl ImportAttributes {
pub fn new_from_lightningcss(prelude: &ImportRule<'static>) -> Self { pub fn new_from_lightningcss(prelude: &ImportRule<'static>) -> Self {
......
...@@ -500,7 +500,8 @@ impl EcmascriptParsable for EcmascriptModuleAsset { ...@@ -500,7 +500,8 @@ impl EcmascriptParsable for EcmascriptModuleAsset {
if this.options.await?.keep_last_successful_parse { if this.options.await?.keep_last_successful_parse {
let real_result_value = real_result.await?; let real_result_value = real_result.await?;
let result_value = if matches!(*real_result_value, ParseResult::Ok { .. }) { let result_value = if matches!(*real_result_value, ParseResult::Ok { .. }) {
this.last_successful_parse.set(real_result_value.clone()); this.last_successful_parse
.set_unconditionally(real_result_value.clone());
real_result_value real_result_value
} else { } else {
let state_ref = this.last_successful_parse.get(); let state_ref = this.last_successful_parse.get();
......
...@@ -51,7 +51,7 @@ use crate::{ ...@@ -51,7 +51,7 @@ use crate::{
transform::{EcmascriptInputTransforms, TransformContext}, transform::{EcmascriptInputTransforms, TransformContext},
}; };
#[turbo_tasks::value(shared, serialization = "none", eq = "manual")] #[turbo_tasks::value(shared, serialization = "none", eq = "manual", cell = "new")]
#[allow(clippy::large_enum_variant)] #[allow(clippy::large_enum_variant)]
pub enum ParseResult { pub enum ParseResult {
// Note: Ok must not contain any Vc as it's snapshot by failsafe_parse // Note: Ok must not contain any Vc as it's snapshot by failsafe_parse
...@@ -73,15 +73,6 @@ pub enum ParseResult { ...@@ -73,15 +73,6 @@ pub enum ParseResult {
NotFound, NotFound,
} }
impl PartialEq for ParseResult {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Ok { .. }, Self::Ok { .. }) => false,
_ => core::mem::discriminant(self) == core::mem::discriminant(other),
}
}
}
/// `original_source_maps_complete` indicates whether the `original_source_maps` cover the whole /// `original_source_maps_complete` indicates whether the `original_source_maps` cover the whole
/// map, i.e. whether every module that ended up in `mappings` had an original sourcemap. /// map, i.e. whether every module that ended up in `mappings` had an original sourcemap.
#[instrument(level = "info", name = "generate source map", skip_all)] #[instrument(level = "info", name = "generate source map", skip_all)]
......
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