AbstractMachine.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /*
  2. * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Function.h>
  8. #include <AK/HashMap.h>
  9. #include <AK/HashTable.h>
  10. #include <AK/OwnPtr.h>
  11. #include <AK/Result.h>
  12. #include <AK/StackInfo.h>
  13. #include <AK/UFixedBigInt.h>
  14. #include <LibWasm/Types.h>
  15. // NOTE: Special case for Wasm::Result.
  16. #include <LibJS/Runtime/Completion.h>
  17. namespace Wasm {
  18. class Configuration;
  19. struct Interpreter;
  20. struct InstantiationError {
  21. ByteString error { "Unknown error" };
  22. };
  23. struct LinkError {
  24. enum OtherErrors {
  25. InvalidImportedModule,
  26. };
  27. Vector<ByteString> missing_imports;
  28. Vector<OtherErrors> other_errors;
  29. };
  30. AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(u64, FunctionAddress, Arithmetic, Comparison, Increment);
  31. AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(u64, ExternAddress, Arithmetic, Comparison, Increment);
  32. AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(u64, TableAddress, Arithmetic, Comparison, Increment);
  33. AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(u64, GlobalAddress, Arithmetic, Comparison, Increment);
  34. AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(u64, ElementAddress, Arithmetic, Comparison, Increment);
  35. AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(u64, DataAddress, Arithmetic, Comparison, Increment);
  36. AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(u64, MemoryAddress, Arithmetic, Comparison, Increment);
  37. // FIXME: These should probably be made generic/virtual if/when we decide to do something more
  38. // fancy than just a dumb interpreter.
  39. class Reference {
  40. public:
  41. struct Null {
  42. ValueType type;
  43. };
  44. struct Func {
  45. FunctionAddress address;
  46. };
  47. struct Extern {
  48. ExternAddress address;
  49. };
  50. using RefType = Variant<Null, Func, Extern>;
  51. explicit Reference(RefType ref)
  52. : m_ref(move(ref))
  53. {
  54. }
  55. explicit Reference()
  56. : m_ref(Reference::Null { ValueType(ValueType::Kind::FunctionReference) })
  57. {
  58. }
  59. auto& ref() const { return m_ref; }
  60. private:
  61. RefType m_ref;
  62. };
  63. class Value {
  64. public:
  65. Value()
  66. : m_value(0)
  67. {
  68. }
  69. using AnyValueType = Variant<i32, i64, float, double, u128, Reference>;
  70. explicit Value(AnyValueType value)
  71. : m_value(move(value))
  72. {
  73. }
  74. template<typename T>
  75. requires(sizeof(T) == sizeof(u64)) explicit Value(ValueType type, T raw_value)
  76. : m_value(0)
  77. {
  78. switch (type.kind()) {
  79. case ValueType::Kind::ExternReference:
  80. m_value = Reference { Reference::Extern { { bit_cast<u64>(raw_value) } } };
  81. break;
  82. case ValueType::Kind::FunctionReference:
  83. m_value = Reference { Reference::Func { { bit_cast<u64>(raw_value) } } };
  84. break;
  85. case ValueType::Kind::I32:
  86. m_value = static_cast<i32>(bit_cast<i64>(raw_value));
  87. break;
  88. case ValueType::Kind::I64:
  89. m_value = static_cast<i64>(bit_cast<u64>(raw_value));
  90. break;
  91. case ValueType::Kind::F32:
  92. m_value = static_cast<float>(bit_cast<double>(raw_value));
  93. break;
  94. case ValueType::Kind::F64:
  95. m_value = bit_cast<double>(raw_value);
  96. break;
  97. case ValueType::Kind::NullFunctionReference:
  98. VERIFY(raw_value == 0);
  99. m_value = Reference { Reference::Null { ValueType(ValueType::Kind::FunctionReference) } };
  100. break;
  101. case ValueType::Kind::NullExternReference:
  102. VERIFY(raw_value == 0);
  103. m_value = Reference { Reference::Null { ValueType(ValueType::Kind::ExternReference) } };
  104. break;
  105. case ValueType::Kind::V128:
  106. m_value = u128(0ull, bit_cast<u64>(raw_value));
  107. break;
  108. default:
  109. VERIFY_NOT_REACHED();
  110. }
  111. }
  112. template<SameAs<u128> T>
  113. explicit Value(T raw_value)
  114. : m_value(raw_value)
  115. {
  116. }
  117. ALWAYS_INLINE Value(Value const& value) = default;
  118. ALWAYS_INLINE Value(Value&& value) = default;
  119. ALWAYS_INLINE Value& operator=(Value&& value) = default;
  120. ALWAYS_INLINE Value& operator=(Value const& value) = default;
  121. template<typename T>
  122. ALWAYS_INLINE Optional<T> to() const
  123. {
  124. Optional<T> result;
  125. m_value.visit(
  126. [&](auto value) {
  127. if constexpr (IsSame<T, decltype(value)> || (!IsFloatingPoint<T> && IsSame<decltype(value), MakeSigned<T>>)) {
  128. result = static_cast<T>(value);
  129. } else if constexpr (!IsFloatingPoint<T> && IsConvertible<decltype(value), T>) {
  130. // NOTE: No implicit vector <-> scalar conversion.
  131. if constexpr (!IsSame<T, u128>) {
  132. if (AK::is_within_range<T>(value))
  133. result = static_cast<T>(value);
  134. }
  135. }
  136. },
  137. [&](u128 value) {
  138. if constexpr (IsSame<T, u128>)
  139. result = value;
  140. },
  141. [&](Reference const& value) {
  142. if constexpr (IsSame<T, Reference>) {
  143. result = value;
  144. } else if constexpr (IsSame<T, Reference::Func>) {
  145. if (auto ptr = value.ref().template get_pointer<Reference::Func>())
  146. result = *ptr;
  147. } else if constexpr (IsSame<T, Reference::Extern>) {
  148. if (auto ptr = value.ref().template get_pointer<Reference::Extern>())
  149. result = *ptr;
  150. } else if constexpr (IsSame<T, Reference::Null>) {
  151. if (auto ptr = value.ref().template get_pointer<Reference::Null>())
  152. result = *ptr;
  153. }
  154. });
  155. return result;
  156. }
  157. ValueType type() const
  158. {
  159. return ValueType(m_value.visit(
  160. [](i32) { return ValueType::Kind::I32; },
  161. [](i64) { return ValueType::Kind::I64; },
  162. [](float) { return ValueType::Kind::F32; },
  163. [](double) { return ValueType::Kind::F64; },
  164. [](u128) { return ValueType::Kind::V128; },
  165. [&](Reference const& type) {
  166. return type.ref().visit(
  167. [](Reference::Func const&) { return ValueType::Kind::FunctionReference; },
  168. [](Reference::Null const& null_type) {
  169. return null_type.type.kind() == ValueType::ExternReference ? ValueType::Kind::NullExternReference : ValueType::Kind::NullFunctionReference;
  170. },
  171. [](Reference::Extern const&) { return ValueType::Kind::ExternReference; });
  172. }));
  173. }
  174. auto& value() const { return m_value; }
  175. private:
  176. AnyValueType m_value;
  177. };
  178. struct Trap {
  179. ByteString reason;
  180. };
  181. // A variant of Result that does not include external reasons for error (JS::Completion, for now).
  182. class PureResult {
  183. public:
  184. explicit PureResult(Vector<Value> values)
  185. : m_result(move(values))
  186. {
  187. }
  188. PureResult(Trap trap)
  189. : m_result(move(trap))
  190. {
  191. }
  192. auto is_trap() const { return m_result.has<Trap>(); }
  193. auto& values() const { return m_result.get<Vector<Value>>(); }
  194. auto& values() { return m_result.get<Vector<Value>>(); }
  195. auto& trap() const { return m_result.get<Trap>(); }
  196. auto& trap() { return m_result.get<Trap>(); }
  197. private:
  198. friend class Result;
  199. explicit PureResult(Variant<Vector<Value>, Trap>&& result)
  200. : m_result(move(result))
  201. {
  202. }
  203. Variant<Vector<Value>, Trap> m_result;
  204. };
  205. class Result {
  206. public:
  207. explicit Result(Vector<Value> values)
  208. : m_result(move(values))
  209. {
  210. }
  211. Result(Trap trap)
  212. : m_result(move(trap))
  213. {
  214. }
  215. Result(JS::Completion completion)
  216. : m_result(move(completion))
  217. {
  218. VERIFY(m_result.get<JS::Completion>().is_abrupt());
  219. }
  220. Result(PureResult&& result)
  221. : m_result(result.m_result.downcast<decltype(m_result)>())
  222. {
  223. }
  224. auto is_trap() const { return m_result.has<Trap>(); }
  225. auto is_completion() const { return m_result.has<JS::Completion>(); }
  226. auto& values() const { return m_result.get<Vector<Value>>(); }
  227. auto& values() { return m_result.get<Vector<Value>>(); }
  228. auto& trap() const { return m_result.get<Trap>(); }
  229. auto& trap() { return m_result.get<Trap>(); }
  230. auto& completion() { return m_result.get<JS::Completion>(); }
  231. auto& completion() const { return m_result.get<JS::Completion>(); }
  232. PureResult assert_wasm_result() &&
  233. {
  234. VERIFY(!is_completion());
  235. return PureResult(move(m_result).downcast<Vector<Value>, Trap>());
  236. }
  237. private:
  238. Variant<Vector<Value>, Trap, JS::Completion> m_result;
  239. };
  240. using ExternValue = Variant<FunctionAddress, TableAddress, MemoryAddress, GlobalAddress>;
  241. class ExportInstance {
  242. public:
  243. explicit ExportInstance(ByteString name, ExternValue value)
  244. : m_name(move(name))
  245. , m_value(move(value))
  246. {
  247. }
  248. auto& name() const { return m_name; }
  249. auto& value() const { return m_value; }
  250. private:
  251. ByteString m_name;
  252. ExternValue m_value;
  253. };
  254. class ModuleInstance {
  255. public:
  256. explicit ModuleInstance(
  257. Vector<FunctionType> types, Vector<FunctionAddress> function_addresses, Vector<TableAddress> table_addresses,
  258. Vector<MemoryAddress> memory_addresses, Vector<GlobalAddress> global_addresses, Vector<DataAddress> data_addresses,
  259. Vector<ExportInstance> exports)
  260. : m_types(move(types))
  261. , m_functions(move(function_addresses))
  262. , m_tables(move(table_addresses))
  263. , m_memories(move(memory_addresses))
  264. , m_globals(move(global_addresses))
  265. , m_datas(move(data_addresses))
  266. , m_exports(move(exports))
  267. {
  268. }
  269. ModuleInstance() = default;
  270. auto& types() const { return m_types; }
  271. auto& functions() const { return m_functions; }
  272. auto& tables() const { return m_tables; }
  273. auto& memories() const { return m_memories; }
  274. auto& globals() const { return m_globals; }
  275. auto& elements() const { return m_elements; }
  276. auto& datas() const { return m_datas; }
  277. auto& exports() const { return m_exports; }
  278. auto& types() { return m_types; }
  279. auto& functions() { return m_functions; }
  280. auto& tables() { return m_tables; }
  281. auto& memories() { return m_memories; }
  282. auto& globals() { return m_globals; }
  283. auto& elements() { return m_elements; }
  284. auto& datas() { return m_datas; }
  285. auto& exports() { return m_exports; }
  286. private:
  287. Vector<FunctionType> m_types;
  288. Vector<FunctionAddress> m_functions;
  289. Vector<TableAddress> m_tables;
  290. Vector<MemoryAddress> m_memories;
  291. Vector<GlobalAddress> m_globals;
  292. Vector<ElementAddress> m_elements;
  293. Vector<DataAddress> m_datas;
  294. Vector<ExportInstance> m_exports;
  295. };
  296. class WasmFunction {
  297. public:
  298. explicit WasmFunction(FunctionType const& type, ModuleInstance const& module, Module::Function const& code)
  299. : m_type(type)
  300. , m_module(module)
  301. , m_code(code)
  302. {
  303. }
  304. auto& type() const { return m_type; }
  305. auto& module() const { return m_module; }
  306. auto& code() const { return m_code; }
  307. private:
  308. FunctionType m_type;
  309. ModuleInstance const& m_module;
  310. Module::Function const& m_code;
  311. };
  312. class HostFunction {
  313. public:
  314. explicit HostFunction(AK::Function<Result(Configuration&, Vector<Value>&)> function, FunctionType const& type)
  315. : m_function(move(function))
  316. , m_type(type)
  317. {
  318. }
  319. auto& function() { return m_function; }
  320. auto& type() const { return m_type; }
  321. private:
  322. AK::Function<Result(Configuration&, Vector<Value>&)> m_function;
  323. FunctionType m_type;
  324. };
  325. using FunctionInstance = Variant<WasmFunction, HostFunction>;
  326. class TableInstance {
  327. public:
  328. explicit TableInstance(TableType const& type, Vector<Reference> elements)
  329. : m_elements(move(elements))
  330. , m_type(type)
  331. {
  332. }
  333. auto& elements() const { return m_elements; }
  334. auto& elements() { return m_elements; }
  335. auto& type() const { return m_type; }
  336. bool grow(u32 size_to_grow, Reference const& fill_value)
  337. {
  338. if (size_to_grow == 0)
  339. return true;
  340. size_t new_size = m_elements.size() + size_to_grow;
  341. if (auto max = m_type.limits().max(); max.has_value()) {
  342. if (max.value() < new_size)
  343. return false;
  344. }
  345. if (new_size >= NumericLimits<u32>::max()) {
  346. return false;
  347. }
  348. auto previous_size = m_elements.size();
  349. if (m_elements.try_resize(new_size).is_error())
  350. return false;
  351. for (size_t i = previous_size; i < m_elements.size(); ++i)
  352. m_elements[i] = fill_value;
  353. return true;
  354. }
  355. private:
  356. Vector<Reference> m_elements;
  357. TableType m_type;
  358. };
  359. class MemoryInstance {
  360. public:
  361. static ErrorOr<MemoryInstance> create(MemoryType const& type)
  362. {
  363. MemoryInstance instance { type };
  364. if (!instance.grow(type.limits().min() * Constants::page_size))
  365. return Error::from_string_literal("Failed to grow to requested size");
  366. return { move(instance) };
  367. }
  368. auto& type() const { return m_type; }
  369. auto size() const { return m_size; }
  370. auto& data() const { return m_data; }
  371. auto& data() { return m_data; }
  372. enum class InhibitGrowCallback {
  373. No,
  374. Yes,
  375. };
  376. bool grow(size_t size_to_grow, InhibitGrowCallback inhibit_callback = InhibitGrowCallback::No)
  377. {
  378. if (size_to_grow == 0)
  379. return true;
  380. u64 new_size = m_data.size() + size_to_grow;
  381. // Can't grow past 2^16 pages.
  382. if (new_size >= Constants::page_size * 65536)
  383. return false;
  384. if (auto max = m_type.limits().max(); max.has_value()) {
  385. if (max.value() * Constants::page_size < new_size)
  386. return false;
  387. }
  388. auto previous_size = m_size;
  389. if (m_data.try_resize(new_size).is_error())
  390. return false;
  391. m_size = new_size;
  392. // The spec requires that we zero out everything on grow
  393. __builtin_memset(m_data.offset_pointer(previous_size), 0, size_to_grow);
  394. // NOTE: This exists because wasm-js-api wants to execute code after a successful grow,
  395. // See [this issue](https://github.com/WebAssembly/spec/issues/1635) for more details.
  396. if (inhibit_callback == InhibitGrowCallback::No && successful_grow_hook)
  397. successful_grow_hook();
  398. return true;
  399. }
  400. Function<void()> successful_grow_hook;
  401. private:
  402. explicit MemoryInstance(MemoryType const& type)
  403. : m_type(type)
  404. {
  405. }
  406. MemoryType m_type;
  407. size_t m_size { 0 };
  408. ByteBuffer m_data;
  409. };
  410. class GlobalInstance {
  411. public:
  412. explicit GlobalInstance(Value value, bool is_mutable)
  413. : m_mutable(is_mutable)
  414. , m_value(move(value))
  415. {
  416. }
  417. auto is_mutable() const { return m_mutable; }
  418. auto& value() const { return m_value; }
  419. GlobalType type() const { return { m_value.type(), is_mutable() }; }
  420. void set_value(Value value)
  421. {
  422. VERIFY(is_mutable());
  423. m_value = move(value);
  424. }
  425. private:
  426. bool m_mutable { false };
  427. Value m_value;
  428. };
  429. class DataInstance {
  430. public:
  431. explicit DataInstance(Vector<u8> data)
  432. : m_data(move(data))
  433. {
  434. }
  435. size_t size() const { return m_data.size(); }
  436. Vector<u8>& data() { return m_data; }
  437. Vector<u8> const& data() const { return m_data; }
  438. private:
  439. Vector<u8> m_data;
  440. };
  441. class ElementInstance {
  442. public:
  443. explicit ElementInstance(ValueType type, Vector<Reference> references)
  444. : m_type(move(type))
  445. , m_references(move(references))
  446. {
  447. }
  448. auto& type() const { return m_type; }
  449. auto& references() const { return m_references; }
  450. private:
  451. ValueType m_type;
  452. Vector<Reference> m_references;
  453. };
  454. class Store {
  455. public:
  456. Store() = default;
  457. Optional<FunctionAddress> allocate(ModuleInstance& module, Module::Function const& function);
  458. Optional<FunctionAddress> allocate(HostFunction&&);
  459. Optional<TableAddress> allocate(TableType const&);
  460. Optional<MemoryAddress> allocate(MemoryType const&);
  461. Optional<DataAddress> allocate_data(Vector<u8>);
  462. Optional<GlobalAddress> allocate(GlobalType const&, Value);
  463. Optional<ElementAddress> allocate(ValueType const&, Vector<Reference>);
  464. FunctionInstance* get(FunctionAddress);
  465. TableInstance* get(TableAddress);
  466. MemoryInstance* get(MemoryAddress);
  467. GlobalInstance* get(GlobalAddress);
  468. DataInstance* get(DataAddress);
  469. ElementInstance* get(ElementAddress);
  470. private:
  471. Vector<FunctionInstance> m_functions;
  472. Vector<TableInstance> m_tables;
  473. Vector<MemoryInstance> m_memories;
  474. Vector<GlobalInstance> m_globals;
  475. Vector<ElementInstance> m_elements;
  476. Vector<DataInstance> m_datas;
  477. };
  478. class Label {
  479. public:
  480. explicit Label(size_t arity, InstructionPointer continuation)
  481. : m_arity(arity)
  482. , m_continuation(continuation)
  483. {
  484. }
  485. auto continuation() const { return m_continuation; }
  486. auto arity() const { return m_arity; }
  487. private:
  488. size_t m_arity { 0 };
  489. InstructionPointer m_continuation { 0 };
  490. };
  491. class Frame {
  492. public:
  493. explicit Frame(ModuleInstance const& module, Vector<Value> locals, Expression const& expression, size_t arity)
  494. : m_module(module)
  495. , m_locals(move(locals))
  496. , m_expression(expression)
  497. , m_arity(arity)
  498. {
  499. }
  500. auto& module() const { return m_module; }
  501. auto& locals() const { return m_locals; }
  502. auto& locals() { return m_locals; }
  503. auto& expression() const { return m_expression; }
  504. auto arity() const { return m_arity; }
  505. private:
  506. ModuleInstance const& m_module;
  507. Vector<Value> m_locals;
  508. Expression const& m_expression;
  509. size_t m_arity { 0 };
  510. };
  511. class Stack {
  512. public:
  513. using EntryType = Variant<Value, Label, Frame>;
  514. Stack() = default;
  515. [[nodiscard]] ALWAYS_INLINE bool is_empty() const { return m_data.is_empty(); }
  516. ALWAYS_INLINE void push(EntryType entry) { m_data.append(move(entry)); }
  517. ALWAYS_INLINE auto pop() { return m_data.take_last(); }
  518. ALWAYS_INLINE auto& peek() const { return m_data.last(); }
  519. ALWAYS_INLINE auto& peek() { return m_data.last(); }
  520. ALWAYS_INLINE auto size() const { return m_data.size(); }
  521. ALWAYS_INLINE auto& entries() const { return m_data; }
  522. ALWAYS_INLINE auto& entries() { return m_data; }
  523. private:
  524. Vector<EntryType, 1024> m_data;
  525. };
  526. using InstantiationResult = AK::ErrorOr<NonnullOwnPtr<ModuleInstance>, InstantiationError>;
  527. class AbstractMachine {
  528. public:
  529. explicit AbstractMachine() = default;
  530. // Validate a module; permanently sets the module's validity status.
  531. ErrorOr<void, ValidationError> validate(Module&);
  532. // Load and instantiate a module, and link it into this interpreter.
  533. InstantiationResult instantiate(Module const&, Vector<ExternValue>);
  534. Result invoke(FunctionAddress, Vector<Value>);
  535. Result invoke(Interpreter&, FunctionAddress, Vector<Value>);
  536. auto& store() const { return m_store; }
  537. auto& store() { return m_store; }
  538. void enable_instruction_count_limit() { m_should_limit_instruction_count = true; }
  539. private:
  540. Optional<InstantiationError> allocate_all_initial_phase(Module const&, ModuleInstance&, Vector<ExternValue>&, Vector<Value>& global_values, Vector<FunctionAddress>& own_functions);
  541. Optional<InstantiationError> allocate_all_final_phase(Module const&, ModuleInstance&, Vector<Vector<Reference>>& elements);
  542. Store m_store;
  543. StackInfo m_stack_info;
  544. bool m_should_limit_instruction_count { false };
  545. };
  546. class Linker {
  547. public:
  548. struct Name {
  549. ByteString module;
  550. ByteString name;
  551. ImportSection::Import::ImportDesc type;
  552. };
  553. explicit Linker(Module const& module)
  554. : m_module(module)
  555. {
  556. }
  557. // Link a module, the import 'module name' is ignored with this.
  558. void link(ModuleInstance const&);
  559. // Link a bunch of qualified values, also matches 'module name'.
  560. void link(HashMap<Name, ExternValue> const&);
  561. auto& unresolved_imports()
  562. {
  563. populate();
  564. return m_unresolved_imports;
  565. }
  566. AK::ErrorOr<Vector<ExternValue>, LinkError> finish();
  567. private:
  568. void populate();
  569. Module const& m_module;
  570. HashMap<Name, ExternValue> m_resolved_imports;
  571. HashTable<Name> m_unresolved_imports;
  572. Vector<Name> m_ordered_imports;
  573. Optional<LinkError> m_error;
  574. };
  575. }
  576. template<>
  577. struct AK::Traits<Wasm::Linker::Name> : public AK::DefaultTraits<Wasm::Linker::Name> {
  578. static constexpr bool is_trivial() { return false; }
  579. static unsigned hash(Wasm::Linker::Name const& entry) { return pair_int_hash(entry.module.hash(), entry.name.hash()); }
  580. static bool equals(Wasm::Linker::Name const& a, Wasm::Linker::Name const& b) { return a.name == b.name && a.module == b.module; }
  581. };