| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
String slices (#4996) ## Description This PR introduces `string slices`. The basic usage is at `test/src/ir_generation/tests/str_slice.sw`: ```sway let a: str = "ABC"; ``` Before this PR `a` would be of type `str[3]`, a string array. Now both `string slices` and `string arrays` exist. This PR contains a new intrinsic that converts from string literals to arrays. ```sway let a: str = "ABC"; let b: str[3] = __to_str_array("ABC"); ``` Runtime conversions can be done using ```sway let a = "abcd"; let b: str[4] = a.try_as_str_array().unwrap(); let c = from_str_array(b); ``` string slices to string arrays can fail, so they return `Option<str[N]>`; and because of this `try_as_str_array` lives in `std`. The inverse, `from_str_array` only fails if `alloc` fails and lives in `core`. At this PR `string slices` are forbidden at `configurable`, `storage`, `const`, and main arguments and returns. The reason for these limitations is the internal structure of `string slices` having a `ptr`. The optimized IR for initializing the slice is: ``` v0 = const string<3> "abc" v1 = ptr_to_int v0 to u64, !2 v2 = get_local ptr { u64, u64 }, __anon_0, !2 v3 = const u64 0 v4 = get_elem_ptr v2, ptr u64, v3 store v1 to v4, !2 v5 = const u64 1 v6 = get_elem_ptr v2, ptr u64, v5 v7 = const u64 3 store v7 to v6, !2 v8 = get_local ptr slice, __anon_1, !2 mem_copy_bytes v8, v2, 16 ``` ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. | 2 年前 | |
Merge std and core libraries (#6729) ## Description Merges the two libraries. They were initially separate to separate the core logic and fuel vm specific functionality, but that separation is no longer maintained so having a merged library is better. Closes #6708 ## Checklist - [ ] I have linked to any relevant issues. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [ ] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [ ] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: Sophie <47993817+sdankel@users.noreply.github.com> Co-authored-by: Igor Rončević <ironcev@hotmail.com> | 1 年前 |