@@ -530,18 +530,10 @@ static std::string getDifferentiationParametersClauseString(
530
530
static void printDifferentiableAttrArguments (
531
531
const DifferentiableAttr *attr, ASTPrinter &printer,
532
532
const PrintOptions &Options, const Decl *D, bool omitWrtClause = false ) {
533
- assert (D);
534
533
// Create a temporary string for the attribute argument text.
535
534
std::string attrArgText;
536
535
llvm::raw_string_ostream stream (attrArgText);
537
536
538
- // Get original function.
539
- auto *original = dyn_cast<AbstractFunctionDecl>(D);
540
- // Handle stored/computed properties and subscript methods.
541
- if (auto *asd = dyn_cast<AbstractStorageDecl>(D))
542
- original = asd->getAccessor (AccessorKind::Get);
543
- assert (original && " Must resolve original declaration" );
544
-
545
537
// Print comma if not leading clause.
546
538
bool isLeadingClause = false ;
547
539
auto printCommaIfNecessary = [&] {
@@ -570,6 +562,23 @@ static void printDifferentiableAttrArguments(
570
562
llvm_unreachable (" Impossible case `NonDifferentiable`" );
571
563
}
572
564
565
+ // If the declaration is not available, there is not enough context to print
566
+ // the differentiability parameters or the 'where' clause, so just print the
567
+ // differentiability kind if applicable (when not `Normal`).
568
+ if (!D) {
569
+ if (attr->getDifferentiabilityKind () != DifferentiabilityKind::Normal) {
570
+ printer << ' (' << stream.str () << ' )' ;
571
+ }
572
+ return ;
573
+ }
574
+
575
+ // Get original function.
576
+ auto *original = dyn_cast<AbstractFunctionDecl>(D);
577
+ // Handle stored/computed properties and subscript methods.
578
+ if (auto *asd = dyn_cast<AbstractStorageDecl>(D))
579
+ original = asd->getAccessor (AccessorKind::Get);
580
+ assert (original && " Must resolve original declaration" );
581
+
573
582
// Print differentiation parameters clause, unless it is to be omitted.
574
583
if (!omitWrtClause) {
575
584
auto diffParamsString = getDifferentiationParametersClauseString (
@@ -616,9 +625,7 @@ static void printDifferentiableAttrArguments(
616
625
return ;
617
626
618
627
// Otherwise, print the attribute argument text enclosed in parentheses.
619
- printer << ' (' ;
620
- printer << stream.str ();
621
- printer << ' )' ;
628
+ printer << ' (' << stream.str () << ' )' ;
622
629
}
623
630
624
631
void DeclAttributes::print (ASTPrinter &Printer, const PrintOptions &Options,
0 commit comments