Skip to content

Commit

Permalink
Merge pull request #852 from candy-lang/support-all-tracingmodes-in-cli
Browse files Browse the repository at this point in the history
Support all `TracingMode`s in CLI
  • Loading branch information
JonasWanke authored Jan 6, 2024
2 parents 1eec5f6 + deceaac commit a68dbb9
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 90 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 56 additions & 33 deletions compiler/cli/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,47 @@ pub struct PathAndExecutionTargetAndTracing {
#[arg(long, value_enum, default_value_t = ExecutionTargetKind::Module)]
execution_target: ExecutionTargetKind,

#[arg(long)]
register_fuzzables: bool,

#[arg(long)]
trace_calls: bool,

#[arg(long)]
trace_evaluated_expressions: bool,
// The tracing modes can be specified as follows:
//
// - not specified or `--register-fuzzables=off`: off
// - `--register-fuzzables` or `--register-fuzzables=only-current`: only current
// - `--register-fuzzables=all`: all
//
// (Same for `trace-calls` and `evaluated-expressions`.)
#[arg(
long,
default_value("off"),
default_missing_value("only-current"),
num_args(0..=1),
require_equals(true)
)]
register_fuzzables: TracingMode,

#[arg(
long,
default_value("off"),
default_missing_value("only-current"),
num_args(0..=1),
require_equals(true)
)]
trace_calls: TracingMode,

