Repository: apple/swift
File: lib/IRGen/IRGenDebugInfo.cpp (C++)

Code before:
          // This is (bridging header) PCH.
          Scope = getOrCreateModule(*SubModuleDesc, nullptr);
      }
    }
    if (!Scope)
      Scope = getOrCreateContext(Context);

    // Scope outermost fileprivate decls in an inline private discriminator
    // namespace.
    //
    // We need to don't do this for decls imported from Clang modules because
    // the scopes of C/C++ symbols are not restricted to a particular file unit.
    if (auto *Decl = DbgTy.getDecl())
      if (Decl->isOutermostPrivateOrFilePrivateScope() &&
          !isa<ClangModuleUnit>(
              Decl->getDeclContext()->getModuleScopeContext()))
        Scope = getFilePrivateScope(Scope, Decl);

    return Scope;
  }

  static bool isExistentialTypeAlias(DebugTypeInfo DbgTy) {
    TypeBase *BaseTy = DbgTy.getType();
    if (BaseTy->getKind() != TypeKind::Existential)
      return false;
    auto *ExistentialTy = BaseTy->castTo<ExistentialType>();
    Type ConstraintTy = ExistentialTy->getConstraintType();
    TypeBase *TyPtr = ConstraintTy.getPointer();
    if (TyPtr->getKind() != TypeKind::TypeAlias)
      return false;
    return true;
  }

  llvm::DIType *getOrCreateType(DebugTypeInfo DbgTy,
                                llvm::DIScope *Scope = nullptr) {
    // Is this an empty type?
    if (DbgTy.isNull())
      // We can't use the empty type as an index into DenseMap.
      return createType(DbgTy, "", TheCU, MainFile);

    // Look in the cache first.
    if (auto *DITy = getTypeOrNull(DbgTy.getType())) {
      assert(sanityCheckCachedType(DbgTy, DITy));
      return DITy;
    }

    // Use a separate IDRefMap cache for existential typealiases
    // because they have identical mangled names as their inner
    // protocol types and cause conflicts in the cache.
    TrackingDIRefMap &RefMap =
        isExistentialTypeAlias(DbgTy) ? ExistentialTypeAliasMap : DIRefMap;

Review comment (suggestion):
You can remove the `getKind()` check if you instead use `getAs<>` and check if the result is null

Code after:
          // This is (bridging header) PCH.
          Scope = getOrCreateModule(*SubModuleDesc, nullptr);
      }
    }
    if (!Scope)
      Scope = getOrCreateContext(Context);

    // Scope outermost fileprivate decls in an inline private discriminator
    // namespace.
    //
    // We need to don't do this for decls imported from Clang modules because
    // the scopes of C/C++ symbols are not restricted to a particular file unit.
    if (auto *Decl = DbgTy.getDecl())
      if (Decl->isOutermostPrivateOrFilePrivateScope() &&
          !isa<ClangModuleUnit>(
              Decl->getDeclContext()->getModuleScopeContext()))
        Scope = getFilePrivateScope(Scope, Decl);

    return Scope;
  }

  static bool isExistentialTypeAlias(DebugTypeInfo DbgTy) {
    TypeBase *BaseTy = DbgTy.getType();
    auto *ExistentialTy = BaseTy->getAs<ExistentialType>();
    if (!ExistentialTy)
      return false;
    Type ConstraintTy = ExistentialTy->getConstraintType();
    TypeBase *TyPtr = ConstraintTy.getPointer();
    return isa<TypeAliasType>(TyPtr);
  }

  llvm::DIType *getOrCreateType(DebugTypeInfo DbgTy,
                                llvm::DIScope *Scope = nullptr) {
    // Is this an empty type?
    if (DbgTy.isNull())
      // We can't use the empty type as an index into DenseMap.
      return createType(DbgTy, "", TheCU, MainFile);

    // Look in the cache first.
    if (auto *DITy = getTypeOrNull(DbgTy.getType())) {
      assert(sanityCheckCachedType(DbgTy, DITy));
      return DITy;
    }

    // Use a separate DIRefMap cache for existential typealiases
    // because they have identical mangled names as their inner
    // protocol types and cause conflicts in the cache. For example,
    // protocol P<Value> {
    //    associatedtype Value
    // }
    // actor A<Value> {