AbstractMachine.h 20 KB

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