static ::mlir::Attribute readAffineMapAttr(MLIRContext* context, DialectBytecodeReader &reader) {
  AffineMap value;
  if (succeeded(readAffineMap(reader, context, value))) {
    return getChecked<AffineMapAttr>([&]() { return reader.emitError(); }, context, value);
  }
  return AffineMapAttr();
}

static LogicalResult write(AffineMapAttr attribute, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* AffineMapAttr */ 23);
  writeAffineMap(writer, attribute);
  return success();
  return failure();
}

static ::mlir::Attribute readArrayAttr(MLIRContext* context, DialectBytecodeReader &reader) {
  SmallVector<Attribute> value;
  if (succeeded(reader.readAttributes(value))) {
    return getChecked<ArrayAttr>([&]() { return reader.emitError(); }, context, value);
  }
  return ArrayAttr();
}

static LogicalResult write(ArrayAttr attribute, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* ArrayAttr */ 0);
  writer.writeAttributes(attribute.getValue());
  return success();
  return failure();
}

static ::mlir::Attribute readCallSiteLoc(MLIRContext* context, DialectBytecodeReader &reader) {
  LocationAttr callee, caller;
  if (succeeded(reader.readAttribute(callee)) &&
      succeeded(reader.readAttribute(caller))) {
    return getChecked<CallSiteLoc>([&]() { return reader.emitError(); }, context, callee, caller);
  }
  return CallSiteLoc();
}

static LogicalResult write(CallSiteLoc attribute, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* CallSiteLoc */ 10);
  writer.writeAttribute(attribute.getCallee());
  writer.writeAttribute(attribute.getCaller());
  return success();
  return failure();
}

static ::mlir::Attribute readDenseArrayAttr(MLIRContext* context, DialectBytecodeReader &reader) {
  Type elementType;
  uint64_t size;
  ArrayRef<char> rawData;
  if (succeeded(reader.readType(elementType)) &&
      succeeded(reader.readVarInt(size)) &&
      succeeded(reader.readBlob(rawData))) {
    return getChecked<DenseArrayAttr>([&]() { return reader.emitError(); }, context, elementType, size, rawData);
  }
  return DenseArrayAttr();
}

static LogicalResult write(DenseArrayAttr attribute, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* DenseArrayAttr */ 17);
  writer.writeType(attribute.getElementType());
  writer.writeVarInt(attribute.getSize());
  writer.writeOwnedBlob(attribute.getRawData());
  return success();
  return failure();
}

static ::mlir::Attribute readDenseResourceElementsAttr(MLIRContext* context, DialectBytecodeReader &reader) {
  ShapedType type;
  FailureOr<DenseResourceElementsHandle> rawHandle;
  if (succeeded(reader.readType(type)) &&
      succeeded(readResourceHandle<DenseResourceElementsHandle>(reader, rawHandle))) {
    return getChecked<DenseResourceElementsAttr>([&]() { return reader.emitError(); }, context, type, *rawHandle);
  }
  return DenseResourceElementsAttr();
}

static LogicalResult write(DenseResourceElementsAttr attribute, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* DenseResourceElementsAttr */ 16);
  writer.writeType(attribute.getType());
  writer.writeResourceHandle(attribute.getRawHandle());
  return success();
  return failure();
}

static ::mlir::Attribute readDenseStringElementsAttr(MLIRContext* context, DialectBytecodeReader &reader) {
  ShapedType type;
  uint64_t _isSplat;
  SmallVector<StringRef> rawStringData;
  if (succeeded(reader.readType(type)) &&
      succeeded(reader.readVarInt(_isSplat)) &&
      succeeded(readPotentiallySplatString(reader, type, _isSplat, rawStringData))) {
    return getChecked<DenseStringElementsAttr>([&]() { return reader.emitError(); }, context, type, rawStringData);
  }
  return DenseStringElementsAttr();
}

static LogicalResult write(DenseStringElementsAttr attribute, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* DenseStringElementsAttr */ 19);
  writer.writeType(attribute.getType());
  writer.writeVarInt(attribute.isSplat());
  writePotentiallySplatString(writer, attribute);
  return success();
  return failure();
}

static ::mlir::Attribute readDenseTypedElementsAttr(MLIRContext* context, DialectBytecodeReader &reader) {
  ShapedType type;
  SmallVector<char> rawData;
  if (succeeded(reader.readType(type)) &&
      succeeded(readDenseTypedElementsAttr(reader, type, rawData))) {
    return getChecked<DenseTypedElementsAttr>([&]() { return reader.emitError(); }, context, type, rawData);
  }
  return DenseTypedElementsAttr();
}

static LogicalResult write(DenseTypedElementsAttr attribute, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* DenseTypedElementsAttr */ 18);
  writer.writeType(attribute.getType());
  writeDenseTypedElementsAttr(writer, attribute);
  return success();
  return failure();
}

