aboutsummaryrefslogtreecommitdiffhomepage
path: root/interp/interp.go
AgeCommit message (Collapse)Author
2024-09-05interp: support big-endian targetsAyke van Laethem
The interp package was assuming that all targets were little-endian. But that's not true: we now have a big-endian target (GOARCH=mips). This fixes the interp package to use the appropriate byte order for a given target.
2024-08-14make spell: add a few missing misspellings, fix format of .csv file, also ↵Dan Kegel
fix *.md
2023-10-01all: remove LLVM 14 supportAyke van Laethem
This is a big change: apart from removing LLVM 14 it also removes typed pointer support (which was only fully supported in LLVM up to version 14). This removes about 200 lines of code, but more importantly removes a ton of special cases for LLVM 14.
2022-10-19all: remove pointer ElementType callsAyke van Laethem
This is needed for opaque pointers, which are enabled by default in LLVM 15.
2022-10-19all: add type parameter to CreateCallAyke van Laethem
This uses LLVMBuildCall2 in the background, which is the replacement for the deprecated LLVMBuildCall function.
2022-08-20make interp timeout configurable from command lineDamian Gryski
2022-05-30builder: free LLVM objects after useAyke van Laethem
This reduces the TinyGo memory consumption when running make tinygo-test from 5.8GB to around 2GB on my laptop.
2022-05-25interp: improve error handling of markExternal* functionsAyke van Laethem
2022-01-19compiler: remove parentHandle from calling conventionNia Waldvogel
This removes the parentHandle argument from the internal calling convention. It was formerly used to implment coroutines. Now that coroutines have been removed, it is no longer necessary.
2021-12-28builder: use build ID as cache keyAyke van Laethem
Instead of storing an increasing version number in relevant packages (compiler.Version, interp.Version, cgo.Version, ...), read the build ID from the currently running executable. This has several benefits: * All changes relevant to the compiled packages are caught. * No need to bump the version for each change to these packages. This avoids merge conflicts. * During development, `go install` is enough. No need to run `tinygo clean` all the time. Of course, the drawback is that it might be updated a bit more often than necessary but I think the overall benefit is big. Regular release users shouldn't see any difference. Because the tinygo binary stays the same, the cache works well.
2021-12-11interp: work around AVR function pointers in globalsAyke van Laethem
Not sure how to test this, since we don't really have any AVR tests configured.
2021-11-11interp: take care of constant globalsAyke van Laethem
Constant globals can't have been modified, even if a pointer is passed externally. Therefore, don't treat it as such in hasExternalStore. In addition, it doesn't make sense to update values of constant globals after the interp pass is finished. So don't do this. TODO: track whether objects are actually modified and only update the globals if this is the case.
2021-07-14interp: fix bug in compiler-time/run-time package initializersAyke van Laethem
Make sure that if a package initializer cannot be run, later package initializers won't try to access any global variables touched by the uninterpretable package initializer.
2021-07-14interp: keep reverted package initializers in orderAyke van Laethem
Previously, a package initializer that could not be reverted correctly would be called at runtime. But the initializer would be called in the wrong order: after later packages are initialized. This commit fixes this oversight and adds a test to verify the new behavior.
2021-07-14interp: don't ignore array indices for untyped objectsAyke van Laethem
This fixes https://github.com/tinygo-org/tinygo/issues/1884. My original plan to fix this was much more complicated, but then I realized that the output type doesn't matter anyway and I can simply cast the type to an *i8 and perform a GEP on that pointer.
2021-06-21interp: fix a bug in pointer cast workaroundAyke van Laethem
This was triggered by the following code: var smallPrimesProduct = new(big.Int).SetUint64(16294579238595022365) It is part of the new TinyGo version of the crypto/rand package.
2021-04-02builder: run interp per packageAyke van Laethem
This results in a significant speedup in some cases. For example, this runs over twice as fast with a warm cache: tinygo build -o test.elf ./testdata/stdlib.go This should help a lot with edit-compile-test cycles, that typically only modify a single package. This required some changes to the interp package to deal with globals created in a previous run of the interp package and to deal with external globals (that can't be loaded from or stored to).
2021-04-02interp: make toLLVMValue return an error instead of panickingAyke van Laethem
This commit replaces a number of panics with returning an error value as a result of changing the toLLVMValue method signature. This should make it easier to diagnose issues.
2021-03-12interp: support GEP on fixed (MMIO) addressesAyke van Laethem
GetElementPtr would not work on values that weren't pointers. Because fixed addresses (often used in memory-mapped I/O) are integers rather than pointers in interp, it would return an error. This resulted in the teensy40 target not compiling correctly since the interp package rewrite. This commit should fix that.
2020-12-27interp: fix alignment of untyped globalsAyke van Laethem
During a run of interp, some memory (for example, memory allocated through runtime.alloc) may not have a known LLVM type. This memory is alllocated by creating an i8 array. This does not necessarily work, as i8 has no alignment requirements while the allocated object may have allocation requirements. Therefore, the resulting global may have an alignment that is too loose. This works on some microcontrollers but notably does not work on a Cortex-M0 or Cortex-M0+, as all load/store operations must be aligned. This commit fixes this by setting the alignment of untyped memory to the maximum alignment. The determination of "maximum alignment" is not great but should get the job done on most architectures.
2020-12-22interp: rewrite entire packageAyke van Laethem
For a full explanation, see interp/README.md. In short, this rewrite is a redesign of the partial evaluator which improves it over the previous partial evaluator. The main functional difference is that when interpreting a function, the interpretation can be rolled back when an unsupported instruction is encountered (for example, an actual unknown instruction or a branch on a value that's only known at runtime). This also means that it is no longer necessary to scan functions to see whether they can be interpreted: instead, this package now just tries to interpret it and reverts when it can't go further. This new design has several benefits: * Most errors coming from the interp package are avoided, as it can simply skip the code it can't handle. This has long been an issue. * The memory model has been improved, which means some packages now pass all tests that previously didn't pass them. * Because of a better design, it is in fact a bit faster than the previous version. This means the following packages now pass tests with `tinygo test`: * hash/adler32: previously it would hang in an infinite loop * math/cmplx: previously it resulted in errors This also means that the math/big package can be imported. It would previously fail with a "interp: branch on a non-constant" error.
2020-03-28interp: show backtrace with errorAyke van Laethem
This should make it much easier to figure out why and where an error happens at package initialization time.
2019-11-26interp: replace many panics with error messagesAyke van Laethem
This commit replaces most panics in interp/frame.go and interp/scan.go with real error messages. The remaining ones are panics that should not happen when working with valid IR.
2019-11-26interp: improve error reportingAyke van Laethem
This commit improves error reporting in several ways: * Location information is read from the intruction that causes the error, as far as that's available. * The package that is being interpreted is included in the error message. This may be the most useful part of the improvements. * The hashmap update intrinsics now doesn't panic, instead it logs a clear error (with location information, as in the above two bullet points). This is possible thanks to improvements in LLVM 9. This means that after this change, TinyGo will depend on LLVM 9.
2019-09-24interp: avoid an extra TargetData argumentAyke van Laethem
This can be easily calculated from the module datalayout string.
2019-05-14compiler: add debug info for function argumentsAyke van Laethem
This commit adds debug info to function arguments, so that in many cases you can see them when compiling with less optimizations enabled. Unfortunately, due to the way Go SSA works, it is hard to preserve them in many cases. Local variables are not yet saved. Also, change the language type to C, to make sure lldb shows function arguments. The previous language was Modula 3, apparently due to a off-by-one error somewhere.
2019-03-08interp: refactor to eliminate lots of codeAyke van Laethem
This may cause a small performance penalty, but the code is easier to maange as a result.
2019-03-07interp: use correct initialization order on panic() callsAyke van Laethem
Whenever interp hits an unreachable instruction, it bails out at that point. However, it used to insert new instructions at the bottom with the old init calls still at the top. So when a panic() happened in a non-main package, the last packages to init would actually be called first. This commit fixes this by setting the insert point at the top of runtime.initAll before starting interpretation, so the initialization order is still correct when a panic() happens during init.
2019-02-05interp: remove init call when hitting 'unreachable'Ayke van Laethem
The interp package interprets calls in runtime.initAll and replaces these calls with non-interpretable instructions if needed. When hitting an unreachable instruction, this call should be removed, but it wasn't. This commit makes sure the call is removed even before trying to interpret the package init function.
2019-01-27all: rename go-llvm to new import pathAyke van Laethem
the new import path is: tinygo.org/x/go-llvm
2019-01-21all: rewrite goroutine loweringAyke van Laethem
Before this commit, goroutine support was spread through the compiler. This commit changes this support, so that the compiler itself only generates simple intrinsics and leaves the real support to a compiler pass that runs as one of the TinyGo-specific optimization passes. The biggest change, that was done together with the rewrite, was support for goroutines in WebAssembly for JavaScript. The challenge in JavaScript is that in general no blocking operations are allowed, which means that programs that call time.Sleep() but do not start goroutines also have to be scheduled by the scheduler.
2018-12-09compiler: always use fat function pointers with contextAyke van Laethem
This reduces complexity in the compiler without affecting binary sizes too much. Cortex-M0: no changes Linux x64: no changes WebAssembly: some testcases (calls, coroutines, map) are slightly bigger
2018-12-01interp: report 'unreachable' instruction as an errorAyke van Laethem
This instruction should never be hit in real programs, but the interpreter may hit it after a call to panic(). This would always be a runtime error.
2018-11-04interp: add new compile-time package initialization interpreterAyke van Laethem
This interpreter currently complements the Go SSA level interpreter. It may stay complementary or may be the only interpreter in the future. This interpreter is experimental and not yet finished (there are known bugs!) so it is disabled by default. It can be enabled by passing the -initinterp flag. The goal is to be able to run all initializations at compile time except for the ones having side effects. This mostly works except perhaps for a few edge cases. In the future, this interpeter may be used to actually run regular Go code, perhaps in a shell.