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

vdbg! macro #4868

Merged
merged 5 commits into from
May 9, 2023
Merged

vdbg! macro #4868

merged 5 commits into from
May 9, 2023

Conversation

alexkirsz
Copy link
Contributor

@alexkirsz alexkirsz commented May 8, 2023

Description

The vdbg! macro works the same way as the dbg! macro, with the additional benefit of automatically calling ValueDebugFormat implementations.

This means that you can do:

vdbg!(42, asset_ident_vc);
vdbg!(42, asset_ident_vc; depth = 1);

and the macro will print out

[src/main.rs:10] 42 = 42
[src/main.rs:10] some_vc = AssetIdent {
    path: FileSystemPath {
        fs: FileSystem(DiskFileSystem {
            name: "project",
            root: "...",
        }),
        path: "...",
    },
    query: None,
    fragment: None,
    assets: [],
    modifiers: [],
    part: None,
}
[src/main.rs:10] 42 = 42
[src/main.rs:10] asset_ident_vc = AssetIdent {
    path: FileSystemPath,
    query: core::option::Option<turbo_tasks::primitives::StringVc>,
    fragment: core::option::Option<turbo_tasks::primitives::StringVc>,
    assets: alloc::vec::Vec<(turbo_tasks::primitives::StringVc, turbopack_core::ident::AssetIdentVc)>,
    modifiers: alloc::vec::Vec<turbo_tasks::primitives::StringVc>,
    part: core::option::Option<turbopack_core::resolve::ModulePartVc>,
}

This is an ergonomic improvement over having to call .dbg() or .dbg_depth() manually in four major ways:

  1. No need to be in an async context and call .await?: the macro will spawn a task on its own. This means that it is no longer necessary to convert a turbo_tasks::function to async just to debug one of its arguments.
  2. No need to import the turbo_tasks::debug::ValueDebug trait. You can call turbo_tasks::vdbg!(...) directly, of vdbg!(...) if you have it imported already.
  3. No need to call eprintln! or dbg!: vdbg! calls eprintln! directly under the hood, with the same format as dbg!.
  4. It's just one macro, with support for the depth argument baked in.

Testing Instructions

N/A
link WEB-520

@alexkirsz alexkirsz requested a review from a team as a code owner May 8, 2023 14:51
@vercel
Copy link

vercel bot commented May 8, 2023

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

Name Status Preview Comments Updated (UTC)
examples-basic-web 🔄 Building (Inspect) May 9, 2023 8:16am
10 Ignored Deployments
Name Status Preview Comments Updated (UTC)
examples-cra-web ⬜️ Ignored (Inspect) May 9, 2023 8:16am
examples-designsystem-docs ⬜️ Ignored (Inspect) May 9, 2023 8:16am
examples-gatsby-web ⬜️ Ignored (Inspect) May 9, 2023 8:16am
examples-kitchensink-blog ⬜️ Ignored (Inspect) May 9, 2023 8:16am
examples-native-web ⬜️ Ignored (Inspect) May 9, 2023 8:16am
examples-nonmonorepo ⬜️ Ignored (Inspect) May 9, 2023 8:16am
examples-svelte-web ⬜️ Ignored (Inspect) May 9, 2023 8:16am
examples-tailwind-web ⬜️ Ignored (Inspect) May 9, 2023 8:16am
examples-vite-web ⬜️ Ignored (Inspect) May 9, 2023 8:16am
turbo-site ⬜️ Ignored (Inspect) Visit Preview May 9, 2023 8:16am

@github-actions
Copy link
Contributor

github-actions bot commented May 8, 2023

🟢 CI successful 🟢

Thanks

@github-actions
Copy link
Contributor

github-actions bot commented May 8, 2023

This change may fail to build next-swc.

