Skip to content

Commit

Permalink
Drop superconsole::State
Browse files Browse the repository at this point in the history
Summary:
Now all the state is passed explicitly to the components. State is no longer used.

State is inconvenient because it is not statically typechecked, so it is fragile, especially for components which requests different parts of state conditionally.

This diff stack addresses the issue facebookincubator/superconsole#6

Next step would be removal of the state from `superconsole` crate, but before that, other users of `superconsole` need to be migrated.

Reviewed By: themarwhal

Differential Revision: D44815383

fbshipit-source-id: 5cd8caea3a9663ff8dfd171921167e4c24915d52
  • Loading branch information
stepancheg authored and facebook-github-bot committed Apr 13, 2023
1 parent f9638a1 commit 34b0ff5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 31 deletions.
8 changes: 3 additions & 5 deletions app/buck2_client/src/commands/log/what_up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,8 @@ impl WhatUpCommand {
StreamValue::Result(result) => {
let result = StatefulSuperConsole::render_result_errors(&result);
super_console.emit(result);
super_console.finalize(
&Self::component(&super_console_state),
&super_console_state.state(),
)?;
super_console
.finalize(&Self::component(&super_console_state), &State::new())?;
buck2_client_ctx::eprintln!("No open spans to render when log ended")?;
return Ok(());
}
Expand All @@ -117,7 +115,7 @@ impl WhatUpCommand {

super_console.finalize_with_mode(
&Self::component(&super_console_state),
&super_console_state.state(),
&State::new(),
DrawMode::Normal,
)?;
anyhow::Ok(())
Expand Down
31 changes: 5 additions & 26 deletions app/buck2_client_ctx/src/subscribers/superconsole.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ impl StatefulSuperConsole {
header: &self.header,
state: &self.state,
},
&self.state.state(),
&State::new(),
DrawMode::Normal,
),
None => Err(anyhow::anyhow!("Cannot render non-existent superconsole")),
Expand Down Expand Up @@ -402,27 +402,6 @@ impl SuperConsoleState {
.update_event_observer(receive_time, event)
}

// Collect all state to send to super console. Note that the SpanTracker state is held in the
// SimpleConsole so that if we downgrade to the SimpleConsole, we don't lose tracked spans.
pub fn state(&self) -> superconsole::State {
let observer = self.simple_console.observer();

superconsole::state![
&self.config,
&self.current_tick,
&self.time_speed,
observer.spans(),
observer.action_stats(),
observer.test_state(),
observer.session_info(),
observer.re_state(),
observer.io_state(),
observer.extra().dice_state(),
observer.extra().debug_events(),
observer.starlark_debugger_state(),
]
}

pub fn session_info(&self) -> &SessionInfo {
self.simple_console.observer.session_info()
}
Expand Down Expand Up @@ -549,7 +528,7 @@ impl UnpackingEventSubscriber for StatefulSuperConsole {
header: &self.header,
state: &self.state,
},
&self.state.state(),
&State::new(),
)?;
}

Expand Down Expand Up @@ -620,7 +599,7 @@ impl UnpackingEventSubscriber for StatefulSuperConsole {
header: &self.header,
state: &self.state,
},
&self.state.state(),
&State::new(),
)
}
None => {
Expand All @@ -642,7 +621,7 @@ impl UnpackingEventSubscriber for StatefulSuperConsole {
header: &self.header,
state: &self.state,
},
&self.state.state(),
&State::new(),
)
}
None => Ok(()),
Expand All @@ -656,7 +635,7 @@ impl UnpackingEventSubscriber for StatefulSuperConsole {
header: &self.header,
state: &self.state,
},
&self.state.state(),
&State::new(),
),
None => Ok(()),
}
Expand Down

0 comments on commit 34b0ff5

Please sign in to comment.