[mlir/unittests] Use std::nullopt instead of None (NFC)

This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
This commit is contained in:
Kazu Hirata 2022-12-03 19:07:59 -08:00
parent 043aa1dbba
commit 3a77eb6698
5 changed files with 31 additions and 30 deletions

View File

@ -18,13 +18,13 @@ using namespace mlir;
using namespace mlir::detail;
static Operation *createOp(MLIRContext *context,
ArrayRef<Value> operands = llvm::None,
ArrayRef<Type> resultTypes = llvm::None,
ArrayRef<Value> operands = std::nullopt,
ArrayRef<Type> resultTypes = std::nullopt,
unsigned int numRegions = 0) {
context->allowUnregisteredDialects();
return Operation::create(UnknownLoc::get(context),
OperationName("foo.bar", context), resultTypes,
operands, llvm::None, llvm::None, numRegions);
operands, std::nullopt, std::nullopt, numRegions);
}
namespace {
@ -33,7 +33,7 @@ TEST(OperandStorageTest, NonResizable) {
Builder builder(&context);
Operation *useOp =
createOp(&context, /*operands=*/llvm::None, builder.getIntegerType(16));
createOp(&context, /*operands=*/std::nullopt, builder.getIntegerType(16));
Value operand = useOp->getResult(0);
// Create a non-resizable operation with one operand.
@ -44,7 +44,7 @@ TEST(OperandStorageTest, NonResizable) {
EXPECT_EQ(user->getNumOperands(), 1u);
// Removing is okay.
user->setOperands(llvm::None);
user->setOperands(std::nullopt);
EXPECT_EQ(user->getNumOperands(), 0u);
// Destroy the operations.
@ -57,7 +57,7 @@ TEST(OperandStorageTest, Resizable) {
Builder builder(&context);
Operation *useOp =
createOp(&context, /*operands=*/llvm::None, builder.getIntegerType(16));
createOp(&context, /*operands=*/std::nullopt, builder.getIntegerType(16));
Value operand = useOp->getResult(0);
// Create a resizable operation with one operand.
@ -68,7 +68,7 @@ TEST(OperandStorageTest, Resizable) {
EXPECT_EQ(user->getNumOperands(), 1u);
// Removing is okay.
user->setOperands(llvm::None);
user->setOperands(std::nullopt);
EXPECT_EQ(user->getNumOperands(), 0u);
// Adding more operands is okay.
@ -85,7 +85,7 @@ TEST(OperandStorageTest, RangeReplace) {
Builder builder(&context);
Operation *useOp =
createOp(&context, /*operands=*/llvm::None, builder.getIntegerType(16));
createOp(&context, /*operands=*/std::nullopt, builder.getIntegerType(16));
Value operand = useOp->getResult(0);
// Create a resizable operation with one operand.
@ -121,7 +121,7 @@ TEST(OperandStorageTest, MutableRange) {
Builder builder(&context);
Operation *useOp =
createOp(&context, /*operands=*/llvm::None, builder.getIntegerType(16));
createOp(&context, /*operands=*/std::nullopt, builder.getIntegerType(16));
Value operand = useOp->getResult(0);
// Create a resizable operation with one operand.
@ -158,7 +158,8 @@ TEST(OperandStorageTest, RangeErase) {
Builder builder(&context);
Type type = builder.getNoneType();
Operation *useOp = createOp(&context, /*operands=*/llvm::None, {type, type});
Operation *useOp =
createOp(&context, /*operands=*/std::nullopt, {type, type});
Value operand1 = useOp->getResult(0);
Value operand2 = useOp->getResult(1);
@ -188,9 +189,9 @@ TEST(OperationOrderTest, OrderIsAlwaysValid) {
MLIRContext context;
Builder builder(&context);
Operation *containerOp =
createOp(&context, /*operands=*/llvm::None, /*resultTypes=*/llvm::None,
/*numRegions=*/1);
Operation *containerOp = createOp(&context, /*operands=*/std::nullopt,
/*resultTypes=*/std::nullopt,
/*numRegions=*/1);
Region &region = containerOp->getRegion(0);
Block *block = new Block();
region.push_back(block);

View File

@ -65,7 +65,7 @@ TEST(AnalysisManagerTest, FineGrainFunctionAnalysisPreservation) {
OwningOpRef<ModuleOp> module(ModuleOp::create(UnknownLoc::get(&context)));
func::FuncOp func1 =
func::FuncOp::create(builder.getUnknownLoc(), "foo",
builder.getFunctionType(llvm::None, llvm::None));
builder.getFunctionType(std::nullopt, std::nullopt));
func1.setPrivate();
module->push_back(func1);
@ -96,7 +96,7 @@ TEST(AnalysisManagerTest, FineGrainChildFunctionAnalysisPreservation) {
OwningOpRef<ModuleOp> module(ModuleOp::create(UnknownLoc::get(&context)));
func::FuncOp func1 =
func::FuncOp::create(builder.getUnknownLoc(), "foo",
builder.getFunctionType(llvm::None, llvm::None));
builder.getFunctionType(std::nullopt, std::nullopt));
func1.setPrivate();
module->push_back(func1);

View File

@ -60,9 +60,9 @@ TEST(PassManagerTest, OpSpecificAnalysis) {
// Create a module with 2 functions.
OwningOpRef<ModuleOp> module(ModuleOp::create(UnknownLoc::get(&context)));
for (StringRef name : {"secret", "not_secret"}) {
auto func =
func::FuncOp::create(builder.getUnknownLoc(), name,
builder.getFunctionType(llvm::None, llvm::None));
auto func = func::FuncOp::create(
builder.getUnknownLoc(), name,
builder.getFunctionType(std::nullopt, std::nullopt));
func.setPrivate();
module->push_back(func);
}

View File

@ -56,7 +56,7 @@ TEST(EnumsGenTest, GeneratedSymbolToStringFn) {
TEST(EnumsGenTest, GeneratedStringToSymbolFn) {
EXPECT_EQ(llvm::Optional<FooEnum>(FooEnum::CaseA), ConvertToEnum("CaseA"));
EXPECT_EQ(llvm::Optional<FooEnum>(FooEnum::CaseB), ConvertToEnum("CaseB"));
EXPECT_EQ(llvm::None, ConvertToEnum("X"));
EXPECT_EQ(std::nullopt, ConvertToEnum("X"));
}
TEST(EnumsGenTest, GeneratedUnderlyingType) {
@ -94,10 +94,10 @@ TEST(EnumsGenTest, GeneratedStringToSymbolForBitEnum) {
EXPECT_EQ(symbolizeBitEnumWithNone("Bit3|Bit0"),
BitEnumWithNone::Bit3 | BitEnumWithNone::Bit0);
EXPECT_EQ(symbolizeBitEnumWithNone("Bit2"), llvm::None);
EXPECT_EQ(symbolizeBitEnumWithNone("Bit3 | Bit4"), llvm::None);
EXPECT_EQ(symbolizeBitEnumWithNone("Bit2"), std::nullopt);
EXPECT_EQ(symbolizeBitEnumWithNone("Bit3 | Bit4"), std::nullopt);
EXPECT_EQ(symbolizeBitEnumWithoutNone("None"), llvm::None);
EXPECT_EQ(symbolizeBitEnumWithoutNone("None"), std::nullopt);
}
TEST(EnumsGenTest, GeneratedSymbolToStringFnForGroupedBitEnum) {
@ -115,7 +115,7 @@ TEST(EnumsGenTest, GeneratedSymbolToStringFnForGroupedBitEnum) {
TEST(EnumsGenTest, GeneratedStringToSymbolForGroupedBitEnum) {
EXPECT_EQ(symbolizeBitEnumWithGroup("Bit0"), BitEnumWithGroup::Bit0);
EXPECT_EQ(symbolizeBitEnumWithGroup("Bit3"), BitEnumWithGroup::Bit3);
EXPECT_EQ(symbolizeBitEnumWithGroup("Bit5"), llvm::None);
EXPECT_EQ(symbolizeBitEnumWithGroup("Bit5"), std::nullopt);
EXPECT_EQ(symbolizeBitEnumWithGroup("Bit3|Bit0"),
BitEnumWithGroup::Bit3 | BitEnumWithGroup::Bit0);
}

View File

@ -14,8 +14,8 @@ using namespace mlir;
static Operation *createOp(MLIRContext *context) {
context->allowUnregisteredDialects();
return Operation::create(UnknownLoc::get(context),
OperationName("foo.bar", context), llvm::None,
llvm::None, llvm::None, llvm::None, 0);
OperationName("foo.bar", context), std::nullopt,
std::nullopt, std::nullopt, std::nullopt, 0);
}
namespace {
@ -39,7 +39,7 @@ TEST(DialectConversionTest, DynamicallyLegalOpCallbackOrder) {
int callbackCalled2 = 0;
target.addDynamicallyLegalOp<DummyOp>([&](Operation *) -> Optional<bool> {
callbackCalled2 = ++index;
return llvm::None;
return std::nullopt;
});
auto *op = createOp(&context);
@ -60,7 +60,7 @@ TEST(DialectConversionTest, DynamicallyLegalOpCallbackSkip) {
int callbackCalled = 0;
target.addDynamicallyLegalOp<DummyOp>([&](Operation *) -> Optional<bool> {
callbackCalled = ++index;
return llvm::None;
return std::nullopt;
});
auto *op = createOp(&context);
@ -85,7 +85,7 @@ TEST(DialectConversionTest, DynamicallyLegalUnknownOpCallbackOrder) {
int callbackCalled2 = 0;
target.markUnknownOpDynamicallyLegal([&](Operation *) -> Optional<bool> {
callbackCalled2 = ++index;
return llvm::None;
return std::nullopt;
});
auto *op = createOp(&context);
@ -103,7 +103,7 @@ TEST(DialectConversionTest, DynamicallyLegalReturnNone) {
ConversionTarget target(context);
target.addDynamicallyLegalOp<DummyOp>(
[&](Operation *) -> Optional<bool> { return llvm::None; });
[&](Operation *) -> Optional<bool> { return std::nullopt; });
auto *op = createOp(&context);
EXPECT_FALSE(target.isLegal(op));
@ -120,7 +120,7 @@ TEST(DialectConversionTest, DynamicallyLegalUnknownReturnNone) {
ConversionTarget target(context);
target.markUnknownOpDynamicallyLegal(
[&](Operation *) -> Optional<bool> { return llvm::None; });
[&](Operation *) -> Optional<bool> { return std::nullopt; });
auto *op = createOp(&context);
EXPECT_FALSE(target.isLegal(op));