Skip to content

Commit 5716649

Browse files
committed
global count fix
1 parent 03aa86b commit 5716649

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/middle/refcount.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
}

test/language.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,8 @@ test('global list release', async () => {
972972
await rv(`
973973
xs = collect(range(1, widen(3)))
974974
xs = collect(range(1, widen(3)))
975-
test length(xs) == 3
975+
n = length(xs)
976+
test n == 3
976977
`)
977978
})
978979

0 commit comments

Comments
 (0)