Skip to content

Commit

Permalink
Remove unused class environments
Browse files Browse the repository at this point in the history
  • Loading branch information
raskad committed Oct 3, 2023
1 parent 55466b0 commit 265a4c9
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 245 deletions.
8 changes: 0 additions & 8 deletions boa_engine/src/builtins/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,6 @@ pub struct OrdinaryFunction {
/// The `[[HomeObject]]` internal slot.
pub(crate) home_object: Option<JsObject>,

/// The class object that this function is associated with.
pub(crate) class_object: Option<JsObject>,

/// The `[[ScriptOrModule]]` internal slot.
pub(crate) script_or_module: Option<ActiveRunnable>,

Expand Down Expand Up @@ -322,11 +319,6 @@ impl OrdinaryFunction {
}
}

/// Sets the class object.
pub(crate) fn set_class_object(&mut self, object: JsObject) {
self.class_object = Some(object);
}

/// Gets the `Realm` from where this function originates.
#[must_use]
pub const fn realm(&self) -> &Realm {
Expand Down
127 changes: 53 additions & 74 deletions boa_engine/src/bytecompiler/class.rs

Large diffs are not rendered by default.

17 changes: 0 additions & 17 deletions boa_engine/src/bytecompiler/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub(crate) struct FunctionCompiler {
strict: bool,
arrow: bool,
binding_identifier: Option<Sym>,
class_name: Option<Sym>,
}

impl FunctionCompiler {
Expand All @@ -34,7 +33,6 @@ impl FunctionCompiler {
strict: false,
arrow: false,
binding_identifier: None,
class_name: None,
}
}

Expand Down Expand Up @@ -79,12 +77,6 @@ impl FunctionCompiler {
self
}

/// Indicate if the function has a class associated with it.
pub(crate) const fn class_name(mut self, class_name: Sym) -> Self {
self.class_name = Some(class_name);
self
}

/// Compile a function statement list and it's parameters into bytecode.
pub(crate) fn compile(
mut self,
Expand All @@ -106,11 +98,6 @@ impl FunctionCompiler {
compiler.this_mode = ThisMode::Lexical;
}

if let Some(class_name) = self.class_name {
compiler.push_compile_environment(false);
compiler.create_immutable_binding(class_name.into(), true);
}

if let Some(binding_identifier) = self.binding_identifier {
compiler.code_block_flags |= CodeBlockFlags::HAS_BINDING_IDENTIFIER;
compiler.push_compile_environment(false);
Expand Down Expand Up @@ -184,10 +171,6 @@ impl FunctionCompiler {
compiler.pop_compile_environment();
}

if self.class_name.is_some() {
compiler.pop_compile_environment();
}

compiler.params = parameters.clone();

Gc::new(compiler.finish())
Expand Down
3 changes: 1 addition & 2 deletions boa_engine/src/bytecompiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ impl<'ctx, 'host> ByteCompiler<'ctx, 'host> {
}

/// Compile a class method AST Node into bytecode.
fn method(&mut self, function: FunctionSpec<'_>, class_name: Sym) {
fn method(&mut self, function: FunctionSpec<'_>) {
let (generator, r#async, arrow) = (
function.kind.is_generator(),
function.kind.is_async(),
Expand Down Expand Up @@ -1409,7 +1409,6 @@ impl<'ctx, 'host> ByteCompiler<'ctx, 'host> {
.strict(true)
.arrow(arrow)
.binding_identifier(binding_identifier)
.class_name(class_name)
.compile(
parameters,
body,
Expand Down
22 changes: 2 additions & 20 deletions boa_engine/src/vm/code_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ impl CodeBlock {
| Instruction::PushClassPrototype
| Instruction::SetClassPrototype
| Instruction::SetHomeObject
| Instruction::SetHomeObjectClass
| Instruction::Add
| Instruction::Sub
| Instruction::Div
Expand Down Expand Up @@ -643,7 +642,8 @@ impl CodeBlock {
| Instruction::Reserved54
| Instruction::Reserved55
| Instruction::Reserved56
| Instruction::Reserved57 => unreachable!("Reserved opcodes are unrechable"),
| Instruction::Reserved57
| Instruction::Reserved58 => unreachable!("Reserved opcodes are unrechable"),
}
}
}
Expand Down Expand Up @@ -784,7 +784,6 @@ pub(crate) fn create_function_object(
code,
environments: context.vm.environments.clone(),
home_object: None,
class_object: None,
script_or_module,
kind: FunctionKind::Async,
realm: context.realm().clone(),
Expand All @@ -794,7 +793,6 @@ pub(crate) fn create_function_object(
code,
environments: context.vm.environments.clone(),
home_object: None,
class_object: None,
script_or_module,
kind: FunctionKind::Ordinary {
constructor_kind: ConstructorKind::Base,
Expand Down Expand Up @@ -871,7 +869,6 @@ pub(crate) fn create_function_object_fast(
let function = OrdinaryFunction {
code,
environments: context.vm.environments.clone(),
class_object: None,
script_or_module,
home_object: None,
kind,
Expand Down Expand Up @@ -965,7 +962,6 @@ pub(crate) fn create_generator_function_object(
code,
environments: context.vm.environments.clone(),
home_object: None,
class_object: None,
script_or_module,
kind: FunctionKind::AsyncGenerator,
realm: context.realm().clone(),
Expand All @@ -980,7 +976,6 @@ pub(crate) fn create_generator_function_object(
code,
environments: context.vm.environments.clone(),
home_object: None,
class_object: None,
script_or_module,
kind: FunctionKind::Generator,
realm: context.realm().clone(),
Expand Down Expand Up @@ -1043,7 +1038,6 @@ impl JsObject {
let code = function.code.clone();
let mut environments = function.environments.clone();
let script_or_module = function.script_or_module.clone();
let class_object = function.class_object.clone();

drop(object);

Expand All @@ -1069,18 +1063,6 @@ impl JsObject {

let mut last_env = code.compile_environments.len() - 1;

if let Some(class_object) = class_object {
let index = context
.vm
.environments
.push_lexical(code.compile_environments[last_env].clone());
context
.vm
.environments
.put_lexical_value(index, 0, class_object.into());
last_env -= 1;
}

if code.has_binding_identifier() {
let index = context
.vm
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/vm/flowgraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ impl CodeBlock {
| Instruction::PushClassPrototype
| Instruction::SetClassPrototype
| Instruction::SetHomeObject
| Instruction::SetHomeObjectClass
| Instruction::Add
| Instruction::Sub
| Instruction::Div
Expand Down Expand Up @@ -522,7 +521,8 @@ impl CodeBlock {
| Instruction::Reserved54
| Instruction::Reserved55
| Instruction::Reserved56
| Instruction::Reserved57 => unreachable!("Reserved opcodes are unrechable"),
| Instruction::Reserved57
| Instruction::Reserved58 => unreachable!("Reserved opcodes are unrechable"),
}
}

Expand Down
17 changes: 0 additions & 17 deletions boa_engine/src/vm/opcode/define/class/getter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{
builtins::function::set_function_name,
object::CONSTRUCTOR,
property::PropertyDescriptor,
vm::{opcode::Operation, CompletionType},
Context, JsResult, JsString,
Expand Down Expand Up @@ -29,7 +28,6 @@ impl DefineClassStaticGetterByName {
.as_function_mut()
.expect("method must be function object");
function_mut.set_home_object(class.clone());
function_mut.set_class_object(class.clone());
}
let set = class
.__get_own_property__(&key, context)?
Expand Down Expand Up @@ -93,13 +91,6 @@ impl DefineClassGetterByName {
.as_function_mut()
.expect("method must be function object");
function_mut.set_home_object(class_proto.clone());
let class = class_proto
.get(CONSTRUCTOR, context)
.expect("class prototype must have constructor")
.as_object()
.expect("class must be object")
.clone();
function_mut.set_class_object(class);
}
let set = class_proto
.__get_own_property__(&key, context)?
Expand Down Expand Up @@ -169,7 +160,6 @@ impl Operation for DefineClassStaticGetterByValue {
.as_function_mut()
.expect("method must be function object");
function_mut.set_home_object(class.clone());
function_mut.set_class_object(class.clone());
}
let set = class
.__get_own_property__(&key, context)?
Expand Down Expand Up @@ -219,13 +209,6 @@ impl Operation for DefineClassGetterByValue {
.as_function_mut()
.expect("method must be function object");
function_mut.set_home_object(class_proto.clone());
let class = class_proto
.get(CONSTRUCTOR, context)
.expect("class prototype must have constructor")
.as_object()
.expect("class must be object")
.clone();
function_mut.set_class_object(class);
}
let set = class_proto
.__get_own_property__(&key, context)?
Expand Down
17 changes: 0 additions & 17 deletions boa_engine/src/vm/opcode/define/class/method.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{
builtins::function::set_function_name,
object::CONSTRUCTOR,
property::PropertyDescriptor,
vm::{opcode::Operation, CompletionType},
Context, JsResult,
Expand Down Expand Up @@ -29,7 +28,6 @@ impl DefineClassStaticMethodByName {
.as_function_mut()
.expect("method must be function object");
function_mut.set_home_object(class.clone());
function_mut.set_class_object(class.clone());
}

class.__define_own_property__(
Expand Down Expand Up @@ -89,13 +87,6 @@ impl DefineClassMethodByName {
.as_function_mut()
.expect("method must be function object");
function_mut.set_home_object(class_proto.clone());
let class = class_proto
.get(CONSTRUCTOR, context)
.expect("class prototype must have constructor")
.as_object()
.expect("class must be object")
.clone();
function_mut.set_class_object(class);
}

class_proto.__define_own_property__(
Expand Down Expand Up @@ -161,7 +152,6 @@ impl Operation for DefineClassStaticMethodByValue {
.as_function_mut()
.expect("method must be function object");
function_mut.set_home_object(class.clone());
function_mut.set_class_object(class.clone());
}

class.define_property_or_throw(
Expand Down Expand Up @@ -207,13 +197,6 @@ impl Operation for DefineClassMethodByValue {
.as_function_mut()
.expect("method must be function object");
function_mut.set_home_object(class_proto.clone());
let class = class_proto
.get(CONSTRUCTOR, context)
.expect("class prototype must have constructor")
.as_object()
.expect("class must be object")
.clone();
function_mut.set_class_object(class);
}

class_proto.__define_own_property__(
Expand Down
17 changes: 0 additions & 17 deletions boa_engine/src/vm/opcode/define/class/setter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{
builtins::function::set_function_name,
object::CONSTRUCTOR,
property::PropertyDescriptor,
vm::{opcode::Operation, CompletionType},
Context, JsResult, JsString,
Expand Down Expand Up @@ -29,7 +28,6 @@ impl DefineClassStaticSetterByName {
.as_function_mut()
.expect("method must be function object");
function_mut.set_home_object(class.clone());
function_mut.set_class_object(class.clone());
}
let get = class
.__get_own_property__(&key, context)?
Expand Down Expand Up @@ -94,13 +92,6 @@ impl DefineClassSetterByName {
.as_function_mut()
.expect("method must be function object");
function_mut.set_home_object(class_proto.clone());
let class = class_proto
.get(CONSTRUCTOR, context)
.expect("class prototype must have constructor")
.as_object()
.expect("class must be object")
.clone();
function_mut.set_class_object(class);
}
let get = class_proto
.__get_own_property__(&key, context)?
Expand Down Expand Up @@ -172,7 +163,6 @@ impl Operation for DefineClassStaticSetterByValue {
.as_function_mut()
.expect("method must be function object");
function_mut.set_home_object(class.clone());
function_mut.set_class_object(class.clone());
}
let get = class
.__get_own_property__(&key, context)?
Expand Down Expand Up @@ -224,13 +214,6 @@ impl Operation for DefineClassSetterByValue {
.as_function_mut()
.expect("method must be function object");
function_mut.set_home_object(class_proto.clone());
let class = class_proto
.get(CONSTRUCTOR, context)
.expect("class prototype must have constructor")
.as_object()
.expect("class must be object")
.clone();
function_mut.set_class_object(class);
}
let get = class_proto
.__get_own_property__(&key, context)?
Expand Down
9 changes: 2 additions & 7 deletions boa_engine/src/vm/opcode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,13 +736,6 @@ generate_opcodes! {
/// Stack: home, function **=>** home, function
SetHomeObject,

/// Set home object internal slot of a class method.
///
/// Operands:
///
/// Stack: home, function **=>** home, function
SetHomeObjectClass,

/// Set the prototype of an object if the value is an object or null.
///
/// Operands:
Expand Down Expand Up @@ -2178,6 +2171,8 @@ generate_opcodes! {
Reserved56 => Reserved,
/// Reserved [`Opcode`].
Reserved57 => Reserved,
/// Reserved [`Opcode`].
Reserved58 => Reserved,
}

/// Specific opcodes for bindings.
Expand Down
2 changes: 0 additions & 2 deletions boa_engine/src/vm/opcode/push/class/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ impl Operation for PushClassField {
.as_object()
.expect("class must be function object");
field_function.set_home_object(class_object.clone());
field_function.set_class_object(class_object.clone());
class_object
.borrow_mut()
.as_function_mut()
Expand Down Expand Up @@ -70,7 +69,6 @@ impl PushClassFieldPrivate {
.as_object()
.expect("class must be function object");
field_function.set_home_object(class_object.clone());
field_function.set_class_object(class_object.clone());

class_object
.borrow_mut()
Expand Down

0 comments on commit 265a4c9

Please sign in to comment.