Comments (13)
It seems totally fine for us to relax the spec to make this code valid (also assuming it's not annoying for implementers), although I imagine that having Binaryen stop emitting code that's program-order-after a statically-known unreachable point (unreachable
and unconditional branches) might also be generally valuable for code-size reasons.
from function-references.
I created #99, which would relax the semantics as suggested. It's not hard but a moderate complication, so we should be perhaps be discussing whether it's worth it.
from function-references.
I don't think I'm clearly understanding whether the code in your linked issue is the input to binaryen or the output. If it's the input, it's invalid, so I'm surprised that Binaryen is attempting to do any kind of optimisation on it at all instead of rejecting it. If it's output, I don't think that there's a clear relaxation of our 1a
-style locals that can make it valid.
Put another way, is the issue that Binaryen is emitting code like this:
(block
unreachable
local.get $i
end)
(where $i
is an uninitialised local)
or code like this?
(block
unreachable
end)
local.get $i
It's definitely possible to relax validation to make the first code snippet above validate (and in fact we'd need to make this relaxation anyway if we ever wanted to move to the 1b/c
cross-block approach) - although I don't understand how code in this form is getting emitted since I'd expect Binaryen to optimise the local.get
away.
We can't make the latter code snippet valid without going beyond our current 1a
intra-block initialisation tracking.
from function-references.
The code in the linked issue is input code. It doesn't cause any errors because binaryen ignores unnamed blocks when doing non-nullable local validation because it never emits those blocks in its output anyway. So I believe Binaryen is producing code like your first example.
(Note that there also appears to be an opportunity to skip even more unreachable code in Binaryen's binary emitter, which I suppose would also solve this problem. I don't know how complicated that solution would be, though, and regardless it seems useful to relax the spec as much as we can.)
from function-references.
True, yeah. We do that in the --dce
pass, so this issue only affects unoptimized code (where code size doesn't matter as much).
Overall if this is a simple and otherwise beneficial relaxation in the spec that could be nice, but if not, we can figure things out in Binaryen of course (but it will add a small amount of work, slowing down builds slightly).
from function-references.
Ah, I hadn't properly understood that some Binaryen configurations might not want to do (syntax-driven) dce. I'm happy to help facilitate relaxing the spec as above (assuming we get a neutral/positive noise from @rossberg and engines).
from function-references.
Would it be possible that Binaryen track the point in a block after which code is unreachable and then avoid adding new instructions to that region, or is the issue that an unreachable gets introduced in the middle of a block?
from function-references.
Yes, Binaryen already does that to some extent, and if it did a better job of it, this issue would go away.
Now that we've identified that fix, I wouldn't say a spec change is strongly motivated by this one problem we ran into. I still think it would be a nice change to make based on the general principle that it is helpful to relax the validation rules to reduce the amount of effort producers have to put into generating valid code.
from function-references.
FWIW I don't think this is a particularly hard change in Wizard's validator; there is literally only one instruction affected, which is local.get
, and the control stack entries are annotated with an inUnreachableCode
flag.
from function-references.
From first glance, this looks like a plausible change. But I probably won't have time to look into it for a week or two. It means a few more conditions in every validators, though, so I wonder if it isn't simpler, globally speaking, to implement the fix in Binaryen, which seems desirable anyway.
from function-references.
FWIW this is turning out to be nontrivial to fix in Binaryen (although still desirable to fix, of course). I am unsurprisingly in favor of this spec change.
from function-references.
I just noticed that this issue is still open. @tlively, is this still relevant for Binaryen?
from function-references.
Yes, I think this is still a problem in principle. We've worked around it by always running DCE in our fuzzer when GC is enabled, though, so it's not a problem that is giving us ongoing trouble. I would be ok closing this issue.
from function-references.
Related Issues (20)
- Issues with the JavaScript spec tests HOT 4
- `Illegal macro parameter reference` in the spec HOT 1
- Binary encoding out of sync with GC proposal
- Merge in latest spec repo HOT 2
- Function reference from JavaScript functions? HOT 4
- Validation rule for call_ref with polymorphic stack HOT 5
- Fix table-elem desugaring
- `func.bind` and iso-recursion HOT 2
- Validating local.get in nested blocks with unreachable HOT 5
- br_on_non_null.wast needs unreachable test HOT 1
- slowness of test/core/skip-stack-guard-page.wast HOT 3
- Drop null casts? HOT 4
- Tweak binary format for table declarations HOT 2
- JS-API is missing value conversions HOT 3
- Extend `TableType` to support non-nullable references in JS-API HOT 1
- Progress toward phase 4 HOT 2
- Malformed br_on_null and br_on_non_null in tests HOT 1
- Default/init values in JS-API for globals and table. HOT 3
- Clarification request: initializers for tables with non-nullable type and initial_size == 0 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from function-references.