1313#include " substrait-mlir/Dialect/Substrait/IR/Substrait.h"
1414#include " substrait-mlir/Target/SubstraitPB/Options.h"
1515#include " llvm/ADT/TypeSwitch.h"
16+ #include " llvm/Support/ErrorHandling.h"
1617
1718#include < google/protobuf/text_format.h>
1819#include < google/protobuf/util/json_util.h>
@@ -114,7 +115,7 @@ std::unique_ptr<proto::Type> exportIntegerType(mlir::Type mlirType,
114115
115116 auto type = std::make_unique<proto::Type>();
116117 type->set_allocated_bool_ (i1Type.release ());
117- return std::move ( type) ;
118+ return type;
118119 }
119120
120121 // Handle SI8.
@@ -127,7 +128,7 @@ std::unique_ptr<proto::Type> exportIntegerType(mlir::Type mlirType,
127128
128129 auto type = std::make_unique<proto::Type>();
129130 type->set_allocated_i8 (i8Type.release ());
130- return std::move ( type) ;
131+ return type;
131132 }
132133
133134 // Handle SI6.
@@ -140,7 +141,7 @@ std::unique_ptr<proto::Type> exportIntegerType(mlir::Type mlirType,
140141
141142 auto type = std::make_unique<proto::Type>();
142143 type->set_allocated_i16 (i16Type.release ());
143- return std::move ( type) ;
144+ return type;
144145 }
145146
146147 // Handle SI32.
@@ -153,7 +154,7 @@ std::unique_ptr<proto::Type> exportIntegerType(mlir::Type mlirType,
153154
154155 auto type = std::make_unique<proto::Type>();
155156 type->set_allocated_i32 (i32Type.release ());
156- return std::move ( type) ;
157+ return type;
157158 }
158159
159160 // Handle SI64.
@@ -166,8 +167,10 @@ std::unique_ptr<proto::Type> exportIntegerType(mlir::Type mlirType,
166167
167168 auto type = std::make_unique<proto::Type>();
168169 type->set_allocated_i64 (i64Type.release ());
169- return std::move ( type) ;
170+ return type;
170171 }
172+
173+ llvm_unreachable (" We should have handled all integer types." );
171174}
172175
173176std::unique_ptr<proto::Type> exportFloatType (mlir::Type mlirType,
@@ -184,7 +187,7 @@ std::unique_ptr<proto::Type> exportFloatType(mlir::Type mlirType,
184187
185188 auto type = std::make_unique<proto::Type>();
186189 type->set_allocated_fp32 (fp32Type.release ());
187- return std::move ( type) ;
190+ return type;
188191 }
189192
190193 // Handle FP64.
@@ -197,26 +200,28 @@ std::unique_ptr<proto::Type> exportFloatType(mlir::Type mlirType,
197200
198201 auto type = std::make_unique<proto::Type>();
199202 type->set_allocated_fp64 (fp64Type.release ());
200- return std::move ( type) ;
203+ return type;
201204 }
205+
206+ llvm_unreachable (" We should have handled all float types." );
202207}
203208
204209FailureOr<std::unique_ptr<proto::Type>>
205210SubstraitExporter::exportType (Location loc, mlir::Type mlirType) {
206211 MLIRContext *context = mlirType.getContext ();
207212
208213 // Handle `IntegerType`'s.
209- if (mlirType. isa <IntegerType>()) {
214+ if (mlir:: isa<IntegerType>(mlirType )) {
210215 return exportIntegerType (mlirType, context);
211216 }
212217
213218 // Handle `FloatType`'s.
214- if (mlirType. isa <FloatType>()) {
219+ if (mlir:: isa<FloatType>(mlirType )) {
215220 return exportFloatType (mlirType, context);
216221 }
217222
218223 // Handle String.
219- if (mlirType. isa <StringType>()) {
224+ if (mlir:: isa<StringType>(mlirType )) {
220225 // TODO(ingomueller): support other nullability modes.
221226 auto stringType = std::make_unique<proto::Type::String>();
222227 stringType->set_nullability (
@@ -228,7 +233,7 @@ SubstraitExporter::exportType(Location loc, mlir::Type mlirType) {
228233 }
229234
230235 // Handle binary type.
231- if (mlirType. isa <BinaryType>()) {
236+ if (mlir:: isa<BinaryType>(mlirType )) {
232237 // TODO(ingomueller): support other nullability modes.
233238 auto binaryType = std::make_unique<proto::Type::Binary>();
234239 binaryType->set_nullability (
@@ -240,7 +245,7 @@ SubstraitExporter::exportType(Location loc, mlir::Type mlirType) {
240245 }
241246
242247 // Handle timestamp.
243- if (mlirType. isa <TimestampType>()) {
248+ if (mlir:: isa<TimestampType>(mlirType )) {
244249 // TODO(ingomueller): support other nullability modes.
245250 auto timestampType = std::make_unique<proto::Type::Timestamp>();
246251 timestampType->set_nullability (
@@ -252,7 +257,7 @@ SubstraitExporter::exportType(Location loc, mlir::Type mlirType) {
252257 }
253258
254259 // Handle timestampe_tz.
255- if (mlirType. isa <TimestampTzType>()) {
260+ if (mlir:: isa<TimestampTzType>(mlirType )) {
256261 // TODO(ingomueller): support other nullability modes.
257262 auto timestampTzType = std::make_unique<proto::Type::TimestampTZ>();
258263 timestampTzType->set_nullability (
@@ -619,20 +624,20 @@ SubstraitExporter::exportOperation(LiteralOp op) {
619624 op->emitOpError (" has integer value with unsupported signedness" );
620625 switch (intType.getWidth ()) {
621626 case 1 :
622- literal->set_boolean (value. cast <IntegerAttr>().getSInt ());
627+ literal->set_boolean (mlir:: cast<IntegerAttr>(value ).getSInt ());
623628 break ;
624629 case 8 :
625- literal->set_i8 (value. cast <IntegerAttr>().getSInt ());
630+ literal->set_i8 (mlir:: cast<IntegerAttr>(value ).getSInt ());
626631 break ;
627632 case 16 :
628- literal->set_i16 (value. cast <IntegerAttr>().getSInt ());
633+ literal->set_i16 (mlir:: cast<IntegerAttr>(value ).getSInt ());
629634 break ;
630635 case 32 :
631636 // TODO(ingomueller): Add tests when we can express plans that use i32.
632- literal->set_i32 (value. cast <IntegerAttr>().getSInt ());
637+ literal->set_i32 (mlir:: cast<IntegerAttr>(value ).getSInt ());
633638 break ;
634639 case 64 :
635- literal->set_i64 (value. cast <IntegerAttr>().getSInt ());
640+ literal->set_i64 (mlir:: cast<IntegerAttr>(value ).getSInt ());
636641 break ;
637642 default :
638643 op->emitOpError (" has integer value with unsupported width" );
@@ -642,29 +647,29 @@ SubstraitExporter::exportOperation(LiteralOp op) {
642647 else if (auto floatType = dyn_cast<FloatType>(literalType)) {
643648 switch (floatType.getWidth ()) {
644649 case 32 :
645- literal->set_fp32 (value. cast <FloatAttr>().getValueAsDouble ());
650+ literal->set_fp32 (mlir:: cast<FloatAttr>(value ).getValueAsDouble ());
646651 break ;
647652 case 64 :
648653 // TODO(ingomueller): Add tests when we can express plans that use i32.
649- literal->set_fp64 (value. cast <FloatAttr>().getValueAsDouble ());
654+ literal->set_fp64 (mlir:: cast<FloatAttr>(value ).getValueAsDouble ());
650655 break ;
651656 default :
652657 op->emitOpError (" has float value with unsupported width" );
653658 }
654659 }
655660 // `StringType`.
656661 else if (auto stringType = dyn_cast<StringType>(literalType)) {
657- literal->set_string (value. cast <StringAttr>().getValue ().str ());
662+ literal->set_string (mlir:: cast<StringAttr>(value ).getValue ().str ());
658663 }
659664 // `BinaryType`.
660665 else if (auto binaryType = dyn_cast<BinaryType>(literalType)) {
661- literal->set_binary (value. cast <StringAttr>().getValue ().str ());
666+ literal->set_binary (mlir:: cast<StringAttr>(value ).getValue ().str ());
662667 }
663668 // `TimestampType`s.
664- else if (literalType. isa <TimestampType>()) {
665- literal->set_timestamp (value. cast <TimestampAttr>().getValue ());
666- } else if (literalType. isa <TimestampTzType>()) {
667- literal->set_timestamp_tz (value. cast <TimestampTzAttr>().getValue ());
669+ else if (auto timestampType = dyn_cast <TimestampType>(literalType )) {
670+ literal->set_timestamp (mlir:: cast<TimestampAttr>(value ).getValue ());
671+ } else if (auto timestampTzType = dyn_cast <TimestampTzType>(literalType )) {
672+ literal->set_timestamp_tz (mlir:: cast<TimestampTzAttr>(value ).getValue ());
668673 }
669674 // `DateType`.
670675 else if (auto dateType = dyn_cast<DateType>(literalType)) {
@@ -731,7 +736,7 @@ SubstraitExporter::exportOperation(NamedTableOp op) {
731736 auto namedStruct = std::make_unique<NamedStruct>();
732737 namedStruct->set_allocated_struct_ (struct_.release ());
733738 for (Attribute attr : op.getFieldNames ()) {
734- namedStruct->add_names (attr. cast <StringAttr>().getValue ().str ());
739+ namedStruct->add_names (mlir:: cast<StringAttr>(attr ).getValue ().str ());
735740 }
736741
737742 // Build `ReadRel` message.
0 commit comments