Граф коммитов

661 коммит

Автор SHA1 Сообщение Дата
Ayke van Laethem
a93f0ed12a all: Go 1.21 support 2023-08-04 11:59:11 +02:00
soypat
bcdb3fc681 fix go:noinlines in volatile package 2023-05-29 22:16:35 +02:00
Ayke van Laethem
2fb866ca86 avr: add attiny1616 support
This is just support for the chip, no boards are currently supported.
However, you can use this target on a custom board.

Notes:

  - This required a new runtime and machine implementation, because the
    hardware is actually very different (and much nicer than older
    AVRs!).
  - I had to update gen-device-avr to support this chip. This also
    affects the generated output of other AVRs, but I checked all chips
    we support and there shouldn't be any backwards incompatible
    changes.
  - I did not implement peripherals like UART, I2C, SPI, etc because I
    don't need them. That is left to do in the future.

You can flash these chips with only a UART and a 1kOhm resistor, which
is really nice (no special hardware needed). Here is the program I've
used for this purpose: https://pypi.org/project/pymcuprog/
2023-05-20 21:18:02 +02:00
Rajat Jindal
572c22f66a add Settings to debug.BuildInfo
Signed-off-by: Rajat Jindal <rajatjindal83@gmail.com>
2023-05-20 14:49:31 +02:00
Ayke van Laethem
4c682680ca compileopts: don't filter build tags, use specific build tags instead
This basically reverts https://github.com/tinygo-org/tinygo/pull/3357
and replaces it with a different mechanism to get to the same goal.

I do not think filtering tags like this is a good idea: it's the wrong
part of the compiler to be concerned with such tags (that part sets
tags, but doesn't modify existing tags). Instead, I've written the
//go:build lines in such a way that it has the same effect: WASI
defaults to leveldb, everything else defaults to fnv, and it's possible
to override the default using build tags.
2023-05-17 11:21:15 +02:00
Damian Gryski
e3c96803c3 runtime: fix structField.data comment 2023-05-16 19:02:08 +02:00
Damian Gryski
07fb3a0cad compiler,reflect: make field offsets varints
Fixes #3686
2023-05-16 19:02:08 +02:00
Daz Wilkin
373ab34492 Add dummy package for runtime/metrics to that modules that depend upon it (e.g. [Prometheus Go client library](https://github.com/prometheus/client_golang/blob/main/prometheus/internal/go_runtime_metrics.go)) will compile.
Avoids:
```console
package runtime/metrics is not in GOROOT
```

Fixes #3705
2023-05-06 14:55:17 +02:00
Damian Gryski
4c0fbbfc7f add struct size and field offsets to reflect data 2023-04-27 11:15:41 +02:00
Ayke van Laethem
0b2aec1164 runtime: improve panic message when heap allocating in an interrupt
The old message may have been confusing. With the new message, it should
be more clear that we mean a _heap_ allocation.
2023-04-26 20:04:06 +02:00
Ayke van Laethem
3392827c3e runtime: print the address where a panic happened
This is not very useful in itself, but makes it possible to detect this
address in the output. See the next commit.

This adds around 50 bytes to each binary (except for AVR and wasm). This
is unfortunate, but I think this feature is quite useful still.
A future enhancement might be to create a build tag for extended panic
information that's not set by default.
2023-04-26 18:40:35 +02:00
Damian Gryski
4e4e4eee04 runtime: use unsafe.Add() in hashmap code 2023-03-30 00:08:07 +02:00
Damian Gryski
bf20c652e2 runtime: take max hash size into account when preallocating with size hint 2023-03-30 00:08:07 +02:00
Damian Gryski
a3afd4e8ac runtime: factor duplicate hashmap snippts to functions 2023-03-30 00:08:07 +02:00
Damian Gryski
cb9c6f0074 runtime: zero map key/value on deletion to so GC doesn't see them 2023-03-30 00:08:07 +02:00
Damian Gryski
5fee3428bc runtime: preallocate maps to size hint actually works 2023-03-30 00:08:07 +02:00
Ayke van Laethem
31043628d8 reflect: use direct calls to runtime string functions
The runtime.stringFromBytesTyped and runtime.stringToBytesTyped
functions aren't really necessary, because they have the same LLVM IR
signature. Therefore, remove them and link directly to the functions
that the compiler uses internally.
2023-03-27 22:24:20 +02:00
Damian Gryski
0b6bb12e9e reflect: add Convert() for string -> []byte and []byte -> string 2023-03-27 18:53:37 +02:00
shivay
d73e12db63 feat: fix typos 2023-03-24 09:22:38 -07:00
Ayke van Laethem
62e1c3ebb7 wasm: implement the //go:wasmimport directive
It is implemented upstream and looks pretty stable.
2023-03-22 11:29:26 +01:00
deadprogram
383e7ae14a machine, runtime/interrupt: switch to use register definitions from device/gba
Signed-off-by: deadprogram <ron@hybridgroup.com>
2023-03-16 15:27:15 +01:00
Damian Gryski
f42d8b3056 debug: stub SetGCPercent() 2023-03-14 16:54:44 +01:00
Damian Gryski
69e5c5088d reflect: add support for remaining map types 2023-03-10 16:28:22 -08:00
deadprogram
51c1579c3d machine/samd51: implement Flash interface
Signed-off-by: deadprogram <ron@hybridgroup.com>
2023-03-09 06:42:41 +01:00
Ayke van Laethem
4ec1e58aa6 all: use unsafe.Add instead of unsafe.Pointer(uintptr(...) + ...)
We have an optimization for this specific pattern, but it's really just
a hack. With the addition of unsafe.Add in Go 1.17 we can directly
specify the intent instead and eventually remove this special case.

The code is also easier to read.
2023-03-03 16:55:13 +01:00
Damian Gryski
9b86080c80 runtime: add sliceGrow function for reflect 2023-03-03 05:21:02 -08:00
Damian Gryski
c0a50e9b47 runtime: add unsafe.pointer reflect wrappers for hashmap calls 2023-02-28 13:10:40 -08:00
deadprogram
74160c0e32 runtime/atsamd51: enable CMCC cache for greatly improved performance on SAMD51
Signed-off-by: deadprogram <ron@hybridgroup.com>
2023-02-27 20:40:41 +01:00
Damian Gryski
7b44fcd865 runtime: properly turn pointer into empty interface when hashing 2023-02-25 06:42:30 -08:00
Ayke van Laethem
cce9c6d5a1 arm64: fix register save/restore to include vector registers
Some vector registers must be preserved across calls, but this wasn't
happening on Linux and MacOS. When I added support for windows/arm64, I
saw that it required these vector registers to be preserved and assumed
this was Windows deviating from the standard calling convention. But
actually, Windows was just implementing the standard calling convention
and the bug was on Linux and MacOS.

This commit fixes the bug on Linux and MacOS and at the same time merges
the Go and assembly files as they no longer need to be separate.
2023-02-19 20:48:32 +01:00
Ayke van Laethem
f41b6a3b96 runtime: check for heap allocations inside interrupts
This is unsafe and should never be done.
2023-02-19 11:33:24 +01:00
Ayke van Laethem
c02cc339c5 runtime: implement KeepAlive using inline assembly 2023-02-18 10:50:26 +01:00
Ayke van Laethem
4e8453167f all: refactor reflect package
This is a big commit that changes the way runtime type information is stored in
the binary. Instead of compressing it and storing it in a number of sidetables,
it is stored similar to how the Go compiler toolchain stores it (but still more
compactly).

This has a number of advantages:

  * It is much easier to add new features to reflect support. They can simply
    be added to these structs without requiring massive changes (especially in
    the reflect lowering pass).
  * It removes the reflect lowering pass, which was a large amount of hard to
    understand and debug code.
  * The reflect lowering pass also required merging all LLVM IR into one
    module, which is terrible for performance especially when compiling large
    amounts of code. See issue 2870 for details.
  * It is (probably!) easier to reason about for the compiler.

The downside is that it increases code size a bit, especially when reflect is
involved. I hope to fix some of that in later patches.
2023-02-17 22:54:34 +01:00
Anuraag Agrawal
f6df276118
runtime: allow custom-gc SetFinalizer and clarify KeepAlive 2023-02-17 00:51:51 +01:00
Ayke van Laethem
1996fad075 windows: add support for syscall.runtimeSetenv
I missed this in https://github.com/tinygo-org/tinygo/pull/3391 (because
I didn't test on Windows, my fault).
2023-02-03 07:31:38 -08:00
Ayke van Laethem
7fe996e7ba runtime: implement internal/godebug.setUpdate
This function was a stub, but it really needs to be implemented for full
Go 1.20 support. Without it, the archive/zip tests will fail.
2023-02-03 07:31:38 -08:00
Anuraag Agrawal
47ca1c037b Add custom-gc stub for ReadMemStats 2023-01-31 16:41:49 +01:00
Ayke van Laethem
df0f5ae1da windows: add ARM64 support
This was actually surprising once I got TinyGo to build on Windows 11
ARM64. All the changes are exactly what you'd expect for a new
architecture, there was no special weirdness just for arm64.

Actually getting TinyGo to build was kind of involved though. The very
short summary is: install arm64 versions of some pieces of software
(like golang, cmake) instead of installing them though choco. In
particular, use the llvm-mingw[1] toolchain instead of using standard
mingw.

[1]: https://github.com/mstorsjo/llvm-mingw/releases
2023-01-30 21:42:47 +01:00
Anuraag Agrawal
eebd2f648b
Add -gc=custom option (#3302)
* Add -gc=custom option
2023-01-28 20:24:56 +01:00
Takeshi Yoneda
13698b17f7 runtime/debug: stubs PrintStack
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-01-27 10:24:54 +01:00
deadprogram
dd9c2273e4 runtime/stm32wlx: change order for init so clock speeds are set before peripheral start
Signed-off-by: deadprogram <ron@hybridgroup.com>
2023-01-27 00:08:38 +01:00
Damian Gryski
0504e4a201 compiler,runtime: make keySize and valueSize uintptr 2023-01-18 09:48:00 +01:00
Damian Gryski
530ca0838d compiler,runtime: allow map values >256 bytes 2023-01-18 09:48:00 +01:00
Ayke van Laethem
c41a212712 wasm: avoid miscompile with ThinLTO
I found that when I enable ThinLTO, a miscompilation triggers that had
been hidden all the time previously. The bug appears to happen as
follows:

 1. TinyGo generates a function with a runtime.trackPointer call, but
    without an alloca (or the alloca gets optimized away).
 2. LLVM sees that no alloca needs to be kept alive across the
    runtime.trackPointer call, and therefore it adds the 'tail' flag.
    One of the effects of this flag is that it makes it undefined
    behavior to keep allocas alive across the call (which is still safe
    at that point).
 3. The GC lowering pass adds a stack slot alloca and converts
    runtime.trackPointer calls into alloca stores.

The last step triggers the bug: the compiler inserts an alloca where
there was none before but that's not valid as long as the 'tail' flag is
present.

This patch fixes the bug in a somewhat dirty way, by always creating a
dummy alloca so that LLVM won't do the optimization in step 2 (and
possibly other optimizations that rely on there being no alloca
instruction).
2023-01-18 08:24:42 +01:00
Ayke van Laethem
655075e5e0 runtime: implement precise GC
This implements the block-based GC as a partially precise GC. This means
that for most heap allocations it is known which words contain a pointer
and which don't. This should in theory make the GC faster (because it
can skip non-pointer object) and have fewer false positives in a GC
cycle. It does however use a bit more RAM to store the layout of each
object.

Right now this GC seems to be slower than the conservative GC, but
should be less likely to run out of memory as a result of false
positives.
2023-01-17 19:32:18 +01:00
Ayke van Laethem
17176a2cea runtime: zero freed memory
This helps to find bugs in the GC. It does have a performance impact so
it's only enabled when asserts are enabled.
2023-01-17 19:32:18 +01:00
Ayke van Laethem
fb73074325 runtime: move GC code around to prepare for precise GC
Most of the code of the conservative GC can be reused for the precise
GC. So before adding precise GC support, this commit just moves code
around to make the next commit cleaner. It is a non-functional change.
2023-01-17 19:32:18 +01:00
Ayke van Laethem
187d9c6aca riscv: use 16-byte alignment everywhere
Source: https://riscv.org/wp-content/uploads/2015/01/riscv-calling.pdf
2023-01-17 19:32:18 +01:00
Ayke van Laethem
35f427c8cc xtensa: use 8-byte alignment
This is probably not necessary on Espressif chips, but let's strictly
follow the ABI to be sure.
2023-01-17 19:32:18 +01:00
Ayke van Laethem
26b6d0b06d runtime: arm actually has 8-byte alignment
Specification:
https://developer.arm.com/documentation/dui0472/k/C-and-C---Implementation-Details/Basic-data-types-in-ARM-C-and-C--
There are multiple types that have an 8-byte alignment (long long,
double) so we need to use the same maximum alignment in TinyGo.

Fixing this is necessary for the precise GC.
2023-01-17 19:32:18 +01:00