Skip to content

Commit 4344db8

Browse files
committed
Ensure that we accurately compute our external function dependencies.
It was possible to not have a reference to an 'external used function' after execution native_ast_to_llvm conversion because some code pathways don't get exercised. The linker downstream cannot now this, and would complain if the value wasn't present.
1 parent 0518886 commit 4344db8

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

typed_python/compiler/native_compiler/native_ast_to_llvm.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from typed_python.compiler.native_compiler.module_definition import ModuleDefinition
1616
from typed_python.compiler.native_compiler.typed_llvm_value import TypedLLVMValue
17+
from typed_python.compiler.native_compiler.native_ast_analysis import extractNamedCallTargets
1718
from typed_python.compiler.native_compiler.native_ast_to_llvm_function_converter import (
1819
type_to_llvm_type,
1920
FunctionConverter,
@@ -292,7 +293,6 @@ def add_functions(self, names_to_definitions):
292293

293294
globalDefinitions = {}
294295
globalDefinitionsLlvmValues = {}
295-
usedExternalFunctions = set()
296296

297297
while names_to_definitions:
298298
for name in sorted(names_to_definitions):
@@ -322,8 +322,7 @@ def add_functions(self, names_to_definitions):
322322
builder,
323323
arg_assignments,
324324
definition.output_type,
325-
external_function_references,
326-
usedExternalFunctions
325+
external_function_references
327326
)
328327

329328
func_converter.setup()
@@ -367,6 +366,15 @@ def add_functions(self, names_to_definitions):
367366
args=[native_ast.Void.pointer().pointer()]
368367
)
369368

369+
usedExternalFunctions = [
370+
callTarget.name for callTarget in extractNamedCallTargets(functionsDefinedHere)
371+
if not callTarget.external and callTarget.name not in functionsDefinedHere
372+
]
373+
374+
for name in usedExternalFunctions:
375+
if name not in self._function_definitions:
376+
raise Exception(f"Somehow we depend on {name} but have no definition for it")
377+
370378
return ModuleDefinition(
371379
str(module),
372380
functionTypes,

typed_python/compiler/native_compiler/native_ast_to_llvm_function_converter.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,7 @@ def __init__(self,
567567
builder,
568568
arg_assignments,
569569
output_type,
570-
external_function_references,
571-
usedExternalFunctions
570+
external_function_references
572571
):
573572
self.function = function
574573

@@ -582,7 +581,6 @@ def __init__(self,
582581
self.arg_assignments = arg_assignments
583582
self.output_type = output_type
584583
self.external_function_references = external_function_references
585-
self.usedExternalFunctions = usedExternalFunctions
586584
self.tags_initialized = {}
587585
self.stack_slots = {}
588586

@@ -722,9 +720,6 @@ def namedCallTargetToLLVM(self, target):
722720
):
723721
func = self.converter.repeatFunctionInModule(target.name, self.module)
724722
else:
725-
# this function is defined in another module.
726-
self.usedExternalFunctions.add(target.name)
727-
728723
if target.name not in self.external_function_references:
729724
self.external_function_references[target.name] = \
730725
llvmlite.ir.Function(self.module, func.function_type, func.name)

0 commit comments

Comments
 (0)