From 97505013c6a9bdae6d069234be007f07e9779a76 Mon Sep 17 00:00:00 2001 From: Geoffrey Martin-Noble Date: Thu, 30 May 2019 11:01:17 -0700 Subject: [PATCH] Make getRank abort for unranked type This better matches the other methods in ShapedType which only make sense for ranked types. There's now an explicit hasRank for checking the rank. Actual call sites rarely used the "-1" sentinel to combine checking for rankedness and checking that rank is a certain value. And in most cases they should actually be checking for rankedness at a higher level using type predicates. Using an explicit method is clearer than a sentinel anyway. -- PiperOrigin-RevId: 250720853 --- mlir/include/mlir/IR/StandardTypes.h | 2 +- mlir/lib/IR/StandardTypes.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mlir/include/mlir/IR/StandardTypes.h b/mlir/include/mlir/IR/StandardTypes.h index 867fb8d00b24..ea88768dd65f 100644 --- a/mlir/include/mlir/IR/StandardTypes.h +++ b/mlir/include/mlir/IR/StandardTypes.h @@ -199,7 +199,7 @@ public: /// If this is a ranked type, return the number of elements. Otherwise, abort. unsigned getNumElements() const; - /// If this is a ranked type, return the rank. Otherwise, return -1. + /// If this is a ranked type, return the rank. Otherwise, abort. int64_t getRank() const; /// Whether or not this is a ranked type. Vector and ranked tensors have a diff --git a/mlir/lib/IR/StandardTypes.cpp b/mlir/lib/IR/StandardTypes.cpp index 300cec94251d..78a39de10609 100644 --- a/mlir/lib/IR/StandardTypes.cpp +++ b/mlir/lib/IR/StandardTypes.cpp @@ -125,7 +125,8 @@ unsigned ShapedType::getNumElements() const { } int64_t ShapedType::getRank() const { - return hasRank() ? getShape().size() : -1; + assert(hasRank()); + return getShape().size(); } bool ShapedType::hasRank() const { return !isa(); }