From ef8ac6ea7d792830172b8cd20cc077b739764887 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 14 Jun 2026 17:04:02 +0200 Subject: [PATCH] LibJS: Remove unused C++ bytecode block classes The Rust bytecode generator now owns basic block construction. The old C++ BasicBlock class no longer has any users. Label no longer needs to translate from BasicBlock. Remove the now-empty Label.cpp from the build as well. --- Libraries/LibJS/Bytecode/BasicBlock.cpp | 32 ---------- Libraries/LibJS/Bytecode/BasicBlock.h | 74 ---------------------- Libraries/LibJS/Bytecode/Executable.cpp | 1 - Libraries/LibJS/Bytecode/Label.cpp | 17 ----- Libraries/LibJS/Bytecode/Label.h | 18 ++---- Libraries/LibJS/CMakeLists.txt | 2 - Libraries/LibJS/Forward.h | 1 - Libraries/LibJS/Runtime/ExecutionContext.h | 1 - 8 files changed, 5 insertions(+), 141 deletions(-) delete mode 100644 Libraries/LibJS/Bytecode/BasicBlock.cpp delete mode 100644 Libraries/LibJS/Bytecode/BasicBlock.h delete mode 100644 Libraries/LibJS/Bytecode/Label.cpp diff --git a/Libraries/LibJS/Bytecode/BasicBlock.cpp b/Libraries/LibJS/Bytecode/BasicBlock.cpp deleted file mode 100644 index f33dd2ce57..0000000000 --- a/Libraries/LibJS/Bytecode/BasicBlock.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2021, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include -#include - -namespace JS::Bytecode { - -NonnullOwnPtr BasicBlock::create(u32 index, String name) -{ - return adopt_own(*new BasicBlock(index, move(name))); -} - -BasicBlock::BasicBlock(u32 index, String name) - : m_index(index) - , m_name(move(name)) -{ -} - -BasicBlock::~BasicBlock() = default; - -void BasicBlock::grow(size_t additional_size) -{ - m_buffer.grow_capacity(m_buffer.size() + additional_size); - m_buffer.resize(m_buffer.size() + additional_size); -} - -} diff --git a/Libraries/LibJS/Bytecode/BasicBlock.h b/Libraries/LibJS/Bytecode/BasicBlock.h deleted file mode 100644 index 56554b4760..0000000000 --- a/Libraries/LibJS/Bytecode/BasicBlock.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2021, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include -#include -#include - -namespace JS::Bytecode { - -class BasicBlock { - AK_MAKE_NONCOPYABLE(BasicBlock); - -public: - static NonnullOwnPtr create(u32 index, String name); - ~BasicBlock(); - - u32 index() const { return m_index; } - - ReadonlyBytes instruction_stream() const LIFETIME_BOUND { return m_buffer.span(); } - u8* data() { return m_buffer.data(); } - u8 const* data() const { return m_buffer.data(); } - size_t size() const { return m_buffer.size(); } - - void rewind() - { - m_buffer.resize_and_keep_capacity(m_last_instruction_start_offset); - m_terminated = false; - } - - void grow(size_t additional_size); - - void terminate(Badge) { m_terminated = true; } - bool is_terminated() const { return m_terminated; } - - String const& name() const { return m_name; } - - void set_handler(BasicBlock const& handler) { m_handler = &handler; } - - BasicBlock const* handler() const { return m_handler; } - - auto const& source_map() const { return m_source_map; } - void add_source_map_entry(u32 bytecode_offset, Position source_start) - { - m_source_map.append({ bytecode_offset, source_start.line, source_start.column }); - } - - [[nodiscard]] bool has_resolved_this() const { return m_has_resolved_this; } - void set_has_resolved_this() { m_has_resolved_this = true; } - - [[nodiscard]] size_t last_instruction_start_offset() const { return m_last_instruction_start_offset; } - void set_last_instruction_start_offset(size_t offset) { m_last_instruction_start_offset = offset; } - -private: - explicit BasicBlock(u32 index, String name); - - u32 m_index { 0 }; - Vector m_buffer; - BasicBlock const* m_handler { nullptr }; - String m_name; - bool m_terminated { false }; - bool m_has_resolved_this { false }; - - Vector m_source_map; - - size_t m_last_instruction_start_offset { 0 }; -}; - -} diff --git a/Libraries/LibJS/Bytecode/Executable.cpp b/Libraries/LibJS/Bytecode/Executable.cpp index 91a396765e..d30fba0c9a 100644 --- a/Libraries/LibJS/Bytecode/Executable.cpp +++ b/Libraries/LibJS/Bytecode/Executable.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include diff --git a/Libraries/LibJS/Bytecode/Label.cpp b/Libraries/LibJS/Bytecode/Label.cpp deleted file mode 100644 index 242c711642..0000000000 --- a/Libraries/LibJS/Bytecode/Label.cpp +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2024, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include - -namespace JS::Bytecode { - -Label::Label(Bytecode::BasicBlock const& basic_block) - : m_address_or_basic_block_index(basic_block.index()) -{ -} - -} diff --git a/Libraries/LibJS/Bytecode/Label.h b/Libraries/LibJS/Bytecode/Label.h index 9536458ca0..122c9a0ecc 100644 --- a/Libraries/LibJS/Bytecode/Label.h +++ b/Libraries/LibJS/Bytecode/Label.h @@ -10,27 +10,19 @@ namespace JS::Bytecode { -class BasicBlock; - class Label { public: - explicit Label(BasicBlock const&); - - explicit Label(u32 basic_block_index) - : m_address_or_basic_block_index(basic_block_index) + explicit Label(u32 address) + : m_address(address) { } - // Used while compiling. - size_t basic_block_index() const { return m_address_or_basic_block_index; } + size_t address() const { return m_address; } - // Used after compiling. - size_t address() const { return m_address_or_basic_block_index; } - - void set_address(size_t address) { m_address_or_basic_block_index = address; } + void set_address(size_t address) { m_address = address; } private: - u32 m_address_or_basic_block_index { 0 }; + u32 m_address { 0 }; }; } diff --git a/Libraries/LibJS/CMakeLists.txt b/Libraries/LibJS/CMakeLists.txt index dc790893e3..dfafad8381 100644 --- a/Libraries/LibJS/CMakeLists.txt +++ b/Libraries/LibJS/CMakeLists.txt @@ -2,12 +2,10 @@ include(libjs_generators) set(SOURCES Bytecode/AsmInterpreter/AsmSlowPaths.cpp - Bytecode/BasicBlock.cpp Bytecode/Executable.cpp Bytecode/IdentifierTable.cpp Bytecode/Instruction.cpp Bytecode/Interpreter.cpp - Bytecode/Label.cpp Bytecode/PropertyNameIterator.cpp Bytecode/PropertyKeyTable.cpp Bytecode/RegexTable.cpp diff --git a/Libraries/LibJS/Forward.h b/Libraries/LibJS/Forward.h index 7a9faa9a8c..77b9faab61 100644 --- a/Libraries/LibJS/Forward.h +++ b/Libraries/LibJS/Forward.h @@ -315,7 +315,6 @@ using NativeFunctionPointer = ThrowCompletionOr (*)(VM&); namespace Bytecode { -class BasicBlock; enum class Builtin : u8; class Executable; class Generator; diff --git a/Libraries/LibJS/Runtime/ExecutionContext.h b/Libraries/LibJS/Runtime/ExecutionContext.h index adecfefe48..94b387de6e 100644 --- a/Libraries/LibJS/Runtime/ExecutionContext.h +++ b/Libraries/LibJS/Runtime/ExecutionContext.h @@ -11,7 +11,6 @@ #include #include -#include #include #include #include