Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
fmt + clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
prozacchiwawa committed Jun 24, 2023
1 parent 1cfdae4 commit e525ef6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 33 deletions.
65 changes: 37 additions & 28 deletions src/compiler/optimize/cse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,16 +381,13 @@ pub fn cse_classify_by_conditions(
.collect()
}

fn detect_common_cse_root(
instances: &[CSEInstance],
) -> Vec<BodyformPathArc> {
fn detect_common_cse_root(instances: &[CSEInstance]) -> Vec<BodyformPathArc> {
// No instances, we can choose the root.
let min_size =
if let Some(m) = instances.iter().map(|i| i.path.len()).min() {
m
} else {
return Vec::new();
};
let min_size = if let Some(m) = instances.iter().map(|i| i.path.len()).min() {
m
} else {
return Vec::new();
};

let mut target_path = instances[0].path.clone();
for idx in 0..min_size {
Expand All @@ -406,12 +403,12 @@ fn detect_common_cse_root(
// Back it up to the body of a let binding.
for (idx, f) in target_path.iter().enumerate().rev() {
if f == &BodyformPathArc::BodyOf {
return target_path.iter().take(idx+1).cloned().collect();
return target_path.iter().take(idx + 1).cloned().collect();
}
}

// No internal root if there was no let traversal.
return Vec::new();
Vec::new()
}

// Finds lambdas that contain CSE detection instances from the provided list.
Expand Down Expand Up @@ -464,7 +461,7 @@ fn add_variable_to_lambda_capture(vn: &[u8], bf: &BodyForm) -> BodyForm {
#[derive(Clone, Debug)]
struct CSEBindingSite {
target_path: Vec<BodyformPathArc>,
binding: Binding
binding: Binding,
}

#[derive(Default, Debug)]
Expand Down Expand Up @@ -629,15 +626,19 @@ pub fn cse_optimize_bodyform(
nl: prototype_instance.loc(),
pattern: BindingPattern::Complex(Rc::new(name_atom)),
body: Rc::new(prototype_instance),
}
},
});

}

new_binding_stack.append(
&mut binding_set.info.iter()
&mut binding_set
.info
.iter()
.map(|(target_path, sites)| {
let bindings: Vec<Rc<Binding>> = sites.iter().map(|site| Rc::new(site.binding.clone())).collect();
let bindings: Vec<Rc<Binding>> = sites
.iter()
.map(|site| Rc::new(site.binding.clone()))
.collect();
(target_path.clone(), bindings)
})
.collect(),
Expand All @@ -650,25 +651,33 @@ pub fn cse_optimize_bodyform(
let replacement_spec = &[PathDetectVisitorResult {
path: target_path.clone(),
subexp: function_body.clone(),
context: ()
context: (),
}];
if let Some(res) = replace_in_bodyform(
replacement_spec,
function_body.borrow(),
&|_v: &PathDetectVisitorResult<()>, b| BodyForm::Let(
LetFormKind::Parallel,
Box::new(LetData {
loc: function_body.loc(),
kw: None,
inline_hint: Some(LetFormInlineHint::NonInline(loc.clone())),
bindings: binding_list.clone(),
body: Rc::new(b.clone()),
}),
)
&|_v: &PathDetectVisitorResult<()>, b| {
BodyForm::Let(
LetFormKind::Parallel,
Box::new(LetData {
loc: function_body.loc(),
kw: None,
inline_hint: Some(LetFormInlineHint::NonInline(loc.clone())),
bindings: binding_list.clone(),
body: Rc::new(b.clone()),
}),
)
},
) {
function_body = res;
} else {
return Err(CompileErr(function_body.loc(), format!("Could not find the target to replace for path {target_path:?} in {}", b.to_sexp())));
return Err(CompileErr(
function_body.loc(),
format!(
"Could not find the target to replace for path {target_path:?} in {}",
b.to_sexp()
),
));
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/tests/classic/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2068,10 +2068,8 @@ fn test_rosetta_code_babbage_problem() {
"run".to_string(),
"resources/tests/strict/rosetta_code_babbage_problem.clsp".to_string(),
]);
let output = do_basic_brun(&vec![
"brun".to_string(),
compiled,
"(269696)".to_string()
]).trim().to_string();
let output = do_basic_brun(&vec!["brun".to_string(), compiled, "(269696)".to_string()])
.trim()
.to_string();
assert_eq!(output, "25264");
}

0 comments on commit e525ef6

Please sign in to comment.