Skip to content
This repository was archived by the owner on Apr 14, 2020. It is now read-only.

Commit 8f36b08

Browse files
committed
Replaced box [] -> vec![] / Vec::new()
1 parent f7223c0 commit 8f36b08

File tree

9 files changed

+57
-57
lines changed

9 files changed

+57
-57
lines changed

builtins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn builtins() -> Vec<(&'static str, Type)> {
1414
io(var2.clone())))),
1515
("io_return", function_type_(var.clone(), io(var.clone()))),
1616
("putStrLn", function_type_(list_type(char_type()), io(unit()))),
17-
("#compare_tags", function_type_(var.clone(), function_type_(var.clone(), Type::new_op(intern("Ordering"), box [])))),
17+
("#compare_tags", function_type_(var.clone(), function_type_(var.clone(), Type::new_op(intern("Ordering"), Vec::new())))),
1818
]
1919
}
2020

compiler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ impl <'a> Compiler<'a> {
409409
stackSize : 0, assemblies: Vec::new(),
410410
module: None,
411411
variables: variables,
412-
context: box []
412+
context: Vec::new()
413413
}
414414
}
415415

@@ -446,7 +446,7 @@ impl <'a> Compiler<'a> {
446446
offset: self.assemblies.iter().flat_map(|assembly| assembly.superCombinators.iter()).len(),
447447
classes: module.classes.clone(),
448448
instances: module.instances.iter()
449-
.map(|x| (x.constraints.clone(), Type::new_op(x.classname.name, box [x.typ.clone()])))
449+
.map(|x| (x.constraints.clone(), Type::new_op(x.classname.name, vec![x.typ.clone()])))
450450
.collect()
451451
,
452452
data_definitions: data_definitions
@@ -1285,7 +1285,7 @@ test = Test [1::Int]";
12851285
let assembly = compile(file);
12861286

12871287
let test = assembly.superCombinators[0];
1288-
assert_eq!(test.instructions, box [Pack(0, 0), PushInt(1), Pack(1, 2), Update(0), Unwind]);
1288+
assert_eq!(test.instructions, vec![Pack(0, 0), PushInt(1), Pack(1, 2), Update(0), Unwind]);
12891289
}
12901290

12911291
#[bench]

