Rework tracing arguments to --keep-traces & --trace-level
This allows for a more fine-grained control over how the traces are showed. Now users can instrument the compiler to preserve only their user-defined traces, or the only the compiler, or all, or none. We also want to add another trace level on top of that: 'compact' to only show line numbers; which will work for both user-defined and/or compiler-generated traces.
This commit is contained in:
@@ -1360,25 +1360,50 @@ pub enum TraceKind {
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Tracing {
|
||||
NoTraces,
|
||||
KeepTraces,
|
||||
UserDefined(TraceLevel),
|
||||
CompilerGenerated(TraceLevel),
|
||||
All(TraceLevel),
|
||||
}
|
||||
|
||||
impl From<bool> for Tracing {
|
||||
fn from(keep: bool) -> Self {
|
||||
if keep {
|
||||
Tracing::KeepTraces
|
||||
} else {
|
||||
Tracing::NoTraces
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum TraceLevel {
|
||||
Silent, // No traces
|
||||
// Compact, // Line numbers only
|
||||
Verbose, // Full verbose traces as provided by the user or the compiler
|
||||
}
|
||||
|
||||
impl Tracing {
|
||||
pub fn silent() -> Self {
|
||||
Tracing::All(TraceLevel::Silent)
|
||||
}
|
||||
|
||||
/// Get the tracing level based on the context we're in.
|
||||
pub fn trace_level(&self, is_code_gen: bool) -> TraceLevel {
|
||||
match self {
|
||||
Tracing::UserDefined(lvl) => {
|
||||
if is_code_gen {
|
||||
TraceLevel::Silent
|
||||
} else {
|
||||
*lvl
|
||||
}
|
||||
}
|
||||
Tracing::CompilerGenerated(lvl) => {
|
||||
if is_code_gen {
|
||||
*lvl
|
||||
} else {
|
||||
TraceLevel::Silent
|
||||
}
|
||||
}
|
||||
Tracing::All(lvl) => *lvl,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Tracing> for bool {
|
||||
fn from(value: Tracing) -> Self {
|
||||
match value {
|
||||
Tracing::NoTraces => false,
|
||||
Tracing::KeepTraces => true,
|
||||
impl Display for TraceLevel {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
|
||||
match self {
|
||||
TraceLevel::Silent => f.write_str("silent"),
|
||||
TraceLevel::Verbose => f.write_str("verbose"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
ast::{Definition, ModuleKind, Tracing, TypedModule, UntypedModule},
|
||||
ast::{Definition, ModuleKind, TraceLevel, Tracing, TypedModule, UntypedModule},
|
||||
builtins,
|
||||
expr::TypedExpr,
|
||||
parser,
|
||||
@@ -31,7 +31,7 @@ fn check_module(
|
||||
kind,
|
||||
"test/project",
|
||||
&module_types,
|
||||
Tracing::KeepTraces,
|
||||
Tracing::All(TraceLevel::Verbose),
|
||||
&mut warnings,
|
||||
);
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ use crate::{
|
||||
ast::{
|
||||
Annotation, Arg, ArgName, AssignmentKind, BinOp, Bls12_381Point, ByteArrayFormatPreference,
|
||||
CallArg, ClauseGuard, Constant, Curve, IfBranch, LogicalOpChainKind, RecordUpdateSpread,
|
||||
Span, TraceKind, Tracing, TypedArg, TypedCallArg, TypedClause, TypedClauseGuard,
|
||||
TypedIfBranch, TypedPattern, TypedRecordUpdateArg, UnOp, UntypedArg, UntypedClause,
|
||||
UntypedClauseGuard, UntypedIfBranch, UntypedPattern, UntypedRecordUpdateArg,
|
||||
Span, TraceKind, TraceLevel, Tracing, TypedArg, TypedCallArg, TypedClause,
|
||||
TypedClauseGuard, TypedIfBranch, TypedPattern, TypedRecordUpdateArg, UnOp, UntypedArg,
|
||||
UntypedClause, UntypedClauseGuard, UntypedIfBranch, UntypedPattern, UntypedRecordUpdateArg,
|
||||
},
|
||||
builtins::{bool, byte_array, function, g1_element, g2_element, int, list, string, tuple},
|
||||
expr::{FnStyle, TypedExpr, UntypedExpr},
|
||||
@@ -436,9 +436,9 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||
|
||||
self.unify(bool(), typed_value.tipo(), typed_value.location(), false)?;
|
||||
|
||||
match self.tracing {
|
||||
Tracing::NoTraces => Ok(typed_value),
|
||||
Tracing::KeepTraces => Ok(TypedExpr::If {
|
||||
match self.tracing.trace_level(false) {
|
||||
TraceLevel::Silent => Ok(typed_value),
|
||||
TraceLevel::Verbose => Ok(TypedExpr::If {
|
||||
location,
|
||||
branches: vec1::vec1![IfBranch {
|
||||
condition: typed_value,
|
||||
@@ -1817,9 +1817,9 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
|
||||
})
|
||||
}
|
||||
|
||||
match self.tracing {
|
||||
Tracing::NoTraces => Ok(then),
|
||||
Tracing::KeepTraces => Ok(TypedExpr::Trace {
|
||||
match self.tracing.trace_level(false) {
|
||||
TraceLevel::Silent => Ok(then),
|
||||
TraceLevel::Verbose => Ok(TypedExpr::Trace {
|
||||
location,
|
||||
tipo,
|
||||
then: Box::new(then),
|
||||
|
||||
Reference in New Issue
Block a user