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

Clarified that implicit return is allowed #407

Closed
wants to merge 1 commit into from

Conversation

Teemperor
Copy link
Member

Current spec doesn't specify what happens in non-void functions without any return.

ml-proto is already doing it as described in the paragraph: https://github.com/WebAssembly/spec/blob/master/ml-proto/test/f32.wast#L2

Current spec doesn't specify what happens in non-void functions without any return.

ml-proto is already doing it as described in the paragraph: https://github.com/WebAssembly/spec/blob/master/ml-proto/test/f32.wast#L2
@rossberg
Copy link
Member

This is just a consequence of being an expression language, so probably hinges on #223 being resolved.

@kg
Copy link
Contributor

kg commented Oct 13, 2015

If I don't end with a return, but my last expression has a type that doesn't match the return type of my function, do we detect that and reject it as an error?
Is it reasonable to do that analysis statically when loading/compiling a wasm module at runtime, since it's 'does the function ever invoke return along this path of execution'? You can certainly do it but I'm not sure how fast it would be.

It might be simpler to just obligate all non-void functions to have a 'last chance' return as their last expression, and prohibit jumping past it with break. Most code generators will produce it anyway and that constraint should be much easier to enforce.

@rossberg
Copy link
Member

If I don't end with a return, but my last expression has a type that
doesn't match the return type of my function, do we detect that and reject
it as an error?

Of course. Already the case.

Is it reasonable to do that analysis statically when loading/compiling a
wasm module at runtime, since it's 'does the function ever invoke return
along this path of execution'? You can certainly do it but I'm not sure how
fast it would be.

The function return type is explicit, so this check is completely trivial,
regardless of what returns a function uses. (In fact, it is simpler than
checking returns.)

@titzer
Copy link

titzer commented Oct 22, 2015

I agree with @rossberg-chromium; if we resolve #223 then this is a non-issue.

@Teemperor Teemperor closed this Oct 23, 2015
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.

4 participants