From 939f188e27403dd359fcb5fa573726e61284a7df Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Fri, 28 Jul 2017 14:45:56 -0700 Subject: [PATCH] Add an inst.all_typevars() method. Get all type variables controlling an instruction, whether it is polymorphic or not. --- lib/cretonne/meta/cdsl/instructions.py | 10 ++++++++++ lib/cretonne/meta/cdsl/ti.py | 6 +----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/cretonne/meta/cdsl/instructions.py b/lib/cretonne/meta/cdsl/instructions.py index 6dec0b7dff..30c27c6649 100644 --- a/lib/cretonne/meta/cdsl/instructions.py +++ b/lib/cretonne/meta/cdsl/instructions.py @@ -267,6 +267,16 @@ class Instruction(object): return other_tvs + def all_typevars(self): + # type: () -> List[TypeVar] + """ + Get a list of all type variables in the instruction. + """ + if self.is_polymorphic: + return [self.ctrl_typevar] + self.other_typevars + else: + return [] + @staticmethod def _to_operand_tuple(x): # type: (Union[Sequence[Operand], Operand]) -> Tuple[Operand, ...] diff --git a/lib/cretonne/meta/cdsl/ti.py b/lib/cretonne/meta/cdsl/ti.py index 028579857d..b2673366be 100644 --- a/lib/cretonne/meta/cdsl/ti.py +++ b/lib/cretonne/meta/cdsl/ti.py @@ -796,11 +796,7 @@ def ti_def(definition, typ): # Create a dict m mapping each free typevar in the signature of definition # to a fresh copy of itself. - if inst.is_polymorphic: - free_formal_tvs = [inst.ctrl_typevar] + inst.other_typevars - else: - free_formal_tvs = [] - + free_formal_tvs = inst.all_typevars() m = {tv: tv.get_fresh_copy(str(typ.get_uid())) for tv in free_formal_tvs} # Update m with any explicitly bound type vars