Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions crates/next-api/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ fn pick_route(entrypoints: OperationVc<Entrypoints>, key: RcStr, route: &Route)
ValueDebugFormat,
NonLocalValue,
OperationValue,
Encode,
Decode,
)]
enum EndpointSelector {
RoutePageHtml(RcStr),
Expand Down
26 changes: 24 additions & 2 deletions crates/next-api/src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,18 @@ enum PageEndpointType {
}

#[derive(
Copy, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Debug, TaskInput, TraceRawVcs,
Copy,
Clone,
Serialize,
Deserialize,
PartialEq,
Eq,
Hash,
Debug,
TaskInput,
TraceRawVcs,
Encode,
Decode,
)]
enum SsrChunkType {
Page,
Expand All @@ -621,7 +632,18 @@ enum SsrChunkType {
}

#[derive(
Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, TaskInput, TraceRawVcs,
Copy,
Clone,
Debug,
PartialEq,
Eq,
Hash,
Serialize,
Deserialize,
TaskInput,
TraceRawVcs,
Encode,
Decode,
)]
enum EmitManifests {
/// Don't emit any manifests
Expand Down
4 changes: 0 additions & 4 deletions crates/next-api/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
/// E.g. `/home/user/projects/my-repo`.
pub root_path: RcStr,

/// A path which contains the app/pages directories, relative to [`Project::root_path`], always

Check warning on line 168 in crates/next-api/src/project.rs

View workflow job for this annotation

GitHub Actions / rustdoc check / build

public documentation for `project_path` links to private item `Project::root_path`

Check warning on line 168 in crates/next-api/src/project.rs

View workflow job for this annotation

GitHub Actions / rustdoc check / build

public documentation for `project_path` links to private item `Project::root_path`
/// Unix path. E.g. `apps/my-app`
pub project_path: RcStr,

Expand Down Expand Up @@ -209,10 +209,6 @@
pub current_node_js_version: RcStr,
}

#[derive(
Debug, Serialize, Deserialize, Clone, TaskInput, PartialEq, Eq, Hash, TraceRawVcs, NonLocalValue,
)]
#[serde(rename_all = "camelCase")]
pub struct PartialProjectOptions {
/// A root path from which all files must be nested under. Trying to access
/// a file outside this root will fail. Think of this as a chroot.
Expand Down
21 changes: 18 additions & 3 deletions crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::BTreeSet;

use anyhow::Result;
use bincode::{Decode, Encode};
use serde::{Deserialize, Serialize};
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, TaskInput, Vc, trace::TraceRawVcs};
Expand Down Expand Up @@ -32,11 +33,13 @@ use turbopack_node::{
};
use turbopack_resolve::resolve_options_context::ResolveOptionsContext;

