mass icon indicating copy to clipboard operation
mass copied to clipboard

Gather Up Variable During Parsing

Open grassator opened this issue 4 years ago • 0 comments

Give a code like this:

const foo = get_foo()
const unused = 2
const bar = foo + 1
return bar

We should be able to realize during parsing that unused variable is unused and if we also track side effects at least for simple expression it can be eliminated.

It is also visible that foo is last used in the assignment to bar.

bar itself should not even need a register allocated since it is only used once right after which means that we could return foo + 1 right away.

The caveat for all of the above is that it only works inside a basic block. Cross-block escape analysis is far beyond the scope atm.

grassator avatar Mar 31 '21 16:03 grassator