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

246 коммитов

Автор SHA1 Сообщение Дата
Ayke van Laethem
01e58691a1 compiler: support constant indices with a named type 2019-10-01 21:31:00 +02:00
Jaden Weiss
b5ecd9cab0 fix LLVM assertions from improved blocking 2019-09-25 23:04:53 +02:00
Ayke van Laethem
da7f7eef00 interp: avoid an extra TargetData argument
This can be easily calculated from the module datalayout string.
2019-09-24 18:16:43 +02:00
Jaden Weiss
17ef7a5c32
all: add support for go 1.13 2019-09-24 16:13:26 +02:00
Jaden Weiss
6c9e55bd06
reflect: delete incorrect optimization 2019-09-24 16:13:19 +02:00
Jaden Weiss
d843ebfe40 Improved blocking (#513)
core: major improvements to blocking, including support for buffered channels.
2019-09-22 17:58:00 +02:00
Ayke van Laethem
65beddafe8 compiler: move OptimizeStringToBytes to transform package
Unfortunately, while doing this I found that it doesn't actually apply
in any real-world programs (tested with `make smoketest`), apparently
because nil pointer checking messes with the functionattrs pass. I hope
to fix that after moving to LLVM 9, which has an optimization that makes
nil pointer checking easier to implement.
2019-09-22 08:25:50 +02:00
Ayke van Laethem
cf2a7b5089 compiler: add //go:align pragma
This is sometimes needed for globals. For example, the atsamd21 chip
requires the DMA buffers to be aligned on a 16 byte boundary.
2019-09-18 20:15:17 +02:00
Jaden Weiss
abca3132a9 fix bugs found by LLVM assertions 2019-09-16 18:31:33 +02:00
Ayke van Laethem
8cd2c7502e all: move OptimizeMaps to transforms and add tests 2019-09-15 21:26:27 +02:00
Ayke van Laethem
d905476231 all: refactor heap-to-stack transform into the transform package
Also add unit tests.

This is the first of several transformation (optimization/lowering)
passes that I'd like to move to the new transform package. This
separates the compiler from the optimizer.

Also, it finally adds unit tests for the compiler, not just end-to-end
compilation tests. This should improve robustness and should make it
easier to change these transformation passes in the future.
While the heap-to-stack transform is relatively simple, other passes are
much more complex. Adding unit tests not only helps robustness over
time, but also doubles as documentation as to what these transformation
passes do exactly.
2019-09-15 21:26:27 +02:00
Ayke van Laethem
10ed3decb0 compiler: rename getZeroValue to llvm.ConstNull
It does the same thing but should be more complete, and it probably is
faster as well (just one CGo call instead of several).
2019-09-15 19:09:10 +02:00
Phil Kedy
55144ad608 WASM: Support for setting an imported function's module name (#455)
* wasm: add support for setting a function's Wasm import module name by using the //go:wasm-module comment.
2019-09-12 08:35:43 +02:00
Ayke van Laethem
c19c738f52 reflect: implement support for array types 2019-08-19 11:08:26 +02:00
Ayke van Laethem
bbc3046687 compiler: add support for 'go' on func values
This commit allows starting a new goroutine directly from a func value,
not just when the static callee is known.

This is necessary to support the whole time package, not just the
commonly used subset that was compiled with the SimpleDCE pass enabled.
2019-08-17 11:51:43 +02:00
Ayke van Laethem
e4fc3bb66a compiler,runtime: fix new task-based scheduler
A bug was introduced in the previous commit that led to miscompilations
in the time.Sleep function when the scheduler was disabled, because
time.Sleep (implemented in the runtime) tried to switch to the scheduler
stack.

This commit restores the binary size of most examples to what it was
before, but still reduces static RAM consumption (.bss) slightly. This
gives me some confidence that it does indeed fix the introduced bug.
2019-08-17 08:42:23 +02:00
Ayke van Laethem
542135c357 compiler,runtime: implement stack-based scheduler
This scheduler is intended to live along the (stackless) coroutine based
scheduler which is needed for WebAssembly and unsupported platforms. The
stack based scheduler is somewhat simpler in implementation as it does
not require full program transform passes and supports things like
function pointers and interface methods out of the box with no changes.

Code size is reduced in most cases, even in the case where no scheduler
scheduler is used at all. I'm not exactly sure why but these changes
likely allowed some further optimizations somewhere. Even RAM is
slightly reduced, perhaps some global was elminated in the process as
well.
2019-08-15 17:31:54 +02:00
Ayke van Laethem
fd3309afa8 compiler,runtime: implement []rune to string conversion
This is used by a few packages in the standard library, at least
compress/gzip and regexp/syntax.
2019-08-11 15:45:35 +02:00
Ayke van Laethem
fea56d4164 compiler: add support for full slice expression for slicing arrays
This was an oversight in the main commit for full slice expressions:
https://github.com/tinygo-org/tinygo/pull/472
This syntax is used by the regexp package, for example.
2019-08-11 15:37:05 +02:00
Ayke van Laethem
ea8e4079bc reflect: add support for linked lists
Linked lists are usually implemented as follows:

    type linkedList struct {
        next *linkedList
        data int // whatever
    }

This caused a stack overflow while writing out the reflect run-time type
information. This has now been fixed by splitting the allocation of a
named type number from setting the underlying type in the sidetable.
2019-08-11 15:00:43 +02:00
Ayke van Laethem
b7cb10519c compiler: fix some invalid IR
Compiling LLVM with assertions enabled revealed some bugs in TinyGo that
weren't caught by normal verifying of the LLVM module.
2019-08-09 21:27:23 +02:00
Ayke van Laethem
562ad740da compiler: make runtime.makeGoroutine AVR compatible
Previously it would use a bitcast, which cannot directly be used on AVR
because functions live in a different address space on AVR. To fix this,
use a ptrtoint/inttoptr pair.

This allows testdata/coroutines.go to be compiled, but due to what
appears to be an LLVM bug cannot be optimized and codegen'ed:

    tinygo: /home/ayke/src/github.com/tinygo-org/tinygo/llvm-project/llvm/lib/IR/Constants.cpp:1776: static llvm::Constant *llvm::ConstantExpr::getBitCast(llvm::Constant *, llvm::Type *, bool): Assertion `CastInst::castIsValid(Instruction::BitCast, C, DstTy) && "Invalid constantexpr bitcast!"' failed.

This happens as one of the function passes after the TinyGo passes and
after the module has been verified so most likely it is a bug somewhere
in LLVM.
2019-08-09 21:27:23 +02:00
Ayke van Laethem
e2c8654237 reflect: add support for struct types 2019-08-08 15:23:47 +02:00
Ayke van Laethem
f43d01bdc7 compiler: make struct types more unique
There are a lot more fields that are important when comparing structs
with each other. Take them into account when building the unique ID per
struct type.

Example code that differs between the compilers:
https://play.golang.org/p/nDX4tSHOf_T
2019-08-08 15:23:47 +02:00
Ayke van Laethem
79b470acee compiler: make goroutine lowering panic message more helpful
This is a workaround for an existing issue, to see which function is to
blame.
2019-08-08 11:59:53 +02:00
Ayke van Laethem
95721a8d8c reflect: add support for named types
With this change, it becomes possible to get the element type of named
slices, pointers, and channels.

This is a prerequisite to enable the common named struct types. There's
more to come.
2019-08-05 14:44:30 +02:00
Ayke van Laethem
33dc4b5121 compiler: fix crash with linked lists in interfaces
This commit fixes the following issue:
https://github.com/tinygo-org/tinygo/issues/309
Also, it prepares for some other reflect-related changes that should
make it easier to add support for named types (etc.) in the future.
2019-08-05 14:44:30 +02:00
Elliott Sales de Andrade
9878f7ebc4 Add support for linux/386 syscalls. 2019-08-04 18:15:06 +02:00
Ayke van Laethem
4688664b41 compiler: implement full slice expression
This feature was introduced in Go 1.2 and is used by some standard
library packages.
2019-08-04 17:51:16 +02:00
Ayke van Laethem
54169c714f all: use baremetal build tag
This simplifies adding more baremetal targets, like a GameBoy Advance,
or baremetal x86 for unikernels.
2019-08-04 17:12:07 +02:00
Justin Clift
f76385850d main: fix outdated panic option text 2019-08-04 14:11:08 +02:00
Ayke van Laethem
152caa3b0a compiler: do not create stack objects for functions that don't allocate
This is a useful optimization for targets with the portable garbage
collector. It isn't as big as you might guess but it does optimize
functions inside the garbage collector itself (which obviously should
not allocate). WebAssembly output in one test is about 1% smaller.
2019-07-08 00:02:28 +02:00
Ayke van Laethem
7ed6b45149 compiler: add the //go:noinline pragma
This is directly useful to avoid some unsafety around runtime.alloc and
should be useful in general.

This pragma has the same form as in the main Go compiler:
https://github.com/golang/go/issues/12312
2019-07-08 00:02:28 +02:00
Ayke van Laethem
c66d979ba3 compiler: avoid some stack frames when this is unnecessary
Some instructions do not create new values, they transform existing
values in some way (bitcast, getelementptr, etc.). Do not store them in
the stack object.

This lowers the size of the repulsion demo from 100kB to 98kB (with a
baseline of 72kB for the leaking GC). That's a useful reduction in file
size.
2019-07-08 00:02:28 +02:00
Ayke van Laethem
ffa38b183b all: add HiFive1 rev B board with RISC-V architecture
This page has been a big help in adding support for this new chip:
https://wiki.osdev.org/HiFive-1_Bare_Bones
2019-07-07 14:03:24 +02:00
Ayke van Laethem
6611578ec8 compiler: remove some TODOs
These have long since been implemented.
2019-07-03 21:22:12 +02:00
Ayke van Laethem
d49a363d0d compiler: track all pointers returned by runtime.alloc
In particular, track the pointers to the memory allocated for coroutine
frames. Before this change, the following code would show memory
corruption:
https://github.com/johanbrandhorst/wasm-experiments/blob/master/canvas/main.go
2019-07-03 21:22:12 +02:00
Ayke van Laethem
385d1d0a5d
compiler,runtime: implement a portable conservative GC 2019-07-01 16:30:33 +02:00
Ayke van Laethem
00e91ec569
all: rename garbage collectors
dumb -> leaking:
  make it more clear what this "GC" does: leak everything.
marksweep -> conservative:
  "marksweep" is too generic, use "conservative" to differentiate
  between future garbage collectors: precise marksweep / mark-compact /
  refcounting.
2019-07-01 13:03:07 +02:00
Justin Clift
46872a70b1 Trivial typo fix 2019-06-20 13:30:38 +02:00
scriptonist
e9f6e51fc8
compiler,runtime: implement string to []rune conversion
Commit message by aykevl
2019-06-19 01:17:21 +02:00
Carolyn Van Slyck
208e1719ad Add test command to tinygo (#243)
* Add test command to tinygo
2019-06-18 12:23:59 +02:00
Ayke van Laethem
a3d1f1a514 all: try more locations to find Clang built-in headers
This commit fixes the case where TinyGo was built with `go build` and
LLVM sources were never downloaded into the TinyGo source directory.
2019-06-13 15:21:04 +02:00
Ayke van Laethem
b7197bcaae compiler,runtime: implement non-blocking selects
Blocking selects are much more complicated, so let's do non-blocking
ones first.
2019-06-12 18:26:52 +02:00
Ayke van Laethem
8890a0f3c8 compiler,runtime: store channel size in the channel itself
This may have a small effect on code size sometimes, but will simplify
the implementation of the select statement.
2019-06-12 18:26:52 +02:00
Ayke van Laethem
b0e767c4a7 compiler: move global handling from ir to compiler package
This is part of a larger rafactor that tries to shrink the ir package
and in general tries to shrink the amount of state that is kept around
in the compiler. The end goal is being able to compile packages
independent of each other, linking them together in a later stage. Along
the way, it cleans up lots of old cruft that has accumulated over the
months.

This refactor also results in globals being loaded lazily. This may be a
problem for some specific programs but will probably change back in a
commit in the near future.
2019-06-08 22:17:09 +02:00
Ayke van Laethem
6b5b4a681d compiler: refactor named types to create them lazily
This commit refactors named types to be created lazily. Instead of
defining all types in advance, do it only when necessary.
2019-06-08 22:17:09 +02:00
Ayke van Laethem
88bb61f287 compiler: return a valid (undef) value from a unsupported select
Returning a nil value may lead to problems later on. Just return undef
here, so that further compilation will at least be safe (the result
will be discarded anyway).
2019-06-08 21:48:05 +02:00
Ayke van Laethem
e169e3b996 compiler: remove superfluous 'err' result in decodeFuncValue 2019-06-08 21:48:05 +02:00
Ayke van Laethem
aa8957dd05 compiler: support non-constant syscall numbers
Not all syscalls use constant numbers.
2019-06-08 21:48:05 +02:00