From 3ed746ce7835a7665866c3c5e40c3f97164d6e38 Mon Sep 17 00:00:00 2001 From: Duncan Uszkay Date: Wed, 1 Apr 2020 17:36:49 -0400 Subject: [PATCH 1/4] Change assertion failure to unreachable statement --- src/compiler.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler.ts b/src/compiler.ts index 495f670822..c24a122e5c 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -7915,7 +7915,9 @@ export class Compiler extends DiagnosticEmitter { return module.unreachable(); } let globalType = global.type; - assert(globalType != Type.void); + if(globalType == Type.void) { + return module.unreachable(); + } if (global.is(CommonFlags.INLINED)) { return this.compileInlineConstant(global, contextualType, constraints); } From 842beccd2d64e02f0c1cd3f6dbe490460ffbb4af Mon Sep 17 00:00:00 2001 From: Duncan Uszkay Date: Tue, 7 Apr 2020 11:23:17 -0400 Subject: [PATCH 2/4] whitespace --- src/compiler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler.ts b/src/compiler.ts index c24a122e5c..1b6042ceb1 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -7915,7 +7915,7 @@ export class Compiler extends DiagnosticEmitter { return module.unreachable(); } let globalType = global.type; - if(globalType == Type.void) { + if (globalType == Type.void) { return module.unreachable(); } if (global.is(CommonFlags.INLINED)) { From 59f618b71bac9939534b22405655b0cb567726a4 Mon Sep 17 00:00:00 2001 From: Duncan Uszkay Date: Wed, 6 May 2020 10:08:25 -0400 Subject: [PATCH 3/4] Move unreachable into top level statement compilation --- src/compiler.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 1b6042ceb1..481891bf47 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -1876,7 +1876,9 @@ export class Compiler extends DiagnosticEmitter { if ( !element.is(CommonFlags.AMBIENT) && // delay imports !element.hasDecorator(DecoratorFlags.LAZY) - ) this.compileGlobal(element); + ) { + if (this.compileGlobal(element)) this.module.unreachable(); + } } } break; @@ -7915,9 +7917,6 @@ export class Compiler extends DiagnosticEmitter { return module.unreachable(); } let globalType = global.type; - if (globalType == Type.void) { - return module.unreachable(); - } if (global.is(CommonFlags.INLINED)) { return this.compileInlineConstant(global, contextualType, constraints); } From d2d2017de8d742dcbe5718f0b359c754887a8da3 Mon Sep 17 00:00:00 2001 From: Duncan Uszkay Date: Wed, 6 May 2020 10:15:33 -0400 Subject: [PATCH 4/4] only set compiled flag upon successful compilation for globals --- src/compiler.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler.ts b/src/compiler.ts index 481891bf47..641fab4aec 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -940,7 +940,6 @@ export class Compiler extends DiagnosticEmitter { /** Compiles a global variable. */ compileGlobal(global: Global): bool { if (global.is(CommonFlags.COMPILED)) return true; - global.set(CommonFlags.COMPILED); var module = this.module; var initExpr: ExpressionRef = 0; @@ -995,6 +994,7 @@ export class Compiler extends DiagnosticEmitter { if (global.is(CommonFlags.AMBIENT) && global.hasDecorator(DecoratorFlags.BUILTIN)) { if (global.internalName == BuiltinNames.heap_base) this.runtimeFeatures |= RuntimeFeatures.HEAP; else if (global.internalName == BuiltinNames.rtti_base) this.runtimeFeatures |= RuntimeFeatures.RTTI; + global.set(CommonFlags.COMPILED); return true; } @@ -1140,6 +1140,7 @@ export class Compiler extends DiagnosticEmitter { } else if (!isDeclaredInline) { // compile normally module.addGlobal(internalName, nativeType, !isDeclaredConstant, initExpr); } + global.set(CommonFlags.COMPILED); return true; }