Optimise indirection when getting the 'eq' or 'show' closure

Bug #1205796 reported by Matt Giuca
6
This bug affects 1 person
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:eq:ref(dict:a)
    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:eq:ref(dict:a)

Related branches

Revision history for this message
Matt Giuca (mgiuca) wrote :

Fixed in trunk r1352.

Changed in mars:
milestone: none → 0.4
status: Triaged → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.