Skip to content

Commit

Permalink
bring back Value wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony committed Aug 9, 2023
1 parent c0ec547 commit b467b74
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 72 deletions.
4 changes: 2 additions & 2 deletions crates/turbopack-cli/src/build/mod.rs
Expand Up @@ -205,10 +205,10 @@ async fn build_internal(
.map(|r| async move {
Ok(match &*r.await? {
EntryRequest::Relative(p) => {
Request::relative(p.clone().into(), QueryMap::empty(), false)
Request::relative(Value::new(p.clone().into()), QueryMap::empty(), false)
}
EntryRequest::Module(m, p) => {
Request::module(m.clone(), p.clone().into(), QueryMap::empty())
Request::module(m.clone(), Value::new(p.clone().into()), QueryMap::empty())
}
})
})
Expand Down
6 changes: 3 additions & 3 deletions crates/turbopack-cli/src/dev/mod.rs
Expand Up @@ -13,7 +13,7 @@ use anyhow::{Context, Result};
use owo_colors::OwoColorize;
use turbo_tasks::{
util::{FormatBytes, FormatDuration},
StatsType, TransientInstance, TurboTasks, TurboTasksBackendApi, UpdateInfo, Vc,
StatsType, TransientInstance, TurboTasks, TurboTasksBackendApi, UpdateInfo, Value, Vc,
};
use turbo_tasks_fs::FileSystem;
use turbo_tasks_malloc::TurboMalloc;
Expand Down Expand Up @@ -269,10 +269,10 @@ async fn source(
.iter()
.map(|r| match r {
EntryRequest::Relative(p) => {
Request::relative(p.clone().into(), QueryMap::empty(), false)
Request::relative(Value::new(p.clone().into()), QueryMap::empty(), false)
}
EntryRequest::Module(m, p) => {
Request::module(m.clone(), p.clone().into(), QueryMap::empty())
Request::module(m.clone(), Value::new(p.clone().into()), QueryMap::empty())
}
})
.collect();
Expand Down
23 changes: 14 additions & 9 deletions crates/turbopack-core/src/ident.rs
@@ -1,13 +1,13 @@
use std::fmt::Write;

use anyhow::Result;
use turbo_tasks::{ValueToString, Vc};
use turbo_tasks::{Value, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPath;
use turbo_tasks_hash::{encode_hex, hash_xxh3_hash64, DeterministicHash, Xxh3Hash64Hasher};

use crate::resolve::{pattern::QueryMap, ModulePart};

#[turbo_tasks::value(serialization = "auto_for_input", shared)]
#[turbo_tasks::value(serialization = "auto_for_input")]
#[derive(Clone, Debug, PartialOrd, Ord, Hash)]
pub struct AssetIdent {
/// The primary path of the asset
Expand Down Expand Up @@ -83,52 +83,57 @@ impl ValueToString for AssetIdent {

#[turbo_tasks::value_impl]
impl AssetIdent {
#[turbo_tasks::function]
pub fn new(ident: Value<AssetIdent>) -> Vc<Self> {
ident.into_value().cell()
}

/// Creates an [AssetIdent] from a [Vc<FileSystemPath>]
#[turbo_tasks::function]
pub fn from_path(path: Vc<FileSystemPath>) -> Vc<Self> {
Self::cell(AssetIdent {
Self::new(Value::new(AssetIdent {
path,
query: QueryMap::empty(),
fragment: None,
assets: Vec::new(),
modifiers: Vec::new(),
part: None,
})
}))
}

#[turbo_tasks::function]
pub fn with_query(&self, query: Vc<QueryMap>) -> Vc<Self> {
let mut this = self.clone();
this.query = this.query.merge(query);
this.cell()
Self::new(Value::new(this))
}

#[turbo_tasks::function]
pub fn with_modifier(&self, modifier: Vc<String>) -> Vc<Self> {
let mut this = self.clone();
this.add_modifier(modifier);
this.cell()
Self::new(Value::new(this))
}

#[turbo_tasks::function]
pub fn with_part(&self, part: Vc<ModulePart>) -> Vc<Self> {
let mut this = self.clone();
this.part = Some(part);
this.cell()
Self::new(Value::new(this))
}

#[turbo_tasks::function]
pub fn with_path(&self, path: Vc<FileSystemPath>) -> Vc<Self> {
let mut this = self.clone();
this.path = path;
this.cell()
Self::new(Value::new(this))
}

#[turbo_tasks::function]
pub async fn rename_as(&self, pattern: String) -> Result<Vc<Self>> {
let mut this = self.clone();
this.rename_as_ref(&pattern).await?;
Ok(this.cell())
Ok(Self::new(Value::new(this)))
}

#[turbo_tasks::function]
Expand Down
16 changes: 8 additions & 8 deletions crates/turbopack-core/src/resolve/mod.rs
Expand Up @@ -1175,7 +1175,7 @@ async fn resolve_internal(
for pattern in patterns {
results.push(resolve_internal(
lookup_path,
Request::raw(pattern, *query, *force_in_lookup_dir),
Request::raw(Value::new(pattern), *query, *force_in_lookup_dir),
options,
));
}
Expand All @@ -1193,7 +1193,7 @@ async fn resolve_internal(
Request::ServerRelative { path, query } => {
let mut new_pat = path.clone();
new_pat.push_front(".".to_string().into());
let relative = Request::relative(new_pat, *query, true);
let relative = Request::relative(Value::new(new_pat), *query, true);

ResolvingIssue {
severity: IssueSeverity::Error.cell(),
Expand Down Expand Up @@ -1316,13 +1316,13 @@ async fn resolve_into_folder(
escapes the current directory"
)
})?;
let request = Request::parse(str.into()).with_query(query);
let request = Request::parse(Value::new(str.into())).with_query(query);
return Ok(resolve_internal(package_path, request, options));
}
ResolveIntoPackage::MainField(name) => {

Check failure on line 1322 in crates/turbopack-core/src/resolve/mod.rs

View workflow job for this annotation

GitHub Actions / Rust lints

Diff in /home/runner/work/turbo/turbo/crates/turbopack-core/src/resolve/mod.rs
if let Some(package_json) = &*read_package_json(package_json_path).await? {
if let Some(field_value) = package_json[name].as_str() {
let request = Request::parse(normalize_request(field_value).into());
let request = Request::parse(Value::new(normalize_request(field_value).into()));

let result = &*resolve_internal(package_path, request, options).await?;
// we are not that strict when a main field fails to resolve
Expand Down Expand Up @@ -1495,7 +1495,7 @@ async fn resolve_module_request(
let mut new_pat = path.clone();
new_pat.push_front(".".to_string().into());

let relative = Request::relative(new_pat, query, true);
let relative = Request::relative(Value::new(new_pat), query, true);
results.push(resolve_internal(*package_path, relative, options));
}

Expand Down Expand Up @@ -1597,7 +1597,7 @@ async fn resolve_alias_field_result(
if let Some(value) = result.as_str() {
return Ok(resolve_internal(
package_path,
Request::parse(Pattern::Constant(value.to_string())).with_query(query),
Request::parse(Value::new(Pattern::Constant(value.to_string()))).with_query(query),
resolve_options,
)
.with_affecting_sources(refs));
Expand All @@ -1607,7 +1607,7 @@ async fn resolve_alias_field_result(
severity: IssueSeverity::Error.cell(),
file_path: issue_context,
request_type: format!("alias field ({field_name})"),
request: Request::parse(Pattern::Constant(issue_request.to_string())),
request: Request::parse(Value::new(Pattern::Constant(issue_request.to_string()))),
resolve_options,
error_message: Some(format!("invalid alias field value: {}", result)),
source: OptionIssueSource::none(),
Expand Down Expand Up @@ -1741,7 +1741,7 @@ fn handle_exports_imports_field(
let mut resolved_results = Vec::new();
for path in results {
if let Some(path) = normalize_path(path) {
let request = Request::relative(format!("./{}", path).into(), query, false);
let request = Request::relative(Value::new(format!("./{}", path).into()), query, false);
resolved_results.push(resolve_internal(package_path, request, options));
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/turbopack-core/src/resolve/options.rs
Expand Up @@ -2,7 +2,7 @@ use std::{collections::BTreeMap, future::Future, pin::Pin};

Check failure on line 2 in crates/turbopack-core/src/resolve/options.rs

View workflow job for this annotation

GitHub Actions / Rust lints

Diff in /home/runner/work/turbo/turbo/crates/turbopack-core/src/resolve/options.rs
use anyhow::Result;
use serde::{Deserialize, Serialize};
use turbo_tasks::{debug::ValueDebugFormat, trace::TraceRawVcs, TryJoinIterExt, ValueToString, Vc};
use turbo_tasks::{debug::ValueDebugFormat, trace::TraceRawVcs, TryJoinIterExt, Value, ValueToString, Vc};
use turbo_tasks_fs::{glob::Glob, FileSystemPath};

use super::{
Expand Down Expand Up @@ -280,7 +280,7 @@ async fn import_mapping_to_result(
ImportMapResult::Result(ResolveResult::primary(ResolveResultItem::Empty).into())
}
ImportMapping::PrimaryAlternative(name, context) => {
let request = Request::parse(name.to_string().into());
let request = Request::parse(Value::new(name.to_string().into()));

ImportMapResult::Alias(request, *context)
}
Expand Down
26 changes: 13 additions & 13 deletions crates/turbopack-core/src/resolve/parse.rs
Expand Up @@ -2,7 +2,7 @@ use anyhow::Result;
use indexmap::IndexMap;
use lazy_static::lazy_static;
use regex::Regex;
use turbo_tasks::{TryJoinIterExt, ValueToString, Vc};
use turbo_tasks::{TryJoinIterExt, Value, ValueToString, Vc};

use super::pattern::{Pattern, QueryMap};

Expand Down Expand Up @@ -206,7 +206,7 @@ impl Request {
}

Check failure on line 206 in crates/turbopack-core/src/resolve/parse.rs

View workflow job for this annotation

GitHub Actions / Rust lints

Diff in /home/runner/work/turbo/turbo/crates/turbopack-core/src/resolve/parse.rs
}
Pattern::Alternatives(list) => Request::Alternatives {
requests: list.into_iter().map(Request::parse).collect(),
requests: list.into_iter().map(Value::new).map(Request::parse).collect(),
},
}
}
Expand All @@ -215,8 +215,8 @@ impl Request {
#[turbo_tasks::value_impl]
impl Request {
#[turbo_tasks::function]
pub fn parse(request: Pattern) -> Vc<Self> {
Self::cell(Request::parse_ref(request))
pub fn parse(request: Value<Pattern>) -> Vc<Self> {
Self::cell(Request::parse_ref(request.into_value()))
}

#[turbo_tasks::function]
Expand All @@ -225,28 +225,28 @@ impl Request {
}

Check failure on line 225 in crates/turbopack-core/src/resolve/parse.rs

View workflow job for this annotation

GitHub Actions / Rust lints

Diff in /home/runner/work/turbo/turbo/crates/turbopack-core/src/resolve/parse.rs

#[turbo_tasks::function]
pub fn raw(path: Pattern, query: Vc<QueryMap>, force_in_lookup_dir: bool) -> Vc<Self> {
pub fn raw(request: Value<Pattern>, query: Vc<QueryMap>, force_in_lookup_dir: bool) -> Vc<Self> {
Self::cell(Request::Raw {
path,
path: request.into_value(),
force_in_lookup_dir,
query,
})
}

Check failure on line 234 in crates/turbopack-core/src/resolve/parse.rs

View workflow job for this annotation

GitHub Actions / Rust lints

Diff in /home/runner/work/turbo/turbo/crates/turbopack-core/src/resolve/parse.rs

#[turbo_tasks::function]
pub fn relative(path: Pattern, query: Vc<QueryMap>, force_in_lookup_dir: bool) -> Vc<Self> {
pub fn relative(request: Value<Pattern>, query: Vc<QueryMap>, force_in_lookup_dir: bool) -> Vc<Self> {
Self::cell(Request::Relative {
path,
path: request.into_value(),
force_in_lookup_dir,
query,
})
}

#[turbo_tasks::function]
pub fn module(module: String, path: Pattern, query: Vc<QueryMap>) -> Vc<Self> {
pub fn module(module: String, path: Value<Pattern>, query: Vc<QueryMap>) -> Vc<Self> {
Self::cell(Request::Module {
module,
path,
path: path.into_value(),
query,
})
}
Expand All @@ -270,17 +270,17 @@ impl Request {
let mut pat = Pattern::Constant(format!("./{module}"));
pat.push(path.clone());
// TODO add query
Self::parse(pat)
Self::parse(Value::new(pat))
}
Request::PackageInternal { path } => {
let mut pat = Pattern::Constant("./".to_string());
pat.push(path.clone());
Self::parse(pat)
Self::parse(Value::new(pat))
}
Request::Unknown { path } => {
let mut pat = Pattern::Constant("./".to_string());
pat.push(path.clone());
Self::parse(pat)
Self::parse(Value::new(pat))
}
Request::Alternatives { requests } => {
let requests = requests.iter().copied().map(Request::as_relative).collect();
Expand Down
4 changes: 2 additions & 2 deletions crates/turbopack-core/src/resolve/pattern.rs
Expand Up @@ -5,7 +5,7 @@ use indexmap::IndexMap;
use lazy_static::lazy_static;
use regex::Regex;
use serde::{Deserialize, Serialize};
use turbo_tasks::{trace::TraceRawVcs, ReadRef, TaskInput, Value, ValueToString, Vc};
use turbo_tasks::{trace::TraceRawVcs, ReadRef, Value, ValueToString, Vc};
use turbo_tasks_fs::{
DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath, LinkContent, LinkType,
};
Expand Down Expand Up @@ -57,7 +57,7 @@ impl ValueToString for QueryMap {
}

#[turbo_tasks::value(shared, serialization = "auto_for_input")]
#[derive(PartialOrd, Ord, Hash, Clone, Debug, Default, TaskInput)]
#[derive(PartialOrd, Ord, Hash, Clone, Debug, Default)]
pub enum Pattern {
Constant(String),
#[default]
Expand Down
5 changes: 2 additions & 3 deletions crates/turbopack-css/src/chunk/mod.rs
Expand Up @@ -384,15 +384,14 @@ impl OutputAsset for CssChunk {
ident
} else {
let (_, ident) = assets[0];
AssetIdent {
AssetIdent::new(Value::new(AssetIdent {
path: ident.path(),
query: QueryMap::empty(),
fragment: None,
assets,
modifiers: Vec::new(),
part: None,
}
.cell()
}))
};

Ok(AssetIdent::from_path(
Expand Down
2 changes: 1 addition & 1 deletion crates/turbopack-css/src/module_asset.rs
Expand Up @@ -170,7 +170,7 @@ impl ModuleCssAsset {
original: name.value.to_string(),
from: CssModuleComposeReference::new(
Vc::upcast(self),
Request::parse(from.to_string().into()),
Request::parse(Value::new(from.to_string().into())),
),
},
CssClassName::Local { name } => ModuleCssClass::Local {
Expand Down
4 changes: 2 additions & 2 deletions crates/turbopack-css/src/references/mod.rs
Expand Up @@ -130,7 +130,7 @@ impl<'a> VisitAstPath for ModuleReferencesVisitor<'a> {

self.references.push(Vc::upcast(ImportAssetReference::new(
self.origin,
Request::parse(src.to_string().into()),
Request::parse(Value::new(src.to_string().into())),
Vc::cell(as_parent_path(ast_path)),
ImportAttributes::new_from_prelude(i).into(),
IssueSource::from_byte_offset(
Expand Down Expand Up @@ -158,7 +158,7 @@ impl<'a> VisitAstPath for ModuleReferencesVisitor<'a> {
let issue_span = u.span;
self.references.push(Vc::upcast(UrlAssetReference::new(
self.origin,
Request::parse(src.to_string().into()),
Request::parse(Value::new(src.to_string().into())),
Vc::cell(as_parent_path(ast_path)),
IssueSource::from_byte_offset(
Vc::upcast(self.source),
Expand Down
6 changes: 3 additions & 3 deletions crates/turbopack-dev/src/ecmascript/evaluate/chunk.rs
Expand Up @@ -3,7 +3,7 @@ use std::io::Write;
use anyhow::{bail, Result};
use indoc::writedoc;
use serde::Serialize;
use turbo_tasks::{ReadRef, TryJoinIterExt, ValueToString, Vc};
use turbo_tasks::{ReadRef, TryJoinIterExt, Value, ValueToString, Vc};
use turbo_tasks_fs::File;
use turbopack_core::{
asset::{Asset, AssetContent},
Expand Down Expand Up @@ -193,9 +193,9 @@ impl OutputAsset for EcmascriptDevEvaluateChunk {
ident.add_modifier(chunk.ident().to_string());
}

let ident = AssetIdent::new(Value::new(ident));
Ok(AssetIdent::from_path(
self.chunking_context
.chunk_path(ident.cell(), ".js".to_string()),
self.chunking_context.chunk_path(ident, ".js".to_string()),
))
}

Expand Down
4 changes: 2 additions & 2 deletions crates/turbopack-dev/src/ecmascript/list/asset.rs
Expand Up @@ -86,9 +86,9 @@ impl OutputAsset for EcmascriptDevChunkList {
// ident, because it must remain stable whenever a chunk is added or
// removed from the list.

let ident = AssetIdent::new(Value::new(ident));
Ok(AssetIdent::from_path(
self.chunking_context
.chunk_path(ident.cell(), ".js".to_string()),
self.chunking_context.chunk_path(ident, ".js".to_string()),
))
}

Expand Down

0 comments on commit b467b74

Please sign in to comment.