info: syncing channel updates for 'nightly-2023-03-09-x86_64-unknown-linux-gnu'
info: latest update on 2023-03-09, rust version 1.70.0-nightly (900c35403 2023-03-08)
info: downloading component 'cargo'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: installing component 'cargo'
info: installing component 'rust-std'
info: installing component 'rustc'
packages/next-swc/crates/next-core/src/next_client/context.rs:197:9: warning: use of deprecated field `turbo_binding::turbopack::turbopack::module_options::ModuleOptionsContext::custom_ecmascript_transforms`: use custom_ecma_transform_plugins instead
packages/next-swc/crates/next-core/src/next_server/context.rs:323:17: warning: use of deprecated field `turbo_binding::turbopack::turbopack::module_options::ModuleOptionsContext::custom_ecmascript_transforms`: use custom_ecma_transform_plugins instead
packages/next-swc/crates/next-core/src/next_server/context.rs:362:17: warning: use of deprecated field `turbo_binding::turbopack::turbopack::module_options::ModuleOptionsContext::custom_ecmascript_transforms`: use custom_ecma_transform_plugins instead
packages/next-swc/crates/next-core/src/next_shared/transforms.rs:73:17: error[E0195]: lifetime parameters or bounds on method `transform` do not match the trait declaration
packages/next-swc/crates/next-core/src/next_shared/transforms.rs:140:17: error[E0195]: lifetime parameters or bounds on method `transform` do not match the trait declaration
packages/next-swc/crates/next-core/src/next_shared/transforms.rs:179:17: error[E0195]: lifetime parameters or bounds on method `transform` do not match the trait declaration
packages/next-swc/crates/next-core/src/next_shared/transforms.rs:270:17: error[E0195]: lifetime parameters or bounds on method `transform` do not match the trait declaration
error: could not compile `next-core` (lib) due to 4 previous errors; 3 warnings emitted

Copy link
Contributor

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a default impl for items which implement Debug but don't implement ValueDebugFormat specifically? #4868 (comment)

crates/turbo-tasks/src/manager.rs Outdated Show resolved Hide resolved
crates/turbo-tasks/src/manager.rs Outdated Show resolved Hide resolved
@ForsakenHarmony
Copy link
Contributor

@jridgewell isn't this already the case?
https://github.com/vercel/turbo/blob/main/crates/turbo-tasks/src/debug/mod.rs#L75

@jridgewell
Copy link
Contributor

Ohh, I didn't read the comments and thought we still needed an impl<T> ValueDebugFormat for T (not for &T).

@alexkirsz alexkirsz added the pr: automerge Kodiak will merge these automatically after checks pass label May 9, 2023
@kodiakhq
Copy link
Contributor

kodiakhq bot commented May 9, 2023

This PR could not be merged because the GitHub API returned an internal server error. To enable Kodiak on this pull request please remove the kodiak:disabled label.

When the GitHub API returns an internal server error (HTTP status code 500), it is not safe for Kodiak to retry merging.

For more information please see https://kodiakhq.com/docs/troubleshooting#merge-errors

If you need help, you can open a GitHub issue, check the docs, or reach us privately at support@kodiakhq.com.

docs | dashboard | support

@kodiakhq kodiakhq bot merged commit 3683efc into main May 9, 2023
@kodiakhq kodiakhq bot deleted the alexkirsz/web-520-improve-dbg-ergonomics branch May 9, 2023 08:41
NicholasLYang pushed a commit to NicholasLYang/turbo that referenced this pull request May 9, 2023
### Description

The `vdbg!` macro works the same way as the `dbg!` macro, with the
additional benefit of automatically calling `ValueDebugFormat`
implementations.

This means that you can do:

```rust
vdbg!(42, asset_ident_vc);
vdbg!(42, asset_ident_vc; depth = 1);
```

and the macro will print out

```rust
[src/main.rs:10] 42 = 42
[src/main.rs:10] some_vc = AssetIdent {
    path: FileSystemPath {
        fs: FileSystem(DiskFileSystem {
            name: "project",
            root: "...",
        }),
        path: "...",
    },
    query: None,
    fragment: None,
    assets: [],
    modifiers: [],
    part: None,
}
```

