Skip to content

Commit a1705e0

Browse files
committed
Runtime prints outbound function dependencies in verbose mode.
1 parent f503fc7 commit a1705e0

File tree

7 files changed

+37
-11
lines changed

7 files changed

+37
-11
lines changed

typed_python/compiler/python_to_native_converter.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,11 @@ def _installInflightFunctions(self, name):
925925

926926
nativeFunction, actual_output_type = self._inflight_definitions.get(identifier)
927927

928+
outboundTargets = []
929+
for outboundFuncId in self._dependencies.getNamesDependedOn(identifier):
930+
name = self._link_name_for_identity[outboundFuncId]
931+
outboundTargets.append(self._targets[name])
932+
928933
try:
929934
v.onNewFunction(
930935
identifier,
@@ -938,7 +943,8 @@ def _installInflightFunctions(self, name):
938943
functionConverter._varname_to_type.get(FunctionOutput),
939944
functionConverter._varname_to_type.get(FunctionYield),
940945
{k: v.typeRepresentation for k, v in functionConverter._varname_to_type.items() if isinstance(k, str)},
941-
conversionType
946+
conversionType,
947+
outboundTargets
942948
)
943949
except Exception:
944950
logging.exception("event handler %s threw an unexpected exception", v.onNewFunction)

typed_python/compiler/runtime.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def onNewFunction(
5656
outputType,
5757
yieldType,
5858
variableTypes,
59-
conversionType
59+
conversionType,
60+
calledFunctions,
6061
):
6162
pass
6263

@@ -96,7 +97,8 @@ def onNewFunction(
9697
outputType,
9798
yieldType,
9899
variableTypes,
99-
conversionType
100+
conversionType,
101+
calledFunctions,
100102
):
101103
if self.short:
102104
print(
@@ -127,6 +129,11 @@ def onNewFunction(
127129
else:
128130
print(" ", varname, varVal)
129131

132+
if calledFunctions:
133+
print(" calls:")
134+
for callTarget in calledFunctions:
135+
print(" ", callTarget)
136+
130137

131138
class CountCompilationsVisitor(RuntimeEventVisitor):
132139
def __init__(self):
@@ -145,7 +152,8 @@ def onNewFunction(
145152
outputType,
146153
yieldType,
147154
variableTypes,
148-
conversionType
155+
conversionType,
156+
calledFunctions,
149157
):
150158
self.count += 1
151159

typed_python/compiler/tests/closures_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def onNewFunction(
5252
outputType,
5353
yieldType,
5454
variableTypes,
55-
conversionType
55+
conversionType,
56+
calledFunctions,
5657
):
5758
self.didCompile = True
5859

typed_python/compiler/tests/conversion_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ def onNewFunction(
8989
outputType,
9090
yieldType,
9191
variableTypes,
92-
conversionType
92+
conversionType,
93+
calledFunctions,
9394
):
9495
self.types[funcName] = makeNamedTuple(
9596
inputTypes=inputTypes,
@@ -1405,7 +1406,8 @@ def onNewFunction(
14051406
outputType,
14061407
yieldType,
14071408
variableTypes,
1408-
conversionType
1409+
conversionType,
1410+
calledFunctions,
14091411
):
14101412
assert issubclass(outputType.typeRepresentation, Type)
14111413

typed_python/compiler/tests/entrypoint_test.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,20 +422,27 @@ def onNewFunction(
422422
outputType,
423423
yieldType,
424424
variableTypes,
425-
conversionType
425+
conversionType,
426+
calledFunctions,
426427
):
427-
out[funcName] = (inputTypes, outputType, variableTypes)
428+
out[funcName] = (inputTypes, outputType, variableTypes, calledFunctions)
429+
430+
@Entrypoint
431+
def g(x):
432+
return x
428433

429434
@Entrypoint
430435
def f(x):
431-
y = x + 1
436+
y = x + g(1)
432437
return str(y)
433438

434439
with Visitor():
435440
f.resultTypeFor(int)
436441

437442
self.assertTrue('f' in out, out)
438443
self.assertEqual(out['f'][2]['y'], int)
444+
self.assertTrue(out['f'][3])
445+
assert type(out['f'][3][0]).__name__ == 'TypedCallTarget'
439446

440447
def test_star_args_on_entrypoint(self):
441448
@Entrypoint

typed_python/compiler/type_wrappers/alternative_wrapper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ def convert_attribute(self, context, instance, attribute, nocheck=False):
355355
return self.convert_method_call(context, instance, "__getattr__", (context.constant(attribute),), {})
356356

357357
return super().convert_attribute(context, instance, attribute)
358+
358359
if len(validIndices) == 1:
359360
with context.ifelse(instance.nonref_expr.ElementPtrIntegers(0, 1).load().neq(validIndices[0])) as (then, otherwise):
360361
with then:

typed_python/type_function_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ def onNewFunction(
360360
outputType,
361361
yieldType,
362362
variableTypes,
363-
conversionType
363+
conversionType,
364+
calledFunctions,
364365
):
365366
if funcName == "do":
366367
self.variableTypes = variableTypes

0 commit comments

Comments
 (0)