ssm-lang / Scoria

This is an embedding of the Sparse Synchronous Model, in Haskell!
BSD 3-Clause "New" or "Revised" License
4 stars 0 forks source link

Transpilation bug - names are duplicated #59

Closed Rewbert closed 2 years ago

Rewbert commented 2 years ago

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.

j-hui commented 2 years ago

Writing a name canonicalization pass could be another good starter issue

Rewbert commented 2 years ago

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.

Rewbert commented 2 years ago

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.

Rewbert commented 2 years ago

Fixed by #73