diff --git a/src/parse_execution.rs b/src/parse_execution.rs index e3a065633..102404e01 100644 --- a/src/parse_execution.rs +++ b/src/parse_execution.rs @@ -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>>, + line_counter: &'a ScopedRefCell>, /// 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>>, + line_counter: &'a ScopedRefCell>, ) -> 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, ) -> 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(); diff --git a/src/parser.rs b/src/parser.rs index 7cd977a69..4ab2a3b04 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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>>, + line_counter: ScopedRefCell>, /// The jobs associated with this parser. job_list: RefCell, @@ -439,7 +439,7 @@ impl Parser { /// Create a parser. pub fn new(variables: Rc, 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( 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::()); + let restore_line_counter = self + .line_counter + .scoped_replace(ps.line_counter::()); // 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();