Skip to content

Commit

Permalink
Impl Copy for TracingConfig, TracingMode
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasWanke committed Dec 26, 2023
1 parent d36e515 commit ac1e1b3
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 72 deletions.
30 changes: 15 additions & 15 deletions compiler/cli/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,40 +165,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 @@ -382,33 +382,33 @@ impl GoldOptions {
let (mir, _) = db
.mir(execution_target.clone(), Self::TRACING_CONFIG.clone())
.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())
.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())
.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())
.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());
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
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
4 changes: 2 additions & 2 deletions compiler/frontend/src/tracing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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 +27,7 @@ impl TracingConfig {
}
}

#[derive(PartialEq, Eq, Hash, Debug, Clone, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[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
38 changes: 18 additions & 20 deletions compiler/language_server/src/features_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,43 +110,43 @@ impl IrFeatures {
&config.module,
db.mir(
ExecutionTarget::Module(config.module.clone()),
tracing_config.clone(),
*tracing_config,
),
tracing_config,
*tracing_config,
),
Ir::OptimizedMir(tracing_config) => Self::rich_ir_for_optimized_mir(
&config.module,
db.optimized_mir(
ExecutionTarget::Module(config.module.clone()),
tracing_config.clone(),
*tracing_config,
),
tracing_config,
*tracing_config,
),
Ir::Lir(tracing_config) => Self::rich_ir_for_lir(
&config.module,
&db.lir(
ExecutionTarget::Module(config.module.clone()),
tracing_config.clone(),
*tracing_config,
),
tracing_config,
*tracing_config,
),
Ir::OptimizedLir(tracing_config) => Self::rich_ir_for_optimized_lir(
&config.module,
db.optimized_lir(
ExecutionTarget::Module(config.module.clone()),
tracing_config.clone(),
*tracing_config,
),
tracing_config,
*tracing_config,
),
Ir::VmByteCode(tracing_config) => Self::rich_ir_for_vm_byte_code(
&config.module,
&candy_vm::lir_to_byte_code::compile_byte_code(
db,
ExecutionTarget::Module(config.module.clone()),
tracing_config.clone(),
*tracing_config,
)
.0,
tracing_config,
*tracing_config,
),
#[cfg(feature = "inkwell")]
Ir::LlvmIr => db
Expand Down Expand Up @@ -179,7 +179,7 @@ impl IrFeatures {
Err(error) => Self::build_rich_ir_for_module_error(builder, module, error),
})
}
fn rich_ir_for_mir(module: &Module, mir: MirResult, tracing_config: &TracingConfig) -> RichIr {
fn rich_ir_for_mir(module: &Module, mir: MirResult, tracing_config: TracingConfig) -> RichIr {
Self::rich_ir_for("MIR", module, tracing_config, |builder| match mir {
Ok((mir, _)) => mir.build_rich_ir(builder),
Err(error) => Self::build_rich_ir_for_module_error(builder, module, error),
Expand All @@ -188,7 +188,7 @@ impl IrFeatures {
fn rich_ir_for_optimized_mir(
module: &Module,
mir: OptimizedMirResult,
tracing_config: &TracingConfig,
tracing_config: TracingConfig,
) -> RichIr {
Self::rich_ir_for(
"Optimized MIR",
Expand All @@ -200,7 +200,7 @@ impl IrFeatures {
},
)
}
fn rich_ir_for_lir(module: &Module, lir: &LirResult, tracing_config: &TracingConfig) -> RichIr {
fn rich_ir_for_lir(module: &Module, lir: &LirResult, tracing_config: TracingConfig) -> RichIr {
Self::rich_ir_for("LIR", module, tracing_config, |builder| match lir {
Ok((lir, _)) => lir.build_rich_ir(builder),
Err(error) => Self::build_rich_ir_for_module_error(builder, module, *error),
Expand All @@ -209,7 +209,7 @@ impl IrFeatures {
fn rich_ir_for_optimized_lir(
module: &Module,
lir: LirResult,
tracing_config: &TracingConfig,
tracing_config: TracingConfig,
) -> RichIr {
Self::rich_ir_for(
"Optimized LIR",
Expand All @@ -224,7 +224,7 @@ impl IrFeatures {
fn rich_ir_for_vm_byte_code(
module: &Module,
byte_code: &candy_vm::byte_code::ByteCode,
tracing_config: &TracingConfig,
tracing_config: TracingConfig,
) -> RichIr {
Self::rich_ir_for("VM Byte Code", module, tracing_config, |builder| {
byte_code.build_rich_ir(builder);
Expand All @@ -233,7 +233,7 @@ impl IrFeatures {
fn rich_ir_for(
ir_name: &str,
module: &Module,
tracing_config: impl Into<Option<&TracingConfig>>,
tracing_config: impl Into<Option<TracingConfig>>,
build_rich_ir: impl FnOnce(&mut RichIrBuilder),
) -> RichIr {
let mut builder = RichIrBuilder::default();
Expand Down Expand Up @@ -409,14 +409,14 @@ pub enum Ir {
LlvmIr,
}
impl Ir {
const fn tracing_config(&self) -> Option<&TracingConfig> {
const fn tracing_config(&self) -> Option<TracingConfig> {
match self {
Self::Rcst | Self::Ast | Self::Hir => None,
Self::Mir(tracing_config)
| Self::OptimizedMir(tracing_config)
| Self::Lir(tracing_config)
| Self::OptimizedLir(tracing_config)
| Self::VmByteCode(tracing_config) => Some(tracing_config),
| Self::VmByteCode(tracing_config) => Some(*tracing_config),
#[cfg(feature = "inkwell")]
Self::LlvmIr => None,
}
Expand Down Expand Up @@ -527,7 +527,6 @@ impl LanguageFeatures for IrFeatures {
config
.ir
.tracing_config()
.cloned()
.unwrap_or_else(TracingConfig::off),
),
};
Expand All @@ -542,7 +541,6 @@ impl LanguageFeatures for IrFeatures {
config
.ir
.tracing_config()
.cloned()
.unwrap_or_else(TracingConfig::off),
),
};
Expand Down
14 changes: 2 additions & 12 deletions compiler/vm/benches/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,7 @@ pub fn setup() -> Database {
db.module_provider.add_str(&MODULE, r#"_ = use "Core""#);

// Load `Core` into the cache.
let errors = compile_byte_code(
&db,
ExecutionTarget::Module(MODULE.clone()),
TRACING.clone(),
)
.1;
let errors = compile_byte_code(&db, ExecutionTarget::Module(MODULE.clone()), TRACING).1;
if !errors.is_empty() {
for error in errors.iter() {
warn!("{}", error.to_string_with_location(&db));
Expand All @@ -104,12 +99,7 @@ pub fn setup() -> Database {

pub fn compile(db: &mut Database, source_code: &str) -> ByteCode {
db.did_open_module(&MODULE, source_code.as_bytes().to_owned());
compile_byte_code(
db,
ExecutionTarget::MainFunction(MODULE.clone()),
TRACING.clone(),
)
.0
compile_byte_code(db, ExecutionTarget::MainFunction(MODULE.clone()), TRACING).0
}

pub fn run(byte_code: impl Borrow<ByteCode>) -> (Heap, InlineObject) {
Expand Down
Loading

0 comments on commit ac1e1b3

Please sign in to comment.