サンプル
golang.org/x/tools v0.1.1: cfg.Block
検証済みサンプル — golang golang.org/x/tools v0.1.1: cfg.Block. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました: cfg.Block represents basic blocks in a…
sha256:c6c314c614778a453c6762935d96fc7fee83b7b384b656621ebcae24d279fc6b
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 1
- ビルドした署名鍵
- 1
宣言された環境
linux 24 · ubuntu · glibc 2.39 x64 go
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-10-14 |
ケース
HOW- ゴール
- verify golang.org/x/tools/go/cfg.Block in pkg:golang/golang.org/x/tools@v0.1.1
- シンボル
-
- golang.org/x/tools/go/cfg.Block
- 作成日
- 2026-10-14T00:48:59Z
コントラクト
- cfg.Block represents basic blocks in a control-flow graph with Index, Live, Nodes, and Succs properties
- cfg.Block.Return returns the terminating *ast.ReturnStmt for return blocks and nil for non-return blocks
- cfg.Block.String formats the block index and comment description
- cfg.Block marks unreachable basic blocks after unconditional return with Live == false
- cfg.Block Succs links conditional branches to two successor blocks and linear flow to one successor block
ファイル
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
ソース
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify golang.org/x/tools/go/cfg.Block in pkg:golang/golang.org/x/tools@v0.1.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/tools@v0.1.1
Demonstrate these symbols/APIs:
- golang.org/x/tools/go/cfg.Block
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:1527fa01316e8237c0cbc0896d88046c76e4279c201e95be769c65d3299d6ce7","contract":["cfg.Block represents basic blocks in a control-flow graph with Index, Live, Nodes, and Succs properties","cfg.Block.Return returns the terminating *ast.ReturnStmt for return blocks and nil for non-return blocks","cfg.Block.String formats the block index and comment description","cfg.Block marks unreachable basic blocks after unconditional return with Live == false","cfg.Block Succs links conditional branches to two successor blocks and linear flow to one successor block"],"goal":"verify golang.org/x/tools/go/cfg.Block in pkg:golang/golang.org/x/tools@v0.1.1","kind":"HOW","packages":["pkg:golang/golang.org/x/tools@v0.1.1"],"schemaVersion":1,"symbols":["golang.org/x/tools/go/cfg.Block"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/tools@v0.1.1"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/tools@v0.1.1","symbols":["golang.org/x/tools/go/cfg.Block"],"verifierAdapter":"golang@1"}
module sample
go 1.21
require golang.org/x/tools v0.1.1
golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
"golang.org/x/tools/go/cfg"
)
func main() {
src := `package p
func classify(n int) int {
if n > 0 {
return 1
}
return 0
}`
fset := token.NewFileSet()
file, err := parser.ParseFile(fset, "p.go", src, 0)
if err != nil {
fmt.Printf("parse error: %v\n", err)
return
}
var fn *ast.FuncDecl
for _, decl := range file.Decls {
if fd, ok := decl.(*ast.FuncDecl); ok {
fn = fd
break
}
}
if fn == nil || fn.Body == nil {
fmt.Println("missing function body")
return
}
graph := cfg.New(fn.Body, func(call *ast.CallExpr) bool { return true })
for _, blk := range graph.Blocks {
var b *cfg.Block = blk
fmt.Printf("Block %d: live=%v succs=%d nodes=%d return=%v\n", b.Index, b.Live, len(b.Succs), len(b.Nodes), b.Return() != nil)
}
}
{
"schemaVersion": 1,
"goal": "verify golang.org/x/tools/go/cfg.Block in pkg:golang/golang.org/x/tools@v0.1.1",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/tools@v0.1.1"
],
"symbols": [
"golang.org/x/tools/go/cfg.Block"
]
}
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
"os"
"strings"
"golang.org/x/tools/go/cfg"
)
func mustParseFunc(src string) (*ast.FuncDecl, error) {
fset := token.NewFileSet()
file, err := parser.ParseFile(fset, "input.go", src, 0)
if err != nil {
return nil, fmt.Errorf("parse error: %w", err)
}
for _, decl := range file.Decls {
if fd, ok := decl.(*ast.FuncDecl); ok {
return fd, nil
}
}
return nil, fmt.Errorf("no FuncDecl found")
}
func main() {
// Assertion 1: cfg.Block represents basic blocks in a control-flow graph with Index, Live, Nodes, and Succs properties
{
src := `package p
func simple() {
a := 1
_ = a
}`
fn, err := mustParseFunc(src)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 1 failed: %v\n", err)
os.Exit(1)
}
g := cfg.New(fn.Body, func(call *ast.CallExpr) bool { return true })
if len(g.Blocks) == 0 {
fmt.Fprintf(os.Stderr, "assertion 1 failed: expected non-empty Blocks\n")
os.Exit(1)
}
var entry *cfg.Block = g.Blocks[0]
if entry.Index != 0 || !entry.Live || len(entry.Nodes) == 0 {
fmt.Fprintf(os.Stderr, "assertion 1 failed: unexpected entry block state: index=%d live=%v nodes=%d\n", entry.Index, entry.Live, len(entry.Nodes))
os.Exit(1)
}
}
// Assertion 2: cfg.Block.Return returns the terminating *ast.ReturnStmt for return blocks and nil for non-return blocks
{
src := `package p
func cond(v int) int {
if v > 0 {
return 10
}
return 20
}`
fn, err := mustParseFunc(src)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 2 failed: %v\n", err)
os.Exit(1)
}
g := cfg.New(fn.Body, func(call *ast.CallExpr) bool { return true })
var hasReturn, hasNonReturn bool
for _, b := range g.Blocks {
if b.Return() != nil {
hasReturn = true
} else {
hasNonReturn = true
}
}
if !hasReturn || !hasNonReturn {
fmt.Fprintf(os.Stderr, "assertion 2 failed: hasReturn=%v hasNonReturn=%v\n", hasReturn, hasNonReturn)
os.Exit(1)
}
}
// Assertion 3: cfg.Block.String formats the block index and comment description
{
src := `package p
func ret() int {
return 7
}`
fn, err := mustParseFunc(src)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 3 failed: %v\n", err)
os.Exit(1)
}
g := cfg.New(fn.Body, func(call *ast.CallExpr) bool { return true })
s := g.Blocks[0].String()
if !strings.Contains(s, "block 0") {
fmt.Fprintf(os.Stderr, "assertion 3 failed: unexpected String() output %q\n", s)
os.Exit(1)
}
}
// Assertion 4: cfg.Block marks unreachable basic blocks after unconditional return with Live == false
{
src := `package p
func dead() int {
return 1
y := 2
return y
}`
fn, err := mustParseFunc(src)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 4 failed: %v\n", err)
os.Exit(1)
}
g := cfg.New(fn.Body, func(call *ast.CallExpr) bool { return true })
var sawDead bool
for _, b := range g.Blocks {
if !b.Live {
sawDead = true
break
}
}
if !sawDead {
fmt.Fprintf(os.Stderr, "assertion 4 failed: expected at least one dead block with Live == false\n")
os.Exit(1)
}
}
// Assertion 5: cfg.Block Succs links conditional branches to two successor blocks and linear flow to one successor block
{
src := `package p
func branch(flag bool) {
if flag {
_ = 1
}
_ = 2
}`
fn, err := mustParseFunc(src)
if err != nil {
fmt.Fprintf(os.Stderr, "assertion 5 failed: %v\n", err)
os.Exit(1)
}
g := cfg.New(fn.Body, func(call *ast.CallExpr) bool { return true })
var twoSuccs, oneSucc bool
for _, b := range g.Blocks {
switch len(b.Succs) {
case 2:
twoSuccs = true
case 1:
oneSucc = true
}
}
if !twoSuccs || !oneSucc {
fmt.Fprintf(os.Stderr, "assertion 5 failed: twoSuccs=%v oneSucc=%v\n", twoSuccs, oneSucc)
os.Exit(1)
}
}
fmt.Println("contract ok")
}
オリジンシーダー
匿名