github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/docs/reference/go-gno-compatibility.md (about) 1 --- 2 id: go-gno-compatibility 3 --- 4 5 # Go - Gno compatibility 6 7 ## Reserved keywords 8 9 | keyword | support | 10 |-------------|------------------------| 11 | break | full | 12 | case | full | 13 | const | full | 14 | continue | full | 15 | default | full | 16 | defer | full | 17 | else | full | 18 | fallthrough | full | 19 | for | full | 20 | func | full | 21 | go | missing (after launch) | 22 | goto | full | 23 | if | full | 24 | import | full | 25 | interface | full | 26 | package | full | 27 | range | full | 28 | return | full | 29 | select | missing (after launch) | 30 | struct | full | 31 | switch | full | 32 | type | full | 33 | var | full | 34 35 Generics are currently not implemented. 36 37 Note that Gno does not support shadowing of built-in types. 38 While the following built-in typecasting assignment would work in Go, this is not supported in Gno. 39 40 ```go 41 rune := rune('a') 42 ``` 43 44 ## Builtin types 45 46 | type | usage | persistency | 47 |-----------------------------------------------|------------------------|------------------------------------------------------------| 48 | `bool` | full | full | 49 | `byte` | full | full | 50 | `int`, `int8`, `int16`, `int32`, `int64` | full | full | 51 | `uint`, `uint8`, `uint16`, `uint32`, `uint64` | full | full | 52 | `float32`, `float64` | full | full | 53 | `complex64`, `complex128` | missing (TBD) | missing | 54 | `uintptr`, `unsafe.Pointer` | missing | missing | 55 | `string` | full | full | 56 | `rune` | full | full | 57 | `interface{}` | full | full | 58 | `[]T` (slices) | full | full\* | 59 | `[N]T` (arrays) | full | full\* | 60 | `map[T1]T2` | full | full\* | 61 | `func (T1...) T2...` | full | full (needs more tests) | 62 | `*T` (pointers) | full | full\* | 63 | `chan T` (channels) | missing (after launch) | missing (after launch) | 64 65 **\*:** depends on `T`/`T1`/`T2` 66 67 Additional builtin types: 68 69 | type | comment | 70 |----------|--------------------------------------------------------------------------------------------| 71 | `bigint` | Based on `math/big.Int` | 72 | `bigdec` | Based on https://github.com/cockroachdb/apd, (see https://github.com/gnolang/gno/pull/306) | 73 74 75 ## Stdlibs 76 77 Legend: 78 79 * `nondet`: the standard library in question would require non-deterministic 80 behaviour to implement as in Go, such as cryptographical randomness or 81 os/network access. The library may still be implemented at one point, with a 82 different API. 83 * `gospec`: the standard library is very Go-specific -- for instance, it is used 84 for debugging information or for parsing/build Go source code. A Gno version 85 may exist at one point, likely with a different package name or semantics. 86 * `gnics`: the standard library requires generics. 87 * `test`: the standard library is currently available for use exclusively in 88 test contexts, and may have limited functionality. 89 * `cmd`: the Go standard library is a command -- a direct equivalent in Gno 90 would not be useful. 91 * `tbd`: whether to include the standard library or not is still up for 92 discussion. 93 * `todo`: the standard library is to be added, and 94 [contributions are welcome.](https://github.com/gnolang/gno/issues/1267) 95 * `part`: the standard library is partially implemented in Gno, and contributions are 96 welcome to add the missing functionality. 97 * `full`: the standard library is fully implemented in Gno. 98 99 <!-- generated with: env -C /usr/lib/go/src find -name '*.go' | grep -v _test.go | grep -vE '(internal|vendor|testdata)/' | xargs dirname | sort | uniq | cut -d/ -f2 --> 100 101 | package | status | 102 |---------------------------------------------|----------| 103 | archive/tar | `tbd` | 104 | archive/zip | `tbd` | 105 | arena | `improb` | 106 | bufio | `full` | 107 | builtin | `full`[^1] | 108 | bytes | `full` | 109 | cmd/\* | `cmd` | 110 | compress/bzip2 | `tbd` | 111 | compress/flate | `tbd` | 112 | compress/gzip | `tbd` | 113 | compress/lzw | `tbd` | 114 | compress/zlib | `tbd` | 115 | container/heap | `tbd` | 116 | container/list | `tbd` | 117 | container/ring | `tbd` | 118 | context | `tbd` | 119 | crypto | `todo` | 120 | crypto/aes | `todo` | 121 | crypto/boring | `tbd` | 122 | crypto/cipher | `part` | 123 | crypto/des | `tbd` | 124 | crypto/dsa | `tbd` | 125 | crypto/ecdh | `tbd` | 126 | crypto/ecdsa | `tbd` | 127 | crypto/ed25519 | `part`[^8] | 128 | crypto/elliptic | `tbd` | 129 | crypto/hmac | `todo` | 130 | crypto/md5 | `test`[^2] | 131 | crypto/rand | `nondet` | 132 | crypto/rc4 | `tbd` | 133 | crypto/rsa | `tbd` | 134 | crypto/sha1 | `test`[^2] | 135 | crypto/sha256 | `part`[^3] | 136 | crypto/sha512 | `tbd` | 137 | crypto/subtle | `tbd` | 138 | crypto/tls | `nondet` | 139 | crypto/tls/fipsonly | `nondet` | 140 | crypto/x509 | `tbd` | 141 | crypto/x509/pkix | `tbd` | 142 | database/sql | `nondet` | 143 | database/sql/driver | `nondet` | 144 | debug/buildinfo | `gospec` | 145 | debug/dwarf | `gospec` | 146 | debug/elf | `gospec` | 147 | debug/gosym | `gospec` | 148 | debug/macho | `gospec` | 149 | debug/pe | `gospec` | 150 | debug/plan9obj | `gospec` | 151 | embed | `tbd` | 152 | encoding | `full` | 153 | encoding/ascii85 | `todo` | 154 | encoding/asn1 | `todo` | 155 | encoding/base32 | `todo` | 156 | encoding/base64 | `full` | 157 | encoding/binary | `part` | 158 | encoding/csv | `todo` | 159 | encoding/gob | `tbd` | 160 | encoding/hex | `full` | 161 | encoding/json | `todo` | 162 | encoding/pem | `todo` | 163 | encoding/xml | `todo` | 164 | errors | `part` | 165 | expvar | `tbd` | 166 | flag | `nondet` | 167 | fmt | `test`[^4] | 168 | go/ast | `gospec` | 169 | go/build | `gospec` | 170 | go/build/constraint | `gospec` | 171 | go/constant | `gospec` | 172 | go/doc | `gospec` | 173 | go/doc/comment | `gospec` | 174 | go/format | `gospec` | 175 | go/importer | `gospec` | 176 | go/parser | `gospec` | 177 | go/printer | `gospec` | 178 | go/scanner | `gospec` | 179 | go/token | `gospec` | 180 | go/types | `gospec` | 181 | hash | `full` | 182 | hash/adler32 | `full` | 183 | hash/crc32 | `todo` | 184 | hash/crc64 | `todo` | 185 | hash/fnv | `todo` | 186 | hash/maphash | `todo` | 187 | html | `todo` | 188 | html/template | `todo` | 189 | image | `tbd` | 190 | image/color | `tbd` | 191 | image/color/palette | `tbd` | 192 | image/draw | `tbd` | 193 | image/gif | `tbd` | 194 | image/jpeg | `tbd` | 195 | image/png | `tbd` | 196 | index/suffixarray | `tbd` | 197 | io | `full` | 198 | io/fs | `tbd` | 199 | io/ioutil | removed[^5] | 200 | log | `tbd` | 201 | log/slog | `tbd` | 202 | log/syslog | `nondet` | 203 | maps | `gnics` | 204 | math | `full` | 205 | math/big | `tbd` | 206 | math/bits | `full` | 207 | math/cmplx | `tbd` | 208 | math/rand | `todo` | 209 | mime | `tbd` | 210 | mime/multipart | `tbd` | 211 | mime/quotedprintable | `tbd` | 212 | net | `nondet` | 213 | net/http | `nondet` | 214 | net/http/cgi | `nondet` | 215 | net/http/cookiejar | `nondet` | 216 | net/http/fcgi | `nondet` | 217 | net/http/httptest | `nondet` | 218 | net/http/httptrace | `nondet` | 219 | net/http/httputil | `nondet` | 220 | net/http/internal | `nondet` | 221 | net/http/pprof | `nondet` | 222 | net/mail | `nondet` | 223 | net/netip | `nondet` | 224 | net/rpc | `nondet` | 225 | net/rpc/jsonrpc | `nondet` | 226 | net/smtp | `nondet` | 227 | net/textproto | `nondet` | 228 | net/url | `full` | 229 | os | `nondet` | 230 | os/exec | `nondet` | 231 | os/signal | `nondet` | 232 | os/user | `nondet` | 233 | path | `full` | 234 | path/filepath | `nondet` | 235 | plugin | `nondet` | 236 | reflect | `todo` | 237 | regexp | `full` | 238 | regexp/syntax | `full` | 239 | runtime | `gospec` | 240 | runtime/asan | `gospec` | 241 | runtime/cgo | `gospec` | 242 | runtime/coverage | `gospec` | 243 | runtime/debug | `gospec` | 244 | runtime/metrics | `gospec` | 245 | runtime/msan | `gospec` | 246 | runtime/pprof | `gospec` | 247 | runtime/race | `gospec` | 248 | runtime/trace | `gospec` | 249 | slices | `gnics` | 250 | sort | `part`[^6] | 251 | strconv | `part` | 252 | strings | `full` | 253 | sync | `tbd` | 254 | sync/atomic | `tbd` | 255 | syscall | `nondet` | 256 | syscall/js | `nondet` | 257 | testing | `part` | 258 | testing/fstest | `tbd` | 259 | testing/iotest | `tbd` | 260 | testing/quick | `tbd` | 261 | text/scanner | `todo` | 262 | text/tabwriter | `todo` | 263 | text/template | `todo` | 264 | text/template/parse | `todo` | 265 | time | `full`[^7] | 266 | time/tzdata | `tbd` | 267 | unicode | `full` | 268 | unicode/utf16 | `full` | 269 | unicode/utf8 | `full` | 270 | unsafe | `nondet` | 271 272 [^1]: `builtin` is a "fake" package that exists to document the behaviour of 273 some builtin functions. The "fake" package does not currently exist in Gno, 274 but [all functions up to Go 1.17 exist](https://pkg.go.dev/builtin@go1.17), 275 except for those relating to complex or channel types. 276 [^2]: `crypto/sha1` and `crypto/md5` implement "deprecated" hashing 277 algorithms, widely considered unsafe for cryptographic hashing. Decision on 278 whether to include these as part of the official standard libraries is still 279 pending. 280 [^3]: `crypto/sha256` is currently only implemented for `Sum256`, which should 281 still cover a majority of use cases. A full implementation is welcome. 282 [^4]: like many other encoding packages, `fmt` depends on `reflect` to be added. 283 For now, package `gno.land/p/demo/ufmt` may do what you need. In test 284 functions, `fmt` works. 285 [^5]: `io/ioutil` [is deprecated in Go.](https://pkg.go.dev/io/ioutil) 286 Its functionality has been moved to packages `os` and `io`. The functions 287 which have been moved in `io` are implemented in that package. 288 [^6]: `sort` has the notable omission of `sort.Slice`. You'll need to write a 289 bit of boilerplate, but you can use `sort.Interface` + `sort.Sort`! 290 [^7]: `time.Now` returns the block time rather than the system time, for 291 determinism. Concurrent functionality (such as `time.Ticker`) is not implemented. 292 [^8]: `crypto/ed25519` is currently only implemented for `Verify`, which should 293 still cover a majority of use cases. A full implementation is welcome. 294 295 ## Tooling (`gno` binary) 296 297 | go command | gno command | comment | 298 |-------------------|---------------------------|-----------------------------------------------------------------------| 299 | go bug | gno bug | same behavior | 300 | go build | gno transpile -gobuild | same intention, limited compatibility | 301 | go clean | gno clean | same intention, limited compatibility | 302 | go doc | gno doc | limited compatibility; see https://github.com/gnolang/gno/issues/522 | 303 | go env | | | 304 | go fix | | | 305 | go fmt | | gofmt (& similar tools, like gofumpt) works on gno code. | 306 | go generate | | | 307 | go get | | see `gno mod download`. | 308 | go help | gno $cmd --help | ie. `gno doc --help` | 309 | go install | | | 310 | go list | | | 311 | go mod | gno mod | | 312 | + go mod init | gno mod init | same behavior | 313 | + go mod download | gno mod download | same behavior | 314 | + go mod tidy | gno mod tidy | same behavior | 315 | + go mod why | gno mod why | same intention | 316 | | gno transpile | | 317 | go work | | | 318 | | gno repl | | 319 | go run | gno run | | 320 | go test | gno test | limited compatibility | 321 | go tool | | | 322 | go version | | | 323 | go vet | | | 324 | golint | gno lint | same intention |