Skip to content
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

Embedding limits #873

Merged
merged 8 commits into from
Oct 9, 2018
Merged

Embedding limits #873

merged 8 commits into from
Oct 9, 2018

Conversation

titzer
Copy link
Contributor

@titzer titzer commented Sep 13, 2018

This PR contains additional spec text and tests for embedding limits as discussed in #607.

builder.setFunctionTableBounds(1, 1);
let array = [];
for (let i = 0; i < count; i++) {
builder.addFunctionTableInit(0, false, array, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This terminology confused me at first; "FunctionTableInit" here is what the spec calls an "Element Segment". I've opened a PR to rename these: #874

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

let kJSEmbeddingMaxFunctionParams = 1000;
let kJSEmbeddingMaxFunctionReturns = 1;
let kJSEmbeddingMaxTableSize = 10000000;
let kJSEmbeddingMaxTableEntries = 10000000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be called kJSEmbeddingMaxElementSegments based on the test below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


The WebAssembly core specification allows an implementation to define limits on the syntactic structure of the module.
The standard WebAssembly JavaScript Interface described in this document hereby defines a set of standard limits on the syntactic module structure as below.
Modules that exceed these limits are invalid and are rejected with a {{CompileError}}.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume it's implied that lower implementation limits may exist?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea here is that there actually shouldn't be lower implementation limits, that these are exact. Should the text be clarified?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, since low-resource devices (like embedded) and computationally-sensitive uses (think: Etherum's eWASM) won't be able to cope with these limits particularly well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These limits only apply to JavaScript embeddings and are not relevant to others, including blockchain platforms.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rossberg What about JS embeddings without sufficient RAM? For one concrete example, mobile devices might have performance problems processing large WASM bundles due to a slower clock speed + less RAM available. (The max amount of allocatable memory per this, for example, is 2GB. Low-end smartphones don't usually have this much available - some only have 2GB of RAM.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL at new text

@littledan
Copy link
Collaborator

Cc @Ms2ger if you could review these tests, it would be great.

<h2 id="limits">Implementation-defined Limits</h2>

The WebAssembly core specification allows an implementation to define limits on the syntactic structure of the module.
The standard WebAssembly JavaScript Interface described in this document hereby defines a set of standard limits on the syntactic module structure as below.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The word "hereby" is not used like this in standards very much; I'd eliminate it (or use formally defined terms like "SHOULD" or "MUST"). But this is editorial and can be done in a follow-on editorial patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL

<li>The initial or maximum number of pages for any memory, declared or imported, is at most 32767.</li>

<li>The maximum number of parameters to any function is 1000.</li>
<li>The maximum number of return types for any function is 1.</li>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/types/values/? Again, an editorial change that we can consider in a follow-on PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

test/build.py Outdated
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this change was intentional

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


The WebAssembly core specification allows an implementation to define limits on the syntactic structure of the module.
The standard WebAssembly JavaScript Interface described in this document hereby defines a set of standard limits on the syntactic module structure as below.
Modules that exceed these limits are invalid and are rejected with a {{CompileError}}.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea here is that there actually shouldn't be lower implementation limits, that these are exact. Should the text be clarified?

if (failures.length > 0) {
throw failures[0];
}
//=======================================================================
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this part need to be removed? (And the similar segment above)


The WebAssembly core specification allows an implementation to define limits on the syntactic structure of the module.
The standard WebAssembly JavaScript Interface described in this document hereby defines a set of standard limits on the syntactic module structure as below.
Modules that exceed these limits are invalid and are rejected with a {{CompileError}}.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a "Statement of fact" with no normative prose to back it up.

It's also a "COMEFROM" statement; it's not in the place where you look when for a definition of compiling or validating modules. Perhaps a better place would be in #compile-a-webassembly-module. We'd need to make sure that HTML calls through that, then.

It's perhaps worth elaborating on why this is in js-api, though, since that seems like a weird layering on first sight.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please submit the test to wpt directly, under its license(s).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we agreed that all tests need to be submitted directly to wpt; they can be added through either side.

let kTestAsyncCompile = true;

//=======================================================================
// HARNESS SNIPPET, DO NOT COMMIT
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not commit.

let kJSEmbeddingMaxMemories = 1;

function verbose(...args) {
if (false) print(...args);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use print().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better alternative? I've found it helpful to have console/print output while developing the tests. Any suggestion?


let kTestValidate = true;
let kTestSyncCompile = true;
let kTestAsyncCompile = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these; split into three files if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd prefer not to split this into three files. The flags were useful in developing the test. Is that worth keeping in your opinion?

}
//=======================================================================

function testLimit(name, min, limit, gen) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some documentation, please.


<li>The maximum number of parameters to any function is 1000.</li>
<li>The maximum number of return types for any function is 1.</li>
<li>The maximum size of a function body, including locals declarations, is 7654321 bytes.</li>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that really the number you want to go with?

})
.catch(err => {
if (expected) {
let msg = `UNEXPECTED FAIL: ${name} == ${count} (${e})`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question about putting this in the same function.

});

// TODO(titzer): ugh, that's hard to test.
DISABLED.testLimit("module size", 1, kJSEmbeddingMaxModuleSize,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File an issue and remove this, please.

let type = builder.addType(kSig_v_v);
let nops = count-2;
let array = new Array(nops);
for (let i = 0; i < nops; i++) array[i] = kExprNop;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think array.fill() is probably well-supported enough, if you want.

Copy link
Collaborator

@littledan littledan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec text LGTM. I'll leave it to @titzer to decide whether he wants to fix the test issues that @Ms2ger identified in this PR or a follow-on one.

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we agreed that all tests need to be submitted directly to wpt; they can be added through either side.

@littledan
Copy link
Collaborator

This PR has very important spec text material, so I'm landing it; @Ms2ger , could you clean up the tests in a follow-on patch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants