Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2ec05da
directly define version in code, add language option
mandoway Sep 11, 2024
06a98c2
set version to latest release
mandoway Sep 11, 2024
435b057
add null reduction
mandoway Sep 11, 2024
1e9a6f3
refactor main reduction loop to test all semantic candidates at once …
mandoway Sep 12, 2024
a290859
fix semantic reduction control flow for removing strategies
mandoway Sep 12, 2024
e9fcfbb
add package reduction
mandoway Sep 13, 2024
aa6c817
add github action
mandoway Sep 13, 2024
03e2e0c
fix github action
mandoway Sep 13, 2024
3584961
fix github action
mandoway Sep 13, 2024
733da15
enable lfs in github action
mandoway Sep 14, 2024
a0ab7f8
install cue in github action
mandoway Sep 14, 2024
189fd69
add redundant_nesting strategy, test plugin in CI
mandoway Sep 14, 2024
9add5b5
add list reduction
mandoway Sep 15, 2024
0e42ab7
fix reduction loop and tests
mandoway Sep 15, 2024
90339f0
add method doc
mandoway Sep 15, 2024
990eaa9
add test instances
mandoway Sep 21, 2024
f27b0da
add alternative reduction execution order
mandoway Sep 21, 2024
c03c80c
fix test
mandoway Sep 22, 2024
d6ca772
add if reductions
mandoway Sep 25, 2024
69afb3d
simplify transformations
mandoway Sep 25, 2024
79d7fb8
update setup go action
mandoway Sep 25, 2024
fa2aa9b
add ellipsis reduction
mandoway Sep 26, 2024
90a0473
add constant propagation
mandoway Sep 27, 2024
8990336
add string interpolation, add evaluation of all expressions
mandoway Sep 28, 2024
402916f
fix reduction bugs
mandoway Sep 28, 2024
a3f03eb
fix resolve function, fix constant propagation
mandoway Sep 29, 2024
87d80bb
add support for partial evaluation
mandoway Sep 29, 2024
c83e195
uncomment tests
mandoway Sep 29, 2024
9f40316
add interpolation test
mandoway Sep 29, 2024
b10d66f
add fixpoint termination
mandoway Sep 29, 2024
60c3795
refine logging
mandoway Sep 29, 2024
46e209e
better logging, better fixpoint detection based on content
mandoway Sep 30, 2024
61f55c9
remove all empty declarations, optimize loop
mandoway Sep 30, 2024
d550ee8
fix test
mandoway Sep 30, 2024
a7be253
add loop unrolling
mandoway Oct 1, 2024
226825e
add unification
mandoway Oct 2, 2024
66341a0
add union reduction
mandoway Oct 3, 2024
93f54d5
add goreleaser config
mandoway Oct 4, 2024
30974cf
bump version
mandoway Oct 4, 2024
8ff6aa1
remove extra pr trigger
mandoway Oct 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Release

on:
push:
tags:
- v*

permissions:
contents: write

jobs:
tests:
uses: ./.github/workflows/release.yaml
release:
runs-on: ubuntu-latest
needs: [tests]
steps:
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40 changes: 40 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Test

on:
push:
branches:
- main
- dev
workflow_dispatch:
workflow_call:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
lfs: 'true'

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23.2'

- name: Install CUE
run: go install cuelang.org/go/cmd/cue@latest

- name: Generate
run: go generate -v ./...

- name: Build
run: go build -v ./...

- name: Test Main
run: go test -v ./...

- name: Test CUE
run: go test -v ./languages/cue/...
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ test.sh
# main program
seru

# Perses tools
perses_deploy.jar
cue.jar

# Tools needed for tests
!test/**/*

# Seru output
seru_reduction_*
seru_reduction_*
dist/
60 changes: 60 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

# The lines below are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

project_name: seru
version: 2

before:
hooks:
- go mod tidy

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
files:
- LICENSE*
- README*
- CHANGELOG
- license*
- readme*
- changelog
# use zip for windows archives
format_overrides:
- goos: windows
format: zip

