How about a command that notifies compiler that you dont need a stack variable anymore?
It could be something like a syntax sugar to use instead of:
{
uint myVariable = 1;
...
}
something like:
uint myVariable = 1;
discard myVariable;
How about a command that notifies compiler that you dont need a stack variable anymore?
It could be something like a syntax sugar to use instead of:
{
uint myVariable = 1;
...
}
something like:
uint myVariable = 1;
discard myVariable;
Can you elaborate a bit more on your use case and on why would you need this?
The motivation is actually explained pretty well in the question.
In order to avoid âStack Too Deepâ, you sometimes need to âscopeâ a variable.
This is demonstrated in the question via the rather âdirtyâ syntax:
{
uint myVariable = 1;
...
}
So the author suggests an alternative syntax for that, which would look âless dirtyâ.
Iâm not sure how exactly compiler works, but it definitely pops variables that get out of scope.
So if it is possible, this operator should pop a variable you dont need anymore.
If not, it should just act like a syntax sugar like i described above.
The goal - to get rid of a variable that you dont need anymore but it still occupies a slot inside stack.
This will allow not only avoid âstack to deepâ but maybe make all the next operations more gas effective (because you have one less slot in stack you need to keep about).
Though iâm not sure in my last statement, it is more to the compiler guys.
But it will at least could help to solve âstack to deepâ issue.
The compiler should be able to do so without any additional hint (such as the discard
sugar syntax in your example).
It obviously doesnât, otherwise you wouldnât need that âscoping hackâ in order to dodge the âStack Too Deepâ problem.
But instead of supporting this sugar syntax, the compiler team may as well just augment the compiler to detect that.
Note that the âStack Too Deepâ problem isnât really a common problem in all compilers (at least AFAIK). Although it sounds similar in name to the âStack Overflowâ problem, the latter is a runtime error which has nothing to do with the compiler (it can also occur on the EVM if you âtry hard enoughâ, BTW).
IMO the proposal from the OP looks like âsyntactic sugarâ to me which is something we frankly wonât pursue and like @barakman said it might no even be a compiler problem.
This syntax is most certainly not conventional for strongly-typed languages (and is not needed for weakly-typed languages), so it is most likely not going to be implemented, I would presume.
Alternative ways to circumvent (work-around) the âStack Too Deepâ problem are:
viaIR: true
in the projectâs compiler setting