1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 21:07:34 +00:00

AK+Everywhere: Rename String to DeprecatedString

We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
This commit is contained in:
Linus Groh 2022-12-04 18:02:33 +00:00 committed by Andreas Kling
parent f74251606d
commit 6e19ab2bbc
2006 changed files with 11635 additions and 11636 deletions

View file

@ -141,7 +141,7 @@ ErrorOr<void, ValidationError> AbstractMachine::validate(Module& module)
InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<ExternValue> externs)
{
if (auto result = validate(const_cast<Module&>(module)); result.is_error())
return InstantiationError { String::formatted("Validation failed: {}", result.error()) };
return InstantiationError { DeprecatedString::formatted("Validation failed: {}", result.error()) };
auto main_module_instance_pointer = make<ModuleInstance>();
auto& main_module_instance = *main_module_instance_pointer;
@ -177,7 +177,7 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<Ex
});
auto result = config.execute(interpreter);
if (result.is_trap())
instantiation_result = InstantiationError { String::formatted("Global value construction trapped: {}", result.trap().reason) };
instantiation_result = InstantiationError { DeprecatedString::formatted("Global value construction trapped: {}", result.trap().reason) };
else
global_values.append(result.values().first());
}
@ -204,7 +204,7 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<Ex
});
auto result = config.execute(interpreter);
if (result.is_trap()) {
instantiation_result = InstantiationError { String::formatted("Element construction trapped: {}", result.trap().reason) };
instantiation_result = InstantiationError { DeprecatedString::formatted("Element construction trapped: {}", result.trap().reason) };
return IterationDecision::Continue;
}
@ -257,7 +257,7 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<Ex
});
auto result = config.execute(interpreter);
if (result.is_trap()) {
instantiation_result = InstantiationError { String::formatted("Element section initialisation trapped: {}", result.trap().reason) };
instantiation_result = InstantiationError { DeprecatedString::formatted("Element section initialisation trapped: {}", result.trap().reason) };
return IterationDecision::Break;
}
auto d = result.values().first().to<i32>();
@ -317,7 +317,7 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<Ex
});
auto result = config.execute(interpreter);
if (result.is_trap()) {
instantiation_result = InstantiationError { String::formatted("Data section initialisation trapped: {}", result.trap().reason) };
instantiation_result = InstantiationError { DeprecatedString::formatted("Data section initialisation trapped: {}", result.trap().reason) };
return;
}
size_t offset = 0;
@ -328,7 +328,7 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<Ex
return;
if (main_module_instance.memories().size() <= data.index.value()) {
instantiation_result = InstantiationError {
String::formatted("Data segment referenced out-of-bounds memory ({}) of max {} entries",
DeprecatedString::formatted("Data segment referenced out-of-bounds memory ({}) of max {} entries",
data.index.value(), main_module_instance.memories().size())
};
return;
@ -347,7 +347,7 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<Ex
if (auto max = instance->type().limits().max(); max.has_value()) {
if (*max * Constants::page_size < data.init.size() + offset) {
instantiation_result = InstantiationError {
String::formatted("Data segment attempted to write to out-of-bounds memory ({}) of max {} bytes",
DeprecatedString::formatted("Data segment attempted to write to out-of-bounds memory ({}) of max {} bytes",
data.init.size() + offset, instance->type().limits().max().value())
};
return;
@ -373,7 +373,7 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<Ex
auto& functions = main_module_instance.functions();
auto index = section.function().index();
if (functions.size() <= index.value()) {
instantiation_result = InstantiationError { String::formatted("Start section function referenced invalid index {} of max {} entries", index.value(), functions.size()) };
instantiation_result = InstantiationError { DeprecatedString::formatted("Start section function referenced invalid index {} of max {} entries", index.value(), functions.size()) };
return;
}
invoke(functions[index.value()], {});

View file

@ -19,13 +19,13 @@ class Configuration;
struct Interpreter;
struct InstantiationError {
String error { "Unknown error" };
DeprecatedString error { "Unknown error" };
};
struct LinkError {
enum OtherErrors {
InvalidImportedModule,
};
Vector<String> missing_imports;
Vector<DeprecatedString> missing_imports;
Vector<OtherErrors> other_errors;
};
@ -168,7 +168,7 @@ private:
};
struct Trap {
String reason;
DeprecatedString reason;
};
class Result {
@ -197,7 +197,7 @@ using ExternValue = Variant<FunctionAddress, TableAddress, MemoryAddress, Global
class ExportInstance {
public:
explicit ExportInstance(String name, ExternValue value)
explicit ExportInstance(DeprecatedString name, ExternValue value)
: m_name(move(name))
, m_value(move(value))
{
@ -207,7 +207,7 @@ public:
auto& value() const { return m_value; }
private:
String m_name;
DeprecatedString m_name;
ExternValue m_value;
};
@ -546,8 +546,8 @@ private:
class Linker {
public:
struct Name {
String module;
String name;
DeprecatedString module;
DeprecatedString name;
ImportSection::Import::ImportDesc type;
};

View file

@ -961,7 +961,7 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi
default:
unimplemented:;
dbgln("Instruction '{}' not implemented", instruction_name(instruction.opcode()));
m_trap = Trap { String::formatted("Unimplemented instruction {}", instruction_name(instruction.opcode())) };
m_trap = Trap { DeprecatedString::formatted("Unimplemented instruction {}", instruction_name(instruction.opcode())) };
return;
}
}

View file

@ -16,7 +16,7 @@ struct BytecodeInterpreter : public Interpreter {
virtual void interpret(Configuration&) override;
virtual ~BytecodeInterpreter() override = default;
virtual bool did_trap() const override { return m_trap.has_value(); }
virtual String trap_reason() const override { return m_trap.value().reason; }
virtual DeprecatedString trap_reason() const override { return m_trap.value().reason; }
virtual void clear_trap() override { m_trap.clear(); }
struct CallFrameHandle {

View file

@ -14,7 +14,7 @@ struct Interpreter {
virtual ~Interpreter() = default;
virtual void interpret(Configuration&) = 0;
virtual bool did_trap() const = 0;
virtual String trap_reason() const = 0;
virtual DeprecatedString trap_reason() const = 0;
virtual void clear_trap() = 0;
};

View file

@ -320,7 +320,7 @@ ErrorOr<void, ValidationError> Validator::validate(Limits const& limits, size_t
template<u32 opcode>
ErrorOr<void, ValidationError> Validator::validate_instruction(Instruction const& instruction, Stack&, bool&)
{
return Errors::invalid(String::formatted("instruction opcode (0x{:x}) (missing validation!)", instruction.opcode().value()));
return Errors::invalid(DeprecatedString::formatted("instruction opcode (0x{:x}) (missing validation!)", instruction.opcode().value()));
}
#define VALIDATE_INSTRUCTION(name) \
@ -2179,7 +2179,7 @@ ErrorOr<void, ValidationError> Validator::validate(Instruction const& instructio
#undef M
default:
is_constant = false;
return Errors::invalid(String::formatted("instruction opcode (0x{:x})", instruction.opcode().value()));
return Errors::invalid(DeprecatedString::formatted("instruction opcode (0x{:x})", instruction.opcode().value()));
}
}
@ -2256,16 +2256,16 @@ bool Validator::Stack::operator==(Stack const& other) const
return true;
}
String Validator::Errors::find_instruction_name(SourceLocation const& location)
DeprecatedString Validator::Errors::find_instruction_name(SourceLocation const& location)
{
auto index = location.function_name().find('<');
auto end_index = location.function_name().find('>');
if (!index.has_value() || !end_index.has_value())
return String::formatted("{}", location);
return DeprecatedString::formatted("{}", location);
auto opcode = location.function_name().substring_view(index.value() + 1, end_index.value() - index.value() - 1).to_uint();
if (!opcode.has_value())
return String::formatted("{}", location);
return DeprecatedString::formatted("{}", location);
return instruction_name(OpCode { *opcode });
}

View file

@ -30,13 +30,13 @@ struct Context {
};
struct ValidationError : public Error {
ValidationError(String error)
ValidationError(DeprecatedString error)
: Error(Error::from_string_view(error))
, error_string(move(error))
{
}
String error_string;
DeprecatedString error_string;
};
class Validator {
@ -255,27 +255,27 @@ private:
}
struct Errors {
static ValidationError invalid(StringView name) { return String::formatted("Invalid {}", name); }
static ValidationError invalid(StringView name) { return DeprecatedString::formatted("Invalid {}", name); }
template<typename Expected, typename Given>
static ValidationError invalid(StringView name, Expected expected, Given given, SourceLocation location = SourceLocation::current())
{
if constexpr (WASM_VALIDATOR_DEBUG)
return String::formatted("Invalid {} in {}, expected {} but got {}", name, find_instruction_name(location), expected, given);
return DeprecatedString::formatted("Invalid {} in {}, expected {} but got {}", name, find_instruction_name(location), expected, given);
else
return String::formatted("Invalid {}, expected {} but got {}", name, expected, given);
return DeprecatedString::formatted("Invalid {}, expected {} but got {}", name, expected, given);
}
template<typename... Args>
static ValidationError non_conforming_types(StringView name, Args... args)
{
return String::formatted("Non-conforming types for {}: {}", name, Vector { args... });
return DeprecatedString::formatted("Non-conforming types for {}: {}", name, Vector { args... });
}
static ValidationError duplicate_export_name(StringView name) { return String::formatted("Duplicate exported name '{}'", name); }
static ValidationError duplicate_export_name(StringView name) { return DeprecatedString::formatted("Duplicate exported name '{}'", name); }
template<typename T, typename U, typename V>
static ValidationError out_of_bounds(StringView name, V value, T min, U max) { return String::formatted("Value {} for {} is out of bounds ({},{})", value, name, min, max); }
static ValidationError out_of_bounds(StringView name, V value, T min, U max) { return DeprecatedString::formatted("Value {} for {} is out of bounds ({},{})", value, name, min, max); }
template<typename... Expected>
static ValidationError invalid_stack_state(Stack const& stack, Tuple<Expected...> expected, SourceLocation location = SourceLocation::current())
@ -310,7 +310,7 @@ private:
}
private:
static String find_instruction_name(SourceLocation const&);
static DeprecatedString find_instruction_name(SourceLocation const&);
};
enum class ChildScopeKind {

View file

@ -66,14 +66,14 @@ static auto parse_vector(InputStream& stream)
}
}
static ParseResult<String> parse_name(InputStream& stream)
static ParseResult<DeprecatedString> parse_name(InputStream& stream)
{
ScopeLogger<WASM_BINPARSER_DEBUG> logger;
auto data = parse_vector<u8>(stream);
if (data.is_error())
return data.error();
return String::copy(data.value());
return DeprecatedString::copy(data.value());
}
template<typename T>
@ -1364,7 +1364,7 @@ bool Module::populate_sections()
return is_ok;
}
String parse_error_to_string(ParseError error)
DeprecatedString parse_error_to_string(ParseError error)
{
switch (error) {
case ParseError::UnexpectedEof:

View file

@ -12,11 +12,11 @@
namespace Wasm {
struct Names {
static HashMap<OpCode, String> instruction_names;
static HashMap<String, OpCode> instructions_by_name;
static HashMap<OpCode, DeprecatedString> instruction_names;
static HashMap<DeprecatedString, OpCode> instructions_by_name;
};
String instruction_name(OpCode const& opcode)
DeprecatedString instruction_name(OpCode const& opcode)
{
return Names::instruction_names.get(opcode).value_or("<unknown>");
}
@ -131,13 +131,13 @@ void Printer::print(Wasm::DataSection::Data const& data)
[this](DataSection::Data::Passive const& value) {
print_indent();
print("(passive init {}xu8 (", value.init.size());
print(String::join(' ', value.init, "{:x}"sv));
print(DeprecatedString::join(' ', value.init, "{:x}"sv));
print(")\n");
},
[this](DataSection::Data::Active const& value) {
print_indent();
print("(active init {}xu8 (", value.init.size());
print(String::join(' ', value.init, "{:x}"sv));
print(DeprecatedString::join(' ', value.init, "{:x}"sv));
print("\n");
{
TemporaryChange change { m_indent, m_indent + 1 };
@ -437,7 +437,7 @@ void Printer::print(Wasm::Instruction const& instruction)
TemporaryChange change { m_indent, m_indent + 1 };
print(args.block_type);
print_indent();
print("(else {}) (end {}))", args.else_ip.has_value() ? String::number(args.else_ip->value()) : "(none)", args.end_ip.value());
print("(else {}) (end {}))", args.else_ip.has_value() ? DeprecatedString::number(args.else_ip->value()) : "(none)", args.end_ip.value());
},
[&](Instruction::TableBranchArgs const& args) {
print("(table_branch");
@ -637,13 +637,13 @@ void Printer::print(Wasm::Value const& value)
print_indent();
print("{} ", value.value().visit([&]<typename T>(T const& value) {
if constexpr (IsSame<Wasm::Reference, T>)
return String::formatted(
return DeprecatedString::formatted(
"addr({})",
value.ref().visit(
[](Wasm::Reference::Null const&) { return String("null"); },
[](auto const& ref) { return String::number(ref.address.value()); }));
[](Wasm::Reference::Null const&) { return DeprecatedString("null"); },
[](auto const& ref) { return DeprecatedString::number(ref.address.value()); }));
else
return String::formatted("{}", value);
return DeprecatedString::formatted("{}", value);
}));
TemporaryChange<size_t> change { m_indent, 0 };
print(value.type());
@ -655,12 +655,12 @@ void Printer::print(Wasm::Reference const& value)
print(
"addr({})\n",
value.ref().visit(
[](Wasm::Reference::Null const&) { return String("null"); },
[](auto const& ref) { return String::number(ref.address.value()); }));
[](Wasm::Reference::Null const&) { return DeprecatedString("null"); },
[](auto const& ref) { return DeprecatedString::number(ref.address.value()); }));
}
}
HashMap<Wasm::OpCode, String> Wasm::Names::instruction_names {
HashMap<Wasm::OpCode, DeprecatedString> Wasm::Names::instruction_names {
{ Instructions::unreachable, "unreachable" },
{ Instructions::nop, "nop" },
{ Instructions::block, "block" },
@ -863,4 +863,4 @@ HashMap<Wasm::OpCode, String> Wasm::Names::instruction_names {
{ Instructions::structured_else, "synthetic:else" },
{ Instructions::structured_end, "synthetic:end" },
};
HashMap<String, Wasm::OpCode> Wasm::Names::instructions_by_name;
HashMap<DeprecatedString, Wasm::OpCode> Wasm::Names::instructions_by_name;

View file

@ -13,7 +13,7 @@ namespace Wasm {
class Reference;
class Value;
String instruction_name(OpCode const& opcode);
DeprecatedString instruction_name(OpCode const& opcode);
Optional<OpCode> instruction_from_name(StringView name);
struct Printer {

View file

@ -8,11 +8,11 @@
#include <AK/Badge.h>
#include <AK/Debug.h>
#include <AK/DeprecatedString.h>
#include <AK/DistinctNumeric.h>
#include <AK/MemoryStream.h>
#include <AK/NonnullOwnPtrVector.h>
#include <AK/Result.h>
#include <AK/String.h>
#include <AK/Variant.h>
#include <LibWasm/Constants.h>
#include <LibWasm/Forward.h>
@ -43,7 +43,7 @@ enum class ParseError {
NotImplemented,
};
String parse_error_to_string(ParseError);
DeprecatedString parse_error_to_string(ParseError);
template<typename T>
using ParseResult = Result<T, ParseError>;
@ -190,7 +190,7 @@ public:
static ParseResult<ValueType> parse(InputStream& stream);
static String kind_name(Kind kind)
static DeprecatedString kind_name(Kind kind)
{
switch (kind) {
case I32:
@ -467,7 +467,7 @@ class CustomSection {
public:
static constexpr u8 section_id = 0;
CustomSection(String name, ByteBuffer contents)
CustomSection(DeprecatedString name, ByteBuffer contents)
: m_name(move(name))
, m_contents(move(contents))
{
@ -479,7 +479,7 @@ public:
static ParseResult<CustomSection> parse(InputStream& stream);
private:
String m_name;
DeprecatedString m_name;
ByteBuffer m_contents;
};
@ -505,7 +505,7 @@ public:
class Import {
public:
using ImportDesc = Variant<TypeIndex, TableType, MemoryType, GlobalType, FunctionType>;
Import(String module, String name, ImportDesc description)
Import(DeprecatedString module, DeprecatedString name, ImportDesc description)
: m_module(move(module))
, m_name(move(name))
, m_description(move(description))
@ -528,8 +528,8 @@ public:
return Import { module.release_value(), name.release_value(), result.release_value() };
};
String m_module;
String m_name;
DeprecatedString m_module;
DeprecatedString m_name;
ImportDesc m_description;
};
@ -690,7 +690,7 @@ private:
public:
class Export {
public:
explicit Export(String name, ExportDesc description)
explicit Export(DeprecatedString name, ExportDesc description)
: m_name(move(name))
, m_description(move(description))
{
@ -702,7 +702,7 @@ public:
static ParseResult<Export> parse(InputStream& stream);
private:
String m_name;
DeprecatedString m_name;
ExportDesc m_description;
};
@ -1042,7 +1042,7 @@ public:
void set_validation_status(ValidationStatus status, Badge<Validator>) { set_validation_status(status); }
ValidationStatus validation_status() const { return m_validation_status; }
StringView validation_error() const { return *m_validation_error; }
void set_validation_error(String error) { m_validation_error = move(error); }
void set_validation_error(DeprecatedString error) { m_validation_error = move(error); }
static ParseResult<Module> parse(InputStream& stream);
@ -1053,6 +1053,6 @@ private:
Vector<AnySection> m_sections;
Vector<Function> m_functions;
ValidationStatus m_validation_status { ValidationStatus::Unchecked };
Optional<String> m_validation_error;
Optional<DeprecatedString> m_validation_error;
};
}