@@ -3488,36 +3488,32 @@ void mlir::python::populateIRCore(py::module &m) {
3488
3488
kValueDunderStrDocstring )
3489
3489
.def (
3490
3490
" get_name" ,
3491
- [](PyValue &self, std::optional<bool > useLocalScope,
3492
- std::optional<std::reference_wrapper<PyAsmState>> state) {
3491
+ [](PyValue &self, bool useLocalScope) {
3493
3492
PyPrintAccumulator printAccum;
3494
- MlirOpPrintingFlags flags;
3495
- MlirAsmState valueState;
3496
- // Use state if provided, else create a new state.
3497
- if (state) {
3498
- valueState = state.value ().get ().get ();
3499
- // Don't allow setting using local scope and state at same time.
3500
- if (useLocalScope.has_value ())
3501
- throw py::value_error (
3502
- " setting AsmState and local scope together not supported" );
3503
- } else {
3504
- flags = mlirOpPrintingFlagsCreate ();
3505
- if (useLocalScope.value_or (false ))
3506
- mlirOpPrintingFlagsUseLocalScope (flags);
3507
- valueState = mlirAsmStateCreateForValue (self.get (), flags);
3508
- }
3493
+ MlirOpPrintingFlags flags = mlirOpPrintingFlagsCreate ();
3494
+ if (useLocalScope)
3495
+ mlirOpPrintingFlagsUseLocalScope (flags);
3496
+ MlirAsmState valueState =
3497
+ mlirAsmStateCreateForValue (self.get (), flags);
3498
+ mlirValuePrintAsOperand (self.get (), valueState,
3499
+ printAccum.getCallback (),
3500
+ printAccum.getUserData ());
3501
+ mlirOpPrintingFlagsDestroy (flags);
3502
+ mlirAsmStateDestroy (valueState);
3503
+ return printAccum.join ();
3504
+ },
3505
+ py::arg (" use_local_scope" ) = false )
3506
+ .def (
3507
+ " get_name" ,
3508
+ [](PyValue &self, std::reference_wrapper<PyAsmState> state) {
3509
+ PyPrintAccumulator printAccum;
3510
+ MlirAsmState valueState = state.get ().get ();
3509
3511
mlirValuePrintAsOperand (self.get (), valueState,
3510
3512
printAccum.getCallback (),
3511
3513
printAccum.getUserData ());
3512
- // Release state if allocated locally.
3513
- if (!state) {
3514
- mlirOpPrintingFlagsDestroy (flags);
3515
- mlirAsmStateDestroy (valueState);
3516
- }
3517
3514
return printAccum.join ();
3518
3515
},
3519
- py::arg (" use_local_scope" ) = std::nullopt,
3520
- py::arg (" state" ) = std::nullopt, kGetNameAsOperand )
3516
+ py::arg (" state" ), kGetNameAsOperand )
3521
3517
.def_property_readonly (
3522
3518
" type" , [](PyValue &self) { return mlirValueGetType (self.get ()); })
3523
3519
.def (
0 commit comments