Skip to content

Commit b0c5d73

Browse files
committed
chore(lint): satisfy golangci-lint v2.5 (gofmt, misspell, nlreturn, staticcheck, unused, wsl)
1 parent 58e1f43 commit b0c5d73

15 files changed

Lines changed: 78 additions & 102 deletions

backend.go

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,9 @@ import (
2626
// Kept minimal and additive so call sites can default-zero fields they
2727
// don't need. ltoMode is "thin" or "" (no LTO).
2828
type compileIROpts struct {
29-
optLevel string // -O0/-O1/-O2/-O3
30-
ltoMode string // "thin" or ""
31-
debug bool
32-
functionSecs bool // -ffunction-sections
33-
dataSecs bool // -fdata-sections
34-
noUnwindTables bool // -fno-unwind-tables -fno-asynchronous-unwind-tables
35-
gLineTablesOnly bool // -gline-tables-only (stacktrace path)
36-
targetFlags []string
29+
optLevel string // -O0/-O1/-O2/-O3
30+
ltoMode string // "thin" or ""
31+
targetFlags []string
3732
}
3833

3934
type linkOpts struct {
@@ -43,8 +38,8 @@ type linkOpts struct {
4338
standaloneDebugMacOS bool
4439
functionSecs bool
4540
dataSecs bool
46-
gcSections bool // -Wl,--gc-sections / -Wl,-dead_strip
47-
useLld bool // -fuse-ld=lld (cross-compile)
41+
gcSections bool // -Wl,--gc-sections / -Wl,-dead_strip
42+
useLld bool // -fuse-ld=lld (cross-compile)
4843
rdynamic bool
4944
targetGOOS string
5045
targetFlags []string
@@ -131,7 +126,7 @@ func linkBinary(inputs []string, outBin string, opts linkOpts) error {
131126

132127
prefix := entry.prefix
133128
if opts.targetGOOS != "darwin" {
134-
prefix = forceBuildIdSha1(prefix)
129+
prefix = forceBuildIDSha1(prefix)
135130
}
136131

137132
argv := append([]string{}, prefix...)
@@ -155,11 +150,11 @@ func linkBinary(inputs []string, outBin string, opts linkOpts) error {
155150
return nil
156151
}
157152

158-
// forceBuildIdSha1 rewrites any `--build-id` (default: timestamp hash)
153+
// forceBuildIDSha1 rewrites any `--build-id` (default: timestamp hash)
159154
// into `--build-id=sha1` so the note is content-derived and stable
160155
// across rebuilds. Leaves an explicit `--build-id=...` choice alone.
161156
// ELF-only -- callers skip this on Mach-O.
162-
func forceBuildIdSha1(args []string) []string {
157+
func forceBuildIDSha1(args []string) []string {
163158
out := make([]string, 0, len(args))
164159
for _, a := range args {
165160
if a == "--build-id" {
@@ -216,34 +211,42 @@ func lldArgvFor(opts linkOpts) *lldArgvEntry {
216211
useLld: opts.useLld,
217212
}
218213

219-
lldArgvCacheMu.Lock()
220-
entry, ok := lldArgvCache[key]
221-
lldArgvCacheMu.Unlock()
222-
223-
if ok {
214+
if entry, ok := lookupLldArgv(key); ok {
224215
return entry
225216
}
226217

227218
if disk := readLldArgvFromDisk(key); disk != nil {
228-
lldArgvCacheMu.Lock()
229-
lldArgvCache[key] = disk
230-
lldArgvCacheMu.Unlock()
219+
storeLldArgv(key, disk)
231220

232221
return disk
233222
}
234223

235-
entry = probeLldArgv(opts)
224+
entry := probeLldArgv(opts)
236225
if entry.err == nil {
237226
writeLldArgvToDisk(key, entry)
238227
}
239228

240-
lldArgvCacheMu.Lock()
241-
lldArgvCache[key] = entry
242-
lldArgvCacheMu.Unlock()
229+
storeLldArgv(key, entry)
243230

244231
return entry
245232
}
246233

234+
func lookupLldArgv(key lldArgvKey) (*lldArgvEntry, bool) {
235+
lldArgvCacheMu.Lock()
236+
defer lldArgvCacheMu.Unlock()
237+
238+
e, ok := lldArgvCache[key]
239+
240+
return e, ok
241+
}
242+
243+
func storeLldArgv(key lldArgvKey, entry *lldArgvEntry) {
244+
lldArgvCacheMu.Lock()
245+
defer lldArgvCacheMu.Unlock()
246+
247+
lldArgvCache[key] = entry
248+
}
249+
247250
// lldProbeCacheDir is the on-disk cache root for linker-argv probe
248251
// results. Lives under .build/host-info alongside the host clang
249252
// metadata so a single `rm -rf .build/host-info` clears every host-
@@ -285,6 +288,7 @@ func readLldArgvFromDisk(k lldArgvKey) *lldArgvEntry {
285288

286289
pf := strings.Split(strings.TrimRight(parts[1], "\n"), "\n")
287290
sf := strings.Split(strings.TrimRight(parts[2], "\n"), "\n")
291+
288292
if len(pf) == 1 && pf[0] == "" {
289293
pf = nil
290294
}
@@ -536,7 +540,7 @@ func isClangTempForBase(t, base string) bool {
536540
}
537541

538542
for _, c := range rest {
539-
if !((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) {
543+
if (c < '0' || c > '9') && (c < 'a' || c > 'f') && (c < 'A' || c > 'F') {
540544
return false
541545
}
542546
}

codegen/check_const_writes.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package codegen
1919
// "may-mutate" set per function name.
2020
//
2121
// 2. Body pass: for each function, mark every binding tainted that
22-
// is initialised from `&top_level_const` or aliases another
22+
// is initialized from `&top_level_const` or aliases another
2323
// tainted binding. Warn when:
2424
// - `*p = ...`, `*p += ...`, `*p++` is performed on a tainted p,
2525
// or
@@ -165,6 +165,7 @@ func scanMutatingParams(fn *ast.FuncDecl, mutators map[string]map[int]bool) map[
165165
}
166166

167167
var walk func(node ast.Node)
168+
168169
walk = func(node ast.Node) {
169170
switch v := node.(type) {
170171
case *ast.Block:
@@ -224,6 +225,7 @@ func scanMutatingParams(fn *ast.FuncDecl, mutators map[string]map[int]bool) map[
224225
walk(v.Body)
225226
case *ast.MatchStmt:
226227
walk(v.Expr)
228+
227229
for _, c := range v.Cases {
228230
walk(c.Body)
229231
}
@@ -311,6 +313,7 @@ func (cg *CodeGen) checkFuncForConstWrites(
311313
tainted := map[string]bool{}
312314

313315
var walk func(node ast.Node)
316+
314317
walk = func(node ast.Node) {
315318
switch v := node.(type) {
316319
case *ast.Block:
@@ -384,6 +387,7 @@ func (cg *CodeGen) checkFuncForConstWrites(
384387
walk(v.Body)
385388
case *ast.MatchStmt:
386389
walk(v.Expr)
390+
387391
for _, c := range v.Cases {
388392
walk(c.Body)
389393
}

codegen/check_unwrapped.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ func (cg *CodeGen) computeFnsTouchingExtern() {
118118
// Propagate: any caller of a touching-fn is itself touching.
119119
// callGraph maps caller -> []callee; flip it once for the worklist.
120120
callers := map[string][]string{}
121+
121122
for caller, callees := range cg.callGraph {
122123
for _, c := range callees {
123124
callers[c] = append(callers[c], caller)

codegen/decls.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2518,6 +2518,7 @@ func (cg *CodeGen) lookupTemplateFile(tmplName string) string {
25182518
}
25192519

25202520
suffix := "__" + tmplName
2521+
25212522
for k, v := range cg.structDeclFiles {
25222523
if v == "" {
25232524
continue
@@ -2628,7 +2629,7 @@ func (cg *CodeGen) ambiguousMethodError(structName string, methods []*ast.FuncDe
26282629
details.WriteString(" with ")
26292630
details.WriteString(whereGuardSummary(m.Constraints))
26302631
details.WriteString(" (declared at ")
2631-
details.WriteString(fmt.Sprintf("%s:%d:%d", declFile, m.Pos().Line, m.Pos().Col))
2632+
fmt.Fprintf(&details, "%s:%d:%d", declFile, m.Pos().Line, m.Pos().Col)
26322633
details.WriteByte(')')
26332634
}
26342635

codegen/diag_snippet.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ func ansi(code, s string) string {
5454
return code + s + ansiReset
5555
}
5656

57-
func ansiBoldText(s string) string { return ansi(ansiBold, s) }
58-
func ansiRedText(s string) string { return ansi(ansiRed, s) }
57+
func ansiBoldText(s string) string { return ansi(ansiBold, s) }
58+
func ansiRedText(s string) string { return ansi(ansiRed, s) }
5959
func ansiYellowText(s string) string { return ansi(ansiYellow, s) }
60-
func ansiCyanText(s string) string { return ansi(ansiCyan, s) }
61-
func ansiDimText(s string) string { return ansi(ansiDim, s) }
60+
func ansiCyanText(s string) string { return ansi(ansiCyan, s) }
61+
func ansiDimText(s string) string { return ansi(ansiDim, s) }
6262

6363
// diagHeader matches the standard `file:line:col[-endcol]: ...`
6464
// prefix produced by every codegen / parser error. The file group
@@ -165,9 +165,11 @@ func formatHeader(level, msg, flag string, file string, lineNum, col int) string
165165
var b strings.Builder
166166

167167
colorize := ansiRedText
168-
if level == "warning" {
168+
169+
switch level {
170+
case "warning":
169171
colorize = ansiYellowText
170-
} else if level == "note" {
172+
case "note":
171173
colorize = ansiCyanText
172174
}
173175

@@ -183,7 +185,7 @@ func formatHeader(level, msg, flag string, file string, lineNum, col int) string
183185
b.WriteString("\n")
184186
b.WriteString(strings.Repeat(" ", numWidth(lineNum)+1))
185187
b.WriteString(ansiCyanText("--> "))
186-
b.WriteString(fmt.Sprintf("%s:%d:%d", file, lineNum, col))
188+
fmt.Fprintf(&b, "%s:%d:%d", file, lineNum, col)
187189

188190
return b.String()
189191
}
@@ -227,7 +229,7 @@ func formatSnippet(level, msg, flag, file string, lineNum, col, endCol int, sour
227229

228230
b.WriteString(gutter)
229231
b.WriteString(ansiCyanText("--> "))
230-
b.WriteString(fmt.Sprintf("%s:%d:%d\n", file, lineNum, col))
232+
fmt.Fprintf(&b, "%s:%d:%d\n", file, lineNum, col)
231233

232234
b.WriteString(gutter)
233235
b.WriteString(ansiCyanText("|\n"))
@@ -293,10 +295,12 @@ func caretSpan(source string, col int) int {
293295
ch := source[col-1+n]
294296
if ch == '\\' && col-1+n+1 < len(source) {
295297
n += 2 // skip the escaped char as a unit
298+
296299
continue
297300
}
298301

299302
n++
303+
300304
if ch == quote {
301305
break
302306
}

codegen/exprs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,7 @@ func (cg *CodeGen) genBinExpr(block *ir.Block, e *ast.BinExpr) (value.Value, err
10511051
hint := ""
10521052
if e.Op == "+" && isStringType(lt) && isStringType(rt) {
10531053
hint = " (use %q to concatenate strings)"
1054+
10541055
return nil, cg.nodeErr(e,
10551056
"binary operator %q is not defined for operands of type %s and %s"+hint,
10561057
e.Op, cg.tinTypeDisplay(lt), cg.tinTypeDisplay(rt), "++")

codegen/exprs_call.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ func (cg *CodeGen) genCallExpr(block *ir.Block, e *ast.CallExpr) (value.Value, e
568568
if pt, ok := objVal.Type().(*irtypes.PointerType); ok {
569569
if traitName, ok2 := cg.isTraitFatPtr(pt.ElemType); ok2 {
570570
loaded := block.NewLoad(pt.ElemType, objVal)
571+
571572
result, err := cg.callTraitMethod(block, loaded, traitName, fn.Field, e.Args)
572573
if err != nil {
573574
return nil, cg.nodeErr(e, "%v", err)

codegen/globals.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -674,23 +674,6 @@ func (cg *CodeGen) inferTopLevelVarType(n ast.Node) ast.TypeExpr {
674674
return nil
675675
}
676676

677-
// inferTopLevelVarType is the function-free wrapper kept for callers
678-
// that don't have a *CodeGen handy.
679-
func inferTopLevelVarType(n ast.Node) ast.TypeExpr {
680-
switch n.(type) {
681-
case *ast.IntLit:
682-
return &ast.SimpleType{Name: "i64"}
683-
case *ast.FloatLit:
684-
return &ast.SimpleType{Name: "f64"}
685-
case *ast.BoolLit:
686-
return &ast.SimpleType{Name: "bool"}
687-
case *ast.StringLit:
688-
return &ast.SimpleType{Name: "string"}
689-
}
690-
691-
return nil
692-
}
693-
694677
// topLevelVarKindWord returns the source-keyword form ("const" / "var")
695678
// for a TopLevelVar so error messages match what the user wrote.
696679
func topLevelVarKindWord(tv *ast.TopLevelVar) string {

codegen/runtime.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ func (cg *CodeGen) staticCallIRName(fn *ast.FieldAccess) string {
466466
}
467467

468468
concrete := bareName
469+
469470
if typeArg != "" {
470471
parts := strings.Split(typeArg, ",")
471472
for i := range parts {
@@ -482,13 +483,13 @@ func (cg *CodeGen) staticCallIRName(fn *ast.FieldAccess) string {
482483
// fat-ptr value whose `data` field is an escape-promoted heap block. Two
483484
// shapes qualify:
484485
//
485-
// 1. Direct: `let p *Trait = &b` where b is in cg.curFnEscapingVars.
486-
// buildPtrToTraitBorrow heap-allocs the iface here; b's heap block
487-
// becomes iface.data.
488-
// 2. Forwarded: `let s = make()` where make() was recorded as
489-
// fnReturnsOwningIface -- make's body created an owning iface and
490-
// returned it. The flag must hop across the call so the caller's
491-
// scope-exit can release both the iface and its data.
486+
// 1. Direct: `let p *Trait = &b` where b is in cg.curFnEscapingVars.
487+
// buildPtrToTraitBorrow heap-allocs the iface here; b's heap block
488+
// becomes iface.data.
489+
// 2. Forwarded: `let s = make()` where make() was recorded as
490+
// fnReturnsOwningIface -- make's body created an owning iface and
491+
// returned it. The flag must hop across the call so the caller's
492+
// scope-exit can release both the iface and its data.
492493
//
493494
// Returns true on either shape so emitScopeRelease cascades through the
494495
// data field on drop.
@@ -632,9 +633,7 @@ func (cg *CodeGen) curFnOwnsStruct(structName string) bool {
632633
// "<Bare>__<typeArgs>" (Bare carries the same #closed tag in noCopyStructs/
633634
// closedStructs since genStructDecl is re-run on the concrete decl).
634635
// "<StructName>$coro" is the async-method coro variant; trim the suffix.
635-
if strings.HasSuffix(fnName, "$coro") {
636-
fnName = strings.TrimSuffix(fnName, "$coro")
637-
}
636+
fnName = strings.TrimSuffix(fnName, "$coro")
638637

639638
prefix := structName + "_"
640639
if strings.HasPrefix(fnName, prefix) {

codegen/scope.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -170,18 +170,3 @@ func (s *scope) eachReverse(fn func(name string, e *scopeEntry)) {
170170
}
171171
}
172172
}
173-
174-
// declKind returns the source-level keyword ("let" / "const" / "var")
175-
// corresponding to this entry's declaredConst / declaredLet flags.
176-
// Used by diagnostics that need to mention how the user spelled the
177-
// declaration. Returns "var" as the fallback when neither flag is set.
178-
func (e *scopeEntry) declKind() string {
179-
switch {
180-
case e.declaredConst:
181-
return "const"
182-
case e.declaredLet:
183-
return "let"
184-
default:
185-
return "var"
186-
}
187-
}

0 commit comments

Comments
 (0)