Skip to content

Commit 1f042c6

Browse files
committed
fix
1 parent d5c8c0d commit 1f042c6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/compiler.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import {
6060
ensureType,
6161
createType,
6262
getConstValueInteger,
63-
isConstNonZero
63+
isConstZero
6464
} from "./module";
6565

6666
import {
@@ -10026,6 +10026,14 @@ export class Compiler extends DiagnosticEmitter {
1002610026

1002710027
// === Specialized code generation ==============================================================
1002810028

10029+
/** Check if possible to optimize the active initialization away if it's zero */
10030+
canOptimizeZeroInitialization(valueExpr: ExpressionRef): bool {
10031+
if ((this.options.runtime != Runtime.Incremental) && (this.options.runtime != Runtime.Stub)) {
10032+
return false;
10033+
}
10034+
return isConstZero(valueExpr);
10035+
}
10036+
1002910037
/** Makes a constant zero of the specified type. */
1003010038
makeZero(type: Type): ExpressionRef {
1003110039
let module = this.module;
@@ -10417,7 +10425,7 @@ export class Compiler extends DiagnosticEmitter {
1041710425
// Memory will be filled with 0 on itcms.__new
1041810426
// Memory grow will default to initialized with 0 as wasm spec
1041910427
// So, optimize the active initialization away if it's zero
10420-
if ((this.options.runtime == Runtime.Incremental || this.options.runtime == Runtime.Stub) && isConstNonZero(valueExpr)) {
10428+
if (!this.canOptimizeZeroInitialization(valueExpr)) {
1042110429
let expr = this.makeCallDirect(setterInstance, [
1042210430
module.local_get(thisLocalIndex, sizeTypeRef),
1042310431
valueExpr

0 commit comments

Comments
 (0)