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

Zero value for except_ref type? #55

Closed
aheejin opened this issue Mar 8, 2018 · 12 comments
Closed

Zero value for except_ref type? #55

aheejin opened this issue Mar 8, 2018 · 12 comments

Comments

@aheejin
Copy link
Member

aheejin commented Mar 8, 2018

The Local Variables section of Semantics in the design repo says

Local variables have value types and are initialized to the appropriate zero value for their type (0 for integers, +0. for floating-point) at the beginning of the function, except parameters which are initialized to the values of the arguments passed to the function.

Because except_ref type can be assigned to locals, we should have a zero value like nullref for except_ref type. Do we have it?

@rossberg
Copy link
Member

rossberg commented Mar 8, 2018

It's coming with the reference type proposal. However, the long-term idea is that (most) future reference types will not include null (see e.g. the section on function refs), and that we have to find ways to cope with that anyway. It would be natural to not include null in the exception thing either.

@eholk
Copy link
Contributor

eholk commented Mar 8, 2018

A reasonable 0 value for exceptions would be one where if_except always fails to match it.

I like the idea of going along with whatever the reference type proposal comes up with. @rossberg - if there is no null, what are reference variables going to be initialized with?

@rossberg
Copy link
Member

rossberg commented Mar 8, 2018

The most obvious solution would be that locals of non-defaultable types require an explicit initialiser.

@eholk
Copy link
Contributor

eholk commented Mar 8, 2018

Ah, right. Of course, that means we have to add initializers, but I think that makes sense. I imagine we'll want to add more types in the future where a default value doesn't make sense.

@dschuff
Copy link
Member

dschuff commented Mar 8, 2018

That just raises the question of "what is a reasonable explicit initializer for an except_ref?" There's currently no way to generate an except_ref value other than catching. So we'd still need an instruction we could put into an initializer.

@eholk
Copy link
Contributor

eholk commented Mar 8, 2018

Ah, good point. So it seems like no matter what we'll want a default value.

Another option is to make sure no variable is read before it's assigned to as part of the Wasm module's validation phase. This is potentially expensive, but I suspect it's easier given that Wasm has only structured control flow. I don't really think this is the best idea though.

If we add a 0 exception, what would rethrowing it mean?

@rossberg
Copy link
Member

rossberg commented Mar 8, 2018

The simpler alternative is to introduce variable definitions with tighter scope, i.e., something let-like. That avoids both null and complicated initialisation checks.

@eholk
Copy link
Contributor

eholk commented Mar 8, 2018

I think for exceptions, let would land us somewhere similar to the original rethrow problem (#30), since we want a way for exceptions to escape their catch scope. We'd have to write code like:

block $top:
  let e = try:
    ... do stuff ...
    break $top
  catch: 
    ... do other stuff, but leave exception ref on stack so it is used to initialize e ...
  end
  ... do exception handling stuff with e ...
end

@rossberg
Copy link
Member

rossberg commented Mar 8, 2018

You could also do it the other way around, because a branch out of the catch could take the ref as an arguments.

@aheejin
Copy link
Member Author

aheejin commented Dec 2, 2018

We don't have let yet anyway, and we need nullref for except_ref type locals in the current spec. The current reference-types spec has nullref, and can I assume we use that for except_ref type local's initial value?

@rossberg
Copy link
Member

rossberg commented Dec 3, 2018

Seems fine to allow null into the exception type as a stop-gap measure for now. But I would hope that we have something akin to let in time to restrict this before finalising this proposal. In particular, the same problem comes up with typed function refs, so we'll need a proper solution soon enough.

@aheejin
Copy link
Member Author

aheejin commented Dec 7, 2018

Closing this, at least we have nullref in the reference type proposal now.

@aheejin aheejin closed this as completed Dec 7, 2018
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

No branches or pull requests

4 participants