Skip to content

Commit 3c58888

Browse files
committed
Merge remote-tracking branch 'origin/master' into release
2 parents df1411c + 088eaad commit 3c58888

Some content is hidden

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

41 files changed

+6850
-89
lines changed

lib/loader/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ Besides demangling classes exported from your entry file to a handy object struc
4343
```
4444

4545
* **__getString**(ptr: `number`): `string`<br />
46-
Copies a string's value from the module's memory.
46+
Copies a string's value from the module's memory. `ptr` must not be zero.
4747

4848
```ts
4949
var str = module.__getString(ptr);
5050
...
5151
```
5252

5353
* **__getArrayBuffer**(ptr: `number`): `ArrayBuffer`<br />
54-
Copies an ArrayBuffer's value from the module's memory.
54+
Copies an ArrayBuffer's value from the module's memory. `ptr` must not be zero.
5555

5656
* **__getArray**(ptr: `number`): `number[]`<br />
57-
Copies an array's values from the module's memory. Infers the array type from RTTI.
57+
Copies an array's values from the module's memory. Infers the array type from RTTI. `ptr` must not be zero.
5858

5959
```ts
6060
var arr = module.__getArray(ptr);
@@ -76,7 +76,7 @@ Besides demangling classes exported from your entry file to a handy object struc
7676
**__getFloat64Array**(ptr: `number`): `Float64Array`
7777

7878
* **__getArrayView**(ptr: `number`): `TypedArray`<br />
79-
Gets a live view on the values of an array in the module's memory. Infers the array type from RTTI.
79+
Gets a live view on the values of an array in the module's memory. Infers the array type from RTTI. `ptr` must not be zero.
8080

8181
This differs from `__getArray` in that the data isn't copied but remains *live* in both directions. That's faster but also unsafe because if the array grows or becomes released, the view will no longer represent the correct memory region and modifying its values in this state will most likely corrupt memory. Use, but use with care.
8282

std/assembly/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,7 @@ declare class Array<T> {
14301430
join(separator?: string): string;
14311431
reverse(): T[];
14321432
/** Flattens an array of arrays. If any null entries exist in the array, they are ignored, unlike JavaScript's version of Array#flat(). */
1433-
flat(): valueof<T>[];
1433+
flat(): T extends unknown[] ? T : never;
14341434
toString(): string;
14351435
}
14361436

std/assembly/rt/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ declare function __visit_globals(cookie: u32): void;
1212
declare function __visit_members(ref: usize, cookie: u32): void;
1313
declare function __allocBuffer(size: usize, id: u32, data?: usize): usize;
1414
declare function __allocArray(length: i32, alignLog2: usize, id: u32, data?: usize): usize;
15+
declare function __finalize(ref: usize): void;
1516
declare const ASC_RTRACE: bool;
1617
declare const __GC_ALL_ACYCLIC: bool;

