From cf109b40a2c786c0b75015a93b6049bce9d4bb31 Mon Sep 17 00:00:00 2001 From: Alexander Lyon Date: Thu, 16 May 2024 10:01:35 +0200 Subject: [PATCH] fix rustc bug in turbopack-trace-server --- crates/turbopack-trace-server/src/bottom_up.rs | 16 +++++++++------- crates/turbopack-trace-server/src/span_ref.rs | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/crates/turbopack-trace-server/src/bottom_up.rs b/crates/turbopack-trace-server/src/bottom_up.rs index b43f70bf44e08a..0576099df48afa 100644 --- a/crates/turbopack-trace-server/src/bottom_up.rs +++ b/crates/turbopack-trace-server/src/bottom_up.rs @@ -1,7 +1,5 @@ use std::{collections::HashMap, env, sync::Arc}; -use either::Either; - use crate::{ span::{SpanBottomUp, SpanIndex}, span_ref::SpanRef, @@ -36,16 +34,20 @@ impl SpanBottomUpBuilder { } pub fn build_bottom_up_graph<'a>( - spans: impl IntoIterator>, + spans: impl Iterator>, ) -> Vec> { 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. This error appears + // in certain cases when building next-swc. + let mut current_iterators: Vec>>> = + 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() { @@ -73,7 +75,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(); } diff --git a/crates/turbopack-trace-server/src/span_ref.rs b/crates/turbopack-trace-server/src/span_ref.rs index 3efa417b4b73b3..7439ef9d128ff7 100644 --- a/crates/turbopack-trace-server/src/span_ref.rs +++ b/crates/turbopack-trace-server/src/span_ref.rs @@ -332,9 +332,9 @@ impl<'a> SpanRef<'a> { pub fn bottom_up(self) -> impl Iterator> { 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, })