• This repository has been archived on 19/Mar/2024
  • Stars
    star
    216
  • Rank 183,179 (Top 4 %)
  • Language
    Go
  • License
    BSD 3-Clause "New...
  • Created almost 8 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Reduce Go programs

goreduce

Build Status

Reduce a program to its simplest form as long as it produces a compiler error or any output (such as a panic) matching a regular expression.

go get -u mvdan.cc/goreduce

Example

func main() {
        a := []int{1, 2, 3}
        if true {
                a = append(a, 4)
        }
        a[1] = -2
        println(a[10])
}
goreduce -match 'index out of range' .
func main() {
        a := []int{}
        println(a[0])
}

For more usage information, see goreduce -h.

Design

  • The tool should be reproducible, giving the same output for an input program as long as external factors don't modify its behavior
  • The rules should be as simple and composable as possible
  • Rules should avoid generating changes that they can know won't compile

Rules

Removing

Before After
statement a; b a or b
index a[1] a
slice a[:2] a or a[:]
binary part a + b, a && b a or b
unary op -a, !a a
star *a a
parentheses (a) a
if/else if a { b } else c b or c
defer defer f() f()
go go f() f()
basic value 123, "foo" 0, ""
composite value T{a, b} T{}

Inlining

Before After
const const c = 0; f(c) f(0)
var v := false; f(v) f(false)
case case x: a a
block { a } a
simple call f() { body }

Resolving

Before After
integer op 2 * 3 6
string op "foo" + "bar" "foobar"
slice "foo"[1:] "oo"
index "foo"[0] 'f'
builtin len("foo") 3

More Repositories

1

sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
Go
7,112
star
2

gofumpt

A stricter gofmt
Go
3,184
star
3

xurls

Extract urls from text
Go
1,175
star
4

github-actions-golang

GitHub Actions as CI for Go
Go
1,025
star
5

interfacer

A linter that suggests interface types
Go
690
star
6

unparam

Find unused parameters in Go
Go
527
star
7

gogrep

Search for Go code using syntax trees
Go
477
star
8

fdroidcl

F-Droid desktop client
Go
262
star
9

bitw

Minimalist BitWarden client
Go
168
star
10

zstd

Zstandard implementation in Wuffs
C
112
star
11

corpus

A corpus of popular Go modules
Go
106
star
12

dockexec

Run Go tests inside a Docker image
Go
98
star
13

accesspoint

Manage wireless access points in Android (abandoned)
Java
73
star
14

benchinit

Benchmark the init cost of Go packages
Go
72
star
15

pastecat

Pastebin service (abandoned)
Go
36
star
16

git-picked

List merged and cherry-picked branches
Go
29
star
17

winup

Automate a Windows 10 VM setup for coding and testing
Go
21
star
18

unindent

Report code that is unnecessarily indented
Go
19
star
19

android-template

Android app template
Java
16
star
20

dotfiles

Here be dragons
Shell
14
star
21

talks

Collection of slides from talks
Go
9
star
22

go-concurrency-workshop

Go
9
star
23

editorconfig

EditorConfig support in Go
Go
8
star
24

lint

Common interfaces for Go code checkers
Go
6
star
25

macfuzzer

Android MAC changer and randomizer (abandoned)
Java
6
star
26

gexf

GEXF file format implementation
Go
3
star
27

mvdan.cc

Personal website
HTML
3
star
28

playtyk

This repo is a temporary home for a hack.
Go
3
star
29

responsefile

Support for response files in Go, to bypass argument length limits
Go
2
star
30

tor

Consensus diffs Tor GSoC project
C
1
star
31

route

portable Go package to obtain simple routing information
Go
1
star
32

nowt

Nothing extraordinary here
Go
1
star
33

basedir

Platform-specific base directories
Go
1
star