std/assembly/rt/pure.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ function decrement(s: Block): void {
124124
__visit_members(changetype<usize>(s) + BLOCK_OVERHEAD, VISIT_DECREMENT);
125125
if (isDefined(__GC_ALL_ACYCLIC)) {
126126
if (DEBUG) assert(!(info & BUFFERED_MASK));
127-
freeBlock(ROOT, s);
127+
finalize(s);
128128
} else {
129129
if (!(info & BUFFERED_MASK)) {
130-
freeBlock(ROOT, s);
130+
finalize(s);
131131
} else {
132132
s.gcInfo = BUFFERED_MASK | COLOR_BLACK | 0;
133133
}
@@ -149,6 +149,14 @@ function decrement(s: Block): void {
149149
}
150150
}
151151

152+
/** Finalizes the specified block, giving it back to the memory manager. */
153+
function finalize(s: Block): void {
154+
if (isDefined(__finalize)) {
155+
__finalize(changetype<usize>(s) + BLOCK_OVERHEAD);
156+
}
157+
freeBlock(ROOT, s);
158+
}
159+
152160
/** Buffer of possible roots. */
153161
// @ts-ignore: decorator
154162
@lazy var ROOTS: usize;
@@ -205,7 +213,7 @@ export function __collect(): void {
205213
cur += sizeof<usize>();
206214
} else {
207215
if ((info & COLOR_MASK) == COLOR_BLACK && !(info & REFCOUNT_MASK)) {
208-
freeBlock(ROOT, s);
216+
finalize(s);
209217
} else {
210218
s.gcInfo = info & ~BUFFERED_MASK;
211219
}
@@ -261,7 +269,7 @@ function collectWhite(s: Block): void {
261269
if ((info & COLOR_MASK) == COLOR_WHITE && !(info & BUFFERED_MASK)) {
262270
s.gcInfo = (info & ~COLOR_MASK) | COLOR_BLACK;
263271
__visit_members(changetype<usize>(s) + BLOCK_OVERHEAD, VISIT_COLLECTWHITE);
264-
freeBlock(ROOT, s);
272+
finalize(s);
265273
}
266274
}
267275

tests/compiler/do.untouched.wat

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,6 +2296,13 @@
22962296
local.get $1
22972297
call $~lib/rt/rtrace/onfree
22982298
)
2299+
(func $~lib/rt/pure/finalize (param $0 i32)
2300+
i32.const 0
2301+
drop
2302+
global.get $~lib/rt/tlsf/ROOT
2303+
local.get $0
2304+
call $~lib/rt/tlsf/freeBlock
2305+
)
22992306
(func $~lib/rt/pure/decrement (param $0 i32)
23002307
(local $1 i32)
23012308
(local $2 i32)
@@ -2352,9 +2359,8 @@
23522359
call $~lib/builtins/abort
23532360
unreachable
23542361
end
2355-
global.get $~lib/rt/tlsf/ROOT
23562362
local.get $0
2357-
call $~lib/rt/tlsf/freeBlock
2363+
call $~lib/rt/pure/finalize
23582364
else
23592365
i32.const 1
23602366
drop

tests/compiler/extends-baseaggregate.untouched.wat

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3377,6 +3377,13 @@
33773377
call $~lib/rt/__visit_members
33783378
end
33793379
)
3380+
(func $~lib/rt/pure/finalize (param $0 i32)
3381+
i32.const 0
3382+
drop
3383+
global.get $~lib/rt/tlsf/ROOT
3384+
local.get $0
3385+
call $~lib/rt/tlsf/freeBlock
3386+
)
33803387
(func $~lib/rt/pure/scanBlack (param $0 i32)
33813388
local.get $0
33823389
local.get $0
@@ -3464,9 +3471,8 @@
34643471
i32.add
34653472
i32.const 5
34663473
call $~lib/rt/__visit_members
3467-
global.get $~lib/rt/tlsf/ROOT
34683474
local.get $0
3469-
call $~lib/rt/tlsf/freeBlock
3475+
call $~lib/rt/pure/finalize
34703476
end
34713477
)
34723478
(func $~lib/rt/pure/__collect
@@ -3539,9 +3545,8 @@
35393545
i32.const 0
35403546
end
35413547
if
3542-
global.get $~lib/rt/tlsf/ROOT
35433548
local.get $5
3544-
call $~lib/rt/tlsf/freeBlock
3549+
call $~lib/rt/pure/finalize
35453550
else
35463551
local.get $5
35473552
local.get $6
@@ -3761,9 +3766,8 @@
37613766
i32.and
37623767
i32.eqz
37633768
if
3764-
global.get $~lib/rt/tlsf/ROOT
37653769
local.get $0
3766-
call $~lib/rt/tlsf/freeBlock
3770+
call $~lib/rt/pure/finalize
37673771
else
37683772
local.get $0
37693773
i32.const -2147483648

tests/compiler/for.untouched.wat

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,6 +2341,13 @@
23412341
local.get $1
23422342
call $~lib/rt/rtrace/onfree
23432343
)
2344+
(func $~lib/rt/pure/finalize (param $0 i32)
2345+
i32.const 0
2346+
drop
2347+
global.get $~lib/rt/tlsf/ROOT
2348+
local.get $0
2349+
call $~lib/rt/tlsf/freeBlock
2350+
)
23442351
(func $~lib/rt/pure/decrement (param $0 i32)
23452352
(local $1 i32)
23462353
(local $2 i32)
@@ -2397,9 +2404,8 @@
23972404
call $~lib/builtins/abort
23982405
unreachable
23992406
end
2400-
global.get $~lib/rt/tlsf/ROOT
24012407
local.get $0
2402-
call $~lib/rt/tlsf/freeBlock
2408+
call $~lib/rt/pure/finalize
24032409
else
24042410
i32.const 1
24052411
drop

tests/compiler/implicit-getter-setter.untouched.wat

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(module
2-
(type $i32_i32_=>_none (func (param i32 i32)))
32
(type $i32_=>_none (func (param i32)))
3+
(type $i32_i32_=>_none (func (param i32 i32)))
44
(type $i32_=>_i32 (func (param i32) (result i32)))
55
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
66
(type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32)))
@@ -1636,6 +1636,13 @@
16361636
local.get $1
16371637
call $~lib/rt/rtrace/onfree
16381638
)
1639+
(func $~lib/rt/pure/finalize (param $0 i32)
1640+
i32.const 0
1641+
drop
1642+
global.get $~lib/rt/tlsf/ROOT
1643+
local.get $0
1644+
call $~lib/rt/tlsf/freeBlock
1645+
)
16391646
(func $~lib/rt/pure/decrement (param $0 i32)
16401647
(local $1 i32)
16411648
(local $2 i32)
@@ -1692,9 +1699,8 @@
16921699
call $~lib/builtins/abort
16931700
unreachable
16941701
end
1695-
global.get $~lib/rt/tlsf/ROOT
16961702
local.get $0
1697-
call $~lib/rt/tlsf/freeBlock
1703+
call $~lib/rt/pure/finalize
16981704
else
16991705
i32.const 1
17001706
drop

tests/compiler/issues/1095.untouched.wat

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,13 @@
16201620
local.get $1
16211621
call $~lib/rt/rtrace/onfree
16221622
)
1623+
(func $~lib/rt/pure/finalize (param $0 i32)
1624+
i32.const 0
1625+
drop
1626+
global.get $~lib/rt/tlsf/ROOT
1627+
local.get $0
1628+
call $~lib/rt/tlsf/freeBlock
1629+
)
16231630
(func $~lib/rt/pure/decrement (param $0 i32)
16241631
(local $1 i32)
16251632
(local $2 i32)
@@ -1676,9 +1683,8 @@
16761683
call $~lib/builtins/abort
16771684
unreachable
16781685
end
1679-
global.get $~lib/rt/tlsf/ROOT
16801686
local.get $0
1681-
call $~lib/rt/tlsf/freeBlock
1687+
call $~lib/rt/pure/finalize
16821688
else
16831689
i32.const 1
16841690
drop

tests/compiler/issues/1225.untouched.wat

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,13 @@
16411641
local.get $1
16421642
call $~lib/rt/rtrace/onfree
16431643
)
1644+
(func $~lib/rt/pure/finalize (param $0 i32)
1645+
i32.const 0
1646+
drop
1647+
global.get $~lib/rt/tlsf/ROOT
1648+
local.get $0
1649+
call $~lib/rt/tlsf/freeBlock
1650+
)
16441651
(func $~lib/rt/pure/decrement (param $0 i32)
16451652
(local $1 i32)
16461653
(local $2 i32)
@@ -1697,9 +1704,8 @@
16971704
call $~lib/builtins/abort
16981705
unreachable
16991706
end
1700-
global.get $~lib/rt/tlsf/ROOT
17011707
local.get $0
1702-
call $~lib/rt/tlsf/freeBlock
1708+
call $~lib/rt/pure/finalize
17031709
else
17041710
i32.const 1
17051711
drop

0 commit comments

Comments
 (0)