nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: bazelbuild/buildtools
Pull request #557 (2019-02-18 13:10:11)

Fix ctx-actions automatic fix
If a positional argument is a binary expression but not with `=` as an operator, `MakePositional` should leave it as it is.


Patch:
diff --git a/warn/warn_bazel_api.go b/warn/warn_bazel_api.go
index bdc5a75..f81f9a0 100644
--- a/warn/warn_bazel_api.go
+++ b/warn/warn_bazel_api.go
@@ -167,7 +167,7 @@ func notLoadedFunctionUsageCheck(f *build.File, category string, globals []strin
 
 // makePositional makes the function argument positional (removes the keyword if it exists)
 func makePositional(argument build.Expr) build.Expr {
-	if binary, ok := argument.(*build.BinaryExpr); ok {
+	if binary, ok := argument.(*build.BinaryExpr); ok && binary.Op == "=" {
 		return binary.Y
 	}
 	return argument


Test patch:
diff --git a/warn/warn_bazel_api_test.go b/warn/warn_bazel_api_test.go
index d2dd851..6297963 100644
--- a/warn/warn_bazel_api_test.go
+++ b/warn/warn_bazel_api_test.go
@@ -89,7 +89,8 @@ func TestCtxActionsWarning(t *testing.T) {
 	checkFindingsAndFix(t, "ctx-actions", `
 def impl(ctx):
   ctx.new_file(foo)
-  ctx.new_file(foo, bar)
+  ctx.new_file(foo, "foo %s " % bar)
+  ctx.new_file(foo, name = bar)
   ctx.new_file(foo, bar, baz)
   ctx.experimental_new_directory(foo, bar)
   ctx.file_action(foo, bar)
@@ -103,6 +104,7 @@ def impl(ctx):
 `, `
 def impl(ctx):
   ctx.actions.declare_file(foo)
+  ctx.actions.declare_file("foo %s " % bar, sibling = foo)
   ctx.actions.declare_file(bar, sibling = foo)
   ctx.new_file(foo, bar, baz)
   ctx.actions.declare_directory(foo, bar)
@@ -119,14 +121,15 @@ def impl(ctx):
 			`:2: "ctx.new_file" is deprecated.`,
 			`:3: "ctx.new_file" is deprecated.`,
 			`:4: "ctx.new_file" is deprecated.`,
-			`:5: "ctx.experimental_new_directory" is deprecated.`,
-			`:6: "ctx.file_action" is deprecated.`,
+			`:5: "ctx.new_file" is deprecated.`,
+			`:6: "ctx.experimental_new_directory" is deprecated.`,
 			`:7: "ctx.file_action" is deprecated.`,
-			`:8: "ctx.action" is deprecated.`,
+			`:8: "ctx.file_action" is deprecated.`,
 			`:9: "ctx.action" is deprecated.`,
-			`:10: "ctx.empty_action" is deprecated.`,
-			`:11: "ctx.template_action" is deprecated.`,
+			`:10: "ctx.action" is deprecated.`,
+			`:11: "ctx.empty_action" is deprecated.`,
 			`:12: "ctx.template_action" is deprecated.`,
+			`:13: "ctx.template_action" is deprecated.`,
 		},
 		scopeEverywhere)
Repository: bazelbuild/buildtools
Pull request #563 (2019-02-26 16:09:04)

Fix out-of-order-load checks
If a symbol is loaded from not a label (a string that doesn't contain a `:`), the `out-of-order-load` check may crash with index error.

May be related to #541 


Patch:
diff --git a/warn/warn_cosmetic.go b/warn/warn_cosmetic.go
index 55cc61f..fbd5d50 100644
--- a/warn/warn_cosmetic.go
+++ b/warn/warn_cosmetic.go
@@ -135,10 +135,16 @@ func outOfOrderLoadWarning(f *build.File, fix bool) []*Finding {
 			// Either both labels have explicit repository names or both don't, compare their packages
 			// and break ties using file names if necessary
 
-			module1Parts := strings.Split(strings.TrimLeft(load1Label, "@"), ":")
-			package1, filename1 := module1Parts[0], module1Parts[1]
-			module2Parts := strings.Split(strings.TrimLeft(load2Label, "@"), ":")
-			package2, filename2 := module2Parts[0], module2Parts[1]
+			module1Parts := strings.SplitN(strings.TrimLeft(load1Label, "@"), ":", 2)
+			package1, filename1 := "", module1Parts[0]
+			if len(module1Parts) == 2 {
+				package1, filename1 = module1Parts[0], module1Parts[1]
+			}
+			module2Parts := strings.SplitN(strings.TrimLeft(load2Label, "@"), ":", 2)
+			package2, filename2 := "", module2Parts[0]
+			if len(module2Parts) == 2 {
+				package2, filename2 = module2Parts[0], module2Parts[1]
+			}
 
 			// in case both packages are the same, use file names to break ties
 			if package1 == package2 {


Test patch:
diff --git a/warn/warn_cosmetic_test.go b/warn/warn_cosmetic_test.go
index 305e079..60d4495 100644
--- a/warn/warn_cosmetic_test.go
+++ b/warn/warn_cosmetic_test.go
@@ -238,6 +238,15 @@ load("//foo:a.bzl", "a")
 load("//foo:a.bzl", "a")
 load("//foo:b.bzl", "b")`,
 		[]string{":2: Load statement is out of its lexicographical order."}, scopeBuild|scopeBzl)
+
+	checkFindingsAndFix(t, "out-of-order-load", `
+load("//foo.bzl", "foo")
+load("//bar.bzl", "bar")
+`, `
+load("//bar.bzl", "bar")
+load("//foo.bzl", "foo")
+`,
+		[]string{":2: Load statement is out of its lexicographical order."}, scopeBuild|scopeBzl)
 }
 
 func TestUnsortedDictItems(t *testing.T) {
Repository: bazelbuild/buildtools
Pull request #608 (2019-04-10 11:10:22)

Temporarily exclude `native.existing_rule` and `native.existing_rules` from the warning
These two functions still don't exist in BUILD files as builtin functions, the warning and the fix are currently not correct.

Related Bazel issue: https://github.com/bazelbuild/bazel/issues/7496


Patch:
diff --git a/warn/warn_bazel.go b/warn/warn_bazel.go
index 133defa..baafce6 100644
--- a/warn/warn_bazel.go
+++ b/warn/warn_bazel.go
@@ -62,6 +62,12 @@ func nativeInBuildFilesWarning(f *build.File, fix bool) []*Finding {
 			return nil
 		}
 
+		// TODO(https://github.com/bazelbuild/bazel/issues/7496): remove as soon as `existing_rule`
+		// and `exsisting_rules` become available in BUILD files.
+		if dot.Name == "existing_rule" || dot.Name == "existing_rules" {
+			return nil
+		}
+
 		if fix {
 			start, _ := dot.Span()
 			return &build.Ident{


Test patch:
diff --git a/warn/warn_bazel_test.go b/warn/warn_bazel_test.go
index 8d9c49d..e94969e 100644
--- a/warn/warn_bazel_test.go
+++ b/warn/warn_bazel_test.go
@@ -30,6 +30,12 @@ cc_library(name = "lib")
 		`:1: The "native" module shouldn't be used in BUILD files, its members are available as global symbols.`,
 		`:3: The "native" module shouldn't be used in BUILD files, its members are available as global symbols.`,
 	}, scopeBuild)
+
+	checkFindings(t, "native-build", `
+native.existing_rule("foo")
+
+native.existing_rules()
+`, []string{}, scopeBuild)
 }
 
 func TestNativePackage(t *testing.T) {
Repository: bazelbuild/buildtools
Pull request #697 (2019-08-09 11:31:50)

Fix false positive argument detection for function-docstring-args
If the `Returns:` section contains a line starting with `foo:` (for example, a link starting with `https://`), buildifier parses it as an argument description (and usually shows a false-positive warning for an argument which is documented but doesn't exist).


Patch:
diff --git a/warn/warn_docstring.go b/warn/warn_docstring.go
index a372ff4..443137d 100644
--- a/warn/warn_docstring.go
+++ b/warn/warn_docstring.go
@@ -69,12 +69,6 @@ type docstringInfo struct {
 	argumentsPos build.Position            // line of the `Arguments:` block (not `Args:`), if it exists
 }
 
-// docstringBlock contains a block of a docstring (separated by empty lines)
-type docstringBlock struct {
-	startLineNo int      // line number of the first line of the block
-	lines       []string // lines
-}
-
 // countLeadingSpaces returns the number of leading spaces of a string.
 func countLeadingSpaces(s string) int {
 	spaces := 0
@@ -133,6 +127,7 @@ func parseFunctionDocstring(doc *build.StringExpr) docstringInfo {
 			isArgumentsDescription = true
 			continue
 		case prefix + "Returns:":
+			isArgumentsDescription = false
 			info.returns = true
 			continue
 		}


Test patch:
diff --git a/warn/warn_docstring_test.go b/warn/warn_docstring_test.go
index d50d6c7..40dd863 100644
--- a/warn/warn_docstring_test.go
+++ b/warn/warn_docstring_test.go
@@ -178,11 +178,16 @@ func TestFunctionDocstringArgs(t *testing.T) {
 def f(x):
    """This is a function.
 
+   Documented here:
+   http://example.com
+
    Args:
-     x: something
+     x: something, as described at
+       http://example.com
 
    Returns:
-     something
+     something, as described at
+     https://example.com
    """
    pass
    pass
Repository: bazelbuild/buildtools
Pull request #709 (2019-09-04 05:32:58)

Fix typo in warning about docstrings


Patch:
diff --git a/warn/warn_control_flow.go b/warn/warn_control_flow.go
index 892a8cb..5f6462c 100644
--- a/warn/warn_control_flow.go
+++ b/warn/warn_control_flow.go
@@ -169,7 +169,7 @@ func noEffectStatementsCheck(body []build.Expr, isTopLevel, isFunc bool, finding
 
 		msg := "Expression result is not used."
 		if isString {
-			msg += " Docstrings should be the first statemensts of a file or a function (they may follow comment lines)."
+			msg += " Docstrings should be the first statements of a file or a function (they may follow comment lines)."
 		}
 		findings = append(findings, makeLinterFinding(stmt, msg))
 	}


Test patch:
diff --git a/warn/warn_control_flow_test.go b/warn/warn_control_flow_test.go
index cb4aaa5..5fae023 100644
--- a/warn/warn_control_flow_test.go
+++ b/warn/warn_control_flow_test.go
@@ -257,9 +257,9 @@ def bar():
     return foo
 `,
 		[]string{
-			":7: Expression result is not used. Docstrings should be the first statemensts of a file or a function (they may follow comment lines).",
+			":7: Expression result is not used. Docstrings should be the first statements of a file or a function (they may follow comment lines).",
 			":11: Expression result is not used.",
-			":12: Expression result is not used. Docstrings should be the first statemensts of a file or a function (they may follow comment lines).",
+			":12: Expression result is not used. Docstrings should be the first statements of a file or a function (they may follow comment lines).",
 		}, scopeEverywhere)
 
 	checkFindings(t, "no-effect", `
Repository: bazelbuild/buildtools
Pull request #720 (2019-09-17 14:30:00)

Allow string escapes for raw strings
The `string-escape` check shouldn't be applied to raw string literals.


Patch:
diff --git a/warn/warn_operation.go b/warn/warn_operation.go
index 9fdcfab..30c7c26 100644
--- a/warn/warn_operation.go
+++ b/warn/warn_operation.go
@@ -117,10 +117,11 @@ func stringEscapeWarning(f *build.File) []*LinterFinding {
 
 	build.WalkPointers(f, func(expr *build.Expr, stack []build.Expr) {
 		str, ok := (*expr).(*build.StringExpr)
-		if !ok || len(str.Token) == 0 {
+		if !ok || len(str.Token) == 0 || strings.HasPrefix(str.Token, "r") {
 			// String literals with empty Token field may appear if they are manually created StringExpr nodes
 			// (token is only used as a hint to the printer, if it doesn't exist, the Value field is used to
 			// generate the string literal).
+			// Raw strings are allowed to have backslashes anywhere.
 			return
 		}
 


Test patch:
diff --git a/warn/warn_operation_test.go b/warn/warn_operation_test.go
index 0ef7497..c70292e 100644
--- a/warn/warn_operation_test.go
+++ b/warn/warn_operation_test.go
@@ -136,4 +136,18 @@ func TestStringEscape(t *testing.T) {
 `,
 		},
 		scopeEverywhere)
+
+	checkFindings(t, "string-escape", `
+r'foo'
+r'\\foo\\"bar"\\'
+r"\foo"
+r'"\foo"\\\bar'
+
+r'''
+"asdf"
+\a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x43\y\z\0\1\2\3\4\5\6\7\8\9
+'''
+`,
+		[]string{},
+		scopeEverywhere)
 }
Repository: bazelbuild/buildtools
Pull request #725 (2019-10-02 16:20:00)

Enable 'load-on-top' for BUILD files


Patch:
diff --git a/warn/warn_cosmetic.go b/warn/warn_cosmetic.go
index d0aac29..4172f36 100644
--- a/warn/warn_cosmetic.go
+++ b/warn/warn_cosmetic.go
@@ -113,8 +113,8 @@ func packageOnTopWarning(f *build.File) []*LinterFinding {
 }
 
 func loadOnTopWarning(f *build.File) []*LinterFinding {
-	if f.Type != build.TypeDefault && f.Type != build.TypeBzl {
-		// Only applicable to default and .bzl files
+	if f.Type == build.TypeWorkspace {
+		// Not applicable to WORKSPACE files
 		return nil
 	}
 


Test patch:
diff --git a/warn/warn_cosmetic_test.go b/warn/warn_cosmetic_test.go
index b70c366..e30892a 100644
--- a/warn/warn_cosmetic_test.go
+++ b/warn/warn_cosmetic_test.go
@@ -136,7 +136,7 @@ foo()
 x()`,
 		[]string{
 			":2: Load statements should be at the top of the file.",
-		}, scopeDefault|scopeBzl)
+		}, scopeDefault|scopeBzl|scopeBuild)
 
 	checkFindingsAndFix(t, "load-on-top", `
 """Docstring"""
@@ -172,7 +172,7 @@ bar()`,
 		[]string{
 			":9: Load statements should be at the top of the file.",
 			":15: Load statements should be at the top of the file.",
-		}, scopeDefault|scopeBzl)
+		}, scopeDefault|scopeBzl|scopeBuild)
 }
 
 func TestOutOfOrderLoad(t *testing.T) {
Repository: bazelbuild/buildtools
Pull request #765 (2020-01-17 17:52:01)

Improve the warning message if no documented args are found
It's possible that the arguments are documented but not correctly and Buildifier fails to parse that. If Buildifier thinks that no arguments are documented at all, print some additional information on how exactly the documentation should look like.


Patch:
diff --git a/warn/warn_docstring.go b/warn/warn_docstring.go
index cc63a2a..2b73f3b 100644
--- a/warn/warn_docstring.go
+++ b/warn/warn_docstring.go
@@ -290,12 +290,34 @@ func functionDocstringArgsWarning(f *build.File) []*LinterFinding {
 		// Check whether all existing arguments are commented
 		if len(notDocumentedArguments) > 0 {
 			message := fmt.Sprintf("Argument %q is not documented.", notDocumentedArguments[0])
+			plural := ""
 			if len(notDocumentedArguments) > 1 {
 				message = fmt.Sprintf(
 					`Arguments "%s" are not documented.`,
 					strings.Join(notDocumentedArguments, `", "`),
 				)
+				plural = "s"
 			}
+
+			if len(info.args) == 0 {
+				// No arguments are documented maybe the Args: block doesn't exist at all or
+				// formatted improperly. Add extra information to the warning message
+				message += fmt.Sprintf(`
+
+If the documentation for the argument%s exists but is not recognized by Buildifier
+make sure it follows the line "Args:" which has the same indentation as the opening """,
+and the argument description starts with "<argument_name>:" and indented with at least
+one (preferably two) space more than "Args:", for example:
+
+    def %s(%s):
+        """Function description.
+
+        Args:
+          %s: argument description, can be
+            multiline with additional indentation.
+        """`, plural, def.Name, notDocumentedArguments[0], notDocumentedArguments[0])
+			}
+
 			findings = append(findings, makeLinterFinding(doc, message))
 		}
 


Test patch:
diff --git a/warn/warn_docstring_test.go b/warn/warn_docstring_test.go
index 40dd863..7fec84a 100644
--- a/warn/warn_docstring_test.go
+++ b/warn/warn_docstring_test.go
@@ -275,7 +275,7 @@ def f(x, y):
 		}, scopeEverywhere)
 
 	checkFindings(t, "function-docstring-args", `
-def f(x, y, z = None, *args, **kwargs):
+def my_function(x, y, z = None, *args, **kwargs):
    """This is a function.
    """
    pass
@@ -285,7 +285,20 @@ def f(x, y, z = None, *args, **kwargs):
    pass
 `,
 		[]string{
-			`2: Arguments "x", "y", "z", "*args", "**kwargs" are not documented.`,
+			`2: Arguments "x", "y", "z", "*args", "**kwargs" are not documented.
+
+If the documentation for the arguments exists but is not recognized by Buildifier
+make sure it follows the line "Args:" which has the same indentation as the opening """,
+and the argument description starts with "<argument_name>:" and indented with at least
+one (preferably two) space more than "Args:", for example:
+
+    def my_function(x):
+        """Function description.
+
+        Args:
+          x: argument description, can be
+            multiline with additional indentation.
+        """`,
 		},
 		scopeEverywhere)
Repository: tetratelabs/wazero
Pull request #2125 (2024-03-06 06:41:44)

wazevo: handle empty host module


Patch:
diff --git a/internal/engine/wazevo/engine.go b/internal/engine/wazevo/engine.go
index d654c3ab..e898ae33 100644
--- a/internal/engine/wazevo/engine.go
+++ b/internal/engine/wazevo/engine.go
@@ -437,6 +437,11 @@ func (e *engine) compileHostModule(ctx context.Context, module *wasm.Module, lis
 		totalSize += len(body)
 	}
 
+	if totalSize == 0 {
+		// Empty module.
+		return cm, nil
+	}
+
 	// Allocate executable memory and then copy the generated machine code.
 	executable, err := platform.MmapCodeSegment(totalSize)
 	if err != nil {


Test patch:
diff --git a/builder_test.go b/builder_test.go
index 2e80fe48..dc13221d 100644
--- a/builder_test.go
+++ b/builder_test.go
@@ -308,7 +308,9 @@ func TestNewHostModuleBuilder_Compile(t *testing.T) {
 		tc := tt
 
 		t.Run(tc.name, func(t *testing.T) {
-			b := tc.input(NewRuntime(testCtx)).(*hostModuleBuilder)
+			cfg := NewRuntimeConfig()
+			cfg.(*runtimeConfig).EnableOptimizingCompiler()
+			b := tc.input(NewRuntimeWithConfig(testCtx, cfg)).(*hostModuleBuilder)
 			compiled, err := b.Compile(testCtx)
 			require.NoError(t, err)
 			m := compiled.(*compiledModule)
Repository: tetratelabs/wazero
Pull request #2126 (2024-03-06 07:00:04)

wazevo: fixes FunctionDefinition index for listeners


Patch:
diff --git a/internal/engine/wazevo/call_engine.go b/internal/engine/wazevo/call_engine.go
index 22c24ea1..38f73867 100644
--- a/internal/engine/wazevo/call_engine.go
+++ b/internal/engine/wazevo/call_engine.go
@@ -359,7 +359,7 @@ func (c *callEngine) callWithStack(ctx context.Context, paramResultStack []uint6
 			index := wasm.Index(stack[0])
 			mod := c.callerModuleInstance()
 			listener := mod.Engine.(*moduleEngine).listeners[index]
-			def := mod.Source.FunctionDefinition(index)
+			def := mod.Source.FunctionDefinition(index + mod.Source.ImportFunctionCount)
 			listener.Before(ctx, mod, def, stack[1:], c.stackIterator(false))
 			c.execCtx.exitCode = wazevoapi.ExitCodeOK
 			afterGoFunctionCallEntrypoint(c.execCtx.goCallReturnAddress, c.execCtxPtr,
@@ -369,7 +369,7 @@ func (c *callEngine) callWithStack(ctx context.Context, paramResultStack []uint6
 			index := wasm.Index(stack[0])
 			mod := c.callerModuleInstance()
 			listener := mod.Engine.(*moduleEngine).listeners[index]
-			def := mod.Source.FunctionDefinition(index)
+			def := mod.Source.FunctionDefinition(index + mod.Source.ImportFunctionCount)
 			listener.After(ctx, mod, def, stack[1:])
 			c.execCtx.exitCode = wazevoapi.ExitCodeOK
 			afterGoFunctionCallEntrypoint(c.execCtx.goCallReturnAddress, c.execCtxPtr,


Test patch:
diff --git a/experimental/listener_test.go b/experimental/listener_test.go
index c634451b..f9d78f68 100644
--- a/experimental/listener_test.go
+++ b/experimental/listener_test.go
@@ -8,7 +8,9 @@ import (
 	"github.com/tetratelabs/wazero"
 	"github.com/tetratelabs/wazero/api"
 	"github.com/tetratelabs/wazero/experimental"
+	"github.com/tetratelabs/wazero/experimental/opt"
 	"github.com/tetratelabs/wazero/experimental/wazerotest"
+	"github.com/tetratelabs/wazero/internal/platform"
 	"github.com/tetratelabs/wazero/internal/testing/binaryencoding"
 	"github.com/tetratelabs/wazero/internal/testing/require"
 	"github.com/tetratelabs/wazero/internal/wasm"
@@ -73,7 +75,12 @@ func TestFunctionListenerFactory(t *testing.T) {
 		},
 	})
 
-	r := wazero.NewRuntime(ctx)
+	var r wazero.Runtime
+	if platform.CompilerSupported() {
+		r = wazero.NewRuntimeWithConfig(ctx, opt.NewRuntimeConfigOptimizingCompiler())
+	} else {
+		r = wazero.NewRuntime(ctx)
+	}
 	defer r.Close(ctx) // This closes everything this Runtime created.
 
 	_, err := r.NewHostModuleBuilder("host").NewFunctionBuilder().WithFunc(func() {}).Export("").Instantiate(ctx)
Repository: tetratelabs/wazero
Pull request #2135 (2024-03-07 10:13:38)

threads: run ExampleCoreFeaturesThreads on both compiler/interpreter


Patch:
diff --git a/internal/engine/wazevo/engine.go b/internal/engine/wazevo/engine.go
index 0cb89917..d0c984ad 100644
--- a/internal/engine/wazevo/engine.go
+++ b/internal/engine/wazevo/engine.go
@@ -472,13 +472,6 @@ func (e *engine) compileHostModule(ctx context.Context, module *wasm.Module, lis
 func (e *engine) Close() (err error) {
 	e.mux.Lock()
 	defer e.mux.Unlock()
-
-	for _, cm := range e.compiledModules {
-		cm.functionOffsets = nil
-		cm.module = nil
-		cm.parent = nil
-		cm.executables = nil
-	}
 	e.sortedCompiledModules = nil
 	e.compiledModules = nil
 	e.sharedFunctions = nil


Test patch:
diff --git a/experimental/features_example_test.go b/experimental/features_example_test.go
index 383e955b..10462f35 100644
--- a/experimental/features_example_test.go
+++ b/experimental/features_example_test.go
@@ -34,9 +34,7 @@ func ExampleCoreFeaturesThreads() {
 	ctx := context.Background()
 
 	// Threads support must be enabled explicitly in addition to standard V2 features.
-
-	// TODO: currently, only the interpreter is supported for snapshotting.
-	cfg := wazero.NewRuntimeConfigInterpreter().WithCoreFeatures(api.CoreFeaturesV2 | experimental.CoreFeaturesThreads)
+	cfg := wazero.NewRuntimeConfig().WithCoreFeatures(api.CoreFeaturesV2 | experimental.CoreFeaturesThreads)
 
 	r := wazero.NewRuntimeWithConfig(ctx, cfg)
 	defer r.Close(ctx)