static ::mlir::Attribute readDictionaryAttr(MLIRContext* context, DialectBytecodeReader &reader) {
  SmallVector<NamedAttribute> value;
  auto readValue = [&]() -> FailureOr<NamedAttribute> {
    StringAttr name;
    Attribute value;
    if (succeeded(reader.readAttribute<StringAttr>(name)) &&
        succeeded(reader.readAttribute(value))) {
      return NamedAttribute(name, value);
    }
    return failure();
  };
  if (succeeded(reader.readList(value, readValue))) {
    return getChecked<DictionaryAttr>([&]() { return reader.emitError(); }, context, value);
  }
  return DictionaryAttr();
}

static LogicalResult write(DictionaryAttr attribute, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* DictionaryAttr */ 1);
  writer.writeList(attribute.getValue(), [&](NamedAttribute attribute) {
    writer.writeAttribute(attribute.getName());
    writer.writeAttribute(attribute.getValue());
  });
  return success();
  return failure();
}

static ::mlir::Attribute readDistinctAttr(MLIRContext* context, DialectBytecodeReader &reader) {
  Attribute referencedAttr;
  if (succeeded(reader.readAttribute(referencedAttr))) {
    return getChecked<DistinctAttr>([&]() { return reader.emitError(); }, context, referencedAttr);
  }
  return DistinctAttr();
}

static LogicalResult write(DistinctAttr attribute, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* DistinctAttr */ 21);
  writer.writeAttribute(attribute.getReferencedAttr());
  return success();
  return failure();
}

static ::mlir::Attribute readFileLineColLoc(MLIRContext* context, DialectBytecodeReader &reader) {
  StringAttr filename;
  uint64_t start_line, start_column;
  if (succeeded(reader.readAttribute<StringAttr>(filename)) &&
      succeeded(reader.readVarInt(start_line)) &&
      succeeded(reader.readVarInt(start_column))) {
    return getChecked<FileLineColRange>([&]() { return reader.emitError(); }, context, filename, start_line, start_column);
  }
  return FileLineColRange();
}

static ::mlir::Attribute readFileLineColRange(MLIRContext* context, DialectBytecodeReader &reader) {
  StringAttr filename;
  SmallVector<uint64_t> rawLocData;
  if (succeeded(reader.readAttribute<StringAttr>(filename)) &&
      succeeded(readFileLineColRangeLocs(reader, rawLocData))) {
    return getFileLineColRange(context, filename, rawLocData);
  }
  return FileLineColRange();
}

static LogicalResult write(FileLineColRange attribute, DialectBytecodeWriter &writer) {
  if (isStrictFileLineColLoc(attribute)) {
    writer.writeVarInt(/* FileLineColLoc */ 11);
    writer.writeAttribute(attribute.getFilename());
    writer.writeVarInt(attribute.getStartLine());
    writer.writeVarInt(attribute.getStartColumn());
    return success();
  }
  if (!isStrictFileLineColLoc(attribute)) {
    writer.writeVarInt(/* FileLineColRange */ 22);
    writer.writeAttribute(attribute.getFilename());
    writeFileLineColRangeLocs(writer, attribute);
    return success();
  }
  return failure();
}

static ::mlir::Attribute readFlatSymbolRefAttr(MLIRContext* context, DialectBytecodeReader &reader) {
  StringAttr rootReference;
  if (succeeded(reader.readAttribute<StringAttr>(rootReference))) {
    return getChecked<FlatSymbolRefAttr>([&]() { return reader.emitError(); }, context, rootReference);
  }
  return FlatSymbolRefAttr();
}

static LogicalResult write(FlatSymbolRefAttr attribute, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* FlatSymbolRefAttr */ 4);
  writer.writeAttribute(attribute.getRootReference());
  return success();
  return failure();
}

static ::mlir::Attribute readFloatAttr(MLIRContext* context, DialectBytecodeReader &reader) {
  Type type;
  FailureOr<APFloat> value;
  if (succeeded(reader.readType(type)) &&
      succeeded(readAPFloatWithKnownSemantics(reader, type, value))) {
    return getChecked<FloatAttr>([&]() { return reader.emitError(); }, context, type, *value);
  }
  return FloatAttr();
}

static LogicalResult write(FloatAttr attribute, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* FloatAttr */ 9);
  writer.writeType(attribute.getType());
  writer.writeAPFloatWithKnownSemantics(attribute.getValue());
  return success();
  return failure();
}

static ::mlir::Attribute readFusedLoc(MLIRContext* context, DialectBytecodeReader &reader) {
  SmallVector<Location> locations;
  auto readLocations = [&]() -> FailureOr<Location> {
    LocationAttr value;
    if (succeeded(reader.readAttribute(value))) {
      return Location(value);
    }
    return failure();
  };
  if (succeeded(reader.readList(locations, readLocations))) {
    return cast<FusedLoc>(getChecked<FusedLoc>([&]() { return reader.emitError(); }, context, locations, Attribute()));
  }
  return FusedLoc();
}

