Merge*Type on their respective class (Type, Memory, ...)#81
Conversation
saulecabrera
left a comment
There was a problem hiding this comment.
I don't have objections on the approach. My main concern (before going over the change) was the overhead that this might introduce, but I'm happy to see that this change is pretty much re-using the validation machinery that was there before (.e.g FuncType). Also ruby-wise, this seems more natural.
|
Overall I think this is great! Makes the API much easier to work with. 🎉 With the caveat that I don't know WASM or the Rust Wasmtime library very well, here is some feedback on the API: Func
# ALT 1
func = Func.new(store, params: [:i32], results: [:i32]) { ... }
# ALT 2
func = Func.new(store, param_types: [:i32], result_types: [:i32]) { ... }GlobalMy understanding is that both a var and const would be instances of Global.var(store, :i32, 1).is_a?(Global) #=> true
Global.const(store, :i32, 1).is_a?(Global) #=> trueBuilding instances with something other than For me, any of these three alternatives would seem more intuitive: # ALT 1
global = Global.new(store, mutability: :var, type: :i32, value: 1)
global.var? # => true
global.const? # => false
global.type # => :i32
global.mutability # => :var
# ALT 2
global = Global.new(store, mutable: true, type: :i32, value: 1)
global.var? # => true
global.const? # => false
global.type # => :i32
global.mutable? # => true
# ALT 3
global = Global.new(store, :var, :i32, 1)
global.var? # => true
global.const? # => false
global.type # => :i32Which one is ideal depends a bit on whether there are more types of mutability that is anticipated in the future. In alt 1 and 2, one could make the mutability kwarg optional, for added convenience at the cost of less explicit code. Also, in both 1 and 2, one could potentially drop the One could also mix the three method signature alternatives above, for example Table
It seem to be |
|
@sandstrom Thanks for the feebdback!
I agree kwargs come with an added readability bonus. In a way, that'd match what WAT does (
That's correct. My rationale for that was to avoid the bool flag. I'm tempted to leave this one as is, particularly given it's easy to add
For that we'll stick with |
9d21213 to
b20fcda
Compare
b20fcda to
d24ee41
Compare
|
As far as design goes, I’m ok with a less vinegary interface given:
There definitely needs to be a more Ruby-ish interface all of this stuff, but the primary goal of this gem is to have a robust foundational layer for wasmtime in Ruby. The ergonomic interfaces will come later in other gems and will be much less of a headache to work with (👋 wit-bindgen-rb, wasmtime-ffi, and other awesome gems the community will write!). That all being said, I don’t think this PR goes against points 1 or 2 so I’m conceptual 👍🏻 on it. Just wanted to set clear expectations |
|
Thanks for chiming in Ian.
Couldn't agree more. That principle has been guiding the design of the gem. I think it's time I document the project goals in the README. |
This is a proposal to change the API to address @sandstrom's feedback in #13. The general ideal is to remove the
*Type(FuncType,MemoryType,GlobalType,TableType), collapsing their API surface on theFunc/Memory/ etc.This PR isn't polished (I need to review the docs and proof-read everything), but putting it out there to collect feedback on the idea.
API changes
FuncParams and results Array are now on
Func.new.FuncType#paramsandFuncType#resultsare moved onFunc.MemoryMin and max size are now on
Memory.newas kwargs (min_sizeis required,max_sizeis optional).MemoryType#minimumand#maximumare nowMemory#min_sizeand#max_size.I chose
minandmaxas it's shorter and is commonly used in Ruby (Array#min,#max,#minmax).GlobalMoved the
.constand.varconstructor fromGlobalTypetoGlobal. MovedGlobalType#contenttoGlobal#type-- unifying withTable(see below). Unlike Rust,typeisn't a reserved word in Ruby, and felt more appropriate thancontent.TableMoved type as as positional argument and min_size and max_size as kwarg on
Table.new. Moved allTableTypemethods toTable, using similar naming asMemory(min_size,max_size) andGlobal(type).