Skip to content

Commit

Permalink
compiler.embedding: rename user-defined types with identical names.
Browse files Browse the repository at this point in the history
Fixes #478.
whitequark committed Jun 22, 2016
1 parent 33e8e59 commit 21574bd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions artiq/compiler/embedding.py
Original file line number Diff line number Diff line change
@@ -63,6 +63,7 @@ def has_module(self, module):

# Types
def store_type(self, host_type, instance_type, constructor_type):
self._rename_type(instance_type)
self.type_map[host_type] = (instance_type, constructor_type)

def retrieve_type(self, host_type):
@@ -71,6 +72,22 @@ def retrieve_type(self, host_type):
def has_type(self, host_type):
return host_type in self.type_map

def _rename_type(self, new_instance_type):
# Generally, user-defined types that have exact same name (which is to say, classes
# defined inside functions) do not pose a problem to the compiler. The two places which
# cannot handle this are:
# 1. {TInstance,TConstructor}.__hash__
# 2. LLVM type names
# Since handling #2 requires renaming on ARTIQ side anyway, it's more straightforward
# to do it once when embedding (since non-embedded code cannot define classes in
# functions). Also, easier to debug.
n = 0
for host_type in self.type_map:
instance_type, constructor_type = self.type_map[host_type]
if instance_type.name == new_instance_type.name:
n += 1
new_instance_type.name = "{}.{}".format(new_instance_type.name, n)

# Functions
def store_function(self, function, ir_function_name):
self.function_map[function] = ir_function_name

0 comments on commit 21574bd

Please sign in to comment.