@@ -1300,6 +1300,11 @@ if (!dict) {
1300
1300
emitError() << "expected DictionaryAttr to set properties";
1301
1301
return ::mlir::failure();
1302
1302
}
1303
+ // keep track of used keys in the input dictionary to be able to error out
1304
+ // if there are some unknown ones.
1305
+ DenseSet<StringAttr> usedKeys;
1306
+ MLIRContext *ctx = dict.getContext();
1307
+ (void)ctx;
1303
1308
)decl" ;
1304
1309
1305
1310
// {0}: fromAttribute call
@@ -1310,7 +1315,9 @@ auto setFromAttr = [] (auto &propStorage, ::mlir::Attribute propAttr,
1310
1315
::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) -> ::mlir::LogicalResult {{
1311
1316
{0};
1312
1317
};
1313
- auto attr = dict.get("{1}");
1318
+ auto {1}AttrName = StringAttr::get(ctx, "{1}");
1319
+ usedKeys.insert({1}AttrName);
1320
+ auto attr = dict.get({1}AttrName);
1314
1321
if (!attr && {2}) {{
1315
1322
emitError() << "expected key entry for {1} in DictionaryAttr to set "
1316
1323
"Properties.";
@@ -1356,7 +1363,9 @@ if (attr && ::mlir::failed(setFromAttr(prop.{1}, attr, emitError)))
1356
1363
bool isRequired = !attr.isOptional () && !attr.hasDefaultValue ();
1357
1364
body << formatv (R"decl(
1358
1365
auto &propStorage = prop.{0};
1359
- auto attr = dict.get("{0}");
1366
+ auto {0}AttrName = StringAttr::get(ctx, "{0}");
1367
+ auto attr = dict.get({0}AttrName);
1368
+ usedKeys.insert(StringAttr::get(ctx, "{1}"));
1360
1369
if (attr || /*isRequired=*/{1}) {{
1361
1370
if (!attr) {{
1362
1371
emitError() << "expected key entry for {0} in DictionaryAttr to set "
@@ -1374,7 +1383,14 @@ if (attr || /*isRequired=*/{1}) {{
1374
1383
)decl" ,
1375
1384
namedAttr.name , isRequired);
1376
1385
}
1377
- body << " return ::mlir::success();\n " ;
1386
+ body << R"decl(
1387
+ for (NamedAttribute attr : dict) {
1388
+ if (!usedKeys.contains(attr.getName()))
1389
+ return emitError() << "unknown key '" << attr.getName() <<
1390
+ "' when parsing properties dictionary";
1391
+ }
1392
+ return ::mlir::success();
1393
+ )decl" ;
1378
1394
}
1379
1395
1380
1396
void OperationFormat::genParser (Operator &op, OpClass &opClass) {
0 commit comments