Skip to content

Commit f0237f5

Browse files
committed
fix
1 parent e82e45f commit f0237f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+13518
-8415
lines changed

src/compiler.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10029,9 +10029,8 @@ export class Compiler extends DiagnosticEmitter {
1002910029
/** Check if possible to optimize the active initialization away if it's zero */
1003010030
canOptimizeZeroInitialization(valueExpr: ExpressionRef): bool {
1003110031
const runtime = this.options.runtime;
10032-
return (runtime == Runtime.Incremental || runtime == Runtime.Stub)
10033-
? isConstZero(valueExpr)
10034-
: false;
10032+
// Memory will be filled with 0 on itcms.__new
10033+
return runtime == Runtime.Incremental ? isConstZero(valueExpr) : false;
1003510034
}
1003610035

1003710036
/** Makes a constant zero of the specified type. */
@@ -10410,6 +10409,7 @@ export class Compiler extends DiagnosticEmitter {
1041010409

1041110410
// Initialize deferred non-parameter fields
1041210411
if (nonParameterFields) {
10412+
const unmanagedClass = classInstance.type.isUnmanaged;
1041310413
for (let i = 0, k = nonParameterFields.length; i < k; ++i) {
1041410414
let field = unchecked(nonParameterFields[i]);
1041510415
let fieldType = field.type;
@@ -10418,23 +10418,18 @@ export class Compiler extends DiagnosticEmitter {
1041810418
assert(fieldPrototype.parameterIndex < 0);
1041910419
let setterInstance = assert(field.setterInstance);
1042010420

10421-
if (initializerNode) {
10422-
// Explicit initializer
10423-
// Check if we need to initialize this field
10424-
const valueExpr: ExpressionRef = this.compileExpression(initializerNode, fieldType, Constraints.ConvImplicit);
10425-
// Memory will be filled with 0 on itcms.__new
10426-
// Memory grow will default to initialized with 0 as wasm spec
10427-
// So, optimize the active initialization away if it's zero
10428-
if (!this.canOptimizeZeroInitialization(valueExpr)) {
10429-
let expr = this.makeCallDirect(setterInstance, [
10430-
module.local_get(thisLocalIndex, sizeTypeRef),
10431-
valueExpr
10432-
], field.identifierNode, true);
10433-
if (this.currentType != Type.void) { // in case
10434-
expr = module.drop(expr);
10435-
}
10436-
stmts.push(expr);
10421+
const valueExpr: ExpressionRef =
10422+
initializerNode ? this.compileExpression(initializerNode, fieldType, Constraints.ConvImplicit)
10423+
: this.makeZero(fieldType);
10424+
if(unmanagedClass || !this.canOptimizeZeroInitialization(valueExpr)) {
10425+
let expr = this.makeCallDirect(setterInstance, [
10426+
module.local_get(thisLocalIndex, sizeTypeRef),
10427+
valueExpr
10428+
], field.identifierNode, true);
10429+
if (this.currentType != Type.void) { // in case
10430+
expr = module.drop(expr);
1043710431
}
10432+
stmts.push(expr);
1043810433
}
1043910434
}
1044010435
}

tests/compiler/assignment-chain.debug.wat

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,30 +2250,35 @@
22502250
local.get $ptr
22512251
return
22522252
)
2253-
(func $assignment-chain/A#set:y (param $this i32) (param $y i64)
2254-
local.get $this
2255-
local.get $y
2256-
i64.store offset=8
2257-
)
22582253
(func $assignment-chain/A#set:x (param $this i32) (param $x i64)
22592254
local.get $this
22602255
local.get $x
22612256
i64.store
22622257
)
2263-
(func $assignment-chain/B#get:_setter_cnt (param $this i32) (result i32)
2258+
(func $assignment-chain/A#set:y (param $this i32) (param $y i64)
22642259
local.get $this
2265-
i32.load
2260+
local.get $y
2261+
i64.store offset=8
22662262
)
22672263
(func $assignment-chain/B#set:_setter_cnt (param $this i32) (param $_setter_cnt i32)
22682264
local.get $this
22692265
local.get $_setter_cnt
22702266
i32.store
22712267
)
2268+
(func $assignment-chain/B#set:_getter_cnt (param $this i32) (param $_getter_cnt i32)
2269+
local.get $this
2270+
local.get $_getter_cnt
2271+
i32.store offset=4
2272+
)
22722273
(func $assignment-chain/B#set:_y (param $this i32) (param $_y f64)
22732274
local.get $this
22742275
local.get $_y
22752276
f64.store offset=8
22762277
)
2278+
(func $assignment-chain/B#get:_setter_cnt (param $this i32) (result i32)
2279+
local.get $this
2280+
i32.load
2281+
)
22772282
(func $assignment-chain/B#get:_getter_cnt (param $this i32) (result i32)
22782283
local.get $this
22792284
i32.load offset=4
@@ -2429,6 +2434,22 @@
24292434
local.get $this
24302435
local.set $1
24312436
global.get $~lib/memory/__stack_pointer
2437+
local.get $1
2438+
i32.store offset=4
2439+
local.get $1
2440+
i64.const 0
2441+
call $assignment-chain/A#set:x
2442+
local.get $this
2443+
local.set $1
2444+
global.get $~lib/memory/__stack_pointer
2445+
local.get $1
2446+
i32.store offset=4
2447+
local.get $1
2448+
i64.const 0
2449+
call $assignment-chain/A#set:y
2450+
local.get $this
2451+
local.set $1
2452+
global.get $~lib/memory/__stack_pointer
24322453
i32.const 8
24332454
i32.add
24342455
global.set $~lib/memory/__stack_pointer
@@ -2531,6 +2552,30 @@
25312552
local.get $this
25322553
local.set $1
25332554
global.get $~lib/memory/__stack_pointer
2555+
local.get $1
2556+
i32.store offset=4
2557+
local.get $1
2558+
i32.const 0
2559+
call $assignment-chain/B#set:_setter_cnt
2560+
local.get $this
2561+
local.set $1
2562+
global.get $~lib/memory/__stack_pointer
2563+
local.get $1
2564+
i32.store offset=4
2565+
local.get $1
2566+
i32.const 0
2567+
call $assignment-chain/B#set:_getter_cnt
2568+
local.get $this
2569+
local.set $1
2570+
global.get $~lib/memory/__stack_pointer
2571+
local.get $1
2572+
i32.store offset=4
2573+
local.get $1
2574+
f64.const 0
2575+
call $assignment-chain/B#set:_y
2576+
local.get $this
2577+
local.set $1
2578+
global.get $~lib/memory/__stack_pointer
25342579
i32.const 8
25352580
i32.add
25362581
global.set $~lib/memory/__stack_pointer

tests/compiler/assignment-chain.release.wat

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
local.get $0
123123
global.set $~lib/rt/itcms/iter
124124
end
125-
block $__inlined_func$~lib/rt/itcms/Object#unlink$124
125+
block $__inlined_func$~lib/rt/itcms/Object#unlink$129
126126
local.get $1
127127
i32.load offset=4
128128
i32.const -4
@@ -146,7 +146,7 @@
146146
call $~lib/builtins/abort
147147
unreachable
148148
end
149-
br $__inlined_func$~lib/rt/itcms/Object#unlink$124
149+
br $__inlined_func$~lib/rt/itcms/Object#unlink$129
150150
end
151151
local.get $1
152152
i32.load offset=8
@@ -1661,6 +1661,18 @@
16611661
local.tee $1
16621662
i32.store
16631663
global.get $~lib/memory/__stack_pointer
1664+
local.get $1
1665+
i32.store offset=4
1666+
local.get $1
1667+
i64.const 0
1668+
i64.store
1669+
global.get $~lib/memory/__stack_pointer
1670+
local.get $1
1671+
i32.store offset=4
1672+
local.get $1
1673+
i64.const 0
1674+
i64.store offset=8
1675+
global.get $~lib/memory/__stack_pointer
16641676
i32.const 8
16651677
i32.add
16661678
global.set $~lib/memory/__stack_pointer
@@ -1778,6 +1790,24 @@
17781790
local.tee $1
17791791
i32.store
17801792
global.get $~lib/memory/__stack_pointer
1793+
local.get $1
1794+
i32.store offset=4
1795+
local.get $1
1796+
i32.const 0
1797+
i32.store
1798+
global.get $~lib/memory/__stack_pointer
1799+
local.get $1
1800+
i32.store offset=4
1801+
local.get $1
1802+
i32.const 0
1803+
i32.store offset=4
1804+
global.get $~lib/memory/__stack_pointer
1805+
local.get $1
1806+
i32.store offset=4
1807+
local.get $1
1808+
f64.const 0
1809+
f64.store offset=8
1810+
global.get $~lib/memory/__stack_pointer
17811811
i32.const 8
17821812
i32.add
17831813
global.set $~lib/memory/__stack_pointer

0 commit comments

Comments
 (0)