Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add derive macro for ResolvedValue #8678

Merged
merged 6 commits into from
Jul 9, 2024
Merged

Add derive macro for ResolvedValue #8678

merged 6 commits into from
Jul 9, 2024

Conversation

bgw
Copy link
Member

@bgw bgw commented Jul 5, 2024

Description

This macro allows the user to safely derive ResolvedValue (#8662). Most of the time, this won't be called directly, but instead as part of #[turbo_tasks::value] (not implemented yet).

The macro works by creating a compile-time assertion for each field of a struct, enum, or union, verifying that the type of the field implements ResolvedValue.

The assertions are designed to give relatively readable error messages, and trybuild is used to test that.

Example

An example of this macro expansion looks like this:

// input code
#[derive(ResolvedValue)]
struct LinkedListNode<T>
where
    T: ResolvedValue,
{
    current: T,
    next: Option<Box<LinkedListNode<T>>>,
}
// generated derived impl
unsafe impl<T> ::turbo_tasks::ResolvedValue for LinkedListNode<T> where T: ResolvedValue {}
const _: fn() = || {
    struct DeriveResolvedValueAssertion<T>(T, Option<Box<LinkedListNode<T>>>)
    where
        T: ResolvedValue;
    impl<T> DeriveResolvedValueAssertion<T>
    where
        T: ResolvedValue,
    {
        fn assert_impl_resolved_value<ExpectedResolvedValue: ResolvedValue + ?Sized>() {}
        fn field_types() {
            Self::assert_impl_resolved_value::<T>();
            Self::assert_impl_resolved_value::<Option<Box<LinkedListNode<T>>>>();
        }
    }
};

Why?

https://www.notion.so/vercel/Resolved-Vcs-Vc-Lifetimes-Local-Vcs-and-Vc-Refcounts-49d666d3f9594017b5b312b87ddc5bff

Testing Instructions

cargo nextest r -p turbo-tasks-macros-tests

I ran this multiple times to weed out any non-determinism of the tests (I had some error order non-determinism issues).

If something changes and the stderr snapshots need to be updated, you can pass in TRYBUILD=overwrite:

TRYBUILD=overwrite cargo nextest r -p turbo-tasks-macros-tests

I used rust-analyzer's "expand macro" feature to debug some issues, and to check that the generated code is as compact as reasonably possible (we want to avoid negative impacts on compile times).

Copy link

vercel bot commented Jul 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
examples-nonmonorepo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 9, 2024 7:06pm
rust-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 9, 2024 7:06pm
8 Skipped Deployments
Name Status Preview Comments Updated (UTC)
examples-basic-web ⬜️ Ignored (Inspect) Visit Preview Jul 9, 2024 7:06pm
examples-designsystem-docs ⬜️ Ignored (Inspect) Visit Preview Jul 9, 2024 7:06pm
examples-gatsby-web ⬜️ Ignored (Inspect) Visit Preview Jul 9, 2024 7:06pm
examples-kitchensink-blog ⬜️ Ignored (Inspect) Visit Preview Jul 9, 2024 7:06pm
examples-native-web ⬜️ Ignored (Inspect) Visit Preview Jul 9, 2024 7:06pm
examples-svelte-web ⬜️ Ignored (Inspect) Visit Preview Jul 9, 2024 7:06pm
examples-tailwind-web ⬜️ Ignored (Inspect) Visit Preview Jul 9, 2024 7:06pm
examples-vite-web ⬜️ Ignored (Inspect) Visit Preview Jul 9, 2024 7:06pm

@vercel vercel bot temporarily deployed to Preview – examples-designsystem-docs July 5, 2024 21:45 Inactive
@vercel vercel bot temporarily deployed to Preview – examples-nonmonorepo July 5, 2024 21:45 Inactive
@vercel vercel bot temporarily deployed to Preview – examples-svelte-web July 5, 2024 21:45 Inactive
@vercel vercel bot temporarily deployed to Preview – examples-vite-web July 5, 2024 21:45 Inactive
@vercel vercel bot temporarily deployed to Preview – examples-gatsby-web July 5, 2024 21:45 Inactive
@vercel vercel bot temporarily deployed to Preview – examples-kitchensink-blog July 5, 2024 21:45 Inactive
@vercel vercel bot temporarily deployed to Preview – examples-basic-web July 5, 2024 21:45 Inactive
@vercel vercel bot temporarily deployed to Preview – examples-native-web July 5, 2024 21:45 Inactive
@vercel vercel bot temporarily deployed to Preview – examples-tailwind-web July 5, 2024 21:45 Inactive
Copy link
Member Author

bgw commented Jul 5, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @bgw and the rest of your teammates on Graphite Graphite

@bgw bgw changed the title Add derive macro for ResolvedValue [Draft] Add derive macro for ResolvedValue Jul 5, 2024
Copy link
Contributor

github-actions bot commented Jul 5, 2024

🟢 Turbopack Benchmark CI successful 🟢

Thanks

Copy link
Contributor

github-actions bot commented Jul 9, 2024

✅ This change can build next-swc

@bgw bgw changed the title [Draft] Add derive macro for ResolvedValue Add derive macro for ResolvedValue Jul 9, 2024
Copy link
Contributor

github-actions bot commented Jul 9, 2024

⚠️ CI failed ⚠️

The following steps have failed in CI:

  • Turbopack Rust tests (mac/win, non-blocking)

See workflow summary for details

@bgw bgw marked this pull request as ready for review July 9, 2024 00:39
@bgw bgw requested review from a team as code owners July 9, 2024 00:39
@bgw bgw removed the request for review from a team July 9, 2024 00:39
bgw added 3 commits July 9, 2024 19:03
Error ordering was non-deterministic. One error per file should mitigate
this.
@bgw bgw force-pushed the bgw/derive-resolved-value branch from e08b8c9 to 04de3a9 Compare July 9, 2024 19:03
@bgw bgw merged commit d9cc807 into main Jul 9, 2024
56 of 57 checks passed
@bgw bgw deleted the bgw/derive-resolved-value branch July 9, 2024 19:59
kdy1 added a commit to vercel/next.js that referenced this pull request Jul 12, 2024
# Turbopack
* vercel/turborepo#8686 <!-- Tobias Koppers -
improve performance of the graph aggregation -->
* vercel/turborepo#8694 <!-- Benjamin Woodruff -
Replace `unreachable` with `bail` in `finalize_css` -->
* vercel/turborepo#8661 <!-- Benjamin Woodruff -
Create a minimum viable `ResolvedVc` type -->
* vercel/turborepo#8662 <!-- Benjamin Woodruff - Add
a minimum viable ResolvedValue marker trait -->
* vercel/turborepo#8678 <!-- Benjamin Woodruff - Add
derive macro for ResolvedValue -->
* vercel/turborepo#8715 <!-- Benjamin Woodruff -
Switch RcStr from std::sync::Arc to triomphe::Arc -->
* vercel/turborepo#8699 <!-- Donny/강동윤 - perf: Merge
multiple `EsmBinding` -->
* vercel/turborepo#8720 <!-- Benjamin Woodruff - Add
support for `#[turbo_tasks::value(resolved)]` and
`#[turbo_tasks::value_trait(resolved)]` -->
* vercel/turborepo#8706 <!-- Donny/강동윤 - build:
Update `swc_core` to `v0.96.9` -->

### What?

Update SWC crates to
swc-project/swc@226617e
and
swc-project/plugins@b7658c3

### Why?

To keep in sync

### How?

 - Closes #64890
 - Closes #63104
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 25, 2024
### Description

We want a way to more strongly guarantee that a `Vc` is resolved for the sake of "local" tasks.

This introduces it in a low-risk way with zero breaking changes. Eventually, we'd want to eliminate `.resolve()` or make `.resolve()` return `ResolvedVc` instead of using a separate `.to_resolved()` method.

Some rough notes about why here: https://www.notion.so/vercel/Resolved-Vcs-Vc-Lifetimes-Local-Vcs-and-Vc-Refcounts-49d666d3f9594017b5b312b87ddc5bff

### Testing Instructions

Tested as a part of vercel/turborepo#8678
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 25, 2024
## Description

This trait will provide a best-effort indication that a type is safe to return from a local task function.

This PR also makes some improvements to the `TraceRawVcs` impls that I noticed as opportunities while working on `ResolvedValue`.

## Why?

https://www.notion.so/vercel/Resolved-Vcs-Vc-Lifetimes-Local-Vcs-and-Vc-Refcounts-49d666d3f9594017b5b312b87ddc5bff

## Testing Instructions

Tested as part of vercel/turborepo#8678
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 25, 2024
## Description

This macro allows the user to safely derive `ResolvedValue` (vercel/turborepo#8662). Most of the time, this won't be called directly, but instead as part of `#[turbo_tasks::value]` (not implemented yet).

The macro works by creating a compile-time assertion for each field of a struct, enum, or union, verifying that the type of the field implements `ResolvedValue`.

The assertions are designed to give relatively readable error messages, and [`trybuild`](https://github.com/dtolnay/trybuild) is used to test that.

## Example

An example of this macro expansion looks like this:

```
// input code
#[derive(ResolvedValue)]
struct LinkedListNode<T>
where
    T: ResolvedValue,
{
    current: T,
    next: Option<Box<LinkedListNode<T>>>,
}
```

```
// generated derived impl
unsafe impl<T> ::turbo_tasks::ResolvedValue for LinkedListNode<T> where T: ResolvedValue {}
const _: fn() = || {
    struct DeriveResolvedValueAssertion<T>(T, Option<Box<LinkedListNode<T>>>)
    where
        T: ResolvedValue;
    impl<T> DeriveResolvedValueAssertion<T>
    where
        T: ResolvedValue,
    {
        fn assert_impl_resolved_value<ExpectedResolvedValue: ResolvedValue + ?Sized>() {}
        fn field_types() {
            Self::assert_impl_resolved_value::<T>();
            Self::assert_impl_resolved_value::<Option<Box<LinkedListNode<T>>>>();
        }
    }
};
```

## Why?

https://www.notion.so/vercel/Resolved-Vcs-Vc-Lifetimes-Local-Vcs-and-Vc-Refcounts-49d666d3f9594017b5b312b87ddc5bff

## Testing Instructions

```
cargo nextest r -p turbo-tasks-macros-tests
```

I ran this multiple times to weed out any non-determinism of the tests (I had some error order non-determinism issues).

If something changes and the stderr snapshots need to be updated, you can pass in `TRYBUILD=overwrite`:

```
TRYBUILD=overwrite cargo nextest r -p turbo-tasks-macros-tests
```

I used [rust-analyzer's "expand macro" feature](https://rust-analyzer.github.io/manual.html#expand-macro-recursively) to debug some issues, and to check that the generated code is as compact as reasonably possible (we want to avoid negative impacts on compile times).
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 29, 2024
### Description

We want a way to more strongly guarantee that a `Vc` is resolved for the sake of "local" tasks.

This introduces it in a low-risk way with zero breaking changes. Eventually, we'd want to eliminate `.resolve()` or make `.resolve()` return `ResolvedVc` instead of using a separate `.to_resolved()` method.

Some rough notes about why here: https://www.notion.so/vercel/Resolved-Vcs-Vc-Lifetimes-Local-Vcs-and-Vc-Refcounts-49d666d3f9594017b5b312b87ddc5bff

### Testing Instructions

Tested as a part of vercel/turborepo#8678
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 29, 2024
## Description

This trait will provide a best-effort indication that a type is safe to return from a local task function.

This PR also makes some improvements to the `TraceRawVcs` impls that I noticed as opportunities while working on `ResolvedValue`.

## Why?

https://www.notion.so/vercel/Resolved-Vcs-Vc-Lifetimes-Local-Vcs-and-Vc-Refcounts-49d666d3f9594017b5b312b87ddc5bff

## Testing Instructions

Tested as part of vercel/turborepo#8678
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 29, 2024
## Description

This macro allows the user to safely derive `ResolvedValue` (vercel/turborepo#8662). Most of the time, this won't be called directly, but instead as part of `#[turbo_tasks::value]` (not implemented yet).

The macro works by creating a compile-time assertion for each field of a struct, enum, or union, verifying that the type of the field implements `ResolvedValue`.

The assertions are designed to give relatively readable error messages, and [`trybuild`](https://github.com/dtolnay/trybuild) is used to test that.

## Example

An example of this macro expansion looks like this:

```
// input code
#[derive(ResolvedValue)]
struct LinkedListNode<T>
where
    T: ResolvedValue,
{
    current: T,
    next: Option<Box<LinkedListNode<T>>>,
}
```

```
// generated derived impl
unsafe impl<T> ::turbo_tasks::ResolvedValue for LinkedListNode<T> where T: ResolvedValue {}
const _: fn() = || {
    struct DeriveResolvedValueAssertion<T>(T, Option<Box<LinkedListNode<T>>>)
    where
        T: ResolvedValue;
    impl<T> DeriveResolvedValueAssertion<T>
    where
        T: ResolvedValue,
    {
        fn assert_impl_resolved_value<ExpectedResolvedValue: ResolvedValue + ?Sized>() {}
        fn field_types() {
            Self::assert_impl_resolved_value::<T>();
            Self::assert_impl_resolved_value::<Option<Box<LinkedListNode<T>>>>();
        }
    }
};
```

## Why?

https://www.notion.so/vercel/Resolved-Vcs-Vc-Lifetimes-Local-Vcs-and-Vc-Refcounts-49d666d3f9594017b5b312b87ddc5bff

## Testing Instructions

```
cargo nextest r -p turbo-tasks-macros-tests
```

I ran this multiple times to weed out any non-determinism of the tests (I had some error order non-determinism issues).

If something changes and the stderr snapshots need to be updated, you can pass in `TRYBUILD=overwrite`:

```
TRYBUILD=overwrite cargo nextest r -p turbo-tasks-macros-tests
```

I used [rust-analyzer's "expand macro" feature](https://rust-analyzer.github.io/manual.html#expand-macro-recursively) to debug some issues, and to check that the generated code is as compact as reasonably possible (we want to avoid negative impacts on compile times).
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 29, 2024
### Description

We want a way to more strongly guarantee that a `Vc` is resolved for the sake of "local" tasks.

This introduces it in a low-risk way with zero breaking changes. Eventually, we'd want to eliminate `.resolve()` or make `.resolve()` return `ResolvedVc` instead of using a separate `.to_resolved()` method.

Some rough notes about why here: https://www.notion.so/vercel/Resolved-Vcs-Vc-Lifetimes-Local-Vcs-and-Vc-Refcounts-49d666d3f9594017b5b312b87ddc5bff

### Testing Instructions

Tested as a part of vercel/turborepo#8678
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 29, 2024
## Description

This trait will provide a best-effort indication that a type is safe to return from a local task function.

This PR also makes some improvements to the `TraceRawVcs` impls that I noticed as opportunities while working on `ResolvedValue`.

## Why?

https://www.notion.so/vercel/Resolved-Vcs-Vc-Lifetimes-Local-Vcs-and-Vc-Refcounts-49d666d3f9594017b5b312b87ddc5bff

## Testing Instructions

Tested as part of vercel/turborepo#8678
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 29, 2024
## Description

This macro allows the user to safely derive `ResolvedValue` (vercel/turborepo#8662). Most of the time, this won't be called directly, but instead as part of `#[turbo_tasks::value]` (not implemented yet).

The macro works by creating a compile-time assertion for each field of a struct, enum, or union, verifying that the type of the field implements `ResolvedValue`.

The assertions are designed to give relatively readable error messages, and [`trybuild`](https://github.com/dtolnay/trybuild) is used to test that.

## Example

An example of this macro expansion looks like this:

```
// input code
#[derive(ResolvedValue)]
struct LinkedListNode<T>
where
    T: ResolvedValue,
{
    current: T,
    next: Option<Box<LinkedListNode<T>>>,
}
```

```
// generated derived impl
unsafe impl<T> ::turbo_tasks::ResolvedValue for LinkedListNode<T> where T: ResolvedValue {}
const _: fn() = || {
    struct DeriveResolvedValueAssertion<T>(T, Option<Box<LinkedListNode<T>>>)
    where
        T: ResolvedValue;
    impl<T> DeriveResolvedValueAssertion<T>
    where
        T: ResolvedValue,
    {
        fn assert_impl_resolved_value<ExpectedResolvedValue: ResolvedValue + ?Sized>() {}
        fn field_types() {
            Self::assert_impl_resolved_value::<T>();
            Self::assert_impl_resolved_value::<Option<Box<LinkedListNode<T>>>>();
        }
    }
};
```

## Why?

https://www.notion.so/vercel/Resolved-Vcs-Vc-Lifetimes-Local-Vcs-and-Vc-Refcounts-49d666d3f9594017b5b312b87ddc5bff

## Testing Instructions

```
cargo nextest r -p turbo-tasks-macros-tests
```

I ran this multiple times to weed out any non-determinism of the tests (I had some error order non-determinism issues).

If something changes and the stderr snapshots need to be updated, you can pass in `TRYBUILD=overwrite`:

```
TRYBUILD=overwrite cargo nextest r -p turbo-tasks-macros-tests
```

I used [rust-analyzer's "expand macro" feature](https://rust-analyzer.github.io/manual.html#expand-macro-recursively) to debug some issues, and to check that the generated code is as compact as reasonably possible (we want to avoid negative impacts on compile times).
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 1, 2024
### Description

We want a way to more strongly guarantee that a `Vc` is resolved for the sake of "local" tasks.

This introduces it in a low-risk way with zero breaking changes. Eventually, we'd want to eliminate `.resolve()` or make `.resolve()` return `ResolvedVc` instead of using a separate `.to_resolved()` method.

Some rough notes about why here: https://www.notion.so/vercel/Resolved-Vcs-Vc-Lifetimes-Local-Vcs-and-Vc-Refcounts-49d666d3f9594017b5b312b87ddc5bff

### Testing Instructions

Tested as a part of vercel/turborepo#8678
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 1, 2024
## Description

This trait will provide a best-effort indication that a type is safe to return from a local task function.

This PR also makes some improvements to the `TraceRawVcs` impls that I noticed as opportunities while working on `ResolvedValue`.

## Why?

https://www.notion.so/vercel/Resolved-Vcs-Vc-Lifetimes-Local-Vcs-and-Vc-Refcounts-49d666d3f9594017b5b312b87ddc5bff

## Testing Instructions

Tested as part of vercel/turborepo#8678
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 1, 2024
## Description

This macro allows the user to safely derive `ResolvedValue` (vercel/turborepo#8662). Most of the time, this won't be called directly, but instead as part of `#[turbo_tasks::value]` (not implemented yet).

The macro works by creating a compile-time assertion for each field of a struct, enum, or union, verifying that the type of the field implements `ResolvedValue`.

The assertions are designed to give relatively readable error messages, and [`trybuild`](https://github.com/dtolnay/trybuild) is used to test that.

## Example

An example of this macro expansion looks like this:

```
// input code
#[derive(ResolvedValue)]
struct LinkedListNode<T>
where
    T: ResolvedValue,
{
    current: T,
    next: Option<Box<LinkedListNode<T>>>,
}
```

```
// generated derived impl
unsafe impl<T> ::turbo_tasks::ResolvedValue for LinkedListNode<T> where T: ResolvedValue {}
const _: fn() = || {
    struct DeriveResolvedValueAssertion<T>(T, Option<Box<LinkedListNode<T>>>)
    where
        T: ResolvedValue;
    impl<T> DeriveResolvedValueAssertion<T>
    where
        T: ResolvedValue,
    {
        fn assert_impl_resolved_value<ExpectedResolvedValue: ResolvedValue + ?Sized>() {}
        fn field_types() {
            Self::assert_impl_resolved_value::<T>();
            Self::assert_impl_resolved_value::<Option<Box<LinkedListNode<T>>>>();
        }
    }
};
```

## Why?

https://www.notion.so/vercel/Resolved-Vcs-Vc-Lifetimes-Local-Vcs-and-Vc-Refcounts-49d666d3f9594017b5b312b87ddc5bff

## Testing Instructions

```
cargo nextest r -p turbo-tasks-macros-tests
```

I ran this multiple times to weed out any non-determinism of the tests (I had some error order non-determinism issues).

If something changes and the stderr snapshots need to be updated, you can pass in `TRYBUILD=overwrite`:

```
TRYBUILD=overwrite cargo nextest r -p turbo-tasks-macros-tests
```

I used [rust-analyzer's "expand macro" feature](https://rust-analyzer.github.io/manual.html#expand-macro-recursively) to debug some issues, and to check that the generated code is as compact as reasonably possible (we want to avoid negative impacts on compile times).
bgw added a commit to vercel/next.js that referenced this pull request Aug 6, 2024
### What & Why?

We want to enforce that values that functions return contain only
`ResolvedVc` and not `Vc` (though the outermost `Vc` is okay). We can do
that using the `ResolvedValue` marker trait
(vercel/turborepo#8678).

This PR allows enforcing that by passing a `resolved` argument to the
`#[turbo_tasks::function(...)]` macro.

This enforcement behavior is currently opt-in, but the goal is
eventually to make it opt-out, so that most functions can easily be
converted to use local tasks.

Bigger picture:
https://www.notion.so/vercel/Resolved-Vcs-Vc-Lifetimes-Local-Vcs-and-Vc-Refcounts-49d666d3f9594017b5b312b87ddc5bff

### How?

The key part of the macro is this bit:

```
fn assert_returns_resolved_value<
    ReturnType,
    Rv,
>() where
    ReturnType: turbo_tasks::task::TaskOutput<Return = Vc<Rv>>,
    Rv: turbo_tasks::ResolvedValue + Send,
{}
assert_returns_resolved_value::<#return_type, _>()
```

That creates no-op code that successfully compiles when the return value
(inside of the outermost `Vc`) is a `ResolvedValue`, but fails when it
isn't. This is the same trick that the [`static_assertions`
library](https://docs.rs/static_assertions/latest/static_assertions/macro.assert_type_eq_all.html)
uses.

### Test Plan

Lots of [trybuild](https://github.com/dtolnay/trybuild) tests!

```
cargo nextest r -p turbo-tasks-macros-tests
```

**Hint:** Use `TRYBUILD=overwrite` when intentionally changing the
tests.
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 14, 2024
* vercel/turborepo#8686 <!-- Tobias Koppers -
improve performance of the graph aggregation -->
* vercel/turborepo#8694 <!-- Benjamin Woodruff -
Replace `unreachable` with `bail` in `finalize_css` -->
* vercel/turborepo#8661 <!-- Benjamin Woodruff -
Create a minimum viable `ResolvedVc` type -->
* vercel/turborepo#8662 <!-- Benjamin Woodruff - Add
a minimum viable ResolvedValue marker trait -->
* vercel/turborepo#8678 <!-- Benjamin Woodruff - Add
derive macro for ResolvedValue -->
* vercel/turborepo#8715 <!-- Benjamin Woodruff -
Switch RcStr from std::sync::Arc to triomphe::Arc -->
* vercel/turborepo#8699 <!-- Donny/강동윤 - perf: Merge
multiple `EsmBinding` -->
* vercel/turborepo#8720 <!-- Benjamin Woodruff - Add
support for `#[turbo_tasks::value(resolved)]` and
`#[turbo_tasks::value_trait(resolved)]` -->
* vercel/turborepo#8706 <!-- Donny/강동윤 - build:
Update `swc_core` to `v0.96.9` -->

Update SWC crates to
swc-project/swc@226617e
and
swc-project/plugins@b7658c3

To keep in sync

 - Closes #64890
 - Closes #63104
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 14, 2024
### What & Why?

We want to enforce that values that functions return contain only
`ResolvedVc` and not `Vc` (though the outermost `Vc` is okay). We can do
that using the `ResolvedValue` marker trait
(vercel/turborepo#8678).

This PR allows enforcing that by passing a `resolved` argument to the
`#[turbo_tasks::function(...)]` macro.

This enforcement behavior is currently opt-in, but the goal is
eventually to make it opt-out, so that most functions can easily be
converted to use local tasks.

Bigger picture:
https://www.notion.so/vercel/Resolved-Vcs-Vc-Lifetimes-Local-Vcs-and-Vc-Refcounts-49d666d3f9594017b5b312b87ddc5bff

### How?

The key part of the macro is this bit:

```
fn assert_returns_resolved_value<
    ReturnType,
    Rv,
>() where
    ReturnType: turbo_tasks::task::TaskOutput<Return = Vc<Rv>>,
    Rv: turbo_tasks::ResolvedValue + Send,
{}
assert_returns_resolved_value::<#return_type, _>()
```

That creates no-op code that successfully compiles when the return value
(inside of the outermost `Vc`) is a `ResolvedValue`, but fails when it
isn't. This is the same trick that the [`static_assertions`
library](https://docs.rs/static_assertions/latest/static_assertions/macro.assert_type_eq_all.html)
uses.

### Test Plan

Lots of [trybuild](https://github.com/dtolnay/trybuild) tests!

```
cargo nextest r -p turbo-tasks-macros-tests
```

**Hint:** Use `TRYBUILD=overwrite` when intentionally changing the
tests.
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 15, 2024
* vercel/turborepo#8686 <!-- Tobias Koppers -
improve performance of the graph aggregation -->
* vercel/turborepo#8694 <!-- Benjamin Woodruff -
Replace `unreachable` with `bail` in `finalize_css` -->
* vercel/turborepo#8661 <!-- Benjamin Woodruff -
Create a minimum viable `ResolvedVc` type -->
* vercel/turborepo#8662 <!-- Benjamin Woodruff - Add
a minimum viable ResolvedValue marker trait -->
* vercel/turborepo#8678 <!-- Benjamin Woodruff - Add
derive macro for ResolvedValue -->
* vercel/turborepo#8715 <!-- Benjamin Woodruff -
Switch RcStr from std::sync::Arc to triomphe::Arc -->
* vercel/turborepo#8699 <!-- Donny/강동윤 - perf: Merge
multiple `EsmBinding` -->
* vercel/turborepo#8720 <!-- Benjamin Woodruff - Add
support for `#[turbo_tasks::value(resolved)]` and
`#[turbo_tasks::value_trait(resolved)]` -->
* vercel/turborepo#8706 <!-- Donny/강동윤 - build:
Update `swc_core` to `v0.96.9` -->

Update SWC crates to
swc-project/swc@226617e
and
swc-project/plugins@b7658c3

To keep in sync

 - Closes #64890
 - Closes #63104
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 15, 2024
### What & Why?

We want to enforce that values that functions return contain only
`ResolvedVc` and not `Vc` (though the outermost `Vc` is okay). We can do
that using the `ResolvedValue` marker trait
(vercel/turborepo#8678).

This PR allows enforcing that by passing a `resolved` argument to the
`#[turbo_tasks::function(...)]` macro.

This enforcement behavior is currently opt-in, but the goal is
eventually to make it opt-out, so that most functions can easily be
converted to use local tasks.

Bigger picture:
https://www.notion.so/vercel/Resolved-Vcs-Vc-Lifetimes-Local-Vcs-and-Vc-Refcounts-49d666d3f9594017b5b312b87ddc5bff

### How?

The key part of the macro is this bit:

```
fn assert_returns_resolved_value<
    ReturnType,
    Rv,
>() where
    ReturnType: turbo_tasks::task::TaskOutput<Return = Vc<Rv>>,
    Rv: turbo_tasks::ResolvedValue + Send,
{}
assert_returns_resolved_value::<#return_type, _>()
```

That creates no-op code that successfully compiles when the return value
(inside of the outermost `Vc`) is a `ResolvedValue`, but fails when it
isn't. This is the same trick that the [`static_assertions`
library](https://docs.rs/static_assertions/latest/static_assertions/macro.assert_type_eq_all.html)
uses.

### Test Plan

Lots of [trybuild](https://github.com/dtolnay/trybuild) tests!

```
cargo nextest r -p turbo-tasks-macros-tests
```

**Hint:** Use `TRYBUILD=overwrite` when intentionally changing the
tests.
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 16, 2024
* vercel/turborepo#8686 <!-- Tobias Koppers -
improve performance of the graph aggregation -->
* vercel/turborepo#8694 <!-- Benjamin Woodruff -
Replace `unreachable` with `bail` in `finalize_css` -->
* vercel/turborepo#8661 <!-- Benjamin Woodruff -
Create a minimum viable `ResolvedVc` type -->
* vercel/turborepo#8662 <!-- Benjamin Woodruff - Add
a minimum viable ResolvedValue marker trait -->
* vercel/turborepo#8678 <!-- Benjamin Woodruff - Add
derive macro for ResolvedValue -->
* vercel/turborepo#8715 <!-- Benjamin Woodruff -
Switch RcStr from std::sync::Arc to triomphe::Arc -->
* vercel/turborepo#8699 <!-- Donny/강동윤 - perf: Merge
multiple `EsmBinding` -->
* vercel/turborepo#8720 <!-- Benjamin Woodruff - Add
support for `#[turbo_tasks::value(resolved)]` and
`#[turbo_tasks::value_trait(resolved)]` -->
* vercel/turborepo#8706 <!-- Donny/강동윤 - build:
Update `swc_core` to `v0.96.9` -->

Update SWC crates to
swc-project/swc@226617e
and
swc-project/plugins@b7658c3

To keep in sync

 - Closes #64890
 - Closes #63104
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 16, 2024
### What & Why?

We want to enforce that values that functions return contain only
`ResolvedVc` and not `Vc` (though the outermost `Vc` is okay). We can do
that using the `ResolvedValue` marker trait
(vercel/turborepo#8678).

This PR allows enforcing that by passing a `resolved` argument to the
`#[turbo_tasks::function(...)]` macro.

This enforcement behavior is currently opt-in, but the goal is
eventually to make it opt-out, so that most functions can easily be
converted to use local tasks.

Bigger picture:
https://www.notion.so/vercel/Resolved-Vcs-Vc-Lifetimes-Local-Vcs-and-Vc-Refcounts-49d666d3f9594017b5b312b87ddc5bff

### How?

The key part of the macro is this bit:

```
fn assert_returns_resolved_value<
    ReturnType,
    Rv,
>() where
    ReturnType: turbo_tasks::task::TaskOutput<Return = Vc<Rv>>,
    Rv: turbo_tasks::ResolvedValue + Send,
{}
assert_returns_resolved_value::<#return_type, _>()
```

That creates no-op code that successfully compiles when the return value
(inside of the outermost `Vc`) is a `ResolvedValue`, but fails when it
isn't. This is the same trick that the [`static_assertions`
library](https://docs.rs/static_assertions/latest/static_assertions/macro.assert_type_eq_all.html)
uses.

### Test Plan

Lots of [trybuild](https://github.com/dtolnay/trybuild) tests!

```
cargo nextest r -p turbo-tasks-macros-tests
```

**Hint:** Use `TRYBUILD=overwrite` when intentionally changing the
tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants