Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure all unused elements are removed during applyDCEGraphRemovals. …
…NFC (#21840) There were bugs in `applyDCEGraphRemovals` that were preventing it from finding certain unused exports in certain cases. This change cleanup up the pass and adds assertions that all unused imports and exports are actually located and removed, thus preventing these types of bugs from sneaking in again. The test we had for `applyDCEGraphRemovals` were worked, but they were writing in a slightly different style to the current emscripten output. In particular the export name and JS name were matching, even though the actual compiler output produces JS names that contain a leading underscore. I also updates the tests to match this style for consistency. I believe the effects of this bug were not captured by our code size tests because they all run closure compiler afterwards which was removing the unused exports itself.
- Loading branch information
Showing
8 changed files
with
164 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,38 @@ | ||
var name; | ||
var wasmImports = { save1: 1, number: 33, name: name, func: function() {}, save2: 2 }; | ||
var wasmImports = { | ||
save1: 1, | ||
number: 33, | ||
name: name, | ||
func: function() {}, | ||
save2: 2 | ||
}; | ||
|
||
// exports gotten directly | ||
var expD1 = Module['expD1'] = wasmExports['expD1']; | ||
var expD2 = Module['expD2'] = wasmExports['expD2']; | ||
var expD3 = Module['expD3'] = wasmExports['expD3']; | ||
var expD4 = Module['expD4'] = wasmExports['expD4']; | ||
var _expD1 = Module['_expD1'] = wasmExports['expD1']; | ||
var _expD2 = Module['_expD2'] = wasmExports['expD2']; | ||
var _expD3 = Module['_expD3'] = wasmExports['expD3']; | ||
var _expD4 = Module['_expD4'] = wasmExports['expD4']; | ||
// Like above, but not exported on the Module | ||
var expD5 = wasmExports['expD5']; | ||
var expD6 = wasmExports['expD6']; | ||
var _expD5 = wasmExports['expD5']; | ||
var _expD6 = wasmExports['expD6']; | ||
|
||
// exports gotten indirectly (async compilation | ||
var expI1 = Module['expI1'] = () => (expI1 = Module['expI1'] = wasmExports['expI1'])(); | ||
var expI2 = Module['expI2'] = () => (expI2 = Module['expI2'] = wasmExports['expI2'])(); | ||
var expI3 = Module['expI3'] = () => (expI3 = Module['expI3'] = wasmExports['expI3'])(); | ||
var expI4 = Module['expI4'] = () => (expI4 = Module['expI4'] = wasmExports['expI4'])(); | ||
var _expI1 = Module['_expI1'] = () => (expI1 = Module['_expI1'] = wasmExports['expI1'])(); | ||
var _expI2 = Module['_expI2'] = () => (expI2 = Module['_expI2'] = wasmExports['expI2'])(); | ||
var _expI3 = Module['_expI3'] = () => (expI3 = Module['_expI3'] = wasmExports['expI3'])(); | ||
var _expI4 = Module['_expI4'] = () => (expI4 = Module['_expI4'] = wasmExports['expI4'])(); | ||
|
||
// Like above, but not exported on the Module | ||
var expI5 = () => (expI5 = wasmExports['expI5'])(); | ||
var expI6 = () => (expI6 = wasmExports['expI6'])(); | ||
var _expI5 = () => (_expI5 = wasmExports['expI5'])(); | ||
var _expI6 = () => (_expI6 = wasmExports['expI6'])(); | ||
|
||
// add uses for some of them, leave *4 as non-roots | ||
expD1; | ||
Module['expD2']; | ||
wasmExports['expD3']; | ||
_expD1; | ||
Module['_expD2']; | ||
wasmExports['_expD3']; | ||
|
||
expI1; | ||
Module['expI2']; | ||
wasmExports['expI3']; | ||
_expI1; | ||
Module['_expI2']; | ||
wasmExports['_expI3']; | ||
|
||
// EXTRA_INFO: { "unused": ["emcc$import$number", "emcc$import$name", "emcc$import$func", "emcc$export$expD4", "emcc$export$expD6", "emcc$export$expI4", "emcc$export$expI6"] } | ||
// EXTRA_INFO: { "unusedImports": ["number", "name", "func"], "unusedExports": ["expD4", "expD6", "expI4", "expI6"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
var name; | ||
var wasmImports = { save1: 1, number: 33, name: name, func: function() {}, save2: 2 }; | ||
var wasmImports = { | ||
save1: 1, | ||
number: 33, | ||
name: name, | ||
func: function() {}, | ||
save2: 2 | ||
}; | ||
|
||
// exports gotten directly in the minimal runtime style | ||
WebAssembly.instantiate(Module["wasm"], imports).then((output) => { | ||
wasmExports = output.instance.exports; | ||
expD1 = wasmExports['expD1']; | ||
expD2 = wasmExports['expD2']; | ||
expD3 = wasmExports['expD3']; | ||
expD4 = wasmExports['expD4']; | ||
_expD1 = wasmExports['expD1']; | ||
_expD2 = wasmExports['expD2']; | ||
_expD3 = wasmExports['expD3']; | ||
_expD4 = wasmExports['expD4']; | ||
initRuntime(wasmExports); | ||
ready(); | ||
}); | ||
|
||
// add uses for some of them, leave *4 as non-roots | ||
expD1; | ||
Module['expD2']; | ||
wasmExports['expD3']; | ||
_expD1; | ||
Module['_expD2']; | ||
wasmExports['_expD3']; | ||
|
||
// EXTRA_INFO: { "unused": ["emcc$import$number", "emcc$import$name", "emcc$import$func", "emcc$export$expD4", "emcc$export$expI4"] } | ||
// EXTRA_INFO: { "unusedImports": ["number", "name", "func"], "unusedExports": ["expD4"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.