Repository: apple/swift
File: include/swift/SIL/SILWitnessVisitor.h (C/C++)

Code before:
        addAutoDiffDerivativeMethodsIfRequired(accessor,
                                               SILDeclRef::Kind::Func);
        addDistributedWitnessMethodsIfRequired(accessor,
                                               SILDeclRef::Kind::Func);
      }
    });
  }

  void visitConstructorDecl(ConstructorDecl *cd) {
    if (cd->requiresNewWitnessTableEntry()) {
      asDerived().addMethod(SILDeclRef(cd, SILDeclRef::Kind::Allocator));
      addAutoDiffDerivativeMethodsIfRequired(cd, SILDeclRef::Kind::Allocator);
    }
  }

  void visitAccessorDecl(AccessorDecl *func) {
    // Accessors are emitted by visitAbstractStorageDecl, above.
  }

  void visitFuncDecl(FuncDecl *func) {
    assert(!isa<AccessorDecl>(func));
    if (!func->requiresNewWitnessTableEntry())
      return;

    // Unreachable functions (with custom availability) should not generate
    // witness entries
    for (auto *attr : func->getAttrs().getAttributes<AvailableAttr>()) {
      if (auto domain = attr->getDomainOrIdentifier().getAsDomain()) {
        if (domain->isCustom() &&
            domain->getCustomDomain()->getKind() ==
                CustomAvailabilityDomain::Kind::Disabled) {
          return;
        }
      }
    }

    asDerived().addMethod(SILDeclRef(func, SILDeclRef::Kind::Func));
    addAutoDiffDerivativeMethodsIfRequired(func, SILDeclRef::Kind::Func);
    addDistributedWitnessMethodsIfRequired(func, SILDeclRef::Kind::Func);
  }

  void visitMissingMemberDecl(MissingMemberDecl *placeholder) {
    asDerived().addPlaceholder(placeholder);
  }

  void visitAssociatedTypeDecl(AssociatedTypeDecl *td) {
    // We already visited these in the first pass.
  }

  void visitTypeAliasDecl(TypeAliasDecl *tad) {
    // We don't care about these by themselves for witnesses.

Review comment (bug):
Could you file a radar about that we can't use `func->isUnreachableAtRuntime()` here because it triggers test failure in `availability_unavailable_protocol_witness.swift‎`? In the source code here, add a `FIXME:` with that associated radar number. 

Code after:
        addAutoDiffDerivativeMethodsIfRequired(accessor,
                                               SILDeclRef::Kind::Func);
        addDistributedWitnessMethodsIfRequired(accessor,
                                               SILDeclRef::Kind::Func);
      }
    });
  }

  void visitConstructorDecl(ConstructorDecl *cd) {
    if (cd->requiresNewWitnessTableEntry()) {
      asDerived().addMethod(SILDeclRef(cd, SILDeclRef::Kind::Allocator));
      addAutoDiffDerivativeMethodsIfRequired(cd, SILDeclRef::Kind::Allocator);
    }
  }

  void visitAccessorDecl(AccessorDecl *func) {
    // Accessors are emitted by visitAbstractStorageDecl, above.
  }

  void visitFuncDecl(FuncDecl *func) {
    assert(!isa<AccessorDecl>(func));
    if (!func->requiresNewWitnessTableEntry())
      return;

    // Unreachable functions (with custom availability) should not generate
    // witness entries
    // FIXME: cannot use func->isUnreachableAtRuntime() here rdar://170184865
    for (auto *attr : func->getAttrs().getAttributes<AvailableAttr>()) {
      if (auto domain = attr->getDomainOrIdentifier().getAsDomain()) {
        if (domain->isCustom() &&
            domain->getCustomDomain()->getKind() ==
                CustomAvailabilityDomain::Kind::Disabled) {
          return;
        }
      }
    }

    asDerived().addMethod(SILDeclRef(func, SILDeclRef::Kind::Func));
    addAutoDiffDerivativeMethodsIfRequired(func, SILDeclRef::Kind::Func);
    addDistributedWitnessMethodsIfRequired(func, SILDeclRef::Kind::Func);
  }

  void visitMissingMemberDecl(MissingMemberDecl *placeholder) {
    asDerived().addPlaceholder(placeholder);
  }

  void visitAssociatedTypeDecl(AssociatedTypeDecl *td) {
    // We already visited these in the first pass.
  }

  void visitTypeAliasDecl(TypeAliasDecl *tad) {