Skip to content

Commit 3c7fea1

Browse files
clippy --fix
1 parent 20a306d commit 3c7fea1

11 files changed

Lines changed: 36 additions & 45 deletions

File tree

src/sea_of_nodes/graph_visualizer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::sync::Mutex;
1010
use std::time::Duration;
1111

1212
pub fn run_graphviz_and_chromium(input: String) {
13-
let child = Command::new(&"bash")
13+
let child = Command::new("bash")
1414
.args(["-c", "dot -Tsvg | base64"])
1515
.stdin(Stdio::piped())
1616
.stdout(Stdio::piped())
@@ -44,7 +44,7 @@ pub fn run_graphviz_and_chromium(input: String) {
4444
let _guard = LOCK.lock().unwrap();
4545

4646
// using chromium becasue firefox only displays it after manually selecting the address hitting enter
47-
Command::new(&"chromium")
47+
Command::new("chromium")
4848
.arg(url)
4949
.stdin(Stdio::null())
5050
.stdout(Stdio::null())

src/sea_of_nodes/nodes/scope.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl Scope {
241241
sea: &mut Nodes<'t>,
242242
) -> Result<(), ()> {
243243
debug_assert!(
244-
name.chars().next() != Some('$') || sea[self].lex_size.len() == 1,
244+
!name.starts_with('$') || sea[self].lex_size.len() == 1,
245245
"Later scopes do not define memory"
246246
);
247247
if sea[self].lex_size.len() > 1 {

src/sea_of_nodes/parser.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,11 @@ impl<'s, 't> Parser<'s, 't> {
489489
// they are ALSO valid at the break. It is the intersection of
490490
// conditions here, not the union.
491491
let break_scope = self.break_scope.unwrap();
492-
break_scope.remove_guards(break_scope.ctrl(&mut self.nodes).unwrap(), &mut self.nodes);
492+
break_scope.remove_guards(break_scope.ctrl(&self.nodes).unwrap(), &mut self.nodes);
493493
self.break_scope = Some(self.jump_to(self.break_scope));
494494
self.require(";")?;
495495
self.break_scope.unwrap().add_guards(
496-
self.break_scope.unwrap().ctrl(&mut self.nodes).unwrap(),
496+
self.break_scope.unwrap().ctrl(&self.nodes).unwrap(),
497497
None,
498498
false,
499499
&mut self.nodes,
@@ -585,7 +585,7 @@ impl<'s, 't> Parser<'s, 't> {
585585
(true, false) => Some(self.parse_asgn()?),
586586
(false, true) => None,
587587
(false, false) => {
588-
Some(*self.con(lhs.unwrap().ty(&self.nodes).unwrap().make_zero(&self.types)))
588+
Some(*self.con(lhs.unwrap().ty(&self.nodes).unwrap().make_zero(self.types)))
589589
}
590590
};
591591
self.scope.remove_guards(if_false, &mut self.nodes);
@@ -874,7 +874,7 @@ impl<'s, 't> Parser<'s, 't> {
874874
type_name,
875875
s.peephole(&mut self.nodes)
876876
.keep(&mut self.nodes)
877-
.to_struct(&mut self.nodes)
877+
.to_struct(&self.nodes)
878878
.unwrap(),
879879
);
880880

@@ -1352,7 +1352,7 @@ impl<'s, 't> Parser<'s, 't> {
13521352
let size = Add::new(*con_base, shl, &mut self.nodes).peep(self);
13531353
self.altmp.clear();
13541354
self.altmp.push(Some(len.unkeep(&mut self.nodes)));
1355-
let init = *self.con(ary.fields()[1].ty.make_init(&self.types));
1355+
let init = *self.con(ary.fields()[1].ty.make_init(self.types));
13561356
self.altmp.push(Some(init));
13571357
self.new_struct(ary, size)
13581358
}
@@ -1802,7 +1802,7 @@ impl<'a> Lexer<'a> {
18021802
fn parse_number<'t>(&mut self, types: &Types<'t>) -> PResult<Ty<'t>> {
18031803
let (flt, snum) = self.is_long_or_double();
18041804
if !flt {
1805-
if snum.len() > 1 && snum.chars().next() == Some('0') {
1805+
if snum.len() > 1 && snum.starts_with('0') {
18061806
Err("Syntax error: integer values cannot start with '0'".to_string())
18071807
} else {
18081808
snum.parse().map(|i| *types.get_int(i)).map_err(|_| {

src/sea_of_nodes/tests/chapter01.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn test_simple_program() {
1212
let stop = parser.parse().unwrap();
1313

1414
assert!(matches!(&parser.nodes[stop], Op::Stop));
15-
let ret = stop.unique_input(&mut parser.nodes).unwrap();
15+
let ret = stop.unique_input(&parser.nodes).unwrap();
1616
assert!(matches!(&parser.nodes[ret], Op::Return));
1717

1818
let ctrl = parser.nodes.inputs[ret][0].expect("has ctrl");

src/sea_of_nodes/tests/chapter04.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn test_var_arg() {
6666
let stop = parser.parse().unwrap();
6767

6868
assert!(matches!(&parser.nodes[stop], Op::Stop));
69-
let ret = stop.unique_input(&mut parser.nodes).expect("has one ret");
69+
let ret = stop.unique_input(&parser.nodes).expect("has one ret");
7070
assert!(matches!(&parser.nodes[ret], Op::Return));
7171

7272
assert!(matches!(

src/sea_of_nodes/tests/chapter09.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,8 @@ fn test_meet() {
427427
let mut t1 = types.top;
428428
let mut t2 = *types.int_top;
429429

430-
assert_eq!(*types.int_top.clone(), t1.meet(t2, &types));
431-
assert_eq!(*types.int_top.clone(), t2.meet(t1, &types));
430+
assert_eq!(*types.int_top, t1.meet(t2, &types));
431+
assert_eq!(*types.int_top, t2.meet(t1, &types));
432432
t1 = types.bot;
433433
t2 = *types.int_bot;
434434
assert_eq!(types.bot.clone(), t1.meet(t2, &types));

src/sea_of_nodes/tests/chapter15.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,7 @@ return rez;
376376
};
377377
let primes = [2, 3, 5, 7, 11, 13, 17, 19];
378378
assert_eq!(nprimes as usize, primes.len());
379-
assert_eq!(
380-
primes.map(|p| Object::Long(p)),
381-
result.heap.objs[obj].fields[1..]
382-
);
379+
assert_eq!(primes.map(Object::Long), result.heap.objs[obj].fields[1..]);
383380
}
384381

385382
#[test]

src/sea_of_nodes/tests/chapter17.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -881,8 +881,5 @@ return rez;
881881
};
882882
let primes = [2, 3, 5, 7, 11, 13, 17, 19];
883883
assert_eq!(nprimes as usize, primes.len());
884-
assert_eq!(
885-
primes.map(|p| Object::Long(p)),
886-
result.heap.objs[obj].fields[1..]
887-
);
884+
assert_eq!(primes.map(Object::Long), result.heap.objs[obj].fields[1..]);
888885
}

src/sea_of_nodes/tests/evaluator.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,7 @@ impl<'a, 't> Evaluator<'a, 't> {
387387
body = vec![init; n as usize + 1]; // Array body
388388

389389
// Length value
390-
body[0] = self
391-
.vall(alloc.inputs(self.sea)[2 + 2].unwrap())
392-
.try_into()
393-
.unwrap();
390+
body[0] = self.vall(alloc.inputs(self.sea)[2 + 2].unwrap()).into();
394391
} else {
395392
let num = ty.fields().len();
396393
body = (0..num)
@@ -407,8 +404,8 @@ impl<'a, 't> Evaluator<'a, 't> {
407404
}
408405

409406
fn load(&self, load: Load) -> Object {
410-
let from = self.valo(load.ptr(&self.sea).unwrap());
411-
let off = self.vall(load.off(&self.sea).unwrap());
407+
let from = self.valo(load.ptr(self.sea).unwrap());
408+
let off = self.vall(load.off(self.sea).unwrap());
412409
let idx = get_field_index(from.ty, load.to_mem_name(self.sea).unwrap(), off);
413410
if idx == from.ty.fields().len() - 1 && from.ty.is_ary() {
414411
let len = from.fields.len() - from.ty.fields().len() + 1;
@@ -423,10 +420,10 @@ impl<'a, 't> Evaluator<'a, 't> {
423420
}
424421

425422
fn store(&mut self, store: Store) -> Object {
426-
let ptr = store.ptr(&self.sea).unwrap();
423+
let ptr = store.ptr(self.sea).unwrap();
427424
let to = self.valo(ptr);
428-
let off = self.vall(store.off(&self.sea).unwrap());
429-
let val = self.val(store.val(&self.sea).unwrap());
425+
let off = self.vall(store.off(self.sea).unwrap());
426+
let val = self.val(store.val(self.sea).unwrap());
430427
let idx = get_field_index(to.ty, store.to_mem_name(self.sea).unwrap(), off);
431428

432429
if idx == to.ty.fields().len() - 1 && to.ty.is_ary() {
@@ -525,14 +522,14 @@ impl<'a, 't> Evaluator<'a, 't> {
525522
TypedNode::Div(n) => self.div(n).into(),
526523
TypedNode::DivF(n) => self.divf(n).into(),
527524
TypedNode::Minus(_) => self
528-
.vall(node.inputs(&self.sea)[1].unwrap())
525+
.vall(node.inputs(self.sea)[1].unwrap())
529526
.wrapping_neg()
530527
.into(),
531-
TypedNode::MinusF(_) => self.vald(node.inputs(&self.sea)[1].unwrap()).neg().into(),
528+
TypedNode::MinusF(_) => self.vald(node.inputs(self.sea)[1].unwrap()).neg().into(),
532529
TypedNode::Mul(_) => self.binaryl(node, i64::wrapping_mul),
533530
TypedNode::MulF(_) => self.binaryd(node, f64::mul),
534531
TypedNode::Not(_) => Object::Long(
535-
if self.is_true(self.val(node.inputs(&self.sea)[1].unwrap())) {
532+
if self.is_true(self.val(node.inputs(self.sea)[1].unwrap())) {
536533
0
537534
} else {
538535
1
@@ -546,19 +543,19 @@ impl<'a, 't> Evaluator<'a, 't> {
546543
TypedNode::And(_) => self.binaryl(node, i64::bitand),
547544
TypedNode::Or(_) => self.binaryl(node, i64::bitor),
548545
TypedNode::Xor(_) => self.binaryl(node, i64::bitxor),
549-
TypedNode::Cast(_) => self.val(node.inputs(&self.sea)[1].unwrap()),
550-
TypedNode::ToFloat(_) => (self.vall(node.inputs(&self.sea)[1].unwrap()) as f64).into(),
546+
TypedNode::Cast(_) => self.val(node.inputs(self.sea)[1].unwrap()),
547+
TypedNode::ToFloat(_) => (self.vall(node.inputs(self.sea)[1].unwrap()) as f64).into(),
551548
TypedNode::Load(n) => self.load(n),
552549
TypedNode::Store(n) => self.store(n),
553550
TypedNode::New(n) => self.alloc(n),
554551
TypedNode::CProj(n) => {
555-
self.valo(n.inputs(&self.sea)[0].unwrap()).fields[self.sea[n].index]
552+
self.valo(n.inputs(self.sea)[0].unwrap()).fields[self.sea[n].index]
556553
}
557554
TypedNode::Proj(n) => {
558-
self.valo(n.inputs(&self.sea)[0].unwrap()).fields[self.sea[n].index]
555+
self.valo(n.inputs(self.sea)[0].unwrap()).fields[self.sea[n].index]
559556
}
560557
TypedNode::ScopeMin(_) => Object::Null,
561-
TypedNode::ReadOnly(n) => self.val(n.inputs(&self.sea)[1].unwrap()),
558+
TypedNode::ReadOnly(n) => self.val(n.inputs(self.sea)[1].unwrap()),
562559
n => unreachable!("Unexpected node {n:?}"),
563560
}
564561
}
@@ -593,10 +590,10 @@ impl<'a, 't> Evaluator<'a, 't> {
593590

594591
match exit_node.downcast(&self.sea.ops) {
595592
TypedNode::Return(n) => {
596-
return EResult::Value(self.val(n.inputs(&self.sea)[1].unwrap()))
593+
return EResult::Value(self.val(n.inputs(self.sea)[1].unwrap()))
597594
}
598595
TypedNode::If(n) => {
599-
let condition = self.is_true(self.val(n.inputs(&self.sea)[1].unwrap()));
596+
let condition = self.is_true(self.val(n.inputs(self.sea)[1].unwrap()));
600597
block = self.blocks[block].next[if condition { 0 } else { 1 }];
601598
// if (block == null) return Status.FALLTHROUGH;
602599
}
@@ -607,12 +604,12 @@ impl<'a, 't> Evaluator<'a, 't> {
607604
loops -= 1;
608605

609606
let exit = self.blocks[block].exit_id.unwrap();
610-
debug_assert!(exit > 0 && exit_node.inputs(&self.sea).len() > exit);
607+
debug_assert!(exit > 0 && exit_node.inputs(self.sea).len() > exit);
611608
block = self.blocks[block].next[0];
612609
// assert block != null;
613610
while i < self.blocks[block].nodes.len() {
614-
if let Some(phi) = self.blocks[block].nodes[i].to_phi(&self.sea) {
615-
let exit_node = phi.inputs(&self.sea)[exit].unwrap();
611+
if let Some(phi) = self.blocks[block].nodes[i].to_phi(self.sea) {
612+
let exit_node = phi.inputs(self.sea)[exit].unwrap();
616613
self.phi_cache.push(self.val(exit_node))
617614
} else {
618615
break;

src/sea_of_nodes/tests/rust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ L3: [[ L194 ]]
726726
727727
"#;
728728
let actual_pretty_print_scheduled_llvm =
729-
ir_printer::pretty_print_llvm(stop, 1000, &mut parser.nodes);
729+
ir_printer::pretty_print_llvm(stop, 1000, &parser.nodes);
730730
assert_eq!(
731731
actual_pretty_print_scheduled_llvm,
732732
expected_pretty_print_scheduled_llvm

0 commit comments

Comments
 (0)