[Mlir-commits] [mlir] [MLIR] Auto generate source location for python bindings (PR #112923)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Oct 18 08:36:38 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {darker}-->


:warning: Python code formatter, darker found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
darker --check --diff -r a3cd269fbebecb6971e216a9c29ad8933ad7b0fc...a5437c05a96cedf538eea98b245e208b1d61d51a mlir/python/mlir/dialects/_ods_common.py mlir/test/python/ir/location.py
``````````

</details>

<details>
<summary>
View the diff from darker here.
</summary>

``````````diff
--- python/mlir/dialects/_ods_common.py	2024-10-18 15:31:51.000000 +0000
+++ python/mlir/dialects/_ods_common.py	2024-10-18 15:36:09.797132 +0000
@@ -49,39 +49,33 @@
     start = sum(segments[i] for i in range(idx))
     end = start + segments[idx]
     return elements[start:end]
 
 
-
-
 def get_source_location():
     """
     Returns a source location from the frame just before the one whose
     filename includes 'python_packages'.
     """
     frame = inspect.currentframe()
     outer_frames = inspect.getouterframes(frame)
-    
+
     # Traverse the frames in reverse order, excluding the current frame
     selected_frame = None
-    for i in range(len(outer_frames)-1, -1, -1):
+    for i in range(len(outer_frames) - 1, -1, -1):
         current_frame = outer_frames[i]
-        if 'python_packages' in current_frame.filename:
+        if "python_packages" in current_frame.filename:
             # Select the frame before the one containing 'python_packages'
-            selected_frame = outer_frames[i+1] if i-1 >= 0 else current_frame
+            selected_frame = outer_frames[i + 1] if i - 1 >= 0 else current_frame
             break
     if selected_frame is None:
         # If no frame containing 'python_packages' is found, use the last frame
         selected_frame = outer_frames[-1]
-    
+
     # Create file location using the selected frame
-    file_loc = _cext.ir.Location.file(
-            selected_frame.filename,
-            selected_frame.lineno,
-            0
-        )
-    loc = _cext.ir.Location.name(selected_frame.function, childLoc = file_loc)
+    file_loc = _cext.ir.Location.file(selected_frame.filename, selected_frame.lineno, 0)
+    loc = _cext.ir.Location.name(selected_frame.function, childLoc=file_loc)
     return loc
 
 
 def equally_sized_accessor(
     elements, n_simple, n_variadic, n_preceding_simple, n_preceding_variadic
--- test/python/ir/location.py	2024-10-18 15:31:51.000000 +0000
+++ test/python/ir/location.py	2024-10-18 15:36:09.852361 +0000
@@ -151,32 +151,33 @@
 
 
 run(testLocationCapsule)
 
 
-
 # CHECK-LABEL: TEST: autoGeneratedLocation
 def autoGeneratedLocation():
-    def generator() :
-        return arith.ConstantOp(value=123, result=IntegerType.get_signless(32)) 
+    def generator():
+        return arith.ConstantOp(value=123, result=IntegerType.get_signless(32))
+
     with Context() as ctx, Location.unknown():
         module = Module.create()
         with InsertionPoint(module.body):
             a = arith.ConstantOp(value=42, result=IntegerType.get_signless(32))
             b = arith.AddIOp(a, generator())
         module.operation.print(enable_debug_info=True)
 
-#CHECK: module {
-#CHECK:  %{{.*}} = arith.constant 42 : i32 loc(#loc4)
-#CHECK:  %{{.*}} = arith.constant 123 : i32 loc(#loc5)
-#CHECK:  %{{.*}} = arith.addi %{{.*}}, %{{.*}} : i32 loc(#loc6)
-#CHECK: } loc(#loc)
-    
-#CHECK: #loc = loc(unknown)
-#CHECK: #loc1 = loc({{.*}}:164:0)
-#CHECK: #loc2 = loc({{.*}}:160:0)
-#CHECK: #loc3 = loc({{.*}}:165:0)
-#CHECK: #loc4 = loc("autoGeneratedLocation"(#loc1))
-#CHECK: #loc5 = loc("generator"(#loc2))
-#CHECK: #loc6 = loc("autoGeneratedLocation"(#loc3))
+
+# CHECK: module {
+# CHECK:  %{{.*}} = arith.constant 42 : i32 loc(#loc4)
+# CHECK:  %{{.*}} = arith.constant 123 : i32 loc(#loc5)
+# CHECK:  %{{.*}} = arith.addi %{{.*}}, %{{.*}} : i32 loc(#loc6)
+# CHECK: } loc(#loc)
+
+# CHECK: #loc = loc(unknown)
+# CHECK: #loc1 = loc({{.*}}:164:0)
+# CHECK: #loc2 = loc({{.*}}:160:0)
+# CHECK: #loc3 = loc({{.*}}:165:0)
+# CHECK: #loc4 = loc("autoGeneratedLocation"(#loc1))
+# CHECK: #loc5 = loc("generator"(#loc2))
+# CHECK: #loc6 = loc("autoGeneratedLocation"(#loc3))
 
 run(autoGeneratedLocation)

``````````

</details>


https://github.com/llvm/llvm-project/pull/112923


More information about the Mlir-commits mailing list