Skip to content

Commit

Permalink
Revert "Issue Reporters (vercel/turborepo#3707)" (vercel/turborepo#3796)
Browse files Browse the repository at this point in the history
This reverts commit 27b64ac.

This commit makes the `turbotrace` hanging, x-ref:
https://vercel.slack.com/archives/C02UJN0A1UL/p1676369060652879
  • Loading branch information
Brooooooklyn authored Feb 14, 2023
1 parent 79bd442 commit 3ca7c2d
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 167 deletions.
85 changes: 24 additions & 61 deletions crates/next-dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ use owo_colors::OwoColorize;
use turbo_malloc::TurboMalloc;
use turbo_tasks::{
util::{FormatBytes, FormatDuration},
CollectiblesSource, RawVc, StatsType, TransientInstance, TransientValue, TurboTasks,
TurboTasksBackendApi, Value,
RawVc, StatsType, TransientInstance, TransientValue, TurboTasks, TurboTasksBackendApi, Value,
};
use turbo_tasks_fs::{DiskFileSystemVc, FileSystem, FileSystemVc};
use turbo_tasks_memory::MemoryBackend;
use turbopack_cli_utils::issue::{ConsoleUiVc, LogOptions};
use turbopack_cli_utils::issue::{ConsoleUi, ConsoleUiVc, LogOptions};
use turbopack_core::{
environment::ServerAddr,
issue::{IssueReporter, IssueReporterVc, IssueSeverity, IssueVc},
issue::IssueSeverity,
resolve::{parse::RequestVc, pattern::QueryMapVc},
server_fs::ServerFileSystemVc,
};
Expand Down Expand Up @@ -63,7 +62,6 @@ pub struct NextDevServerBuilder {
entry_requests: Vec<EntryRequest>,
eager_compile: bool,
hostname: Option<IpAddr>,
issue_reporter: Option<Box<dyn IssueReporterProvider>>,
port: Option<u16>,
browserslist_query: String,
log_level: IssueSeverity,
Expand All @@ -85,7 +83,6 @@ impl NextDevServerBuilder {
entry_requests: vec![],
eager_compile: false,
hostname: None,
issue_reporter: None,
port: None,
browserslist_query: "last 1 Chrome versions, last 1 Firefox versions, last 1 Safari \
versions, last 1 Edge versions"
Expand Down Expand Up @@ -142,14 +139,6 @@ impl NextDevServerBuilder {
self
}

pub fn issue_reporter(
mut self,
issue_reporter: Box<dyn IssueReporterProvider>,
) -> NextDevServerBuilder {
self.issue_reporter = Some(issue_reporter);
self
}

/// Attempts to find an open port to bind.
fn find_port(&self, host: IpAddr, port: u16, max_attempts: u16) -> Result<DevServerBuilder> {
// max_attempts of 1 means we loop 0 times.
Expand Down Expand Up @@ -203,72 +192,58 @@ impl NextDevServerBuilder {
let show_all = self.show_all;
let log_detail = self.log_detail;
let browserslist_query = self.browserslist_query;
let log_options = Arc::new(LogOptions {
let log_options = LogOptions {
current_dir: current_dir().unwrap(),
show_all,
log_detail,
log_level: self.log_level,
});
};
let entry_requests = Arc::new(self.entry_requests);
let console_ui = Arc::new(ConsoleUi::new(log_options));
let console_ui_to_dev_server = console_ui.clone();
let server_addr = Arc::new(server.addr);
let tasks = turbo_tasks.clone();
let issue_provider = self.issue_reporter.unwrap_or_else(|| {
// Initialize a ConsoleUi reporter if no custom reporter was provided
Box::new(move || ConsoleUiVc::new(log_options.clone().into()).into())
});
let issue_reporter_arc = Arc::new(move || issue_provider.get_issue_reporter());

let get_issue_reporter = issue_reporter_arc.clone();
let source = move || {
source(
root_dir.clone(),
project_dir.clone(),
entry_requests.clone().into(),
eager_compile,
turbo_tasks.clone().into(),
get_issue_reporter(),
console_ui.clone().into(),
browserslist_query.clone(),
server_addr.clone().into(),
)
};

Ok(server.serve(tasks, source, issue_reporter_arc.clone()))
Ok(server.serve(tasks, source, console_ui_to_dev_server))
}
}

async fn handle_issues<T: Into<RawVc> + CollectiblesSource + Copy>(
source: T,
issue_reporter: IssueReporterVc,
) -> Result<()> {
let issues = IssueVc::peek_issues_with_path(source)
.await?
.strongly_consistent()
async fn handle_issues<T: Into<RawVc>>(source: T, console_ui: ConsoleUiVc) -> Result<()> {
let state = console_ui
.group_and_display_issues(TransientValue::new(source.into()))
.await?;

issue_reporter.report_issues(
TransientInstance::new(issues.clone()),
TransientValue::new(source.into()),
);

if issues.has_fatal().await? {
if state.has_fatal {
Err(anyhow!("Fatal issue(s) occurred"))
} else {
Ok(())
}
}

#[turbo_tasks::function]
async fn project_fs(project_dir: &str, issue_reporter: IssueReporterVc) -> Result<FileSystemVc> {
async fn project_fs(project_dir: &str, console_ui: ConsoleUiVc) -> Result<FileSystemVc> {
let disk_fs = DiskFileSystemVc::new("project".to_string(), project_dir.to_string());
handle_issues(disk_fs, issue_reporter).await?;
handle_issues(disk_fs, console_ui).await?;
disk_fs.await?.start_watching()?;
Ok(disk_fs.into())
}

#[turbo_tasks::function]
async fn output_fs(project_dir: &str, issue_reporter: IssueReporterVc) -> Result<FileSystemVc> {
async fn output_fs(project_dir: &str, console_ui: ConsoleUiVc) -> Result<FileSystemVc> {
let disk_fs = DiskFileSystemVc::new("output".to_string(), project_dir.to_string());
handle_issues(disk_fs, issue_reporter).await?;
handle_issues(disk_fs, console_ui).await?;
disk_fs.await?.start_watching()?;
Ok(disk_fs.into())
}
Expand All @@ -281,12 +256,13 @@ async fn source(
entry_requests: TransientInstance<Vec<EntryRequest>>,
eager_compile: bool,
turbo_tasks: TransientInstance<TurboTasks<MemoryBackend>>,
issue_reporter: IssueReporterVc,
console_ui: TransientInstance<ConsoleUi>,
browserslist_query: String,
server_addr: TransientInstance<SocketAddr>,
) -> Result<ContentSourceVc> {
let output_fs = output_fs(&project_dir, issue_reporter);
let fs = project_fs(&root_dir, issue_reporter);
let console_ui = (*console_ui).clone().cell();
let output_fs = output_fs(&project_dir, console_ui);
let fs = project_fs(&root_dir, console_ui);
let project_relative = project_dir.strip_prefix(&root_dir).unwrap();
let project_relative = project_relative
.strip_prefix(MAIN_SEPARATOR)
Expand Down Expand Up @@ -396,9 +372,9 @@ async fn source(
.cell()
.into();

handle_issues(dev_server_fs, issue_reporter).await?;
handle_issues(web_source, issue_reporter).await?;
handle_issues(page_source, issue_reporter).await?;
handle_issues(dev_server_fs, console_ui).await?;
handle_issues(web_source, console_ui).await?;
handle_issues(page_source, console_ui).await?;

Ok(source)
}
Expand Down Expand Up @@ -575,16 +551,3 @@ fn profile_timeout<T>(
) -> impl Future<Output = T> {
future
}

pub trait IssueReporterProvider: Send + Sync + 'static {
fn get_issue_reporter(&self) -> IssueReporterVc;
}

impl<T> IssueReporterProvider for T
where
T: Fn() -> IssueReporterVc + Send + Sync + Clone + 'static,
{
fn get_issue_reporter(&self) -> IssueReporterVc {
self()
}
}
27 changes: 12 additions & 15 deletions crates/node-file-trace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ use turbopack::{
resolve_options_context::ResolveOptionsContext, transition::TransitionsByNameVc,
ModuleAssetContextVc,
};
use turbopack_cli_utils::issue::{ConsoleUiVc, IssueSeverityCliOption, LogOptions};
use turbopack_cli_utils::issue::{ConsoleUi, IssueSeverityCliOption, LogOptions};
use turbopack_core::{
asset::{Asset, AssetVc, AssetsVc},
context::{AssetContext, AssetContextVc},
environment::{EnvironmentIntention, EnvironmentVc, ExecutionEnvironment, NodeJsEnvironment},
issue::{IssueReporter, IssueSeverity, IssueVc},
issue::{IssueSeverity, IssueVc},
reference::all_assets,
resolve::options::{ImportMapping, ResolvedMap},
source_asset::SourceAssetVc,
Expand Down Expand Up @@ -487,27 +487,24 @@ async fn run<B: Backend + 'static, F: Future<Output = ()>>(
let (sender, mut receiver) = channel(1);
let dir = current_dir().unwrap();
let tt = create_tt();
let console_ui = Arc::new(ConsoleUi::new(LogOptions {
current_dir: dir.clone(),
show_all,
log_detail,
log_level: log_level.map_or_else(|| IssueSeverity::Error, |l| l.0),
}));
let task = tt.spawn_root_task(move || {
let console_ui = ConsoleUiVc::new(TransientInstance::new(LogOptions {
current_dir: dir.clone(),
show_all,
log_detail,
log_level: log_level.map_or_else(|| IssueSeverity::Error, |l| l.0),
}));
let dir = dir.clone();
let args = args.clone();
let console_ui = console_ui.clone();
let sender = sender.clone();
Box::pin(async move {
let output = main_operation(TransientValue::new(dir.clone()), args.clone().into());

let source = TransientValue::new(output.into());
let issues = IssueVc::peek_issues_with_path(output)
.await?
.strongly_consistent()
.await?;
let console_ui = (*console_ui).clone().cell();
console_ui
.as_issue_reporter()
.report_issues(TransientInstance::new(issues), source);
.group_and_display_issues(TransientValue::new(output.into()))
.await?;

if has_return_value {
let output_read_ref = output.await?;
Expand Down
61 changes: 36 additions & 25 deletions crates/turbopack-cli-utils/src/issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ use std::{
use anyhow::{anyhow, Result};
use crossterm::style::{StyledContent, Stylize};
use owo_colors::{OwoColorize as _, Style};
use turbo_tasks::{
RawVc, ReadRef, TransientInstance, TransientValue, TryJoinIterExt, ValueToString,
};
use turbo_tasks::{RawVc, TransientValue, TryJoinIterExt, ValueToString};
use turbo_tasks_fs::{
attach::AttachedFileSystemVc,
source_context::{get_source_context, SourceContextLine},
to_sys_path, FileLinesContent, FileSystemPathVc,
};
use turbopack_core::issue::{
CapturedIssues, Issue, IssueProcessingPathItem, IssueReporter, IssueReporterVc, IssueSeverity,
OptionIssueProcessingPathItemsVc, PlainIssue, PlainIssueSource,
Issue, IssueProcessingPathItem, IssueSeverity, IssueVc, OptionIssueProcessingPathItemsVc,
PlainIssue, PlainIssueSource,
};

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
Expand Down Expand Up @@ -414,34 +412,41 @@ impl PartialEq for ConsoleUi {
}
}

#[turbo_tasks::value_impl]
impl ConsoleUiVc {
#[turbo_tasks::function]
pub fn new(options: TransientInstance<LogOptions>) -> Self {
impl ConsoleUi {
pub fn new(options: LogOptions) -> Self {
ConsoleUi {
options: (*options).clone(),
options,
seen: Arc::new(Mutex::new(SeenIssues::new())),
}
.cell()
}
}

#[turbo_tasks::value(transparent)]
pub struct DisplayIssueState {
pub has_fatal: bool,
pub has_issues: bool,
pub has_new_issues: bool,
}

#[turbo_tasks::value_impl]
impl IssueReporter for ConsoleUi {
impl ConsoleUiVc {
#[turbo_tasks::function]
async fn report_issues(
&self,
issues: TransientInstance<ReadRef<CapturedIssues>>,
pub async fn group_and_display_issues(
self,
source: TransientValue<RawVc>,
) -> Result<()> {
let issues = &*issues;
let LogOptions {
) -> Result<DisplayIssueStateVc> {
let source = source.into_value();
let this = self.await?;

let issues = IssueVc::peek_issues_with_path(source).await?;
let issues = issues.await?;
let &LogOptions {
ref current_dir,
show_all,
log_detail,
log_level,
..
} = self.options;
} = &this.options;
let mut grouped_issues: GroupedIssues = HashMap::new();

let issues = issues
Expand All @@ -459,11 +464,11 @@ impl IssueReporter for ConsoleUi {
.iter()
.map(|(_, _, _, id)| *id)
.collect::<HashSet<_>>();
let mut new_ids = self
.seen
.lock()
.unwrap()
.new_ids(source.into_value(), issue_ids);
let mut new_ids = this.seen.lock().unwrap().new_ids(source, issue_ids);

let mut has_fatal = false;
let has_issues = !issues.is_empty();
let has_new_issues = !new_ids.is_empty();

for (plain_issue, path, context, id) in issues {
if !new_ids.remove(&id) {
Expand All @@ -474,6 +479,7 @@ impl IssueReporter for ConsoleUi {
let context_path = make_relative_to_cwd(context, current_dir).await?;
let category = &plain_issue.category;
let title = &plain_issue.title;
has_fatal = severity == IssueSeverity::Fatal;
let severity_map = grouped_issues
.entry(severity)
.or_insert_with(Default::default);
Expand Down Expand Up @@ -606,7 +612,12 @@ impl IssueReporter for ConsoleUi {
}
}

Ok(())
Ok(DisplayIssueState {
has_fatal,
has_issues,
has_new_issues,
}
.cell())
}
}

Expand Down
27 changes: 1 addition & 26 deletions crates/turbopack-core/src/issue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ use futures::FutureExt;
use turbo_tasks::{
emit,
primitives::{BoolVc, StringVc, U64Vc},
CollectiblesSource, RawVc, ReadRef, TransientInstance, TransientValue, TryJoinIterExt,
ValueToString, ValueToStringVc,
CollectiblesSource, ReadRef, TryJoinIterExt, ValueToString, ValueToStringVc,
};
use turbo_tasks_fs::{
FileContent, FileContentReadRef, FileLine, FileLinesContent, FileSystemPathReadRef,
Expand Down Expand Up @@ -341,21 +340,6 @@ pub struct CapturedIssues {
processing_path: ItemIssueProcessingPathVc,
}

impl CapturedIssues {
pub async fn has_fatal(&self) -> Result<bool> {
let mut has_fatal = false;

for issue in self.issues.iter() {
let severity = *issue.severity().await?;
if severity == IssueSeverity::Fatal {
has_fatal = true;
break;
}
}
Ok(has_fatal)
}
}

#[turbo_tasks::value_impl]
impl CapturedIssuesVc {
#[turbo_tasks::function]
Expand Down Expand Up @@ -584,12 +568,3 @@ impl PlainAssetVc {
.cell())
}
}

#[turbo_tasks::value_trait]
pub trait IssueReporter {
fn report_issues(
&self,
issues: TransientInstance<ReadRef<CapturedIssues>>,
source: TransientValue<RawVc>,
);
}
Loading

0 comments on commit 3ca7c2d

Please sign in to comment.