Skip to content

Commit f37063e

Browse files
committed
LibJS: Stop worrying about Instruction destructors
By adding static_asserts to prove that all of our generated instruction classes are trivially destructible, we can confidently remove the destructor walk in BasicBlock and save ourselves some unnecessary work.
1 parent 370b81f commit f37063e

File tree

4 files changed

+2
-27
lines changed

4 files changed

+2
-27
lines changed

Libraries/LibJS/Bytecode/BasicBlock.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,7 @@ BasicBlock::BasicBlock(u32 index, String name)
2121
{
2222
}
2323

24-
BasicBlock::~BasicBlock()
25-
{
26-
Bytecode::InstructionStreamIterator it(instruction_stream());
27-
while (!it.at_end()) {
28-
auto& to_destroy = (*it);
29-
++it;
30-
Instruction::destroy(const_cast<Instruction&>(to_destroy));
31-
}
32-
}
24+
BasicBlock::~BasicBlock() = default;
3325

3426
void BasicBlock::grow(size_t additional_size)
3527
{

Libraries/LibJS/Bytecode/Instruction.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,6 @@
1010

1111
namespace JS::Bytecode {
1212

13-
void Instruction::destroy(Instruction& instruction)
14-
{
15-
#define __BYTECODE_OP(op) \
16-
case Type::op: \
17-
static_cast<Op::op&>(instruction).~op(); \
18-
return;
19-
20-
switch (instruction.type()) {
21-
ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
22-
default:
23-
VERIFY_NOT_REACHED();
24-
}
25-
26-
#undef __BYTECODE_OP
27-
}
28-
2913
void Instruction::visit_labels(Function<void(JS::Bytecode::Label&)> visitor)
3014
{
3115
#define __BYTECODE_OP(op) \

Libraries/LibJS/Bytecode/Instruction.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include <AK/Forward.h>
1010
#include <AK/Function.h>
11-
#include <AK/Span.h>
1211
#include <LibJS/Bytecode/Executable.h>
1312
#include <LibJS/Bytecode/OpCodes.h>
1413
#include <LibJS/Forward.h>
@@ -85,7 +84,6 @@ class alignas(void*) Instruction {
8584
ByteString to_byte_string(Bytecode::Executable const&) const;
8685
void visit_labels(Function<void(Label&)> visitor);
8786
void visit_operands(Function<void(Operand&)> visitor);
88-
static void destroy(Instruction&);
8987

9088
Strict strict() const { return m_strict; }
9189
void set_strict(Strict strict) { m_strict = strict; }

Meta/generate-libjs-bytecode-def-derived.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ def generate_class(op: OpDef) -> str:
322322
lines.append(f" {f.type} {f.name};")
323323

324324
lines.append("};")
325+
lines.append(f"static_assert(IsTriviallyDestructible<{op.name}>);")
325326
return "\n".join(lines)
326327

327328

0 commit comments

Comments
 (0)