Sample
golang.org/x/tools v0.49.0: typeutil.Map
Verified sample for golang golang.org/x/tools v0.49.0: typeutil.Map. The contract ran on go 1.26 · linux debian/x64 · docker and passed: typeutil.Map maps…
sha256:0a6db5348200b83797b11dc06594a35d312be2d6cb4ff7f9121cac87ecf2de5c
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
linux 24 · ubuntu · glibc 2.39 x64 go
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| 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-09-02 |
Case
HOW- Goal
- verify golang.org/x/tools/go/types/typeutil.Map in pkg:golang/golang.org/x/tools@v0.49.0
- Packages
- Symbols
-
- golang.org/x/tools/go/types/typeutil.Map
- Created
- 2026-09-02T20:33:15Z
Contract
- typeutil.Map maps types.Type keys using types.Identical equivalence for structurally identical types
- typeutil.Map.Set stores values and returns previous value when overwriting an existing key
- typeutil.Map.At returns nil for absent keys and the associated value for present keys
- typeutil.Map.Delete removes entries by type equivalence and reports true if present
- typeutil.Map.Iterate visits all map entries and Len reflects the number of entries
Files
- PROMPT.md
- csx.json
- go.mod
- go.sum
- spec.json
- test/contract.go
- typemap.go
Source
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/types/typeutil.Map in pkg:golang/golang.org/x/tools@v0.49.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/tools@v0.49.0
Demonstrate these symbols/APIs:
- golang.org/x/tools/go/types/typeutil.Map
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:7e71903d49b6281d28ad005f211e362207e7c2fecd1f529d54046702b4f6f93b","contract":["typeutil.Map maps types.Type keys using types.Identical equivalence for structurally identical types","typeutil.Map.Set stores values and returns previous value when overwriting an existing key","typeutil.Map.At returns nil for absent keys and the associated value for present keys","typeutil.Map.Delete removes entries by type equivalence and reports true if present","typeutil.Map.Iterate visits all map entries and Len reflects the number of entries"],"goal":"verify golang.org/x/tools/go/types/typeutil.Map in pkg:golang/golang.org/x/tools@v0.49.0","kind":"HOW","packages":["pkg:golang/golang.org/x/tools@v0.49.0"],"schemaVersion":1,"symbols":["golang.org/x/tools/go/types/typeutil.Map"]},"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.49.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/tools@v0.49.0","symbols":["golang.org/x/tools/go/types/typeutil.Map"],"verifierAdapter":"golang@1"}
module example.com/typeutil-map
go 1.25.0
require golang.org/x/tools v0.49.0
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/mod v0.39.0 h1:UF5zwQdCRRUpHfyPwr7d4UrGiVeldIsogtzWVnczL74=
golang.org/x/mod v0.39.0/go.mod h1:bvIbwjQ0HUFFf5AKukeeYQG4ZBUG9yxQbR9aEweIwYY=
golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/tools v0.49.0 h1:3NI7VXzL9+1WZD52Dx2ttoPwD5DWrFGpl9mFZDlmisI=
golang.org/x/tools v0.49.0/go.mod h1:SJNXV9DBKT0UbdttsQjbfJlAE/q+y36++zo3uL3N0Oo=
{
"schemaVersion": 1,
"goal": "verify golang.org/x/tools/go/types/typeutil.Map in pkg:golang/golang.org/x/tools@v0.49.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/tools@v0.49.0"
],
"symbols": [
"golang.org/x/tools/go/types/typeutil.Map"
]
}
package main
import (
"fmt"
"go/types"
"os"
typemap "example.com/typeutil-map"
"golang.org/x/tools/go/types/typeutil"
)
func main() {
reg := typemap.NewTypeRegistry()
// Assertion 1: typeutil.Map maps types.Type keys using types.Identical equivalence for structurally identical types
{
slice1 := types.NewSlice(types.Typ[types.Int])
slice2 := types.NewSlice(types.Typ[types.Int])
if slice1 == slice2 {
fmt.Fprintf(os.Stderr, "FAIL 1: expected distinct pointers for independently created slices\n")
os.Exit(1)
}
reg.Set(slice1, "int-slice")
val := reg.At(slice2)
if val != "int-slice" {
fmt.Fprintf(os.Stderr, "FAIL 1: expected identical slice lookup to yield 'int-slice', got %v\n", val)
os.Exit(1)
}
field1 := types.NewField(0, nil, "FieldA", types.Typ[types.String], false)
field2 := types.NewField(0, nil, "FieldA", types.Typ[types.String], false)
struct1 := types.NewStruct([]*types.Var{field1}, nil)
struct2 := types.NewStruct([]*types.Var{field2}, nil)
if struct1 == struct2 {
fmt.Fprintf(os.Stderr, "FAIL 1: expected distinct pointers for structs\n")
os.Exit(1)
}
reg.Set(struct1, "struct-val")
if reg.At(struct2) != "struct-val" {
fmt.Fprintf(os.Stderr, "FAIL 1: expected struct lookup via structural equivalence to succeed\n")
os.Exit(1)
}
}
// Assertion 2: typeutil.Map.Set stores values and returns previous value when overwriting an existing key
{
sliceKey := types.NewSlice(types.Typ[types.Int])
prev := reg.Set(sliceKey, "updated-slice")
if prev != "int-slice" {
fmt.Fprintf(os.Stderr, "FAIL 2: expected previous value 'int-slice', got %v\n", prev)
os.Exit(1)
}
if reg.At(sliceKey) != "updated-slice" {
fmt.Fprintf(os.Stderr, "FAIL 2: expected current value to be 'updated-slice'\n")
os.Exit(1)
}
}
// Assertion 3: typeutil.Map.At returns nil for absent keys and the associated value for present keys
{
absentKey := types.Typ[types.String]
if reg.At(absentKey) != nil {
fmt.Fprintf(os.Stderr, "FAIL 3: expected nil for absent key, got %v\n", reg.At(absentKey))
os.Exit(1)
}
presentKey := types.NewSlice(types.Typ[types.Int])
if reg.At(presentKey) != "updated-slice" {
fmt.Fprintf(os.Stderr, "FAIL 3: expected 'updated-slice' for present key\n")
os.Exit(1)
}
}
// Assertion 4: typeutil.Map.Delete removes entries by type equivalence and reports true if present
{
sliceLookup := types.NewSlice(types.Typ[types.Int])
deleted := reg.Delete(sliceLookup)
if !deleted {
fmt.Fprintf(os.Stderr, "FAIL 4: expected Delete to return true for existing key\n")
os.Exit(1)
}
if reg.At(sliceLookup) != nil {
fmt.Fprintf(os.Stderr, "FAIL 4: expected At to return nil after deletion\n")
os.Exit(1)
}
if reg.Delete(sliceLookup) {
fmt.Fprintf(os.Stderr, "FAIL 4: expected Delete to return false when key already removed\n")
os.Exit(1)
}
}
// Assertion 5: typeutil.Map.Iterate visits all map entries and Len reflects the number of entries
{
var m typeutil.Map
m.Set(types.Typ[types.Bool], "bool-val")
m.Set(types.Typ[types.Float64], "float-val")
m.Set(types.NewPointer(types.Typ[types.Int]), "ptr-val")
if m.Len() != 3 {
fmt.Fprintf(os.Stderr, "FAIL 5: expected Len() == 3, got %d\n", m.Len())
os.Exit(1)
}
visited := make(map[string]any)
m.Iterate(func(key types.Type, value any) {
visited[key.String()] = value
})
if len(visited) != 3 {
fmt.Fprintf(os.Stderr, "FAIL 5: expected 3 visited entries, got %d\n", len(visited))
os.Exit(1)
}
if visited["bool"] != "bool-val" || visited["float64"] != "float-val" || visited["*int"] != "ptr-val" {
fmt.Fprintf(os.Stderr, "FAIL 5: visited entries do not match expected contents: %v\n", visited)
os.Exit(1)
}
m.Delete(types.Typ[types.Bool])
if m.Len() != 2 {
fmt.Fprintf(os.Stderr, "FAIL 5: expected Len() == 2 after deletion, got %d\n", m.Len())
os.Exit(1)
}
}
fmt.Println("PASS: all typeutil.Map contract assertions verified")
}
package typemap
import (
"go/types"
"golang.org/x/tools/go/types/typeutil"
)
// TypeRegistry associates Go types with arbitrary metadata values using typeutil.Map.
type TypeRegistry struct {
mapping typeutil.Map
}
// NewTypeRegistry creates an empty TypeRegistry.
func NewTypeRegistry() *TypeRegistry {
return &TypeRegistry{}
}
// Set associates the given type key with value, returning the previous value if present.
func (r *TypeRegistry) Set(k types.Type, value any) any {
return r.mapping.Set(k, value)
}
// At retrieves the value associated with the given type key, or nil if not found.
func (r *TypeRegistry) At(k types.Type) any {
return r.mapping.At(k)
}
// Delete removes the entry for the given type key and reports whether it existed.
func (r *TypeRegistry) Delete(k types.Type) bool {
return r.mapping.Delete(k)
}
// Len returns the count of active entries in the registry.
func (r *TypeRegistry) Len() int {
return r.mapping.Len()
}
// Keys returns all keys present in the registry.
func (r *TypeRegistry) Keys() []types.Type {
return r.mapping.Keys()
}
// Iterate iterates over all key-value pairs in the registry.
func (r *TypeRegistry) Iterate(f func(key types.Type, value any)) {
r.mapping.Iterate(f)
}
Origin Seeder
anonymous