core.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl Module<Id> {
2020
Module {
2121
classes: vec![],
2222
data_definitions: vec![],
23-
newtypes: box [],
23+
newtypes: Vec::new(),
2424
instances: vec![],
2525
bindings: vec![Binding {
2626
name: Id::new(Name { name: intern("main"), uid: 0 }, expr.get_type().clone(), vec![]),
@@ -484,7 +484,7 @@ pub mod translate {
484484
for instance in new_instances.iter_mut() {
485485
let (class_var, class_decls) = (translator.functions_in_class)(instance.classname);
486486
let defaults = create_default_stubs(class_var, class_decls, instance);
487-
let mut temp = box [];
487+
let mut temp = Vec::new();
488488
::std::mem::swap(&mut temp, &mut instance.bindings);
489489
let vec: Vec<Binding<Id<Name>>> = temp.into_iter().chain(defaults.into_iter()).collect();
490490
instance.bindings = vec;
@@ -509,7 +509,7 @@ pub mod translate {
509509
let mut typ = decl.typ.clone();
510510
::typecheck::replace_var(&mut typ.value, class_var, &instance.typ);
511511
{
512-
let context = ::std::mem::replace(&mut typ.constraints, box []);
512+
let context = ::std::mem::replace(&mut typ.constraints, Vec::new());
513513
//Remove all constraints which refer to the class's variable
514514
let vec_context: Vec<Constraint<Name>> = context.into_iter()
515515
.filter(|c| c.variables[0] != *class_var)
@@ -597,7 +597,7 @@ impl <'a> Translator<'a> {
597597
self.translate_case(*expr, alts)
598598
}
599599
module::Expr::IfElse(pred, if_true, if_false) => {
600-
Case(box self.translate_expr(*pred), box [
600+
Case(box self.translate_expr(*pred), vec![
601601
Alternative { pattern: bool_pattern("True"), expression: self.translate_expr(*if_true) },
602602
Alternative { pattern: bool_pattern("False"), expression: self.translate_expr(*if_false) }
603603
])
@@ -745,7 +745,7 @@ impl <'a> Translator<'a> {
745745
let dummy_var = [Id::new(self.name_supply.anonymous(), Type::new_var(intern("a")), vec![])];
746746
let uid = self.name_supply.next_id();
747747
for module::Alternative { pattern: pattern, matches: matches, where_bindings: where_bindings } in alts.into_iter() {
748-
let bindings = where_bindings.map_or(box [], |bs| self.translate_bindings(bs));
748+
let bindings = where_bindings.map_or(Vec::new(), |bs| self.translate_bindings(bs));
749749
vec.push((self.unwrap_patterns(uid, dummy_var, [pattern.node]), bindings, matches));
750750
}
751751
let mut x = self.translate_equations_(vec);
@@ -817,7 +817,7 @@ impl <'a> Translator<'a> {
817817
where_bindings: where_bindings,
818818
..
819819
} = bind;
820-
let where_bindings_binds = where_bindings.map_or(box [], |bs| self.translate_bindings(bs));
820+
let where_bindings_binds = where_bindings.map_or(Vec::new(), |bs| self.translate_bindings(bs));
821821
(self.unwrap_patterns(uid, arg_ids.as_slice(), arguments), where_bindings_binds, matches)
822822
}).collect();
823823
let mut expr = self.translate_equations_(equations);

deriving.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn generate_deriving(instances: &mut Vec<Instance<Id<Name>>>, data: &DataDef
1313
let mut bindings = Vec::new();
1414
bindings.push(gen.generate_eq(data));
1515
instances.push(Instance {
16-
constraints: box [],
16+
constraints: Vec::new(),
1717
typ: data.typ.value.clone(),
1818
classname: Name { name: intern("Eq"), uid: 0 },
1919
bindings: bindings
@@ -25,7 +25,7 @@ pub fn generate_deriving(instances: &mut Vec<Instance<Id<Name>>>, data: &DataDef
2525
debug!("Generated Ord {:?} ->>\n{:?}", data.typ, b);
2626
bindings.push(b);
2727
instances.push(Instance {
28-
constraints: box [],
28+
constraints: Vec::new(),
2929
typ: data.typ.value.clone(),
3030
classname: Name { name: intern("Ord"), uid: 0 },
3131
bindings: bindings
@@ -73,7 +73,7 @@ impl DerivingGen {
7373
}
7474

7575
fn ord_fields(&mut self, args_l: &[Id<Name>], args_r: &[Id<Name>]) -> Expr<Id<Name>> {
76-
let ordering = Type::new_op(intern("Ordering"), box []);
76+
let ordering = Type::new_op(intern("Ordering"), Vec::new());
7777
if args_l.len() >= 1 {
7878
let mut iter = args_l.iter().zip(args_r.iter()).rev();
7979
let (x, y) = iter.next().unwrap();
@@ -105,8 +105,8 @@ impl DerivingGen {
105105
fn make_constraints(mut result: Vec<Constraint<Name>>, class: InternedStr, typ: &Type) -> Vec<Constraint<Name>> {
106106
match typ {
107107
&Type::Application(ref f, ref param) => {
108-
result.push(Constraint { class: Name { name: class, uid: 0 }, variables: box [param.var().clone()] });
109-
make_constraints(result, class, *f)
108+
result.push(Constraint { class: Name { name: class, uid: 0 }, variables: vec![param.var().clone()] });
109+
make_constraints(result, class, &**f)
110110
}
111111
_ => result
112112
}
@@ -119,10 +119,10 @@ impl DerivingGen {
119119
}
120120

121121
fn eq_or_default(&mut self, cmp: Expr<Id<Name>>, def: Expr<Id<Name>>) -> Expr<Id<Name>> {
122-
let match_id = Id::new(self.name_supply.anonymous(), Type::new_op(intern("Ordering"), box []), box []);
123-
Case(box cmp, box [
122+
let match_id = Id::new(self.name_supply.anonymous(), Type::new_op(intern("Ordering"), Vec::new()), Vec::new());
123+
Case(box cmp, vec![
124124
Alternative {
125-
pattern: Pattern::Constructor(id("EQ", Type::new_op(intern("Ordering"), box [])), box []),
125+
pattern: Pattern::Constructor(id("EQ", Type::new_op(intern("Ordering"), Vec::new())), Vec::new()),
126126
expression: def
127127
},
128128
Alternative { pattern: Pattern::Identifier(match_id.clone()), expression: Identifier(match_id) }
@@ -142,11 +142,11 @@ impl DerivingGen {
142142
let ctor_id = Id::new(constructor.name, iter.typ.clone(), constructor.typ.constraints.clone());
143143
let expr = f(self, args_l, args_r);
144144
let pattern_r = Pattern::Constructor(ctor_id.clone(), args_r);
145-
let inner = Case(box Identifier(id_r.clone()), box [
145+
let inner = Case(box Identifier(id_r.clone()), vec![
146146
Alternative { pattern: pattern_r, expression: expr },
147147
Alternative {
148148
pattern: Pattern::WildCard,
149-
expression: Identifier(Id::new(Name { uid: 0, name: intern("False") }, bool_type(), box []))
149+
expression: Identifier(Id::new(Name { uid: 0, name: intern("False") }, bool_type(), Vec::new()))
150150
}
151151
]);
152152
Alternative { pattern: Pattern::Constructor(ctor_id, args_l), expression: inner }
@@ -157,13 +157,13 @@ impl DerivingGen {
157157

158158

159159
fn id(s: &str, typ: Type) -> Id<Name> {
160-
Id::new(Name {name: intern(s), uid: 0 }, typ, box [])
160+
Id::new(Name {name: intern(s), uid: 0 }, typ, Vec::new())
161161
}
162162

163163
fn compare_tags(lhs: Expr<Id<Name>>, rhs: Expr<Id<Name>>) -> Expr<Id<Name>> {
164164
let var = Type::new_var(intern("a"));
165-
let typ = function_type_(var.clone(), function_type_(var.clone(), Type::new_op(intern("Ordering"), box [])));
166-
let id = Id::new(Name { name: intern("#compare_tags"), uid: 0 }, typ, box []);
165+
let typ = function_type_(var.clone(), function_type_(var.clone(), Type::new_op(intern("Ordering"), Vec::new())));
166+
let id = Id::new(Name { name: intern("#compare_tags"), uid: 0 }, typ, Vec::new());
167167
Apply(box Apply(box Identifier(id), box lhs), box rhs)
168168
}
169169

@@ -172,12 +172,12 @@ fn bool_binop(op: &str, lhs: Expr<Id<Name>>, rhs: Expr<Id<Name>>) -> Expr<Id<Nam
172172
}
173173
fn binop(op: &str, lhs: Expr<Id<Name>>, rhs: Expr<Id<Name>>, return_type: Type) -> Expr<Id<Name>> {
174174
let typ = function_type_(lhs.get_type().clone(), function_type_(rhs.get_type().clone(), return_type));
175-
let f = Identifier(Id::new(Name { name: intern(op), uid: 0 }, typ, box []));
175+
let f = Identifier(Id::new(Name { name: intern(op), uid: 0 }, typ, Vec::new()));
176176
Apply(box Apply(box f, box lhs), box rhs)
177177
}
178178

179179
fn true_expr() -> Expr<Id<Name>> {
180-
Identifier(Id::new(Name { uid: 0, name: intern("True") }, bool_type(), box []))
180+
Identifier(Id::new(Name { uid: 0, name: intern("True") }, bool_type(), Vec::new()))
181181
}
182182

183183
struct ArgIterator<'a> {
@@ -198,7 +198,7 @@ impl <'a> Iterator for ArgIterator<'a> {
198198
}
199199
fn extract_applied_type<'a>(typ: &'a Type) -> &'a Type {
200200
match typ {
201-
&Type::Application(ref lhs, _) => extract_applied_type(*lhs),
201+
&Type::Application(ref lhs, _) => extract_applied_type(&**lhs),
202202
_ => typ
203203
}
204204
}

lambda_lift.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ fn abstract_(&mut self, free_vars: &HashMap<Name, TypeAndStr>, input_expr: &mut
9999
rhs = Lambda(var.clone(), box rhs);
100100
typ = function_type_(var.get_type().clone(), typ);
101101
}
102-
let id = Id::new(self.name_supply.from_str("#sc"), typ.clone(), box []);
102+
let id = Id::new(self.name_supply.from_str("#sc"), typ.clone(), Vec::new());
103103
let bind = Binding {
104104
name: id.clone(),
105105
expression: rhs
@@ -148,7 +148,7 @@ pub fn lift_lambdas<T>(mut module: Module<T>) -> Module<T> {
148148
}
149149
let mut visitor = LambdaLifter { out_lambdas: Vec::new() };
150150
visitor.visit_module(&mut module);
151-
let mut temp = box [];
151+
let mut temp = Vec::new();
152152
::std::mem::swap(&mut temp, &mut module.bindings);
153153
let vec : Vec<Binding<T>> = temp.into_iter()
154154
.chain(visitor.out_lambdas.into_iter())

main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ fn main() {
6868
];
6969
let matches = {
7070
let args = std::os::args();
71-
getopts(args.tail(), opts)
71+
getopts(args.tail(), &opts)
7272
.unwrap_or_else(|err| panic!("{:?}", err))
7373
};
7474

7575
if matches.opt_present("h") {
76-
println!("Usage: vm [OPTIONS|EXPRESSION] {:?}", usage("", opts));
76+
println!("Usage: vm [OPTIONS|EXPRESSION] {:?}", usage("", &opts));
7777
return;
7878
}
7979
match matches.opt_str("l") {

parser.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ fn import(&mut self) -> Import<InternedStr> {
143143
self.lexer.next();
144144
let x = if self.lexer.peek().token == RPARENS {
145145
self.lexer.next();
146-
box []
146+
Vec::new()
147147
}
148148
else {
149149
let imports = self.sep_by_1(|this| this.require_next(NAME).value, COMMA);
@@ -755,7 +755,7 @@ fn constrained_type(&mut self) -> (Vec<Constraint>, Type) {
755755
}
756756
else {
757757
self.lexer.backtrack();
758-
box [self.parse_type()]
758+
vec![self.parse_type()]
759759
};
760760
let maybeContextArrow = self.lexer.next().token;
761761
//If there is => arrow we proceed to parse the type
@@ -764,13 +764,13 @@ fn constrained_type(&mut self) -> (Vec<Constraint>, Type) {
764764
}
765765
else if maybeContextArrow == ARROW {
766766
self.lexer.backtrack();
767-
let mut args = box [];
767+
let mut args = Vec::new();
768768
swap(&mut args, &mut maybeConstraints);
769769
self.parse_return_type(make_tuple_type(args))
770770
}
771771
else {//If no => was found, translate the constraint list into a type
772772
self.lexer.backtrack();
773-
let mut args = box [];
773+
let mut args = Vec::new();
774774
swap(&mut args, &mut maybeConstraints);
775775
make_tuple_type(args)
776776
};
@@ -785,7 +785,7 @@ fn constructor_type(&mut self, arity : &mut int, dataDef: &DataDefinition) -> Ty
785785
Type::new_var(self.lexer.current().value)
786786
}
787787
else {
788-
Type::new_op(self.lexer.current().value.clone(), box [])
788+
Type::new_op(self.lexer.current().value.clone(), Vec::new())
789789
};
790790
function_type_(arg, self.constructor_type(arity, dataDef))
791791
}
@@ -805,10 +805,10 @@ fn data_definition(&mut self) -> DataDefinition {
805805
self.require_next(DATA);
806806

807807
let mut definition = DataDefinition {
808-
constructors : box [],
808+
constructors : Vec::new(),
809809
typ : qualified(vec![], Type::new_var(intern("a"))),
810810
parameters : HashMap::new(),
811-
deriving: box []
811+
deriving: Vec::new()
812812
};
813813
definition.typ.value = self.data_lhs();
814814
self.require_next(EQUALSSIGN);
@@ -833,9 +833,9 @@ fn newtype(&mut self) -> Newtype {
833833
.unwrap_or_else(|| panic!("Parse error when parsing argument to new type at {:?}", location));
834834

835835
Newtype {
836-
typ: qualified(box [], typ.clone()),
836+
typ: qualified(Vec::new(), typ.clone()),
837837
constructor_name: name,
838-
constructor_type: qualified(box [], function_type_(arg_type, typ)),
838+
constructor_type: qualified(Vec::new(), function_type_(arg_type, typ)),
839839
deriving: self.deriving()
840840
}
841841
}
@@ -860,7 +860,7 @@ fn deriving(&mut self) -> Vec<InternedStr> {
860860
}
861861
else {
862862
self.lexer.backtrack();
863-
box []
863+
Vec::new()
864864
}
865865
}
866866

@@ -888,7 +888,7 @@ fn sub_type(&mut self) -> Option<Type> {
888888
}
889889
NAME => {
890890
if token.value.as_slice().char_at(0).is_uppercase() {
891-
Some(Type::new_op(token.value, box []))
891+
Some(Type::new_op(token.value, Vec::new()))
892892
}
893893
else {
894894
Some(Type::new_var(token.value))
@@ -995,7 +995,7 @@ fn make_constraints(types: Vec<Type>) -> Vec<Constraint> {
995995
types.into_iter().map(|typ| {
996996
match typ {
997997
Type::Application(lhs, rhs) => {
998-
Constraint { class: lhs.ctor().name.clone(), variables: box [rhs.var().clone()] }
998+
Constraint { class: lhs.ctor().name.clone(), variables: vec![rhs.var().clone()] }
999999
}
10001000
_ => panic!("Parse error in constraint, non applied type")
10011001
}
@@ -1310,9 +1310,9 @@ import Prelude (id, sum)
13101310
assert_eq!(module.imports[0].module.as_slice(), "Hello");
13111311
assert_eq!(module.imports[0].imports, None);
13121312
assert_eq!(module.imports[1].module.as_slice(), "World");
1313-
assert_eq!(module.imports[1].imports, Some(box []));
1313+
assert_eq!(module.imports[1].imports, Some(Vec::new()));
13141314
assert_eq!(module.imports[2].module.as_slice(), "Prelude");
1315-
assert_eq!(module.imports[2].imports, Some(box [intern("id"), intern("sum")]));
1315+
assert_eq!(module.imports[2].imports, Some(vec![intern("id"), intern("sum")]));
13161316
}
13171317
#[test]
13181318
fn parse_module_imports() {
@@ -1356,8 +1356,8 @@ test2 x y = 1
13561356
".chars());
13571357
let module = parser.module();
13581358
assert_eq!(module.fixity_declarations.as_slice(), &[
1359-
FixityDeclaration { assoc: RightAssoc, precedence: 5, operators: box [intern("test")] },
1360-
FixityDeclaration { assoc: RightAssoc, precedence: 6, operators: box [intern("test2"), intern("|<")] },
1359+
FixityDeclaration { assoc: RightAssoc, precedence: 5, operators: vec![intern("test")] },
1360+
FixityDeclaration { assoc: RightAssoc, precedence: 6, operators: vec![intern("test2"), intern("|<")] },
13611361
]);
13621362
}
13631363

@@ -1371,7 +1371,7 @@ dummy = 1
13711371
".chars());
13721372
let module = parser.module();
13731373
let data = &module.dataDefinitions[0];
1374-
assert_eq!(data.typ, qualified(box [], Type::new_op(intern("Test"), box [])));
1374+
assert_eq!(data.typ, qualified(Vec::new(), Type::new_op(intern("Test"), Vec::new())));
13751375
assert_eq!(data.deriving.as_slice(), &[intern("Eq"), intern("Show")]);
13761376
}
13771377

@@ -1438,9 +1438,9 @@ newtype IntPair a = IntPair (a, Int)
14381438
";
14391439
let module = Parser::new(s.chars()).module();
14401440
let a = Type::new_var(intern("a"));
1441-
let typ = Type::new_op(intern("IntPair"), box [a.clone()]);
1442-
assert_eq!(module.newtypes[0].typ, qualified(box [], typ.clone()));
1443-
assert_eq!(module.newtypes[0].constructor_type.value, function_type_(Type::new_op(intern("(,)"), box [a, int_type()]), typ));
1441+
let typ = Type::new_op(intern("IntPair"), vec![a.clone()]);
1442+
assert_eq!(module.newtypes[0].typ, qualified(Vec::new(), typ.clone()));
1443+
assert_eq!(module.newtypes[0].constructor_type.value, function_type_(Type::new_op(intern("(,)"), vec![a, int_type()]), typ));
14441444
}
14451445

14461446
#[test]

repl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub fn run_and_print_expr(expr_str: &str) {
6767
let assembly = compile_expr(vm.get_assembly(0), expr_str.as_slice());
6868
let (instructions, type_decl) = find_main(&assembly);
6969
let assembly_index = vm.add_assembly(assembly);
70-
let result = evaluate(&vm, instructions, assembly_index);//TODO 0 is not necessarily correct
70+
let result = evaluate(&vm, &*instructions, assembly_index);//TODO 0 is not necessarily correct
7171
println!("{:?} {:?}", result, type_decl);
7272
}
7373

@@ -76,15 +76,15 @@ pub fn start() {
7676
let prelude = compile_file("Prelude.hs");
7777
let mut vm = VM::new();
7878
vm.add_assembly(prelude);
79-
for line in ::std::io::stdin().lines() {
79+
for line in ::std::io::stdin().lock().lines() {
8080
let expr_str = match line {
8181
Ok(l) => l,
8282
Err(e) => panic!("Reading line failed with '{:?}'", e)
8383
};
8484
let assembly = compile_expr(vm.get_assembly(0), expr_str.as_slice());
8585
let (instructions, typ) = find_main(&assembly);
8686
let assembly_index = vm.add_assembly(assembly);
87-
let result = evaluate(&vm, instructions, assembly_index);//TODO 0 is not necessarily correct
87+
let result = evaluate(&vm, &*instructions, assembly_index);//TODO 0 is not necessarily correct
8888
println!("{:?} {:?}", result, typ);
8989
}
9090
}

0 commit comments

Comments
 (0)