girving / duck

a functional language built around overloading
http://groups.google.com/group/duck-lang
Other
10 stars 2 forks source link

Ensure Var.fresh works safely #22

Closed dylex closed 15 years ago

dylex commented 15 years ago

I fear there are a number of bugs around from uses of freshen. A fresh variable is guaranteed to be unique only from variables currently in scope. However, one could be later shadowed by a user variable. At least it seems a few uses in Ir have this problem (or, at least, I think I'm introducing some), and possibly elsewhere. One solution would be to have variables be (String,Int), where the Int (or Bool) is non-zero exactly for fake variables. Alternatively (or maybe as well) we could have a variable monad that keeps track of these things as well as renaming all later shadowing variables.

girving commented 15 years ago

I'm using a scheme from http://research.microsoft.com/en-us/um/people/simonpj/papers/inlining. The idea is that you don't prevent all variable shadowing, just enough to make things work. In the case of patterns, your new variables need to be fresh with respect to (1) everything in scope and (2) all variables declared in the pattern. They don't need to be fresh with respect to variables declared in expressions later on, since it's fine if those declares shadow the temporary variables generated by pattern matching.

In the long run, especially when we hit optimization, we may want to reconsider this scheme. For now, I guess I'll close this.