Closed dhil closed 10 months ago
@rossberg, I would expect this program to fail due to $ct
not being a well-formed type. A well-formed continuation type is always parameterised by a valid function type. But looking at the reference interpreter, we never seem to check whether types are well-formed.
I noticed it is possible to define a function type in terms of itself, e.g. the following program type checks and runs:
(module
(type $ft (func (param (ref $ft))))
(func $f (param $f (ref $ft))
(call_ref $ft
(local.get $f)
(local.get $f)))
(elem declare func $f)
(func (export "main")
(call $f (ref.func $f)))
)
(assert_exhaustion (invoke "main") "call stack exhausted")
This construction leads me to think that singly typedefs are implicitly recursive. Is this construction intended?
A type without rec is simply a short-hand for a singleton recursion group, so the latter is well-typed.
As for the OP, I'm surprised the type definition passes validation. AFAICS, we do check type definitions, and we do check that cont is given a function type.
I was looking at the version in the effect-handlers repo, the one here does indeed seem to miss that check:
aha, so this has been lost in a merge sometime ago. I will reinstall the check. Thanks!
Using a recursive continuation type triggers an assertion failure in the interpreter. Minimal repo:
Output: