Repository: apple/swift
File: lib/SILGen/SILGenLazyConformance.cpp (C++)

Code before:

using namespace swift;
using namespace swift::Lowering;

void SILGenModule::useConformance(SILInstruction *inst,
                                  ProtocolConformanceRef conformanceRef) {
  // If the conformance is invalid, crash deterministically even in noassert
  // builds.
  if (conformanceRef.isInvalid()) {
    // When lazy type checking is enabled, a conformance may only be diagnosed
    // as invalid during SILGen. Ignore it instead of asserting.
    auto &ctx = getASTContext();
    if (ctx.TypeCheckerOpts.EnableLazyTypecheck && ctx.hadError())
      return;

    llvm::errs() << "Found an invalid conformance in SILGen. This may indicate a problem in ";
    llvm::errs() << "Sema or the ClangImporter.\n";

    if (inst != nullptr) {
      llvm::errs() << "\n";
      llvm::errs() << "Emitting lazy conformances for instruction:\n";
      inst->print(llvm::errs());
      llvm::errs() << "\n";
      llvm::errs() << "In function:\n";
      inst->getFunction()->print(llvm::errs());
      llvm::errs() << "\n";
    }

    abort();
  }

  // We don't need to emit dependent conformances.
  if (conformanceRef.isAbstract())
    return;

  // Recursively visit pack conformances.
  if (conformanceRef.isPack()) {
    auto *packConformance = conformanceRef.getPack();

    for (auto patternConformanceRef : packConformance->getPatternConformances())
      useConformance(inst, patternConformanceRef);

    return;
  }

  auto conformance = conformanceRef.getConcrete();

  // Always look through inherited conformances.
  if (auto *inherited = dyn_cast<InheritedProtocolConformance>(conformance))
    conformance = inherited->getInheritedConformance();


Review comment (bug):
Can you use `ABORT` instead here? e.g

```cxx
ABORT([&](auto &out) {
  out << "logging"
})
```

That way the message also is picked up by the crash reporter

Code after:

using namespace swift;
using namespace swift::Lowering;

void SILGenModule::useConformance(SILInstruction *inst,
                                  ProtocolConformanceRef conformanceRef) {
  // If the conformance is invalid, crash deterministically even in noassert
  // builds.
  if (conformanceRef.isInvalid()) {
    // When lazy type checking is enabled, a conformance may only be diagnosed
    // as invalid during SILGen. Ignore it instead of asserting.
    auto &ctx = getASTContext();
    if (ctx.TypeCheckerOpts.EnableLazyTypecheck && ctx.hadError())
      return;

    ABORT([&](auto &out) {
      out << "Found an invalid conformance in SILGen. This may indicate a problem in ";
      out << "Sema or the ClangImporter.\n";

      if (inst != nullptr) {
        out << "\n";
        out << "Emitting lazy conformances for instruction:\n";
        inst->print(out);
        out << "\n";
        out << "In function:\n";
        inst->getFunction()->print(out);
        out << "\n";
      }
    });
  }

  // We don't need to emit dependent conformances.
  if (conformanceRef.isAbstract())
    return;

  // Recursively visit pack conformances.
  if (conformanceRef.isPack()) {
    auto *packConformance = conformanceRef.getPack();

    for (auto patternConformanceRef : packConformance->getPatternConformances())
      useConformance(inst, patternConformanceRef);

    return;
  }

  auto conformance = conformanceRef.getConcrete();

  // Always look through inherited conformances.
  if (auto *inherited = dyn_cast<InheritedProtocolConformance>(conformance))
    conformance = inherited->getInheritedConformance();