Optimise indirection when getting the 'eq' or 'show' closure
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Mars |
Fix Committed
|
Wishlist
|
Matt Giuca |
Bug Description
When the 'eq' or 'show' functions are referenced, but not directly called, a new closure template is generated. This extra indirection is inefficient. For example, consider this code:
def get_eq() :: (a, a) -> Num:
return eq
This generates the following Mars assembly code:
def get_eq(dict:a :: :Dict(a)) :: (a, a) -> Num:
r = @ct:eq{dict:a}
def ct:eq{dict:a :: :Dict(a)}(x :: a, y :: a) :: Num:
t = @:Dict:
r = t(x, y)
The value you get back from calling get_eq() is not the eq function for a -- it is a closure carrying around the type dict for a which, when called, looks up the eq function for a and calls it. This is more indirect than necessary. It should generate the following code:
def get_eq(dict:a :: :Dict(a)) :: (a, a) -> Num:
r = @:Dict:
Fixed in trunk r1352.