use super::transforms::get_next_client_transforms_rules;
use crate::{
mode::NextMode,
next_build::get_postcss_package_mapping,
next_client::runtime_entry::{RuntimeEntries, RuntimeEntry},
next_client::{
runtime_entry::{RuntimeEntries, RuntimeEntry},
transforms::get_next_client_transforms_rules,
},
next_config::NextConfig,
next_font::local::NextFontLocalResolvePlugin,
next_import_map::{
Expand Down Expand Up @@ -405,7 +408,19 @@ pub async fn get_client_module_options_context(
Ok(module_options_context)
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, TaskInput, TraceRawVcs, Serialize, Deserialize)]
#[derive(
Clone,
Debug,
PartialEq,
Eq,
Hash,
TaskInput,
TraceRawVcs,
Serialize,
Deserialize,
Encode,
Decode,
)]
pub struct ClientChunkingContextOptions {
pub mode: Vc<NextMode>,
pub root_path: FileSystemPath,
Expand Down
15 changes: 14 additions & 1 deletion crates/next-core/src/next_edge/context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Result;
use bincode::{Decode, Encode};
use serde::{Deserialize, Serialize};
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, TaskInput, Vc, trace::TraceRawVcs};
Expand Down Expand Up @@ -196,7 +197,19 @@ pub async fn get_edge_resolve_options_context(
.cell())
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, TaskInput, TraceRawVcs, Serialize, Deserialize)]
#[derive(
Clone,
Debug,
PartialEq,
Eq,
Hash,
TaskInput,
TraceRawVcs,
Serialize,
Deserialize,
Encode,
Decode,
)]
pub struct EdgeChunkingContextOptions {
pub mode: Vc<NextMode>,
pub root_path: FileSystemPath,
Expand Down
18 changes: 11 additions & 7 deletions crates/next-core/src/next_root_params/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use either::Either;
use indoc::formatdoc;
use itertools::Itertools;
use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks::{EitherTaskInput, ResolvedVc, Vc};
use turbo_tasks_fs::{FileContent, FileSystemPath};
use turbopack_core::{
asset::AssetContent,
Expand Down Expand Up @@ -36,17 +36,21 @@ pub async fn insert_next_root_params_mapping(
) -> Result<()> {
import_map.insert_exact_alias(
"next/root-params",
get_next_root_params_mapping(is_root_params_enabled, ty, collected_root_params)
.to_resolved()
.await?,
get_next_root_params_mapping(
is_root_params_enabled,
EitherTaskInput(ty),
collected_root_params,
)
.to_resolved()
.await?,
);
Ok(())
}

#[turbo_tasks::function]
async fn get_next_root_params_mapping(
is_root_params_enabled: Vc<bool>,
ty: Either<ServerContextType, ClientContextType>,
ty: EitherTaskInput<ServerContextType, ClientContextType>,
collected_root_params: Option<Vc<CollectedRootParams>>,
) -> Result<Vc<ImportMapping>> {
// This mapping goes into the global resolve options, so we want to avoid invalidating it if
Expand Down Expand Up @@ -77,12 +81,12 @@ impl NextRootParamsMapper {
#[turbo_tasks::function]
pub fn new(
is_root_params_enabled: ResolvedVc<bool>,
context_type: Either<ServerContextType, ClientContextType>,
context_type: EitherTaskInput<ServerContextType, ClientContextType>,
collected_root_params: Option<ResolvedVc<CollectedRootParams>>,
) -> Vc<Self> {
NextRootParamsMapper {
is_root_params_enabled,
context_type,
context_type: context_type.0,
collected_root_params,
}
.cell()
Expand Down
24 changes: 18 additions & 6 deletions crates/next-core/src/next_server/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::BTreeSet;

use anyhow::{Result, bail};
use bincode::{Decode, Encode};
use serde::{Deserialize, Serialize};
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, TaskInput, Vc, trace::TraceRawVcs};
Expand Down Expand Up @@ -38,18 +39,17 @@ use turbopack_node::{
use turbopack_nodejs::NodeJsChunkingContext;
use turbopack_resolve::resolve_options_context::ResolveOptionsContext;

use super::{
resolve::ExternalCjsModulesResolvePlugin,
transforms::{get_next_server_internal_transforms_rules, get_next_server_transforms_rules},
};
use crate::{
app_structure::CollectedRootParams,
mode::NextMode,
next_build::get_postcss_package_mapping,
next_config::NextConfig,
next_font::local::NextFontLocalResolvePlugin,
next_import_map::{get_next_edge_and_server_fallback_import_map, get_next_server_import_map},
next_server::resolve::ExternalPredicate,
next_server::{
resolve::{ExternalCjsModulesResolvePlugin, ExternalPredicate},
transforms::{get_next_server_internal_transforms_rules, get_next_server_transforms_rules},
},
next_shared::{
resolve::{
ModuleFeatureReportResolvePlugin, NextExternalResolvePlugin,
Expand Down Expand Up @@ -981,7 +981,19 @@ pub async fn get_server_module_options_context(
Ok(module_options_context)
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, TaskInput, TraceRawVcs, Serialize, Deserialize)]
#[derive(
Clone,
Debug,
PartialEq,
Eq,
Hash,
TaskInput,
TraceRawVcs,
Serialize,
Deserialize,
Encode,
Decode,
)]
pub struct ServerChunkingContextOptions {
pub mode: Vc<NextMode>,
pub root_path: FileSystemPath,
Expand Down
13 changes: 12 additions & 1 deletion crates/next-core/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,18 @@ pub fn defines(define_env: &FxIndexMap<RcStr, Option<RcStr>>) -> CompileTimeDefi
}

#[derive(
Debug, Clone, Copy, PartialEq, Eq, Hash, TaskInput, Serialize, Deserialize, TraceRawVcs,
Debug,
Clone,
Copy,
PartialEq,
Eq,
Hash,
TaskInput,
Serialize,
Deserialize,
TraceRawVcs,
Encode,
Decode,
)]
pub enum PathType {
PagesPage,
Expand Down
4 changes: 3 additions & 1 deletion turbopack/crates/turbo-bincode/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[doc(hidden)]
pub mod macro_helpers;

use std::ptr::copy_nonoverlapping;
use std::{any::Any, ptr::copy_nonoverlapping};

use ::smallvec::SmallVec;
use bincode::{
Expand All @@ -17,6 +17,8 @@ pub type TurboBincodeEncoder<'a> =
EncoderImpl<TurboBincodeWriter<'a>, bincode::config::Configuration>;
pub type TurboBincodeDecoder<'a> =
DecoderImpl<TurboBincodeReader<'a>, bincode::config::Configuration, ()>;
pub type AnyEncodeFn = fn(&dyn Any, &mut TurboBincodeEncoder<'_>) -> Result<(), EncodeError>;
pub type AnyDecodeFn<T> = fn(&mut TurboBincodeDecoder<'_>) -> Result<T, DecodeError>;

fn new_turbo_bincode_encoder(buf: &mut TurboBincodeBuffer) -> TurboBincodeEncoder<'_> {
EncoderImpl::new(TurboBincodeWriter::new(buf), TURBO_BINCODE_CONFIG)
Expand Down
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-backend/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cargo-fuzz = true
afl = "0.15.18"
anyhow = { workspace = true }
arbitrary = { version = "1.4.1", features = ["derive"] }
bincode = { workspace = true }
libfuzzer-sys = "0.4.9"
once_cell = { workspace = true }
serde = { workspace = true }
Expand Down
5 changes: 5 additions & 0 deletions turbopack/crates/turbo-tasks-backend/fuzz/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::sync::Arc;

use anyhow::Result;
use arbitrary::Arbitrary;
use bincode::{Decode, Encode};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use turbo_tasks::{self, NonLocalValue, State, TaskInput, TurboTasks, Vc, trace::TraceRawVcs};
Expand All @@ -19,6 +20,8 @@ use turbo_tasks_malloc::TurboMalloc;
Deserialize,
TraceRawVcs,
TaskInput,
Encode,
Decode,
)]
pub struct TaskReferenceSpec {
task: u16,
Expand All @@ -39,6 +42,8 @@ pub struct TaskReferenceSpec {
Deserialize,
TraceRawVcs,
TaskInput,
Encode,
Decode,
)]
pub struct TaskSpec {
references: Vec<TaskReferenceSpec>,
Expand Down
11 changes: 0 additions & 11 deletions turbopack/crates/turbo-tasks-backend/src/kv_backing_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,17 +604,6 @@ fn encode_task_type(
buffer: &mut TurboBincodeBuffer,
task_id: Option<TaskId>,
) -> Result<()> {
// DO NOT REMOVE THE `inline(never)` ATTRIBUTE!
// CachedTaskType's `Encode`/`Decode` implementations use `pot` internally for `TaskInput`s.
// TODO: remove `serde` and `pot`, make `TaskInput: Encode + Decode`.
//
// `pot` uses the pointer address of `&'static str` to deduplicate Symbols.
// If this function is inlined into multiple different callsites it might inline the Serialize
// implementation too, which can pull a `&'static str` from another crate into this crate.
// Since string deduplication between crates is not guaranteed, it can lead to behavior changes
// due to the pointer addresses. This can lead to lookup path and store path creating different
// serialization of the same task type, which breaks task cache lookups.
#[inline(never)]
fn encode_once_into(
task_type: &CachedTaskType,
buffer: &mut TurboBincodeBuffer,
Expand Down
6 changes: 2 additions & 4 deletions turbopack/crates/turbo-tasks-backend/tests/trace_transient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![feature(arbitrary_self_types_pointers)]

use anyhow::Result;
use serde::{Deserialize, Serialize};
use bincode::{Decode, Encode};
use turbo_tasks::{NonLocalValue, ResolvedVc, TaskInput, Vc, trace::TraceRawVcs};
use turbo_tasks_testing::{Registration, register, run_once_without_cache_check};

Expand Down Expand Up @@ -62,9 +62,7 @@ async fn read_incorrect_task_input_operation(value: IncorrectTaskInput) -> Resul

/// Has an intentionally incorrect `TaskInput` implementation, representing some code that the debug
/// tracing might be particularly useful with.
#[derive(
Copy, Clone, Debug, PartialEq, Eq, Hash, TraceRawVcs, Serialize, Deserialize, NonLocalValue,
)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TraceRawVcs, Encode, Decode, NonLocalValue)]
struct IncorrectTaskInput(ResolvedVc<u64>);

impl TaskInput for IncorrectTaskInput {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![feature(arbitrary_self_types)]
#![feature(arbitrary_self_types_pointers)]

use serde::{Deserialize, Serialize};
use bincode::{Decode, Encode};
use turbo_tasks::{NonLocalValue, ResolvedVc, TaskInput, trace::TraceRawVcs};
use turbo_tasks_testing::{Registration, register, run_once_without_cache_check};

Expand Down Expand Up @@ -30,9 +30,7 @@ fn emit_incorrect_task_input_operation(value: IncorrectTaskInput) {
}

/// Has an intentionally incorrect `TaskInput` implementation
#[derive(
Copy, Clone, Debug, PartialEq, Eq, Hash, TraceRawVcs, Serialize, Deserialize, NonLocalValue,
)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TraceRawVcs, Encode, Decode, NonLocalValue)]
struct IncorrectTaskInput(ResolvedVc<U32Wrapper>);

impl TaskInput for IncorrectTaskInput {
Expand Down
Loading
Loading