[Mlir-commits] [mlir] [mlir][examples] Use {} instead of std::nullopt (NFC) (PR #146949)
Kazu Hirata
llvmlistbot at llvm.org
Thu Jul 3 15:14:51 PDT 2025
https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/146949
>From e123a86d673fbd421369cbda7f8af3fe9f28790c Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 3 Jul 2025 09:33:45 -0700
Subject: [PATCH 1/2] [mlir] Use {} instead of std::nullopt (NFC)
This patch fixes deprecation warnings like:
mlir/include/mlir/IR/TypeRange.h:51:19: error: 'ArrayRef' is
deprecated: Use {} or ArrayRef<T>() instead
[-Werror,-Wdeprecated-declarations]
---
mlir/examples/toy/Ch2/mlir/MLIRGen.cpp | 2 +-
mlir/examples/toy/Ch3/mlir/MLIRGen.cpp | 2 +-
mlir/examples/toy/Ch4/mlir/MLIRGen.cpp | 2 +-
mlir/examples/toy/Ch5/mlir/MLIRGen.cpp | 2 +-
mlir/examples/toy/Ch6/mlir/MLIRGen.cpp | 2 +-
mlir/examples/toy/Ch7/mlir/MLIRGen.cpp | 6 +++---
6 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp
index bf4c099fe05d2..96925bebf07b7 100644
--- a/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp
@@ -120,7 +120,7 @@ class MLIRGenImpl {
// Arguments type are uniformly unranked tensors.
llvm::SmallVector<mlir::Type, 4> argTypes(proto.getArgs().size(),
getType(VarType{}));
- auto funcType = builder.getFunctionType(argTypes, std::nullopt);
+ auto funcType = builder.getFunctionType(argTypes, {});
return builder.create<mlir::toy::FuncOp>(location, proto.getName(),
funcType);
}
diff --git a/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp
index bf4c099fe05d2..96925bebf07b7 100644
--- a/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp
@@ -120,7 +120,7 @@ class MLIRGenImpl {
// Arguments type are uniformly unranked tensors.
llvm::SmallVector<mlir::Type, 4> argTypes(proto.getArgs().size(),
getType(VarType{}));
- auto funcType = builder.getFunctionType(argTypes, std::nullopt);
+ auto funcType = builder.getFunctionType(argTypes, {});
return builder.create<mlir::toy::FuncOp>(location, proto.getName(),
funcType);
}
diff --git a/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp
index b56e2f7c90086..82955a87e8249 100644
--- a/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp
@@ -120,7 +120,7 @@ class MLIRGenImpl {
// Arguments type are uniformly unranked tensors.
llvm::SmallVector<mlir::Type, 4> argTypes(proto.getArgs().size(),
getType(VarType{}));
- auto funcType = builder.getFunctionType(argTypes, std::nullopt);
+ auto funcType = builder.getFunctionType(argTypes, {});
return builder.create<mlir::toy::FuncOp>(location, proto.getName(),
funcType);
}
diff --git a/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp
index b56e2f7c90086..82955a87e8249 100644
--- a/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp
@@ -120,7 +120,7 @@ class MLIRGenImpl {
// Arguments type are uniformly unranked tensors.
llvm::SmallVector<mlir::Type, 4> argTypes(proto.getArgs().size(),
getType(VarType{}));
- auto funcType = builder.getFunctionType(argTypes, std::nullopt);
+ auto funcType = builder.getFunctionType(argTypes, {});
return builder.create<mlir::toy::FuncOp>(location, proto.getName(),
funcType);
}
diff --git a/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp
index b56e2f7c90086..82955a87e8249 100644
--- a/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp
@@ -120,7 +120,7 @@ class MLIRGenImpl {
// Arguments type are uniformly unranked tensors.
llvm::SmallVector<mlir::Type, 4> argTypes(proto.getArgs().size(),
getType(VarType{}));
- auto funcType = builder.getFunctionType(argTypes, std::nullopt);
+ auto funcType = builder.getFunctionType(argTypes, {});
return builder.create<mlir::toy::FuncOp>(location, proto.getName(),
funcType);
}
diff --git a/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp
index e554e375209f1..4e2a4d8a8c28d 100644
--- a/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp
@@ -182,7 +182,7 @@ class MLIRGenImpl {
return nullptr;
argTypes.push_back(type);
}
- auto funcType = builder.getFunctionType(argTypes, std::nullopt);
+ auto funcType = builder.getFunctionType(argTypes, {});
return builder.create<mlir::toy::FuncOp>(location, proto.getName(),
funcType);
}
@@ -441,10 +441,10 @@ class MLIRGenImpl {
for (auto &var : lit.getValues()) {
if (auto *number = llvm::dyn_cast<NumberExprAST>(var.get())) {
attrElements.push_back(getConstantAttr(*number));
- typeElements.push_back(getType(std::nullopt));
+ typeElements.push_back(getType({}));
} else if (auto *lit = llvm::dyn_cast<LiteralExprAST>(var.get())) {
attrElements.push_back(getConstantAttr(*lit));
- typeElements.push_back(getType(std::nullopt));
+ typeElements.push_back(getType({}));
} else {
auto *structLit = llvm::cast<StructLiteralExprAST>(var.get());
auto attrTypePair = getConstantAttr(*structLit);
>From fd30e1723c06eff6e4c4a0b2a2b464f11f36faa1 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 3 Jul 2025 15:09:49 -0700
Subject: [PATCH 2/2] Address a comment.
---
mlir/examples/toy/Ch3/mlir/MLIRGen.cpp | 2 +-
mlir/examples/toy/Ch4/mlir/MLIRGen.cpp | 2 +-
mlir/examples/toy/Ch5/mlir/MLIRGen.cpp | 2 +-
mlir/examples/toy/Ch6/mlir/MLIRGen.cpp | 2 +-
mlir/examples/toy/Ch7/mlir/MLIRGen.cpp | 6 +++---
5 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp
index 96925bebf07b7..c8cba82cb63a0 100644
--- a/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp
@@ -120,7 +120,7 @@ class MLIRGenImpl {
// Arguments type are uniformly unranked tensors.
llvm::SmallVector<mlir::Type, 4> argTypes(proto.getArgs().size(),
getType(VarType{}));
- auto funcType = builder.getFunctionType(argTypes, {});
+ auto funcType = builder.getFunctionType(argTypes, /*results=*/{});
return builder.create<mlir::toy::FuncOp>(location, proto.getName(),
funcType);
}
diff --git a/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp
index 82955a87e8249..9371815577b1b 100644
--- a/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp
@@ -120,7 +120,7 @@ class MLIRGenImpl {
// Arguments type are uniformly unranked tensors.
llvm::SmallVector<mlir::Type, 4> argTypes(proto.getArgs().size(),
getType(VarType{}));
- auto funcType = builder.getFunctionType(argTypes, {});
+ auto funcType = builder.getFunctionType(argTypes, /*results=*/{});
return builder.create<mlir::toy::FuncOp>(location, proto.getName(),
funcType);
}
diff --git a/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp
index 82955a87e8249..9371815577b1b 100644
--- a/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp
@@ -120,7 +120,7 @@ class MLIRGenImpl {
// Arguments type are uniformly unranked tensors.
llvm::SmallVector<mlir::Type, 4> argTypes(proto.getArgs().size(),
getType(VarType{}));
- auto funcType = builder.getFunctionType(argTypes, {});
+ auto funcType = builder.getFunctionType(argTypes, /*results=*/{});
return builder.create<mlir::toy::FuncOp>(location, proto.getName(),
funcType);
}
diff --git a/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp
index 82955a87e8249..9371815577b1b 100644
--- a/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp
@@ -120,7 +120,7 @@ class MLIRGenImpl {
// Arguments type are uniformly unranked tensors.
llvm::SmallVector<mlir::Type, 4> argTypes(proto.getArgs().size(),
getType(VarType{}));
- auto funcType = builder.getFunctionType(argTypes, {});
+ auto funcType = builder.getFunctionType(argTypes, /*results=*/{});
return builder.create<mlir::toy::FuncOp>(location, proto.getName(),
funcType);
}
diff --git a/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp
index 4e2a4d8a8c28d..2490f17163b80 100644
--- a/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp
+++ b/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp
@@ -182,7 +182,7 @@ class MLIRGenImpl {
return nullptr;
argTypes.push_back(type);
}
- auto funcType = builder.getFunctionType(argTypes, {});
+ auto funcType = builder.getFunctionType(argTypes, /*results=*/{});
return builder.create<mlir::toy::FuncOp>(location, proto.getName(),
funcType);
}
@@ -441,10 +441,10 @@ class MLIRGenImpl {
for (auto &var : lit.getValues()) {
if (auto *number = llvm::dyn_cast<NumberExprAST>(var.get())) {
attrElements.push_back(getConstantAttr(*number));
- typeElements.push_back(getType({}));
+ typeElements.push_back(getType(/*shape=*/{}));
} else if (auto *lit = llvm::dyn_cast<LiteralExprAST>(var.get())) {
attrElements.push_back(getConstantAttr(*lit));
- typeElements.push_back(getType({}));
+ typeElements.push_back(getType(/*shape=*/{}));
} else {
auto *structLit = llvm::cast<StructLiteralExprAST>(var.get());
auto attrTypePair = getConstantAttr(*structLit);
More information about the Mlir-commits
mailing list