sys::Obj compiler::CompilerSupport compiler::CompilerStep compiler::ClosureToImmutable
ClosureToImmutable processes each closure to determine its immutability. At this point, all the enclosed variables have been mapped to fields by ClosureVars. So we have three cases:
- If every field is known const, then the function is always immutable, and we can just override isImmutable to return true.
- If any field is known to never be const, then the function can never be immutable, and we just use Func defaults for isImmutable and toImmutable.
- In the last case we have fields like Obj or List which require us calling toImmutable. In this case we generate a toImmutable method which constructs a new closure instance by calling toImmutable on each field.
Are all the fields known to be const types?
Are any of the fields known to never be immutable?
new make(Compiler compiler)
virtual override Void run()
Set const flag on every field def.