Skip to content

Commit

Permalink
Refactor add merge separator constant
Browse files Browse the repository at this point in the history
  • Loading branch information
imaqtkatt committed Mar 25, 2024
1 parent 3ccd408 commit 4bdf93e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/hvmc_net/mutual_recursion.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::diagnostics::{Diagnostics, WarningType, ERR_INDENT_SIZE};
use crate::{
diagnostics::{Diagnostics, WarningType, ERR_INDENT_SIZE},
term::transform::definition_merge::MERGE_SEPARATOR,
};
use hvmc::ast::{Book, Tree};
use indexmap::{IndexMap, IndexSet};
use std::fmt::Debug;
Expand Down Expand Up @@ -157,9 +160,9 @@ impl Debug for Graph {
fn combinations_from_merges(cycle: Vec<Ref>) -> Vec<Vec<Ref>> {
let mut combinations: Vec<Vec<Ref>> = vec![vec![]];
for r#ref in cycle {
if let Some(index) = r#ref.find("_$_") {
if let Some(index) = r#ref.find(MERGE_SEPARATOR) {
let (left, right) = r#ref.split_at(index);
let right = &right[3 ..]; // skip "_$_"
let right = &right[MERGE_SEPARATOR.len() ..]; // skip merge separator
let mut new_combinations = Vec::new();
for combination in &combinations {
let mut left_comb = combination.clone();
Expand Down
4 changes: 3 additions & 1 deletion src/term/transform/definition_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use indexmap::{IndexMap, IndexSet};
use itertools::Itertools;
use std::collections::BTreeMap;

pub const MERGE_SEPARATOR: &str = "_$_";

impl Book {
/// Merges definitions that have the same structure into one definition.
/// Expects variables to be linear.
Expand All @@ -28,7 +30,7 @@ impl Book {

for (term, equal_defs) in equal_terms {
// def1_$_def2_$_def3
let new_name = Name::new(equal_defs.iter().join("_$_"));
let new_name = Name::new(equal_defs.iter().join(MERGE_SEPARATOR));

// Builtin origin takes precedence
let builtin = equal_defs.iter().any(|nam| self.defs[nam].builtin);
Expand Down
2 changes: 1 addition & 1 deletion tests/golden_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ fn mutual_recursion() {
..DiagnosticsConfig::new(Severity::Allow, true)
};
let mut book = do_parse_book(code, path)?;
let mut opts = CompileOpts::light();
let mut opts = CompileOpts::light();
opts.merge = true;
let res = compile_book(&mut book, opts, diagnostics_cfg, None)?;
Ok(format!("{}{}", res.diagnostics, res.core_book))
Expand Down

0 comments on commit 4bdf93e

Please sign in to comment.