Skip to content

Commit ff12696

Browse files
stepanchegfacebook-github-bot
authored andcommitted
Remove feature box_patterns
Summary: Working on making starlark-rust compatible with stable. Reviewed By: bobyangyf Differential Revision: D41062170 fbshipit-source-id: fac84d9ffc5739ba472e91c9a18342df3a2105bc
1 parent 0c6d5f5 commit ff12696

File tree

23 files changed

+309
-183
lines changed

23 files changed

+309
-183
lines changed

starlark/src/analysis/bind.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,14 @@ fn stmt(x: &AstStmt, res: &mut Vec<Bind>) {
255255
flow(res)
256256
}
257257
Stmt::Expression(x) => expr(x, res),
258-
Stmt::If(a, box b) => {
258+
Stmt::If(a, b) => {
259259
expr(a, res);
260260
flow(res);
261261
stmt(b, res);
262262
flow(res);
263263
}
264-
Stmt::IfElse(a, box (b, c)) => {
264+
Stmt::IfElse(a, b_c) => {
265+
let (b, c) = &**b_c;
265266
expr(a, res);
266267
flow(res);
267268
stmt(b, res);
@@ -277,7 +278,8 @@ fn stmt(x: &AstStmt, res: &mut Vec<Bind>) {
277278
stmt(body, &mut inner);
278279
res.push(Bind::Scope(Scope::new(inner)));
279280
}
280-
Stmt::Assign(lhs, box (ty, rhs)) => {
281+
Stmt::Assign(lhs, ty_rhs) => {
282+
let (ty, rhs) = &**ty_rhs;
281283
opt_expr(ty.as_ref(), res);
282284
expr(rhs, res);
283285
expr_lvalue(lhs, res);
@@ -292,7 +294,8 @@ fn stmt(x: &AstStmt, res: &mut Vec<Bind>) {
292294
expr(rhs, res);
293295
expr_lvalue(lhs, res);
294296
}
295-
Stmt::For(dest, box (inner, body)) => {
297+
Stmt::For(dest, inner_body) => {
298+
let (inner, body) = &**inner_body;
296299
expr(inner, res);
297300
expr_lvalue(dest, res);
298301
flow(res);

starlark/src/analysis/definition.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,8 @@ impl LspModule {
443443
return;
444444
}
445445

446-
if let StmtP::Assign(l, box (_ty, r)) = &v.node {
446+
if let StmtP::Assign(l, ty_r) = &v.node {
447+
let (_ty, r) = &**ty_r;
447448
let main_assign_span = match &l.node {
448449
AssignP::Identifier(main_assign_id) if main_assign_id.0 == name => {
449450
main_assign_id.span

starlark/src/analysis/flow.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ fn final_return(x: &AstStmt) -> bool {
9090
None => false,
9191
Some(x) => final_return(x),
9292
},
93-
Stmt::IfElse(_, box (x, y)) => final_return(x) && final_return(y),
93+
Stmt::IfElse(_, x_y) => {
94+
let (x, y) = &**x_y;
95+
final_return(x) && final_return(y)
96+
}
9497
_ => false,
9598
}
9699
}
@@ -173,7 +176,8 @@ fn reachable(codemap: &CodeMap, x: &AstStmt, res: &mut Vec<LintT<FlowIssue>>) ->
173176
}
174177
false
175178
}
176-
Stmt::IfElse(_, box (x, y)) => {
179+
Stmt::IfElse(_, x_y) => {
180+
let (x, y) = &**x_y;
177181
let abort1 = reachable(codemap, x, res);
178182
let abort2 = reachable(codemap, y, res);
179183
abort1 && abort2
@@ -204,8 +208,9 @@ fn redundant(codemap: &CodeMap, x: &AstStmt, res: &mut Vec<LintT<FlowIssue>>) {
204208
Stmt::Statements(xs) if !xs.is_empty() => {
205209
check(is_loop, codemap, xs.last().unwrap(), res)
206210
}
207-
Stmt::If(_, box x) => check(is_loop, codemap, x, res),
208-
Stmt::IfElse(_, box (x, y)) => {
211+
Stmt::If(_, x) => check(is_loop, codemap, x, res),
212+
Stmt::IfElse(_, x_y) => {
213+
let (x, y) = &**x_y;
209214
check(is_loop, codemap, x, res);
210215
check(is_loop, codemap, y, res);
211216
}
@@ -215,7 +220,10 @@ fn redundant(codemap: &CodeMap, x: &AstStmt, res: &mut Vec<LintT<FlowIssue>>) {
215220

216221
fn f(codemap: &CodeMap, x: &AstStmt, res: &mut Vec<LintT<FlowIssue>>) {
217222
match &**x {
218-
Stmt::For(_, box (_, body)) => check(true, codemap, body, res),
223+
Stmt::For(_, over_body) => {
224+
let (_over, body) = &**over_body;
225+
check(true, codemap, body, res)
226+
}
219227
Stmt::Def(_, _, _, body, _payload) => check(false, codemap, body, res),
220228
_ => {}
221229
}

starlark/src/analysis/incompatible.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fn duplicate_top_level_assignment(module: &AstModule, res: &mut Vec<LintT<Incomp
153153
res: &mut Vec<LintT<Incompatibility>>,
154154
) {
155155
match &**x {
156-
Stmt::Assign(lhs, box (_, rhs)) => match (&**lhs, &**rhs) {
156+
Stmt::Assign(lhs, op_rhs) => match (&**lhs, &(**op_rhs).1.node) {
157157
(Assign::Identifier(x), Expr::Identifier(y, _))
158158
if x.node.0 == y.node
159159
&& defined.get(x.node.0.as_str()).map_or(false, |x| x.1)

starlark/src/analysis/names.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ fn inappropriate_underscore(
226226
}
227227
inappropriate_underscore(codemap, x, false, res)
228228
}
229-
Stmt::Assign(lhs, box (_, rhs)) | Stmt::AssignModify(lhs, _, box rhs) if !top => {
229+
Stmt::Assign(lhs, type_rhs) if !top => {
230+
let (_, rhs) = &**type_rhs;
230231
match (&**lhs, &**rhs) {
231232
(Assign::Identifier(name), Expr::Lambda(..)) if name.0.starts_with('_') => res
232233
.push(LintT::new(
@@ -237,6 +238,16 @@ fn inappropriate_underscore(
237238
_ => {}
238239
}
239240
}
241+
Stmt::AssignModify(lhs, _, rhs) if !top => match (&**lhs, &rhs.node) {
242+
(Assign::Identifier(name), Expr::Lambda(..)) if name.0.starts_with('_') => {
243+
res.push(LintT::new(
244+
codemap,
245+
name.span,
246+
NameWarning::UnderscoreFunction(name.node.0.clone()),
247+
))
248+
}
249+
_ => {}
250+
},
240251
_ => x.visit_stmt(|x| inappropriate_underscore(codemap, x, top, res)),
241252
}
242253
}

starlark/src/eval/bc/compiler/compr.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ impl ComprCompiled {
7878

7979
pub(crate) fn write_bc(&self, span: FrozenFileSpan, target: BcSlotOut, bc: &mut BcWriter) {
8080
bc.alloc_slot(|temp, bc| {
81-
match *self {
82-
ComprCompiled::List(box ref expr, ref clauses) => {
81+
match self {
82+
ComprCompiled::List(ref expr, ref clauses) => {
8383
bc.write_instr::<InstrListNew>(span, temp.to_out());
8484
let (first, rem) = clauses.split_last();
8585
first.write_bc(bc, rem, |bc| {
@@ -91,7 +91,8 @@ impl ComprCompiled {
9191
});
9292
});
9393
}
94-
ComprCompiled::Dict(box (ref k, ref v), ref clauses) => {
94+
ComprCompiled::Dict(k_v, clauses) => {
95+
let (k, v) = &**k_v;
9596
bc.write_instr::<InstrDictNew>(span, temp.to_out());
9697
let (first, rem) = clauses.split_last();
9798
first.write_bc(bc, rem, |bc| {

starlark/src/eval/bc/compiler/expr.rs

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,14 @@ impl ExprCompiled {
139139
}
140140
}
141141
ExprCompiled::Compr(compr) => compr.mark_definitely_assigned_after(bc),
142-
ExprCompiled::If(box (c, _t, _f)) => {
142+
ExprCompiled::If(c_t_f) => {
143+
let (c, _t, _f) = &**c_t_f;
143144
// Condition is executed unconditionally, so we use it to mark definitely assigned.
144145
// But we don't know which of the branches will be executed.
145146
c.mark_definitely_assigned_after(bc);
146147
}
147-
ExprCompiled::Slice(box (l, a, b, c)) => {
148+
ExprCompiled::Slice(l_a_b_c) => {
149+
let (l, a, b, c) = &**l_a_b_c;
148150
l.mark_definitely_assigned_after(bc);
149151
if let Some(a) = a {
150152
a.mark_definitely_assigned_after(bc);
@@ -159,17 +161,20 @@ impl ExprCompiled {
159161
ExprCompiled::Builtin1(_op, expr) => {
160162
expr.mark_definitely_assigned_after(bc);
161163
}
162-
ExprCompiled::LogicalBinOp(_op, box (a, b)) => {
164+
ExprCompiled::LogicalBinOp(_op, a_b) => {
165+
let (a, b) = &**a_b;
163166
// `a` is executed unconditionally, but `b` is not,
164167
// so we mark only `a` as definitely assigned.
165168
a.mark_definitely_assigned_after(bc);
166169
let _ = b;
167170
}
168-
ExprCompiled::Seq(box (a, b)) => {
171+
ExprCompiled::Seq(a_b) => {
172+
let (a, b) = &**a_b;
169173
a.mark_definitely_assigned_after(bc);
170174
b.mark_definitely_assigned_after(bc);
171175
}
172-
ExprCompiled::Builtin2(_op, box (a, b)) => {
176+
ExprCompiled::Builtin2(_op, a_b) => {
177+
let (a, b) = &**a_b;
173178
a.mark_definitely_assigned_after(bc);
174179
b.mark_definitely_assigned_after(bc);
175180
}
@@ -293,20 +298,20 @@ impl IrSpanned<ExprCompiled> {
293298

294299
pub(crate) fn write_bc(&self, target: BcSlotOut, bc: &mut BcWriter) {
295300
let span = self.span;
296-
match self.node {
301+
match &self.node {
297302
ExprCompiled::Value(v) => {
298-
bc.write_const(span, v, target);
303+
bc.write_const(span, *v, target);
299304
}
300305
ExprCompiled::Local(slot) => {
301-
bc.write_load_local(span, slot, target);
306+
bc.write_load_local(span, *slot, target);
302307
}
303308
ExprCompiled::LocalCaptured(slot) => {
304-
bc.write_load_local_captured(span, slot, target);
309+
bc.write_load_local_captured(span, *slot, target);
305310
}
306311
ExprCompiled::Module(slot) => {
307-
bc.write_instr::<InstrLoadModule>(span, (slot, target));
312+
bc.write_instr::<InstrLoadModule>(span, (*slot, target));
308313
}
309-
ExprCompiled::Tuple(ref xs) => {
314+
ExprCompiled::Tuple(xs) => {
310315
write_exprs(xs, bc, |xs, bc| {
311316
bc.write_instr::<InstrTupleNPop>(span, (xs, target));
312317
});
@@ -325,7 +330,8 @@ impl IrSpanned<ExprCompiled> {
325330
}
326331
ExprCompiled::Dict(ref xs) => Self::write_dict(span, xs, target, bc),
327332
ExprCompiled::Compr(ref compr) => compr.write_bc(span, target, bc),
328-
ExprCompiled::Slice(box (ref l, ref start, ref stop, ref step)) => {
333+
ExprCompiled::Slice(l_start_stop_step) => {
334+
let (l, start, stop, step) = &**l_start_stop_step;
329335
l.write_bc_cb(bc, |l, bc| {
330336
write_expr_opt(start, bc, |start, bc| {
331337
write_expr_opt(stop, bc, |stop, bc| {
@@ -336,10 +342,8 @@ impl IrSpanned<ExprCompiled> {
336342
})
337343
});
338344
}
339-
ExprCompiled::Builtin1(Builtin1::Not, box ref expr) => {
340-
Self::write_not(expr, target, bc)
341-
}
342-
ExprCompiled::Builtin1(ref op, ref expr) => {
345+
ExprCompiled::Builtin1(Builtin1::Not, expr) => Self::write_not(expr, target, bc),
346+
ExprCompiled::Builtin1(op, expr) => {
343347
expr.write_bc_cb(bc, |expr, bc| {
344348
let arg = (expr, target);
345349
match op {
@@ -361,15 +365,17 @@ impl IrSpanned<ExprCompiled> {
361365
}
362366
});
363367
}
364-
ExprCompiled::If(box (ref cond, ref t, ref f)) => {
368+
ExprCompiled::If(cond_t_f) => {
369+
let (cond, t, f) = &**cond_t_f;
365370
write_if_else(
366371
cond,
367372
|bc| t.write_bc(target, bc),
368373
|bc| f.write_bc(target, bc),
369374
bc,
370375
);
371376
}
372-
ExprCompiled::LogicalBinOp(op, box (ref l, ref r)) => {
377+
ExprCompiled::LogicalBinOp(op, l_r) => {
378+
let (l, r) = &**l_r;
373379
l.write_bc_cb(bc, |l_slot, bc| {
374380
let maybe_not = match op {
375381
ExprLogicalBinOp::And => MaybeNot::Id,
@@ -384,14 +390,17 @@ impl IrSpanned<ExprCompiled> {
384390
);
385391
});
386392
}
387-
ExprCompiled::Seq(box (ref l, ref r)) => {
393+
ExprCompiled::Seq(l_r) => {
394+
let (l, r) = &**l_r;
388395
l.write_bc_for_effect(bc);
389396
r.write_bc(target, bc);
390397
}
391-
ExprCompiled::Builtin2(Builtin2::Equals, box (ref l, ref r)) => {
398+
ExprCompiled::Builtin2(Builtin2::Equals, l_r) => {
399+
let (l, r) = &**l_r;
392400
Self::write_equals(span, l, r, target, bc)
393401
}
394-
ExprCompiled::Builtin2(op, box (ref l, ref r)) => {
402+
ExprCompiled::Builtin2(op, l_r) => {
403+
let (l, r) = &**l_r;
395404
write_n_exprs([l, r], bc, |[l, r], bc| {
396405
let arg = (l, r, target);
397406
match op {

starlark/src/eval/bc/compiler/if_compiler.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ fn write_cond(
154154
ExprCompiled::Builtin1(Builtin1::Not, cond) => {
155155
write_cond(cond, maybe_not.negate(), t, f, bc);
156156
}
157-
ExprCompiled::LogicalBinOp(op, box (x, y)) => {
157+
ExprCompiled::LogicalBinOp(op, x_y) => {
158+
let (x, y) = &**x_y;
158159
write_cond_bin_op(x, y, *op, maybe_not, t, f, bc);
159160
}
160161
_ => {

starlark/src/eval/bc/compiler/stmt.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ impl StmtCompiled {
104104
rhs.mark_definitely_assigned_after(bc);
105105
lhs.mark_definitely_assigned_after(bc);
106106
}
107-
StmtCompiled::If(box (cond, t, f)) => {
107+
StmtCompiled::If(cond_t_f) => {
108+
let (cond, t, f) = &**cond_t_f;
108109
cond.mark_definitely_assigned_after(bc);
109110
// We could merge `t` and `f` definitely assigned, e. g.
110111
// ```
@@ -116,7 +117,8 @@ impl StmtCompiled {
116117
// we could mark `x` as definitely assigned.
117118
let _ = (t, f);
118119
}
119-
StmtCompiled::For(box (_var, over, _body)) => {
120+
StmtCompiled::For(var_over_body) => {
121+
let (_var, over, _body) = &**var_over_body;
120122
over.mark_definitely_assigned_after(bc);
121123
}
122124
StmtCompiled::Break => {}
@@ -212,13 +214,13 @@ impl IrSpanned<StmtCompiled> {
212214

213215
fn write_bc_inner(&self, compiler: &StmtCompileContext, bc: &mut BcWriter) {
214216
let span = self.span;
215-
match self.node {
217+
match &self.node {
216218
StmtCompiled::PossibleGc => bc.write_instr::<InstrPossibleGc>(span, ()),
217-
StmtCompiled::Return(ref expr) => Self::write_return(span, expr, compiler, bc),
218-
StmtCompiled::Expr(ref expr) => {
219+
StmtCompiled::Return(expr) => Self::write_return(span, expr, compiler, bc),
220+
StmtCompiled::Expr(expr) => {
219221
expr.write_bc_for_effect(bc);
220222
}
221-
StmtCompiled::Assign(ref lhs, ref ty, ref rhs) => {
223+
StmtCompiled::Assign(lhs, ty, rhs) => {
222224
fn check_type(
223225
ty: &Option<IrSpanned<ExprCompiled>>,
224226
slot_expr: BcSlotIn,
@@ -242,13 +244,15 @@ impl IrSpanned<StmtCompiled> {
242244
});
243245
}
244246
}
245-
StmtCompiled::AssignModify(ref lhs, op, ref rhs) => {
246-
lhs.write_bc(span, op, rhs, bc);
247+
StmtCompiled::AssignModify(lhs, op, rhs) => {
248+
lhs.write_bc(span, *op, rhs, bc);
247249
}
248-
StmtCompiled::If(box (ref c, ref t, ref f)) => {
250+
StmtCompiled::If(c_t_f) => {
251+
let (c, t, f) = &**c_t_f;
249252
Self::write_if_else(c, t, f, compiler, bc);
250253
}
251-
StmtCompiled::For(box (ref assign, ref over, ref body)) => {
254+
StmtCompiled::For(assign_over_body) => {
255+
let (assign, over, body) = &**assign_over_body;
252256
write_for(over, assign, span, bc, |bc| body.write_bc(compiler, bc));
253257
}
254258
StmtCompiled::Break => {

starlark/src/eval/compiler/compr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,12 @@ impl ComprCompiled {
136136

137137
pub(crate) fn optimize(&self, ctx: &mut OptCtx) -> ExprCompiled {
138138
match self {
139-
ComprCompiled::List(box ref x, ref clauses) => {
139+
ComprCompiled::List(ref x, ref clauses) => {
140140
let clauses = clauses.optimize(ctx);
141141
ExprCompiled::compr(ComprCompiled::List(box x.optimize(ctx), clauses))
142142
}
143-
ComprCompiled::Dict(box (ref k, ref v), ref clauses) => {
143+
ComprCompiled::Dict(k_v, ref clauses) => {
144+
let (k, v) = &**k_v;
144145
let clauses = clauses.optimize(ctx);
145146
ExprCompiled::compr(ComprCompiled::Dict(
146147
box (k.optimize(ctx), v.optimize(ctx)),

0 commit comments

Comments
 (0)