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

Support start #182

Merged
merged 2 commits into from
Feb 5, 2016
Merged

Support start #182

merged 2 commits into from
Feb 5, 2016

Conversation

jfbastien
Copy link
Member

As spec'd in: WebAssembly/design#495
And discussed in: WebAssembly/spec#231

This will make it simpler and more uniform to add a start entry point.

s2wasm is the right place to add start because it'll eventually need to
do other basic setup, e.g. put code in start to setup the stack, as
@dschuff is doing in:
#179
Or rather, the linker is the right place and s2wasm happens to act as
our linker right now.

@jfbastien
Copy link
Member Author

@rossberg-chromium @binji it would be good for your parsers to support (start func).

@@ -696,7 +700,7 @@ class S2WasmBuilder {
Name target = cleanFunction(getCommaSeparated());
auto aliased = aliasedFunctions.find(target);
if (aliased != aliasedFunctions.end()) target = aliased->second;
if (implementedFunctions.count(target) > 0) {
if (implementedFunctions.count(target) != 0) {
Copy link
Member

Choose a reason for hiding this comment

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

why?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh extra change, I initially modified implementedFunctions and had to change all its uses, but then put it back. I didn't realize I'd changed it to something else (I was just restoring the old behavior), but it can only ever be 0 or 1 so != seems more natural?

Copy link
Member

Choose a reason for hiding this comment

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

Seems less natural to me, but whatever :)

@kripken
Copy link
Member

kripken commented Feb 4, 2016

We'll need a followup issue for the interpreter actually calling the start method. I assume the spec repo will get a test for that eventually.

As spec'd in: WebAssembly/design#495
And discussed in: WebAssembly/spec#231

This will make it simpler and more uniform to add a start entry point.

s2wasm is the right place to add start because it'll eventually need to
do other basic setup, e.g. put code in start to setup the stack, as
dschuff is doing in:
  #179
Or rather, the linker is the right place and s2wasm happens to act as
our linker right now.
jfbastien added a commit that referenced this pull request Feb 5, 2016
@jfbastien jfbastien merged commit 8f67b6e into master Feb 5, 2016
@jfbastien jfbastien deleted the start branch February 5, 2016 10:23
@jfbastien
Copy link
Member Author

Merged because timezones, let me know if you have any follow-up concerns that I should address.

@kripken
Copy link
Member

kripken commented Feb 5, 2016

As mentioned above, I actually don't even understand what this pull request does. Please explain when you get a chance.

@@ -1193,6 +1198,42 @@ class S2WasmBuilder {
}
}
}
if (!!startFunction) {
Copy link
Member

Choose a reason for hiding this comment

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

Why doesn't startFunction.is() work..?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because it refers to a string "\0" which isn't nullptr, whereas operator! checks for nullptr and str[0] == '\0'. It's not very idiomatic C++!

Copy link
Member

Choose a reason for hiding this comment

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

isn't startFunction null if not used? Then checking is() which checks the pointer is not null would be fine?

or are you saying startFunction has a valid pointer that points to an empty string?

Copy link
Member Author

Choose a reason for hiding this comment

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

startFunction is initialized with a std::string which makes it "\0" because Name passes that to IString's ctor. So yes, it's a valid zero-length string :-)

I much prefer idiomatic std::string, despite its shortcomings! Commoning strings is fine in some cases, but I'm not sure these tools really need it especially for such short strings which could just be inline. We could also use folly::string which is more configurable and closer to std::string. Also well tested, but I'm biased on that ;-)

Copy link
Member

Choose a reason for hiding this comment

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

But we use Name extensively, for performance reasons. I'd rather use Name for startFunction as well. Is there a reason not to?

Copy link
Member Author

Choose a reason for hiding this comment

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

String performance on large strings are a gain with the Name approach, but small strings usually win with the inline approach that most std::string implementations use. Names are usually small, so without measurements showing otherwise I'd just stick to std::string until we measure a perf issue. There's also the idiomatic argument: C++ APIs work a certain way, Name looks different and isn't obvious. This !! thing is an example of that.

I went with Name since the rest of the codebase does that, but the corners seem sharp from here!

Copy link
Member

Choose a reason for hiding this comment

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

I'm ok to change the API to make it more idiomatic if you want, let's discuss.

But in general I think Name is the right thing for the AST - we know it helps perf hugely there. And anything interfacing with that should be a Name or else we'll have constant weird mismatches of std::string here but Name there. That's what I want to avoid.

@jfbastien
Copy link
Member Author

As mentioned above, I actually don't even understand what this pull request does. Please explain when you get a chance.

You mean WebAssembly/design#495 isn't clear? Or the way this PR implements it isn't? I'm not sure what's unclear ;-)

@@ -1193,6 +1198,42 @@ class S2WasmBuilder {
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Let me try to be clearer. This line, and the big multiline change under it - lines 1201 to 1236 - are completely unclear to me. Why do they exist? What to they do?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, that's creating the _start function, creating enough locals to match main's (or rather, whatever startFunction says the function name is) expected arguments, and calling main with these arguments. It then exports _start and creates the (start $_start) entry.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, now I see.

Why is this in s2wasm? Should'nt the backend do this?

@kripken
Copy link
Member

kripken commented Feb 5, 2016

This seems confused to me. Maybe it's me that is confused. There is both a _start function, and a startFunction? Your code creates the former and makes it call the latter? And the former is marked as the wasm "start"?

That seems very convoluted to me. Why not just mark startFunction as the wasm "start"?

@kripken
Copy link
Member

kripken commented Feb 5, 2016

(I'm fine to iterate on this after the merge, but in the future, how about not merging while there are outstanding questions?)

@jfbastien
Copy link
Member Author

Sorry, I didn't realize your question was expressing concern, I thought you just wanted a follow-up :-)

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.

None yet

2 participants