Skip to content

Commit 1a25224

Browse files
committed
Adapt to rustc 1.26.0 features (rust-lang/rust#49394)
1 parent 8751014 commit 1a25224

12 files changed

+188
-191
lines changed

src/closure.rs

+38-38
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@ pub struct Prog(pub Box<[Fundef]>, pub Closure);
4848
impl Closure {
4949
fn fmt2(&self, f: &mut fmt::Formatter, level: usize) -> fmt::Result {
5050
use self::Closure::*;
51-
match *self {
51+
match self {
5252
Unit => write!(f, "()"),
5353
Int(v) => write!(f, "{}", v),
5454
Float(fv) => write!(f, "{}", fv),
55-
Neg(ref x) => write!(f, "-{}", x),
56-
IntBin(op, ref x, ref y) => {
55+
Neg(x) => write!(f, "-{}", x),
56+
IntBin(op, x, y) => {
5757
let op_str = match op {
5858
self::IntBin::Add => "+",
5959
self::IntBin::Sub => "-",
6060
};
6161
write!(f, "{} {} {}", x, op_str, y)
6262
},
63-
FNeg(ref x) => write!(f, "-.{}", x),
64-
FloatBin(op, ref x, ref y) => {
63+
FNeg(x) => write!(f, "-.{}", x),
64+
FloatBin(op, x, y) => {
6565
let op_str = match op {
6666
self::FloatBin::FAdd => "+.",
6767
self::FloatBin::FSub => "-.",
@@ -70,7 +70,7 @@ impl Closure {
7070
};
7171
write!(f, "{} {} {}", x, op_str, y)
7272
},
73-
IfComp(op, ref x, ref y, ref e1, ref e2) => {
73+
IfComp(op, x, y, e1, e2) => {
7474
let op_str = match op {
7575
self::CompBin::Eq => "=",
7676
self::CompBin::LE => "<=",
@@ -90,7 +90,7 @@ impl Closure {
9090
}
9191
e2.fmt2(f, level + 2)
9292
},
93-
Let((ref x, ref t), ref e1, ref e2) => {
93+
Let((x, t), e1, e2) => {
9494
if let Type::Unit = *t {
9595
if x.len() >= 6 && &x[0..6] == "_dummy" {
9696
// this let expression is actually "e1; e2"
@@ -110,31 +110,31 @@ impl Closure {
110110
}
111111
e2.fmt2(f, level)
112112
},
113-
Var(ref x) => write!(f, "{}", x),
114-
MakeCls(ref x, ref t, ref cls, ref e) => {
113+
Var(x) => write!(f, "{}", x),
114+
MakeCls(x, t, cls, e) => {
115115
write!(f, "MakeCls {}: {} (", x, t)?;
116-
let Cls { entry: id::L(ref l), actual_fv: ref fv } = *cls;
116+
let Cls { entry: id::L(l), actual_fv: fv } = cls;
117117
write!(f, "{} {:?}) in\n", l, fv)?;
118118
for _ in 0 .. level {
119119
write!(f, " ")?;
120120
}
121121
e.fmt2(f, level)
122122
},
123-
AppDir(id::L(ref func), ref args) => {
123+
AppDir(id::L(func), args) => {
124124
write!(f, "{}", func)?;
125125
for v in args.iter() {
126126
write!(f, " {}", v)?;
127127
}
128128
Ok(())
129129
},
130-
AppCls(ref func, ref args) => {
130+
AppCls(func, args) => {
131131
write!(f, "[{}]", func)?;
132132
for v in args.iter() {
133133
write!(f, " {}", v)?;
134134
}
135135
Ok(())
136136
},
137-
Tuple(ref elems) => {
137+
Tuple(elems) => {
138138
write!(f, "(")?;
139139
for i in 0 .. elems.len() {
140140
write!(f, "{}", elems[i])?;
@@ -144,7 +144,7 @@ impl Closure {
144144
}
145145
write!(f, ")")
146146
},
147-
LetTuple(ref xts, ref y, ref e) => {
147+
LetTuple(xts, y, e) => {
148148
write!(f, "let (")?;
149149
for i in 0 .. xts.len() {
150150
write!(f, "{}: {}", xts[i].0, xts[i].1)?;
@@ -158,11 +158,11 @@ impl Closure {
158158
}
159159
e.fmt2(f, level)
160160
},
161-
Get(ref x, ref y) =>
161+
Get(x, y) =>
162162
write!(f, "{}.({})", x, y),
163-
Put(ref x, ref y, ref z) =>
163+
Put(x, y, z) =>
164164
write!(f, "{}.({}) <- {}", x, y, z),
165-
ExtArray(id::L(ref a)) => write!(f, "(extarr:{})", a),
165+
ExtArray(id::L(a)) => write!(f, "(extarr:{})", a),
166166
}
167167
}
168168
}
@@ -175,15 +175,15 @@ impl fmt::Display for Closure {
175175

176176
impl fmt::Display for Fundef {
177177
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
178-
let Fundef { name: (id::L(ref x), ref t), args: ref yts, body: ref e1,
179-
formal_fv: ref fv } = *self;
178+
let Fundef { name: (id::L(x), t), args: yts, body: e1,
179+
formal_fv: fv } = self;
180180
write!(f, "define ({}: {})", x, t)?;
181-
for &(ref y, ref t) in yts.iter() {
181+
for (y, t) in yts.iter() {
182182
write!(f, " ({}: {})", y, t)?;
183183
}
184184
if !fv.is_empty() {
185185
write!(f, " freevar:")?;
186-
for &(ref x, ref t) in fv.iter() {
186+
for (x, t) in fv.iter() {
187187
write!(f, " ({}: {})", x, t)?;
188188
}
189189
}
@@ -196,7 +196,7 @@ impl fmt::Display for Fundef {
196196

197197
impl fmt::Display for Prog {
198198
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
199-
let Prog(ref fundefs, ref e) = *self;
199+
let Prog(fundefs, e) = self;
200200
for fundef in fundefs.iter() {
201201
write!(f, "{}\n", fundef)?;
202202
}
@@ -210,35 +210,35 @@ pub fn fv(e: &Closure) -> HashSet<String> {
210210
macro_rules! invoke {
211211
($e:expr) => (fv($e));
212212
}
213-
match *e {
213+
match e {
214214
Unit | Int(_) | Float(_) | ExtArray(_) => HashSet::new(),
215-
Neg(ref x) | FNeg(ref x) => build_set!(x),
216-
IntBin(_, ref x, ref y) | FloatBin(_, ref x, ref y) |
217-
Get(ref x, ref y) =>
215+
Neg(x) | FNeg(x) => build_set!(x),
216+
IntBin(_, x, y) | FloatBin(_, x, y) |
217+
Get(x, y) =>
218218
build_set!(x, y),
219-
IfComp(_, ref x, ref y, ref e1, ref e2) => {
219+
IfComp(_, x, y, e1, e2) => {
220220
let h = build_set!(x, y);
221221
let s1 = invoke!(e1);
222222
let s2 = invoke!(e2);
223223
&(&h | &s1) | &s2
224224
},
225-
Let((ref x, _), ref e1, ref e2) => {
225+
Let((x, _), e1, e2) => {
226226
let s1 = invoke!(e1);
227227
let s2 = &invoke!(e2) - &build_set!(x);
228228
&s1 | &s2
229229
}
230-
Var(ref x) => build_set!(x),
231-
MakeCls(ref x, _, Cls { entry: _, actual_fv: ref ys }, ref e) =>
230+
Var(x) => build_set!(x),
231+
MakeCls(x, _, Cls { entry: _, actual_fv: ys }, e) =>
232232
&(&ys.iter().cloned().collect() | &invoke!(e)) - &build_set!(x),
233-
AppCls(ref x, ref ys) =>
233+
AppCls(x, ys) =>
234234
&build_set!(x) | &ys.iter().cloned().collect::<HashSet<_>>(),
235-
AppDir(_, ref xs) | Tuple(ref xs) => xs.iter().cloned().collect(),
236-
LetTuple(ref xs, ref y, ref e) => {
235+
AppDir(_, xs) | Tuple(xs) => xs.iter().cloned().collect(),
236+
LetTuple(xs, y, e) => {
237237
let tmp: HashSet<String> = xs.iter().map(|x| x.0.clone())
238238
.collect(); // S.of_list (List.map fst xs)
239239
&build_set!(y) | &(&invoke!(e) - &tmp)
240240
},
241-
Put(ref x, ref y, ref z) => build_set!(x, y, z),
241+
Put(x, y, z) => build_set!(x, y, z),
242242
}
243243
}
244244

@@ -272,13 +272,13 @@ fn g(env: &HashMap<String, Type>, known: &HashSet<String>,
272272
let mut known_p = known.clone();
273273
known_p.insert(x.clone());
274274
let mut env_p2 = env_p.clone();
275-
for &(ref y, ref t) in yts.iter() {
275+
for (y, t) in yts.iter() {
276276
env_p2.insert(y.clone(), t.clone());
277277
}
278278
let e1p = g(&env_p2, &known_p, (*e1).clone(), &mut toplevel_cp);
279279
/* Check if e1p contains free variables */
280280
let zs =
281-
&fv(&e1p) - &yts.iter().map(|&(ref y, _)| y.clone()).collect();
281+
&fv(&e1p) - &yts.iter().map(|(y, _)| y.clone()).collect();
282282
let (known_p, e1p) = if zs.is_empty() {
283283
*toplevel = toplevel_cp;
284284
(&known_p, e1p)
@@ -290,7 +290,7 @@ fn g(env: &HashMap<String, Type>, known: &HashSet<String>,
290290
(known, e1p)
291291
};
292292
let zs: Vec<String> = (&zs - &build_set!(x)).into_iter().collect();
293-
let zts: Vec<(String, Type)> = zs.iter().map(|&ref z| (z.clone(), env.get(z).unwrap().clone())).collect();
293+
let zts: Vec<(String, Type)> = zs.iter().map(|z| (z.clone(), env.get(z).unwrap().clone())).collect();
294294
toplevel.push(Fundef { name: (id::L(x.clone()), t.clone()),
295295
args: yts,
296296
formal_fv: zts.into_boxed_slice(),
@@ -315,7 +315,7 @@ fn g(env: &HashMap<String, Type>, known: &HashSet<String>,
315315
KNormal::Tuple(xs) => Tuple(xs),
316316
KNormal::LetTuple(xts, y, e) => {
317317
let mut cp_env = env.clone();
318-
for &(ref x, ref t) in xts.iter() {
318+
for (x, t) in xts.iter() {
319319
cp_env.insert(x.clone(), t.clone());
320320
}
321321
LetTuple(xts, y, Box::new(g(&cp_env, known, *e, toplevel)))

src/const_fold.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,15 @@ type ConstEnv = HashMap<String, Const>;
1818
fn add_env(env: &mut ConstEnv, x: String, e: &KNormal) {
1919
use self::KNormal::*;
2020
use self::Const::*;
21-
match *e {
22-
Int(v) => { env.insert(x, IntConst(v)); },
23-
Float(f) => { env.insert(x, FloatConst(f.into())); },
21+
match e {
22+
Int(v) => { env.insert(x, IntConst(*v)); },
23+
Float(f) => { env.insert(x, FloatConst((*f).into())); },
2424
// Tuple const folding is done only if all components are constant.
25-
Tuple(ref xs) => {
25+
Tuple(xs) => {
2626
let result: Option<Vec<Const>> =
2727
xs.iter().map(|x| env.get(x).cloned()).collect();
28-
match result {
29-
None => (),
30-
Some(result) => {
31-
env.insert(x, TupleConst(result.into_boxed_slice()));
32-
},
28+
if let Some(result) = result {
29+
env.insert(x, TupleConst(result.into_boxed_slice()));
3330
}
3431
},
3532
_ => (),
@@ -40,21 +37,21 @@ fn add_env(env: &mut ConstEnv, x: String, e: &KNormal) {
4037
fn findi(x: &str, env: &ConstEnv) -> Option<i64> {
4138
use self::Const::*;
4239
match env.get(x) {
43-
Some(&IntConst(v)) => Some(v),
40+
Some(IntConst(v)) => Some(*v),
4441
_ => None,
4542
}
4643
}
4744
fn findf(x: &str, env: &ConstEnv) -> Option<f64> {
4845
use self::Const::*;
4946
match env.get(x) {
50-
Some(&FloatConst(v)) => Some(v.into()),
47+
Some(FloatConst(v)) => Some((*v).into()),
5148
_ => None,
5249
}
5350
}
5451
fn findt(x: &str, env: &ConstEnv) -> Option<Box<[Const]>> {
5552
use self::Const::*;
5653
match env.get(x) {
57-
Some(&TupleConst(ref vals)) => Some(vals.clone()),
54+
Some(TupleConst(vals)) => Some(vals.clone()),
5855
_ => None,
5956
}
6057
}

src/elim.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use k_normal::fv;
55

66
fn has_effect(e: &KNormal) -> bool {
77
use self::KNormal::*;
8-
match *e {
9-
Let(_, ref e1, ref e2) | IfComp(_, _, _, ref e1, ref e2) =>
8+
match e {
9+
Let(_, e1, e2) | IfComp(_, _, _, e1, e2) =>
1010
has_effect(e1) || has_effect(e2),
11-
LetRec(_, ref e) | LetTuple(_, _, ref e) => has_effect(e),
11+
LetRec(_, e) | LetTuple(_, _, e) => has_effect(e),
1212
App(_, _) | Put(_, _, _) | ExtFunApp(_, _) => true,
1313
_ => false,
1414
}
@@ -46,7 +46,7 @@ pub fn f(e: KNormal) -> KNormal {
4646
LetTuple(xts, y, e) => {
4747
let ep = invoke!(e);
4848
let live = fv(&ep);
49-
let any_used = xts.iter().any(|&(ref x, _)| live.contains(x));
49+
let any_used = xts.iter().any(|(x, _)| live.contains(x));
5050
if any_used {
5151
LetTuple(xts, y, ep)
5252
} else {

src/id.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl IdGen {
2222
Type::Var(a)
2323
}
2424
fn id_of_typ(t: &Type) -> String {
25-
match *t {
25+
match t {
2626
Type::Unit => "u",
2727
Type::Bool => "b",
2828
Type::Int => "i",

src/inline.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ use k_normal::{KNormal, KFundef, fv};
44
use syntax::Type;
55
use id::IdGen;
66

7-
fn is_recursive(&KFundef { name: (ref x, ref _t), args: ref _yts, body: ref e1 }: &KFundef)
7+
fn is_recursive(KFundef { name: (x, _t), args: _yts, body: e1 }: &KFundef)
88
-> bool {
9-
fv(&e1).contains(x)
9+
fv(e1).contains(x)
1010
}
1111

1212
pub fn size(e: &KNormal) -> usize {
1313
use self::KNormal::*;
14-
match *e {
15-
IfComp(_, _, _, ref e1, ref e2) |
16-
Let(_, ref e1, ref e2) |
17-
LetRec(KFundef { name: _, args: _, body: ref e1 }, ref e2) =>
14+
match e {
15+
IfComp(_, _, _, e1, e2) |
16+
Let(_, e1, e2) |
17+
LetRec(KFundef { name: _, args: _, body: e1 }, e2) =>
1818
1 + size(e1) + size(e2),
19-
LetTuple(_, _, ref e) => 1 + size(e),
19+
LetTuple(_, _, e) => 1 + size(e),
2020
_ => 1,
2121
}
2222
}

0 commit comments

Comments
 (0)