Skip to content

Commit a565d73

Browse files
authored
Remove no longer used half of RTTI (#2555)
BREAKING CHANGE: RTTI at `__rtti_base` no longer contains base class ids and now is just type flags.
1 parent 0fd4db2 commit a565d73

File tree

163 files changed

+3562
-3726
lines changed

Some content is hidden

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

163 files changed

+3562
-3726
lines changed

Diff for: lib/loader/index.d.ts

-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ export interface ASUtil {
8282
/** Gets a function from poiner which contain table's index. */
8383
__getFunction(ptr: number): ((...args: unknown[]) => unknown) | null;
8484

85-
/** Tests whether a managed object is an instance of the class represented by the specified base id. */
86-
__instanceof(ptr: number, baseId: number): boolean;
8785
/** Allocates a new string in the module's memory and returns a reference (pointer) to it. */
8886
__newString(str: string): number;
8987
/** Allocates a new ArrayBuffer in the module's memory and returns a reference (pointer) to it. */

Diff for: lib/loader/index.js

+6-28
Original file line numberDiff line numberDiff line change
@@ -102,30 +102,23 @@ function postInstantiate(extendedExports, instance) {
102102
const __unpin = exports.__unpin || F_NO_EXPORT_RUNTIME;
103103
const __collect = exports.__collect || F_NO_EXPORT_RUNTIME;
104104
const __rtti_base = exports.__rtti_base;
105-
const getRttiCount = __rtti_base ? arr => arr[__rtti_base >>> 2] : F_NO_EXPORT_RUNTIME;
105+
const getTypeinfoCount = __rtti_base ? arr => arr[__rtti_base >>> 2] : F_NO_EXPORT_RUNTIME;
106106

107107
extendedExports.__new = __new;
108108
extendedExports.__pin = __pin;
109109
extendedExports.__unpin = __unpin;
110110
extendedExports.__collect = __collect;
111111

112112
/** Gets the runtime type info for the given id. */
113-
function getRttInfo(id) {
113+
function getTypeinfo(id) {
114114
const U32 = new Uint32Array(memory.buffer);
115-
if ((id >>>= 0) >= getRttiCount(U32)) throw Error(`invalid id: ${id}`);
116-
return U32[(__rtti_base + 4 >>> 2) + (id << 1)];
115+
if ((id >>>= 0) >= getTypeinfoCount(U32)) throw Error(`invalid id: ${id}`);
116+
return U32[(__rtti_base + 4 >>> 2) + id];
117117
}
118118

119-
/** Gets the runtime base id for the given id. */
120-
function getRttBase(id) {
121-
const U32 = new Uint32Array(memory.buffer);
122-
if ((id >>>= 0) >= getRttiCount(U32)) throw Error(`invalid id: ${id}`);
123-
return U32[(__rtti_base + 4 >>> 2) + (id << 1) + 1];
124-
}
125-
126-
/** Gets and validate runtime type info for the given id for array like objects */
119+
/** Gets and validates runtime type info for the given id for array like objects */
127120
function getArrayInfo(id) {
128-
const info = getRttInfo(id);
121+
const info = getTypeinfo(id);
129122
if (!(info & (ARRAYBUFFERVIEW | ARRAY | STATICARRAY))) throw Error(`not an array: ${id}, flags=${info}`);
130123
return info;
131124
}
@@ -320,21 +313,6 @@ function postInstantiate(extendedExports, instance) {
320313
});
321314
}
322315

323-
/** Tests whether an object is an instance of the class represented by the specified base id. */
324-
function __instanceof(ptr, baseId) {
325-
const U32 = new Uint32Array(memory.buffer);
326-
let id = U32[ptr + ID_OFFSET >>> 2];
327-
if (id <= getRttiCount(U32)) {
328-
do {
329-
if (id == baseId) return true;
330-
id = getRttBase(id);
331-
} while (id);
332-
}
333-
return false;
334-
}
335-
336-
extendedExports.__instanceof = __instanceof;
337-
338316
// Pull basic exports to extendedExports so code in preInstantiate can use them
339317
extendedExports.memory = extendedExports.memory || memory;
340318
extendedExports.table = extendedExports.table || table;

Diff for: lib/loader/tests/build/default.wasm

-103 Bytes
Binary file not shown.

Diff for: lib/loader/tests/build/legacy.wasm

-103 Bytes
Binary file not shown.

Diff for: lib/loader/tests/index.js

-16
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ function test(file) {
8888
{
8989
let arr = [1, 2, 3, 4, 5, 0x80000000 | 0];
9090
let ref = exports.__newArray(exports.INT32ARRAY_ID, arr);
91-
assert(exports.__instanceof(ref, exports.INT32ARRAY_ID));
9291

9392
// should be able to get the values of an array
9493
assert.deepStrictEqual(exports.__getArray(ref), arr);
@@ -104,7 +103,6 @@ function test(file) {
104103
{
105104
let arr = [1, 2, 3, 4, 5, 0x80000000 | 0];
106105
let ref = exports.__newArray(exports.STATICARRAYI32_ID, arr);
107-
assert(exports.__instanceof(ref, exports.STATICARRAYI32_ID));
108106

109107
// should be able to get the values of an array
110108
assert.deepStrictEqual(exports.__getArray(ref), arr);
@@ -120,17 +118,14 @@ function test(file) {
120118
{
121119
let arrU8Arr = new Uint8Array([0, 1, 2]);
122120
let refU8Arr = module.__newUint8Array(arrU8Arr);
123-
assert(module.__instanceof(refU8Arr, module.UINT8ARRAY_ID));
124121
assert.deepStrictEqual(module.__getUint8Array(refU8Arr), arrU8Arr);
125122
126123
let arrU16Arr = new Uint16Array([0, 0x7FFF, 0xFFFF]);
127124
let refU16Arr = module.__newUint16Array(arrU16Arr);
128-
assert(module.__instanceof(refU16Arr, module.UINT16ARRAY_ID));
129125
assert.deepStrictEqual(module.__getUint16Array(refU16Arr), arrU16Arr);
130126
131127
let arrI16Arr = new Int16Array([0, -1, -2]);
132128
let refI16Arr = module.__newInt16Array(arrI16Arr);
133-
assert(module.__instanceof(refI16Arr, module.INT16ARRAY_ID));
134129
assert.deepStrictEqual(module.__getInt16Array(refI16Arr), arrI16Arr);
135130
}
136131
*/
@@ -140,7 +135,6 @@ function test(file) {
140135
let values = [0, 255, 127];
141136
let arr = new Uint8Array(values);
142137
let ref = exports.__newArray(exports.UINT8ARRAY_ID, arr);
143-
assert(exports.__instanceof(ref, exports.UINT8ARRAY_ID));
144138
assert.deepStrictEqual(exports.__getUint8Array(ref), arr);
145139
assert.deepStrictEqual(exports.__getUint8ArrayView(ref), arr);
146140
assert.deepStrictEqual(exports.__getArray(ref), values);
@@ -150,7 +144,6 @@ function test(file) {
150144
{
151145
let arr = [0, 255, 127];
152146
let ref = exports.__newArray(exports.STATICARRAYU8_ID, arr);
153-
assert(exports.__instanceof(ref, exports.STATICARRAYU8_ID));
154147
assert.deepStrictEqual(exports.__getArray(ref), arr);
155148
}
156149

@@ -159,7 +152,6 @@ function test(file) {
159152
let values = [0, 0xFFFF, -0x00FF];
160153
let arr = new Int16Array(values);
161154
let ref = exports.__newArray(exports.INT16ARRAY_ID, arr);
162-
assert(exports.__instanceof(ref, exports.INT16ARRAY_ID));
163155
assert.deepStrictEqual(exports.__getInt16Array(ref), arr);
164156
assert.deepStrictEqual(exports.__getInt16ArrayView(ref), arr);
165157
assert.deepStrictEqual(exports.__getArray(ref), [0, -1, -255]);
@@ -169,7 +161,6 @@ function test(file) {
169161
{
170162
let arr = [0, 0xFFFF, -0x00FF];
171163
let ref = exports.__newArray(exports.STATICARRAYI16_ID, arr);
172-
assert(exports.__instanceof(ref, exports.STATICARRAYI16_ID));
173164
assert.deepStrictEqual(exports.__getArray(ref), [0, -1, -255]);
174165
}
175166

@@ -178,7 +169,6 @@ function test(file) {
178169
let values = [1, -1 >>> 0, 0x80000000];
179170
let arr = new Uint32Array(values);
180171
let ref = exports.__newArray(exports.UINT32ARRAY_ID, arr);
181-
assert(exports.__instanceof(ref, exports.UINT32ARRAY_ID));
182172
assert.deepStrictEqual(exports.__getUint32Array(ref), arr);
183173
assert.deepStrictEqual(exports.__getUint32ArrayView(ref), arr);
184174
assert.deepStrictEqual(exports.__getArray(ref), values);
@@ -188,7 +178,6 @@ function test(file) {
188178
{
189179
let arr = [1, -1 >>> 0, 0x80000000];
190180
let ref = exports.__newArray(exports.STATICARRAYU32_ID, arr);
191-
assert(exports.__instanceof(ref, exports.STATICARRAYU32_ID));
192181
assert.deepStrictEqual(exports.__getArray(ref), arr);
193182
}
194183

@@ -197,7 +186,6 @@ function test(file) {
197186
let values = [0.0, 1.5, 2.5];
198187
let arr = new Float32Array(values);
199188
let ref = exports.__newArray(exports.FLOAT32ARRAY_ID, arr);
200-
assert(exports.__instanceof(ref, exports.FLOAT32ARRAY_ID));
201189
assert.deepStrictEqual(exports.__getFloat32Array(ref), arr);
202190
assert.deepStrictEqual(exports.__getFloat32ArrayView(ref), arr);
203191
assert.deepStrictEqual(exports.__getArray(ref), values);
@@ -207,29 +195,25 @@ function test(file) {
207195
{
208196
let arr = [0.0, 1.5, 2.5];
209197
let ref = exports.__newArray(exports.STATICARRAYF32_ID, arr);
210-
assert(exports.__instanceof(ref, exports.STATICARRAYF32_ID));
211198
assert.deepStrictEqual(exports.__getArray(ref), arr);
212199
}
213200

214201
// should be able to create empty arrays
215202
{
216203
let ref = exports.__newArray(exports.ARRAYI32_ID);
217-
assert(exports.__instanceof(ref, exports.ARRAYI32_ID));
218204
assert.deepStrictEqual(exports.__getArray(ref), []);
219205
}
220206

221207
// should be able to create arrays with capacity
222208
{
223209
let ref = exports.__newArray(exports.ARRAYI32_ID, 32);
224-
assert(exports.__instanceof(ref, exports.ARRAYI32_ID));
225210
assert.strictEqual(exports.__getArray(ref).length, 32);
226211
}
227212

228213
// should be able to work with normal arrays
229214
{
230215
let arr = [1, 2, 3, 4, 5];
231216
let ref = exports.__newArray(exports.ARRAYI32_ID, arr);
232-
assert(exports.__instanceof(ref, exports.ARRAYI32_ID));
233217
exports.changeLength(ref, 3);
234218
assert.deepStrictEqual(exports.__getArray(ref), [1, 2, 3]);
235219
}

Diff for: lib/loader/umd/index.js

+7-32
Original file line numberDiff line numberDiff line change
@@ -132,31 +132,23 @@ var loader = (function(exports) {
132132
const __collect = exports.__collect || F_NO_EXPORT_RUNTIME;
133133

134134
const __rtti_base = exports.__rtti_base;
135-
const getRttiCount = __rtti_base ? arr => arr[__rtti_base >>> 2] : F_NO_EXPORT_RUNTIME;
135+
const getTypeinfoCount = __rtti_base ? arr => arr[__rtti_base >>> 2] : F_NO_EXPORT_RUNTIME;
136136
extendedExports.__new = __new;
137137
extendedExports.__pin = __pin;
138138
extendedExports.__unpin = __unpin;
139139
extendedExports.__collect = __collect;
140140
/** Gets the runtime type info for the given id. */
141141

142-
function getRttInfo(id) {
142+
function getTypeinfo(id) {
143143
const U32 = new Uint32Array(memory.buffer);
144-
if ((id >>>= 0) >= getRttiCount(U32)) throw Error(`invalid id: ${id}`);
145-
return U32[(__rtti_base + 4 >>> 2) + (id << 1)];
144+
if ((id >>>= 0) >= getTypeinfoCount(U32)) throw Error(`invalid id: ${id}`);
145+
return U32[(__rtti_base + 4 >>> 2) + id];
146146
}
147-
/** Gets the runtime base id for the given id. */
148-
149-
150-
function getRttBase(id) {
151-
const U32 = new Uint32Array(memory.buffer);
152-
if ((id >>>= 0) >= getRttiCount(U32)) throw Error(`invalid id: ${id}`);
153-
return U32[(__rtti_base + 4 >>> 2) + (id << 1) + 1];
154-
}
155-
/** Gets and validate runtime type info for the given id for array like objects */
147+
/** Gets and validates runtime type info for the given id for array like objects */
156148

157149

158150
function getArrayInfo(id) {
159-
const info = getRttInfo(id);
151+
const info = getTypeinfo(id);
160152
if (!(info & (ARRAYBUFFERVIEW | ARRAY | STATICARRAY))) throw Error(`not an array: ${id}, flags=${info}`);
161153
return info;
162154
}
@@ -366,25 +358,8 @@ var loader = (function(exports) {
366358
[BigUint64Array, BigInt64Array].forEach(ctor => {
367359
attachTypedArrayFunctions(ctor, ctor.name.slice(3), 3);
368360
});
369-
}
370-
/** Tests whether an object is an instance of the class represented by the specified base id. */
371-
372-
373-
function __instanceof(ptr, baseId) {
374-
const U32 = new Uint32Array(memory.buffer);
375-
let id = U32[ptr + ID_OFFSET >>> 2];
376-
377-
if (id <= getRttiCount(U32)) {
378-
do {
379-
if (id == baseId) return true;
380-
id = getRttBase(id);
381-
} while (id);
382-
}
383-
384-
return false;
385-
}
361+
} // Pull basic exports to extendedExports so code in preInstantiate can use them
386362

387-
extendedExports.__instanceof = __instanceof; // Pull basic exports to extendedExports so code in preInstantiate can use them
388363

389364
extendedExports.memory = extendedExports.memory || memory;
390365
extendedExports.table = extendedExports.table || table; // Demangle exports and provide the usual utility on the prototype

Diff for: src/builtins.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -10399,7 +10399,7 @@ export function compileRTTI(compiler: Compiler): void {
1039910399
let module = compiler.module;
1040010400
let managedClasses = program.managedClasses;
1040110401
let count = managedClasses.size;
10402-
let size = 4 + 8 * count;
10402+
let size = 4 + 4 * count; // count | TypeInfo*
1040310403
let data = new Uint8Array(size);
1040410404
writeI32(count, data, 0);
1040510405
let off = 4;
@@ -10443,8 +10443,6 @@ export function compileRTTI(compiler: Compiler): void {
1044310443
}
1044410444
writeI32(flags, data, off); off += 4;
1044510445
instance.rttiFlags = flags;
10446-
let base = instance.base;
10447-
writeI32(base ? base.id : 0, data, off); off += 4;
1044810446
}
1044910447
assert(off == size);
1045010448
let usizeType = program.options.usizeType;

Diff for: src/common.ts

-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ export namespace CommonNames {
256256
export const renew = "__renew";
257257
export const link = "__link";
258258
export const collect = "__collect";
259-
export const typeinfo = "__typeinfo";
260259
export const visit = "__visit";
261260
export const newBuffer = "__newBuffer";
262261
export const newArray = "__newArray";

Diff for: src/program.ts

-8
Original file line numberDiff line numberDiff line change
@@ -729,14 +729,6 @@ export class Program extends DiagnosticEmitter {
729729
}
730730
private _visitInstance: Function | null = null;
731731

732-
/** Gets the runtime `__typeinfo(id: u32): RTTIFlags` instance. */
733-
get typeinfoInstance(): Function {
734-
let cached = this._typeinfoInstance;
735-
if (!cached) this._typeinfoInstance = cached = this.requireFunction(CommonNames.typeinfo);
736-
return cached;
737-
}
738-
private _typeinfoInstance: Function | null = null;
739-
740732
/** Gets the runtime `__newBuffer(size: usize, id: u32, data: usize = 0): usize` instance. */
741733
get newBufferInstance(): Function {
742734
let cached = this._newBufferInstance;

Diff for: std/assembly/rt.ts

-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Typeinfo, TypeinfoFlags } from "./shared/typeinfo";
22
import { E_INDEXOUTOFRANGE } from "./util/error";
3-
import { OBJECT, TOTAL_OVERHEAD } from "./rt/common";
43
import { ArrayBufferView } from "./arraybuffer";
54

65
// @ts-ignore: decorator
@@ -23,18 +22,6 @@ export function __typeinfo(id: u32): TypeinfoFlags {
2322
return changetype<Typeinfo>(ptr + sizeof<u32>() + id * offsetof<Typeinfo>()).flags;
2423
}
2524

26-
// @ts-ignore: decorator
27-
@unsafe
28-
export function __instanceof(ptr: usize, classId: u32): bool { // keyword
29-
let id = changetype<OBJECT>(ptr - TOTAL_OVERHEAD).rtId;
30-
let rttiBase = __rtti_base;
31-
if (id <= load<u32>(rttiBase)) {
32-
do if (id == classId) return true;
33-
while (id = changetype<Typeinfo>(rttiBase + sizeof<u32>() + id * offsetof<Typeinfo>()).base);
34-
}
35-
return false;
36-
}
37-
3825
// @ts-ignore: decorator
3926
@unsafe
4027
export function __newBuffer(size: usize, id: u32, data: usize = 0): usize {

Diff for: std/assembly/rt/README.md

-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ Interface
5252
* **__typeinfo**(id: `u32`): `RTTIFlags`<br />
5353
Obtains the runtime type information for objects with the specified runtime id. Runtime type information is a set of flags indicating whether a type is managed, an array or similar, and what the relevant alignments when creating an instance externally are etc.
5454

55-
* **__instanceof**(ptr: `usize`, classId: `u32`): `bool`<br />
56-
Tests if the object pointed to by `ptr` is an instance of the specified class id.
57-
5855
ITCMS / `--runtime incremental`
5956
-----
6057

Diff for: std/assembly/rt/index.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ declare function __collect(): void;
1212

1313
// Runtime type info
1414
declare function __typeinfo(id: u32): u32;
15-
declare function __instanceof(ptr: usize, superId: u32): bool;
1615

1716
// Visitors
1817
declare function __visit(ptr: usize, cookie: i32): void;

Diff for: std/assembly/shared/typeinfo.ts

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
// │ count │
88
// ╞═══════════════════════════════════════════════════════════════╡ ┐
99
// │ Typeinfo#flags [id=0] │ id < count
10-
// ├ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┤
11-
// │ Typeinfo#base [id=0] │
1210
// ├───────────────────────────────────────────────────────────────┤
1311
// │ ... │
1412

@@ -17,8 +15,6 @@
1715
export class Typeinfo {
1816
/** Flags describing the shape of this class type. */
1917
flags: TypeinfoFlags = TypeinfoFlags.NONE;
20-
/** Base class id or `0` if none. */
21-
base: u32 = 0;
2218
}
2319

2420
/** Runtime type information flags. */

0 commit comments

Comments
 (0)