Fantom

 

class compiler::ClosureToImmutable

sys::Obj
  compiler::CompilerSupport
    compiler::CompilerStep
      compiler::ClosureToImmutable

Source

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:

  1. If every field is known const, then the function is always immutable, and we can just override isImmutable to return true.
  2. 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.
  3. 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)

Source

Are all the fields known to be const types?

isNeverImmutable

Bool isNeverImmutable(TypeDef cls)

Source

Are any of the fields known to never be immutable?

make

new make(Compiler compiler)

Source

run

virtual override Void run()

Source

setAllFieldsConst

Void setAllFieldsConst(TypeDef cls)

Source

Set const flag on every field def.