Skip to content

Commit f770ebb

Browse files
sokrahuozhi
authored andcommitted
Turbopack: Make tasks deterministic (#85524)
### What? Fix Equal implementation on a bunch of structs. Make tasks deterministic
1 parent 58a8a8b commit f770ebb

File tree

6 files changed

+10
-32
lines changed

6 files changed

+10
-32
lines changed

turbopack/crates/turbopack-core/src/changed.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::Result;
22
use turbo_tasks::{
33
Completion, Completions, ResolvedVc, TryJoinIterExt, Vc,
4-
graph::{GraphTraversal, NonDeterministic},
4+
graph::{AdjacencyMap, GraphTraversal, NonDeterministic},
55
};
66

77
use crate::{
@@ -32,13 +32,13 @@ pub async fn get_referenced_modules(
3232
pub async fn any_content_changed_of_module(
3333
root: ResolvedVc<Box<dyn Module>>,
3434
) -> Result<Vc<Completion>> {
35-
let completions = NonDeterministic::new()
35+
let completions = AdjacencyMap::new()
3636
.skip_duplicates()
3737
.visit([root], get_referenced_modules)
3838
.await
3939
.completed()?
4040
.into_inner()
41-
.into_iter()
41+
.into_postorder_topological()
4242
.map(|m| content_changed(*ResolvedVc::upcast(m)))
4343
.map(|v| v.to_resolved())
4444
.try_join()

turbopack/crates/turbopack-css/src/asset.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ impl CssChunkItem for CssModuleChunkItem {
330330
if let FinalCssResult::Ok {
331331
output_code,
332332
source_map,
333-
..
334333
} = &*result
335334
{
336335
Ok(CssChunkItemContent {

turbopack/crates/turbopack-css/src/process.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::sync::{Arc, RwLock};
22

33
use anyhow::{Result, bail};
44
use lightningcss::{
5-
css_modules::{CssModuleExport, CssModuleExports, Pattern, Segment},
5+
css_modules::{CssModuleExport, Pattern, Segment},
66
stylesheet::{MinifyOptions, ParserOptions, PrinterOptions, StyleSheet, ToCssResult},
77
targets::{BrowserslistConfig, Features, Targets},
88
traits::ToCss,
@@ -193,27 +193,18 @@ pub enum CssWithPlaceholderResult {
193193
NotFound,
194194
}
195195

196-
#[turbo_tasks::value(shared, serialization = "none", eq = "manual")]
196+
#[turbo_tasks::value(shared, serialization = "none")]
197197
pub enum FinalCssResult {
198198
Ok {
199199
#[turbo_tasks(trace_ignore)]
200200
output_code: String,
201201

202-
#[turbo_tasks(trace_ignore)]
203-
exports: Option<CssModuleExports>,
204-
205202
source_map: ResolvedVc<OptionStringifiedSourceMap>,
206203
},
207204
Unparsable,
208205
NotFound,
209206
}
210207

211-
impl PartialEq for FinalCssResult {
212-
fn eq(&self, _: &Self) -> bool {
213-
false
214-
}
215-
}
216-
217208
#[turbo_tasks::function]
218209
pub async fn process_css_with_placeholder(
219210
parse_result: ResolvedVc<ParseCssResult>,
@@ -327,7 +318,6 @@ pub async fn finalize_css(
327318

328319
Ok(FinalCssResult::Ok {
329320
output_code: result.code,
330-
exports: result.exports,
331321
source_map: ResolvedVc::cell(srcmap),
332322
}
333323
.cell())

turbopack/crates/turbopack-css/src/references/import.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::{
2121
};
2222

2323
#[turbo_tasks::value(eq = "manual", serialization = "none", shared)]
24+
#[derive(PartialEq)]
2425
pub enum ImportAttributes {
2526
LightningCss {
2627
#[turbo_tasks(trace_ignore)]
@@ -32,11 +33,7 @@ pub enum ImportAttributes {
3233
},
3334
}
3435

35-
impl PartialEq for ImportAttributes {
36-
fn eq(&self, _: &Self) -> bool {
37-
false
38-
}
39-
}
36+
impl Eq for ImportAttributes {}
4037

4138
impl ImportAttributes {
4239
pub fn new_from_lightningcss(prelude: &ImportRule<'static>) -> Self {

turbopack/crates/turbopack-ecmascript/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,8 @@ impl EcmascriptParsable for EcmascriptModuleAsset {
500500
if this.options.await?.keep_last_successful_parse {
501501
let real_result_value = real_result.await?;
502502
let result_value = if matches!(*real_result_value, ParseResult::Ok { .. }) {
503-
this.last_successful_parse.set(real_result_value.clone());
503+
this.last_successful_parse
504+
.set_unconditionally(real_result_value.clone());
504505
real_result_value
505506
} else {
506507
let state_ref = this.last_successful_parse.get();

turbopack/crates/turbopack-ecmascript/src/parse.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use crate::{
5151
transform::{EcmascriptInputTransforms, TransformContext},
5252
};
5353

54-
#[turbo_tasks::value(shared, serialization = "none", eq = "manual")]
54+
#[turbo_tasks::value(shared, serialization = "none", eq = "manual", cell = "new")]
5555
#[allow(clippy::large_enum_variant)]
5656
pub enum ParseResult {
5757
// Note: Ok must not contain any Vc as it's snapshot by failsafe_parse
@@ -73,15 +73,6 @@ pub enum ParseResult {
7373
NotFound,
7474
}
7575

76-
impl PartialEq for ParseResult {
77-
fn eq(&self, other: &Self) -> bool {
78-
match (self, other) {
79-
(Self::Ok { .. }, Self::Ok { .. }) => false,
80-
_ => core::mem::discriminant(self) == core::mem::discriminant(other),
81-
}
82-
}
83-
}
84-
8576
/// `original_source_maps_complete` indicates whether the `original_source_maps` cover the whole
8677
/// map, i.e. whether every module that ended up in `mappings` had an original sourcemap.
8778
#[instrument(level = "info", name = "generate source map", skip_all)]

0 commit comments

Comments
 (0)