@@ -190,7 +190,7 @@ function refcountsIR(code: MIR): MIR {
190190 const lv = ir . liveness ( code )
191191 const pr = new ir . Pipe ( code )
192192 for ( const bl of pr . blocks ( ) ) {
193- const rel = ( x : number ) => { if ( isreftype ( code . type ( x ) ) ) release ( pr , code . type ( x ) as Type , x ) }
193+ const rel = ( x : number ) => { if ( ! isglobal ( code , x ) && isreftype ( code . type ( x ) ) ) release ( pr , code . type ( x ) as Type , x ) }
194194 // unused block arguments
195195 for ( const x of code . block ( bl . id ) . args )
196196 if ( ! some ( lv . blocks . get ( bl . id ) ) . has ( x ) ) rel ( x )
@@ -205,6 +205,7 @@ function refcountsIR(code: MIR): MIR {
205205 if ( st . expr . head === 'release' ) {
206206 pr . delete ( v )
207207 const x = asNumber ( st . expr . body [ 0 ] )
208+ if ( isglobal ( code , x ) ) continue
208209 const T = code . type ( x )
209210 if ( isreftype ( T ) && ! lv . stmts . get ( v ) ! . has ( x ) ) release ( pr , T , x )
210211 } else if ( st . expr . head === 'retain' ) {
@@ -228,6 +229,7 @@ function refcountsIR(code: MIR): MIR {
228229 pr . replace ( v , v2 )
229230 // dropped variable
230231 if ( st . type !== ir . unreachable ) {
232+ if ( isglobal ( code , v ) ) continue
231233 if ( isreftype ( st . type ) && ! lv . stmts . get ( v ) ! . has ( v ) ) release ( pr , st . type , v2 )
232234 }
233235 }
0 commit comments