static ::mlir::Attribute readFusedLocWithMetadata(MLIRContext* context, DialectBytecodeReader &reader) {
  SmallVector<Location> locations;
  Attribute metadata;
  auto readLocations = [&]() -> FailureOr<Location> {
    LocationAttr value;
    if (succeeded(reader.readAttribute(value))) {
      return Location(value);
    }
    return failure();
  };
  if (succeeded(reader.readList(locations, readLocations)) &&
      succeeded(reader.readAttribute(metadata))) {
    return cast<FusedLoc>(getChecked<FusedLoc>([&]() { return reader.emitError(); }, context, locations, metadata));
  }
  return FusedLoc();
}

static LogicalResult write(FusedLoc attribute, DialectBytecodeWriter &writer) {
  if (!attribute.getMetadata()) {
    writer.writeVarInt(/* FusedLoc */ 12);
    writer.writeList(attribute.getLocations(), [&](Location attribute) {
      writer.writeAttribute((LocationAttr)attribute);
    });
    return success();
  }
  if (attribute.getMetadata()) {
    writer.writeVarInt(/* FusedLocWithMetadata */ 13);
    writer.writeList(attribute.getLocations(), [&](Location attribute) {
      writer.writeAttribute((LocationAttr)attribute);
    });
    writer.writeAttribute(attribute.getMetadata());
    return success();
  }
  return failure();
}

static ::mlir::Attribute readIntegerAttr(MLIRContext* context, DialectBytecodeReader &reader) {
  Type type;
  FailureOr<APInt> value;
  if (succeeded(reader.readType(type)) &&
      succeeded(readAPIntWithKnownWidth(reader, type, value))) {
    return getChecked<IntegerAttr>([&]() { return reader.emitError(); }, context, type, *value);
  }
  return IntegerAttr();
}

static LogicalResult write(IntegerAttr attribute, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* IntegerAttr */ 8);
  writer.writeType(attribute.getType());
  writer.writeAPIntWithKnownWidth(attribute.getValue());
  return success();
  return failure();
}

static ::mlir::Attribute readNameLoc(MLIRContext* context, DialectBytecodeReader &reader) {
  StringAttr name;
  LocationAttr childLoc;
  if (succeeded(reader.readAttribute<StringAttr>(name)) &&
      succeeded(reader.readAttribute(childLoc))) {
    return getChecked<NameLoc>([&]() { return reader.emitError(); }, context, name, childLoc);
  }
  return NameLoc();
}

static LogicalResult write(NameLoc attribute, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* NameLoc */ 14);
  writer.writeAttribute(attribute.getName());
  writer.writeAttribute(attribute.getChildLoc());
  return success();
  return failure();
}

static ::mlir::Attribute readSparseElementsAttr(MLIRContext* context, DialectBytecodeReader &reader) {
  ShapedType type;
  DenseIntElementsAttr indices;
  DenseElementsAttr values;
  if (succeeded(reader.readType(type)) &&
      succeeded(reader.readAttribute(indices)) &&
      succeeded(reader.readAttribute(values))) {
    return getChecked<SparseElementsAttr>([&]() { return reader.emitError(); }, context, type, indices, values);
  }
  return SparseElementsAttr();
}

static LogicalResult write(SparseElementsAttr attribute, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* SparseElementsAttr */ 20);
  writer.writeType(attribute.getType());
  writer.writeAttribute(attribute.getIndices());
  writer.writeAttribute(attribute.getValues());
  return success();
  return failure();
}

static ::mlir::Attribute readStringAttr(MLIRContext* context, DialectBytecodeReader &reader) {
  StringRef value;
  if (succeeded(reader.readString(value))) {
    return getChecked<StringAttr>([&]() { return reader.emitError(); }, context, value);
  }
  return StringAttr();
}

static ::mlir::Attribute readStringAttrWithType(MLIRContext* context, DialectBytecodeReader &reader) {
  StringRef value;
  Type type;
  if (succeeded(reader.readString(value)) &&
      succeeded(reader.readType(type))) {
    return getChecked<StringAttr>([&]() { return reader.emitError(); }, context, value, type);
  }
  return StringAttr();
}

static LogicalResult write(StringAttr attribute, DialectBytecodeWriter &writer) {
  if (::llvm::isa<NoneType>(attribute.getType())) {
    writer.writeVarInt(/* StringAttr */ 2);
    writer.writeOwnedString(attribute);
    return success();
  }
  if (!::llvm::isa<NoneType>(attribute.getType())) {
    writer.writeVarInt(/* StringAttrWithType */ 3);
    writer.writeOwnedString(attribute);
    writer.writeType(attribute.getType());
    return success();
  }
  return failure();
}

static ::mlir::Attribute readSymbolRefAttr(MLIRContext* context, DialectBytecodeReader &reader) {
  StringAttr rootReference;
  SmallVector<FlatSymbolRefAttr> nestedReferences;
  if (succeeded(reader.readAttribute<StringAttr>(rootReference)) &&
      succeeded(reader.readAttributes(nestedReferences))) {
    return getChecked<SymbolRefAttr>([&]() { return reader.emitError(); }, context, rootReference, nestedReferences);
  }
  return SymbolRefAttr();
}

