LibJS: Remove dead C++ bytecode compilation functions

Remove Bytecode::compile() and the old create() overloads on
ECMAScriptFunctionObject that accepted C++ AST nodes. These
have no remaining callers now that all compilation goes through
the Rust pipeline.

Also remove the if-constexpr Parse Node branch from
async_block_start, since the Statement template instantiation
was already removed.

Fix transitive include dependencies on Generator.h by adding
explicit includes for headers that were previously pulled in
transitively.
This commit is contained in:
Andreas Kling 2026-03-19 12:52:19 -05:00 committed by Andreas Kling
parent 3518efd71c
commit 272562ddc5
9 changed files with 7 additions and 126 deletions

View file

@ -12,6 +12,7 @@
#include <LibJS/Runtime/DeclarativeEnvironment.h>
#include <LibJS/Runtime/ECMAScriptFunctionObject.h>
#include <LibJS/Runtime/ModuleEnvironment.h>
#include <LibJS/Runtime/Reference.h>
#include <LibJS/Runtime/TypedArray.h>
#include <LibJS/Runtime/Value.h>
#include <LibJS/Runtime/ValueInlines.h>

View file

@ -13,7 +13,6 @@
#include <LibJS/Bytecode/AsmInterpreter/AsmInterpreter.h>
#include <LibJS/Bytecode/BasicBlock.h>
#include <LibJS/Bytecode/FormatOperand.h>
#include <LibJS/Bytecode/Generator.h>
#include <LibJS/Bytecode/Instruction.h>
#include <LibJS/Bytecode/Interpreter.h>
#include <LibJS/Bytecode/Label.h>
@ -880,30 +879,6 @@ void Interpreter::catch_exception(Operand dst)
reg(Register::exception()) = js_special_empty_value();
}
GC::Ref<Bytecode::Executable> compile(VM& vm, ASTNode const& node, FunctionKind kind, Utf16FlyString const& name)
{
auto bytecode_executable = Bytecode::Generator::generate_from_ast_node(vm, node, kind);
bytecode_executable->name = name;
if (Bytecode::g_dump_bytecode)
bytecode_executable->dump();
return bytecode_executable;
}
GC::Ref<Bytecode::Executable> compile(VM& vm, GC::Ref<SharedFunctionInstanceData const> shared_function_instance_data, BuiltinAbstractOperationsEnabled builtin_abstract_operations_enabled)
{
auto const& name = shared_function_instance_data->m_name;
auto bytecode_executable = Bytecode::Generator::generate_from_function(vm, shared_function_instance_data, builtin_abstract_operations_enabled);
bytecode_executable->name = name;
if (Bytecode::g_dump_bytecode)
bytecode_executable->dump();
return bytecode_executable;
}
// NOTE: This function assumes that the index is valid within the TypedArray,
// and that the TypedArray is not detached.
template<typename T>

View file

@ -116,7 +116,4 @@ private:
JS_API extern bool g_dump_bytecode;
GC::Ref<Bytecode::Executable> compile(VM&, ASTNode const&, JS::FunctionKind kind, Utf16FlyString const& name);
GC::Ref<Bytecode::Executable> compile(VM&, GC::Ref<SharedFunctionInstanceData const>, BuiltinAbstractOperationsEnabled builtin_abstract_operations_enabled);
}

View file

@ -8,6 +8,7 @@
#include <LibJS/Bytecode/Executable.h>
#include <LibJS/Bytecode/IdentifierTable.h>
#include <LibJS/Bytecode/PutKind.h>
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/Accessor.h>
#include <LibJS/Runtime/Completion.h>

View file

