1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:57:43 +00:00

Everywhere: Stop using NonnullOwnPtrVector

Same as NonnullRefPtrVector: weird semantics, questionable benefits.
This commit is contained in:
Andreas Kling 2023-03-06 17:16:25 +01:00
parent 689ca370d4
commit 359d6e7b0b
111 changed files with 517 additions and 503 deletions

View file

@ -12,7 +12,7 @@ void Executable::dump() const
{
dbgln("\033[33;1mJS::Bytecode::Executable\033[0m ({})", name);
for (auto& block : basic_blocks)
block.dump(*this);
block->dump(*this);
if (!string_table->is_empty()) {
outln();
string_table->dump();

View file

@ -16,7 +16,7 @@ namespace JS::Bytecode {
struct Executable {
DeprecatedFlyString name;
NonnullOwnPtrVector<BasicBlock> basic_blocks;
Vector<NonnullOwnPtr<BasicBlock>> basic_blocks;
NonnullOwnPtr<StringTable> string_table;
NonnullOwnPtr<IdentifierTable> identifier_table;
size_t number_of_registers { 0 };

View file

@ -36,9 +36,9 @@ CodeGenerationErrorOr<NonnullOwnPtr<Executable>> Generator::generate(ASTNode con
if (generator.is_in_generator_or_async_function()) {
// Terminate all unterminated blocks with yield return
for (auto& block : generator.m_root_basic_blocks) {
if (block.is_terminated())
if (block->is_terminated())
continue;
generator.switch_to_basic_block(block);
generator.switch_to_basic_block(*block);
generator.emit<Bytecode::Op::LoadImmediate>(js_undefined());
generator.emit<Bytecode::Op::Yield>(nullptr);
}

View file

@ -104,7 +104,7 @@ public:
if (name.is_empty())
name = DeprecatedString::number(m_next_block++);
m_root_basic_blocks.append(BasicBlock::create(name));
return m_root_basic_blocks.last();
return *m_root_basic_blocks.last();
}
bool is_current_block_terminated() const
@ -227,7 +227,7 @@ private:
};
BasicBlock* m_current_basic_block { nullptr };
NonnullOwnPtrVector<BasicBlock> m_root_basic_blocks;
Vector<NonnullOwnPtr<BasicBlock>> m_root_basic_blocks;
NonnullOwnPtr<StringTable> m_string_table;
NonnullOwnPtr<IdentifierTable> m_identifier_table;

View file

@ -62,7 +62,7 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable const& e
pushed_execution_context = true;
}
TemporaryChange restore_current_block { m_current_block, entry_point ?: &executable.basic_blocks.first() };
TemporaryChange restore_current_block { m_current_block, entry_point ?: executable.basic_blocks.first() };
if (in_frame)
m_register_windows.append(in_frame);

View file

@ -164,7 +164,7 @@ void GenerateCFG::perform(PassPipelineExecutable& executable)
unwind_frames.append(&top_level_frame);
generate_cfg_for_block(executable.executable.basic_blocks.first(), executable);
generate_cfg_for_block(*executable.executable.basic_blocks.first(), executable);
finished();
}

View file

@ -175,20 +175,20 @@ void EliminateLoads::perform(PassPipelineExecutable& executable)
// save some work between blocks
for (auto it = executable.executable.basic_blocks.begin(); it != executable.executable.basic_blocks.end(); ++it) {
auto const& old_block = *it;
auto new_block = eliminate_loads(old_block, executable.executable.number_of_registers);
auto new_block = eliminate_loads(*old_block, executable.executable.number_of_registers);
// We will replace the old block, with a new one, so we need to replace all references,
// to the old one with the new one
for (auto& block : executable.executable.basic_blocks) {
InstructionStreamIterator it { block.instruction_stream() };
InstructionStreamIterator it { block->instruction_stream() };
while (!it.at_end()) {
auto& instruction = *it;
++it;
const_cast<Instruction&>(instruction).replace_references(old_block, *new_block);
const_cast<Instruction&>(instruction).replace_references(*old_block, *new_block);
}
}
executable.executable.basic_blocks.ptr_at(it.index()) = move(new_block);
executable.executable.basic_blocks[it.index()] = move(new_block);
}
finished();

View file

@ -81,7 +81,7 @@ void MergeBlocks::perform(PassPipelineExecutable& executable)
first_successor_position = it.index();
}
for (auto& block : executable.executable.basic_blocks) {
InstructionStreamIterator it { block.instruction_stream() };
InstructionStreamIterator it { block->instruction_stream() };
while (!it.at_end()) {
auto& instruction = *it;
++it;

View file

@ -35,7 +35,7 @@ void PlaceBlocks::perform(PassPipelineExecutable& executable)
};
// Make sure to visit the entry block first
visit(&executable.executable.basic_blocks.first());
visit(executable.executable.basic_blocks.first());
for (auto& entry : cfg)
visit(entry.key);

View file

@ -22,19 +22,19 @@ void UnifySameBlocks::perform(PassPipelineExecutable& executable)
for (size_t i = 0; i < executable.executable.basic_blocks.size(); ++i) {
auto& block = executable.executable.basic_blocks[i];
auto block_bytes = block.instruction_stream();
auto block_bytes = block->instruction_stream();
for (auto& candidate_block : executable.executable.basic_blocks.span().slice(i + 1)) {
if (equal_blocks.contains(&*candidate_block))
continue;
// FIXME: This can probably be relaxed a bit...
if (candidate_block->size() != block.size())
if (candidate_block->size() != block->size())
continue;
auto candidate_bytes = candidate_block->instruction_stream();
// FIXME: NewBigInt's value is not correctly reflected by its encoding in memory,
// this will yield false negatives for blocks containing that
if (memcmp(candidate_bytes.data(), block_bytes.data(), candidate_block->size()) == 0)
equal_blocks.set(&*candidate_block, &block);
equal_blocks.set(candidate_block.ptr(), block);
}
}
@ -47,7 +47,7 @@ void UnifySameBlocks::perform(PassPipelineExecutable& executable)
first_successor_position = it.index();
for (auto& block : executable.executable.basic_blocks) {
InstructionStreamIterator it { block.instruction_stream() };
InstructionStreamIterator it { block->instruction_stream() };
while (!it.at_end()) {
auto& instruction = *it;
++it;

View file

@ -61,12 +61,12 @@ public:
{
started();
for (auto& pass : m_passes)
pass.perform(executable);
pass->perform(executable);
finished();
}
private:
NonnullOwnPtrVector<Pass> m_passes;
Vector<NonnullOwnPtr<Pass>> m_passes;
};
namespace Passes {