static LogicalResult write(SymbolRefAttr attribute, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* SymbolRefAttr */ 5);
  writer.writeAttribute(attribute.getRootReference());
  writer.writeAttributes(attribute.getNestedReferences());
  return success();
  return failure();
}

static ::mlir::Attribute readTypeAttr(MLIRContext* context, DialectBytecodeReader &reader) {
  Type value;
  if (succeeded(reader.readType(value))) {
    return getChecked<TypeAttr>([&]() { return reader.emitError(); }, context, value);
  }
  return TypeAttr();
}

static LogicalResult write(TypeAttr attribute, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* TypeAttr */ 6);
  writer.writeType(attribute.getValue());
  return success();
  return failure();
}

static ::mlir::Attribute readUnitAttr(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<UnitAttr>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(UnitAttr attribute, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* UnitAttr */ 7);
  return success();
  return failure();
}

static ::mlir::Attribute readUnknownLoc(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<UnknownLoc>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(UnknownLoc attribute, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* UnknownLoc */ 15);
  return success();
  return failure();
}

static Attribute readAttribute(MLIRContext* context, DialectBytecodeReader &reader) {
  uint64_t kind;
  if (failed(reader.readVarInt(kind)))
    return Attribute();
  switch (kind) {
    case 0:
      return readArrayAttr(context, reader);
    case 1:
      return readDictionaryAttr(context, reader);
    case 2:
      return readStringAttr(context, reader);
    case 3:
      return readStringAttrWithType(context, reader);
    case 4:
      return readFlatSymbolRefAttr(context, reader);
    case 5:
      return readSymbolRefAttr(context, reader);
    case 6:
      return readTypeAttr(context, reader);
    case 7:
      return readUnitAttr(context, reader);
    case 8:
      return readIntegerAttr(context, reader);
    case 9:
      return readFloatAttr(context, reader);
    case 10:
      return readCallSiteLoc(context, reader);
    case 11:
      return readFileLineColLoc(context, reader);
    case 12:
      return readFusedLoc(context, reader);
    case 13:
      return readFusedLocWithMetadata(context, reader);
    case 14:
      return readNameLoc(context, reader);
    case 15:
      return readUnknownLoc(context, reader);
    case 16:
      return readDenseResourceElementsAttr(context, reader);
    case 17:
      return readDenseArrayAttr(context, reader);
    case 18:
      return readDenseTypedElementsAttr(context, reader);
    case 19:
      return readDenseStringElementsAttr(context, reader);
    case 20:
      return readSparseElementsAttr(context, reader);
    case 21:
      return readDistinctAttr(context, reader);
    case 22:
      return readFileLineColRange(context, reader);
    case 23:
      return readAffineMapAttr(context, reader);
    default:
      reader.emitError() << "unknown attribute code: " << kind;
      return Attribute();
  }
  return Attribute();
}

static LogicalResult writeAttribute(Attribute attribute,
                                DialectBytecodeWriter &writer) {
  return TypeSwitch<Attribute, LogicalResult>(attribute)
    .Case([&](AffineMapAttr t) {
      return write(t, writer);
    })
    .Case([&](ArrayAttr t) {
      return write(t, writer);
    })
    .Case([&](CallSiteLoc t) {
      return write(t, writer);
    })
    .Case([&](DenseArrayAttr t) {
      return write(t, writer);
    })
    .Case([&](DenseResourceElementsAttr t) {
      return write(t, writer);
    })
    .Case([&](DenseStringElementsAttr t) {
      return write(t, writer);
    })
    .Case([&](DenseTypedElementsAttr t) {
      return write(t, writer);
    })
    .Case([&](DictionaryAttr t) {
      return write(t, writer);
    })
    .Case([&](DistinctAttr t) {
      return write(t, writer);
    })
    .Case([&](FileLineColRange t) {
      return write(t, writer);
    })
    .Case([&](FlatSymbolRefAttr t) {
      return write(t, writer);
    })
    .Case([&](FloatAttr t) {
      return write(t, writer);
    })
    .Case([&](FusedLoc t) {
      return write(t, writer);
    })
    .Case([&](IntegerAttr t) {
      return write(t, writer);
    })
    .Case([&](NameLoc t) {
      return write(t, writer);
    })
    .Case([&](SparseElementsAttr t) {
      return write(t, writer);
    })
    .Case([&](StringAttr t) {
      return write(t, writer);
    })
    .Case([&](SymbolRefAttr t) {
      return write(t, writer);
    })
    .Case([&](TypeAttr t) {
      return write(t, writer);
    })
    .Case([&](UnitAttr t) {
      return write(t, writer);
    })
    .Case([&](UnknownLoc t) {
      return write(t, writer);
    })
    .Default([&](Attribute) { return failure(); });
}

static ::mlir::Type readBFloat16Type(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<BFloat16Type>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(BFloat16Type type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* BFloat16Type */ 3);
  return success();
  return failure();
}

static ::mlir::Type readComplexType(MLIRContext* context, DialectBytecodeReader &reader) {
  Type elementType;
  if (succeeded(reader.readType(elementType))) {
    return getChecked<ComplexType>([&]() { return reader.emitError(); }, context, elementType);
  }
  return ComplexType();
}

static LogicalResult write(ComplexType type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* ComplexType */ 9);
  writer.writeType(type.getElementType());
  return success();
  return failure();
}

static ::mlir::Type readFloat128Type(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<Float128Type>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(Float128Type type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* Float128Type */ 8);
  return success();
  return failure();
}

static ::mlir::Type readFloat16Type(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<Float16Type>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(Float16Type type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* Float16Type */ 4);
  return success();
  return failure();
}

static ::mlir::Type readFloat32Type(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<Float32Type>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(Float32Type type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* Float32Type */ 5);
  return success();
  return failure();
}

static ::mlir::Type readFloat4E2M1FNType(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<Float4E2M1FNType>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(Float4E2M1FNType type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* Float4E2M1FNType */ 29);
  return success();
  return failure();
}

static ::mlir::Type readFloat64Type(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<Float64Type>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(Float64Type type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* Float64Type */ 6);
  return success();
  return failure();
}

static ::mlir::Type readFloat6E2M3FNType(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<Float6E2M3FNType>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(Float6E2M3FNType type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* Float6E2M3FNType */ 30);
  return success();
  return failure();
}

static ::mlir::Type readFloat6E3M2FNType(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<Float6E3M2FNType>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(Float6E3M2FNType type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* Float6E3M2FNType */ 31);
  return success();
  return failure();
}

static ::mlir::Type readFloat80Type(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<Float80Type>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(Float80Type type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* Float80Type */ 7);
  return success();
  return failure();
}

static ::mlir::Type readFloat8E3M4Type(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<Float8E3M4Type>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(Float8E3M4Type type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* Float8E3M4Type */ 28);
  return success();
  return failure();
}

static ::mlir::Type readFloat8E4M3B11FNUZType(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<Float8E4M3B11FNUZType>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(Float8E4M3B11FNUZType type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* Float8E4M3B11FNUZType */ 27);
  return success();
  return failure();
}

static ::mlir::Type readFloat8E4M3FNType(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<Float8E4M3FNType>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(Float8E4M3FNType type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* Float8E4M3FNType */ 24);
  return success();
  return failure();
}

static ::mlir::Type readFloat8E4M3FNUZType(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<Float8E4M3FNUZType>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(Float8E4M3FNUZType type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* Float8E4M3FNUZType */ 26);
  return success();
  return failure();
}

static ::mlir::Type readFloat8E4M3Type(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<Float8E4M3Type>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(Float8E4M3Type type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* Float8E4M3Type */ 23);
  return success();
  return failure();
}

static ::mlir::Type readFloat8E5M2FNUZType(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<Float8E5M2FNUZType>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(Float8E5M2FNUZType type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* Float8E5M2FNUZType */ 25);
  return success();
  return failure();
}

static ::mlir::Type readFloat8E5M2Type(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<Float8E5M2Type>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(Float8E5M2Type type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* Float8E5M2Type */ 22);
  return success();
  return failure();
}

static ::mlir::Type readFloat8E8M0FNUType(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<Float8E8M0FNUType>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(Float8E8M0FNUType type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* Float8E8M0FNUType */ 32);
  return success();
  return failure();
}

static ::mlir::Type readFloatTF32Type(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<FloatTF32Type>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(FloatTF32Type type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* FloatTF32Type */ 21);
  return success();
  return failure();
}

static ::mlir::Type readFunctionType(MLIRContext* context, DialectBytecodeReader &reader) {
  SmallVector<Type> inputs, results;
  if (succeeded(reader.readTypes(inputs)) &&
      succeeded(reader.readTypes(results))) {
    return getChecked<FunctionType>([&]() { return reader.emitError(); }, context, inputs, results);
  }
  return FunctionType();
}

static LogicalResult write(FunctionType type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* FunctionType */ 2);
  writer.writeTypes(type.getInputs());
  writer.writeTypes(type.getResults());
  return success();
  return failure();
}

static ::mlir::Type readIndexType(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<IndexType>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(IndexType type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* IndexType */ 1);
  return success();
  return failure();
}

static ::mlir::Type readIntegerType(MLIRContext* context, DialectBytecodeReader &reader) {
  uint64_t _widthAndSignedness, width;
  IntegerType::SignednessSemantics signedness;
  if (succeeded(reader.readVarInt(_widthAndSignedness)) &&
      ((width = _widthAndSignedness >> 2), true) &&
      ((signedness = static_cast<IntegerType::SignednessSemantics>(_widthAndSignedness & 0x3)), true)) {
    return getChecked<IntegerType>([&]() { return reader.emitError(); }, context, width, signedness);
  }
  return IntegerType();
}

static LogicalResult write(IntegerType type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* IntegerType */ 0);
  writer.writeVarInt(type.getWidth() << 2 | type.getSignedness());
  return success();
  return failure();
}

static ::mlir::Type readMemRefType(MLIRContext* context, DialectBytecodeReader &reader) {
  SmallVector<int64_t> shape;
  Type elementType;
  MemRefLayoutAttrInterface layout;
  auto readShape = [&]() -> FailureOr<int64_t> {
    int64_t temp;
    if (succeeded(reader.readSignedVarInt(temp))) {
      return temp;
    }
    return failure();
  };
  if (succeeded(reader.readList(shape, readShape)) &&
      succeeded(reader.readType(elementType)) &&
      succeeded(reader.readAttribute(layout))) {
    return getChecked<MemRefType>([&]() { return reader.emitError(); }, context, shape, elementType, layout);
  }
  return MemRefType();
}

static ::mlir::Type readMemRefTypeWithMemSpace(MLIRContext* context, DialectBytecodeReader &reader) {
  Attribute memorySpace;
  SmallVector<int64_t> shape;
  Type elementType;
  MemRefLayoutAttrInterface layout;
  auto readShape = [&]() -> FailureOr<int64_t> {
    int64_t temp;
    if (succeeded(reader.readSignedVarInt(temp))) {
      return temp;
    }
    return failure();
  };
  if (succeeded(reader.readAttribute(memorySpace)) &&
      succeeded(reader.readList(shape, readShape)) &&
      succeeded(reader.readType(elementType)) &&
      succeeded(reader.readAttribute(layout))) {
    return getChecked<MemRefType>([&]() { return reader.emitError(); }, context, shape, elementType, layout, memorySpace);
  }
  return MemRefType();
}

static LogicalResult write(MemRefType type, DialectBytecodeWriter &writer) {
  if (!type.getMemorySpace()) {
    writer.writeVarInt(/* MemRefType */ 10);
    writer.writeList(type.getShape(), [&](int64_t type) {
      writer.writeSignedVarInt(type);
    });
    writer.writeType(type.getElementType());
    writer.writeAttribute(type.getLayout());
    return success();
  }
  if (!!type.getMemorySpace()) {
    writer.writeVarInt(/* MemRefTypeWithMemSpace */ 11);
    writer.writeAttribute(type.getMemorySpace());
    writer.writeList(type.getShape(), [&](int64_t type) {
      writer.writeSignedVarInt(type);
    });
    writer.writeType(type.getElementType());
    writer.writeAttribute(type.getLayout());
    return success();
  }
  return failure();
}

static ::mlir::Type readNoneType(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<NoneType>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(NoneType type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* NoneType */ 12);
  return success();
  return failure();
}

static ::mlir::Type readRankedTensorType(MLIRContext* context, DialectBytecodeReader &reader) {
  SmallVector<int64_t> shape;
  Type elementType;
  auto readShape = [&]() -> FailureOr<int64_t> {
    int64_t temp;
    if (succeeded(reader.readSignedVarInt(temp))) {
      return temp;
    }
    return failure();
  };
  if (succeeded(reader.readList(shape, readShape)) &&
      succeeded(reader.readType(elementType))) {
    return getChecked<RankedTensorType>([&]() { return reader.emitError(); }, context, shape, elementType);
  }
  return RankedTensorType();
}

static ::mlir::Type readRankedTensorTypeWithEncoding(MLIRContext* context, DialectBytecodeReader &reader) {
  Attribute encoding;
  SmallVector<int64_t> shape;
  Type elementType;
  auto readShape = [&]() -> FailureOr<int64_t> {
    int64_t temp;
    if (succeeded(reader.readSignedVarInt(temp))) {
      return temp;
    }
    return failure();
  };
  if (succeeded(reader.readAttribute(encoding)) &&
      succeeded(reader.readList(shape, readShape)) &&
      succeeded(reader.readType(elementType))) {
    return getChecked<RankedTensorType>([&]() { return reader.emitError(); }, context, shape, elementType, encoding);
  }
  return RankedTensorType();
}

static LogicalResult write(RankedTensorType type, DialectBytecodeWriter &writer) {
  if (!type.getEncoding()) {
    writer.writeVarInt(/* RankedTensorType */ 13);
    writer.writeList(type.getShape(), [&](int64_t type) {
      writer.writeSignedVarInt(type);
    });
    writer.writeType(type.getElementType());
    return success();
  }
  if (type.getEncoding()) {
    writer.writeVarInt(/* RankedTensorTypeWithEncoding */ 14);
    writer.writeAttribute(type.getEncoding());
    writer.writeList(type.getShape(), [&](int64_t type) {
      writer.writeSignedVarInt(type);
    });
    writer.writeType(type.getElementType());
    return success();
  }
  return failure();
}

