From b83816bdfcbadaefdab4e09429552e8c670caaac Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Thu, 28 Jul 2022 08:35:48 +0300 Subject: [PATCH 1/4] init --- src/resolver.ts | 27 +++++++++++++++++++++--- std/assembly/index.d.ts | 4 ++-- tests/compiler/indexof-valueof.debug.wat | 17 +++++++++++++++ tests/compiler/indexof-valueof.ts | 6 ++++++ 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/resolver.ts b/src/resolver.ts index 7c7aac2fa9..1ec0983233 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -96,7 +96,8 @@ import { import { uniqueMap, - isPowerOf2 + isPowerOf2, + CharCode } from "./util"; import { @@ -525,8 +526,28 @@ export class Resolver extends DiagnosticEmitter { if (!typeArgument) return null; var classReference = typeArgument.getClassOrWrapper(this.program); if (classReference) { - let overload = classReference.lookupOverload(OperatorKind.INDEXED_GET); - if (overload) return overload.signature.returnType; + if (classReference.extends(this.program.arrayBufferViewInstance.prototype)) { + // Fast path for typed arrays + let name = classReference.name; + let headChar = name.charCodeAt(0); + if (headChar == CharCode.F) { // float points + if (name == CommonNames.Float32Array) return Type.f32; + if (name == CommonNames.Float64Array) return Type.f64; + } else if (headChar == CharCode.U) { // unsigned + if (name == CommonNames.Uint8Array || name == CommonNames.Uint8ClampedArray) return Type.u8; + if (name == CommonNames.Uint16Array) return Type.u16; + if (name == CommonNames.Uint32Array) return Type.u32; + if (name == CommonNames.Uint64Array) return Type.u64; + } else { + if (name == CommonNames.Int8Array) return Type.i8; + if (name == CommonNames.Int16Array) return Type.i16; + if (name == CommonNames.Int32Array) return Type.i32; + if (name == CommonNames.Int64Array) return Type.i64; + } + } else { + let overload = classReference.lookupOverload(OperatorKind.INDEXED_GET); + if (overload) return overload.signature.returnType; + } } if (reportMode == ReportMode.REPORT) { this.error( diff --git a/std/assembly/index.d.ts b/std/assembly/index.d.ts index 4ce37925f2..07877315f1 100644 --- a/std/assembly/index.d.ts +++ b/std/assembly/index.d.ts @@ -1349,9 +1349,9 @@ declare abstract class i31 { /** Macro type evaluating to the underlying native WebAssembly type. */ declare type native = T; /** Special type evaluating the indexed access index type. */ -declare type indexof = keyof T; +declare type indexof> = keyof T; /** Special type evaluating the indexed access value type. */ -declare type valueof = T[0]; +declare type valueof> = T[0]; /** A special type evaluated to the return type of T if T is a callable function. */ declare type ReturnType any> = T extends (...args: any) => infer R ? R : any; /** A special type evaluated to the return type of T if T is a callable function. */ diff --git a/tests/compiler/indexof-valueof.debug.wat b/tests/compiler/indexof-valueof.debug.wat index 769d965c90..533013ceaf 100644 --- a/tests/compiler/indexof-valueof.debug.wat +++ b/tests/compiler/indexof-valueof.debug.wat @@ -73,6 +73,23 @@ drop i32.const 1 drop + i32.const 0 + i32.eqz + drop + i32.const 4 + i32.const 4 + i32.eq + drop + i32.const 1 + drop + i32.const 1 + drop + i32.const 8 + i32.const 8 + i32.eq + drop + i32.const 1 + drop i32.const 1 drop i32.const 1 diff --git a/tests/compiler/indexof-valueof.ts b/tests/compiler/indexof-valueof.ts index 9e271e2c0b..44bc5cc950 100644 --- a/tests/compiler/indexof-valueof.ts +++ b/tests/compiler/indexof-valueof.ts @@ -39,6 +39,12 @@ assert(sizeof>() == 4); // i32 assert(isInteger>()); assert(!isSigned>()); assert(sizeof>() == 1); +assert(isFloat>()); +assert(!isInteger>()); +assert(sizeof>() == 4); +assert(isInteger>()); +assert(isSigned>()); +assert(sizeof>() == 8); // map indexes assert(isInteger>>()); From b3ef47b388f828be0bcfe38b290a0b75e7ac53a0 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Thu, 28 Jul 2022 08:38:40 +0300 Subject: [PATCH 2/4] remove comments --- src/resolver.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/resolver.ts b/src/resolver.ts index 1ec0983233..433e8b4fa4 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -530,10 +530,10 @@ export class Resolver extends DiagnosticEmitter { // Fast path for typed arrays let name = classReference.name; let headChar = name.charCodeAt(0); - if (headChar == CharCode.F) { // float points + if (headChar == CharCode.F) { if (name == CommonNames.Float32Array) return Type.f32; if (name == CommonNames.Float64Array) return Type.f64; - } else if (headChar == CharCode.U) { // unsigned + } else if (headChar == CharCode.U) { if (name == CommonNames.Uint8Array || name == CommonNames.Uint8ClampedArray) return Type.u8; if (name == CommonNames.Uint16Array) return Type.u16; if (name == CommonNames.Uint32Array) return Type.u32; From 99f59973e2d5897a14303805bec0684bfafbcef4 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Thu, 28 Jul 2022 08:41:41 +0300 Subject: [PATCH 3/4] remove fast path code --- src/resolver.ts | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/src/resolver.ts b/src/resolver.ts index 433e8b4fa4..d365e26da2 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -526,28 +526,8 @@ export class Resolver extends DiagnosticEmitter { if (!typeArgument) return null; var classReference = typeArgument.getClassOrWrapper(this.program); if (classReference) { - if (classReference.extends(this.program.arrayBufferViewInstance.prototype)) { - // Fast path for typed arrays - let name = classReference.name; - let headChar = name.charCodeAt(0); - if (headChar == CharCode.F) { - if (name == CommonNames.Float32Array) return Type.f32; - if (name == CommonNames.Float64Array) return Type.f64; - } else if (headChar == CharCode.U) { - if (name == CommonNames.Uint8Array || name == CommonNames.Uint8ClampedArray) return Type.u8; - if (name == CommonNames.Uint16Array) return Type.u16; - if (name == CommonNames.Uint32Array) return Type.u32; - if (name == CommonNames.Uint64Array) return Type.u64; - } else { - if (name == CommonNames.Int8Array) return Type.i8; - if (name == CommonNames.Int16Array) return Type.i16; - if (name == CommonNames.Int32Array) return Type.i32; - if (name == CommonNames.Int64Array) return Type.i64; - } - } else { - let overload = classReference.lookupOverload(OperatorKind.INDEXED_GET); - if (overload) return overload.signature.returnType; - } + let overload = classReference.lookupOverload(OperatorKind.INDEXED_GET); + if (overload) return overload.signature.returnType; } if (reportMode == ReportMode.REPORT) { this.error( From 9e49f0c381f69f510e8edf7766d29184ae193710 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Thu, 28 Jul 2022 08:42:42 +0300 Subject: [PATCH 4/4] cleanup --- src/resolver.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/resolver.ts b/src/resolver.ts index d365e26da2..7c7aac2fa9 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -96,8 +96,7 @@ import { import { uniqueMap, - isPowerOf2, - CharCode + isPowerOf2 } from "./util"; import {