Skip to content
  • Matthew Pickering's avatar
    7698a505
    typechecker: Perform type family consistency checks in topological order · 7698a505
    Matthew Pickering authored and Marge Bot's avatar Marge Bot committed
    Consider a module M importing modules A, B and C.
    
    We can waste a lot of work depending on the order that the modules are
    checked for family consistency.
    
    Consider that C imports A and B. When compiling C we must have already
    checked A and B for consistency, therefore if C is processed first then
    A and B will not need to be checked for consistency again.
    
    If A and B are compared first, then the consistency checks will be
    performed against (wasted as we already performed them for C).
    
    At the moment the order which modules are checked is non-deterministic.
    
    Clearly we should engineer that C is checked before B and A, but by what
    scheme?
    
    A simple one is to observe that if a module M is in the transitive
    closure of X then the size of the consistent family set of M is less
    than or equal to size of the consistent family set of X.
    
    Therefore by sorting the imports by the size of the consistent family
    set and processing the largest first, you make sure to process modules
    in topological order.
    
    In practice we have observed that this strategy has reduced the amount
    of consistency checks performed.
    
    One solution to #25554
    7698a505
    typechecker: Perform type family consistency checks in topological order
    Matthew Pickering authored and Marge Bot's avatar Marge Bot committed
    Consider a module M importing modules A, B and C.
    
    We can waste a lot of work depending on the order that the modules are
    checked for family consistency.
    
    Consider that C imports A and B. When compiling C we must have already
    checked A and B for consistency, therefore if C is processed first then
    A and B will not need to be checked for consistency again.
    
    If A and B are compared first, then the consistency checks will be
    performed against (wasted as we already performed them for C).
    
    At the moment the order which modules are checked is non-deterministic.
    
    Clearly we should engineer that C is checked before B and A, but by what
    scheme?
    
    A simple one is to observe that if a module M is in the transitive
    closure of X then the size of the consistent family set of M is less
    than or equal to size of the consistent family set of X.
    
    Therefore by sorting the imports by the size of the consistent family
    set and processing the largest first, you make sure to process modules
    in topological order.
    
    In practice we have observed that this strategy has reduced the amount
    of consistency checks performed.
    
    One solution to #25554
Loading