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

fix rustc bug in turbopack-trace-server #8158

Merged
merged 1 commit into from
May 21, 2024
Merged
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
18 changes: 11 additions & 7 deletions crates/turbopack-trace-server/src/bottom_up.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::{collections::HashMap, env, sync::Arc};

use either::Either;

use crate::{
span::{SpanBottomUp, SpanIndex},
span_ref::SpanRef,
Expand Down Expand Up @@ -36,16 +34,22 @@ impl SpanBottomUpBuilder {
}

pub fn build_bottom_up_graph<'a>(
spans: impl IntoIterator<Item = SpanRef<'a>>,
spans: impl Iterator<Item = SpanRef<'a>>,
) -> Vec<Arc<SpanBottomUp>> {
let max_depth = env::var("BOTTOM_UP_DEPTH")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(usize::MAX);
let mut roots = HashMap::new();
let mut current_iterators = vec![Either::Left(
spans.into_iter().flat_map(|span| span.children()),
)];

// unfortunately there is a rustc bug that fails the typechecking here
// when using Either<impl Iterator, impl Iterator>. This error appears
// in certain cases when building next-swc.
//
// see here: https://github.com/rust-lang/rust/issues/124891
let mut current_iterators: Vec<Box<dyn Iterator<Item = SpanRef<'_>>>> =
vec![Box::new(spans.flat_map(|span| span.children()))];

let mut current_path: Vec<(&'_ str, SpanIndex)> = vec![];
while let Some(mut iter) = current_iterators.pop() {
if let Some(child) = iter.next() {
Expand Down Expand Up @@ -73,7 +77,7 @@ pub fn build_bottom_up_graph<'a>(
}

current_path.push((child.group_name(), child.index()));
current_iterators.push(Either::Right(child.children()));
current_iterators.push(Box::new(child.children()));
} else {
current_path.pop();
}
Expand Down
4 changes: 2 additions & 2 deletions crates/turbopack-trace-server/src/span_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ impl<'a> SpanRef<'a> {
pub fn bottom_up(self) -> impl Iterator<Item = SpanBottomUpRef<'a>> {
self.extra()
.bottom_up
.get_or_init(|| build_bottom_up_graph([self]))
.get_or_init(|| build_bottom_up_graph([self].into_iter()))
.iter()
.map(|bottom_up| SpanBottomUpRef {
.map(move |bottom_up| SpanBottomUpRef {
bottom_up: bottom_up.clone(),
store: self.store,
})
Expand Down
Loading