Repository navigation
Define precise order of sections - #597
Conversation
|
In your PR Description you forgot about
That means a silent failure for a known section. I would have preferred to trap if 2 known sections are swapped to help catch possible bugs. |
…#597) Removed the subsequent dependency and replaced it with a check for function signatures and bodies.
…#597) Removed the subsequent dependency and replaced it with a check for function signatures and bodies.
…#597) Removed the subsequent dependency and replaced it with a check for function signatures and bodies.
Correct, I was more just giving rationale; the proposed order is what's listed in the list in BinaryEncoding.md.
Agreed, this is what I was on the fence about as well. So we could define this by saying that any given section id is either "known" or "unknown" and only "unknown" sections can be skipped. That's easy enough; sound good to everyone else? |
|
Mostly a bikeshed, but is there any rationale for the location of the memory module? It seems more natural to me for that to be first. |
|
@binji The memory limits can be used to optimize the compiled code so need to be before the function bodies to avoid blocking compilation, but that's the only 'rationale' that comes to mind. |
|
I liked the principle of "imports as early as possible" followed by all the exportable definitions (incl. memory), followed by the export table. But this still allows the memory section to be in any one of 3 positions (relative to |
|
Might there be some utility in retaining an 'end' style section marker that indicates the end of the execution-semantic sections? This might give the runtime more confidence to start execution before the entire file has been received, given that the tail might have a lot of meta information, and not increase the latency when adding meta information. |
|
Given that the engine will know itself which sections it understands and that unknown sections are ignored, I wouldn't think the engine would need any extra hints. For example, regardless of the end section, an engine could start executing (assuming it's reading from a network stream) right after the data segments section finished (before the name section). |
|
@lukewagner Might there ever be sections added that have a semantic effect on execution, so that the data segments is not the last etc? Also since unknown sections can come anywhere, how can it know that the optional data segments section is not still to come? If a sections directory could be added at the start then this would also resolve the matter. |
|
If new sections were added in the future, they would continue to be ignored by older engines (b/c they would be unknown to those engines). Newer engines that recognized those sections would know to wait for them. There's only one data section so with a precise ordering, after you've seen it, you can know there's nothing semantically-visible left. |
|
@lukewagner But the data segments section is optional? So after reading all the function bodies, then seeing a big unknown section, and before a 'names' section, the runtime still does not know if it can start execution (there may be no data segments section to end the execution semantic sections)? The concern is that adding meta data in unknown sections will introduce latency that could be avoided. The PR seems to define all sections as optional 'The shortest valid module is 8 bytes', but some depend on others. Could this is made clearer with a consistent text paragraph for each section stating the constraints under which it is required and that it is otherwise optional etc. |
|
I guess I'd like to see evidence of large non-semantic sections between spec-defined semantics-affecting sections (e.g., between bodies and data) to justify adding new "dividing" markers (which is a different proposal from an "end" marker which would literally be the last section). Such markers could also be added in the future. I think many of the constraints are already present in the validation criteria: e.g. the number of function bodies has to match function signatures, function table indices have to be in range (implying there must be a section), etc. Are there any particular validation criteria that are missing? |
|
@lukewagner There is the 'evidence': Facts:
There is a technical use case of reducing latency, somewhat of core goal for wasm, and I would like it accommodated in the presence of source code meta information that helps make the code more accessible which I personally think is important. My preference would be to add a mandatory sections directory which would address this use case by letting the runtime know early what sections follow from which it could determine when it had received all the execution-semantic information. This would also address uses cases that require random access into the binary encoding, without requiring a side-cache. But a section marker would also be an option that could be added now until a sections directory is added. |
|
Ah, I see your point now: in the case where no data section is present, an engine would have to consume until the end of the stream just to know it wasn't yet still to come. That makes sense and that's a good argument for a mandatory end section (which wasn't actually the last section and could be followed by any number of necessarily-unknown sections). I'll rebase and add that back to the PR. |
|
Thank you, very much appreciate your understanding. |
8784089 to
e8fb2df
Compare
|
Rebased and pushed with that and above request for rejecting out-of-order known sections. |
|
If a module needs to be valid to be accepted and 'the end of the last present section must coincide with the last byte of the module' then might this block early execution? Might the runtime need to wait until the end of the file just to check that it ends on a section boundary before starting execution? Would it be possible to define content after the |
|
That makes sense: if the point here is to allow execution to begin after "End" (while, e.g., "Names" is still being downloaded), then nothing after "End" can invalidate the whole module. |
|
Thinking about the practical implications a bit more:
So all this adds up, I think, to not having a before-the-end End section. |
|
I was thinking about this some. When a section has many potential orderings because it has few current constraints (like memory), we'll want to place it earlier if we guess that future sections will depend on it. For example, imagine we add a new section that depends on the memory section (perhaps a dynamic linking section), it will necessarily go after the all the sections that precede the memory section, even if it doesn't depend on them. I guess what I'm saying is that it seems like we'll always be able to produce a topological sort (because no section can depend on a section that will be added later), but we won't necessary have a very good one unless we can reasonably predict future dependencies. Maybe this doesn't matter too much? Or am I missing something? |
|
@lukewagner Perhaps reporting messages are not part of the spec, so a runtime has discretion over waiting for the Even for MVP the content will stream in and it seem possible for a runtime to choose to end the download after the |
|
@lukewagner Another point, but getting a little off topic, is that my understanding of the 'stream' support is that it is a JS API in code that the web developer supplies and thus not matters that the browser vendor or the user have discretion in? I think this is a very significant distinction. Depending on a JS API to meet the 'meta-info-download/latency' use case would meet distinctly different use cases to it being under the control of the browser/user. Further, it might be possible to articulate a design principle to the effect that the user being able to 'view source' should also give the user control over the download of the meta information to view the source, rather than it being at the discretion of the web app developer to enable or disable it on the client side (developers can still decide to include meta info or not on the server side). |
|
Oops, I let this drop while on vacation. @binji That makes sense, but in the future we can always choose to loosen ordering requirements. FWIW, I'm expecting the section structure, and possibly order, to change again in one of our upcoming binary updates, but as this currently matches the precise format accepted by FF (and, though perhaps not exclusively, accepted by Chakra/V8), any objections to merging the current ordering and dealing with further changes in future PRs? @titzer @Cellule? @JSStats In the MVP, the only APIs for compiling wasm will take |
|
V8 doesn't check the exact order of sections yet, but we will when the On Wed, Mar 30, 2016 at 12:22 AM, Luke Wagner [email protected]
|
|
@lukewagner Personally I think the higher level design is fundamentally too web developer centric and too anti-user. When making any design decision I would have asked: can this be designed to avoid exposing information about the runtime to the web, and can it be designed to put the user in control rather than the web code. This principle is absent in the design and it shows up here too, with the requirement that buffer or streaming be via software that the web developer supplies, software that the user has to just trust and that likely does not support features the user would want. Adding an 'end' section would have given the user the option to reduce latency, and to reduce storage requirements, and to avoid exposing information about the validity of the following sections. The higher level design of wasm could have been organised around privileged code, code that the community can scrutinised, just as a web browser is trusted, and this could have implemented the streaming options etc. So as it stands a defensive web browser can just fail to report validation errors in meta information sections, as if they were not supported, but the web developers code might probe for a validation error to check for support and believing there is no support decide not to include the meta information and the code will be incomplete and the user loses out having not choice. |
|
@titzer so, good to merge? @JSStats Non-web native environments have strictly more options for optimizing load time and can do what the web does and more. E.g., they can mmap the wasm file all at once and seek randomly around, using the section lengths to easily skip over ignored sections. If you want to continue this discussion, it seems like a new issue is the right place since this PR is focused on defining a precise order and what you're talking about is changing the rules for how and when things are validated. |
|
@lukewagner You are removing the 'end' section and not giving it an ordering, but I guess you are doing it in a context in which the meta data sections are validated, so I guess the discussion on this could be moved to a separate issue, sorry. Just for the record, many of my points are web related. A file can't be mmapped if it has not been downloaded and the download latency can be significant on the web. A web app can not know if the user will need the meta information unless it prompts them or the browser exposes a personal setting to the app, and this does not seem a good approach to me and this is a web issue. |
|
lgtm |
This PR defines the order of sections so that an engine can walk down an optional list of sections and easily match section ids when decoding a module.
A rationale for the particular order in this PR:
Two other details in this PR to note/discuss: