Skip to content

Factorial function ends up deadlocking VM #88

@xTrayambak

Description

@xTrayambak

Example Source

function fac(n, acc) {
	console.log("n:", n)
	console.log("acc:", acc)
	if (n == 0) {
		return acc;
	}

	let value = fac(n - 1, n * acc)
	return value
}

console.log(fac(5, 1))

Expected Output

Log: n: 5
Log: acc: 1
Log: n: 4
Log: acc: 5
Log: n: 3
Log: acc: 20
Log: n: 2
Log: acc: 60
Log: n: 1
Log: acc: 120
Log: n: 0
Log: acc: 120
Log: 120

Current Output

Log: n: 5
Log: acc: 1
Log: n: 4
Log: acc: 4
Log: n: 3
Log: acc: 12
Log: n: 2
Log: acc: 24
Log: n: 1
Log: acc: 24
Log: n: 0
Log: acc: 0

<VM hangs and starts allocating a bunch of memory, eventually leading to OOM>

Metadata

Metadata

Assignees

Labels

codegen bugA bug in the IR emitter

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions