#i128 to RawVal

48 messages · Page 1 of 1 (latest)

lone kindle
#

it seems like with BigInt migration we've missed some conversion helpers and I no longer seem to be able to do something like (&i128_var,).into_val(&e) to create a Vec<RawVal>. can we bring this back? cc @tacit minnow
all the conversions are there, I just had an error elsewhere

tacit minnow
#

👍🏻 Please add any missing conversions.

#

I doubt any gaps are intentional.

lone kindle
#

ok, I'm just still not quite comfortable with all the conversions (feels like we have too many...), so I wanted to check if there is something preventing us from adding this

tacit minnow
#

Does try_into_val work? If so we're probably just missing the into_val equiv.

lone kindle
#

nope

tacit minnow
lone kindle
#

I mean, it works for i128 itself, but not for tuple->vec conversion nvm, that's for the literal

tacit minnow
#

If you look just north of that line, you'll see the u64 conversions.

#

And just south of that line is the 128 conversions having Object but not RawVal.

lone kindle
#

ok

tacit minnow
#

I'm not actually sure why we have the object conversions, we don't normally bother with them.

#

They don't do any harm though.

lone kindle
#

that's what I'm talking about 🙂

#

I think we could benefit from removing some conversions and replacing some of the stuff that is conversion now with named methods

tacit minnow
#

Graydon has a WIP removing some conversion traits.

lone kindle
#

(we sometimes have both, like to_raw() and into() for RawVal etc)

#

nice

#

hmm, I'm still a bit confused. what is i128 in the contract context?

#

it seems like it's the Rust value

#

do we do ScVal->Object->rust i128 trip?

#

i.e. do we create a redundant object in host?

tacit minnow
#

Object is a u60 handle.

lone kindle
#

right, but i128 doesn't fit into RawVal, right?

#

so it has to be an Object. but from the contract interface standpoint we pass the rust i128 type as an argument, which is not an Object

#

actually the same is already true for u64... I'm just trying to understand if we create objects for the contract invocation arguments that are rust integer types

tacit minnow
#

Every value is converted to/from a RawVal at the boundaries of a contract.

lone kindle
#

so we create redundant objects, right? they're not accessible from the contract itself

tacit minnow
#

What is a redundant object?

lone kindle
#

when we invoke a contract we create an object in host for u64/i128 etc. but the contract itself operates on the rust type, i.e. IIUC it would compile the respective integer operations in WASM. there is no access to the object that has been created in host in the first place

#

that's probably not a big deal, just trying to understand the data flow

tacit minnow
#

there is no access to the object that has been created in host in the first place
What do you mean by this?

#

It might be worth sharing an annotated example.

lone kindle
#

is i128 in the contract interface an object or just a rust value?

#

IIUC it's not an object, hence there is no access to the original host object created during the contract invocation

#

hence the object is redundant

#

the only way to go from i128 back to the RawVal/Object etc. is to create a new host object

tacit minnow
#

The contract when invoked receives RawVals, and it converts them into the native Rust types.

#

The contractimpl macro wraps the function the developer writes in an exported function that receives the same number of arguments, but with type RawVal.

lone kindle
#

indeed. the point is that the majority of object types hold the original host object references (bytes, vec, map etc), while integer types don't. I don't think that's a big deal, it just makes the conversions a bit more confusing

#

hmm, actually the conversions are there, just defined with macro

tacit minnow
#

All values need converting. Some require host functions for the conversion, others do not. But all need converting.

#

Oh, I guess except Symbol. We never convert them, but they do get validated as part of their "conversion".

#

The same is true of handle types that stay in an obj. Bytes for example, no conversion actually happens, then handle is just validated (locally only) and moved into a type.

lone kindle
#

ok, I'm dumb. the conversions are in place, I just was trying to pass Vec to a method that expects &Vec 🤦‍♂️

tacit minnow
#

Interesting. I wonder where the conversions are then. I only see the conversions to and from Object, but that isn't sufficient.

#

Oh, they're immediately below. Graydon created macros for them, and my eyes were glossing over the macros.

lone kindle
#

decl_int128_conversions