Unverified Commit a2d221b9 authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

refactor(turbopack): Make various types directly or indirectly included in…

refactor(turbopack): Make various types directly or indirectly included in `State<T>` types into OperationValues and/or NonLocalValues (#74008)

This is a refactor ahead of #73876

This adds the `OperationValue` trait (and in a few cases, `NonLocalValue`) to a large number of types where it can be trivially done.

These types are needed in #73876 because they're used somewhere inside of a `State<...>` type (most likely transitively).
parent bb0e59f9
......@@ -28,8 +28,8 @@ use turbo_tasks::{
fxindexmap,
graph::{AdjacencyMap, GraphTraversal},
trace::TraceRawVcs,
Completion, Completions, FxIndexMap, IntoTraitRef, NonLocalValue, ReadRef, ResolvedVc, State,
TaskInput, TransientInstance, TryFlatJoinIterExt, Value, Vc,
Completion, Completions, FxIndexMap, IntoTraitRef, NonLocalValue, OperationValue, ReadRef,
ResolvedVc, State, TaskInput, TransientInstance, TryFlatJoinIterExt, Value, Vc,
};
use turbo_tasks_env::{EnvMap, ProcessEnv};
use turbo_tasks_fs::{DiskFileSystem, FileSystem, FileSystemPath, VirtualFileSystem};
......@@ -73,7 +73,17 @@ use crate::{
};
#[derive(
Debug, Serialize, Deserialize, Clone, TaskInput, PartialEq, Eq, Hash, TraceRawVcs, NonLocalValue,
Debug,
Serialize,
Deserialize,
Clone,
TaskInput,
PartialEq,
Eq,
Hash,
TraceRawVcs,
NonLocalValue,
OperationValue,
)]
#[serde(rename_all = "camelCase")]
pub struct DraftModeOptions {
......@@ -95,6 +105,7 @@ pub struct DraftModeOptions {
Hash,
TraceRawVcs,
NonLocalValue,
OperationValue,
)]
#[serde(rename_all = "camelCase")]
pub struct WatchOptions {
......@@ -107,7 +118,17 @@ pub struct WatchOptions {
}
#[derive(
Debug, Serialize, Deserialize, Clone, TaskInput, PartialEq, Eq, Hash, TraceRawVcs, NonLocalValue,
Debug,
Serialize,
Deserialize,
Clone,
TaskInput,
PartialEq,
Eq,
Hash,
TraceRawVcs,
NonLocalValue,
OperationValue,
)]
#[serde(rename_all = "camelCase")]
pub struct ProjectOptions {
......@@ -192,7 +213,17 @@ pub struct PartialProjectOptions {
}
#[derive(
Debug, Serialize, Deserialize, Clone, TaskInput, PartialEq, Eq, Hash, TraceRawVcs, NonLocalValue,
Debug,
Serialize,
Deserialize,
Clone,
TaskInput,
PartialEq,
Eq,
Hash,
TraceRawVcs,
NonLocalValue,
OperationValue,
)]
#[serde(rename_all = "camelCase")]
pub struct DefineEnv {
......
This diff is collapsed.
......@@ -5,14 +5,23 @@ use async_trait::async_trait;
use modularize_imports::{modularize_imports, PackageConfig};
use serde::{Deserialize, Serialize};
use swc_core::ecma::ast::Program;
use turbo_tasks::{trace::TraceRawVcs, FxIndexMap, NonLocalValue, ResolvedVc};
use turbo_tasks::{trace::TraceRawVcs, FxIndexMap, NonLocalValue, OperationValue, ResolvedVc};
use turbopack::module_options::{ModuleRule, ModuleRuleEffect};
use turbopack_ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext};
use super::module_rule_match_js_no_url;
#[derive(
Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue,
Clone,
Debug,
Default,
PartialEq,
Eq,
Serialize,
Deserialize,
TraceRawVcs,
NonLocalValue,
OperationValue,
)]
#[serde(rename_all = "camelCase")]
pub struct ModularizeImportPackageConfig {
......@@ -24,7 +33,16 @@ pub struct ModularizeImportPackageConfig {
}
#[derive(
Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue,
Clone,
Debug,
Default,
PartialEq,
Eq,
Serialize,
Deserialize,
TraceRawVcs,
NonLocalValue,
OperationValue,
)]
#[serde(untagged)]
pub enum Transform {
......
......@@ -67,12 +67,16 @@ macro_rules! impl_auto_marker_trait {
unsafe impl<T: $trait + ?Sized> $trait for ::std::cell::RefCell<T> {}
unsafe impl<T: ?Sized> $trait for ::std::marker::PhantomData<T> {}
unsafe impl<T: $trait + ?Sized> $trait for $crate::TraitRef<T> {}
unsafe impl<T> $trait for $crate::ReadRef<T>
where
T: $crate::VcValueType,
<<T as $crate::VcValueType>::Read as $crate::VcRead<T>>::Target: $trait
{}
unsafe impl<T: $trait> $trait for $crate::State<T> {}
unsafe impl<T: $trait> $trait for $crate::Value<T> {}
unsafe impl<T: $trait> $trait for $crate::TransientValue<T> {}
unsafe impl<T: $trait> $trait for $crate::TransientInstance<T> {}
unsafe impl<T: $trait + ?Sized> $trait for &T {}
unsafe impl<T: $trait + ?Sized> $trait for &mut T {}
......
......@@ -6,7 +6,7 @@ use std::{
use anyhow::{Context, Result};
use indexmap::{IndexMap, IndexSet};
use turbo_tasks::Vc;
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::{
rope::{Rope, RopeBuilder},
util::uri_from_file,
......@@ -21,14 +21,13 @@ use crate::{
};
/// A mapping of byte-offset in the code string to an associated source map.
pub type Mapping = (usize, Option<Vc<Box<dyn GenerateSourceMap>>>);
pub type Mapping = (usize, Option<ResolvedVc<Box<dyn GenerateSourceMap>>>);
/// Code stores combined output code and the source map of that output code.
#[turbo_tasks::value(shared, local)]
#[turbo_tasks::value(shared)]
#[derive(Debug, Clone)]
pub struct Code {
code: Rope,
mappings: Vec<Mapping>,
}
......@@ -36,7 +35,6 @@ pub struct Code {
#[derive(Default)]
pub struct CodeBuilder {
code: RopeBuilder,
mappings: Vec<Mapping>,
}
......@@ -63,7 +61,11 @@ impl CodeBuilder {
/// Pushes original user code with an optional source map if one is
/// available. If it's not, this is no different than pushing Synthetic
/// code.
pub fn push_source(&mut self, code: &Rope, map: Option<Vc<Box<dyn GenerateSourceMap>>>) {
pub fn push_source(
&mut self,
code: &Rope,
map: Option<ResolvedVc<Box<dyn GenerateSourceMap>>>,
) {
self.push_map(map);
self.code += code;
}
......@@ -98,7 +100,7 @@ impl CodeBuilder {
/// original code section. By inserting an empty source map when reaching a
/// synthetic section directly after an original section, we tell Chrome
/// that the previous map ended at this point.
fn push_map(&mut self, map: Option<Vc<Box<dyn GenerateSourceMap>>>) {
fn push_map(&mut self, map: Option<ResolvedVc<Box<dyn GenerateSourceMap>>>) {
if map.is_none() && matches!(self.mappings.last(), None | Some((_, None))) {
// No reason to push an empty map directly after an empty map
return;
......
......@@ -121,7 +121,7 @@ impl VersionedContentExt for AssetContent {
/// Describes the current version of an object, and how to update them from an
/// earlier version.
#[turbo_tasks::value_trait(local)]
#[turbo_tasks::value_trait]
pub trait Version {
/// Get a unique identifier of the version as a string. There is no way
/// to convert an id back to its original `Version`, so the original object
......@@ -149,7 +149,7 @@ pub trait VersionedContentMerger {
#[turbo_tasks::value(transparent)]
pub struct VersionedContents(Vec<ResolvedVc<Box<dyn VersionedContent>>>);
#[turbo_tasks::value]
#[turbo_tasks::value(operation)]
pub struct NotFoundVersion;
#[turbo_tasks::value_impl]
......@@ -209,7 +209,7 @@ pub struct PartialUpdate {
/// [`Version`] implementation that hashes a file at a given path and returns
/// the hex encoded hash as a version identifier.
#[turbo_tasks::value]
#[turbo_tasks::value(operation)]
#[derive(Clone)]
pub struct FileHashVersion {
hash: RcStr,
......
......@@ -94,7 +94,7 @@ impl CssChunk {
content.source_map.map(ResolvedVc::upcast)
};
body.push_source(&content.inner_code, source_map.map(|v| *v));
body.push_source(&content.inner_code, source_map);
writeln!(body, "{close}")?;
writeln!(body)?;
......
......@@ -59,7 +59,7 @@ impl SingleItemCssChunk {
code.push_source(
&content.inner_code,
content.source_map.map(ResolvedVc::upcast).map(|v| *v),
content.source_map.map(ResolvedVc::upcast),
);
write!(code, "{close}")?;
......
......@@ -164,7 +164,7 @@ impl DevHtmlAsset {
}
}
#[turbo_tasks::value]
#[turbo_tasks::value(operation)]
struct DevHtmlAssetContent {
chunk_paths: Vec<RcStr>,
body: Option<RcStr>,
......@@ -234,7 +234,7 @@ impl VersionedContent for DevHtmlAssetContent {
}
}
#[turbo_tasks::value]
#[turbo_tasks::value(operation)]
struct DevHtmlAssetVersion {
content: ReadRef<DevHtmlAssetContent>,
}
......
......@@ -33,13 +33,14 @@ use self::{
};
/// The result of proxying a request to another HTTP server.
#[turbo_tasks::value(shared)]
#[turbo_tasks::value(shared, operation)]
pub struct ProxyResult {
/// The HTTP status code to return.
pub status: u16,
/// Headers arranged as contiguous (name, value) pairs.
pub headers: Vec<(RcStr, RcStr)>,
/// The body to return.
#[turbo_tasks(trace_ignore)]
pub body: Body,
}
......
use hyper::{HeaderMap, Uri};
use turbo_tasks::NonLocalValue;
use super::Body;
/// A request to a content source.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, NonLocalValue)]
pub struct SourceRequest {
/// The HTTP method to use.
pub method: String,
/// The URI to request.
#[turbo_tasks(trace_ignore)]
pub uri: Uri,
/// The headers to send.
#[turbo_tasks(trace_ignore)]
pub headers: HeaderMap<hyper::header::HeaderValue>,
/// The body to send.
pub body: Body,
......
......@@ -14,10 +14,12 @@ use swc_core::{
visit::FoldWith,
},
};
use turbo_tasks::{trace::TraceRawVcs, NonLocalValue, ValueDefault, Vc};
use turbo_tasks::{trace::TraceRawVcs, NonLocalValue, OperationValue, ValueDefault, Vc};
use turbopack_ecmascript::{CustomTransformer, TransformContext};
#[derive(Clone, PartialEq, Eq, Debug, TraceRawVcs, Serialize, Deserialize, NonLocalValue)]
#[derive(
Clone, PartialEq, Eq, Debug, TraceRawVcs, Serialize, Deserialize, NonLocalValue, OperationValue,
)]
#[serde(rename_all = "kebab-case")]
pub enum EmotionLabelKind {
DevOnly,
......@@ -27,7 +29,7 @@ pub enum EmotionLabelKind {
//[TODO]: need to support importmap, there are type mismatch between
//next.config.js to swc's emotion options
#[turbo_tasks::value(shared)]
#[turbo_tasks::value(shared, operation)]
#[derive(Default, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct EmotionTransformConfig {
......
......@@ -5,11 +5,13 @@ use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use swc_core::{common::FileName, ecma::ast::Program};
use swc_relay::RelayLanguageConfig;
use turbo_tasks::{trace::TraceRawVcs, NonLocalValue};
use turbo_tasks::{trace::TraceRawVcs, NonLocalValue, OperationValue};
use turbo_tasks_fs::FileSystemPath;
use turbopack_ecmascript::{CustomTransformer, TransformContext};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)]
#[derive(
Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue,
)]
#[serde(rename_all = "camelCase")]
pub struct RelayConfig {
pub src: String,
......@@ -17,7 +19,9 @@ pub struct RelayConfig {
pub language: Option<RelayLanguage>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)]
#[derive(
Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue,
)]
#[serde(rename_all = "lowercase")]
pub enum RelayLanguage {
TypeScript,
......
......@@ -9,7 +9,7 @@ use swc_core::{
use turbo_tasks::{ValueDefault, Vc};
use turbopack_ecmascript::{CustomTransformer, TransformContext};
#[turbo_tasks::value(shared)]
#[turbo_tasks::value(shared, operation)]
#[derive(Clone, Debug)]
#[serde(default, rename_all = "camelCase")]
pub struct StyledComponentsTransformConfig {
......
......@@ -155,12 +155,11 @@ impl EcmascriptChunkItemContent {
match source_map {
Some(map) => fileify_source_map(map, *rewrite_source_path)
.await?
.map(|v| *v)
.map(Vc::upcast),
.map(ResolvedVc::upcast),
None => None,
}
} else {
self.source_map.map(|v| *v)
self.source_map
};
code.push_source(&self.inner_code, source_map);
......
......@@ -19,7 +19,7 @@ use swc_core::{
transforms::base::fixer::paren_remover,
},
};
use turbo_tasks::Vc;
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{
code_builder::{Code, CodeBuilder},
......@@ -106,8 +106,8 @@ pub async fn minify(path: Vc<FileSystemPath>, code: Vc<Code>) -> Result<Vc<Code>
let mut builder = CodeBuilder::default();
builder.push_source(
&src.into(),
Some(Vc::upcast(
ParseResultSourceMap::new(cm, src_map_buf, original_map).cell(),
Some(ResolvedVc::upcast(
ParseResultSourceMap::new(cm, src_map_buf, original_map).resolved_cell(),
)),
);
......
......@@ -54,7 +54,7 @@ impl StaticEcmascriptCode {
let mut code = CodeBuilder::default();
code.push_source(
&runtime_base_content.inner_code,
runtime_base_content.source_map.map(|v| *v),
runtime_base_content.source_map,
);
Ok(Code::cell(code.build()))
}
......
......@@ -24,7 +24,7 @@ fn modifier() -> Vc<RcStr> {
Vc::cell("mdx".into())
}
#[turbo_tasks::value(shared)]
#[turbo_tasks::value(shared, operation)]
#[derive(Hash, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub enum MdxParseConstructs {
......@@ -35,7 +35,7 @@ pub enum MdxParseConstructs {
/// Subset of mdxjs::Options to allow to inherit turbopack's jsx-related configs
/// into mdxjs. This is thin, near straightforward subset of mdxjs::Options to
/// enable turbo tasks.
#[turbo_tasks::value(shared)]
#[turbo_tasks::value(shared, operation)]
#[derive(Hash, Debug, Clone)]
#[serde(rename_all = "camelCase", default)]
pub struct MdxTransformOptions {
......
......@@ -8,8 +8,8 @@ use serde_json::{json, Value as JsonValue};
use serde_with::serde_as;
use turbo_rcstr::RcStr;
use turbo_tasks::{
trace::TraceRawVcs, Completion, NonLocalValue, ResolvedVc, TaskInput, TryJoinIterExt, Value,
ValueToString, Vc,
trace::TraceRawVcs, Completion, NonLocalValue, OperationValue, ResolvedVc, TaskInput,
TryJoinIterExt, Value, ValueToString, Vc,
};
use turbo_tasks_bytes::stream::SingleValue;
use turbo_tasks_env::ProcessEnv;
......@@ -75,7 +75,9 @@ struct WebpackLoadersProcessingResult {
assets: Option<Vec<EmittedAsset>>,
}
#[derive(Clone, PartialEq, Eq, Debug, TraceRawVcs, Serialize, Deserialize, NonLocalValue)]
#[derive(
Clone, PartialEq, Eq, Debug, TraceRawVcs, Serialize, Deserialize, NonLocalValue, OperationValue,
)]
pub struct WebpackLoaderItem {
pub loader: RcStr,
pub options: serde_json::Map<String, serde_json::Value>,
......
......@@ -12,7 +12,7 @@ use turbopack_ecmascript::chunk::EcmascriptChunkContent;
use super::content::chunk_items;
#[turbo_tasks::value(serialization = "none", local)]
#[turbo_tasks::value(serialization = "none")]
pub(super) struct EcmascriptBuildNodeChunkVersion {
chunk_path: String,
chunk_items: Vec<(ReadRef<ModuleId>, ReadRef<Code>)>,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment