Rename UnknownType to OpaqueType (NFC)
authorMehdi Amini <aminim@google.com>
Wed, 3 Apr 2019 23:49:01 +0000 (16:49 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Thu, 4 Apr 2019 02:21:47 +0000 (19:21 -0700)
    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
mlir/g3doc/Rationale.md
mlir/g3doc/Tutorials/Toy/Ch-2.md
mlir/include/mlir/IR/StandardTypes.h
mlir/include/mlir/IR/Types.h
mlir/lib/IR/AsmPrinter.cpp
mlir/lib/IR/MLIRContext.cpp
mlir/lib/IR/TypeDetail.h
mlir/lib/IR/Types.cpp
mlir/lib/Parser/Parser.cpp
mlir/test/Quantization/parse-uniform-invalid.mlir

index 98777ad..5bd8073 100644 (file)
@@ -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
index e44a07c..42b32cf 100644 (file)
@@ -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
 
index 6ea86f1..3285b12 100644 (file)
@@ -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");
index b8f2b2f..030d109 100644 (file)
@@ -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<VectorType>() ||
-           type.isa<UnknownType>() ||
+           type.isa<OpaqueType>() ||
            (type.getKind() > Type::Kind::LAST_STANDARD_TYPE);
   }
 
index 6cf5fbb..e207291 100644 (file)
@@ -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<UnknownType, Type, detail::UnknownTypeStorage> {
+class OpaqueType
+    : public Type::TypeBase<OpaqueType, Type, detail::OpaqueTypeStorage> {
 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<Location> 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.
index 14946f8..e3e1d0e 100644 (file)
@@ -719,10 +719,10 @@ void ModulePrinter::printType(Type type) {
     os << "\">";
     return;
   }
-  case Type::Kind::Unknown: {
-    auto unknownTy = type.cast<UnknownType>();
-    os << '!' << unknownTy.getDialectNamespace() << "<\""
-       << unknownTy.getTypeData() << "\">";
+  case Type::Kind::Opaque: {
+    auto opaqueTy = type.cast<OpaqueType>();
+    os << '!' << opaqueTy.getDialectNamespace() << "<\""
+       << opaqueTy.getTypeData() << "\">";
     return;
   }
   case StandardTypes::Index:
index dbc20d8..1a459ad 100644 (file)
@@ -104,7 +104,7 @@ namespace {
 /// validity of the IR.
 struct BuiltinDialect : public Dialect {
   BuiltinDialect(MLIRContext *context) : Dialect(/*name=*/"", context) {
-    addTypes<FunctionType, UnknownType, FloatType, IndexType, IntegerType,
+    addTypes<FunctionType, OpaqueType, FloatType, IndexType, IntegerType,
              VectorType, RankedTensorType, UnrankedTensorType, MemRefType,
              ComplexType, TupleType>();
   }
index 8f9aa89..48f0f08 100644 (file)
@@ -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>())
-        UnknownTypeStorage(key.first, tyData);
+    return new (allocator.allocate<OpaqueTypeStorage>())
+        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;
 };
 
index 0863b59..7019354 100644 (file)
@@ -50,28 +50,28 @@ ArrayRef<Type> 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<Location> loc, MLIRContext *context, Identifier dialect,
     StringRef typeData) {
   if (!Dialect::isValidNamespace(dialect.strref())) {
index 48843ba..c07cabe 100644 (file)
@@ -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 '>'.
index 9168566..f6d872c 100644 (file)
@@ -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">