Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Generated seed of trackc (scripts/update_seed.sh): collapse it in diffs.
bootstrap/seed/*.c linguist-generated=true -diff
# The committed native seed of trackc (scripts/update_seed.sh): a binary.
bootstrap/seed/trackc binary
48 changes: 29 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ on:

jobs:
build:
# Track from the committed C seed: cc and POSIX tools only.
# Track from the committed native seed (bootstrap/seed/trackc, a static
# x86-64 Linux ELF): no C compiler, assembler, linker or Rust toolchain.
runs-on: ubuntu-latest
env:
TRACKC: ${{ github.workspace }}/build/bootstrap/stage3/trackc
steps:
- uses: actions/checkout@v4

- name: No Rust toolchain on PATH
- name: Bootstrap from bootstrap/seed/trackc (seed -> stage1 -> stage2 = stage3)
# Only the tools bootstrap.sh uses are on PATH; every stage runs
# under env -i PATH=/nonexistent.
run: |
if env PATH=/usr/bin:/bin sh -c 'command -v cargo || command -v rustc'; then
echo "cargo or rustc is reachable"; exit 1
fi
echo "✓ no cargo or rustc on PATH=/usr/bin:/bin"

- name: Bootstrap from bootstrap/seed (cc -> stage1 -> stage3, then native)
run: env PATH=/usr/bin:/bin scripts/bootstrap.sh
mkdir -p /tmp/bootstrap-bin
for t in sh cp chmod mkdir rm cmp wc basename dirname env sed; do
ln -sf "$(command -v "$t")" /tmp/bootstrap-bin/"$t"
done
env -i PATH=/tmp/bootstrap-bin HOME="$HOME" scripts/bootstrap.sh

- name: Seed is up to date
run: env PATH=/usr/bin:/bin scripts/update_seed.sh --check
Expand All @@ -39,7 +40,7 @@ jobs:
env PATH=/usr/bin:/bin "$TRACKC" check "$f" || { echo "check failed: $f"; exit 1; }
done
mkdir -p build
env PATH=/usr/bin:/bin "$TRACKC" build --native tools/yard/main.trk -o build/yard
env PATH=/usr/bin:/bin "$TRACKC" build tools/yard/main.trk -o build/yard
(cd compiler && env PATH=/usr/bin:/bin TRACKC="$TRACKC" ../build/yard check)
(cd compiler && env PATH=/usr/bin:/bin TRACKC="$TRACKC" ../build/yard build)

Expand All @@ -52,27 +53,36 @@ jobs:
- name: trackc lsp passes its recorded sessions
run: env PATH=/usr/bin:/bin tests/lsp/run.sh "$TRACKC"

- name: Self-hosting from .trk alone (native, no C toolchain)
- name: Self-hosting from .trk alone (n2 = n3 = n4, nothing on PATH)
run: env PATH=/usr/bin:/bin scripts/selfhost.sh "$TRACKC"

- name: Check examples
- name: Examples build, run and match their goldens
run: |
hb=0
[ -f /etc/hostname ] && hb=$(wc -c </etc/hostname | tr -d ' ')
mkdir -p build/examples
for f in examples/*.trk; do
if [[ "$f" == *"_err.trk" ]]; then
s=$(basename "$f" .trk)
if [[ "$s" == *_err ]]; then
if env PATH=/usr/bin:/bin "$TRACKC" check "$f" >/dev/null 2>&1; then
echo "Error: expected rejection for $f but check succeeded"
exit 1
echo "Error: expected rejection for $f but check succeeded"; exit 1
fi
echo "✓ rejected $f"
else
env PATH=/usr/bin:/bin "$TRACKC" check "$f"
continue
fi
env PATH=/usr/bin:/bin "$TRACKC" build "$f" -o "build/examples/$s" >/dev/null
set +e
env PATH=/usr/bin:/bin "build/examples/$s" >"build/examples/$s.out" 2>/dev/null
rc=$?
set -e
sed "s/@HOSTNAME_BYTES@/$hb/" "tests/cases/examples/$s.out" | cmp -s - "build/examples/$s.out" \
|| { echo "✗ $s: output differs"; exit 1; }
[ "$rc" = "$(cat "tests/cases/examples/$s.code")" ] || { echo "✗ $s: exit $rc"; exit 1; }
echo "✓ $s"
done

- name: Verify versions
run: |
mkdir -p build
env PATH=/usr/bin:/bin "$TRACKC" build --native tools/yard/main.trk -o build/yard >/dev/null
"$TRACKC" --version | grep -q "1.0.0"
build/yard --version | grep -q "1.0.0"
echo "✓ versions ok"
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Removed
- **All C code and the C backend.** `compiler/src/cgen.trk`,
`runtime_c.trk`, `runtime/track_runtime.c`, the C seed
(`bootstrap/seed/trackc.c`, `trackc.rt.c`), `trackc emit-c`,
`scripts/native_parity.sh`, `bench/race.sh` and the C/Rust benchmark
suite in `scratch/` are deleted. `trackc build` and `run` always write
static x86-64 Linux executables; `--native` and `--rt=track` are accepted
no-ops. Track now targets x86-64 Linux only and bootstraps from
`bootstrap/seed/trackc`, a committed native seed binary:
`scripts/bootstrap.sh` runs seed -> stage1 -> stage2 -> stage3 with no C
compiler and requires stage2 = stage3. `scripts/embed_rt.sh` is now
`scripts/embed_runtime.sh`. Tests that compared C with native or needed
cc/ASan are converted to goldens (`tests/cases/native_runs/`) or dropped.
- **All Rust code.** The Rust stage 0 compiler, the Rust yard and the Rust
LSP (`src/`), `Cargo.toml`, `Cargo.lock` and the cargo test suites
(`tests/*.rs`) are deleted. Track builds from the C seed with
Expand Down
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

**Track** is a low-level systems programming language designed for deterministic memory management, zero-cost abstractions, and real-time execution.

- **No Garbage Collector.** Resource lifecycles are verified at compile time; there is no collector and only a small runtime, in C or in Track.
- **No Garbage Collector.** Resource lifecycles are verified at compile time; there is no collector and only a small runtime, written in Track.
- **Linear Ownership.** Rejects use-after-free and double-free. The self-hosted compiler infers where each allocation's life ends and places it on the stack or frees it there ([docs/lifecycles.md](docs/lifecycles.md)).
- **Lexical Lenses.** Scoped mutable access without manual pointer arithmetic or ownership transfer.
- **Native Backend.** `trackc build --native` writes a static x86-64 Linux executable itself, with no C compiler, assembler or linker.
- **Native Backend.** `trackc build` writes a static x86-64 Linux executable itself, with no C compiler, assembler or linker.
- **Track only.** The repository holds no C or Rust. Track targets x86-64 Linux only and bootstraps from a committed native seed binary.

## Hello World

Expand Down Expand Up @@ -51,11 +52,13 @@ curl -fsSL https://raw.githubusercontent.com/dev-dami/track/main/scripts/install

### Build from Source

Requires a C compiler (`cc`) and POSIX tools; nothing else.
Requires an x86-64 Linux host and POSIX tools; nothing else. No C
compiler, assembler or linker is used: Track bootstraps from
`bootstrap/seed/trackc`, a committed static trackc binary.

```bash
scripts/bootstrap.sh # cc -> stage1..3 -> native; trackc is build/bootstrap/stage3/trackc
build/bootstrap/stage3/trackc build --native tools/yard/main.trk -o yard # yard, written in Track
scripts/bootstrap.sh # seed -> stage1..3; trackc is build/bootstrap/stage3/trackc
build/bootstrap/stage3/trackc build tools/yard/main.trk -o yard # yard, written in Track
./scripts/install.sh # or: bootstrap and install trackc + yard
```

Expand All @@ -67,7 +70,7 @@ build/bootstrap/stage3/trackc build --native tools/yard/main.trk -o yard # yar
# Type-check a source file
trackc check examples/hello.trk

# Compile to an executable (through C, or natively with --native)
# Compile to a static x86-64 Linux executable
trackc build examples/hello.trk -o hello
./hello

Expand Down Expand Up @@ -101,44 +104,41 @@ yard test

Track is self-hosting: `compiler/` is the Track compiler written in Track
(`compiler/src/`, plus its runtime in `compiler/rt/`). It compiles itself
to a verified fixed point, through C or natively. A clean checkout
bootstraps with only `cc`. `scripts/bootstrap.sh` builds the committed C
seed (`bootstrap/seed/`). (Earlier versions used a Rust compiler in `src/` as
stage 0; it has been removed, along with the Rust yard and LSP.) The native stages of
the default run need an x86-64 Linux host with `sha256sum` and GNU `date`
(`+%s%N`); elsewhere, use
`scripts/bootstrap.sh --no-native`.
to a verified fixed point. A clean checkout bootstraps from
`bootstrap/seed/trackc`, the committed static x86-64 Linux trackc binary;
`scripts/bootstrap.sh` needs no C compiler. (Earlier versions bootstrapped
from a Rust compiler, then from a committed C seed; both are gone, along
with the C backend.)

```bash
# cc builds bootstrap/seed/ -> stage1; stage1 -> stage2 -> stage3; check the
# C and binary fixed point, then the native fixed point (n2 = n3 = n4)
# seed -> stage1 -> stage2 -> stage3 under env -i PATH=/nonexistent;
# stage2 and stage3 must be byte-identical
scripts/bootstrap.sh # trackc is build/bootstrap/stage3/trackc
scripts/update_seed.sh # regenerate the seed after compiler changes

T=build/bootstrap/stage3/trackc
$T build examples/hello.trk -o hello
$T build -g examples/hello.trk -o hello # with a symbol table
$T run examples/generics.trk
$T emit-c examples/hello.trk # generated C on stdout
$T build --native examples/hello.trk -o hello # no C compiler

# Native trackc rebuilds itself with no C toolchain on PATH (n2 = n3 = n4)
# trackc rebuilds itself with nothing on PATH (n2 = n3 = n4)
scripts/selfhost.sh
```

See [docs/bootstrap.md](docs/bootstrap.md) for the pipeline, the shared
word-ABI runtime, the C backend contract and the native backend, and
See [docs/bootstrap.md](docs/bootstrap.md) for the pipeline, the word-ABI
runtime and the native backend, and
[docs/native.md](docs/native.md) for the runtime written in Track.

## Testing

```bash
scripts/bootstrap.sh # seed bootstrap: C and native fixed points
scripts/bootstrap.sh # seed bootstrap: stage2 = stage3
tests/run.sh -j 4 # language, runtime, native, CLI and tools suites
tests/yard/run.sh # yard behaviour
tests/lsp/run.sh # recorded `trackc lsp` sessions
scripts/update_seed.sh --check # seed matches compiler/src
scripts/selfhost.sh # native fixed point, no C toolchain
bench/native.sh # native vs C scoreboard
scripts/selfhost.sh # fixed point with nothing on PATH
bench/native.sh # native scoreboard (cycles, faults, self-compile)
```

## License
Expand Down
4 changes: 2 additions & 2 deletions SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ with payload variants as heap cells `[tag, payload...]`, structs as
`[name hash, fields...]`, and arrays as `[length, elements...]`. Arithmetic wraps,
shift amounts are taken modulo 64, `>>` is logical, and `/` or `%` by zero, or of
`INT64_MIN` by `-1` (the one quotient that does not fit), traps: stdout is flushed,
then `SIGFPE` (shell status 136) on every backend. Both compilers share this model and the runtime in
`runtime/track_runtime.c`; see [docs/bootstrap.md](docs/bootstrap.md).
then `SIGFPE` (shell status 136). trackc lowers to static x86-64 Linux executables and links
the runtime written in Track (`compiler/rt/`); see [docs/bootstrap.md](docs/bootstrap.md).

## 12. Diagnostics & Error Reporting

Expand Down
60 changes: 24 additions & 36 deletions bench/native.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
#!/bin/sh
# Native-race scoreboard: user-mode cycles of each bench/progs program built
# two ways (trackc --native, trackc via C/gcc -O2), with
# output checked identical, plus native self-compile time. A second table adds wall ms, page faults and
# user-vs-total (user+kernel) cycles so never-freed heap cost is visible.
# Native scoreboard: each bench/progs program built by trackc, its output
# checked against tests/cases/native_runs/<prog>.out, then measured: user-mode
# cycles, wall ms, page faults and user-vs-total (user+kernel) cycles, so
# never-freed heap cost is visible. Ends with the self-compile time.
# Usage: bench/native.sh [trackc] (default $BOOTSTRAP_DIR/stage3/trackc, else build/bootstrap/stage3/trackc)
# Exit 1 on any output mismatch or build failure.
# Needs perf for the cycle columns ("-" without it). Exit 1 on any output
# mismatch or build failure.
set -eu
root=$(cd "$(dirname "$0")/.." && pwd); cd "$root"
T=${1:-${BOOTSTRAP_DIR:-build/bootstrap}/stage3/trackc}
case "$T" in /*) ;; *) T="$root/$T" ;; esac
runs=${RACE_RUNS:-3}
o=$(mktemp -d); trap 'rm -rf "$o"' EXIT
fail=0
cyc() { # median user cycles (millions) of $runs runs
for i in $(seq "$runs"); do
perf stat -x, -e cycles:u "$@" 2>&1 >/dev/null | grep cycles | cut -d, -f1
done | sort -n | awk '{a[NR]=$1} END {printf "%.0f", a[int((NR+1)/2)]/1e6}'
}
# probe <bin>: one perf run per sample -> median "ms faults Mucyc Mtotcyc"
# (wall ms, page faults, user-mode and user+kernel megacycles); "-" without perf.
# (wall ms, page faults, user-mode and user+kernel megacycles); perf columns
# are 0 without perf.
probe() {
command -v perf >/dev/null 2>&1 || { echo "- - - -"; return; }
_n=${RACE_RUNS:-3}; _i=0
while [ $_i -lt "$_n" ]; do
_i=0
while [ $_i -lt "$runs" ]; do
_s=$(date +%s%N)
_p=$(perf stat -x, -e page-faults,cycles:u,cycles "$@" 2>&1 >/dev/null || true)
if command -v perf >/dev/null 2>&1; then
_p=$(perf stat -x, -e page-faults,cycles:u,cycles "$@" 2>&1 >/dev/null || true)
else
"$@" >/dev/null 2>&1 || true; _p=
fi
_e=$(date +%s%N)
echo "$(( (_e - _s) / 1000000 )) $(echo "$_p" | awk -F, '
$3 ~ /^page-faults/ { f = $1 } $3 ~ /^cycles:u/ { u = $1 } $3 ~ /^cycles(:|$)/ && $3 !~ /:u/ { t = $1 }
Expand All @@ -36,30 +36,18 @@ probe() {
for (i = 1; i <= n; i++) for (j = i + 1; j <= n; j++) if (x[j] < x[i]) { t = x[i]; x[i] = x[j]; x[j] = t }
printf "%s%s", x[int((n + 1) / 2)], (k < 4 ? " " : "\n") } }'
}
rows=
printf '%-11s %9s %9s %8s\n' prog native C "nat/C"
printf '%-11s %8s %9s %9s %10s %7s\n' prog "wall ms" faults "user Mcyc" "total Mcyc" "kern %"
for f in bench/progs/*.trk; do
n=$(basename "$f" .trk)
"$T" build --native "$f" -o "$o/$n.nat" >/dev/null 2>&1 || { echo "$n: native build failed"; fail=1; continue; }
"$T" build "$f" -o "$o/$n.c" >/dev/null 2>&1 || { echo "$n: C build failed"; fail=1; continue; }
a=$("$o/$n.nat" 2>&1; echo "rc=$?"); b=$("$o/$n.c" 2>&1; echo "rc=$?")
if [ "$a" != "$b" ]; then echo "$n: OUTPUT MISMATCH"; fail=1; continue; fi
cn=$(cyc "$o/$n.nat"); cc=$(cyc "$o/$n.c")
printf '%-11s %8sM %8sM %8s\n' "$n" "$cn" "$cc" \
"$(awk "BEGIN{printf \"%.2f\", $cn/$cc}")"
for k in native C; do
case $k in native) b=nat ;; C) b=c ;; esac
rows="$rows$(printf '%-11s %-7s %s' "$n" "$k" "$(probe "$o/$n.$b")")
"
done
"$T" build "$f" -o "$o/$n" >/dev/null 2>&1 || { echo "$n: build failed"; fail=1; continue; }
"$o/$n" >"$o/$n.out" 2>/dev/null || true
if ! cmp -s "$o/$n.out" "tests/cases/native_runs/$n.out"; then echo "$n: OUTPUT MISMATCH"; fail=1; continue; fi
probe "$o/$n" | awk -v n="$n" '{ k = ($3 > 0 && $4 >= $3) ? sprintf("%.0f", ($4 - $3) * 100 / $4) : "-"
printf "%-11s %8s %9s %9s %10s %7s\n", n, $1, $2, $3, $4, k }'
done
# honest scoreboard: wall ms, page faults, user vs user+kernel megacycles (median of runs)
printf '\n%-11s %-7s %8s %9s %9s %10s %7s\n' prog build "wall ms" faults "user Mcyc" "total Mcyc" "kern %"
printf '%s' "$rows" | awk 'NF { k = ($5 > 0 && $6 >= $5) ? sprintf("%.0f", ($6 - $5) * 100 / $6) : "-"
printf "%-11s %-7s %8s %9s %9s %10s %7s\n", $1, $2, $3, $4, $5, $6, k }'
# native self-compile: median wall ms of 5
# self-compile: median wall ms of 5
for i in 1 2 3 4 5; do
s=$(date +%s%N); "$T" build --native compiler/src/main.trk -o "$o/self" >/dev/null; e=$(date +%s%N)
s=$(date +%s%N); "$T" build compiler/src/main.trk -o "$o/self" >/dev/null; e=$(date +%s%N)
echo $(( (e - s) / 1000000 ))
done | sort -n | sed -n 3p | xargs printf 'native self-compile (main.trk): %s ms\n'
done | sort -n | sed -n 3p | xargs printf 'self-compile (main.trk): %s ms\n'
exit $fail
Loading
Loading