#[arg(
long,
default_value("off"),
default_missing_value("only-current"),
num_args(0..=1),
require_equals(true)
)]
trace_evaluated_expressions: TracingMode,
}
impl PathAndExecutionTargetAndTracing {
#[must_use]
const fn to_tracing_config(&self) -> TracingConfig {
TracingConfig {
register_fuzzables: TracingMode::only_current_or_off(self.register_fuzzables),
calls: TracingMode::only_current_or_off(self.trace_calls),
evaluated_expressions: TracingMode::only_current_or_off(
self.trace_evaluated_expressions,
),
register_fuzzables: self.register_fuzzables,
calls: self.trace_calls,
evaluated_expressions: self.trace_evaluated_expressions,
}
}
}
Expand Down Expand Up @@ -165,40 +188,40 @@ pub fn debug(options: Options) -> ProgramResult {
let module = module_for_path(options.path.clone())?;
let execution_target = options.execution_target.resolve(module.clone());
let tracing = options.to_tracing_config();
let mir = db.mir(execution_target, tracing.clone());
let mir = db.mir(execution_target, tracing);
mir.ok()
.map(|(mir, _)| RichIr::for_mir(&module, &mir, &tracing))
.map(|(mir, _)| RichIr::for_mir(&module, &mir, tracing))
}
Options::OptimizedMir(options) => {
let module = module_for_path(options.path.clone())?;
let execution_target = options.execution_target.resolve(module.clone());
let tracing = options.to_tracing_config();
let mir = db.optimized_mir(execution_target, tracing.clone());
let mir = db.optimized_mir(execution_target, tracing);
mir.ok()
.map(|(mir, _, _)| RichIr::for_optimized_mir(&module, &mir, &tracing))
.map(|(mir, _, _)| RichIr::for_optimized_mir(&module, &mir, tracing))
}
Options::Lir(options) => {
let module = module_for_path(options.path.clone())?;
let execution_target = options.execution_target.resolve(module.clone());
let tracing = options.to_tracing_config();
let lir = db.lir(execution_target, tracing.clone());
let lir = db.lir(execution_target, tracing);
lir.ok()
.map(|(lir, _)| RichIr::for_lir(&module, &lir, &tracing))
.map(|(lir, _)| RichIr::for_lir(&module, &lir, tracing))
}
Options::OptimizedLir(options) => {
let module = module_for_path(options.path.clone())?;
let execution_target = options.execution_target.resolve(module.clone());
let tracing = options.to_tracing_config();
let lir = db.optimized_lir(execution_target, tracing.clone());
let lir = db.optimized_lir(execution_target, tracing);
lir.ok()
.map(|(lir, _)| RichIr::for_optimized_lir(&module, &lir, &tracing))
.map(|(lir, _)| RichIr::for_optimized_lir(&module, &lir, tracing))
}
Options::VmByteCode(options) => {
let module = module_for_path(options.path.clone())?;
let execution_target = options.execution_target.resolve(module.clone());
let tracing = options.to_tracing_config();
let (vm_byte_code, _) = compile_byte_code(&db, execution_target, tracing.clone());
Some(RichIr::for_byte_code(&module, &vm_byte_code, &tracing))
let (vm_byte_code, _) = compile_byte_code(&db, execution_target, tracing);
Some(RichIr::for_byte_code(&module, &vm_byte_code, tracing))
}
#[cfg(feature = "inkwell")]
Options::LlvmIr(options) => {
Expand Down Expand Up @@ -380,35 +403,35 @@ impl GoldOptions {
visit("HIR", hir.text);

let (mir, _) = db
.mir(execution_target.clone(), Self::TRACING_CONFIG.clone())
.mir(execution_target.clone(), Self::TRACING_CONFIG)
.unwrap();
let mir = RichIr::for_mir(&module, &mir, &Self::TRACING_CONFIG);
let mir = RichIr::for_mir(&module, &mir, Self::TRACING_CONFIG);
visit("MIR", mir.text);

let (optimized_mir, _, _) = db
.optimized_mir(execution_target.clone(), Self::TRACING_CONFIG.clone())
.optimized_mir(execution_target.clone(), Self::TRACING_CONFIG)
.unwrap();
let optimized_mir =
RichIr::for_optimized_mir(&module, &optimized_mir, &Self::TRACING_CONFIG);
RichIr::for_optimized_mir(&module, &optimized_mir, Self::TRACING_CONFIG);
visit("Optimized MIR", optimized_mir.text);

let (lir, _) = db
.lir(execution_target.clone(), Self::TRACING_CONFIG.clone())
.lir(execution_target.clone(), Self::TRACING_CONFIG)
.unwrap();
let lir = RichIr::for_lir(&module, &lir, &Self::TRACING_CONFIG);
let lir = RichIr::for_lir(&module, &lir, Self::TRACING_CONFIG);
visit("LIR", lir.text);

let (optimized_lir, _) = db
.optimized_lir(execution_target.clone(), Self::TRACING_CONFIG.clone())
.optimized_lir(execution_target.clone(), Self::TRACING_CONFIG)
.unwrap();
let optimized_lir =
RichIr::for_optimized_lir(&module, &optimized_lir, &Self::TRACING_CONFIG);
RichIr::for_optimized_lir(&module, &optimized_lir, Self::TRACING_CONFIG);
visit("Optimized LIR", optimized_lir.text);

let (vm_byte_code, _) =
compile_byte_code(db, execution_target.clone(), Self::TRACING_CONFIG.clone());
compile_byte_code(db, execution_target.clone(), Self::TRACING_CONFIG);
let vm_byte_code_rich_ir =
RichIr::for_byte_code(&module, &vm_byte_code, &Self::TRACING_CONFIG);
RichIr::for_byte_code(&module, &vm_byte_code, Self::TRACING_CONFIG);
visit(
"VM Byte Code",
Self::format_byte_code(&vm_byte_code, &vm_byte_code_rich_ir),
Expand Down
1 change: 1 addition & 0 deletions compiler/frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ rust-version = "1.56"
[lib]

[dependencies]
clap = { version = "4.1.8", features = ["derive"] }
derive_more = "0.99.17"
dunce = "1.0.4"
enumset = "1.0.12"
Expand Down
6 changes: 3 additions & 3 deletions compiler/frontend/src/hir_to_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn mir(db: &dyn HirToMir, target: ExecutionTarget, tracing: TracingConfig) -> Mi
module,
target_is_main_function,
&hir,
&tracing,
tracing,
&mut errors,
);
(mir, errors)
Expand Down Expand Up @@ -185,7 +185,7 @@ fn generate_needs_function(body: &mut BodyBuilder) -> Id {
struct LoweringContext<'a> {
mapping: &'a mut FxHashMap<hir::Id, Id>,
needs_function: Id,
tracing: &'a TracingConfig,
tracing: TracingConfig,
ongoing_destructuring: Option<OngoingDestructuring>,
errors: &'a mut FxHashSet<CompilerError>,
}
Expand All @@ -202,7 +202,7 @@ impl<'a> LoweringContext<'a> {
module: Module,
target_is_main_function: bool,
hir: &hir::Body,
tracing: &TracingConfig,
tracing: TracingConfig,
errors: &mut FxHashSet<CompilerError>,
) -> Mir {
Mir::build(|body| {
Expand Down
4 changes: 2 additions & 2 deletions compiler/frontend/src/mir_optimize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn optimized_mir(
) -> OptimizedMirResult {
let module = target.module();
debug!("{module}: Compiling.");
let (mir, errors) = db.mir(target.clone(), tracing.clone())?;
let (mir, errors) = db.mir(target.clone(), tracing)?;
let mut mir = (*mir).clone();
let mut pureness = PurenessInsights::default();
let mut errors = (*errors).clone();
Expand Down Expand Up @@ -216,7 +216,7 @@ impl Context<'_> {
}
}

#[allow(clippy::unnecessary_wraps)]
#[allow(clippy::trivially_copy_pass_by_ref, clippy::unnecessary_wraps)]
fn recover_from_cycle(
_db: &dyn OptimizeMir,
cycle: &[String],
Expand Down
20 changes: 10 additions & 10 deletions compiler/frontend/src/rich_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ impl RichIrBuilder {
.push(range);
}

pub fn push_tracing_config(&mut self, tracing_config: &TracingConfig) {
fn push_mode(builder: &mut RichIrBuilder, title: &str, mode: &TracingMode) {
pub fn push_tracing_config(&mut self, tracing_config: TracingConfig) {
fn push_mode(builder: &mut RichIrBuilder, title: &str, mode: TracingMode) {
builder.push_comment_line(format!(
"• {title} {}",
match mode {
Expand All @@ -308,13 +308,13 @@ impl RichIrBuilder {
push_mode(
self,
"Include tracing of fuzzable functions?",
&tracing_config.register_fuzzables,
tracing_config.register_fuzzables,
);
push_mode(self, "Include tracing of calls?", &tracing_config.calls);
push_mode(self, "Include tracing of calls?", tracing_config.calls);
push_mode(
self,
"Include tracing of evaluated expressions?",
&tracing_config.evaluated_expressions,
tracing_config.evaluated_expressions,
);
}

Expand Down Expand Up @@ -373,25 +373,25 @@ impl RichIr {
Self::for_ir("HIR", module, None, |builder| body.build_rich_ir(builder))
}
#[must_use]
pub fn for_mir(module: &Module, mir: &Mir, tracing_config: &TracingConfig) -> Self {
pub fn for_mir(module: &Module, mir: &Mir, tracing_config: TracingConfig) -> Self {
Self::for_ir("MIR", module, tracing_config, |builder| {
mir.build_rich_ir(builder);
})
}
#[must_use]
pub fn for_optimized_mir(module: &Module, mir: &Mir, tracing_config: &TracingConfig) -> Self {
pub fn for_optimized_mir(module: &Module, mir: &Mir, tracing_config: TracingConfig) -> Self {
Self::for_ir("Optimized MIR", module, tracing_config, |builder| {
mir.build_rich_ir(builder);
})
}
#[must_use]
pub fn for_lir(module: &Module, lir: &Lir, tracing_config: &TracingConfig) -> Self {
pub fn for_lir(module: &Module, lir: &Lir, tracing_config: TracingConfig) -> Self {
Self::for_ir("LIR", module, tracing_config, |builder| {
lir.build_rich_ir(builder);
})
}
#[must_use]
pub fn for_optimized_lir(module: &Module, lir: &Lir, tracing_config: &TracingConfig) -> Self {
pub fn for_optimized_lir(module: &Module, lir: &Lir, tracing_config: TracingConfig) -> Self {
Self::for_ir("Optimized LIR", module, tracing_config, |builder| {
lir.build_rich_ir(builder);
})
Expand All @@ -400,7 +400,7 @@ impl RichIr {
fn for_ir(
ir_name: &str,
module: &Module,
tracing_config: impl Into<Option<&TracingConfig>>,
tracing_config: impl Into<Option<TracingConfig>>,
build_rich_ir: impl FnOnce(&mut RichIrBuilder),
) -> Self {
let mut builder = RichIrBuilder::default();
Expand Down
5 changes: 3 additions & 2 deletions compiler/frontend/src/tracing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use clap::ValueEnum;
use serde::{Deserialize, Serialize};

#[derive(PartialEq, Eq, Hash, Debug, Clone, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TracingConfig {
pub register_fuzzables: TracingMode,
Expand All @@ -27,7 +28,7 @@ impl TracingConfig {
}
}

#[derive(PartialEq, Eq, Hash, Debug, Clone, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, ValueEnum)]
#[serde(rename_all = "camelCase")]
pub enum TracingMode {
Off,
Expand Down
2 changes: 1 addition & 1 deletion compiler/language_server/src/debug_adapter/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl DebugSession {
let byte_code = compile_byte_code(
&self.db,
ExecutionTarget::MainFunction(module.clone()),
tracing.clone(),
tracing,
)
.0;

Expand Down
Loading

1 comment on commit a68dbb9

@jwbot
Copy link
Collaborator

@jwbot jwbot commented on a68dbb9 Jan 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiler

Benchmark suite Current: a68dbb9 Previous: 1eec5f6 Ratio
Time: Compiler/hello_world 22131864 ns/iter (± 416337) 21891685 ns/iter (± 768022) 1.01
Time: Compiler/fibonacci 177627245 ns/iter (± 2599838) 178832688 ns/iter (± 1059467) 0.99
Time: VM Runtime/hello_world 32837 ns/iter (± 2809) 32405 ns/iter (± 1280) 1.01

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.