@ -10,9 +10,6 @@
#include <AK/Debug.h>
#include <AK/Function.h>
#include <LibGC/DeferGC.h>
#include <LibJS/AST.h>
#include <LibJS/Bytecode/BasicBlock.h>
#include <LibJS/Bytecode/Generator.h>
#include <LibJS/Bytecode/Interpreter.h>
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/Array.h>
@ -51,83 +48,6 @@ static GC::Ref<Object> prototype_for_function_kind(Realm& realm, FunctionKind ki
VERIFY_NOT_REACHED();
}
GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& realm, Utf16FlyString name, Utf16String source_text, Statement const& ecmascript_code, NonnullRefPtr<FunctionParameters const> parameters, i32 function_length, Vector<LocalVariable> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind kind, bool is_strict, FunctionParsingInsights parsing_insights, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
{
auto prototype = prototype_for_function_kind(realm, kind);
auto shared_data = realm.heap().allocate<SharedFunctionInstanceData>(
realm.vm(),
kind,
move(name),
function_length,
*parameters,
ecmascript_code,
Utf16View {},
is_strict,
is_arrow_function,
parsing_insights,
move(local_variables_names));
shared_data->m_class_field_initializer_name = move(class_field_initializer_name);
shared_data->m_source_text_owner = move(source_text);
shared_data->m_source_text = shared_data->m_source_text_owner.utf16_view();
return realm.create<ECMAScriptFunctionObject>(
move(shared_data),
parent_environment,
private_environment,
*prototype);
}
GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& realm, Utf16FlyString name, Utf16View source_text, Statement const& ecmascript_code, NonnullRefPtr<FunctionParameters const> parameters, i32 function_length, Vector<LocalVariable> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind kind, bool is_strict, FunctionParsingInsights parsing_insights, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
{
auto prototype = prototype_for_function_kind(realm, kind);
auto shared_data = realm.heap().allocate<SharedFunctionInstanceData>(
realm.vm(),
kind,
move(name),
function_length,
*parameters,
ecmascript_code,
source_text,
is_strict,
is_arrow_function,
parsing_insights,
move(local_variables_names));
shared_data->m_class_field_initializer_name = move(class_field_initializer_name);
return realm.create<ECMAScriptFunctionObject>(
move(shared_data),
parent_environment,
private_environment,
*prototype);
}
GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& realm, Utf16FlyString name, Object& prototype, Utf16View source_text, Statement const& ecmascript_code, NonnullRefPtr<FunctionParameters const> parameters, i32 function_length, Vector<LocalVariable> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind kind, bool is_strict, FunctionParsingInsights parsing_insights, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
{
auto shared_data = realm.heap().allocate<SharedFunctionInstanceData>(
realm.vm(),
kind,
move(name),
function_length,
*parameters,
ecmascript_code,
source_text,
is_strict,
is_arrow_function,
parsing_insights,
move(local_variables_names));
shared_data->m_class_field_initializer_name = move(class_field_initializer_name);
return realm.create<ECMAScriptFunctionObject>(
move(shared_data),
parent_environment,
private_environment,
prototype);
}
GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create_from_function_data(
GC::Ref<Realm> realm,
GC::Ref<SharedFunctionInstanceData> shared_data,
@ -538,17 +458,11 @@ void async_block_start(VM& vm, T const& async_body, PromiseCapability const& pro
// a. Let acAsyncContext be the running execution context.
// b. If asyncBody is a Parse Node, then
if constexpr (!IsSame<T, GC::Function<Completion()>>) {
// i. Let result be Completion(Evaluation of asyncBody).
auto executable = Bytecode::compile(vm, async_body, FunctionKind::Async, "AsyncBlockStart"_utf16_fly_string);
result = vm.bytecode_interpreter().run_executable(vm.running_execution_context(), *executable, {});
}
// i. Let result be Completion(Evaluation of asyncBody).
// c. Else,
else {
// i. Assert: asyncBody is an Abstract Closure with no parameters.
// ii. Let result be asyncBody().
result = async_body.function()();
}
// i. Assert: asyncBody is an Abstract Closure with no parameters.
// ii. Let result be asyncBody().
result = async_body.function()();
// d. Assert: If we return here, the async function either threw an exception or performed an implicit or explicit return; all awaiting is done.
// e. Remove acAsyncContext from the execution context stack and restore the execution context that is at the top of the execution context stack as the running execution context.
vm.pop_execution_context();

View file

@ -8,7 +8,6 @@
#pragma once
#include <LibJS/Bytecode/Generator.h>
#include <LibJS/Bytecode/Interpreter.h>
#include <LibJS/Export.h>
#include <LibJS/Runtime/ClassFieldDefinition.h>
@ -30,10 +29,6 @@ class JS_API ECMAScriptFunctionObject final : public FunctionObject {
GC_DECLARE_ALLOCATOR(ECMAScriptFunctionObject);
public:
static GC::Ref<ECMAScriptFunctionObject> create(Realm&, Utf16FlyString name, Utf16String source_text, Statement const& ecmascript_code, NonnullRefPtr<FunctionParameters const> parameters, i32 function_length, Vector<LocalVariable> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind, bool is_strict, FunctionParsingInsights, bool is_arrow_function = false, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name = {});
static GC::Ref<ECMAScriptFunctionObject> create(Realm&, Utf16FlyString name, Utf16View source_text, Statement const& ecmascript_code, NonnullRefPtr<FunctionParameters const> parameters, i32 function_length, Vector<LocalVariable> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind, bool is_strict, FunctionParsingInsights, bool is_arrow_function = false, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name = {});
static GC::Ref<ECMAScriptFunctionObject> create(Realm&, Utf16FlyString name, Object& prototype, Utf16View source_text, Statement const& ecmascript_code, NonnullRefPtr<FunctionParameters const> parameters, i32 function_length, Vector<LocalVariable> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind, bool is_strict, FunctionParsingInsights, bool is_arrow_function = false, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name = {});
[[nodiscard]] static GC::Ref<ECMAScriptFunctionObject> create_from_function_data(
GC::Ref<Realm>,
GC::Ref<SharedFunctionInstanceData>,

View file

@ -5,7 +5,6 @@
*/
#include <AK/TemporaryChange.h>
#include <LibJS/Bytecode/Generator.h>
#include <LibJS/Bytecode/Interpreter.h>
#include <LibJS/Runtime/CompletionCell.h>
#include <LibJS/Runtime/GeneratorObject.h>

View file

@ -6,6 +6,7 @@
#include <LibJS/Runtime/GeneratorPrototype.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Iterator.h>
namespace JS {

View file

@ -13,8 +13,6 @@
#include <LibCore/ArgsParser.h>
#include <LibCore/ConfigFile.h>
#include <LibCore/StandardPaths.h>
#include <LibJS/Bytecode/BasicBlock.h>
#include <LibJS/Bytecode/Generator.h>
#include <LibJS/Bytecode/Interpreter.h>
#include <LibJS/Console.h>
#include <LibJS/Contrib/Test262/GlobalObject.h>