Skip to content

Remove generation of intermediary variable

Basically a lot of our process add intermediary compiler generated variable.

For instance the contract view.ml

type 'a return = operation list * 'a

[@view] let v1 (n,s: int * int) : int = s + n + 1
let v2 (_,s: int * int) : int = s + 2
let bad_view (_,_: int * nat ) : nat = 1n

let main (((),s): unit * int) : int return = ([]:operation list) , s

add theses variables

type return = fun 'a . ( list (operation) * 'a )
const v1 = lambda (#193) return let #205 = #193 in  match #205 with
                                                     | ( n , s ) ->
                                                     ADD(ADD(s , n) , 1)[@view]
const v2 = lambda (#194) return let #207 = #194 in  match #207 with
                                                     | ( #195 , s ) ->
                                                     ADD(s , 2)
const bad_view = lambda (#196) return let #209 = #196 in  match #209 with
                                                           | ( #198 , #197 ) ->
                                                           +1
const main = lambda (#199) return let #211 = #199 in  match #211 with
                                                       | ( #200 , s ) ->
                                                       ( LIST_EMPTY() , s )

The goal of this issue would be to identify where we add unnecessary variables and see if we can remove them.

Note that we will have a self-pass at the end of the middle-end to remove the unnecessary indirection, but not adding them in the first place should increase the speed slightly.

(This is a big task but is good for someone who would like to get into the whole pipeline, like onboarding stage 2)

Edited by Pierre-Emmanuel Wulfman