Unverified Commit 299fe740 authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

[turbopack] Remove the implementation of `TaskInput` from `AutoSet` (#84867)

TaskInputs should have deterministic serialization and that isn't really possible with `AutoSet`

This was only used as part of the `CapturedIssues` api, so that is modified to wrap the autoset in a `cell` instead of an `Arc`.  Originally the `Arc` was used to make it possible to call `peek_issues` from top level `run_once` tasks.  So to fix that, I audited callsites and moved one call of `peek_issues` from `handle_issues` into the `IssueReporter`.

As part of the audit, I changed the API of `take_issues` to `drop_issues` since that is the only usecase for this function.
parent d540fbd3
...@@ -38,7 +38,7 @@ async fn entrypoints_without_collectibles_operation( ...@@ -38,7 +38,7 @@ async fn entrypoints_without_collectibles_operation(
) -> Result<Vc<Entrypoints>> { ) -> Result<Vc<Entrypoints>> {
let _ = entrypoints.resolve_strongly_consistent().await?; let _ = entrypoints.resolve_strongly_consistent().await?;
let _ = entrypoints.take_collectibles::<Box<dyn Diagnostic>>(); let _ = entrypoints.take_collectibles::<Box<dyn Diagnostic>>();
let _ = entrypoints.take_issues(); entrypoints.drop_issues();
let _ = get_effects(entrypoints).await?; let _ = get_effects(entrypoints).await?;
Ok(entrypoints.connect()) Ok(entrypoints.connect())
} }
......
...@@ -991,7 +991,7 @@ impl Project { ...@@ -991,7 +991,7 @@ impl Project {
// In development mode, we need to to take and drop the issues, otherwise every // In development mode, we need to to take and drop the issues, otherwise every
// route will report all issues. // route will report all issues.
let vc = module_graphs_op.resolve_strongly_consistent().await?; let vc = module_graphs_op.resolve_strongly_consistent().await?;
let _ = module_graphs_op.take_issues(); module_graphs_op.drop_issues();
*vc *vc
}; };
......
...@@ -19,6 +19,9 @@ use crate::{ ...@@ -19,6 +19,9 @@ use crate::{
/// Trait to implement in order for a type to be accepted as a /// Trait to implement in order for a type to be accepted as a
/// [`#[turbo_tasks::function]`][crate::function] argument. /// [`#[turbo_tasks::function]`][crate::function] argument.
///
/// Serialization must be deterministic and compatible with `eq` comparisons. If two `TaskInputs`
/// compare equal they must also serialize to the same bytes.
pub trait TaskInput: Send + Sync + Clone + Debug + PartialEq + Eq + Hash + TraceRawVcs { pub trait TaskInput: Send + Sync + Clone + Debug + PartialEq + Eq + Hash + TraceRawVcs {
fn resolve_input(&self) -> impl Future<Output = Result<Self>> + Send + '_ { fn resolve_input(&self) -> impl Future<Output = Result<Self>> + Send + '_ {
async { Ok(self.clone()) } async { Ok(self.clone()) }
...@@ -332,19 +335,6 @@ where ...@@ -332,19 +335,6 @@ where
} }
} }
impl<T> TaskInput for auto_hash_map::AutoSet<T>
where
T: TaskInput,
{
fn is_resolved(&self) -> bool {
self.iter().all(TaskInput::is_resolved)
}
fn is_transient(&self) -> bool {
self.iter().any(TaskInput::is_transient)
}
}
macro_rules! tuple_impls { macro_rules! tuple_impls {
( $( $name:ident )+ ) => { ( $( $name:ident )+ ) => {
impl<$($name: TaskInput),+> TaskInput for ($($name,)+) impl<$($name: TaskInput),+> TaskInput for ($($name,)+)
......
...@@ -15,8 +15,8 @@ use turbo_rcstr::RcStr; ...@@ -15,8 +15,8 @@ use turbo_rcstr::RcStr;
use turbo_tasks::{RawVc, TransientInstance, TransientValue, Vc}; use turbo_tasks::{RawVc, TransientInstance, TransientValue, Vc};
use turbo_tasks_fs::{FileLinesContent, source_context::get_source_context}; use turbo_tasks_fs::{FileLinesContent, source_context::get_source_context};
use turbopack_core::issue::{ use turbopack_core::issue::{
CapturedIssues, IssueReporter, IssueSeverity, PlainIssue, PlainIssueSource, PlainTraceItem, CollectibleIssuesExt, IssueReporter, IssueSeverity, PlainIssue, PlainIssueSource,
StyledString, PlainTraceItem, StyledString,
}; };
use crate::source_context::format_source_context_lines; use crate::source_context::format_source_context_lines;
...@@ -357,11 +357,10 @@ impl IssueReporter for ConsoleUi { ...@@ -357,11 +357,10 @@ impl IssueReporter for ConsoleUi {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn report_issues( async fn report_issues(
&self, &self,
issues: TransientInstance<CapturedIssues>,
source: TransientValue<RawVc>, source: TransientValue<RawVc>,
min_failing_severity: IssueSeverity, min_failing_severity: IssueSeverity,
) -> Result<Vc<bool>> { ) -> Result<Vc<bool>> {
let issues = &*issues; let issues = source.peek_issues();
let LogOptions { let LogOptions {
ref current_dir, ref current_dir,
ref project_dir, ref project_dir,
......
...@@ -6,18 +6,16 @@ pub mod resolve; ...@@ -6,18 +6,16 @@ pub mod resolve;
use std::{ use std::{
cmp::min, cmp::min,
fmt::{Display, Formatter}, fmt::{Display, Formatter},
sync::Arc,
}; };
use anyhow::{Result, anyhow}; use anyhow::{Result, anyhow};
use async_trait::async_trait;
use auto_hash_map::AutoSet; use auto_hash_map::AutoSet;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ use turbo_tasks::{
CollectiblesSource, IntoTraitRef, NonLocalValue, OperationVc, RawVc, ReadRef, ResolvedVc, CollectiblesSource, IntoTraitRef, NonLocalValue, OperationVc, RawVc, ReadRef, ResolvedVc,
TaskInput, TransientInstance, TransientValue, TryJoinIterExt, Upcast, ValueDefault, TaskInput, TransientValue, TryJoinIterExt, Upcast, ValueDefault, ValueToString, Vc, emit,
ValueToString, Vc, emit, trace::TraceRawVcs, trace::TraceRawVcs,
}; };
use turbo_tasks_fs::{FileContent, FileLine, FileLinesContent, FileSystem, FileSystemPath}; use turbo_tasks_fs::{FileContent, FileLine, FileLinesContent, FileSystem, FileSystemPath};
use turbo_tasks_hash::{DeterministicHash, Xxh3Hash64Hasher}; use turbo_tasks_hash::{DeterministicHash, Xxh3Hash64Hasher};
...@@ -164,9 +162,8 @@ pub trait ImportTracer { ...@@ -164,9 +162,8 @@ pub trait ImportTracer {
fn get_traces(self: Vc<Self>, path: FileSystemPath) -> Vc<ImportTraces>; fn get_traces(self: Vc<Self>, path: FileSystemPath) -> Vc<ImportTraces>;
} }
#[derive( #[turbo_tasks::value]
Debug, Clone, TaskInput, TraceRawVcs, Hash, Eq, PartialEq, Serialize, Deserialize, NonLocalValue, #[derive(Debug)]
)]
pub struct DelegatingImportTracer { pub struct DelegatingImportTracer {
delegates: AutoSet<ResolvedVc<Box<dyn ImportTracer>>>, delegates: AutoSet<ResolvedVc<Box<dyn ImportTracer>>>,
} }
...@@ -220,7 +217,7 @@ pub struct Issues(Vec<ResolvedVc<Box<dyn Issue>>>); ...@@ -220,7 +217,7 @@ pub struct Issues(Vec<ResolvedVc<Box<dyn Issue>>>);
#[derive(Debug)] #[derive(Debug)]
pub struct CapturedIssues { pub struct CapturedIssues {
issues: AutoSet<ResolvedVc<Box<dyn Issue>>>, issues: AutoSet<ResolvedVc<Box<dyn Issue>>>,
tracer: Arc<DelegatingImportTracer>, tracer: ResolvedVc<DelegatingImportTracer>,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
...@@ -250,14 +247,12 @@ impl CapturedIssues { ...@@ -250,14 +247,12 @@ impl CapturedIssues {
// Returns all the issues as formatted `PlainIssues`. // Returns all the issues as formatted `PlainIssues`.
pub async fn get_plain_issues(&self) -> Result<Vec<ReadRef<PlainIssue>>> { pub async fn get_plain_issues(&self) -> Result<Vec<ReadRef<PlainIssue>>> {
let mut list = let mut list = self
self.issues .issues
.iter() .iter()
.map(|issue| async move { .map(|issue| async move { PlainIssue::from_issue(**issue, Some(*self.tracer)).await })
PlainIssue::from_issue(**issue, Some(self.tracer.clone())).await .try_join()
}) .await?;
.try_join()
.await?;
list.sort(); list.sort();
Ok(list) Ok(list)
} }
...@@ -716,7 +711,7 @@ impl PlainIssue { ...@@ -716,7 +711,7 @@ impl PlainIssue {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn from_issue( pub async fn from_issue(
issue: ResolvedVc<Box<dyn Issue>>, issue: ResolvedVc<Box<dyn Issue>>,
import_tracer: Option<Arc<DelegatingImportTracer>>, import_tracer: Option<ResolvedVc<DelegatingImportTracer>>,
) -> Result<Vc<Self>> { ) -> Result<Vc<Self>> {
let description: Option<StyledString> = match *issue.description().await? { let description: Option<StyledString> = match *issue.description().await? {
Some(description) => Some(description.owned().await?), Some(description) => Some(description.owned().await?),
...@@ -747,8 +742,13 @@ impl PlainIssue { ...@@ -747,8 +742,13 @@ impl PlainIssue {
}, },
import_traces: match import_tracer { import_traces: match import_tracer {
Some(tracer) => { Some(tracer) => {
into_plain_trace(tracer.get_traces(issue.file_path().owned().await?).await?) into_plain_trace(
.await? tracer
.await?
.get_traces(issue.file_path().owned().await?)
.await?,
)
.await?
} }
None => vec![], None => vec![],
}, },
...@@ -796,16 +796,14 @@ pub trait IssueReporter { ...@@ -796,16 +796,14 @@ pub trait IssueReporter {
/// ///
/// # Arguments: /// # Arguments:
/// ///
/// * `issues` - A [ReadRef] of [CapturedIssues]. Typically obtained with
/// `source.peek_issues()`.
/// * `source` - The root [Vc] from which issues are traced. Can be used by implementers to /// * `source` - The root [Vc] from which issues are traced. Can be used by implementers to
/// determine which issues are new. /// determine which issues are new. This must be derived from the OperationVc so issues can
/// be collected.
/// * `min_failing_severity` - The minimum Vc<[IssueSeverity]> /// * `min_failing_severity` - The minimum Vc<[IssueSeverity]>
/// The minimum issue severity level considered to fatally end the program. /// The minimum issue severity level considered to fatally end the program.
#[turbo_tasks::function] #[turbo_tasks::function]
fn report_issues( fn report_issues(
self: Vc<Self>, self: Vc<Self>,
issues: TransientInstance<CapturedIssues>,
source: TransientValue<RawVc>, source: TransientValue<RawVc>,
min_failing_severity: IssueSeverity, min_failing_severity: IssueSeverity,
) -> Vc<bool>; ) -> Vc<bool>;
...@@ -815,18 +813,17 @@ pub trait CollectibleIssuesExt ...@@ -815,18 +813,17 @@ pub trait CollectibleIssuesExt
where where
Self: Sized, Self: Sized,
{ {
/// Returns all issues from `source` in a list with their associated /// Returns all issues from `source`
/// processing path. ///
/// Must be called in a turbo-task as this constructs a `cell`
fn peek_issues(self) -> CapturedIssues; fn peek_issues(self) -> CapturedIssues;
/// Returns all issues from `source` in a list with their associated /// Drops all issues from `source`
/// processing path.
/// ///
/// This unemits the issues. They will not propagate up. /// This unemits the issues. They will not propagate up.
fn take_issues(self) -> CapturedIssues; fn drop_issues(self);
} }
#[async_trait]
impl<T> CollectibleIssuesExt for T impl<T> CollectibleIssuesExt for T
where where
T: CollectiblesSource + Copy + Send, T: CollectiblesSource + Copy + Send,
...@@ -835,23 +832,21 @@ where ...@@ -835,23 +832,21 @@ where
CapturedIssues { CapturedIssues {
issues: self.peek_collectibles(), issues: self.peek_collectibles(),
tracer: Arc::new(DelegatingImportTracer { tracer: DelegatingImportTracer {
delegates: self.peek_collectibles(), delegates: self.peek_collectibles(),
}), }
.resolved_cell(),
} }
} }
fn take_issues(self) -> CapturedIssues { fn drop_issues(self) {
CapturedIssues { let _ = self.take_collectibles::<Box<dyn Issue>>();
issues: self.take_collectibles(),
tracer: Arc::new(DelegatingImportTracer {
delegates: self.take_collectibles(),
}),
}
} }
} }
/// A helper function to print out issues to the console.
///
/// Must be called in a turbo-task as this constructs a `cell`
pub async fn handle_issues<T: Send>( pub async fn handle_issues<T: Send>(
source_op: OperationVc<T>, source_op: OperationVc<T>,
issue_reporter: Vc<Box<dyn IssueReporter>>, issue_reporter: Vc<Box<dyn IssueReporter>>,
...@@ -861,10 +856,8 @@ pub async fn handle_issues<T: Send>( ...@@ -861,10 +856,8 @@ pub async fn handle_issues<T: Send>(
) -> Result<()> { ) -> Result<()> {
let source_vc = source_op.connect(); let source_vc = source_op.connect();
let _ = source_op.resolve_strongly_consistent().await?; let _ = source_op.resolve_strongly_consistent().await?;
let issues = source_op.peek_issues();
let has_fatal = issue_reporter.report_issues( let has_fatal = issue_reporter.report_issues(
TransientInstance::new(issues),
TransientValue::new(Vc::into_raw(source_vc)), TransientValue::new(Vc::into_raw(source_vc)),
min_failing_severity, min_failing_severity,
); );
......
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