Go with checked errors, nil-safe option types, closed unions, and a way back to standard Go.
LoGOs is a fork of the Go 1.27.4 toolchain that adds the .lgo language and the logos command. It is for Go developers who want compiler-checked error paths, nilability, concurrency boundaries, and generated serialization while staying inside Go's module and package model.
The logos command builds .lgo and .go packages. The go command keeps upstream Go language semantics and command text. When you need to leave, logos eject writes a standard Go copy of the module.
package main
import (
"fmt"
"strconv"
)
func double(s string) (int, error) {
n := strconv.Atoi(s)?
return 2 * n, nil
}
func main() {
fmt.Println(double("21"))
}Output:
42 <nil>
Why use it:
?makes an error path explicit at the call site and checked at compile time.*Tdeclared in.lgois non-nil; pointers from imported Go packages may be nil, so compare them withnilbefore dereferencing.T?marks absence and supports?.and??.- A closed union declares its variants, and the compiler checks exhaustive switches.
go groupjoins child goroutines and cancels siblings on the first failure.logos ejectemits standard Go with source comments and support modules preserved.
Contents: Quick start · Installation · Usage · Language tour · Documentation · Development · License
The repository ships a source build. Build it with Bash and an upstream Go 1.27.4 installation:
git clone https://github.com/gosuda/LoGOs.git
cd LoGOs
unset GOROOT GOTOOLCHAIN
upstream_go=$(command -v go)
bootstrap_root=$(env -u GOROOT GOTOOLCHAIN=local "$upstream_go" env GOROOT)
(cd src && GOROOT_BOOTSTRAP="$bootstrap_root" ./make.bash)
export GOROOT="$PWD"
export PATH="$GOROOT/bin:$PATH"
export GOTOOLCHAIN=local
logos versionlogos version reports the fork's Go baseline, for example logos version go1.27.4 linux/amd64.
Create a module outside the toolchain tree:
hello=$(mktemp -d) && cd "$hello"
logos mod init example.com/hello
cat > main.lgo <<'EOF'
package main
import (
"fmt"
"strconv"
)
func double(s string) (int, error) {
n := strconv.Atoi(s)?
return 2 * n, nil
}
func main() {
fmt.Println(double("21"))
}
EOF
logos run .Output:
42 <nil>
- CI bootstraps the fork with upstream Go 1.27.4.
- If
gois not onPATH, orcommand -v gofinds a LoGOs build instead of upstream Go, pass the upstream root directly:GOROOT_BOOTSTRAP=/path/to/go. - The build installs
bin/goandbin/logosin the repository. ExportGOROOT,PATH, andGOTOOLCHAINin each shell that uses them. README.go.mdis the upstream Go README retained for the base project; it does not document a LoGOs binary installer.
Use logos on a LoGOs module the way you use go on a Go module: logos mod init, logos build, logos run, logos test, logos list, and logos get follow their Go counterparts.
LoGOs adds these commands:
-
logos conc run|test [conc flags]runs a program or its tests under a monitor that reports lock order inversions, stalled group children, goroutine leaks, long lock holds, and unbounded groups. -
logos context <pkg>#<symbol>prints one declaration and one level of signatures without function bodies. -
logos eject -o DIRwrites a standard Go copy of the main module. -
logos lint [build flags] [--pedantic] [--json-diagnostics] [packages]runs compiler lints without writing binaries. -
logos lspserves the language server protocol over standard input and output throughgopls. -
logos next [--fix | --ai-patch]previews the conversion of a Go module to.lgosource as a diff;--fixprints a patch for you to apply, and no form of the command changes a source file.
Module rules:
- A module holds only
.lgopackages or only.gopackages; a package holds one kind. - A
.lgopackage can import a Go package, and a.gopackage can import a LoGOs package underlogos. - Plain
goignores.lgofiles while it loads packages. Invoked asgo, the binary decides before any toolchain selection whether to re-execute aslogos: for a LoGOs-only subcommand orgo helptopic, for alogos.tomlbesidego.mod(read through-overlayfrom the command line orGOFLAGS), for a directory the command names, for thealland./...patterns (at a workspace root, unioning the members) and package paths and package-path patterns that map onto a main-module directory holding LoGOs sources and no.gofiles, and, during package loading only, for an import that resolves to such a directory in the main modules or in a dependency. The import trigger fires only with no Go provider and exactly one LoGOs-only candidate, one directory for a single-package path or one module root for a...pattern; a named file is an input to the command and never triggers. The target scan skips the value of every flag that takes one, in both the-flag valueand the-flag=valueforms; a bare word that resolves to no path is no target, so the working-directory rule still applies. A...pattern counts only a directory whose import path matches the full pattern; avendortree counts only when the pattern names that vendor path, while directories ago.modignoredirective excludes never count. A program that logos starts sees the host's effective -O level in LOGOS_OPT_LEVEL: a test binary and a logos run program carry it, and the level resolves from the -O flag, then LOGOS_OPT_LEVEL, then the logos.toml of the main module roots. Inlogosmode the command never switches to a stock toolchain.go version,go env,go bug, andgo telemetrykeep the upstream text;go helpkeeps the upstream text except with a LoGOs-only subcommand as its topic, which re-executes aslogosto describe it; andgo fmtformats.gofiles and ignores.lgofiles without re-executing. The standard library never triggers a re-execution.
logos eject writes every .lgo file as a .go file, copies LoGOs dependency modules under _logos_deps, and places the shared support module under _logos_deps/rt as github.com/gosuda/loGos/rt. The output builds with upstream Go 1.27.4 or newer.
logos eject -o /tmp/logos-hello-go &&
cd /tmp/logos-hello-go &&
env -u GOROOT -u GOTOOLCHAIN "$upstream_go" run .Output:
42 <nil>
DIR must not exist, or it must be empty. Ejection never replaces files in the source module; keep DIR outside the module, because a nested DIR such as ./out still lands inside the source tree.
logos lint ./...
logos lint --pedantic --json-diagnostics ./...logos lint checks packages in the main module only. It applies every rule to .lgo packages and language-neutral rules to .go packages, then stops before code generation. --pedantic raises the pedantic group from allow to warn; --json-diagnostics prints one JSON object per diagnostic.
A //logos:allow(<rule>) comment before a statement or declaration silences a deny or warn rule. It cannot silence a forbid rule in .lgo source. A //logos:zeroalloc comment above a function makes allocation sites selected by escape analysis a diagnostic.
? unwraps every non-error result from a call whose last result is error. On a non-nil error it returns the zero values plus the original error from a function whose last result is error.
package main
import (
"fmt"
"strconv"
)
func parsePair(raw string) (sum int, err error) {
n := strconv.Atoi(raw)?
defer cleanup()?
return n + n, nil
}
func cleanup() error { return nil }
func main() {
fmt.Println(parsePair("21"))
}Output:
42 <nil>
defer f()? joins a cleanup error into the result. errdefer f() runs only when the function returns an error, panics, or exits through runtime.Goexit. Deferred calls still run last in, first out.
go group keeps child goroutines inside a block, joins them before the block exits, cancels siblings after the first error or panic, and caps concurrency with limit.
package main
import (
"context"
"fmt"
"logos/sync"
)
func run(ctx context.Context) error {
var c sync.Locked[int]
go group (ctx, limit = 8) {
for _, x := range []int{10, 20, 30} {
go {
c.WithLock(s => { *s += x })
}
}
}
var res int
c.WithLock(s => { res = *s })
fmt.Println("sum:", res)
return nil
}
func main() {
if err := run(context.Background()); err != nil {
panic(err)
}
}Output:
sum: 60
logos/sync.Locked[T] pairs a value with its mutex and exposes it through WithLock. Hot[T] atomically publishes read-mostly values. A bare go statement in .lgo outside a group is a compile error.
A closed union is an interface with a finite member list. A type switch expression without default must cover every member and nil.
package main
import "fmt"
type Value interface {
int | string
}
func tag(v Value) string {
return switch v.(type) {
case int => "int"
case string => "str"
case nil => "nil"
}
}
func main() {
var v Value = 7
fmt.Println(tag(v))
var z Value
fmt.Println(tag(z))
}Output:
int
nil
A property interface declares field-style contracts. A struct satisfies it through an explicit : I declaration:
package main
import "fmt"
type Creature interface {
const Name string
HP int
}
type Monster struct : Creature {
Name string
HP int
}
func main() {
m := &Monster{Name: "orc", HP: 7}
m.HP += 5
fmt.Println(m.Name, m.HP)
}Output:
orc 12
A read-write property requires a pointer. Go importers see generated getter and setter methods, while .lgo code reads and writes m.HP directly.
const if, const for, and const switch T move fixed decisions into compilation. const for unrolls over a struct's fields in declaration order.
package main
import (
"comptime"
"fmt"
)
type Src struct{ X int }
type Dst struct{ X int }
func copyFields[D, S any](dst *D, src *S) {
const for _, f := range comptime.Fields[D]() {
dst.[f] = src.[f]
}
}
func main() {
var d Dst
copyFields(&d, &Src{X: 7})
fmt.Println(d.X)
}Output:
7
const switch T picks a case by the type argument: exact cases match one named type, ~ cases match an underlying basic type, and interface cases expose that interface's method set. Unmatched types continue after the switch. A default arm and multiple types in one case are syntax errors.
A function's multiple results can become a named tuple. Tuples can be stored, passed, destructured, and read by field name.
package main
import "fmt"
func resolve(service string) (host string, port int) {
return "api.example.com", 443
}
func main() {
api := resolve("api")
fmt.Println(api.host, api.port)
host, port := api
fmt.Println(host, port)
}Output:
api.example.com 443
api.example.com 443
The language also has target-typed lambdas (x => x + 1) and slice chains such as xs.filter(x => x > 2).map(x => 2 * x).take(5). Consecutive filter, map, take, and drop stages fuse into one loop.
A const view reads an existing slice, pointer, map, or composite without allowing writes through that name. logos/rt.Freeze deep-copies a value and returns a protected view, so later writes to the source cannot change it.
Fixed-size numeric arrays support element-wise +, -, *, /, &, |, and ^, plus .sum(), .min(), .max(), and .dot():
package main
import "fmt"
func main() {
a := [4]float64{1, 2, 3, 4}
b := [4]float64{5, 6, 7, 8}
fmt.Println(a + b, a.dot(b))
}Output:
[6 8 10 12] 70
Array operators work on power-of-two arrays of at most 64 bytes. With GOEXPERIMENT=simd, supported shapes lower through simd/archsimd behind a CPU feature check; otherwise the compiler emits unrolled scalar code with the same numeric result.
| Form | What it does |
|---|---|
$"user {name}: {count}" |
Interpolates supported values once, left to right. |
&expr |
Gives a non-addressable value a fresh pointer each evaluation. |
type Cfg struct { Port int = 8080 } |
Fills omitted fields from constant defaults in .lgo literals. |
S{A: 1, ..src()} |
Copies same-name, same-type fields from a struct source. |
yield |
Writes iter.Seq and iter.Seq2 generators without returning a closure literal. |
scope defer |
Runs cleanup at block exit, including each loop iteration. |
const composites and maps |
Places fixed data in read-only storage and lowers map lookup without a run-time map table. |
| Static JSON and binary methods | Generates marshalers for eligible .lgo structs without a call-site rewrite. |
logos.toml |
Configures cgo policy, optimization, target CPU, arena behavior, lint severities, and capability audits. |
-O=0 to -O=3 and -O=s |
Selects optimization levels for Go and LoGOs packages; O3 adds bounded scalar analysis. |
| Automatic vectorization | Vectorizes eligible integer loops with GOEXPERIMENT=simd on supported targets while retaining scalar semantics. |
| WASM profile | Activates for GOOS=js GOARCH=wasm and GOOS=wasip1 GOARCH=wasm under logos, including a host loader. |
//logos:zeroalloc |
Rejects escape-analysis heap sites in the marked function without claiming every run-time allocation is impossible. |
- Language specification: the normative contract for every language form.
- Implementation plan and milestone map: shipped slices, gates, and build-plan context.
- AGENTS.md: repository commands, test entry points, and contribution workflow.
- Agent skills: packaged usage, review, migration, performance, concurrency, and toolchain skills.
- Upstream Go README: the retained README for the base Go project.
Build the toolchain with the source-build commands in the quick start. Then run focused checks from the repository root:
export GOROOT="$PWD"
export PATH="$GOROOT/bin:$PATH"
export GOTOOLCHAIN=local
(cd src && go test -count=1 cmd/internal/testdir -run 'Test/logos/')
(cd src && go test -count=1 -short cmd/compile/internal/types2 -run TestLogos)
(cd src && go test -count=1 cmd/go -run 'Script/^logos_')For contributions, read AGENTS.md first. Add language behavior with a failing test under test/logos/ or src/internal/types/testdata/logos/, run the focused gate, and keep plain go behavior compatible unless a documented exception applies. Commit subjects use the Go convention <area>: <lowercase summary>.
CONTRIBUTING.md is the inherited upstream Go contribution document. The fork-specific workflow is in AGENTS.md.
LoGOs additions and toolchain modifications use the BSD-3-Clause license, the same license as the standard Go source. See LICENSE for the terms.