class compiler::ClosureToImmutable
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.
- isAlwaysImmutable
-
Bool isAlwaysImmutable(TypeDef cls)
Are all the fields known to be const types?
- isNeverImmutable
-
Str? isNeverImmutable(TypeDef cls)
Are any of the fields known to never be immutable? If any field is not immutable, then return meaningful error message.
- make
-
new make(Compiler compiler)
- run
-
virtual override Void run()
- setAllFieldsConst
-
Void setAllFieldsConst(TypeDef cls)
Set const flag on every field def.