diff --git a/src/checker.ts b/src/checker.ts index 9fc55d4ca..df46bcd37 100644 --- a/src/checker.ts +++ b/src/checker.ts @@ -142,7 +142,6 @@ export class TypeChecker { node: arg, }); } - } } @@ -159,7 +158,7 @@ export class TypeChecker { return this.getTypeOfNode(sym.declarations[0]); } - @memoize + @memoize(node => node.id) private getTypeOfNode(node: BoltSyntax): Type { switch (node.kind) { case SyntaxKind.BoltReferenceTypeExpression: @@ -193,8 +192,8 @@ export class TypeChecker { type = this.resolveType('String', node)!; } else if (typeof node.value === 'boolean') { type = this.resolveType('bool', node)!; - } else if (typeof node.value === 'number') { - type = this.resolveType('int32', node)!; + } else if (typeof node.value === 'bigint') { + type = this.resolveType('i32', node)!; } else { throw new Error(`Could not derive type of constant expression.`); } diff --git a/src/util.ts b/src/util.ts index 939c278c9..9445eeea5 100644 --- a/src/util.ts +++ b/src/util.ts @@ -123,22 +123,26 @@ class DeepMap { } -export function memoize(target: any, key: PropertyKey) { - const origMethod = target[key]; - target[key] = function wrapper(...args: any[]) { - if (this.__MEMOIZE_CACHE === undefined) { - this.__MEMOIZE_CACHE = Object.create(null); +export function memoize(hasher: (...args: any[]) => string) { + return function (target: any, key: PropertyKey) { + const origMethod = target[key]; + target[key] = function wrapper(...args: any[]) { + if (this.__MEMOIZE_CACHE === undefined) { + this.__MEMOIZE_CACHE = Object.create(null); + } + if (this.__MEMOIZE_CACHE[key] === undefined) { + this.__MEMOIZE_CACHE[key] = Object.create(null); + } + const hashed = hasher(...args); + const cache = this.__MEMOIZE_CACHE[key]; + if (hashed in cache) { + return cache[hashed]; + } + const result = origMethod.apply(this, args); + cache[hashed] = result; + return result; } - if (this.__MEMOIZE_CACHE[key] === undefined) { - this.__MEMOIZE_CACHE[key] = new DeepMap(); - } - const cache = this.__MEMOIZE_CACHE[key]; - if (cache.has(args)) { - return cache.get(args); - } - const result = origMethod.apply(this, args); - cache.set(args, result); - return result; + return target; } }