File tree Expand file tree Collapse file tree 3 files changed +12
-9
lines changed Expand file tree Collapse file tree 3 files changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -2840,11 +2840,14 @@ MlirLocation tracebackToLocation(MlirContext ctx) {
2840
2840
2841
2841
if (count == 0 )
2842
2842
return mlirLocationUnknownGet (ctx);
2843
- if (count == 1 )
2844
- return frames[0 ];
2845
2843
2846
2844
MlirLocation callee = frames[0 ];
2845
+ assert (!mlirLocationIsNull (callee) && " expected non-null callee location" );
2846
+ if (count == 1 )
2847
+ return callee;
2848
+
2847
2849
MlirLocation caller = frames[count - 1 ];
2850
+ assert (!mlirLocationIsNull (caller) && " expected non-null caller location" );
2848
2851
for (int i = count - 2 ; i >= 1 ; i--)
2849
2852
caller = mlirLocationCallSiteGet (frames[i], caller);
2850
2853
@@ -3134,10 +3137,10 @@ void mlir::python::populateIRCore(nb::module_ &m) {
3134
3137
.def (" __eq__" , [](PyLocation &self, nb::object other) { return false ; })
3135
3138
.def_prop_ro_static (
3136
3139
" current" ,
3137
- [](nb::object & /* class*/ ) {
3140
+ [](nb::object & /* class*/ ) -> std::optional<PyLocation *> {
3138
3141
auto *loc = PyThreadContextEntry::getDefaultLocation ();
3139
3142
if (!loc)
3140
- throw nb::value_error ( " No current Location " ) ;
3143
+ return std::nullopt ;
3141
3144
return loc;
3142
3145
},
3143
3146
" Gets the Location bound to the current thread or raises ValueError" )
Original file line number Diff line number Diff line change @@ -78,12 +78,12 @@ def equally_sized_accessor(
78
78
def get_default_loc_context (location = None ):
79
79
"""
80
80
Returns a context in which the defaulted location is created. If the location
81
- is None, takes the current location from the stack, raises ValueError if there
82
- is no location on the stack.
81
+ is None, takes the current location from the stack.
83
82
"""
84
83
if location is None :
85
- # Location.current raises ValueError if there is no current location.
86
- return _cext .ir .Location .current .context
84
+ if _cext .ir .Location .current :
85
+ return _cext .ir .Location .current .context
86
+ return None
87
87
return location .context
88
88
89
89
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ def with_infer_location():
25
25
# CHECK-LABEL: TEST: testInferLocations
26
26
@run
27
27
def testInferLocations ():
28
- with Context () as ctx , Location . unknown (), with_infer_location ():
28
+ with Context () as ctx , with_infer_location ():
29
29
ctx .allow_unregistered_dialects = True
30
30
31
31
op = Operation .create ("custom.op1" )
You can’t perform that action at this time.
0 commit comments