Skip to content
  • Travis Whitaker's avatar
    Correct closure observation, construction, and mutation on weak memory machines. · 62e19a6d
    Travis Whitaker authored and Ben Gamari's avatar Ben Gamari committed
    Here the following changes are introduced:
        - A read barrier machine op is added to Cmm.
        - The order in which a closure's fields are read and written is changed.
        - Memory barriers are added to RTS code to ensure correctness on
          out-or-order machines with weak memory ordering.
    
    Cmm has a new CallishMachOp called MO_ReadBarrier. On weak memory machines, this
    is lowered to an instruction that ensures memory reads that occur after said
    instruction in program order are not performed before reads coming before said
    instruction in program order. On machines with strong memory ordering properties
    (e.g. X86, SPARC in TSO mode) no such instruction is necessary, so
    MO_ReadBarrier is simply erased. However, such an instruction is necessary on
    weakly ordered machines, e.g. ARM and PowerPC.
    
    Weam memory ordering has consequences for how closures are observed and mutated.
    For example, consider a closure that needs to be upda...
    62e19a6d