Skip to content

Commit

Permalink
support for string slice
Browse files Browse the repository at this point in the history
  • Loading branch information
xunilrj committed Dec 2, 2024
1 parent 63da357 commit 6f3f3be
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 8 deletions.
4 changes: 0 additions & 4 deletions sway-core/src/language/ty/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@ impl TyProgram {
field.type_argument.type_id,
&field.type_argument,
|t| match t {
TypeInfo::StringSlice => {
Some(TypeNotAllowedReason::StringSliceInConfigurables)
}
TypeInfo::RawUntypedPtr => Some(
TypeNotAllowedReason::TypeNotAllowedInContractStorage {
ty: engines.help_out(t).to_string(),
Expand Down Expand Up @@ -396,7 +393,6 @@ impl TyProgram {
c.return_type,
&c.type_ascription,
|t| match t {
TypeInfo::StringSlice => Some(TypeNotAllowedReason::StringSliceInConfigurables),
TypeInfo::Slice(_) => Some(TypeNotAllowedReason::SliceInConst),
_ => None,
},
Expand Down
3 changes: 0 additions & 3 deletions sway-error/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2804,9 +2804,6 @@ pub enum TypeNotAllowedReason {
#[error("Returning `str` or a type containing `str` from `main()` is not allowed.")]
StringSliceInMainReturn,

#[error("`str` or a type containing `str` on `configurables` is not allowed.")]
StringSliceInConfigurables,

#[error("`str` or a type containing `str` on `const` is not allowed.")]
StringSliceInConst,

Expand Down
2 changes: 2 additions & 0 deletions sway-lib-core/src/codec.sw
Original file line number Diff line number Diff line change
Expand Up @@ -2522,6 +2522,7 @@ pub fn abi_decode_in_place<T>(ptr: raw_ptr, len: u64, target: raw_ptr)
where
T: AbiDecode,
{
asm(ptr: ptr) { log ptr ptr ptr ptr; }
let mut buffer = BufferReader::from_parts(ptr, len);
let temp = T::abi_decode(buffer);
asm(
Expand Down Expand Up @@ -2635,6 +2636,7 @@ impl AbiDecode for str {
fn abi_decode(ref mut buffer: BufferReader) -> str {
let len = buffer.read_8_bytes::<u64>();
let data = buffer.read_bytes(len);
asm(data: data, len: len, a: 0) { log data len a a; };
asm(s: (data.ptr(), len)) {
s: str
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ configurable {
TUPLE_BOOL_U64: (bool, u64) = (true, 11),
STR_4: str[4] = __to_str_array("abcd"),
VEC_U8: Vec<u8> = Vec::new(),
STRING_SLICE: str = "Hello, Sway",

// The test runner does not have a way to calculate the dynamic part of the data section
// This configurable guarantee that all the others have their buffer size calculated correctly.
Expand Down Expand Up @@ -73,6 +74,8 @@ fn main() {
assert(TUPLE_BOOL_U64.1 == 11);
assert(sha256_str_array(STR_4) == sha256("abcd"));
assert(VEC_U8.len() == 0);
//__log(STRING_SLICE);
//assert(sha256(STRING_SLICE) == sha256("Hello, Sway"));

// Assert address do not change
let addr_1 = asm(addr: __addr_of(&BOOL)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ category = "run"
expected_result = { action = "return", value = 0 }
expected_result_new_encoding = { action = "return_data", value = "" }
validate_abi = true
expected_warnings = 2
expected_warnings = 3
unsupported_profiles = ["debug"]

# check: $()ANOTHER_U8 8
Expand Down

0 comments on commit 6f3f3be

Please sign in to comment.