[rust] fix lints
Joe Savona committed
Jul 12, 2023 at 13:01 UTC
e029e22a9a8a443287ac212d26bcd7b85ee82ad9
8 files changed
+38
-85
compiler/forget/crates/build-hir/src/build.rs
+23
-75
@@ -30,7 +30,7 @@ pub fn build<'a>(
30
31
match fun.function.body {
32
Some(estree::FunctionBody::BlockStatement(body)) => {
33
- lower_block_statement(env, &mut builder, *body, None)?
33
+ lower_block_statement(env, &mut builder, *body)?
34
}
35
Some(estree::FunctionBody::Expression(body)) => {
36
lower_expression(env, &mut builder, body)?;
@@ -62,13 +62,9 @@ pub fn build<'a>(
62
// In case the function did not explicitly return, terminate the final
63
// block with an explicit `return undefined`. If the function *did* return,
64
// this will be unreachable and get pruned later.
65
- let implicit_return_value = lower_value_to_temporary(
66
- env,
67
- &mut builder,
68
- InstructionValue::Primitive(hir::Primitive {
69
- value: PrimitiveValue::Undefined,
70
- }),
71
- );
65
+ let implicit_return_value = builder.push(InstructionValue::Primitive(hir::Primitive {
66
+ value: PrimitiveValue::Undefined,
67
+ }));
68
builder.terminate(
69
TerminalValue::Return(hir::ReturnTerminal {
70
value: Operand {
@@ -96,7 +92,6 @@ fn lower_block_statement<'a>(
92
env: &'a Environment<'a>,
93
builder: &mut Builder<'a>,
94
stmt: BlockStatement,
99
- label: Option<String<'a>>,
95
) -> Result<(), BuildDiagnostic> {
96
for stmt in stmt.body {
97
lower_statement(env, builder, stmt, None)?;
@@ -114,7 +109,7 @@ fn lower_statement<'a>(
109
) -> Result<(), BuildDiagnostic> {
110
match stmt {
111
Statement::BlockStatement(stmt) => {
117
- lower_block_statement(env, builder, *stmt, label)?;
112
+ lower_block_statement(env, builder, *stmt)?;
113
}
114
Statement::BreakStatement(stmt) => {
115
let block = builder.resolve_break(stmt.label.as_ref())?;
@@ -139,13 +134,9 @@ fn lower_statement<'a>(
134
Statement::ReturnStatement(stmt) => {
135
let ix = match stmt.argument {
136
Some(argument) => lower_expression(env, builder, argument)?,
142
- None => lower_value_to_temporary(
143
- env,
144
- builder,
145
- InstructionValue::Primitive(hir::Primitive {
146
- value: PrimitiveValue::Undefined,
147
- }),
148
- ),
137
+ None => builder.push(InstructionValue::Primitive(hir::Primitive {
138
+ value: PrimitiveValue::Undefined,
139
+ })),
140
};
141
builder.terminate(
142
TerminalValue::Return(hir::ReturnTerminal {
@@ -196,19 +187,15 @@ fn lower_statement<'a>(
187
));
188
}
189
};
199
- lower_value_to_temporary(
200
- env,
201
- builder,
202
- InstructionValue::DeclareLocal(hir::DeclareLocal {
203
- lvalue: LValue {
204
- identifier: IdentifierOperand {
205
- identifier,
206
- effect: None,
207
- },
208
- kind,
190
+ builder.push(InstructionValue::DeclareLocal(hir::DeclareLocal {
191
+ lvalue: LValue {
192
+ identifier: IdentifierOperand {
193
+ identifier,
194
+ effect: None,
195
},
210
- }),
211
- );
196
+ kind,
197
+ },
198
+ }));
199
}
200
}
201
}
@@ -450,17 +437,13 @@ fn lower_assignment<'a>(
437
AssignmentTarget::Pattern(lvalue) => match lvalue {
438
Pattern::Identifier(lvalue) => {
439
let identifier = lower_identifier_for_assignment(env, builder, kind, *lvalue)?;
453
- lower_value_to_temporary(
454
- env,
455
- builder,
456
- InstructionValue::StoreLocal(hir::StoreLocal {
457
- lvalue: LValue { identifier, kind },
458
- value: Operand {
459
- ix: value,
460
- effect: None,
461
- },
462
- }),
463
- )
440
+ builder.push(InstructionValue::StoreLocal(hir::StoreLocal {
441
+ lvalue: LValue { identifier, kind },
442
+ value: Operand {
443
+ ix: value,
444
+ effect: None,
445
+ },
446
+ }))
447
}
448
_ => todo!("lower assignment pattern for {:#?}", lvalue),
449
},
@@ -488,41 +471,6 @@ fn lower_identifier_for_assignment<'a>(
471
}
472
}
473
491
-/// Given an already lowered InstructionValue:
492
-/// - if the instruction is a LoadLocal for a temporary location, avoid the indirection
493
-/// and return the place that the LoadLocal loads from
494
-/// - otherwise, create a new temporary place, push an instruction to associate the value with
495
-/// that temporary, and return a clone of the temporary
496
-fn lower_value_to_temporary<'a>(
497
- env: &'a Environment<'a>,
498
- builder: &mut Builder<'a>,
499
- value: InstructionValue<'a>,
500
-) -> InstrIx {
501
- // if let InstructionValue::LoadLocal(LoadLocal {
502
- // place:
503
- // place @ Operand {
504
- // identifier: Identifier { name: None, .. },
505
- // ..
506
- // },
507
- // }) = value
508
- // {
509
- // return place;
510
- // }
511
- builder.push(value)
512
-}
513
-
514
-/// Constructs a temporary Identifier and Place wrapper, which can be used as an Instruction lvalue
515
-/// or other places where a temporary target is required
516
-fn build_temporary_place<'a>(
517
- _env: &'a Environment<'a>,
518
- builder: &mut Builder<'a>,
519
-) -> IdentifierOperand<'a> {
520
- IdentifierOperand {
521
- identifier: builder.make_temporary(),
522
- effect: None,
523
- }
524
-}
525
-
474
/// Converts an ESTree literal into a HIR primitive
475
fn lower_primitive<'a>(
476
env: &'a Environment<'a>,
compiler/forget/crates/build-hir/src/builder.rs
+5
-2
@@ -6,8 +6,7 @@ use std::{cell::RefCell, collections::HashSet, rc::Rc};
6
7
use hir::{
8
BasicBlock, BlockId, BlockKind, Environment, GotoKind, Identifier, IdentifierData, InstrIx,
9
- Instruction, InstructionIdGenerator, InstructionValue, Operand, Terminal, TerminalValue, Type,
10
- HIR,
9
+ Instruction, InstructionIdGenerator, InstructionValue, Terminal, TerminalValue, Type, HIR,
10
};
11
use indexmap::IndexMap;
12
@@ -251,6 +250,10 @@ impl<'a> Builder<'a> {
250
}
251
252
/// Returns a new temporary identifier
253
+ /// This may be necessary for destructuring with default values. there
254
+ /// we synthesize a temporary identifier to store the possibly-missing value
255
+ /// into, and emit a later StoreLocal for the original identifier
256
+ #[allow(dead_code)]
257
pub(crate) fn make_temporary(&self) -> hir::Identifier<'a> {
258
hir::Identifier {
259
id: self.environment.next_identifier_id(),
compiler/forget/crates/estree-swc/src/lib.rs
+1
-1
@@ -407,7 +407,7 @@ fn convert_member_expression(cx: &Context, expr: &MemberExpr) -> estree::MemberE
407
estree::MemberExpression {
408
object: estree::ExpressionOrSuper::Expression(convert_expression(cx, &expr.obj)),
409
property,
410
- computed: false, // TODO
410
+ computed: is_computed,
411
// optional: false, // TODO
412
loc: None,
413
range: convert_span(&expr.span),
compiler/forget/crates/hir-ssa/src/enter.rs
+1
-1
@@ -3,7 +3,7 @@ use std::{cell::RefCell, rc::Rc};
3
use bumpalo::collections::{CollectIn, Vec};
4
use hir::{
5
BasicBlock, BlockId, Blocks, Environment, Function, Identifier, IdentifierData, IdentifierId,
6
- IdentifierOperand, Instruction, LValue, MutableRange, Phi, HIR,
6
+ IdentifierOperand, Instruction, LValue, MutableRange, Phi,
7
};
8
use indexmap::{IndexMap, IndexSet};
9
use thiserror::Error;
compiler/forget/crates/hir-ssa/src/leave.rs
+3
-1
@@ -1,3 +1,5 @@
1
use hir::{Environment, HIR};
2
3
-pub fn leave_ssa<'a>(env: &'a Environment, hir: &mut HIR<'a>) {}
3
+pub fn leave_ssa<'a>(_env: &'a Environment, _hir: &mut HIR<'a>) {
4
+ todo!("leave_ssa()");
5
+}
compiler/forget/crates/hir-ssa/src/minimize_phis.rs
+3
-1
@@ -1,3 +1,5 @@
1
use hir::{Environment, HIR};
2
3
-pub fn minimize_phis<'a>(env: &'a Environment, hir: &mut HIR<'a>) {}
3
+pub fn minimize_phis<'a>(_env: &'a Environment, _hir: &mut HIR<'a>) {
4
+ todo!("minimize_phis()");
5
+}
compiler/forget/crates/hir/src/function.rs
-2
@@ -1,5 +1,3 @@
1
-use std::cell::Cell;
2
-
1
use bumpalo::{
2
boxed::Box,
3
collections::{String, Vec},
compiler/forget/crates/hir/src/print.rs
+2
-2
@@ -166,7 +166,7 @@ impl<'a> Print<'a> for ArrayElement {
166
}
167
168
impl<'a> Print<'a> for Operand {
169
- fn print(&self, hir: &HIR<'a>, out: &mut impl Write) -> Result {
169
+ fn print(&self, _hir: &HIR<'a>, out: &mut impl Write) -> Result {
170
write!(
171
out,
172
"{} {}",
@@ -201,7 +201,7 @@ impl<'a> Print<'a> for IdentifierOperand<'a> {
201
}
202
203
impl<'a> Print<'a> for Identifier<'a> {
204
- fn print(&self, hir: &HIR<'a>, out: &mut impl Write) -> Result {
204
+ fn print(&self, _hir: &HIR<'a>, out: &mut impl Write) -> Result {
205
write!(
206
out,
207
"{}{}",