Remove Rc from line_counter

We no longer need this.
This commit is contained in:
Peter Ammon
2025-03-15 16:22:13 -07:00
parent d1c7e8d96f
commit a0a6edd303
2 changed files with 14 additions and 13 deletions

View File

@@ -74,7 +74,7 @@ pub enum EndExecutionReason {
error,
}
pub struct ExecutionContext {
pub struct ExecutionContext<'a> {
// The parsed source and its AST.
pstree: ParsedSourceRef,
@@ -84,7 +84,7 @@ pub struct ExecutionContext {
// Helper to count lines.
// This is shared with the Parser so that the Parser can access the current line.
line_counter: Rc<ScopedRefCell<LineCounter<ast::JobPipeline>>>,
line_counter: &'a ScopedRefCell<LineCounter<ast::JobPipeline>>,
/// The block IO chain.
/// For example, in `begin; foo ; end < file.txt` this would have the 'file.txt' IO.
@@ -111,13 +111,13 @@ macro_rules! report_error_formatted {
}};
}
impl<'a> ExecutionContext {
impl<'a> ExecutionContext<'a> {
/// Construct a context in preparation for evaluating a node in a tree, with the given block_io.
/// The execution context may access the parser and parent job group (if any) through ctx.
pub fn new(
pstree: ParsedSourceRef,
block_io: IoChain,
line_counter: Rc<ScopedRefCell<LineCounter<ast::JobPipeline>>>,
line_counter: &'a ScopedRefCell<LineCounter<ast::JobPipeline>>,
) -> Self {
Self {
pstree,
@@ -134,7 +134,7 @@ pub fn pstree(&self) -> &ParsedSourceRef {
pub fn eval_node(
&mut self,
ctx: &OperationContext<'_>,
node: &dyn Node,
node: &'a dyn Node,
associated_block: Option<BlockId>,
) -> EndExecutionReason {
match node.typ() {
@@ -1531,8 +1531,9 @@ fn run_1_job(
let _saved_eval_level = ctx.parser().push_scope(|s| s.eval_level += 1);
// Save the executing node.
let line_counter = Rc::clone(&self.line_counter);
let _saved_node = line_counter.scoped_set(job_node as *const _, |s| &mut s.node);
let _saved_node = self
.line_counter
.scoped_set(job_node as *const _, |s| &mut s.node);
// Profiling support.
let profile_item_id = ctx.parser().create_profile_item();

View File

@@ -398,7 +398,7 @@ pub enum CancelBehavior {
pub struct Parser {
/// A shared line counter. This is handed out to each execution context
/// so they can communicate the line number back to this Parser.
line_counter: Rc<ScopedRefCell<LineCounter<ast::JobPipeline>>>,
line_counter: ScopedRefCell<LineCounter<ast::JobPipeline>>,
/// The jobs associated with this parser.
job_list: RefCell<JobList>,
@@ -439,7 +439,7 @@ impl Parser {
/// Create a parser.
pub fn new(variables: Rc<EnvStack>, cancel_behavior: CancelBehavior) -> Parser {
let result = Self {
line_counter: Rc::new(ScopedRefCell::new(LineCounter::empty())),
line_counter: ScopedRefCell::new(LineCounter::empty()),
job_list: RefCell::default(),
wait_handles: RefCell::new(WaitHandleStore::new()),
block_list: RefCell::default(),
@@ -624,13 +624,13 @@ pub fn eval_node<T: Node>(
op_ctx.cancel_checker = cancel_checker;
// Restore the line counter.
let line_counter = Rc::clone(&self.line_counter);
let restore_line_counter =
line_counter.scoped_replace(ps.line_counter::<ast::JobPipeline>());
let restore_line_counter = self
.line_counter
.scoped_replace(ps.line_counter::<ast::JobPipeline>());
// Create a new execution context.
let mut execution_context =
ExecutionContext::new(ps.clone(), block_io.clone(), Rc::clone(&line_counter));
ExecutionContext::new(ps.clone(), block_io.clone(), &self.line_counter);
terminal_protocols_disable_ifn();