@@ -68,6 +68,12 @@ template <typename T> static inline void debugDump(T &v) {
68
68
<< v << " \n ==== END DEBUG DUMP ====\n " );
69
69
}
70
70
71
+ static bool isInLLDBREPL (SILModule &module ) {
72
+ llvm::StringRef module_name = module .getSwiftModule ()->getNameStr ();
73
+ // TODO(SR-9704): Use a more prinicpled way to do this check.
74
+ return module_name.startswith (" __lldb_expr_" );
75
+ }
76
+
71
77
// / Creates arguments in the entry block based on the function type.
72
78
static void createEntryArguments (SILFunction *f) {
73
79
auto *entry = f->getEntryBlock ();
@@ -1651,12 +1657,21 @@ emitAssociatedFunctionReference(ADContext &context, SILBuilder &builder,
1651
1657
context.lookUpMinimalDifferentiationTask (originalFn, desiredIndices);
1652
1658
if (!task) {
1653
1659
if (originalFn->isExternalDeclaration ()) {
1654
- context.emitNondifferentiabilityError (original, parentTask,
1655
- diag::autodiff_external_nondifferentiable_function);
1656
- return None;
1660
+ // For lldb repl, we should attempt to load the function as
1661
+ // this may be defined in a different cell.
1662
+ if (isInLLDBREPL (*original->getModule ())) {
1663
+ original->getModule ()->loadFunction (originalFn);
1664
+ }
1665
+ // If we still don't have the definition, generate an error message.
1666
+ if (!originalFn->isDefinition ()) {
1667
+ context.emitNondifferentiabilityError (
1668
+ original, parentTask,
1669
+ diag::autodiff_external_nondifferentiable_function);
1670
+ return None;
1671
+ }
1657
1672
}
1658
- task = context.registerDifferentiationTask (
1659
- originalFn, desiredIndices, invoker);
1673
+ task = context.registerDifferentiationTask (originalFn, desiredIndices,
1674
+ invoker);
1660
1675
}
1661
1676
assert (task);
1662
1677
taskCallback (task);
0 commit comments