-
Notifications
You must be signed in to change notification settings - Fork 997
interp: rewrite entire package #1430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
#1412 has been merged. Not sure what change is needed to go-llvm or if that has already been made. |
|
No, a different change is needed. I'll get back to this, it really helps to make TinyGo a more correct Go compiler. |
6ce02a0 to
539a81b
Compare
|
Looks like this almost works, but needs some work to support some Go versions. |
0749d15 to
87258f6
Compare
|
Note that this should probably be merged after the next release, to give it some time to find possible bugs. |
|
Indeed 😺 |
87258f6 to
946be58
Compare
946be58 to
0b3b692
Compare
|
With tinygo (dev branch), I could not compile my application: Then I applied the 3 commits This fixed the previous error ! Thanks Olivier |
Previously, EmitPointerPack would generate an out-of-bounds read from an alloca. This commit fixes that by creating an alloca of the appropriate size instead of using the size of the to-be-packed data (which might be smaller than a pointer). I discovered this error while working on a rewrite of the interp package, which checks for out-of-bounds reads and writes. There I discovered this issue when the image package was compiled.
Because the parentHandle parameter wasn't always set to the right value, the coroutine lowering pass would sometimes panic with "trying to make exported function async" even though there was no exported function involved. Therefore, it should unconditionally be set to avoid this. The parent function doesn't always have the parentHandle function parameter set because it can only be set after defining a function, not when it is only declared.
0b3b692 to
87180f6
Compare
niaow
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, one minor comment
interp/memory.go
Outdated
| } | ||
| mv.objects[objectIndex] = obj | ||
| } | ||
| // TODO: also mark objects referenced by this object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this going to break anything now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my testing, no. However it is technically unsound and should probably be fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, does this require additional work now, or should we merge and deal with in future effort?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think I shouldn't be lazy and fix this (even if it doesn't seem to affect the behavior right now).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed now.
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.
87180f6 to
b331e3e
Compare
|
Okay, I've written the missing bits (see the force push for a diff). Ready for review again. |
|
What is the status of this PR? It would appear that all feedback has now been addressed. |
|
Ready from my POV but maybe @niaow wants to comment. |
|
Here we go!! 🚀 🦝 |
|
Unfortunately this appears to have broken at least support for the Circuit Playground Express. Even examples/blinky1 doesn't work anymore. |
|
OK that seems odd, because the TinyHCI tests passed on CPE board after the merge. However I am able right now to verify the problem on CPE myself. Also confirm it is commit 30df912 that causes the problem. |
|
I'll take a look, but probably not before Saturday. |
|
I wonder if it is specifically related to USB-CDC code somehow? I notice that now that this merged into |
|
Yes, probably. I will investigate soon. |
|
What I've discovered so far is that |
|
I have figured out the issue, the fix is in #1547. |
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:
This means the following packages now pass tests with
tinygo test:This PR depends on #1412, which should be merged first. Also, it requires a change to the go-llvm package.