Closed Rewbert closed 3 years ago
Writing a name canonicalization pass could be another good starter issue
Since we are generating names it makes a lot of sense to generate unique names from the beginning. The SSM
monad has an Int
-state for generating fresh names. It is a data type that is mutually recursive with SSMStm
, so e.g If :: SSMExp -> SSM () -> Maybe (SSM ()) -> SSMStm
contains further SSM ()
computations. When we run these recursive computations in order to get the [Stm]
out of them, we must pass in the current name generating state. Right now I think I just reset it, which is obviously wrong.
An alpha-renaming phase makes more sense if you are parsing programs written by a user I think, but since we are generating our programs from a user EDSL specification, we shouldn't need such a pass.
Minimal program to duplicate bug:
test :: SSM ()
test = boxNullary "test" $ do
x <- var true'
ifThen false' $ do
y <- var false'
return ()
Generated (and pretty-printed) program:
entrypoint:
test()
global variables:
test() {
bool *fresh0 = var True
if(False) {
bool *fresh0 = var False
} else {
}
}
The name fresh0
is generated twice.
Fixed by #73
I've not verified this but I think I thought of a case where names in the core syntax representation generated by the frontend might be duplicated. In different scopes, so it's still valid w.r.t types, but the whole point of generating names is to generate unique names. We don't want to overshadow anything.