release:
extra_files:
- glob: "*.so"
- glob: cue.jar
- glob: perses_deploy.jar

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,21 @@ SeRu currently supports:
```
3. Make sure you have Java installed (for Perses)
4. Run SeRu using Go or standalone
1. `go run -ldflags="-X github.com/mandoway/seru/version.Version=v0.0.1-alpha" .`
2. `go build -ldflags="-X github.com/mandoway/seru/version.Version=v0.0.1-alpha" && ./seru`
1. `go run .`
2. `go build && ./seru`
3. Command line options:
1. `-i <input>` _Required_
Target file to reduce
2. `-t <test>` _Required_
Test script checking if the reduced file still kept the required property
A test script **must return 0** when the property was kept and 1 (or any code) if the property was lost
3. `-l <language>`
Programming language of the input file. Will be inferred from the file extension if omitted.
4. `-s`
Use strategy isolation.
This mode will apply only one semantic strategy and try to reduce all returned candidates using the syntactic reducer.
Default mode: strategy combination
In strategy combination, all strategies are applied and combined to one "best candidate". Then this one candidate will be reduced by the syntactic reducer.

# Future plans

Expand Down
42 changes: 24 additions & 18 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,32 @@ import (
"os"
)

var (
inputFile, testScript string
rootCmd = &cobra.Command{
Use: "seru",
Short: "A tool to reduce a program while maintaining a property",
// TODO
Long: `TODO`,
Run: func(cmd *cobra.Command, args []string) {
err := reduction.StartReductionProcess(inputFile, testScript, "")
if err != nil {
log.Fatal(err)
}
},
Version: version.Version,
}
)
type Flags struct {
InputFile, TestScript, GivenLanguage string
UseStrategyIsolation bool
}

var flags Flags

var rootCmd = &cobra.Command{
Use: "seru",
Short: "A tool to reduce a program while maintaining a property",
// TODO
Long: `TODO`,
Run: func(cmd *cobra.Command, args []string) {
err := reduction.StartReductionProcess(flags.InputFile, flags.TestScript, flags.GivenLanguage, flags.UseStrategyIsolation)
if err != nil {
log.Fatal(err)
}
},
Version: version.Version,
}

func init() {
rootCmd.PersistentFlags().StringVarP(&inputFile, "input", "i", "", "-i <path to file>")
rootCmd.PersistentFlags().StringVarP(&testScript, "test", "t", "", "-i <path to testscript>")
rootCmd.PersistentFlags().StringVarP(&flags.InputFile, "input", "i", "", "-i <path to file>")
rootCmd.PersistentFlags().StringVarP(&flags.TestScript, "test", "t", "", "-i <path to testscript>")
rootCmd.PersistentFlags().StringVarP(&flags.GivenLanguage, "lang", "l", "", "-l <language of file>")
rootCmd.PersistentFlags().BoolVarP(&flags.UseStrategyIsolation, "strategy-isolation", "s", false, "")

_ = rootCmd.MarkPersistentFlagRequired("input")
_ = rootCmd.MarkPersistentFlagRequired("test")
Expand Down
3 changes: 3 additions & 0 deletions cue.jar
Git LFS file not shown
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
module github.com/mandoway/seru

go 1.23
go 1.23.2

require github.com/stretchr/testify v1.9.0
require (
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
2 changes: 1 addition & 1 deletion go.work
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go 1.23
go 1.23.2

use (
languages/cue
Expand Down
23 changes: 10 additions & 13 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
cuelabs.dev/go/oci/ociregistry v0.0.0-20240807094312-a32ad29eed79/go.mod h1:5A4xfTzHTXfeVJBU6RAUf+QrlfTCW+017q/QiW+sMLg=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/emicklei/proto v1.13.2/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/rogpeppe/go-internal v1.12.1-0.20240709150035-ccf4b4329d21/go.mod h1:RMRJLmBOqWacUkmJHRMiPKh1S1m3PA7Zh4W80/kWPpg=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
Expand All @@ -15,15 +10,17 @@ github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzl
github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A=
github.com/yuin/goldmark v1.7.4 h1:BDXOHExt+A7gwPCJgPIIq7ENvceR7we7rOS9TNoLZeg=
github.com/yuin/goldmark v1.7.4/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU=
golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk=
golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM=
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
12 changes: 12 additions & 0 deletions languages/cue/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ import (

var Strategies = []semantic.Strategy[ast.File]{
strategy.LetReduction{},
strategy.EmptyDeclarationReduction{},
strategy.PackageReduction{},
strategy.RedundantNestingReduction{},
strategy.ListReduction{},
strategy.TrivialIfReduction{},
strategy.IfReduction{},
strategy.EllipsisReduction{},
strategy.ConstantPropagationReduction{},
strategy.StringInterpolationReduction{},
strategy.LoopUnrollingReduction{},
strategy.UnificationReduction{},
strategy.UnionReduction{},
}

var Context = semantic.Context[ast.File]{
Expand Down
4 changes: 2 additions & 2 deletions languages/cue/count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func countTokensUsingApplyAfter(tree *ast.File) int {

func countTokensUsingScanner(t *testing.T, source []byte) int {
eh := func(_ token.Pos, msg string, args []interface{}) {
t.Errorf("error handler called (msg = %s)", fmt.Sprintf(msg, args...))
t.Logf("error handler called (msg = %s)", fmt.Sprintf(msg, args...))
}

// verify scan
Expand All @@ -155,7 +155,7 @@ func countTokensUsingScanner(t *testing.T, source []byte) int {
count++
}
if s.ErrorCount > 0 {
t.Errorf("error count is %d", s.ErrorCount)
t.Logf("error count is %d", s.ErrorCount)
}

return count
Expand Down
14 changes: 12 additions & 2 deletions languages/cue/go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
module github.com/mandoway/seru/languages/cue

go 1.23
go 1.23.2

replace github.com/mandoway/seru => ../../.

require (
cuelang.org/go v0.10.0
github.com/mandoway/seru v0.0.0-00010101000000-000000000000
github.com/stretchr/testify v1.9.0
)

require github.com/cockroachdb/apd/v3 v3.2.1 // indirect
require (
github.com/cockroachdb/apd/v3 v3.2.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/text v0.18.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading