@@ -530,18 +530,10 @@ static std::string getDifferentiationParametersClauseString(
530530static void printDifferentiableAttrArguments (
531531 const DifferentiableAttr *attr, ASTPrinter &printer,
532532 const PrintOptions &Options, const Decl *D, bool omitWrtClause = false ) {
533- assert (D);
534533 // Create a temporary string for the attribute argument text.
535534 std::string attrArgText;
536535 llvm::raw_string_ostream stream (attrArgText);
537536
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-
545537 // Print comma if not leading clause.
546538 bool isLeadingClause = false ;
547539 auto printCommaIfNecessary = [&] {
@@ -570,6 +562,23 @@ static void printDifferentiableAttrArguments(
570562 llvm_unreachable (" Impossible case `NonDifferentiable`" );
571563 }
572564
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+
573582 // Print differentiation parameters clause, unless it is to be omitted.
574583 if (!omitWrtClause) {
575584 auto diffParamsString = getDifferentiationParametersClauseString (
@@ -616,9 +625,7 @@ static void printDifferentiableAttrArguments(
616625 return ;
617626
618627 // Otherwise, print the attribute argument text enclosed in parentheses.
619- printer << ' (' ;
620- printer << stream.str ();
621- printer << ' )' ;
628+ printer << ' (' << stream.str () << ' )' ;
622629}
623630
624631void DeclAttributes::print (ASTPrinter &Printer, const PrintOptions &Options,
0 commit comments