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 1, 2023
1 parent 8fd4744 commit 40aa140
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 284 deletions.
32 changes: 3 additions & 29 deletions boa_engine/src/builtins/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ pub(crate) enum FunctionKind {
/// The `[[PrivateMethods]]` internal slot.
private_methods: ThinVec<(PrivateName, PrivateElement)>,

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

/// The `[[ScriptOrModule]]` internal slot.
script_or_module: Option<ActiveRunnable>,
},
Expand All @@ -192,9 +189,6 @@ pub(crate) enum FunctionKind {
/// The `[[HomeObject]]` internal slot.
home_object: Option<JsObject>,

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

/// The `[[ScriptOrModule]]` internal slot.
script_or_module: Option<ActiveRunnable>,
},
Expand All @@ -210,9 +204,6 @@ pub(crate) enum FunctionKind {
/// The `[[HomeObject]]` internal slot.
home_object: Option<JsObject>,

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

/// The `[[ScriptOrModule]]` internal slot.
script_or_module: Option<ActiveRunnable>,
},
Expand All @@ -228,9 +219,6 @@ pub(crate) enum FunctionKind {
/// The `[[HomeObject]]` internal slot.
home_object: Option<JsObject>,

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

/// The `[[ScriptOrModule]]` internal slot.
script_or_module: Option<ActiveRunnable>,
},
Expand Down Expand Up @@ -273,7 +261,6 @@ unsafe impl Trace for FunctionKind {
home_object,
fields,
private_methods,
class_object,
script_or_module,
..
} => {
Expand All @@ -286,16 +273,14 @@ unsafe impl Trace for FunctionKind {
for (_, elem) in private_methods {
mark(elem);
}
mark(class_object);
mark(script_or_module);
}
Self::Async { code, environments, home_object, class_object, script_or_module }
| Self::Generator { code, environments, home_object, class_object, script_or_module}
| Self::AsyncGenerator { code, environments, home_object, class_object, script_or_module} => {
Self::Async { code, environments, home_object, script_or_module }
| Self::Generator { code, environments, home_object, script_or_module}
| Self::AsyncGenerator { code, environments, home_object, script_or_module} => {
mark(code);
mark(environments);
mark(home_object);
mark(class_object);
mark(script_or_module);
}
}
Expand Down Expand Up @@ -427,17 +412,6 @@ impl Function {
}
}

/// Sets the class object.
pub(crate) fn set_class_object(&mut self, object: JsObject) {
match &mut self.kind {
FunctionKind::Ordinary { class_object, .. }
| FunctionKind::Async { class_object, .. }
| FunctionKind::Generator { class_object, .. }
| FunctionKind::AsyncGenerator { class_object, .. } => *class_object = Some(object),
FunctionKind::Native { .. } => {}
}
}

/// Gets the `Realm` from where this function originates.
#[must_use]
pub const fn realm(&self) -> &Realm {
Expand Down
126 changes: 52 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
43 changes: 5 additions & 38 deletions boa_engine/src/vm/code_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ impl CodeBlock {
| Instruction::PushClassPrototype
| Instruction::SetClassPrototype
| Instruction::SetHomeObject
| Instruction::SetHomeObjectClass
| Instruction::Add
| Instruction::Sub
| Instruction::Div
Expand Down Expand Up @@ -632,7 +631,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 @@ -774,7 +774,6 @@ pub(crate) fn create_function_object(
code,
environments: context.vm.environments.clone(),
home_object: None,
class_object: None,
script_or_module,
},
context.realm().clone(),
Expand All @@ -788,7 +787,6 @@ pub(crate) fn create_function_object(
home_object: None,
fields: ThinVec::new(),
private_methods: ThinVec::new(),
class_object: None,
script_or_module,
},
context.realm().clone(),
Expand Down Expand Up @@ -853,7 +851,6 @@ pub(crate) fn create_function_object_fast(
code,
environments: context.vm.environments.clone(),
home_object: None,
class_object: None,
script_or_module,
}
} else {
Expand All @@ -864,7 +861,6 @@ pub(crate) fn create_function_object_fast(
home_object: None,
fields: ThinVec::new(),
private_methods: ThinVec::new(),
class_object: None,
script_or_module,
}
};
Expand Down Expand Up @@ -959,7 +955,6 @@ pub(crate) fn create_generator_function_object(
code,
environments: context.vm.environments.clone(),
home_object: None,
class_object: None,
script_or_module,
},
context.realm().clone(),
Expand All @@ -975,7 +970,6 @@ pub(crate) fn create_generator_function_object(
code,
environments: context.vm.environments.clone(),
home_object: None,
class_object: None,
script_or_module,
},
context.realm().clone(),
Expand Down Expand Up @@ -1027,8 +1021,7 @@ impl JsObject {

context.enter_realm(realm);

let (code, mut environments, class_object, script_or_module) = match function_object.kind()
{
let (code, mut environments, script_or_module) = match function_object.kind() {
FunctionKind::Native {
function,
constructor,
Expand All @@ -1053,7 +1046,6 @@ impl JsObject {
FunctionKind::Ordinary {
code,
environments,
class_object,
script_or_module,
..
} => {
Expand All @@ -1064,39 +1056,26 @@ impl JsObject {
.with_realm(context.realm().clone())
.into());
}
(
code,
environments.clone(),
class_object.clone(),
script_or_module.clone(),
)
(code, environments.clone(), script_or_module.clone())
}
FunctionKind::Async {
code,
environments,
class_object,
script_or_module,
..
}
| FunctionKind::Generator {
code,
environments,
class_object,
script_or_module,
..
}
| FunctionKind::AsyncGenerator {
code,
environments,
class_object,
script_or_module,
..
} => (
code.clone(),
environments.clone(),
class_object.clone(),
script_or_module.clone(),
),
} => (code.clone(), environments.clone(), script_or_module.clone()),
};

drop(object);
Expand All @@ -1123,18 +1102,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 @@ -358,7 +358,6 @@ impl CodeBlock {
| Instruction::PushClassPrototype
| Instruction::SetClassPrototype
| Instruction::SetHomeObject
| Instruction::SetHomeObjectClass
| Instruction::Add
| Instruction::Sub
| Instruction::Div
Expand Down Expand Up @@ -523,7 +522,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

0 comments on commit 40aa140

Please sign in to comment.