Version 2 (modified by 11 years ago) (diff) | ,
---|

# Linearity

Instead of:

type DmdEnv = VarEnv Demand

we want:

type DmdEnv = Env CoreExpr Demand

We keep track of demands on partial applications.

After calling dmd_anal on the body of a let, which results in demand type `dmd_ty`

with demand env `dmd_env`

, we do the following for each let-bound variable `f`

:

- Iterate through all the keys in
`dmd_env`

, finding all applications of`f`

to*n*arguments. - For each
*i*from 1 through*n*(where*n*is`f`

's arity), if each of the applications of`f`

to*i*arguments has usage demand`OneOrZero`

, then it's safe to mark the corresponding lambda-expression as a one-shot lambda.

This might work, but is kind of kludgy.