```rust
[src/main.rs:10] 42 = 42
[src/main.rs:10] asset_ident_vc = AssetIdent {
    path: FileSystemPath,
    query: core::option::Option<turbo_tasks::primitives::StringVc>,
    fragment: core::option::Option<turbo_tasks::primitives::StringVc>,
    assets: alloc::vec::Vec<(turbo_tasks::primitives::StringVc, turbopack_core::ident::AssetIdentVc)>,
    modifiers: alloc::vec::Vec<turbo_tasks::primitives::StringVc>,
    part: core::option::Option<turbopack_core::resolve::ModulePartVc>,
}
```

This is an ergonomic improvement over having to call `.dbg()` or
`.dbg_depth()` manually in four major ways:
1. No need to be in an async context and call `.await?`: the macro will
spawn a task on its own. This means that it is no longer necessary to
convert a `turbo_tasks::function` to async just to debug one of its
arguments.
2. No need to import the `turbo_tasks::debug::ValueDebug` trait. You can
call `turbo_tasks::vdbg!(...)` directly, of `vdbg!(...)` if you have it
imported already.
3. No need to call `eprintln!` or `dbg!`: `vdbg!` calls `eprintln!`
directly under the hood, with the same format as `dbg!`.
4. It's just one macro, with support for the `depth` argument baked in.

### Testing Instructions

N/A
link WEB-520
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 25, 2024
### Description

The `vdbg!` macro works the same way as the `dbg!` macro, with the
additional benefit of automatically calling `ValueDebugFormat`
implementations.

This means that you can do:

```rust
vdbg!(42, asset_ident_vc);
vdbg!(42, asset_ident_vc; depth = 1);
```

and the macro will print out

```rust
[src/main.rs:10] 42 = 42
[src/main.rs:10] some_vc = AssetIdent {
    path: FileSystemPath {
        fs: FileSystem(DiskFileSystem {
            name: "project",
            root: "...",
        }),
        path: "...",
    },
    query: None,
    fragment: None,
    assets: [],
    modifiers: [],
    part: None,
}
```

```rust
[src/main.rs:10] 42 = 42
[src/main.rs:10] asset_ident_vc = AssetIdent {
    path: FileSystemPath,
    query: core::option::Option<turbo_tasks::primitives::StringVc>,
    fragment: core::option::Option<turbo_tasks::primitives::StringVc>,
    assets: alloc::vec::Vec<(turbo_tasks::primitives::StringVc, turbopack_core::ident::AssetIdentVc)>,
    modifiers: alloc::vec::Vec<turbo_tasks::primitives::StringVc>,
    part: core::option::Option<turbopack_core::resolve::ModulePartVc>,
}
```

This is an ergonomic improvement over having to call `.dbg()` or
`.dbg_depth()` manually in four major ways:
1. No need to be in an async context and call `.await?`: the macro will
spawn a task on its own. This means that it is no longer necessary to
convert a `turbo_tasks::function` to async just to debug one of its
arguments.
2. No need to import the `turbo_tasks::debug::ValueDebug` trait. You can
call `turbo_tasks::vdbg!(...)` directly, of `vdbg!(...)` if you have it
imported already.
3. No need to call `eprintln!` or `dbg!`: `vdbg!` calls `eprintln!`
directly under the hood, with the same format as `dbg!`.
4. It's just one macro, with support for the `depth` argument baked in.

### Testing Instructions

N/A
link WEB-520
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 29, 2024
### Description

The `vdbg!` macro works the same way as the `dbg!` macro, with the
additional benefit of automatically calling `ValueDebugFormat`
implementations.

This means that you can do:

```rust
vdbg!(42, asset_ident_vc);
vdbg!(42, asset_ident_vc; depth = 1);
```

