Skip to content

Commit

Permalink
SCC stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony committed Jul 12, 2023
1 parent bda50b9 commit e49643d
Show file tree
Hide file tree
Showing 38 changed files with 700 additions and 479 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 61 additions & 6 deletions crates/turbo-tasks-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,74 @@ pub fn derive_task_input(input: TokenStream) -> TokenStream {
/// Creates a ValueVc struct for a `struct` or `enum` that represent
/// that type placed into a cell in a Task.
///
/// That ValueVc object can be `.await?`ed to get a readonly reference
/// to the original value.
/// That ValueVc object can be `await`ed to get a readonly reference
/// to the value contained in the cell.
///
/// `into` argument (`#[turbo_tasks::value(into: xxx)]`)
/// ## Arguments
///
/// Example: `#[turbo_tasks::value(into = "new", eq = "manual")]`
///
/// ### `cell`
///
/// Possible values:
///
/// - "new": Always overrides the value in the cell. Invalidating all
/// dependent tasks.
/// - "shared" (default): Compares with the existing value in the cell, before
/// overriding it. Requires Value to implement [Eq].
///
/// ### `eq`
///
/// Possible values:
///
/// - "manual": Prevents deriving [Eq] so you can do it manually.
///
/// ### `into`
///
/// When provided the ValueVc implement `From<Value>` to allow to convert
/// a Value to a ValueVc by placing it into a cell in a Task.
///
/// `into: new`: Always overrides the value in the cell. Invalidating all
/// dependent tasks.
/// Possible values:
///
/// `into: shared`: Compares with the existing value in the cell, before
/// - "new": Always overrides the value in the cell. Invalidating all
/// dependent tasks.
/// - "shared": Compares with the existing value in the cell, before
/// overriding it. Requires Value to implement [Eq].
/// - "none" (default): Prevents implementing `From<Value>`.
///
/// ### `serialization`
///
/// Affects serialization via [serde::Serialize] and [serde::Deserialize].
///
/// Possible values:
///
/// - "auto" (default): Derives the serialization traits and enabled
/// serialization.
/// - "auto_for_input": Same as "auto", but also adds the marker trait
/// [turbo_tasks::TypedForInput].
/// - "custom": Prevents deriving the serialization traits, but still enables
/// serialization (you need to manually implement [serde::Serialize] and
/// [serde::Deserialize]).
/// - "custom_for_input":Same as "auto", but also adds the marker trait
/// [turbo_tasks::TypedForInput].
/// - "none": Disables serialization and prevents deriving the traits.
///
/// ### `shared`
///
/// Sets both `cell = "shared"` and `into = "shared"`
///
/// No value.
///
/// Example: `#[turbo_tasks::value(shared)]`
///
/// ### `transparent`
///
/// If applied to a unit struct (e.g. `struct Wrapper(Value)`) the outer struct
/// is skipped for all operations (cell, into, reading).
///
/// No value.
///
/// Example: `#[turbo_tasks::value(transparent)]`
///
/// TODO: add more documentation: presets, traits
#[allow_internal_unstable(min_specialization, into_future, trivial_bounds)]
Expand Down
2 changes: 1 addition & 1 deletion crates/turbo-tasks/src/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use internal::PassthroughDebug;
///
/// We don't use `StringVc` directly because we don't want the `Debug`/`Display`
/// representations to be escaped.
#[derive(Clone)]
#[turbo_tasks::value]
#[derive(Clone)]
pub struct ValueDebugString(String);

impl Debug for ValueDebugString {
Expand Down
41 changes: 23 additions & 18 deletions crates/turbo-tasks/src/join_iter_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,47 +124,52 @@ pin_project! {
}
}

impl<T, F> Future for TryFlatJoin<F>
impl<F, I, U> Future for TryFlatJoin<F>
where
F: Future<Output = Result<Option<T>>>,
F: Future<Output = Result<I>>,
I: IntoIterator<IntoIter = U, Item = U::Item>,
U: Iterator,
{
type Output = Result<Vec<T>>;
type Output = Result<Vec<U::Item>>;

fn poll(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> {
match self.project().inner.poll_unpin(cx) {
Poll::Ready(res) => Poll::Ready(
res.into_iter()
.filter_map(|r| match r {
Ok(Some(v)) => Some(Ok(v)),
Ok(None) => None,
Err(e) => Some(Err(e)),
})
.collect::<Result<Vec<_>>>(),
),
Poll::Ready(res) => {
let mut v = Vec::new();
for r in res {
v.extend(r?);
}

Poll::Ready(Ok(v))
}
Poll::Pending => Poll::Pending,
}
}
}

pub trait TryFlatJoinIterExt<T, F>: Iterator
pub trait TryFlatJoinIterExt<F, I, U>: Iterator
where
F: Future<Output = Result<Option<T>>>,
F: Future<Output = Result<I>>,
I: IntoIterator<IntoIter = U, Item = U::Item>,
U: Iterator,
{
/// Returns a future that resolves to a vector of the outputs of the futures
/// in the iterator, or to an error if one of the futures fail.
///
/// It also filters out any `Option::None`s
/// It also flattens the result.
///
/// Unlike `Futures::future::try_join_all`, this returns the Error that
/// occurs first in the list of futures, not the first to fail in time.
fn try_flat_join(self) -> TryFlatJoin<F>;
}

impl<T, F, IF, It> TryFlatJoinIterExt<T, F> for It
impl<F, IF, It, I, U> TryFlatJoinIterExt<F, I, U> for It
where
F: Future<Output = Result<Option<T>>>,
IF: IntoFuture<Output = Result<Option<T>>, IntoFuture = F>,
F: Future<Output = Result<I>>,
IF: IntoFuture<Output = Result<I>, IntoFuture = F>,
It: Iterator<Item = IF>,
I: IntoIterator<IntoIter = U, Item = U::Item>,
U: Iterator,
{
fn try_flat_join(self) -> TryFlatJoin<F> {
TryFlatJoin {
Expand Down
46 changes: 44 additions & 2 deletions crates/turbo-tasks/src/primitives.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::ops::Deref;
use std::{future::IntoFuture, ops::Deref};

use anyhow::Result;
use auto_hash_map::AutoSet;
use futures::TryFutureExt;
use turbo_tasks::debug::ValueDebugFormat;

use crate::{self as turbo_tasks, RawVc, ValueToString, ValueToStringVc};
use crate::{self as turbo_tasks, RawVc, TryJoinIterExt, ValueToString, ValueToStringVc};

#[turbo_tasks::value(transparent)]
pub struct String(std::string::String);
Expand Down Expand Up @@ -51,6 +52,47 @@ impl StringsVc {
#[turbo_tasks::value(transparent)]
pub struct Bool(bool);

#[turbo_tasks::value(transparent)]
pub struct Bools(Vec<bool>);

#[turbo_tasks::value(transparent)]
pub struct BoolVcs(Vec<BoolVc>);

#[turbo_tasks::value_impl]
impl BoolVcsVc {
#[turbo_tasks::function]
pub fn empty() -> Self {
Self::cell(Vec::new())
}

#[turbo_tasks::function]
async fn into_bools(self) -> Result<BoolsVc> {
let this = self.await?;

let bools = this
.iter()
.map(|b| b.into_future().map_ok(|b| *b))
.try_join()
.await?;

Ok(BoolsVc::cell(bools))
}

#[turbo_tasks::function]
pub async fn all(self) -> Result<BoolVc> {
let bools = self.into_bools().await?;

Ok(BoolVc::cell(bools.iter().all(|b| *b)))
}

#[turbo_tasks::function]
pub async fn any(self) -> Result<BoolVc> {
let bools = self.into_bools().await?;

Ok(BoolVc::cell(bools.iter().any(|b| *b)))
}
}

#[turbo_tasks::value(transparent)]
pub struct Usize(usize);

Expand Down
2 changes: 1 addition & 1 deletion crates/turbo-tasks/src/value_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ where

/// Marker trait that a turbo_tasks::value is prepared for
/// serialization as Value<...> input.
/// Either use `#[turbo_tasks::value(serialization: auto_for_input)]`
/// Either use `#[turbo_tasks::value(serialization = "auto_for_input")]`
/// or avoid Value<...> in favor of a real Vc
pub trait TypedForInput: Typed {}

Expand Down
3 changes: 2 additions & 1 deletion crates/turbopack-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ bench = false
bench = false

[[bench]]
name = "mod"
name = "turbopack-cli"
path = "benches/mod.rs"
harness = false

[features]
Expand Down
9 changes: 9 additions & 0 deletions crates/turbopack-core/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ impl AssetsVc {
}
}

#[turbo_tasks::value_impl]
impl AssetsSetVc {
/// Creates an empty set of [Asset]s
#[turbo_tasks::function]
pub fn empty() -> Self {
AssetsSetVc::cell(IndexSet::new())
}
}

/// An asset. It also forms a graph when following [Asset::references].
#[turbo_tasks::value_trait]
pub trait Asset {
Expand Down
2 changes: 1 addition & 1 deletion crates/turbopack-core/src/chunk/available_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl AvailableAssetsVc {
}

#[turbo_tasks::function]
async fn chunkable_assets_set(root: AssetVc) -> Result<AssetsSetVc> {
pub async fn chunkable_assets_set(root: AssetVc) -> Result<AssetsSetVc> {
let assets = AdjacencyMap::new()
.skip_duplicates()
.visit(once(root), |&asset: &AssetVc| async move {
Expand Down
2 changes: 1 addition & 1 deletion crates/turbopack-core/src/issue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ pub struct Issues(Vec<IssueVc>);

/// A list of issues captured with [`IssueVc::peek_issues_with_path`] and
/// [`IssueVc::take_issues_with_path`].
#[derive(Debug)]
#[turbo_tasks::value]
#[derive(Debug)]
pub struct CapturedIssues {
issues: AutoSet<IssueVc>,
#[cfg(feature = "issue_path")]
Expand Down
2 changes: 1 addition & 1 deletion crates/turbopack-ecmascript/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ num-bigint = "0.4"
num-traits = "0.2.15"
once_cell = { workspace = true }
parking_lot = { workspace = true }
petgraph = "0.6.2"
petgraph = { workspace = true }
pin-project-lite = { workspace = true }
regex = { workspace = true }
rustc-hash = { workspace = true }
Expand Down
Loading

0 comments on commit e49643d

Please sign in to comment.