Skip to content

Commit

Permalink
LibWasm: Remove uses of AK::Result
Browse files Browse the repository at this point in the history
Closes #23500.
  • Loading branch information
alimpfard committed Mar 12, 2024
1 parent 8003bde commit 5a40ce4
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ void Linker::link(HashMap<Linker::Name, ExternValue> const& exports)
m_unresolved_imports.remove(entry);
}

AK::Result<Vector<ExternValue>, LinkError> Linker::finish()
AK::ErrorOr<Vector<ExternValue>, LinkError> Linker::finish()
{
populate();
if (!m_unresolved_imports.is_empty()) {
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ class Stack {
Vector<EntryType, 1024> m_data;
};

using InstantiationResult = AK::Result<NonnullOwnPtr<ModuleInstance>, InstantiationError>;
using InstantiationResult = AK::ErrorOr<NonnullOwnPtr<ModuleInstance>, InstantiationError>;

class AbstractMachine {
public:
Expand Down Expand Up @@ -655,7 +655,7 @@ class Linker {
return m_unresolved_imports;
}

AK::Result<Vector<ExternValue>, LinkError> finish();
AK::ErrorOr<Vector<ExternValue>, LinkError> finish();

private:
void populate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ void BytecodeInterpreter::binary_numeric_operation(Configuration& configuration,
auto lhs = lhs_ptr->to<PopTypeLHS>();
PushType result;
auto call_result = Operator { forward<Args>(args)... }(lhs.value(), rhs.value());
if constexpr (IsSpecializationOf<decltype(call_result), AK::Result>) {
if constexpr (IsSpecializationOf<decltype(call_result), AK::ErrorOr>) {
if (call_result.is_error()) {
trap_if_not(false, call_result.error());
return;
Expand All @@ -328,7 +328,7 @@ void BytecodeInterpreter::unary_operation(Configuration& configuration, Args&&..
auto value = entry_ptr->to<PopType>();
auto call_result = Operator { forward<Args>(args)... }(*value);
PushType result;
if constexpr (IsSpecializationOf<decltype(call_result), AK::Result>) {
if constexpr (IsSpecializationOf<decltype(call_result), AK::ErrorOr>) {
if (call_result.is_error()) {
trap_if_not(false, call_result.error());
return;
Expand Down
14 changes: 7 additions & 7 deletions Userland/Libraries/LibWasm/AbstractMachine/Operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ struct Divide {
Checked value(lhs);
value /= rhs;
if (value.has_overflow())
return AK::Result<Lhs, StringView>("Integer division overflow"sv);
return AK::Result<Lhs, StringView>(value.value());
return AK::ErrorOr<Lhs, StringView>("Integer division overflow"sv);
return AK::ErrorOr<Lhs, StringView>(value.value());
}
}

Expand All @@ -71,12 +71,12 @@ struct Modulo {
auto operator()(Lhs lhs, Rhs rhs) const
{
if (rhs == 0)
return AK::Result<Lhs, StringView>("Integer division overflow"sv);
return AK::ErrorOr<Lhs, StringView>("Integer division overflow"sv);
if constexpr (IsSigned<Lhs>) {
if (rhs == -1)
return AK::Result<Lhs, StringView>(0); // Spec weirdness right here, signed division overflow is ignored.
return AK::ErrorOr<Lhs, StringView>(0); // Spec weirdness right here, signed division overflow is ignored.
}
return AK::Result<Lhs, StringView>(lhs % rhs);
return AK::ErrorOr<Lhs, StringView>(lhs % rhs);
}

static StringView name() { return "%"sv; }
Expand Down Expand Up @@ -479,7 +479,7 @@ struct Floor {

struct Truncate {
template<typename Lhs>
AK::Result<Lhs, StringView> operator()(Lhs lhs) const
AK::ErrorOr<Lhs, StringView> operator()(Lhs lhs) const
{
if constexpr (IsSame<Lhs, float>)
return truncf(lhs);
Expand Down Expand Up @@ -536,7 +536,7 @@ struct Wrap {
template<typename ResultT>
struct CheckedTruncate {
template<typename Lhs>
AK::Result<ResultT, StringView> operator()(Lhs lhs) const
AK::ErrorOr<ResultT, StringView> operator()(Lhs lhs) const
{
if (isnan(lhs) || isinf(lhs)) // "undefined", let's just trap.
return "Truncation undefined behavior"sv;
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWasm/Parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static auto parse_vector(Stream& stream)
{
ScopeLogger<WASM_BINPARSER_DEBUG> logger;
if constexpr (requires { T::parse(stream); }) {
using ResultT = typename decltype(T::parse(stream))::ValueType;
using ResultT = typename decltype(T::parse(stream))::ResultType;
auto count_or_error = stream.read_value<LEB128<size_t>>();
if (count_or_error.is_error())
return ParseResult<Vector<ResultT>> { with_eof_check(stream, ParseError::ExpectedSize) };
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWasm/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ enum class ParseError {
ByteString parse_error_to_byte_string(ParseError);

template<typename T>
using ParseResult = Result<T, ParseError>;
using ParseResult = ErrorOr<T, ParseError>;

AK_TYPEDEF_DISTINCT_ORDERED_ID(size_t, TypeIndex);
AK_TYPEDEF_DISTINCT_ORDERED_ID(size_t, FunctionIndex);
Expand Down

0 comments on commit 5a40ce4

Please sign in to comment.