Skip to content
  • niteria's avatar
    Make type-class dictionary let binds deterministic · a5cb27f3
    niteria authored and Ben Gamari's avatar Ben Gamari committed
    When generating dictionary let binds in dsTcEvBinds we may
    end up generating them in arbitrary order according to Unique order.
    
    Consider:
    
    ```
    let $dEq = GHC.Classes.$fEqInt in
    let $$dNum = GHC.Num.$fNumInt in ...
    ```
    
    vs
    
    ```
    let $dNum = GHC.Num.$fNumInt in
    let $dEq = GHC.Classes.$fEqInt in ...
    ```
    
    The way this change fixes it is by using `UniqDFM` - a type of
    deterministic finite maps of things keyed on `Unique`s. This way when
    you pull out evidence variables corresponding to type-class dictionaries
    they are in deterministic order.
    
    Currently it's the order of insertion and the way it's implemented is by
    tagging the values with the time of insertion.
    
    Test Plan:
    I've added a new test case to reproduce the issue.
    ./validate
    
    Reviewers: ezyang, simonmar, austin, simonpj, bgamari
    
    Reviewed By: simonmar, simonpj, bgamari
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D1396
    
    GHC Trac Issues: #4012
    a5cb27f3