diff --git a/src/protocol/ast.rs b/src/protocol/ast.rs index c119e5ed087671302601906a25c5e0eff565789d..5800b6a77377c7065d6a1b62f336f81296b253c5 100644 --- a/src/protocol/ast.rs +++ b/src/protocol/ast.rs @@ -1170,30 +1170,35 @@ impl Statement { } } - pub fn span(&self) -> InputSpan { + pub fn maybe_span(&self) -> Option { match self { - Statement::Block(v) => v.span, - Statement::Local(v) => v.span(), - Statement::Labeled(v) => v.label.span, - Statement::If(v) => v.span, - Statement::While(v) => v.span, - Statement::Break(v) => v.span, - Statement::Continue(v) => v.span, - Statement::Synchronous(v) => v.span, - Statement::Fork(v) => v.span, - Statement::Select(v) => v.span, - Statement::Return(v) => v.span, - Statement::Goto(v) => v.span, - Statement::New(v) => v.span, - Statement::Expression(v) => v.span, + Statement::Block(v) => Some(v.span), + Statement::Local(v) => Some(v.span()), + Statement::Labeled(v) => Some(v.label.span), + Statement::If(v) => Some(v.span), + Statement::While(v) => Some(v.span), + Statement::Break(v) => Some(v.span), + Statement::Continue(v) => Some(v.span), + Statement::Synchronous(v) => Some(v.span), + Statement::Fork(v) => Some(v.span), + Statement::Select(v) => Some(v.span), + Statement::Return(v) => Some(v.span), + Statement::Goto(v) => Some(v.span), + Statement::New(v) => Some(v.span), + Statement::Expression(v) => Some(v.span), Statement::EndBlock(_) | Statement::EndIf(_) | Statement::EndWhile(_) | Statement::EndSynchronous(_) | Statement::EndFork(_) - | Statement::EndSelect(_) => unreachable!(), + | Statement::EndSelect(_) => None, } } + + pub fn span(&self) -> InputSpan { + return self.maybe_span().unwrap(); + } + pub fn link_next(&mut self, next: StatementId) { match self { Statement::Block(stmt) => stmt.next = next, diff --git a/src/protocol/eval/error.rs b/src/protocol/eval/error.rs index 81128b445a5c36ed8cda7034b2ca9d2f99084a8e..488097f6357b6d5e67f9d2eb2fd3fa387a06c09d 100644 --- a/src/protocol/eval/error.rs +++ b/src/protocol/eval/error.rs @@ -10,7 +10,7 @@ use super::executor::*; /// Represents a stack frame recorded in an error #[derive(Debug)] pub struct EvalFrame { - pub line: u32, + pub line: Option, pub module_name: String, pub procedure: String, // function or component pub is_func: bool, @@ -24,10 +24,15 @@ impl fmt::Display for EvalFrame { "component" }; + let line_str = match self.line { + Some(line_number) => line_number.to_string(), + None => String::from("??"), + }; + if self.module_name.is_empty() { - write!(f, "{} {}:{}", func_or_comp, &self.procedure, self.line) + write!(f, "{} {}:{}", func_or_comp, &self.procedure, line_str) } else { - write!(f, "{} {}:{}:{}", func_or_comp, &self.module_name, &self.procedure, self.line) + write!(f, "{} {}:{}:{}", func_or_comp, &self.module_name, &self.procedure, line_str) } } } @@ -50,7 +55,7 @@ impl EvalError { for frame in prompt.frames.iter() { let definition = &heap[frame.definition]; let statement = &heap[frame.position]; - let statement_span = statement.span(); + let statement_span = statement.maybe_span(); // Lookup module name, if it has one let module = modules.iter().find(|m| m.root_id == definition.defined_in).unwrap(); @@ -62,7 +67,7 @@ impl EvalError { last_module_source = &module.source; frames.push(EvalFrame{ - line: statement_span.begin.line, + line: statement_span.map(|v| v.begin.line), module_name, procedure: definition.identifier.value.as_str().to_string(), is_func: definition.kind == ProcedureKind::Function, diff --git a/src/runtime2/component/consensus.rs b/src/runtime2/component/consensus.rs index 05856ffc3820837f251057c98e963c98eb51ddf4..e4706c27995c39138d51ef1629058bcca6d0d004 100644 --- a/src/runtime2/component/consensus.rs +++ b/src/runtime2/component/consensus.rs @@ -331,7 +331,7 @@ impl Consensus { /// we've failed and wait until all the participants have been notified of /// the error. pub(crate) fn notify_sync_end_failure(&mut self, sched_ctx: &SchedulerCtx, comp_ctx: &CompCtx) -> SyncRoundDecision { - debug_assert_eq!(self.mode, Mode::SyncBusy); + // debug_assert_eq!(self.mode, Mode::SyncBusy); self.mode = Mode::SyncAwaitingSolution; let local_solution = self.generate_local_solution(comp_ctx, true); diff --git a/src/runtime2/tests/mod.rs b/src/runtime2/tests/mod.rs index b3988d25db7fc32e3077a29ad6b0d4589e2ade98..493bb3c46ee383e5ce2fb327a85bf7eec90af413 100644 --- a/src/runtime2/tests/mod.rs +++ b/src/runtime2/tests/mod.rs @@ -14,7 +14,7 @@ const NUM_THREADS: u32 = 1; pub(crate) fn compile_and_create_component(source: &str, routine_name: &str, args: ValueGroup) { let protocol = ProtocolDescription::parse(source.as_bytes()) .expect("successful compilation"); - let runtime = Runtime::new(NUM_THREADS, LogLevel::None, protocol) + let runtime = Runtime::new(NUM_THREADS, LOG_LEVEL, protocol) .expect("successful runtime startup"); create_component(&runtime, "", routine_name, args); }