Skip to content

Conversation

@DCupello1
Copy link

@DCupello1 DCupello1 commented Jan 13, 2026

It probably is a good time to make use of the let premise in efforts to make function definitions more translatable.

This pass goes through all list of premises, and if there is a LHS that has a variable that has not been declared before, then it introduces a let premise.

Due to this approach, this pass relies on the ordering of the premises. Perhaps there is a way to remove this restriction but for now this naive approach should work fine.

Valid LHS are:
VarE, StrE (records), CaseE, IterE (probably should only allow identity iteration), TupE

In the validator, there are some RHS that need to be inferred, but some expressions are not possible to have there type inferred.

So, the RHS not allowed are:
OptE, StrE

For the most part, this works well. However due to some of the restrictions above, (and uncaseE appearing in unfortunate locations) it sometimes just does not introduce the let premise.

Example from Wasm 3.0:

rec {
def $minus_recs(typevar*, typeuse*) : (typevar*, typeuse*)
  def $minus_recs([], []) = ([], [])
  def $minus_recs{n : n, `tv*` : typevar*, tu_1 : typeuse, `tu*` : typeuse*}([REC_typevar(n)] ++ tv*{tv <- `tv*`}, [tu_1] ++ tu*{tu <- `tu*`}) = $minus_recs(tv*{tv <- `tv*`}, tu*{tu <- `tu*`})
  def $minus_recs{x : idx, `tv*` : typevar*, tu_1 : typeuse, `tu*` : typeuse*, `tv'*` : typevar*, `tu'*` : typeuse*}([_IDX_typevar(x)] ++ tv*{tv <- `tv*`}, [tu_1] ++ tu*{tu <- `tu*`}) = ([_IDX_typevar(x)] ++ tv'*{tv' <- `tv'*`}, [tu_1] ++ tu'*{tu' <- `tu'*`})
    -- if ((tv'*{tv' <- `tv'*`}, tu'*{tu' <- `tu'*`}) = $minus_recs(tv*{tv <- `tv*`}, tu*{tu <- `tu*`}))
}

to

rec {
def $minus_recs(typevar*, typeuse*) : (typevar*, typeuse*)
  def $minus_recs([], []) = ([], [])
  def $minus_recs{n : nat, `tv*` : typevar*, tu_1 : typeuse, `tu*` : typeuse*}([REC_typevar(n)] ++ tv*{tv <- `tv*`}, [tu_1] ++ tu*{tu <- `tu*`}) = $minus_recs(tv*{tv <- `tv*`}, tu*{tu <- `tu*`})
  def $minus_recs{x : uN(32), `tv*` : typevar*, tu_1 : typeuse, `tu*` : typeuse*, `tv'*` : typevar*, `tu'*` : typeuse*}([_IDX_typevar(x)] ++ tv*{tv <- `tv*`}, [tu_1] ++ tu*{tu <- `tu*`}) = ([_IDX_typevar(x)] ++ tv'*{tv' <- `tv'*`}, [tu_1] ++ tu'*{tu' <- `tu'*`})
    -- where (tv'*{tv' <- `tv'*`}, tu'*{tu' <- `tu'*`}) = $minus_recs(tv*{tv <- `tv*`}, tu*{tu <- `tu*`}) {tu', `tu'*`, tv', `tv'*`}
}

Based off #198 so need to merge that one first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants