|
99 | 99 |
|
100 | 100 | #include "ir/module-utils.h" |
101 | 101 | #include "ir/names.h" |
| 102 | +#include "ir/utils.h" |
102 | 103 | #include "support/colors.h" |
103 | 104 | #include "support/file.h" |
104 | 105 | #include "wasm-builder.h" |
@@ -557,6 +558,30 @@ void fuseImportsAndExports(const PassOptions& options) { |
557 | 558 | updateNames(merged, kindNameUpdates); |
558 | 559 | } |
559 | 560 |
|
| 561 | +// Things may have been imported using supertypes, which means they can get |
| 562 | +// refined after merging. |
| 563 | +void updateTypes(Module& wasm) { |
| 564 | + struct Updater : public WalkerPass<PostWalker<Updater>> { |
| 565 | + bool isFunctionParallel() override { return true; } |
| 566 | + |
| 567 | + std::unique_ptr<Pass> create() override { |
| 568 | + return std::make_unique<Updater>(); |
| 569 | + } |
| 570 | + |
| 571 | + void visitRefFunc(RefFunc* curr) { |
| 572 | + curr->finalize(getModule()->getFunction(curr->func)->type); |
| 573 | + } |
| 574 | + |
| 575 | + void visitFunction(Function* curr) { |
| 576 | + ReFinalize().walkFunctionInModule(curr, getModule()); |
| 577 | + } |
| 578 | + } updater; |
| 579 | + |
| 580 | + PassRunner runner(&wasm); |
| 581 | + updater.run(&runner, &wasm); |
| 582 | + updater.runOnModuleCode(&runner, &wasm); |
| 583 | +} |
| 584 | + |
560 | 585 | // Merges an input module into an existing target module. The input module can |
561 | 586 | // be modified, as it will no longer be needed (so it is intentionally not |
562 | 587 | // marked as const here). |
@@ -765,6 +790,9 @@ Input source maps can be specified by adding an -ism option right after the modu |
765 | 790 | // module. |
766 | 791 | fuseImportsAndExports(options.passOptions); |
767 | 792 |
|
| 793 | + // Update types after combing and linking everything. |
| 794 | + updateTypes(merged); |
| 795 | + |
768 | 796 | { |
769 | 797 | PassRunner passRunner(&merged); |
770 | 798 | // We might have made some globals read from others that now appear after |
|
0 commit comments