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) {
28402840
28412841 if (count == 0 )
28422842 return mlirLocationUnknownGet (ctx);
2843- if (count == 1 )
2844- return frames[0 ];
28452843
28462844 MlirLocation callee = frames[0 ];
2845+ assert (!mlirLocationIsNull (callee) && " expected non-null callee location" );
2846+ if (count == 1 )
2847+ return callee;
2848+
28472849 MlirLocation caller = frames[count - 1 ];
2850+ assert (!mlirLocationIsNull (caller) && " expected non-null caller location" );
28482851 for (int i = count - 2 ; i >= 1 ; i--)
28492852 caller = mlirLocationCallSiteGet (frames[i], caller);
28502853
@@ -3134,10 +3137,10 @@ void mlir::python::populateIRCore(nb::module_ &m) {
31343137 .def (" __eq__" , [](PyLocation &self, nb::object other) { return false ; })
31353138 .def_prop_ro_static (
31363139 " current" ,
3137- [](nb::object & /* class*/ ) {
3140+ [](nb::object & /* class*/ ) -> std::optional<PyLocation *> {
31383141 auto *loc = PyThreadContextEntry::getDefaultLocation ();
31393142 if (!loc)
3140- throw nb::value_error ( " No current Location " ) ;
3143+ return std:: nullopt ;
31413144 return loc;
31423145 },
31433146 " 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(
7878def get_default_loc_context (location = None ):
7979 """
8080 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.
8382 """
8483 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
8787 return location .context
8888
8989
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ def with_infer_location():
2525# CHECK-LABEL: TEST: testInferLocations
2626@run
2727def testInferLocations ():
28- with Context () as ctx , Location . unknown (), with_infer_location ():
28+ with Context () as ctx , with_infer_location ():
2929 ctx .allow_unregistered_dialects = True
3030
3131 op = Operation .create ("custom.op1" )
You can’t perform that action at this time.
0 commit comments