Skip to content

v0.7.0

Choose a tag to compare

@mpyw mpyw released this 23 Dec 03:33
· 81 commits to main since this release
802a081

New Features

conc Library Support

Added support for github.com/sourcegraph/conc APIs:

# Enable/disable with -conc flag (default: true)
goroutinectx -conc=false ./...

Supported APIs:

Example:

// v0.6.0: No detection
// v0.7.0: Detects missing context
func handler(ctx context.Context) {
    p := pool.New()
    p.Go(func() {        // Warning: pool.Pool.Go() closure should use context "ctx"
        doSomething()
    })
}

E2E Tests

Added end-to-end CLI tests that build and run the actual binary.


Command Options

Flag v0.6.0 v0.7.0
-conc N/A true (NEW)
-goroutine true true
-errgroup true true
-waitgroup true true
-spawner true true
-spawnerlabel false false
-gotask true true

Detection Improvements

Higher-Order Function Patterns

v0.6.0: Limited detection
v0.7.0: Improved SSA-based tracing

// Now correctly detected
func handler(ctx context.Context) {
    makeWorker := func() func() {
        return func() {
            fmt.Println("no ctx")  // v0.7.0: Detected!
        }
    }
    go makeWorker()()
}

Factory Function Returns

func handler(ctx context.Context) {
    g := new(errgroup.Group)
    g.Go(makeTask())  // v0.7.0: Traces into makeTask() return value
}

func makeTask() func() error {
    return func() error {
        return nil  // Warning if ctx not captured
    }
}

Struct Field / Slice / Map Access

func handler(ctx context.Context) {
    holder := &taskHolder{
        task: func() error { return nil },  // No ctx
    }
    g.Go(holder.task)  // v0.7.0: Detected!

    tasks := []func() error{func() error { return nil }}
    g.Go(tasks[0])  // v0.7.0: Detected!
}

Internal Architecture Changes

SSA-Based Analysis Foundation

  • New internal/ssa/ package for Static Single Assignment analysis
  • More accurate variable tracking across assignments
  • Better nested closure context capture detection

Unified Pattern/Registry System

Before (v0.6.0):

internal/checkers/
├── errgroup/checker.go
├── goroutine/checker.go
├── goroutinederive/checker.go
├── gotask/checker.go
├── spawner/checker.go
├── spawnerlabel/checker.go
└── waitgroup/checker.go

After (v0.7.0):

internal/
├── apis.go              # API registration
├── runner.go            # Unified runner
├── registry/            # Pattern registry
├── patterns/            # Pattern implementations
│   ├── gostmt.go
│   ├── closure_captures_ctx.go
│   ├── callback_calls_deriver.go
│   └── ...
└── ssa/                 # SSA analysis
    ├── builder.go
    ├── tracer.go
    └── helpers.go

Context Detection Reorganization

internal/context/ split into focused files:

  • capture.go - Context capture detection
  • assignment.go - Variable assignment tracking
  • composite.go - Composite type handling
  • factory.go - Factory function analysis

File Changes Summary

  • 119 files changed
  • +6,008 insertions
  • -2,640 deletions