static ::mlir::Type readTokenType(MLIRContext* context, DialectBytecodeReader &reader) {
  return getChecked<TokenType>([&]() { return reader.emitError(); }, context);
}

static LogicalResult write(TokenType type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* TokenType */ 33);
  return success();
  return failure();
}

static ::mlir::Type readTupleType(MLIRContext* context, DialectBytecodeReader &reader) {
  SmallVector<Type> types;
  if (succeeded(reader.readTypes(types))) {
    return getChecked<TupleType>([&]() { return reader.emitError(); }, context, types);
  }
  return TupleType();
}

static LogicalResult write(TupleType type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* TupleType */ 15);
  writer.writeTypes(type.getTypes());
  return success();
  return failure();
}

static ::mlir::Type readUnrankedMemRefType(MLIRContext* context, DialectBytecodeReader &reader) {
  Type elementType;
  if (succeeded(reader.readType(elementType))) {
    return getChecked<UnrankedMemRefType>([&]() { return reader.emitError(); }, context, elementType, Attribute());
  }
  return UnrankedMemRefType();
}

static ::mlir::Type readUnrankedMemRefTypeWithMemSpace(MLIRContext* context, DialectBytecodeReader &reader) {
  Attribute memorySpace;
  Type elementType;
  if (succeeded(reader.readAttribute(memorySpace)) &&
      succeeded(reader.readType(elementType))) {
    return getChecked<UnrankedMemRefType>([&]() { return reader.emitError(); }, context, elementType, memorySpace);
  }
  return UnrankedMemRefType();
}

static LogicalResult write(UnrankedMemRefType type, DialectBytecodeWriter &writer) {
  if (!type.getMemorySpace()) {
    writer.writeVarInt(/* UnrankedMemRefType */ 16);
    writer.writeType(type.getElementType());
    return success();
  }
  if (type.getMemorySpace()) {
    writer.writeVarInt(/* UnrankedMemRefTypeWithMemSpace */ 17);
    writer.writeAttribute(type.getMemorySpace());
    writer.writeType(type.getElementType());
    return success();
  }
  return failure();
}

static ::mlir::Type readUnrankedTensorType(MLIRContext* context, DialectBytecodeReader &reader) {
  Type elementType;
  if (succeeded(reader.readType(elementType))) {
    return getChecked<UnrankedTensorType>([&]() { return reader.emitError(); }, context, elementType);
  }
  return UnrankedTensorType();
}

static LogicalResult write(UnrankedTensorType type, DialectBytecodeWriter &writer) {
  writer.writeVarInt(/* UnrankedTensorType */ 18);
  writer.writeType(type.getElementType());
  return success();
  return failure();
}

static ::mlir::Type readVectorType(MLIRContext* context, DialectBytecodeReader &reader) {
  SmallVector<int64_t> shape;
  Type elementType;
  auto readShape = [&]() -> FailureOr<int64_t> {
    int64_t temp;
    if (succeeded(reader.readSignedVarInt(temp))) {
      return temp;
    }
    return failure();
  };
  if (succeeded(reader.readList(shape, readShape)) &&
      succeeded(reader.readType(elementType))) {
    return VectorType::getChecked([&]() { return reader.emitError("invalid vector type"); }, shape, elementType);
  }
  return VectorType();
}

static ::mlir::Type readVectorTypeWithScalableDims(MLIRContext* context, DialectBytecodeReader &reader) {
  SmallVector<bool> scalableDims;
  SmallVector<int64_t> shape;
  Type elementType;
  auto readScalableDims = [&]() -> FailureOr<bool> {
    bool temp;
    if (succeeded(reader.readBool(temp))) {
      return temp;
    }
    return failure();
  };
  auto readShape = [&]() -> FailureOr<int64_t> {
    int64_t temp;
    if (succeeded(reader.readSignedVarInt(temp))) {
      return temp;
    }
    return failure();
  };
  if (succeeded(reader.readList(scalableDims, readScalableDims)) &&
      succeeded(reader.readList(shape, readShape)) &&
      succeeded(reader.readType(elementType))) {
    return getChecked<VectorType>([&]() { return reader.emitError(); }, context, shape, elementType, scalableDims);
  }
  return VectorType();
}

static LogicalResult write(VectorType type, DialectBytecodeWriter &writer) {
  if (!type.isScalable()) {
    writer.writeVarInt(/* VectorType */ 19);
    writer.writeList(type.getShape(), [&](int64_t type) {
      writer.writeSignedVarInt(type);
    });
    writer.writeType(type.getElementType());
    return success();
  }
  if (type.isScalable()) {
    writer.writeVarInt(/* VectorTypeWithScalableDims */ 20);
    writer.writeList(type.getScalableDims(), [&](bool type) {
      writer.writeOwnedBool(type);
    });
    writer.writeList(type.getShape(), [&](int64_t type) {
      writer.writeSignedVarInt(type);
    });
    writer.writeType(type.getElementType());
    return success();
  }
  return failure();
}

static Type readType(MLIRContext* context, DialectBytecodeReader &reader) {
  uint64_t kind;
  if (failed(reader.readVarInt(kind)))
    return Type();
  switch (kind) {
    case 0:
      return readIntegerType(context, reader);
    case 1:
      return readIndexType(context, reader);
    case 2:
      return readFunctionType(context, reader);
    case 3:
      return readBFloat16Type(context, reader);
    case 4:
      return readFloat16Type(context, reader);
    case 5:
      return readFloat32Type(context, reader);
    case 6:
      return readFloat64Type(context, reader);
    case 7:
      return readFloat80Type(context, reader);
    case 8:
      return readFloat128Type(context, reader);
    case 9:
      return readComplexType(context, reader);
    case 10:
      return readMemRefType(context, reader);
    case 11:
      return readMemRefTypeWithMemSpace(context, reader);
    case 12:
      return readNoneType(context, reader);
    case 13:
      return readRankedTensorType(context, reader);
    case 14:
      return readRankedTensorTypeWithEncoding(context, reader);
    case 15:
      return readTupleType(context, reader);
    case 16:
      return readUnrankedMemRefType(context, reader);
    case 17:
      return readUnrankedMemRefTypeWithMemSpace(context, reader);
    case 18:
      return readUnrankedTensorType(context, reader);
    case 19:
      return readVectorType(context, reader);
    case 20:
      return readVectorTypeWithScalableDims(context, reader);
    case 21:
      return readFloatTF32Type(context, reader);
    case 22:
      return readFloat8E5M2Type(context, reader);
    case 23:
      return readFloat8E4M3Type(context, reader);
    case 24:
      return readFloat8E4M3FNType(context, reader);
    case 25:
      return readFloat8E5M2FNUZType(context, reader);
    case 26:
      return readFloat8E4M3FNUZType(context, reader);
    case 27:
      return readFloat8E4M3B11FNUZType(context, reader);
    case 28:
      return readFloat8E3M4Type(context, reader);
    case 29:
      return readFloat4E2M1FNType(context, reader);
    case 30:
      return readFloat6E2M3FNType(context, reader);
    case 31:
      return readFloat6E3M2FNType(context, reader);
    case 32:
      return readFloat8E8M0FNUType(context, reader);
    case 33:
      return readTokenType(context, reader);
    default:
      reader.emitError() << "unknown attribute code: " << kind;
      return Type();
  }
  return Type();
}

static LogicalResult writeType(Type type,
                                DialectBytecodeWriter &writer) {
  return TypeSwitch<Type, LogicalResult>(type)
    .Case([&](BFloat16Type t) {
      return write(t, writer);
    })
    .Case([&](ComplexType t) {
      return write(t, writer);
    })
    .Case([&](Float128Type t) {
      return write(t, writer);
    })
    .Case([&](Float16Type t) {
      return write(t, writer);
    })
    .Case([&](Float32Type t) {
      return write(t, writer);
    })
    .Case([&](Float4E2M1FNType t) {
      return write(t, writer);
    })
    .Case([&](Float64Type t) {
      return write(t, writer);
    })
    .Case([&](Float6E2M3FNType t) {
      return write(t, writer);
    })
    .Case([&](Float6E3M2FNType t) {
      return write(t, writer);
    })
    .Case([&](Float80Type t) {
      return write(t, writer);
    })
    .Case([&](Float8E3M4Type t) {
      return write(t, writer);
    })
    .Case([&](Float8E4M3B11FNUZType t) {
      return write(t, writer);
    })
    .Case([&](Float8E4M3FNType t) {
      return write(t, writer);
    })
    .Case([&](Float8E4M3FNUZType t) {
      return write(t, writer);
    })
    .Case([&](Float8E4M3Type t) {
      return write(t, writer);
    })
    .Case([&](Float8E5M2FNUZType t) {
      return write(t, writer);
    })
    .Case([&](Float8E5M2Type t) {
      return write(t, writer);
    })
    .Case([&](Float8E8M0FNUType t) {
      return write(t, writer);
    })
    .Case([&](FloatTF32Type t) {
      return write(t, writer);
    })
    .Case([&](FunctionType t) {
      return write(t, writer);
    })
    .Case([&](IndexType t) {
      return write(t, writer);
    })
    .Case([&](IntegerType t) {
      return write(t, writer);
    })
    .Case([&](MemRefType t) {
      return write(t, writer);
    })
    .Case([&](NoneType t) {
      return write(t, writer);
    })
    .Case([&](RankedTensorType t) {
      return write(t, writer);
    })
    .Case([&](TokenType t) {
      return write(t, writer);
    })
    .Case([&](TupleType t) {
      return write(t, writer);
    })
    .Case([&](UnrankedMemRefType t) {
      return write(t, writer);
    })
    .Case([&](UnrankedTensorType t) {
      return write(t, writer);
    })
    .Case([&](VectorType t) {
      return write(t, writer);
    })
    .Default([&](Type) { return failure(); });
}

