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:
KtorZ
2024-01-17 17:23:34 +01:00
parent 86146ae7f4
commit d27ea98a8f
12 changed files with 145 additions and 73 deletions

View File

@@ -36,7 +36,7 @@ pub fn exec(
) -> miette::Result<()> {
with_project(directory.as_deref(), false, |p| {
if rebuild {
p.build(false, Tracing::NoTraces, Tracing::NoTraces)?;
p.build(false, Tracing::silent())?;
}
let title = module.as_ref().map(|m| {

View File

@@ -31,7 +31,7 @@ pub fn exec(
) -> miette::Result<()> {
with_project(directory.as_deref(), false, |p| {
if rebuild {
p.build(false, Tracing::NoTraces, Tracing::NoTraces)?;
p.build(false, Tracing::silent())?;
}
let title = module.as_ref().map(|m| {

View File

@@ -31,7 +31,7 @@ pub fn exec(
) -> miette::Result<()> {
with_project(directory.as_deref(), false, |p| {
if rebuild {
p.build(false, Tracing::NoTraces, Tracing::NoTraces)?;
p.build(false, Tracing::silent())?;
}
let title = module.as_ref().map(|m| {

View File

@@ -1,4 +1,7 @@
use aiken_lang::ast::{TraceLevel, Tracing};
use aiken_project::watch::{self, watch_project, with_project};
use clap::builder::MapValueParser;
use clap::builder::{PossibleValuesParser, TypedValueParser};
use std::{path::PathBuf, process};
#[derive(clap::Args)]
@@ -19,13 +22,18 @@ pub struct Args {
#[clap(short, long)]
uplc: bool,
/// Do not remove traces when generating code
#[clap(short, long)]
keep_traces: bool,
/// Do not remove traces when generating code.
#[clap(short, long, value_parser=keep_traces_parser(), default_missing_value="all")]
keep_traces: Option<fn(TraceLevel) -> Tracing>,
/// Add code gen traces when generating code
#[clap(short, long)]
code_gen_traces: bool,
/// Choose the level of tracing
/// - silent: disable traces altogether
/// - compact: only culprit line numbers are shown on failures
/// - verbose: enable full verbose traces as provided by the user or the compiler
///
///
#[clap(short, long, value_parser=trace_level_parser(), default_value_t=TraceLevel::Verbose, verbatim_doc_comment)]
trace_level: TraceLevel,
}
pub fn exec(
@@ -35,18 +43,52 @@ pub fn exec(
watch,
uplc,
keep_traces,
code_gen_traces,
trace_level,
}: Args,
) -> miette::Result<()> {
let result = if watch {
watch_project(directory.as_deref(), watch::default_filter, 500, |p| {
p.build(uplc, keep_traces.into(), code_gen_traces.into())
p.build(
uplc,
match keep_traces {
Some(keep_traces) => keep_traces(trace_level),
None => Tracing::All(trace_level),
},
)
})
} else {
with_project(directory.as_deref(), deny, |p| {
p.build(uplc, keep_traces.into(), code_gen_traces.into())
p.build(
uplc,
match keep_traces {
Some(keep_traces) => keep_traces(trace_level),
None => Tracing::All(trace_level),
},
)
})
};
result.map_err(|_| process::exit(1))
}
#[allow(clippy::type_complexity)]
pub fn keep_traces_parser(
) -> MapValueParser<PossibleValuesParser, fn(String) -> fn(TraceLevel) -> Tracing> {
PossibleValuesParser::new(["user-defined", "compiler-generated", "all"]).map(
|s: String| match s.as_str() {
"user-defined" => Tracing::UserDefined,
"compiler-generated" => Tracing::CompilerGenerated,
"all" => Tracing::All,
_ => unreachable!(),
},
)
}
#[allow(clippy::type_complexity)]
pub fn trace_level_parser() -> MapValueParser<PossibleValuesParser, fn(String) -> TraceLevel> {
PossibleValuesParser::new(["silent", "verbose"]).map(|s| match s.as_str() {
"silent" => TraceLevel::Silent,
"verbose" => TraceLevel::Verbose,
_ => unreachable!(),
})
}

View File

@@ -1,3 +1,5 @@
use super::build::{keep_traces_parser, trace_level_parser};
use aiken_lang::ast::{TraceLevel, Tracing};
use aiken_project::watch::{self, watch_project, with_project};
use std::{path::PathBuf, process};
@@ -34,13 +36,17 @@ pub struct Args {
#[clap(short, long)]
exact_match: bool,
/// Remove traces when generating code (including tests)
#[clap(long)]
no_traces: bool,
/// Do not remove traces when generating code
#[clap(short, long, value_parser=keep_traces_parser(), default_missing_value="all")]
keep_traces: Option<fn(TraceLevel) -> Tracing>,
/// Remove code gen traces when generating code (including tests)
#[clap(long)]
no_code_gen_traces: bool,
/// Choose the level of tracing
/// - silent: disable traces altogether
/// - compact: only culprit line numbers are shown on failures
/// - verbose: enable full verbose traces as provided by the user or the compiler
/// [optional]
#[clap(short, long, value_parser=trace_level_parser(), default_value_t=TraceLevel::Verbose, verbatim_doc_comment)]
trace_level: TraceLevel,
}
pub fn exec(
@@ -51,9 +57,9 @@ pub fn exec(
debug,
match_tests,
exact_match,
no_traces,
no_code_gen_traces,
watch,
keep_traces,
trace_level,
}: Args,
) -> miette::Result<()> {
let result = if watch {
@@ -63,8 +69,10 @@ pub fn exec(
match_tests.clone(),
debug,
exact_match,
(!no_traces).into(),
(!no_code_gen_traces).into(),
match keep_traces {
Some(keep_traces) => keep_traces(trace_level),
None => Tracing::All(trace_level),
},
)
})
} else {
@@ -74,8 +82,10 @@ pub fn exec(
match_tests.clone(),
debug,
exact_match,
(!no_traces).into(),
(!no_code_gen_traces).into(),
match keep_traces {
Some(keep_traces) => keep_traces(trace_level),
None => Tracing::All(trace_level),
},
)
})
};