nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: googleapis/api-linter
Pull request #900 (2021-11-11 13:23:22)

refactor: add MethodOption location function


Patch:
diff --git a/locations/method_locations.go b/locations/method_locations.go
index 116f7f3..1756be5 100644
--- a/locations/method_locations.go
+++ b/locations/method_locations.go
@@ -34,13 +34,13 @@ func MethodResponseType(m *desc.MethodDescriptor) *dpb.SourceCodeInfo_Location {
 // MethodHTTPRule returns the precise location of the method's `google.api.http`
 // rule, if any.
 func MethodHTTPRule(m *desc.MethodDescriptor) *dpb.SourceCodeInfo_Location {
-	return pathLocation(m, 4, int(apb.E_Http.TypeDescriptor().Number())) // MethodDescriptor.options == 4
+	return MethodOption(m, int(apb.E_Http.TypeDescriptor().Number()))
 }
 
 // MethodOperationInfo returns the precise location of the method's
 // `google.longrunning.operation_info` annotation, if any.
 func MethodOperationInfo(m *desc.MethodDescriptor) *dpb.SourceCodeInfo_Location {
-	return pathLocation(m, 4, int(lrpb.E_OperationInfo.TypeDescriptor().Number())) // MethodDescriptor.options == 4
+	return MethodOption(m, int(lrpb.E_OperationInfo.TypeDescriptor().Number()))
 }
 
 // MethodSignature returns the precise location of the method's
@@ -48,3 +48,8 @@ func MethodOperationInfo(m *desc.MethodDescriptor) *dpb.SourceCodeInfo_Location
 func MethodSignature(m *desc.MethodDescriptor, index int) *dpb.SourceCodeInfo_Location {
 	return pathLocation(m, 4, int(apb.E_MethodSignature.TypeDescriptor().Number()), index) // MethodDescriptor.options == 4
 }
+
+// MethodOption returns the precise location of the method's option with the given field number, if any.
+func MethodOption(m *desc.MethodDescriptor, fieldNumber int) *dpb.SourceCodeInfo_Location {
+	return pathLocation(m, 4, fieldNumber) // MethodDescriptor.options == 4
+}


Test patch:
diff --git a/locations/method_locations_test.go b/locations/method_locations_test.go
index 48b40e5..7e67096 100644
--- a/locations/method_locations_test.go
+++ b/locations/method_locations_test.go
@@ -117,3 +117,34 @@ func TestMethodSignature(t *testing.T) {
 		}
 	}
 }
+
+func TestMethodOption(t *testing.T) {
+	f := parse(t, `
+		service Library {
+		  rpc GetBook(GetBookRequest) returns (Book) {
+		    option deprecated = true;
+		  }
+		  rpc UpdateBook(UpdateBookRequest) returns (Book) {}
+		}
+		message GetBookRequest{}
+		message Book {}
+		message UpdateBookRequest {}
+	`)
+
+	for _, test := range []struct {
+		name      string
+		methodIdx int
+		want      []int32
+	}{
+		{"OptionSet", 0, []int32{4, 4, 29}},
+		{"OptionNotSet", 1, nil},
+	} {
+		t.Run(test.name, func(t *testing.T) {
+			// field number of the deprecated option == 33
+			loc := MethodOption(f.GetServices()[0].GetMethods()[test.methodIdx], 33)
+			if diff := cmp.Diff(loc.GetSpan(), test.want); diff != "" {
+				t.Errorf("Diff: %s", diff)
+			}
+		})
+	}
+}
Repository: googleapis/api-linter
Pull request #918 (2022-01-11 14:35:44)

chore: add location helper for `cc_enable_arenas` file option
Signed-off-by: Maxim Tschumak <maxim.tschumak@gmail.com>


Patch:
diff --git a/locations/file_locations.go b/locations/file_locations.go
index 5e16220..c0483d7 100644
--- a/locations/file_locations.go
+++ b/locations/file_locations.go
@@ -84,3 +84,8 @@ func FileResourceDefinition(f *desc.FileDescriptor, index int) *dpb.SourceCodeIn
 func FileImport(f *desc.FileDescriptor, index int) *dpb.SourceCodeInfo_Location {
 	return pathLocation(f, 3, index) // 3 == dependency
 }
+
+// FileCCEnableArenas returns the location of the `cc_enable_arenas` option.
+func FileCCEnableArenas(f *desc.FileDescriptor) *dpb.SourceCodeInfo_Location {
+	return pathLocation(f, 8, 31) // 8 == (file) options, 31 == cc_enable_arenas
+}


Test patch:
diff --git a/locations/file_locations_test.go b/locations/file_locations_test.go
index 727b02a..b554de3 100644
--- a/locations/file_locations_test.go
+++ b/locations/file_locations_test.go
@@ -36,6 +36,7 @@ func TestLocations(t *testing.T) {
 		option java_package = "com.google.api.linter";
 		option php_namespace = "Google\\Api\\Linter";
 		option ruby_package = "Google::Api::Linter";
+		option cc_enable_arenas = false;
 
 		message Foo {
 			string bar = 1;
@@ -85,6 +86,11 @@ func TestLocations(t *testing.T) {
 				idx:      0,
 				wantSpan: []int32{3, 0, int32(len(`import "google/api/resource.proto";`))},
 			},
+			{
+				testName: "CCEnableArenas",
+				fx:       FileCCEnableArenas,
+				wantSpan: []int32{11, 0, int32(len(`option cc_enable_arenas = false;`))},
+			},
 		}
 		for _, test := range tests {
 			t.Run(test.testName, func(t *testing.T) {
Repository: jax-ml/jax
Pull request #25419 (2024-12-11 20:02:46)

jax.lax: raise TypeError for mismatched dtypes
This currently results in a verbose jaxpr verifyer error. It looks like this regressed in #16419.

Current behavior:
```python
>>> jax.lax.add(0, 0.0)
...
ValueError: Cannot lower jaxpr with verifier errors:
	op requires the same element type for all operands and results
		at loc("jit(add)/jit(main)/add"(callsite("<module>"("<ipython-input-2-fff9f9eef5ff>":1:0) at callsite("InteractiveShell.run_code"("/lib/python3.12/site-packages/IPython/core/interactiveshell.py":3577:20) at callsite("InteractiveShell.run_ast_nodes"("/lib/python3.12/site-packages/IPython/core/interactiveshell.py":3517:19) at callsite("InteractiveShell.run_cell_async"("/lib/python3.12/site-packages/IPython/core/interactiveshell.py":3334:29) at callsite("_pseudo_sync_runner"("/lib/python3.12/site-packages/IPython/core/async_helpers.py":129:8) at callsite("InteractiveShell._run_cell"("/lib/python3.12/site-packages/IPython/core/interactiveshell.py":3130:21) at callsite("InteractiveShell.run_cell"("/lib/python3.12/site-packages/IPython/core/interactiveshell.py":3075:21) at callsite("TerminalInteractiveShell.interact"("/lib/python3.12/site-packages/IPython/terminal/interactiveshell.py":910:20) at callsite("TerminalInteractiveShell.mainloop"("/lib/python3.12/site-packages/IPython/terminal/interactiveshell.py":917:16) at "TerminalIPythonApp.start"("/lib/python3.12/site-packages/IPython/terminal/ipapp.py":317:12))))))))))))
Define JAX_DUMP_IR_TO to dump the module.
```
Behavior after this PR
```python
>>> jax.lax.add(0, 0.0)
...
TypeError: lax.add requires arguments to have the same dtypes, got int32, float32. (Tip: jnp.add is a similar function that does automatic type promotion on inputs).
```


Patch:
diff --git a/jax/_src/lax/lax.py b/jax/_src/lax/lax.py
index 84b936e97..e8227eed0 100644
--- a/jax/_src/lax/lax.py
+++ b/jax/_src/lax/lax.py
@@ -2209,7 +2209,7 @@ def broadcasting_sharding_rule(name, *avals):
 
 
 def naryop(result_dtype, accepted_dtypes, name, allow_extended_dtype=False,
-           require_same_dtypes=False):
+           require_same_dtypes=True):
   dtype_rule = partial(naryop_dtype_rule, result_dtype, accepted_dtypes, name,
                        allow_extended_dtype=allow_extended_dtype,
                        require_same=require_same_dtypes)


Test patch:
diff --git a/tests/lax_test.py b/tests/lax_test.py
index 89d41d0b9..b3c436183 100644
--- a/tests/lax_test.py
+++ b/tests/lax_test.py
@@ -3366,6 +3366,12 @@ class LaxTest(jtu.JaxTestCase):
     with self.assertRaisesRegex(TypeError, ".*does not accept dtype complex.*"):
       op(2+3j, 4+5j)
 
+  @parameterized.parameters([lax.add, lax.mul, lax.div, lax.rem, lax.lt, lax.gt,
+                             lax.ge, lax.le, lax.eq, lax.ne])
+  def test_ops_error_on_mismatched_dtypes(self, op):
+    with self.assertRaisesRegex(TypeError, ".*requires arguments to have the same dtypes.*"):
+      op(0, 0.0)
+
   def test_population_count_booleans_not_supported(self):
     # https://github.com/jax-ml/jax/issues/3886
     msg = "population_count does not accept dtype bool"