Opened 12 months ago

Last modified 12 months ago

#15698 new task

SingleEntry update flag for Stg bindings is not used

Reported by: osa1 Owned by:
Priority: lowest Milestone: 8.6.1
Component: Compiler Version: 8.6.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

I was looking at code generation for bindings with different update flags. Update flag type is defined as:

data UpdateFlag = ReEntrant | Updatable | SingleEntry

I realized that we don't care about the difference between ReEntrant and SingleEntry, we only care about whether a binding is updatable or not, which is defined as

isUpdatable :: UpdateFlag -> Bool
isUpdatable ReEntrant   = False
isUpdatable SingleEntry = False
isUpdatable Updatable   = True

So we could remove SingleEntry and replace all uses of it with ReEntrant and everything would work the same.

This raises the question of whether we're missing an optimisation in the code generator. Looking at code generation differences of updatable and non-updatable bindings, it seems like for a thunk (a binding with no arguments) we generate a thunk header and push an update frame regardless of the update flag. As far as I can see, update flag is only used when generating AP and selector thunks (we don't generate AP or selector thunks if the binding is not updatable).

My question is: it seems to me that if a thunk is single entry then we should be able to give it a non-thunk type (maybe FUN?) and avoid pushing an update frame in closureCodeBody. Am I missing anything or is this possible? Is this worth trying?

Change History (1)

comment:1 Changed 12 months ago by simonpj

it seems like for a thunk (a binding with no arguments) we generate a thunk header and push an update frame regardless of the update flag

I don't think so. See

setupUpdate closure_info node body
  | not (lfUpdatable (closureLFInfo closure_info))
  = body

That is, it's a no-op if the thunk is non-updatable (single-entry).

Note: See TracTickets for help on using tickets.