diff --git a/lib/wasmextractor/wasmextractor.go b/lib/wasmextractor/wasmextractor.go index 91e9a0978..457b3ef79 100644 --- a/lib/wasmextractor/wasmextractor.go +++ b/lib/wasmextractor/wasmextractor.go @@ -127,7 +127,7 @@ func readImports(data []byte) []WasmItem { imports := make([]WasmItem, numItems) - for i := 0; i < int(numItems); i++ { + for i := range int(numItems) { moduleLen, n := binary.Uvarint(data[offset:]) offset += n @@ -163,7 +163,7 @@ func readExports(data []byte) []WasmItem { exports := make([]WasmItem, numItems) - for i := 0; i < int(numItems); i++ { + for i := range int(numItems) { fieldLen, n := binary.Uvarint(data[offset:]) offset += n diff --git a/runtime/collections/in_mem/hnsw/vector_index_test.go b/runtime/collections/in_mem/hnsw/vector_index_test.go index 5736b7d5e..c131abbea 100644 --- a/runtime/collections/in_mem/hnsw/vector_index_test.go +++ b/runtime/collections/in_mem/hnsw/vector_index_test.go @@ -11,6 +11,7 @@ package hnsw import ( "fmt" + "slices" "sync" "testing" @@ -36,7 +37,7 @@ func TestMultipleSequentialVectorIndexes(t *testing.T) { numIndexes := 20 // Create and initialize the indexes - for i := 0; i < numIndexes; i++ { + for i := range numIndexes { wg.Add(1) go func(i int) { @@ -52,7 +53,7 @@ func TestMultipleSequentialVectorIndexes(t *testing.T) { for j := range baseTextIds { textIds[j] = baseTextIds[j] + int64(i*len(baseTextIds)) keys[j] = baseKeys[j] + fmt.Sprint(i) - vecs[j] = append([]float32{}, baseVecs[j]...) + vecs[j] = slices.Clone(baseVecs[j]) for k := range vecs[j] { vecs[j][k] += float32(i) / 10 } diff --git a/runtime/collections/in_mem/sequential/vector_index_test.go b/runtime/collections/in_mem/sequential/vector_index_test.go index 4ae11a344..1f2e54ef0 100644 --- a/runtime/collections/in_mem/sequential/vector_index_test.go +++ b/runtime/collections/in_mem/sequential/vector_index_test.go @@ -11,6 +11,7 @@ package sequential import ( "fmt" + "slices" "sync" "testing" @@ -36,7 +37,7 @@ func TestMultipleSequentialVectorIndexes(t *testing.T) { numIndexes := 20 // Create and initialize the indexes - for i := 0; i < numIndexes; i++ { + for i := range numIndexes { wg.Add(1) go func(i int) { @@ -52,7 +53,7 @@ func TestMultipleSequentialVectorIndexes(t *testing.T) { for j := range baseTextIds { textIds[j] = baseTextIds[j] + int64(i*len(baseTextIds)) keys[j] = baseKeys[j] + fmt.Sprint(i) - vecs[j] = append([]float32{}, baseVecs[j]...) + vecs[j] = slices.Clone(baseVecs[j]) for k := range vecs[j] { vecs[j][k] += float32(i) / 10 } diff --git a/runtime/collections/in_mem/text_index_test.go b/runtime/collections/in_mem/text_index_test.go index 334fbdcda..26330615e 100644 --- a/runtime/collections/in_mem/text_index_test.go +++ b/runtime/collections/in_mem/text_index_test.go @@ -25,7 +25,7 @@ func TestMultipleInMemCollections(t *testing.T) { numCollections := 10 // Create and initialize the collections - for i := 0; i < numCollections; i++ { + for i := range numCollections { wg.Add(1) go func(i int) { diff --git a/runtime/collections/index/helper.go b/runtime/collections/index/helper.go index e642946c7..945c71155 100644 --- a/runtime/collections/index/helper.go +++ b/runtime/collections/index/helper.go @@ -47,7 +47,7 @@ func BytesAsFloatArray(encoded []byte, retVal *[]float32) { if resultLen == 0 { return } - for i := 0; i < resultLen; i++ { + for range resultLen { // Assume LittleEndian for encoding since this is // the assumption elsewhere when reading from client. // See dgraph-io/dgo/protos/api.pb.go diff --git a/runtime/collections/utils/heap.go b/runtime/collections/utils/heap.go index 6fc751267..62e1ea2c2 100644 --- a/runtime/collections/utils/heap.go +++ b/runtime/collections/utils/heap.go @@ -47,11 +47,11 @@ func (h MaxTupleHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] } -func (h *MaxTupleHeap) Push(x interface{}) { +func (h *MaxTupleHeap) Push(x any) { *h = append(*h, x.(MaxHeapElement)) } -func (h *MaxTupleHeap) Pop() interface{} { +func (h *MaxTupleHeap) Pop() any { old := *h n := len(old) x := old[n-1] diff --git a/runtime/collections/utils/heap_test.go b/runtime/collections/utils/heap_test.go index 3e59a018f..24864f70a 100644 --- a/runtime/collections/utils/heap_test.go +++ b/runtime/collections/utils/heap_test.go @@ -43,7 +43,7 @@ func TestHeap(t *testing.T) { expectedIndices := []string{"three", "two", "one"} initialLen := h.Len() // Store initial length of heap - for i := 0; i < initialLen; i++ { + for i := range initialLen { popped := heap.Pop(h).(MaxHeapElement) if popped.value != expectedValues[i] || popped.index != expectedIndices[i] { t.Errorf("Expected pop value of %v and index '%s', got %v and '%s'", expectedValues[i], expectedIndices[i], popped.value, popped.index) diff --git a/runtime/collections/vector.go b/runtime/collections/vector.go index f95311926..ff84056ed 100644 --- a/runtime/collections/vector.go +++ b/runtime/collections/vector.go @@ -35,10 +35,7 @@ func batchInsertVectorsToMemory(ctx context.Context, vectorIndex interfaces.Vect return errors.New("mismatch in vectors, keys, and textIds") } for i := 0; i < len(textIds); i += batchSize { - end := i + batchSize - if end > len(textIds) { - end = len(textIds) - } + end := min(i+batchSize, len(textIds)) textIdsBatch := textIds[i:end] vectorIdsBatch := vectorIds[i:end] keysBatch := keys[i:end] @@ -212,10 +209,7 @@ func processTexts(ctx context.Context, col interfaces.CollectionNamespace, vecto return fmt.Errorf("mismatch in keys and texts") } for i := 0; i < len(keys); i += batchSize { - end := i + batchSize - if end > len(keys) { - end = len(keys) - } + end := min(i+batchSize, len(keys)) keysBatch := keys[i:end] textsBatch := texts[i:end] diff --git a/runtime/db/inferencehistory.go b/runtime/db/inferencehistory.go index f9e00680d..de920b098 100644 --- a/runtime/db/inferencehistory.go +++ b/runtime/db/inferencehistory.go @@ -54,7 +54,7 @@ type Inference struct { StartedAt string `json:"started_at,omitempty"` DurationMs int64 `json:"duration_ms,omitempty"` Function string `json:"function,omitempty"` - Plugin Plugin `json:"plugin,omitempty"` + Plugin Plugin `json:"plugin"` } const batchSize = 100 diff --git a/runtime/graphql/datasource/source.go b/runtime/graphql/datasource/source.go index 72808444c..0abe31bc7 100644 --- a/runtime/graphql/datasource/source.go +++ b/runtime/graphql/datasource/source.go @@ -120,7 +120,7 @@ func writeGraphQLResponse(ctx context.Context, out *bytes.Buffer, result any, gq gqlErrors = append(gqlErrors, resolve.GraphQLError{ Message: fnErr.Error(), Path: []any{fieldName}, - Extensions: map[string]interface{}{ + Extensions: map[string]any{ "level": "error", }, }) @@ -402,7 +402,7 @@ func transformErrors(messages []utils.LogMessage, ci *callInfo) []resolve.GraphQ errors = append(errors, resolve.GraphQLError{ Message: msg.Message, Path: []any{ci.FieldInfo.AliasOrName()}, - Extensions: map[string]interface{}{ + Extensions: map[string]any{ "level": msg.Level, }, }) diff --git a/runtime/graphql/engine/logging.go b/runtime/graphql/engine/logging.go index 0aa27bbad..3c62779ce 100644 --- a/runtime/graphql/engine/logging.go +++ b/runtime/graphql/engine/logging.go @@ -60,8 +60,8 @@ func (l *loggerAdapter) LevelLogger(level abstractlogger.Level) abstractlogger.L } } -func (l *loggerAdapter) fields(fields []abstractlogger.Field) map[string]interface{} { - out := make(map[string]interface{}, len(fields)) +func (l *loggerAdapter) fields(fields []abstractlogger.Field) map[string]any { + out := make(map[string]any, len(fields)) for _, f := range fields { lf := *convertLoggerField(&f) @@ -92,7 +92,7 @@ type LevelLoggerAdapter struct { level abstractlogger.Level } -func (s *LevelLoggerAdapter) Println(v ...interface{}) { +func (s *LevelLoggerAdapter) Println(v ...any) { switch s.level { case abstractlogger.DebugLevel: s.l.Debug().Msgf("%v", v[0]) @@ -109,7 +109,7 @@ func (s *LevelLoggerAdapter) Println(v ...interface{}) { } } -func (s *LevelLoggerAdapter) Printf(format string, v ...interface{}) { +func (s *LevelLoggerAdapter) Printf(format string, v ...any) { switch s.level { case abstractlogger.DebugLevel: s.l.Debug().Msgf(format, v...) @@ -137,7 +137,7 @@ type loggerField struct { stringsValue []string intValue int64 byteValue []byte - interfaceValue interface{} + interfaceValue any errorValue error } diff --git a/runtime/graphql/graphql.go b/runtime/graphql/graphql.go index edb586fe3..74c24ff76 100644 --- a/runtime/graphql/graphql.go +++ b/runtime/graphql/graphql.go @@ -13,6 +13,7 @@ import ( "context" "fmt" "net/http" + "slices" "strconv" "strings" @@ -172,7 +173,7 @@ func handleGraphQLRequest(w http.ResponseWriter, r *http.Request) { if f := q.Get("fields"); f.Exists() && f.Type == gjson.Null { response[f.Index] = '[' response[f.Index+1] = ']' - response = append(response[:f.Index+2], response[f.Index+4:]...) + response = slices.Delete(response, f.Index+2, f.Index+4) } } } diff --git a/runtime/hnsw/distance_test.go b/runtime/hnsw/distance_test.go index 726433eba..bc43c9ac3 100644 --- a/runtime/hnsw/distance_test.go +++ b/runtime/hnsw/distance_test.go @@ -48,8 +48,8 @@ func TestCosineSimilarity(t *testing.T) { func BenchmarkCosineSimilarity(b *testing.B) { v1 := randFloats(1536) v2 := randFloats(1536) - b.ResetTimer() - for i := 0; i < b.N; i++ { + + for b.Loop() { _, err := CosineDistance(v1, v2) if err != nil { b.Fatal(err) diff --git a/runtime/hnsw/encode.go b/runtime/hnsw/encode.go index bad72f974..433fb11f1 100644 --- a/runtime/hnsw/encode.go +++ b/runtime/hnsw/encode.go @@ -25,7 +25,7 @@ import ( var byteOrder = binary.LittleEndian -func binaryRead(r io.Reader, data interface{}) (int, error) { +func binaryRead(r io.Reader, data any) (int, error) { switch v := data.(type) { case *int: br, ok := r.(io.ByteReader) @@ -219,7 +219,7 @@ func (h *Graph[K]) Import(r io.Reader) error { } h.layers = make([]*layer[K], nLayers) - for i := 0; i < nLayers; i++ { + for i := range nLayers { var nNodes int _, err = binaryRead(r, &nNodes) if err != nil { @@ -227,7 +227,7 @@ func (h *Graph[K]) Import(r io.Reader) error { } nodes := make(map[K]*layerNode[K], nNodes) - for j := 0; j < nNodes; j++ { + for j := range nNodes { var key K var vec Vector var nNeighbors int @@ -237,7 +237,7 @@ func (h *Graph[K]) Import(r io.Reader) error { } neighbors := make([]K, nNeighbors) - for k := 0; k < nNeighbors; k++ { + for k := range nNeighbors { var neighbor K _, err = binaryRead(r, &neighbor) if err != nil { diff --git a/runtime/hnsw/encode_test.go b/runtime/hnsw/encode_test.go index 7826c8951..76bddcab9 100644 --- a/runtime/hnsw/encode_test.go +++ b/runtime/hnsw/encode_test.go @@ -133,7 +133,7 @@ func requireGraphApproxEquals[K cmp.Ordered](t *testing.T, g1, g2 *Graph[K]) { func TestGraph_ExportImport(t *testing.T) { g1 := newTestGraph[int]() - for i := 0; i < 128; i++ { + for i := range 128 { err := g1.Add( Node[int]{ i, randFloats(1), @@ -176,7 +176,7 @@ func TestSavedGraph(t *testing.T) { g1, err := LoadSavedGraph[int](dir + "/graph") require.NoError(t, err) require.Equal(t, 0, g1.Len()) - for i := 0; i < 128; i++ { + for i := range 128 { err := g1.Add( Node[int]{ i, randFloats(1), @@ -199,7 +199,7 @@ const benchGraphSize = 100 func BenchmarkGraph_Import(b *testing.B) { b.ReportAllocs() g := newTestGraph[int]() - for i := 0; i < benchGraphSize; i++ { + for i := range benchGraphSize { err := g.Add( Node[int]{ i, randFloats(256), @@ -212,10 +212,9 @@ func BenchmarkGraph_Import(b *testing.B) { err := g.Export(buf) require.NoError(b, err) - b.ResetTimer() b.SetBytes(int64(buf.Len())) - for i := 0; i < b.N; i++ { + for b.Loop() { b.StopTimer() rdr := bytes.NewReader(buf.Bytes()) g := newTestGraph[int]() @@ -228,7 +227,7 @@ func BenchmarkGraph_Import(b *testing.B) { func BenchmarkGraph_Export(b *testing.B) { b.ReportAllocs() g := newTestGraph[int]() - for i := 0; i < benchGraphSize; i++ { + for i := range benchGraphSize { err := g.Add( Node[int]{ i, randFloats(256), @@ -238,8 +237,8 @@ func BenchmarkGraph_Export(b *testing.B) { } var buf bytes.Buffer - b.ResetTimer() - for i := 0; i < b.N; i++ { + + for i := 0; b.Loop(); i++ { err := g.Export(&buf) require.NoError(b, err) if i == 0 { diff --git a/runtime/hnsw/graph.go b/runtime/hnsw/graph.go index 4dcaa303e..dc320e2b2 100644 --- a/runtime/hnsw/graph.go +++ b/runtime/hnsw/graph.go @@ -355,7 +355,7 @@ func (h *Graph[K]) randomLevel() (int, error) { } } - for level := 0; level < max; level++ { + for level := range max { if h.Rng == nil { h.Rng = defaultRand() } diff --git a/runtime/hnsw/graph_test.go b/runtime/hnsw/graph_test.go index affaf712c..04ca59d13 100644 --- a/runtime/hnsw/graph_test.go +++ b/runtime/hnsw/graph_test.go @@ -106,7 +106,7 @@ func newTestGraph[K cmp.Ordered]() *Graph[K] { func TestGraph_AddSearch(t *testing.T) { g := newTestGraph[int]() - for i := 0; i < 128; i++ { + for i := range 128 { err := g.Add( Node[int]{ Key: i, @@ -151,7 +151,7 @@ func TestGraph_AddSearch(t *testing.T) { func TestGraph_AddDelete(t *testing.T) { g := newTestGraph[int]() - for i := 0; i < 128; i++ { + for i := range 128 { err := g.Add(Node[int]{ Key: i, Value: Vector{float32(i)}, @@ -197,7 +197,7 @@ func Benchmark_HNSW(b *testing.B) { g := Graph[int]{} g.Ml = 0.5 g.Distance = EuclideanDistance - for i := 0; i < size; i++ { + for i := range size { err := g.Add(Node[int]{ Key: i, Value: Vector{float32(i)}, @@ -207,7 +207,7 @@ func Benchmark_HNSW(b *testing.B) { b.ResetTimer() b.Run("Search", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { _, err := g.Search( []float32{float32(i % size)}, 4, @@ -235,7 +235,7 @@ func Benchmark_HNSW_1536(b *testing.B) { g := newTestGraph[int]() const size = 1000 points := make([]Node[int], size) - for i := 0; i < size; i++ { + for i := range size { points[i] = Node[int]{ Key: i, Value: Vector(randFloats(1536)), @@ -246,7 +246,7 @@ func Benchmark_HNSW_1536(b *testing.B) { b.ResetTimer() b.Run("Search", func(b *testing.B) { - for i := 0; i < b.N; i++ { + for i := 0; b.Loop(); i++ { _, err := g.Search( points[i%size].Value, 4, diff --git a/runtime/hnsw/heap/heap.go b/runtime/hnsw/heap/heap.go index ffa33e7f7..a4daf52c9 100644 --- a/runtime/hnsw/heap/heap.go +++ b/runtime/hnsw/heap/heap.go @@ -36,11 +36,11 @@ func (h *innerHeap[T]) Swap(i, j int) { h.data[i], h.data[j] = h.data[j], h.data[i] } -func (h *innerHeap[T]) Push(x interface{}) { +func (h *innerHeap[T]) Push(x any) { h.data = append(h.data, x.(T)) } -func (h *innerHeap[T]) Pop() interface{} { +func (h *innerHeap[T]) Pop() any { n := len(h.data) x := h.data[n-1] h.data = h.data[:n-1] diff --git a/runtime/hnsw/heap/heap_test.go b/runtime/hnsw/heap/heap_test.go index 90f6442da..f4fde4872 100644 --- a/runtime/hnsw/heap/heap_test.go +++ b/runtime/hnsw/heap/heap_test.go @@ -27,7 +27,7 @@ func (i Int) Less(j Int) bool { func TestHeap(t *testing.T) { h := Heap[Int]{} - for i := 0; i < 20; i++ { + for range 20 { h.Push(Int(rand.Int() % 100)) } diff --git a/runtime/integration_tests/postgresql_integration_test.go b/runtime/integration_tests/postgresql_integration_test.go index 2b930684c..5be92d5cf 100644 --- a/runtime/integration_tests/postgresql_integration_test.go +++ b/runtime/integration_tests/postgresql_integration_test.go @@ -55,8 +55,8 @@ const ( ) type graphQLRequest struct { - Query string `json:"query"` - Variables map[string]interface{} `json:"variables,omitempty"` + Query string `json:"query"` + Variables map[string]any `json:"variables,omitempty"` } func runGraphqlQuery(greq graphQLRequest) ([]byte, error) { diff --git a/runtime/langsupport/primitives/converters.go b/runtime/langsupport/primitives/converters.go index 17eceeef4..6fdda384c 100644 --- a/runtime/langsupport/primitives/converters.go +++ b/runtime/langsupport/primitives/converters.go @@ -134,7 +134,7 @@ func sliceToBytes[T primitive](s []T, size int) []byte { func bytesToSliceFixed32[T ~int | ~uint | ~uintptr](b []byte, size int) []T { x := make([]T, len(b)/size) - for i := 0; i < len(x); i++ { + for i := range x { x[i] = T(*(*uint32)(unsafe.Pointer(&b[i*size]))) } return x @@ -142,7 +142,7 @@ func bytesToSliceFixed32[T ~int | ~uint | ~uintptr](b []byte, size int) []T { func sliceToBytesFixed32[T ~int | ~uint | ~uintptr](s []T, size int) []byte { b := make([]byte, len(s)*size) - for i := 0; i < len(s); i++ { + for i := range s { u := uint32(s[i]) bytes := *(*[4]byte)(unsafe.Pointer(&u)) copy(b[i*size:], bytes[:size]) diff --git a/runtime/languages/assemblyscript/handler_maps.go b/runtime/languages/assemblyscript/handler_maps.go index 7bbea5f7b..b012de664 100644 --- a/runtime/languages/assemblyscript/handler_maps.go +++ b/runtime/languages/assemblyscript/handler_maps.go @@ -158,7 +158,7 @@ func (h *mapHandler) Read(ctx context.Context, wa langsupport.WasmAdapter, offse } else { // return a pseudo-map s := reflect.MakeSlice(h.rtPseudoMapSlice, mapSize, mapSize) - for i := 0; i < mapSize; i++ { + for i := range mapSize { p := entries + uint32(i)*entrySize k, err := h.keyHandler.Read(ctx, wa, p) diff --git a/runtime/languages/assemblyscript/tests/maps_test.go b/runtime/languages/assemblyscript/tests/maps_test.go index e16efa78c..75d700e4a 100644 --- a/runtime/languages/assemblyscript/tests/maps_test.go +++ b/runtime/languages/assemblyscript/tests/maps_test.go @@ -226,7 +226,7 @@ func TestClassContainingMapOutput_string_string(t *testing.T) { func makeTestMap(size int) map[string]string { m := make(map[string]string, size) - for i := 0; i < size; i++ { + for i := range size { key := fmt.Sprintf("key_%03d", i) val := fmt.Sprintf("val_%03d", i) m[key] = val diff --git a/runtime/languages/golang/handler_arrays.go b/runtime/languages/golang/handler_arrays.go index 4aede683c..9b7285276 100644 --- a/runtime/languages/golang/handler_arrays.go +++ b/runtime/languages/golang/handler_arrays.go @@ -48,7 +48,7 @@ type arrayHandler struct { func (h *arrayHandler) Read(ctx context.Context, wa langsupport.WasmAdapter, offset uint32) (any, error) { elementSize := h.elementHandler.TypeInfo().Size() items := reflect.New(h.typeInfo.ReflectedType()).Elem() - for i := 0; i < h.arrayLen; i++ { + for i := range h.arrayLen { itemOffset := offset + uint32(i)*elementSize item, err := h.elementHandler.Read(ctx, wa, itemOffset) if err != nil { @@ -70,7 +70,7 @@ func (h *arrayHandler) Write(ctx context.Context, wa langsupport.WasmAdapter, of elementSize := h.elementHandler.TypeInfo().Size() // write exactly the number of items that will fit in the array - for i := 0; i < h.arrayLen; i++ { + for i := range h.arrayLen { if i >= len(items) { break } @@ -98,7 +98,7 @@ func (h *arrayHandler) Write(ctx context.Context, wa langsupport.WasmAdapter, of func (h *arrayHandler) Decode(ctx context.Context, wa langsupport.WasmAdapter, vals []uint64) (any, error) { array := reflect.New(h.typeInfo.ReflectedType()).Elem() itemLen := int(h.elementHandler.TypeInfo().EncodingLength()) - for i := 0; i < h.arrayLen; i++ { + for i := range h.arrayLen { data, err := h.elementHandler.Decode(ctx, wa, vals[i*itemLen:(i+1)*itemLen]) if err != nil { return nil, err diff --git a/runtime/languages/golang/handler_maps.go b/runtime/languages/golang/handler_maps.go index aeef56b39..0d2704ded 100644 --- a/runtime/languages/golang/handler_maps.go +++ b/runtime/languages/golang/handler_maps.go @@ -116,13 +116,13 @@ func (h *mapHandler) Read(ctx context.Context, wa langsupport.WasmAdapter, offse if rtKey.Comparable() { // return a map m := reflect.MakeMapWithSize(h.typeInfo.ReflectedType(), size) - for i := 0; i < size; i++ { + for i := range size { m.SetMapIndex(rvKeys.Index(i), rvVals.Index(i)) } return m.Interface(), nil } else { s := reflect.MakeSlice(h.rtPseudoMapSlice, size, size) - for i := 0; i < size; i++ { + for i := range size { s.Index(i).Field(0).Set(rvKeys.Index(i)) s.Index(i).Field(1).Set(rvVals.Index(i)) } diff --git a/runtime/languages/golang/handler_primitivearrays.go b/runtime/languages/golang/handler_primitivearrays.go index 40e702cf2..5a6aecd86 100644 --- a/runtime/languages/golang/handler_primitivearrays.go +++ b/runtime/languages/golang/handler_primitivearrays.go @@ -98,7 +98,7 @@ func (h *primitiveArrayHandler[T]) Read(ctx context.Context, wa langsupport.Wasm // convert the slice to an array of the target type array := reflect.New(h.typeInfo.ReflectedType()).Elem() - for i := 0; i < h.arrayLen; i++ { + for i := range h.arrayLen { array.Index(i).Set(reflect.ValueOf(items[i])) } return array.Interface(), nil @@ -131,7 +131,7 @@ func (h *primitiveArrayHandler[T]) Decode(ctx context.Context, wa langsupport.Wa } rvItems := reflect.New(h.typeInfo.ReflectedType()).Elem() - for i := 0; i < h.arrayLen; i++ { + for i := range h.arrayLen { item := h.converter.Decode(vals[i]) ptr := rvItems.Index(i).Addr().UnsafePointer() *(*T)(ptr) = item @@ -150,7 +150,7 @@ func (h *primitiveArrayHandler[T]) Encode(ctx context.Context, wa langsupport.Wa } results := make([]uint64, h.arrayLen) - for i := 0; i < h.arrayLen; i++ { + for i := range h.arrayLen { results[i] = h.converter.Encode(items[i]) } return results, nil, nil diff --git a/runtime/languages/golang/tests/maps_test.go b/runtime/languages/golang/tests/maps_test.go index 8cc3fd58d..ba1e63118 100644 --- a/runtime/languages/golang/tests/maps_test.go +++ b/runtime/languages/golang/tests/maps_test.go @@ -186,7 +186,7 @@ func TestStructContainingMapOutput_string_string(t *testing.T) { func makeTestMap(size int) map[string]string { m := make(map[string]string, size) - for i := 0; i < size; i++ { + for i := range size { key := fmt.Sprintf("key_%03d", i) val := fmt.Sprintf("val_%03d", i) m[key] = val diff --git a/runtime/languages/golang/tests/planner_test.go b/runtime/languages/golang/tests/planner_test.go index 4187949a2..d807ac17f 100644 --- a/runtime/languages/golang/tests/planner_test.go +++ b/runtime/languages/golang/tests/planner_test.go @@ -500,13 +500,13 @@ var rtTypeHandler = reflect.TypeFor[langsupport.TypeHandler]() func getInnerHandlers(handler langsupport.TypeHandler) []langsupport.TypeHandler { var results []langsupport.TypeHandler rvHandler := reflect.ValueOf(handler).Elem() - for i := 0; i < rvHandler.NumField(); i++ { + for i := range rvHandler.NumField() { rf := rvHandler.Field(i) field := reflect.NewAt(rf.Type(), unsafe.Pointer(rf.UnsafeAddr())).Elem() if field.Type().Implements(rtTypeHandler) { results = append(results, field.Interface().(langsupport.TypeHandler)) } else if field.Kind() == reflect.Slice && field.Type().Elem().Implements(rtTypeHandler) { - for j := 0; j < field.Len(); j++ { + for j := range field.Len() { results = append(results, field.Index(j).Interface().(langsupport.TypeHandler)) } } diff --git a/runtime/metrics/metrics_test.go b/runtime/metrics/metrics_test.go index bb07068a7..dbbaa5424 100644 --- a/runtime/metrics/metrics_test.go +++ b/runtime/metrics/metrics_test.go @@ -73,15 +73,15 @@ func TestRuntimeMetrics(t *testing.T) { } func BenchmarkSummary(b *testing.B) { - b.ResetTimer() - for i := 0; i < b.N; i++ { + + for i := 0; b.Loop(); i++ { metrics.FunctionExecutionDurationMillisecondsSummary.WithLabelValues("test").Observe(float64(i)) } } func BenchmarkHistogram(b *testing.B) { - b.ResetTimer() - for i := 0; i < b.N; i++ { + + for i := 0; b.Loop(); i++ { metrics.FunctionExecutionDurationMilliseconds.WithLabelValues("test").Observe(float64(i)) } } diff --git a/runtime/middleware/jwt.go b/runtime/middleware/jwt.go index 619480165..2860ce68c 100644 --- a/runtime/middleware/jwt.go +++ b/runtime/middleware/jwt.go @@ -120,7 +120,7 @@ func HandleJWT(next http.Handler) http.Handler { var found bool for _, pemPublicKey := range globalAuthKeys.getPemPublicKeys() { - token, err = jwtParser.Parse(tokenStr, func(token *jwt.Token) (interface{}, error) { + token, err = jwtParser.Parse(tokenStr, func(token *jwt.Token) (any, error) { return pemPublicKey, nil }) if err == nil { @@ -133,7 +133,7 @@ func HandleJWT(next http.Handler) http.Handler { } if !found { for _, jwksPublicKey := range globalAuthKeys.getJwksPublicKeys() { - token, err = jwtParser.Parse(tokenStr, func(token *jwt.Token) (interface{}, error) { + token, err = jwtParser.Parse(tokenStr, func(token *jwt.Token) (any, error) { return jwksPublicKey, nil }) if err == nil { diff --git a/runtime/utils/sentry.go b/runtime/utils/sentry.go index 9cf4a04ed..4c6c8c4f3 100644 --- a/runtime/utils/sentry.go +++ b/runtime/utils/sentry.go @@ -152,7 +152,7 @@ func sentryBeforeSendTransaction(event *sentry.Event, hint *sentry.EventHint) *s // Include any extra information that may be useful for debugging. func sentryAddExtras(event *sentry.Event) { if event.Extra == nil { - event.Extra = make(map[string]interface{}) + event.Extra = make(map[string]any) } // Capture the k8s namespace environment variable. diff --git a/runtime/utils/slices.go b/runtime/utils/slices.go index 52a47e926..7c0706956 100644 --- a/runtime/utils/slices.go +++ b/runtime/utils/slices.go @@ -68,7 +68,7 @@ func ConvertToSlice(input any) ([]any, error) { } out := make([]any, 0, rv.Len()) - for i := 0; i < rv.Len(); i++ { + for i := range rv.Len() { out = append(out, rv.Index(i).Interface()) } @@ -171,7 +171,7 @@ func ConvertToSliceOf[T any](obj any) ([]T, bool) { switch rv.Kind() { case reflect.Array: out := make([]T, rv.Len()) - for i := 0; i < rv.Len(); i++ { + for i := range rv.Len() { out[i] = rv.Index(i).Interface().(T) } return out, true @@ -181,7 +181,7 @@ func ConvertToSliceOf[T any](obj any) ([]T, bool) { return out, true } out := make([]T, rv.Len()) - for i := 0; i < rv.Len(); i++ { + for i := range rv.Len() { out[i] = rv.Index(i).Interface().(T) } return out, true diff --git a/runtime/wasmhost/hostfns.go b/runtime/wasmhost/hostfns.go index 69e789a3e..f55050933 100644 --- a/runtime/wasmhost/hostfns.go +++ b/runtime/wasmhost/hostfns.go @@ -128,7 +128,7 @@ func (host *wasmHost) newHostFunction(modName, funcName string, fn any, opts ... // For now, we'll assume single-value, one-to-one mapping between Go and Wasm types. paramTypes := make([]wasm.ValueType, 0, numParams) - for i := 0; i < numParams; i++ { + for i := range numParams { if hasContextParam && i == 0 { continue } @@ -145,7 +145,7 @@ func (host *wasmHost) newHostFunction(modName, funcName string, fn any, opts ... } resultTypes := make([]wasm.ValueType, 0, numResults) - for i := 0; i < numResults; i++ { + for i := range numResults { if hasErrorResult && i == numResults-1 { continue } @@ -238,7 +238,7 @@ func (host *wasmHost) newHostFunction(modName, funcName string, fn any, opts ... // Read input parameter values params := make([]any, 0, numParams) - for i := 0; i < numParams; i++ { + for i := range numParams { if hasContextParam && i == 0 { continue } @@ -285,7 +285,7 @@ func (host *wasmHost) newHostFunction(modName, funcName string, fn any, opts ... } // copy results to the results slice - for i := 0; i < numResults; i++ { + for i := range numResults { if hasErrorResult && i == numResults-1 { continue } else { diff --git a/sdk/go/pkg/neo4j/neo4j_test.go b/sdk/go/pkg/neo4j/neo4j_test.go index e1febd2f1..0589bd183 100644 --- a/sdk/go/pkg/neo4j/neo4j_test.go +++ b/sdk/go/pkg/neo4j/neo4j_test.go @@ -43,7 +43,7 @@ func TestRecordJSONMarshal(t *testing.T) { func TestExecuteQuery(t *testing.T) { dbName := "mydb" query := "query" - parameters := map[string]interface{}{ + parameters := map[string]any{ "param1": "value1", "param2": "value2", } diff --git a/sdk/go/pkg/vectors/vectors.go b/sdk/go/pkg/vectors/vectors.go index 61f255ccc..eecc1c39f 100644 --- a/sdk/go/pkg/vectors/vectors.go +++ b/sdk/go/pkg/vectors/vectors.go @@ -121,7 +121,7 @@ func DivideNumberInPlace[T constraints.Integer | constraints.Float](a []T, b T) func Dot[T constraints.Integer | constraints.Float](a, b []T) T { assertEqualLength(a, b) var result T = 0 - for i := 0; i < len(a); i++ { + for i := range a { result += a[i] * b[i] } return result @@ -150,7 +150,7 @@ func Sum[T constraints.Integer | constraints.Float](a []T) T { // Product computes the product of all elements in a vector. func Product[T constraints.Integer | constraints.Float](a []T) T { var result T = 1 - for i := 0; i < len(a); i++ { + for i := range a { result *= a[i] } return result @@ -166,7 +166,7 @@ func Mean[T constraints.Integer | constraints.Float](a []T) T { func Min[T constraints.Integer | constraints.Float](a []T) T { assertNonEmpty(a) result := a[0] - for i := 0; i < len(a); i++ { + for i := range a { if a[i] < result { result = a[i] } @@ -178,7 +178,7 @@ func Min[T constraints.Integer | constraints.Float](a []T) T { func Max[T constraints.Integer | constraints.Float](a []T) T { assertNonEmpty(a) result := a[0] - for i := 0; i < len(a); i++ { + for i := range a { if a[i] > result { result = a[i] } @@ -211,7 +211,7 @@ func AbsInPlace[T constraints.Integer | constraints.Float](a []T) { func EuclidianDistance[T constraints.Integer | constraints.Float](a, b []T) float64 { assertEqualLength(a, b) var result float64 = 0 - for i := 0; i < len(a); i++ { + for i := range a { result += math.Pow(float64(a[i]-b[i]), 2) } return math.Sqrt(result) diff --git a/sdk/go/tools/modus-go-build/codegen/preprocess.go b/sdk/go/tools/modus-go-build/codegen/preprocess.go index b56425bd1..36568e009 100644 --- a/sdk/go/tools/modus-go-build/codegen/preprocess.go +++ b/sdk/go/tools/modus-go-build/codegen/preprocess.go @@ -306,7 +306,7 @@ func writeFuncWrappers(b *bytes.Buffer, pkg *packages.Package, imports map[strin if n == 0 { n = 1 } - for j := 0; j < n; j++ { + for j := range n { b.WriteByte('r') b.WriteString(strconv.Itoa(i + j)) b.WriteString(", ") @@ -324,7 +324,7 @@ func writeFuncWrappers(b *bytes.Buffer, pkg *packages.Package, imports map[strin if numResults > 0 { b.WriteString("\treturn ") - for i := 0; i < numResults; i++ { + for i := range numResults { if i > 0 { b.WriteString(", ") } diff --git a/sdk/go/tools/modus-go-build/extractor/functions.go b/sdk/go/tools/modus-go-build/extractor/functions.go index 48ea0d65d..fc6dec46d 100644 --- a/sdk/go/tools/modus-go-build/extractor/functions.go +++ b/sdk/go/tools/modus-go-build/extractor/functions.go @@ -167,14 +167,14 @@ func findRequiredTypes(f *types.Func, m map[string]types.Type) { sig := f.Type().(*types.Signature) if params := sig.Params(); params != nil { - for i := 0; i < params.Len(); i++ { + for i := range params.Len() { t := params.At(i).Type() addRequiredTypes(t, m) } } if results := sig.Results(); results != nil { - for i := 0; i < results.Len(); i++ { + for i := range results.Len() { t := results.At(i).Type() addRequiredTypes(t, m) } @@ -215,7 +215,7 @@ func addRequiredTypes(t types.Type, m map[string]types.Type) bool { } if s, ok := u.(*types.Struct); ok { - for i := 0; i < s.NumFields(); i++ { + for i := range s.NumFields() { addRequiredTypes(s.Field(i).Type(), m) } } diff --git a/sdk/go/tools/modus-go-build/extractor/transform.go b/sdk/go/tools/modus-go-build/extractor/transform.go index 4d84f8186..5ad1a7ebd 100644 --- a/sdk/go/tools/modus-go-build/extractor/transform.go +++ b/sdk/go/tools/modus-go-build/extractor/transform.go @@ -33,7 +33,7 @@ func transformStruct(name string, s *types.Struct, pkgs map[string]*packages.Pac structDocs := getDocs(structDecl.Doc) fields := make([]*metadata.Field, s.NumFields()) - for i := 0; i < s.NumFields(); i++ { + for i := range s.NumFields() { f := s.Field(i) fieldDocs := getDocs(structType.Fields.List[i].Doc) @@ -73,7 +73,7 @@ func transformFunc(name string, f *types.Func, pkgs map[string]*packages.Package if params != nil { ret.Parameters = make([]*metadata.Parameter, params.Len()) - for i := 0; i < params.Len(); i++ { + for i := range params.Len() { p := params.At(i) ret.Parameters[i] = &metadata.Parameter{ Name: p.Name(), @@ -84,7 +84,7 @@ func transformFunc(name string, f *types.Func, pkgs map[string]*packages.Package if results != nil { ret.Results = make([]*metadata.Result, results.Len()) - for i := 0; i < results.Len(); i++ { + for i := range results.Len() { r := results.At(i) ret.Results[i] = &metadata.Result{ Name: r.Name(),