From 3a2955fa1fce8d27734704a253b65f5c5265167a Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Wed, 3 Apr 2019 16:49:01 -0700 Subject: [PATCH] Rename UnknownType to OpaqueType (NFC) This came up in a review of the tutorial, it was suggested that "opaque" is more descriptive than "unknown" here. -- PiperOrigin-RevId: 241832927 --- mlir/examples/toy/Ch2/mlir/MLIRGen.cpp | 4 +-- mlir/g3doc/Rationale.md | 8 +++--- mlir/g3doc/Tutorials/Toy/Ch-2.md | 4 +-- mlir/include/mlir/IR/StandardTypes.h | 2 +- mlir/include/mlir/IR/Types.h | 32 +++++++++++------------ mlir/lib/IR/AsmPrinter.cpp | 8 +++--- mlir/lib/IR/MLIRContext.cpp | 2 +- mlir/lib/IR/TypeDetail.h | 16 ++++++------ mlir/lib/IR/Types.cpp | 26 +++++++++--------- mlir/lib/Parser/Parser.cpp | 6 ++--- mlir/test/Quantization/parse-uniform-invalid.mlir | 2 +- 11 files changed, 55 insertions(+), 55 deletions(-) diff --git a/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp index 98777ad..5bd8073 100644 --- a/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp @@ -495,8 +495,8 @@ private: } typeName += ">"; } - return mlir::UnknownType::get(mlir::Identifier::get("toy", &context), - typeName, &context); + return mlir::OpaqueType::get(mlir::Identifier::get("toy", &context), + typeName, &context); } /// Build an MLIR type from a Toy AST variable type diff --git a/mlir/g3doc/Rationale.md b/mlir/g3doc/Rationale.md index e44a07c..42b32cf9 100644 --- a/mlir/g3doc/Rationale.md +++ b/mlir/g3doc/Rationale.md @@ -440,10 +440,10 @@ necessary for IR validity. MLIR supports unregistered operations in generic assembly form. MLIR also supports a similar concept for types. When parsing, if the dialect for dialect -type has not been registered the type is modeled as an 'UnknownType'. This -allows for types to be round-tripped without needing to link in the dialect -library that defined them. No additional information about unknown types, -outside of parsing/printing, will be available. +type has not been registered the type is modeled as an 'OpaqueType'. This allows +for types to be round-tripped without needing to link in the dialect library +that defined them. No additional information about opaque types, outside of +parsing/printing, will be available. #### Dialect type syntax diff --git a/mlir/g3doc/Tutorials/Toy/Ch-2.md b/mlir/g3doc/Tutorials/Toy/Ch-2.md index 6ea86f1..3285b12 100644 --- a/mlir/g3doc/Tutorials/Toy/Ch-2.md +++ b/mlir/g3doc/Tutorials/Toy/Ch-2.md @@ -104,7 +104,7 @@ To build the `custom.operation` from the listing above, assuming you have a ```c++ // The return type for the operation: `!another_dialect<"other_type">` auto another_dialect_prefix = mlir::Identifier::get("another_dialect", &context); -auto returnType = mlir::UnknownType::get(another_dialect_prefix, +auto returnType = mlir::OpaqueType::get(another_dialect_prefix, "custom_type", &context); // Creation of the state defining the operation: mlir::OperationState state(&context, location, "custom.operation"); @@ -128,7 +128,7 @@ mlir::Operation *createTransposeOp(FuncBuilder *builder, // We bundle our custom type in a `toy` dialect. auto toyDialect = mlir::Identifier::get("toy", builder->getContext()); // Create a custom type, in the MLIR assembly it is: !toy<"array<2, 2>"> - auto type = mlir::UnknownType::get(toyDialect, "array<2, 2>", builder->getContext()); + auto type = mlir::OpaqueType::get(toyDialect, "array<2, 2>", builder->getContext()); // Fill the `OperationState` with the required fields mlir::OperationState result(builder->getContext(), location, "toy.transpose"); diff --git a/mlir/include/mlir/IR/StandardTypes.h b/mlir/include/mlir/IR/StandardTypes.h index b8f2b2f..030d109 100644 --- a/mlir/include/mlir/IR/StandardTypes.h +++ b/mlir/include/mlir/IR/StandardTypes.h @@ -278,7 +278,7 @@ public: // types. Dialects are expected to verify that tensor types have a valid // element type within that dialect. return type.isIntOrFloat() || type.isa() || - type.isa() || + type.isa() || (type.getKind() > Type::Kind::LAST_STANDARD_TYPE); } diff --git a/mlir/include/mlir/IR/Types.h b/mlir/include/mlir/IR/Types.h index 6cf5fbb..e207291 100644 --- a/mlir/include/mlir/IR/Types.h +++ b/mlir/include/mlir/IR/Types.h @@ -34,7 +34,7 @@ class TypeStorage; namespace detail { struct FunctionTypeStorage; -struct UnknownTypeStorage; +struct OpaqueTypeStorage; } // namespace detail /// Instances of the Type class are immutable and uniqued. They wrap a pointer @@ -101,8 +101,8 @@ public: enum Kind { // Builtin types. Function, - Unknown, - LAST_BUILTIN_TYPE = Unknown, + Opaque, + LAST_BUILTIN_TYPE = Opaque, // Reserve type kinds for dialect specific type system extensions. #define DEFINE_TYPE_KIND_RANGE(Dialect) \ @@ -280,37 +280,37 @@ public: static bool kindof(unsigned kind) { return kind == Kind::Function; } }; -/// Unknown types represent types of non-registered dialects. These are types +/// Opaque types represent types of non-registered dialects. These are types /// represented in their raw string form, and can only usefully be tested for /// type equality. -class UnknownType - : public Type::TypeBase { +class OpaqueType + : public Type::TypeBase { public: using Base::Base; - /// Get or create a new UnknownType with the provided dialect and string data. - static UnknownType get(Identifier dialect, StringRef typeData, - MLIRContext *context); + /// Get or create a new OpaqueType with the provided dialect and string data. + static OpaqueType get(Identifier dialect, StringRef typeData, + MLIRContext *context); - /// Get or create a new UnknownType with the provided dialect and string data. + /// Get or create a new OpaqueType with the provided dialect and string data. /// If the given identifier is not a valid namespace for a dialect, then a /// null type is returned. - static UnknownType getChecked(Identifier dialect, StringRef typeData, - MLIRContext *context, Location location); + static OpaqueType getChecked(Identifier dialect, StringRef typeData, + MLIRContext *context, Location location); - /// Returns the dialect namespace of the unknown type. + /// Returns the dialect namespace of the opaque type. Identifier getDialectNamespace() const; - /// Returns the raw type data of the unknown type. + /// Returns the raw type data of the opaque type. StringRef getTypeData() const; - /// Verify the construction of an unknown type. + /// Verify the construction of an opaque type. static LogicalResult verifyConstructionInvariants(llvm::Optional loc, MLIRContext *context, Identifier dialect, StringRef typeData); - static bool kindof(unsigned kind) { return kind == Kind::Unknown; } + static bool kindof(unsigned kind) { return kind == Kind::Opaque; } }; // Make Type hashable. diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp index 14946f8..e3e1d0e 100644 --- a/mlir/lib/IR/AsmPrinter.cpp +++ b/mlir/lib/IR/AsmPrinter.cpp @@ -719,10 +719,10 @@ void ModulePrinter::printType(Type type) { os << "\">"; return; } - case Type::Kind::Unknown: { - auto unknownTy = type.cast(); - os << '!' << unknownTy.getDialectNamespace() << "<\"" - << unknownTy.getTypeData() << "\">"; + case Type::Kind::Opaque: { + auto opaqueTy = type.cast(); + os << '!' << opaqueTy.getDialectNamespace() << "<\"" + << opaqueTy.getTypeData() << "\">"; return; } case StandardTypes::Index: diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp index dbc20d8..1a459ad 100644 --- a/mlir/lib/IR/MLIRContext.cpp +++ b/mlir/lib/IR/MLIRContext.cpp @@ -104,7 +104,7 @@ namespace { /// validity of the IR. struct BuiltinDialect : public Dialect { BuiltinDialect(MLIRContext *context) : Dialect(/*name=*/"", context) { - addTypes(); } diff --git a/mlir/lib/IR/TypeDetail.h b/mlir/lib/IR/TypeDetail.h index 8f9aa89..48f0f08 100644 --- a/mlir/lib/IR/TypeDetail.h +++ b/mlir/lib/IR/TypeDetail.h @@ -34,9 +34,9 @@ class MLIRContext; namespace detail { -/// Unknown Type Storage and Uniquing. -struct UnknownTypeStorage : public TypeStorage { - UnknownTypeStorage(Identifier dialectNamespace, StringRef typeData) +/// Opaque Type Storage and Uniquing. +struct OpaqueTypeStorage : public TypeStorage { + OpaqueTypeStorage(Identifier dialectNamespace, StringRef typeData) : dialectNamespace(dialectNamespace), typeData(typeData) {} /// The hash key used for uniquing. @@ -45,17 +45,17 @@ struct UnknownTypeStorage : public TypeStorage { return key == KeyTy(dialectNamespace, typeData); } - static UnknownTypeStorage *construct(TypeStorageAllocator &allocator, - const KeyTy &key) { + static OpaqueTypeStorage *construct(TypeStorageAllocator &allocator, + const KeyTy &key) { StringRef tyData = allocator.copyInto(key.second); - return new (allocator.allocate()) - UnknownTypeStorage(key.first, tyData); + return new (allocator.allocate()) + OpaqueTypeStorage(key.first, tyData); } // The unknown dialect namespace. Identifier dialectNamespace; - // The parser type data for this unknown type. + // The parser type data for this opaque type. StringRef typeData; }; diff --git a/mlir/lib/IR/Types.cpp b/mlir/lib/IR/Types.cpp index 0863b59..7019354 100644 --- a/mlir/lib/IR/Types.cpp +++ b/mlir/lib/IR/Types.cpp @@ -50,28 +50,28 @@ ArrayRef FunctionType::getResults() const { return getImpl()->getResults(); } -/// UnknownType +/// OpaqueType -UnknownType UnknownType::get(Identifier dialect, StringRef typeData, - MLIRContext *context) { - return Base::get(context, Type::Kind::Unknown, dialect, typeData); +OpaqueType OpaqueType::get(Identifier dialect, StringRef typeData, + MLIRContext *context) { + return Base::get(context, Type::Kind::Opaque, dialect, typeData); } -UnknownType UnknownType::getChecked(Identifier dialect, StringRef typeData, - MLIRContext *context, Location location) { - return Base::getChecked(location, context, Kind::Unknown, dialect, typeData); +OpaqueType OpaqueType::getChecked(Identifier dialect, StringRef typeData, + MLIRContext *context, Location location) { + return Base::getChecked(location, context, Kind::Opaque, dialect, typeData); } -/// Returns the dialect namespace of the unknown type. -Identifier UnknownType::getDialectNamespace() const { +/// Returns the dialect namespace of the opaque type. +Identifier OpaqueType::getDialectNamespace() const { return getImpl()->dialectNamespace; } -/// Returns the raw type data of the unknown type. -StringRef UnknownType::getTypeData() const { return getImpl()->typeData; } +/// Returns the raw type data of the opaque type. +StringRef OpaqueType::getTypeData() const { return getImpl()->typeData; } -/// Verify the construction of an unknown type. -LogicalResult UnknownType::verifyConstructionInvariants( +/// Verify the construction of an opaque type. +LogicalResult OpaqueType::verifyConstructionInvariants( llvm::Optional loc, MLIRContext *context, Identifier dialect, StringRef typeData) { if (!Dialect::isValidNamespace(dialect.strref())) { diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp index 48843ba4..c07cabe 100644 --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -526,9 +526,9 @@ Type Parser::parseExtendedType() { if (!result) return nullptr; } else { - // Otherwise, form a new unknown type. - result = UnknownType::getChecked(Identifier::get(identifier, state.context), - typeData, state.context, loc); + // Otherwise, form a new opaque type. + result = OpaqueType::getChecked(Identifier::get(identifier, state.context), + typeData, state.context, loc); } // Consume the '>'. diff --git a/mlir/test/Quantization/parse-uniform-invalid.mlir b/mlir/test/Quantization/parse-uniform-invalid.mlir index 9168566..f6d872c 100644 --- a/mlir/test/Quantization/parse-uniform-invalid.mlir +++ b/mlir/test/Quantization/parse-uniform-invalid.mlir @@ -1,7 +1,7 @@ // RUN: mlir-opt %s -split-input-file -verify // ----- -// Unknown type. +// Invalid type. // expected-error@+1 {{unknown quantized type foobar}} !qalias = type !quant<"foobar"> -- 2.7.4