def on_attach(self, env): #boilerplate from old implementation if self.env is not None: raise Exception( "A DestroyHandler instance can only serve one Env.") for attr in ('destroyers', 'destroy_handler'): if hasattr(env, attr): raise toolbox.AlreadyThere( "DestroyHandler feature is already present or in conflict with another plugin." ) def get_destroyers_of(r): droot, impact, root_destroyer = self.refresh_droot_impact() try: return [root_destroyer[droot[r]]] except Exception: return [] env.destroyers = get_destroyers_of env.destroy_handler = self self.env = env self.destroyers = set( ) #set of Apply instances with non-null destroy_map self.view_i = {} # variable -> variable used in calculation self.view_o = { } # variable -> set of variables that use this one as a direct input #clients: how many times does an apply use a given variable self.clients = {} # variable -> apply -> ninputs self.stale_droot = True self.debug_all_apps = set() if self.do_imports_on_attach: toolbox.Bookkeeper.on_attach(self, env)
def on_attach(self, fgraph): """ When attaching to a new fgraph, check that 1) This DestroyHandler wasn't already attached to some fgraph (its data structures are only set up to serve one) 2) The FunctionGraph doesn't already have a DestroyHandler. This would result in it validating everything twice, causing compilation to be slower. Give the FunctionGraph instance: 1) A new method "destroyers(var)" TODO: what does this do exactly? 2) A new attribute, "destroy_handler" TODO: WRITEME: what does this do besides the checks? """ ####### Do the checking ########### already_there = False if self.fgraph is fgraph: already_there = True if self.fgraph is not None: raise Exception( "A DestroyHandler instance can only serve one FunctionGraph. (Matthew 6:24)" ) for attr in ('destroyers', 'destroy_handler'): if hasattr(fgraph, attr): already_there = True if already_there: # FunctionGraph.attach_feature catches AlreadyThere and cancels the attachment raise toolbox.AlreadyThere( "DestroyHandler feature is already present or in conflict with another plugin." ) ####### Annotate the FunctionGraph ############ def get_destroyers_of(r): droot, impact, root_destroyer = self.refresh_droot_impact() try: return [root_destroyer[droot[r]]] except Exception: return [] fgraph.destroyers = get_destroyers_of fgraph.destroy_handler = self self.fgraph = fgraph self.destroyers = set( ) #set of Apply instances with non-null destroy_map self.view_i = {} # variable -> variable used in calculation self.view_o = { } # variable -> set of variables that use this one as a direct input #clients: how many times does an apply use a given variable self.clients = {} # variable -> apply -> ninputs self.stale_droot = True self.debug_all_apps = set() if self.do_imports_on_attach: toolbox.Bookkeeper.on_attach(self, fgraph)
def on_attach(self, fgraph): """ When attaching to a new fgraph, check that 1) This DestroyHandler wasn't already attached to some fgraph (its data structures are only set up to serve one) 2) The FunctionGraph doesn't already have a DestroyHandler. This would result in it validating everything twice, causing compilation to be slower. TODO: WRITEME: what does this do besides the checks? """ ####### Do the checking ########### already_there = False if self.fgraph is fgraph: already_there = True if self.fgraph not in [None, fgraph]: raise Exception("A DestroyHandler instance can only serve" " one FunctionGraph. (Matthew 6:24)") for attr in ('destroyers', 'destroy_handler'): if hasattr(fgraph, attr): already_there = True if already_there: # FunctionGraph.attach_feature catches AlreadyThere # and cancels the attachment raise toolbox.AlreadyThere( "DestroyHandler feature is already present or in" " conflict with another plugin.") ####### end of checking ############ def get_destroyers_of(r): droot, impact, root_destroyer = self.refresh_droot_impact() try: return [root_destroyer[droot[r]]] except Exception: return [] fgraph.destroyers = get_destroyers_of fgraph.destroy_handler = self self.fgraph = fgraph self.destroyers = OrderedSet() # set of Apply instances with non-null destroy_map self.view_i = {} # variable -> variable used in calculation self.view_o = {} # variable -> set of variables that use this one as a direct input # clients: how many times does an apply use a given variable self.clients = {} # variable -> apply -> ninputs self.stale_droot = True # IG: It's unclear if this is meant to be included in deployed code. It looks like # it is unnecessary if FunctionGraph is working correctly, so I am commenting uses # of it (for speed) but leaving the commented code in place so it is easy to restore # for debugging purposes. # Note: is there anything like the C preprocessor for python? It would be useful to # just ifdef these things out # self.debug_all_apps = set() if self.do_imports_on_attach: toolbox.Bookkeeper.on_attach(self, fgraph)