[rust] fix lints

This commit is contained in:
Joe Savona committed 2023-07-12 13:01:42 +09:00
1 parent c7ccc5dd30
commit e029e22a9a
8 files changed
+38 -85

No files matched your search

+23 -75
View File
@@ -30,7 +30,7 @@ pub fn build<'a>(
match fun.function.body {
Some(estree::FunctionBody::BlockStatement(body)) => {
lower_block_statement(env, &mut builder, *body, None)?
lower_block_statement(env, &mut builder, *body)?
}
Some(estree::FunctionBody::Expression(body)) => {
lower_expression(env, &mut builder, body)?;
@@ -62,13 +62,9 @@ pub fn build<'a>(
// In case the function did not explicitly return, terminate the final
// block with an explicit `return undefined`. If the function *did* return,
// this will be unreachable and get pruned later.
let implicit_return_value = lower_value_to_temporary(
env,
&mut builder,
InstructionValue::Primitive(hir::Primitive {
value: PrimitiveValue::Undefined,
}),
);
let implicit_return_value = builder.push(InstructionValue::Primitive(hir::Primitive {
value: PrimitiveValue::Undefined,
}));
builder.terminate(
TerminalValue::Return(hir::ReturnTerminal {
value: Operand {
@@ -96,7 +92,6 @@ fn lower_block_statement<'a>(
env: &'a Environment<'a>,
builder: &mut Builder<'a>,
stmt: BlockStatement,
label: Option<String<'a>>,
) -> Result<(), BuildDiagnostic> {
for stmt in stmt.body {
lower_statement(env, builder, stmt, None)?;
@@ -114,7 +109,7 @@ fn lower_statement<'a>(
) -> Result<(), BuildDiagnostic> {
match stmt {
Statement::BlockStatement(stmt) => {
lower_block_statement(env, builder, *stmt, label)?;
lower_block_statement(env, builder, *stmt)?;
}
Statement::BreakStatement(stmt) => {
let block = builder.resolve_break(stmt.label.as_ref())?;
@@ -139,13 +134,9 @@ fn lower_statement<'a>(
Statement::ReturnStatement(stmt) => {
let ix = match stmt.argument {
Some(argument) => lower_expression(env, builder, argument)?,
None => lower_value_to_temporary(
env,
builder,
InstructionValue::Primitive(hir::Primitive {
value: PrimitiveValue::Undefined,
}),
),
None => builder.push(InstructionValue::Primitive(hir::Primitive {
value: PrimitiveValue::Undefined,
})),
};
builder.terminate(
TerminalValue::Return(hir::ReturnTerminal {
@@ -196,19 +187,15 @@ fn lower_statement<'a>(
));
}
};
lower_value_to_temporary(
env,
builder,
InstructionValue::DeclareLocal(hir::DeclareLocal {
lvalue: LValue {
identifier: IdentifierOperand {
identifier,
effect: None,
},
kind,
builder.push(InstructionValue::DeclareLocal(hir::DeclareLocal {
lvalue: LValue {
identifier: IdentifierOperand {
identifier,
effect: None,
},
}),
);
kind,
},
}));
}
}
}
@@ -450,17 +437,13 @@ fn lower_assignment<'a>(
AssignmentTarget::Pattern(lvalue) => match lvalue {
Pattern::Identifier(lvalue) => {
let identifier = lower_identifier_for_assignment(env, builder, kind, *lvalue)?;
lower_value_to_temporary(
env,
builder,
InstructionValue::StoreLocal(hir::StoreLocal {
lvalue: LValue { identifier, kind },
value: Operand {
ix: value,
effect: None,
},
}),
)
builder.push(InstructionValue::StoreLocal(hir::StoreLocal {
lvalue: LValue { identifier, kind },
value: Operand {
ix: value,
effect: None,
},
}))
}
_ => todo!("lower assignment pattern for {:#?}", lvalue),
},
@@ -488,41 +471,6 @@ fn lower_identifier_for_assignment<'a>(
}
}
/// Given an already lowered InstructionValue:
/// - if the instruction is a LoadLocal for a temporary location, avoid the indirection
/// and return the place that the LoadLocal loads from
/// - otherwise, create a new temporary place, push an instruction to associate the value with
/// that temporary, and return a clone of the temporary
fn lower_value_to_temporary<'a>(
env: &'a Environment<'a>,
builder: &mut Builder<'a>,
value: InstructionValue<'a>,
) -> InstrIx {
// if let InstructionValue::LoadLocal(LoadLocal {
// place:
// place @ Operand {
// identifier: Identifier { name: None, .. },
// ..
// },
// }) = value
// {
// return place;
// }
builder.push(value)
}
/// Constructs a temporary Identifier and Place wrapper, which can be used as an Instruction lvalue
/// or other places where a temporary target is required
fn build_temporary_place<'a>(
_env: &'a Environment<'a>,
builder: &mut Builder<'a>,
) -> IdentifierOperand<'a> {
IdentifierOperand {
identifier: builder.make_temporary(),
effect: None,
}
}
/// Converts an ESTree literal into a HIR primitive
fn lower_primitive<'a>(
env: &'a Environment<'a>,
@@ -6,8 +6,7 @@ use std::{cell::RefCell, collections::HashSet, rc::Rc};
use hir::{
BasicBlock, BlockId, BlockKind, Environment, GotoKind, Identifier, IdentifierData, InstrIx,
Instruction, InstructionIdGenerator, InstructionValue, Operand, Terminal, TerminalValue, Type,
HIR,
Instruction, InstructionIdGenerator, InstructionValue, Terminal, TerminalValue, Type, HIR,
};
use indexmap::IndexMap;
@@ -251,6 +250,10 @@ impl<'a> Builder<'a> {
}
/// Returns a new temporary identifier
/// This may be necessary for destructuring with default values. there
/// we synthesize a temporary identifier to store the possibly-missing value
/// into, and emit a later StoreLocal for the original identifier
#[allow(dead_code)]
pub(crate) fn make_temporary(&self) -> hir::Identifier<'a> {
hir::Identifier {
id: self.environment.next_identifier_id(),
+1 -1
View File
@@ -407,7 +407,7 @@ fn convert_member_expression(cx: &Context, expr: &MemberExpr) -> estree::MemberE
estree::MemberExpression {
object: estree::ExpressionOrSuper::Expression(convert_expression(cx, &expr.obj)),
property,
computed: false, // TODO
computed: is_computed,
// optional: false, // TODO
loc: None,
range: convert_span(&expr.span),
+1 -1
View File
@@ -3,7 +3,7 @@ use std::{cell::RefCell, rc::Rc};
use bumpalo::collections::{CollectIn, Vec};
use hir::{
BasicBlock, BlockId, Blocks, Environment, Function, Identifier, IdentifierData, IdentifierId,
IdentifierOperand, Instruction, LValue, MutableRange, Phi, HIR,
IdentifierOperand, Instruction, LValue, MutableRange, Phi,
};
use indexmap::{IndexMap, IndexSet};
use thiserror::Error;
+3 -1
View File
@@ -1,3 +1,5 @@
use hir::{Environment, HIR};
pub fn leave_ssa<'a>(env: &'a Environment, hir: &mut HIR<'a>) {}
pub fn leave_ssa<'a>(_env: &'a Environment, _hir: &mut HIR<'a>) {
todo!("leave_ssa()");
}
@@ -1,3 +1,5 @@
use hir::{Environment, HIR};
pub fn minimize_phis<'a>(env: &'a Environment, hir: &mut HIR<'a>) {}
pub fn minimize_phis<'a>(_env: &'a Environment, _hir: &mut HIR<'a>) {
todo!("minimize_phis()");
}
@@ -1,5 +1,3 @@
use std::cell::Cell;
use bumpalo::{
boxed::Box,
collections::{String, Vec},
+2 -2
View File
@@ -166,7 +166,7 @@ impl<'a> Print<'a> for ArrayElement {
}
impl<'a> Print<'a> for Operand {
fn print(&self, hir: &HIR<'a>, out: &mut impl Write) -> Result {
fn print(&self, _hir: &HIR<'a>, out: &mut impl Write) -> Result {
write!(
out,
"{} {}",
@@ -201,7 +201,7 @@ impl<'a> Print<'a> for IdentifierOperand<'a> {
}
impl<'a> Print<'a> for Identifier<'a> {
fn print(&self, hir: &HIR<'a>, out: &mut impl Write) -> Result {
fn print(&self, _hir: &HIR<'a>, out: &mut impl Write) -> Result {
write!(
out,
"{}{}",