Skip to content

Commit

Permalink
Custom debug implementation for Vcs (vercel/turborepo#193)
Browse files Browse the repository at this point in the history
This PR builds our own `Debug`-like derive-macro machinery for formatting structs, relying on `std::fmt::Formatter` for the actual formatting.

### Usage

A new `ValueDebug` trait is automatically implemented for all `#[turbo_tasks::value]`s, which has a single `.dbg()` method which resolves to a debug representation that can then be printed to the screen. `#[turbo_tasks::value_trait]` also implement the `.dbg()` method directly.

```rust
dbg!(any_vc.dbg().await?);
```

If you have a `#[turbo_tasks::value]` struct with a field that doesn't implement `Debug`, you'll want to declare that field as `#[debug_ignore]`. For instance:

```rust
#[turbo_tasks::value(ContentSource, serialization: none, eq: manual, cell: new, into: new)]
pub struct TurboTasksSource {
    #[debug_ignore]
    #[trace_ignore]
    pub turbo_tasks: Arc<TurboTasks<MemoryBackend>>,
}
```

### Why not use `Debug` directly?

We can't use `Debug` because our values are resolved asynchronously and can nest `Vc`s arbitrarily. I tried using `futures::executor::block_on` to resolve them synchronously in a `Debug` implementation but that causes deadlocks.
  • Loading branch information
alexkirsz committed Aug 2, 2022
1 parent fe3bc76 commit a30a224
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions crates/next-dev/src/turbo_tasks_viz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use turbopack_dev_server::source::{ContentSource, ContentSourceVc};

#[turbo_tasks::value(ContentSource, serialization: none, eq: manual, cell: new, into: new)]
pub struct TurboTasksSource {
#[debug_ignore]
#[trace_ignore]
pub turbo_tasks: Arc<TurboTasks<MemoryBackend>>,
}
Expand Down

0 comments on commit a30a224

Please sign in to comment.