diff --git a/compiler/forget/crates/build-hir/src/build.rs b/compiler/forget/crates/build-hir/src/build.rs index 4b9e7bb2fb..af4d4fc82c 100644 --- a/compiler/forget/crates/build-hir/src/build.rs +++ b/compiler/forget/crates/build-hir/src/build.rs @@ -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>, ) -> 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>, diff --git a/compiler/forget/crates/build-hir/src/builder.rs b/compiler/forget/crates/build-hir/src/builder.rs index 1a09348a1c..82534bdbbd 100644 --- a/compiler/forget/crates/build-hir/src/builder.rs +++ b/compiler/forget/crates/build-hir/src/builder.rs @@ -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(), diff --git a/compiler/forget/crates/estree-swc/src/lib.rs b/compiler/forget/crates/estree-swc/src/lib.rs index d6e4221a29..f90d3eb8c2 100644 --- a/compiler/forget/crates/estree-swc/src/lib.rs +++ b/compiler/forget/crates/estree-swc/src/lib.rs @@ -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), diff --git a/compiler/forget/crates/hir-ssa/src/enter.rs b/compiler/forget/crates/hir-ssa/src/enter.rs index 8f45ea6e59..dbe3cee914 100644 --- a/compiler/forget/crates/hir-ssa/src/enter.rs +++ b/compiler/forget/crates/hir-ssa/src/enter.rs @@ -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; diff --git a/compiler/forget/crates/hir-ssa/src/leave.rs b/compiler/forget/crates/hir-ssa/src/leave.rs index 590fbaae5e..151cd33dc3 100644 --- a/compiler/forget/crates/hir-ssa/src/leave.rs +++ b/compiler/forget/crates/hir-ssa/src/leave.rs @@ -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()"); +} diff --git a/compiler/forget/crates/hir-ssa/src/minimize_phis.rs b/compiler/forget/crates/hir-ssa/src/minimize_phis.rs index a76e029205..05db37903f 100644 --- a/compiler/forget/crates/hir-ssa/src/minimize_phis.rs +++ b/compiler/forget/crates/hir-ssa/src/minimize_phis.rs @@ -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()"); +} diff --git a/compiler/forget/crates/hir/src/function.rs b/compiler/forget/crates/hir/src/function.rs index ac9e832349..6e48ce2525 100644 --- a/compiler/forget/crates/hir/src/function.rs +++ b/compiler/forget/crates/hir/src/function.rs @@ -1,5 +1,3 @@ -use std::cell::Cell; - use bumpalo::{ boxed::Box, collections::{String, Vec}, diff --git a/compiler/forget/crates/hir/src/print.rs b/compiler/forget/crates/hir/src/print.rs index d9e0ef4c01..1a401a2ef4 100644 --- a/compiler/forget/crates/hir/src/print.rs +++ b/compiler/forget/crates/hir/src/print.rs @@ -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, "{}{}",