@@ -193,7 +193,8 @@ import {
193193 writeF32 ,
194194 writeF64 ,
195195 uniqueMap ,
196- isPowerOf2
196+ isPowerOf2 ,
197+ v128_zero
197198} from "./util" ;
198199
199200/** Compiler options. */
@@ -3058,10 +3059,11 @@ export class Compiler extends DiagnosticEmitter {
30583059 if ( initExpr ) {
30593060 let precomp = module . runExpression ( initExpr , ExpressionRunnerFlags . PreserveSideeffects ) ;
30603061 if ( precomp ) {
3061- initExpr = precomp ;
3062- let local = new Local ( name , - 1 , type , flow . parentFunction ) ;
3062+ initExpr = precomp ; // always use precomputed initExpr
3063+ let local : Local | null = null ;
30633064 switch ( < u32 > getExpressionType ( initExpr ) ) {
30643065 case < u32 > NativeType . I32 : {
3066+ local = new Local ( name , - 1 , type , flow . parentFunction ) ;
30653067 local . setConstantIntegerValue (
30663068 i64_new (
30673069 getConstValueI32 ( initExpr ) ,
@@ -3072,6 +3074,7 @@ export class Compiler extends DiagnosticEmitter {
30723074 break ;
30733075 }
30743076 case < u32 > NativeType . I64 : {
3077+ local = new Local ( name , - 1 , type , flow . parentFunction ) ;
30753078 local . setConstantIntegerValue (
30763079 i64_new (
30773080 getConstValueI64Low ( initExpr ) ,
@@ -3082,33 +3085,33 @@ export class Compiler extends DiagnosticEmitter {
30823085 break ;
30833086 }
30843087 case < u32 > NativeType . F32 : {
3088+ local = new Local ( name , - 1 , type , flow . parentFunction ) ;
30853089 local . setConstantFloatValue ( < f64 > getConstValueF32 ( initExpr ) , type ) ;
30863090 break ;
30873091 }
30883092 case < u32 > NativeType . F64 : {
3093+ local = new Local ( name , - 1 , type , flow . parentFunction ) ;
30893094 local . setConstantFloatValue ( getConstValueF64 ( initExpr ) , type ) ;
30903095 break ;
30913096 }
3092- default : {
3093- assert ( false ) ;
3094- return module . unreachable ( ) ;
3095- }
30963097 }
3097- // Create a virtual local that doesn't actually exist in WebAssembly
3098- let scopedLocals = flow . scopedLocals ;
3099- if ( ! scopedLocals ) flow . scopedLocals = scopedLocals = new Map ( ) ;
3100- else if ( scopedLocals . has ( name ) ) {
3101- let existing = assert ( scopedLocals . get ( name ) ) ;
3102- this . errorRelated (
3103- DiagnosticCode . Duplicate_identifier_0 ,
3104- declaration . name . range ,
3105- existing . declaration . name . range ,
3106- name
3107- ) ;
3108- return this . module . unreachable ( ) ;
3098+ if ( local ) {
3099+ // Add as a virtual local that doesn't actually exist in WebAssembly
3100+ let scopedLocals = flow . scopedLocals ;
3101+ if ( ! scopedLocals ) flow . scopedLocals = scopedLocals = new Map ( ) ;
3102+ else if ( scopedLocals . has ( name ) ) {
3103+ let existing = assert ( scopedLocals . get ( name ) ) ;
3104+ this . errorRelated (
3105+ DiagnosticCode . Duplicate_identifier_0 ,
3106+ declaration . name . range ,
3107+ existing . declaration . name . range ,
3108+ name
3109+ ) ;
3110+ return this . module . unreachable ( ) ;
3111+ }
3112+ scopedLocals . set ( name , local ) ;
3113+ isStatic = true ;
31093114 }
3110- scopedLocals . set ( name , local ) ;
3111- isStatic = true ;
31123115 }
31133116 } else {
31143117 this . error (
@@ -11035,8 +11038,6 @@ export class Compiler extends DiagnosticEmitter {
1103511038
1103611039// helpers
1103711040
11038- const v128_zero = new Uint8Array ( 16 ) ;
11039-
1104011041function mangleImportName (
1104111042 element : Element ,
1104211043 declaration : DeclarationStatement
0 commit comments