Skip to content

Commit

Permalink
Manually clean up LLM output
Browse files Browse the repository at this point in the history
  • Loading branch information
bgw committed Oct 27, 2024
1 parent 60d39e9 commit 27b2512
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 44 deletions.
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-css/src/chunk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl OutputAsset for CssChunk {
} else {
*ServerFileSystem::new().root().to_resolved().await?
},
query: *Vc::<RcStr>::default().to_resolved().await?,
query: Vc::<RcStr>::default(),
fragment: None,
assets,
modifiers: Vec::new(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub async fn resolve_source_request(
}
ContentSourceContent::Static(static_content) => {
return Ok(ResolveSourceRequestResult::Static(
static_content.to_resolved().await?,
*static_content,
HeaderList::new(response_header_overwrites)
.to_resolved()
.await?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl RouteTree {
match selector_segment {
BaseSegment::Static(value) => Ok(RouteTree {
base,
static_segments: fxindexmap! { value => *inner.resolved_cell() },
static_segments: fxindexmap! { value => inner.cell() },
..Default::default()
}
.cell()),
Expand Down Expand Up @@ -380,9 +380,8 @@ impl RouteTree {
for s in not_found_sources.iter_mut() {
*s = mapper.map_get_content(*s);
}

for r in static_segments.values_mut() {
*r = *r.map_routes(mapper).to_resolved().await?;
*r = r.map_routes(mapper);
}
for r in dynamic_segments.iter_mut() {
*r = r.map_routes(mapper).to_resolved().await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,22 @@ impl ChunkGroupFilesChunkItem {
async fn chunks(&self) -> Result<Vc<OutputAssets>> {
let inner = self.inner.await?;
let chunks = if let Some(ecma) =
ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(inner.module.to_resolved().await?)
.await?
Vc::try_resolve_sidecast::<Box<dyn EvaluatableAsset>>(inner.module).await?
{
let empty_assets = EvaluatableAssets::empty().to_resolved().await?;
inner.chunking_context.evaluated_chunk_group_assets(
inner.module.ident(),
inner
.runtime_entries
.unwrap_or_else(|| empty_assets)
.with_entry(*ecma),
.as_deref()
.copied()
.unwrap_or_else(EvaluatableAssets::empty)
.with_entry(ecma),
Value::new(AvailabilityInfo::Root),
)
} else {
inner
.chunking_context
.root_chunk_group_assets(*ResolvedVc::upcast(inner.module.to_resolved().await?))
.root_chunk_group_assets(Vc::upcast(inner.module))
};
Ok(chunks)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ impl EsmExports {
}

if export_info.has_dynamic_exports {
dynamic_exports.push((**asset).to_resolved().await?);
dynamic_exports.push(*asset);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl AnalyzeEcmascriptModuleResultBuilder {
for c in self.code_gens.iter_mut() {
match c {
CodeGen::CodeGenerateable(c) => {
*c = *c.to_resolved().await?;
*c = c.resolve().await?;
}
CodeGen::CodeGenerateableWithAsyncModuleInfo(c) => {
*c = c.to_resolved().await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ impl DirList {
DirectoryEntry::File(path) => {
if let Some(relative_path) = root_val.get_relative_path_to(&*path.await?) {
if regex.is_match(&relative_path) {
list.insert(
relative_path,
DirListEntry::File(path.to_resolved().await?),
);
list.insert(relative_path, DirListEntry::File(*path));
}
}
}
Expand Down Expand Up @@ -124,8 +121,7 @@ impl DirList {
for (k, entry) in &*dir {
match entry {
DirListEntry::File(path) => {
// Don't dereference the path, store it as a Vc
list.insert(k.clone(), path.resolve().await?);
list.insert(k.clone(), **path);
}
DirListEntry::Dir(d) => {
queue.push_back(d.await?);
Expand Down
7 changes: 2 additions & 5 deletions turbopack/crates/turbopack-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub async fn external_asset_entrypoints(
/// assets.
#[turbo_tasks::function]
async fn separate_assets(
intermediate_asset: Vc<Box<dyn OutputAsset>>,
intermediate_asset: ResolvedVc<Box<dyn OutputAsset>>,
intermediate_output_path: Vc<FileSystemPath>,
) -> Result<Vc<SeparatedAssets>> {
let intermediate_output_path = &*intermediate_output_path.await?;
Expand Down Expand Up @@ -166,10 +166,7 @@ async fn separate_assets(

let graph = AdjacencyMap::new()
.skip_duplicates()
.visit(
once(Type::Internal(intermediate_asset.to_resolved().await?)),
get_asset_children,
)
.visit(once(Type::Internal(intermediate_asset)), get_asset_children)
.await
.completed()?
.into_inner();
Expand Down
4 changes: 3 additions & 1 deletion turbopack/crates/turbopack-node/src/render/render_static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ async fn render_stream_internal(
RenderStaticIncomingMessage::Headers { data } => yield RenderItem::Headers(data),
RenderStaticIncomingMessage::Rewrite { path } => {
drop(guard);
yield RenderItem::Response(StaticResult::rewrite(RewriteBuilder::new(path).build()).to_resolved().await?);
yield RenderItem::Response(
StaticResult::rewrite(RewriteBuilder::new(path).build()).to_resolved().await?
);
return;
}
RenderStaticIncomingMessage::Response {
Expand Down
13 changes: 3 additions & 10 deletions turbopack/crates/turbopack-node/src/transforms/postcss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,16 +511,9 @@ impl PostCssTransformedAsset {

// TODO handle SourceMap
let file = File::from(processed_css.css);
let mut resolved_assets = Vec::new();
for asset in emitted_assets_to_virtual_sources(processed_css.assets) {
resolved_assets.push(asset.to_resolved().await?);
}
let content = AssetContent::File(*FileContent::Content(file).resolved_cell()).cell();
Ok(ProcessPostCssResult {
content,
assets: resolved_assets,
}
.cell())
let assets = emitted_assets_to_virtual_sources(processed_css.assets).await?;
let content = AssetContent::File(FileContent::Content(file).cell()).cell();
Ok(ProcessPostCssResult { content, assets }.cell())
}
}

Expand Down
11 changes: 7 additions & 4 deletions turbopack/crates/turbopack-node/src/transforms/util.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::collections::BTreeMap;

use anyhow::Result;
use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue;
use turbo_tasks::{RcStr, Vc};
use turbo_tasks::{RcStr, ResolvedVc, TryJoinIterExt};
use turbo_tasks_fs::{File, FileContent, FileSystem};
use turbopack_core::{
asset::AssetContent, server_fs::ServerFileSystem, virtual_source::VirtualSource,
Expand All @@ -16,9 +17,9 @@ pub struct EmittedAsset {
source_map: Option<JsonValue>,
}

pub fn emitted_assets_to_virtual_sources(
pub async fn emitted_assets_to_virtual_sources(
assets: Option<Vec<EmittedAsset>>,
) -> Vec<Vc<VirtualSource>> {
) -> Result<Vec<ResolvedVc<VirtualSource>>> {
assets
.into_iter()
.flatten()
Expand All @@ -38,6 +39,8 @@ pub fn emitted_assets_to_virtual_sources(
ServerFileSystem::new().root().join(file),
AssetContent::File(FileContent::Content(File::from(content)).cell()).cell(),
)
.to_resolved()
})
.collect()
.try_join()
.await
}
6 changes: 5 additions & 1 deletion turbopack/crates/turbopack-node/src/transforms/webpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,11 @@ impl WebpackLoadersProcessedAsset {
Either::Left(str) => File::from(str),
Either::Right(bytes) => File::from(bytes.binary),
};
let assets = emitted_assets_to_virtual_sources(processed.assets);
let assets = emitted_assets_to_virtual_sources(processed.assets)
.await?
.into_iter()
.map(|asset| *asset)
.collect();
let content = AssetContent::File(FileContent::Content(file).cell()).cell();
Ok(ProcessWebpackLoadersResult {
content,
Expand Down
7 changes: 3 additions & 4 deletions turbopack/crates/turbopack/src/graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,12 @@ impl AggregatedGraph {
.collect::<Vec<_>>()
{
let cost = cost.await?.0;
let resolved_reference = reference.to_resolved().await?;
if cost == 0 {
inner.insert(resolved_reference);
inner.insert(reference);
} else if cost > self_cost {
references.insert(resolved_reference);
references.insert(reference);
} else {
outer.insert(resolved_reference);
outer.insert(reference);
}
}
Ok(AggregatedGraphsValuedReferences {
Expand Down

0 comments on commit 27b2512

Please sign in to comment.