and the macro will print out

```rust
[src/main.rs:10] 42 = 42
[src/main.rs:10] some_vc = AssetIdent {
    path: FileSystemPath {
        fs: FileSystem(DiskFileSystem {
            name: "project",
            root: "...",
        }),
        path: "...",
    },
    query: None,
    fragment: None,
    assets: [],
    modifiers: [],
    part: None,
}
```

```rust
[src/main.rs:10] 42 = 42
[src/main.rs:10] asset_ident_vc = AssetIdent {
    path: FileSystemPath,
    query: core::option::Option<turbo_tasks::primitives::StringVc>,
    fragment: core::option::Option<turbo_tasks::primitives::StringVc>,
    assets: alloc::vec::Vec<(turbo_tasks::primitives::StringVc, turbopack_core::ident::AssetIdentVc)>,
    modifiers: alloc::vec::Vec<turbo_tasks::primitives::StringVc>,
    part: core::option::Option<turbopack_core::resolve::ModulePartVc>,
}
```

This is an ergonomic improvement over having to call `.dbg()` or
`.dbg_depth()` manually in four major ways:
1. No need to be in an async context and call `.await?`: the macro will
spawn a task on its own. This means that it is no longer necessary to
convert a `turbo_tasks::function` to async just to debug one of its
arguments.
2. No need to import the `turbo_tasks::debug::ValueDebug` trait. You can
call `turbo_tasks::vdbg!(...)` directly, of `vdbg!(...)` if you have it
imported already.
3. No need to call `eprintln!` or `dbg!`: `vdbg!` calls `eprintln!`
directly under the hood, with the same format as `dbg!`.
4. It's just one macro, with support for the `depth` argument baked in.

### Testing Instructions

N/A
link WEB-520
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 1, 2024
### Description

The `vdbg!` macro works the same way as the `dbg!` macro, with the
additional benefit of automatically calling `ValueDebugFormat`
implementations.

This means that you can do:

```rust
vdbg!(42, asset_ident_vc);
vdbg!(42, asset_ident_vc; depth = 1);
```

and the macro will print out

```rust
[src/main.rs:10] 42 = 42
[src/main.rs:10] some_vc = AssetIdent {
    path: FileSystemPath {
        fs: FileSystem(DiskFileSystem {
            name: "project",
            root: "...",
        }),
        path: "...",
    },
    query: None,
    fragment: None,
    assets: [],
    modifiers: [],
    part: None,
}
```

```rust
[src/main.rs:10] 42 = 42
[src/main.rs:10] asset_ident_vc = AssetIdent {
    path: FileSystemPath,
    query: core::option::Option<turbo_tasks::primitives::StringVc>,
    fragment: core::option::Option<turbo_tasks::primitives::StringVc>,
    assets: alloc::vec::Vec<(turbo_tasks::primitives::StringVc, turbopack_core::ident::AssetIdentVc)>,
    modifiers: alloc::vec::Vec<turbo_tasks::primitives::StringVc>,
    part: core::option::Option<turbopack_core::resolve::ModulePartVc>,
}
```

This is an ergonomic improvement over having to call `.dbg()` or
`.dbg_depth()` manually in four major ways:
1. No need to be in an async context and call `.await?`: the macro will
spawn a task on its own. This means that it is no longer necessary to
convert a `turbo_tasks::function` to async just to debug one of its
arguments.
2. No need to import the `turbo_tasks::debug::ValueDebug` trait. You can
call `turbo_tasks::vdbg!(...)` directly, of `vdbg!(...)` if you have it
imported already.
3. No need to call `eprintln!` or `dbg!`: `vdbg!` calls `eprintln!`
directly under the hood, with the same format as `dbg!`.
4. It's just one macro, with support for the `depth` argument baked in.

### Testing Instructions

N/A
link WEB-520
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: automerge Kodiak will merge these automatically after checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants