Fantom

 

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:

  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.

Slots

isAlwaysImmutableSource

Bool isAlwaysImmutable(TypeDef cls)

Are all the fields known to be const types?

isNeverImmutableSource

Bool isNeverImmutable(TypeDef cls)

Are any of the fields known to never be immutable?

makeSource

new make(Compiler compiler)

runSource

override Void run()

Run the step

setAllFieldsConstSource

Void setAllFieldsConst(TypeDef cls)

Set const flag on every field def.