# HG changeset patch # User paulb@localhost.localdomain # Date 1186342720 -7200 # Node ID 90a475a21cc75fd28e6001e7cf92598b461016b2 # Parent aa73f702c9a6143e8d222cbb9844f28948f75eff Turned the Simplifier structures and subprograms attributes into sets. Added a fix_signatures method to the instance fixer in order to get better performance in consolidating specialisations and invocations. diff -r aa73f702c9a6 -r 90a475a21cc7 simplify/__init__.py --- a/simplify/__init__.py Tue Jul 31 01:05:24 2007 +0200 +++ b/simplify/__init__.py Sun Aug 05 21:38:40 2007 +0200 @@ -229,6 +229,8 @@ for module in self.get_modules(): simplify.fixinstances.fix_structures(module) for module in self.get_modules(): + simplify.fixinstances.fix_signatures(module) + for module in self.get_modules(): simplify.fixinstances.fix(module) # vim: tabstop=4 expandtab shiftwidth=4 diff -r aa73f702c9a6 -r 90a475a21cc7 simplify/ast.py --- a/simplify/ast.py Tue Jul 31 01:05:24 2007 +0200 +++ b/simplify/ast.py Sun Aug 05 21:38:40 2007 +0200 @@ -73,8 +73,8 @@ """ Visitor.__init__(self) - self.subprograms = [] # Subprograms outside the tree. - self.structures = [] # Structures/classes. + self.subprograms = set() # Subprograms outside the tree. + self.structures = set() # Structures/classes. self.constants = {} # Constants. self.current_subprograms = [] # Current subprograms being processed. self.current_structures = [] # Current structures being processed. @@ -208,7 +208,8 @@ subprogram.code = results self.current_subprograms.pop() - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram + self.subprograms.add(subprogram) + self.subnames[subprogram.full_name()] = subprogram # Make an invocation of the subprogram. @@ -556,7 +557,8 @@ subprogram.code = results self.current_subprograms.pop() - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram + self.subprograms.add(subprogram) + self.subnames[subprogram.full_name()] = subprogram # Make an invocation of the subprogram. @@ -586,7 +588,7 @@ bases = class_.bases structure = get_class()(name=class_.name, module=self.module, bases=self.dispatches(bases)) - self.structures.append(structure) + self.structures.add(structure) within_class = self.within_class self.within_class = 1 @@ -603,7 +605,8 @@ self.within_class = within_class self.current_structures.pop() self.current_subprograms.pop() - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram + self.subprograms.add(subprogram) + self.subnames[subprogram.full_name()] = subprogram # Make a definition of the class associating it with a name. @@ -759,7 +762,8 @@ subprogram.code = results self.current_subprograms.pop() - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram + self.subprograms.add(subprogram) + self.subnames[subprogram.full_name()] = subprogram # Make an invocation of the subprogram. @@ -885,7 +889,8 @@ # Finish the subprogram definition. self.current_subprograms.pop() - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram + self.subprograms.add(subprogram) + self.subnames[subprogram.full_name()] = subprogram # Obtain an iterator for the sequence involved. # Then, make an invocation of the subprogram. @@ -994,7 +999,8 @@ subprogram.params = params subprogram.star = star subprogram.dstar = dstar - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram + self.subprograms.add(subprogram) + self.subnames[subprogram.full_name()] = subprogram def visitFunction(self, function): @@ -1185,7 +1191,8 @@ ) self.current_subprograms.pop() - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram + self.subprograms.add(subprogram) + self.subnames[subprogram.full_name()] = subprogram # Make an invocation of the subprogram. @@ -1229,7 +1236,8 @@ ] self.current_subprograms.pop() - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram + self.subprograms.add(subprogram) + self.subnames[subprogram.full_name()] = subprogram # Make an invocation of the subprogram. @@ -1365,7 +1373,8 @@ subprogram.code = results self.current_subprograms.pop() - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram + self.subprograms.add(subprogram) + self.subnames[subprogram.full_name()] = subprogram # Make an invocation of the subprogram. @@ -1722,7 +1731,8 @@ subprogram.code = [test] self.current_subprograms.pop() - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram + self.subprograms.add(subprogram) + self.subnames[subprogram.full_name()] = subprogram # Make an invocation of the subprogram. @@ -1836,7 +1846,8 @@ ] self.current_subprograms.pop() - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram + self.subprograms.add(subprogram) + self.subnames[subprogram.full_name()] = subprogram result = InvokeRef( binary, @@ -1907,7 +1918,8 @@ ] self.current_subprograms.pop() - self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram + self.subprograms.add(subprogram) + self.subnames[subprogram.full_name()] = subprogram result = InvokeRef( binary, diff -r aa73f702c9a6 -r 90a475a21cc7 simplify/fixinstances.py --- a/simplify/fixinstances.py Tue Jul 31 01:05:24 2007 +0200 +++ b/simplify/fixinstances.py Sun Aug 05 21:38:40 2007 +0200 @@ -109,6 +109,18 @@ for name, attrs in instance.namespace.items(): instance.namespace[name] = self._replace(attrs) + def process_signatures(self, module): + + "Process the signatures of subprograms in this 'module'." + + self.module = module + + # Visit each subprogram, updating the signatures. + + for subprogram in self.module.simplifier.subprograms: + for specialisation in subprogram.active(): + self._replace_dict(specialisation, "paramtypes") + def process_node(self, node): """ @@ -148,15 +160,10 @@ for name in ("non_accesses", "non_writes", "raises", "returns", "types", "invocations"): if hasattr(node, name): - attrs = getattr(node, name) - setattr(node, name, self._replace(attrs, name)) + self._replace_list(node, name) for name in ("accesses", "writes", "paramtypes"): if hasattr(node, name): - d = getattr(node, name) - new_d = {} - for expr, attrs in d.items(): - new_d[self._get_replacement(expr)] = self._replace(attrs, name) - setattr(node, name, new_d) + self._replace_dict(node, name) # Visit program nodes. @@ -182,6 +189,17 @@ return node + def _replace_list(self, node, name): + attrs = getattr(node, name) + setattr(node, name, self._replace(attrs, name)) + + def _replace_dict(self, node, name): + d = getattr(node, name) + new_d = {} + for expr, attrs in d.items(): + new_d[self._get_replacement(expr)] = self._replace(attrs, name) + setattr(node, name, new_d) + def _replace(self, items, name=None): """ @@ -265,6 +283,13 @@ fixer = Fixer() fixer.process_structures(module) +def fix_signatures(module): + + "Fix the signatures in the given 'module'." + + fixer = Fixer() + fixer.process_signatures(module) + def fix(module): "Fix the structure references in the given 'module'."