-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Correct handling string return values #1292
Conversation
@@ -20,7 +20,7 @@ fn main() -> bool { | |||
assert(!is_reference_type::<byte>()); | |||
assert(!is_reference_type::<u64>()); | |||
|
|||
assert(is_reference_type::<str[1]>()); | |||
assert(!is_reference_type::<str[1]>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go with this, then we should probably make it clear, in the language, that types that "fit in a word" are always copy types. That includes things like str[1]
, struct { u64 }
, struct { struct { u64 } }
, array[1]
, and so on. It is a bit weird, but I think this would make the specs a bit simpler where the optimization that we've been talking about is actually baked in the language and has to happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right. We'd absolutely need regression tests to enforce it for all our types too.
@@ -20,7 +20,7 @@ fn main() -> bool { | |||
assert(!is_reference_type::<byte>()); | |||
assert(!is_reference_type::<u64>()); | |||
|
|||
assert(is_reference_type::<str[1]>()); | |||
assert(!is_reference_type::<str[1]>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right. We'd absolutely need regression tests to enforce it for all our types too.
Two things:
String
.Strings
of size 1 word or less as copy types. We might have to do the same for structs and other complex types when they're small enough to fit in registers.The following contract, for example, now returns the correct receipts and can be tested from the SDK.
The SDK has a test similar to the above that should be re-enabled (cc @digorithm). For now, I can't really check this from a script because I can't check what was returned from the contract call against a literal
String
using anassert
. Relevant: #1291