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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .github/workflows/regenerate.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: regenerate

# Scheduled proof that the committed goldens are reproducible byte-for-byte
# from the pinned oracle (libpg_query 18.0.0 via pg_query_go's wrapper, cgo).
# from the pinned oracle (libpg_query 18.1.0 via pg_query_go's wrapper, cgo).
# This is the only place cgo ever runs; the main module never links it.

on:
Expand All @@ -24,7 +24,7 @@ jobs:
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- name: Fetch pinned corpus
run: |
git clone --depth 1 --branch 18.0.0 https://github.com/pganalyze/libpg_query /tmp/libpg_query
git clone --depth 1 --branch 18.1.0 https://github.com/pganalyze/libpg_query /tmp/libpg_query
- name: Build the oracle's pg_query_go dependency
# No pg_query_go release ships libpg_query 18 yet; this reproduces
# pg_query_go's `make update_source` against the pinned tag.
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# oliphant development guide

Pure Go port of pg_query_go. Read `PLAN.md` first — it is the contract.
Pin: libpg_query **18.0.0** (PostgreSQL 18.4, patched). No cgo anywhere in
Pin: libpg_query **18.1.0** (PostgreSQL 18.6, patched). No cgo anywhere in
the main module; the only module allowed to link pg_query_go (cgo) is
`oracle/`, and only `cmd/regenerate`/`cmd/difftest` ever run it.

Expand Down
7 changes: 4 additions & 3 deletions PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ PostgreSQL before extraction.

Initial pin: **libpg_query `17-6.2.2` (PostgreSQL 17.7)** — the exact tag
pg_query_go v6.2.2 ships and the version sqlc builds against at the time.
*(The pin advanced on 2026-08-17: the current pin is **libpg_query `18.0.0`
(PostgreSQL 18.4)**, `ParseResult.Version == 180004`, via the § Regeneration
*(The pin advanced on 2026-08-17 to libpg_query `18.0.0` (PostgreSQL 18.4),
and again on 2026-12-01: the current pin is **libpg_query `18.1.0`
(PostgreSQL 18.6)**, `ParseResult.Version == 180006`, via the § Regeneration
workflow. No pg_query_go release ships libpg_query 18 yet, so the oracle
builds pg_query_go's wrapper against the 18.0.0 sources locally — see
builds pg_query_go's wrapper against the 18.1.0 sources locally — see
`oracle/update-pg-query-go.sh`.)* The plan treats "advance the pin" as a
first-class workflow (§ Regeneration) rather than targeting a moving version.

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ error type, same fingerprints. Consumers change one import path:
+import pg_query "github.com/sqlc-dev/oliphant"
```

Pinned to **libpg_query `18.0.0`** (PostgreSQL 18.4, patched) — the exact
build pg_query_go v6.2.2 ships. Every golden in `parser/testdata` derives
Pinned to **libpg_query `18.1.0`** (PostgreSQL 18.6, patched), built
against pg_query_go v6.2.2's wrapper. Every golden in `parser/testdata` derives
from that oracle, byte for byte, and is never edited by hand.

See [`PLAN.md`](PLAN.md) for the full design and [`CLAUDE.md`](CLAUDE.md)
Expand Down
90 changes: 63 additions & 27 deletions ast/pg_query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/generate/plpgsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func generatePlpgsql(refDir, outPath string) error {
var b strings.Builder
b.WriteString("// Code generated by cmd/generate -plpgsql from internal/reference/\n")
b.WriteString("// pl_reserved_kwlist.h, pl_unreserved_kwlist.h, and plerrcodes.h\n")
b.WriteString("// (libpg_query 18.0.0). DO NOT EDIT.\n\npackage plpgsql\n\n")
b.WriteString("// (libpg_query 18.1.0). DO NOT EDIT.\n\npackage plpgsql\n\n")

b.WriteString("// reservedKeywords is pl_reserved_kwlist.h: these are passed to the core\n")
b.WriteString("// scanner's keyword list, so they win over any variable name.\n")
Expand Down
7 changes: 7 additions & 0 deletions cmd/regenerate/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ func extractCStrings(src string) ([]string, error) {
i += end + 2
case c == ' ' || c == '\t' || c == '\n' || c == '\r':
i++
case strings.HasPrefix(src[i:], "NULL"):
// Trailing NULL sentinel (parse_tests.c since libpg_query
// 18.1.0): the runner stops there, so the array ends too.
if inEntry {
entries = append(entries, cur.String())
}
return entries, nil
default:
return nil, fmt.Errorf("unexpected byte %q in tests[] array", c)
}
Expand Down
12 changes: 7 additions & 5 deletions cmd/regenerate/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Command regenerate derives every golden in parser/testdata from the pinned
// oracle (libpg_query 18.0.0 via pg_query_go v6.2.2, cgo). It is the only
// oracle (libpg_query 18.1.0 via pg_query_go v6.2.2, cgo). It is the only
// writer of that tree; expected outputs are NEVER edited by hand.
//
// go run ./cmd/regenerate -libpg-query <checkout@18.0.0> -pg-query-go <checkout@v6.2.2>
// go run ./cmd/regenerate -libpg-query <checkout@18.1.0> -pg-query-go <checkout@v6.2.2>
//
// Corpus tiers extracted:
//
Expand All @@ -13,7 +13,9 @@
// - inline test tables (test/*_tests.c) → their respective suites
// (inputs transcribed mechanically; expectations always from the oracle)
// - pg_query_go testdata/fingerprint.json → fingerprint suite (includes the
// 1.1 MB stress insert)
// 1.1 MB stress insert; libpg_query 18.1.0 dropped its copy, so this is
// pg_query_go's own at the oracle's pinned commit — see
// oracle/update-pg-query-go.sh)
//
// Output must be byte-identical across runs — that reproducibility is
// milestone 2's acceptance gate and is enforced weekly in CI.
Expand All @@ -34,7 +36,7 @@ import (
var stats struct{ files, cases int }

func main() {
libpgQuery := flag.String("libpg-query", "", "path to a libpg_query checkout at tag 18.0.0")
libpgQuery := flag.String("libpg-query", "", "path to a libpg_query checkout at tag 18.1.0")
pgQueryGo := flag.String("pg-query-go", "", "path to a pg_query_go checkout at tag v6.2.2")
oracleBin := flag.String("oracle", "", "prebuilt oracle binary (default: go build ./oracle)")
out := flag.String("out", "parser/testdata", "output corpus root")
Expand Down Expand Up @@ -197,7 +199,7 @@ func main() {
}
fpData, err := os.ReadFile(filepath.Join(*pgQueryGo, "testdata", "fingerprint.json"))
check(err)
// libpg_query 18.0.0's fingerprint.json carries a // line comment
// libpg_query's fingerprint.json (as of 18.0.0) carries a // line comment
// ("disableOnMsvc": true, // Doesn't work because of C2026), which
// encoding/json rejects; strip comments outside strings before decoding.
check(json.Unmarshal(stripJSONLineComments(fpData), &fpCases))
Expand Down
4 changes: 2 additions & 2 deletions compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func TestScanTokens(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if result.Version != 180004 {
t.Fatalf("ScanResult.Version = %d, want 180004", result.Version)
if result.Version != 180006 {
t.Fatalf("ScanResult.Version = %d, want 180006", result.Version)
}
type tok struct {
start, end int32
Expand Down
Loading
Loading