-
Notifications
You must be signed in to change notification settings - Fork 843
Fixes regarding explicit names #6466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
44459f7
e5ba9c2
f8c6b7e
bae02d1
7afab53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -48,6 +48,7 @@ Function* copyFunction(Function* func, | |||||
| std::optional<std::vector<Index>> fileIndexMap) { | ||||||
| auto ret = std::make_unique<Function>(); | ||||||
| ret->name = newName.is() ? newName : func->name; | ||||||
| ret->hasExplicitName = newName.is() || func->hasExplicitName; | ||||||
|
||||||
| ret->hasExplicitName = newName.is() || func->hasExplicitName; | |
| ret->hasExplicitName = func->hasExplicitName; |
I think it's better to just match the copied function. Their names may differ (if copied into the same module) but the property of having an explicit name seems like it should be the same, at least by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, indeed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this move? The description of the function it was moved to is that it copies toplevel module items like Functions and Globals, and not metadata.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, you think I should rather put the code that copy type names in wasm-merge.cc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't see why my question, which was about the deletion of this line, is answered by something about wasm-merge? What is the context I am missing?
From the standpoint of this file by itself (not thinking about wasm-merge at all), this change seems surprising as I said - it looks like this code moved up to copyModuleItems which I don't understand the motivation for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wasm-merge currently does not copy type names from the input modules to the merged module. I added some code for that in copyModuleItems. But then this line became unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, so wasm-merge uses copyModuleItems and not copyModule. The difference between those two decreases with this change, and the meaning of the difference becomes less clear to me. Perhaps we don't need two functions here at all, and there could just be a single function with maybe a set of options as to whether to copy exports, the start method, etc. (the things only in copyModule). Anyhow, for this PR I think the change you made is good, but please add a TODO on copyModule to remind us later, maybe something like TODO: merge this with copyModuleItems, and add options for copying exports and other things that are currently different between them, if we still need those differences.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -864,19 +864,27 @@ void WasmBinaryWriter::writeNames() { | |
|
|
||
| // function names | ||
| { | ||
| auto substart = | ||
| startSubsection(BinaryConsts::CustomSections::Subsection::NameFunction); | ||
| o << U32LEB(indexes.functionIndexes.size()); | ||
| Index emitted = 0; | ||
| auto add = [&](Function* curr) { | ||
| o << U32LEB(emitted); | ||
| writeEscapedName(curr->name.str); | ||
| emitted++; | ||
| std::vector<std::pair<Index, Function*>> functionsWithNames; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the very same code as for globals. |
||
| Index checked = 0; | ||
| auto check = [&](Function* curr) { | ||
| if (curr->hasExplicitName) { | ||
| functionsWithNames.push_back({checked, curr}); | ||
| } | ||
| checked++; | ||
| }; | ||
| ModuleUtils::iterImportedFunctions(*wasm, add); | ||
| ModuleUtils::iterDefinedFunctions(*wasm, add); | ||
| assert(emitted == indexes.functionIndexes.size()); | ||
| finishSubsection(substart); | ||
| ModuleUtils::iterImportedFunctions(*wasm, check); | ||
| ModuleUtils::iterDefinedFunctions(*wasm, check); | ||
| assert(checked == indexes.functionIndexes.size()); | ||
| if (functionsWithNames.size() > 0) { | ||
| auto substart = | ||
| startSubsection(BinaryConsts::CustomSections::Subsection::NameFunction); | ||
| o << U32LEB(functionsWithNames.size()); | ||
| for (auto& [index, global] : functionsWithNames) { | ||
| o << U32LEB(index); | ||
| writeEscapedName(global->name.str); | ||
| } | ||
| finishSubsection(substart); | ||
| } | ||
| } | ||
|
|
||
| // local names | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| ;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. | ||
| ;; RUN: wasm-merge -g %s first %s.second second -all -o %t.wasm | ||
| ;; RUN: wasm-opt -all %t.wasm -S -o - | filecheck %s | ||
| (module | ||
| ;; CHECK: (type $0 (func)) | ||
|
|
||
| ;; CHECK: (type $t (struct (field $a i32) (field $b i32))) | ||
|
|
||
| ;; CHECK: (type $2 (func (param (ref $t)))) | ||
|
|
||
| ;; CHECK: (type $u (struct (field $c i64) (field $d i32))) | ||
|
|
||
| ;; CHECK: (type $4 (func (param (ref $u)))) | ||
|
|
||
| ;; CHECK: (global $global$0 i32 (i32.const 0)) | ||
|
|
||
| ;; CHECK: (global $glob2 i32 (i32.const 0)) | ||
|
|
||
| ;; CHECK: (global $global$2 i32 (i32.const 0)) | ||
|
|
||
| ;; CHECK: (global $glob0 i32 (i32.const 0)) | ||
|
|
||
| ;; CHECK: (memory $mem0 0) | ||
|
|
||
| ;; CHECK: (memory $1 0) | ||
|
|
||
| ;; CHECK: (memory $mem2 0) | ||
|
|
||
| ;; CHECK: (memory $3 0) | ||
|
|
||
| ;; CHECK: (table $table0 1 funcref) | ||
|
|
||
| ;; CHECK: (table $1 1 funcref) | ||
|
|
||
| ;; CHECK: (table $table2 1 funcref) | ||
|
|
||
| ;; CHECK: (table $3 1 funcref) | ||
|
|
||
| ;; CHECK: (tag $tag0) | ||
|
|
||
| ;; CHECK: (tag $tag$1) | ||
|
|
||
| ;; CHECK: (tag $tag2) | ||
|
|
||
| ;; CHECK: (tag $tag$3) | ||
|
|
||
| ;; CHECK: (export "m0" (memory $mem0)) | ||
|
|
||
| ;; CHECK: (export "m1" (memory $1)) | ||
|
|
||
| ;; CHECK: (export "f0" (func $func0)) | ||
|
|
||
| ;; CHECK: (export "f1" (func $1)) | ||
|
|
||
| ;; CHECK: (export "t0" (table $table0)) | ||
|
|
||
| ;; CHECK: (export "t1" (table $1)) | ||
|
|
||
| ;; CHECK: (export "g0" (global $glob0)) | ||
|
|
||
| ;; CHECK: (export "g1" (global $global$2)) | ||
|
|
||
| ;; CHECK: (export "tag0" (tag $tag0)) | ||
|
|
||
| ;; CHECK: (export "tag1" (tag $tag$1)) | ||
|
|
||
| ;; CHECK: (export "func" (func $2)) | ||
|
|
||
| ;; CHECK: (export "m2" (memory $mem2)) | ||
|
|
||
| ;; CHECK: (export "m3" (memory $3)) | ||
|
|
||
| ;; CHECK: (export "f2" (func $func2)) | ||
|
|
||
| ;; CHECK: (export "f3" (func $4)) | ||
|
|
||
| ;; CHECK: (export "t2" (table $table2)) | ||
|
|
||
| ;; CHECK: (export "t3" (table $3)) | ||
|
|
||
| ;; CHECK: (export "g2" (global $glob2)) | ||
|
|
||
| ;; CHECK: (export "g3" (global $global$0)) | ||
|
|
||
| ;; CHECK: (export "tag2" (tag $tag2)) | ||
|
|
||
| ;; CHECK: (export "tag3" (tag $tag$3)) | ||
|
|
||
| ;; CHECK: (export "func2" (func $5)) | ||
|
|
||
| ;; CHECK: (func $func0 (type $0) | ||
| ;; CHECK-NEXT: (nop) | ||
| ;; CHECK-NEXT: ) | ||
| (func $func0 (export "f0")) | ||
| (func (export "f1")) | ||
|
|
||
| (table $table0 (export "t0") 1 funcref) | ||
| (table (export "t1") 1 funcref) | ||
|
|
||
| (global $glob0 (export g0) i32 (i32.const 0)) | ||
| (global (export g1) i32 (i32.const 0)) | ||
|
|
||
| (memory $mem0 (export "m0") 0) | ||
| (memory (export "m1") 0) | ||
|
|
||
| (elem $elem0 func) | ||
| (elem func) | ||
|
|
||
| (data $data0 "") | ||
| (data "") | ||
|
|
||
| (tag $tag0 (export tag0)) | ||
| (tag (export tag1)) | ||
|
|
||
| (type $t (struct (field $a i32) (field $b i32))) | ||
|
|
||
| (func (export "func") (param $x (ref $t))) | ||
| ) | ||
| ;; CHECK: (func $1 (type $0) | ||
| ;; CHECK-NEXT: (nop) | ||
| ;; CHECK-NEXT: ) | ||
|
|
||
| ;; CHECK: (func $2 (type $2) (param $x (ref $t)) | ||
| ;; CHECK-NEXT: (nop) | ||
| ;; CHECK-NEXT: ) | ||
|
|
||
| ;; CHECK: (func $func2 (type $0) | ||
| ;; CHECK-NEXT: (nop) | ||
| ;; CHECK-NEXT: ) | ||
|
|
||
| ;; CHECK: (func $4 (type $0) | ||
| ;; CHECK-NEXT: (nop) | ||
| ;; CHECK-NEXT: ) | ||
|
|
||
| ;; CHECK: (func $5 (type $4) (param $0 (ref $u)) | ||
| ;; CHECK-NEXT: (nop) | ||
| ;; CHECK-NEXT: ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| (module | ||
|
|
||
| (func $func2 (export "f2")) | ||
| (func (export "f3")) | ||
|
|
||
| (table $table2 (export "t2") 1 funcref) | ||
| (table (export "t3") 1 funcref) | ||
|
|
||
| (memory $mem2 (export "m2") 0) | ||
| (memory (export "m3") 0) | ||
|
|
||
| (global $glob2 (export g2) i32 (i32.const 0)) | ||
| (global (export g3) i32 (i32.const 0)) | ||
|
|
||
| (elem $elem2 func) | ||
| (elem func) | ||
|
|
||
| (data $data2 "") | ||
| (data "") | ||
|
|
||
| (tag $tag2 (export tag2)) | ||
| (tag (export tag3)) | ||
|
|
||
| (type $u (struct (field $c i64) (field $d i32))) | ||
|
|
||
| (func (export "func2") (param (ref $u))) | ||
| ) |
vouillon marked this conversation as resolved.
Show resolved
Hide resolved
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did this change?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function name section is no longer written when there is no name. |
Uh oh!
There was an error while loading. Please reload this page.