You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/docs/reference/lang-support/_index.md
+14-23Lines changed: 14 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,48 +5,39 @@ description: |
5
5
Which Go language features are supported by TinyGo and which are still a work in progress.
6
6
---
7
7
8
-
While TinyGo supports a big subset of the Go language, not everything is supported yet.
8
+
The TinyGo compiler implements all major Go language features, although some details are missing. Below you will find a description of some of the missing features, as of june 2023.
9
9
10
-
Here is a list of features that are supported:
11
-
12
-
* The subset of Go that directly translates to C is well supported. This includes all basic types and all regular control flow (including `switch`).
13
-
* Slices are well supported.
14
-
* Interfaces are quite stable and should work well in almost all cases. Type switches and type asserts are also supported, as well as calling methods on interfaces. The only exception is comparing two interface values (but comparing against `nil` works).
15
-
* Closures and bound methods are supported, for example inline anonymous (lambda-like) functions.
16
-
* The `defer` keyword is almost entirely supported, with the exception of deferring some builtin functions.
17
-
18
-
## Concurrency
19
-
20
-
At the time of writing (2019-11-27), support for goroutines and channels works for the most part. Support for concurrency on ARM microcontrollers is complete but may have some edge cases that don't work. Support for other platforms (such as WebAssembly) is a bit more limited: calling a blocking function may for example allocate heap memory.
10
+
If you're wondering "Does TinyGo support feature X", we often cannot give a good answer! The rest of this page gives a good indication, but other than that you will just have to try for yourself to see whether a particular piece of software works with TinyGo. There are just way too many edge cases that are not entirely supported or work slightly differently, many of which we don't even know about.
21
11
22
12
## Cgo
23
13
24
-
While TinyGo embeds the [Clang](https://clang.llvm.org/) compiler to parse `import "C"` blocks, many features of Cgo are still unsupported. For example, `#cgo` statements are only partially supported.
14
+
While TinyGo embeds the [Clang](https://clang.llvm.org/) compiler to parse `import "C"` blocks, some features of Cgo are still unsupported or may work slightly differently. For example, `#cgo` statements are only partially supported.
25
15
26
16
## Reflection
27
17
28
-
Many packages, especially in the standard library, rely on reflection to work. The `reflect` package has been re-implemented in TinyGo and most common types like numbers, strings, and structs are supported now.
18
+
Many packages, especially in the standard library, rely on reflection to work. The `reflect` package has been re-implemented in TinyGo and most of it works, but some parts are not yet fully supported.
29
19
30
20
## Maps
31
21
32
-
Support for maps is not yet complete but is usable. You can use any type as a value, but only some types are acceptable as map keys. Also, they have not been optimized for performance and will cause linear lookup times in some cases.
33
-
34
-
Types supported as map keys include strings, integers, pointers, and structs/arrays that contain only these types.
22
+
Maps generally work fine, but may be slower than you expect them to be. There are a few reasons for this, one of which is that some types (like structs) may internally be compared using reflection instead of using a dedicated hash/compare function.
35
23
36
24
## Standard library
37
25
38
26
Due to the above missing pieces and because parts of the standard library depend on the particular compiler/runtime in use, many packages do not yet compile. See the [list of compiling packages here]({{<ref "stdlib.md">}}) (but note that "compiling" does not imply that works entirely).
39
27
40
28
## Garbage collection
41
29
42
-
While not directly a language feature (the Go spec doesn't mention it), garbage collection is important for most Go programs to make sure their memory usage stays in reasonable bounds.
30
+
Garbage collection generally works fine, but may work not as well on very small chips (AVR) and on WebAssembly. It is also a lot slower than the usual Go garbage collector.
31
+
32
+
Careful design may avoid memory allocations in main loops where they can reduce performance a lot. You may want to compile with `-print-allocs=.` to find out where allocations happen and why they happen. For more information, see [heap allocation]({{<ref "heap-allocation.md">}}).
43
33
44
-
Garbage collection is currently supported on all platforms, although it works best on 32-bit chips. A simple conservative mark-sweep collector is used that will trigger a collection cycle when the heap runs out (that is fixed at compile time) or when requested manually using `runtime.GC()`. Some other collector designs are used for other targets, TinyGo will automatically pick a good GC for a given target.
34
+
## `recover` builtin
45
35
46
-
Careful design may avoid memory allocations in main loops. You may want to compile with `-print-allocs=.` to find out where allocations happen and why they happen. For more information, see [heap allocation]({{<ref "heap-allocation.md">}}).
36
+
The `recover` builtin is supported on most architectures, with the notable exception of WebAssembly. For WebAssembly, we need the [exception handling proposal](https://webassembly.org/roadmap/) which is implemented in browsers but is not implemented in many WASI runtimes.
47
37
48
-
## A note on the `recover`builtin
38
+
On architectures where `recover`is not implemented, a panic will always exit the program without running any deferred functions.
49
39
50
-
The `recover` builtin is not yet supported. Instead, a `panic` will always terminate a program and `recover`simply returns nil.
40
+
Some notes on `recover`support in TinyGo:
51
41
52
-
This is a deviation from the Go spec but so far works well in practice. While there are no immediate plans to implement `recover`, if it can be shown to be necessary for compatibility it will be implemented. Please note that this comes at a cost: it means that every `defer` call will need some extra memory (both code and stack), so this feature is not free. It might also be architecture dependent. If it gets implemented, it will likely be opt-in to not increase code size for existing projects.
42
+
* We don't follow the Go language specification to the letter, in particular `recover()` also returns a value in functions that aren't directly called by `defer` (meaning, it returns a value inside a function that is called by a deferred function). In practice, this happens very rarely. This inconsistency should eventually be fixed.
43
+
* Runtime panics can currently not be recovered from. This includes things like divide-by-zero and nil pointer dereferences, which are used in some standard library tests.
0 commit comments