mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Merge branch 'main' of github.com:roc-lang/roc into glue-getters-rtfeldman
This commit is contained in:
commit
f1b1aa6a7b
72 changed files with 2496 additions and 1853 deletions
|
@ -3493,6 +3493,53 @@ fn reserve_unchanged() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn release_excess_capacity() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
List.reserve [] 15
|
||||
|> List.releaseExcessCapacity
|
||||
"#
|
||||
),
|
||||
(0, RocList::empty()),
|
||||
RocList<u64>,
|
||||
|value: RocList<u64>| (value.capacity(), value)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn release_excess_capacity_with_len() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
List.reserve [1] 50
|
||||
|> List.releaseExcessCapacity
|
||||
"#
|
||||
),
|
||||
(1, RocList::from_slice(&[1])),
|
||||
RocList<u64>,
|
||||
|value: RocList<u64>| (value.capacity(), value)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn release_excess_capacity_empty() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
List.releaseExcessCapacity []
|
||||
"#
|
||||
),
|
||||
(0, RocList::empty()),
|
||||
RocList<u64>,
|
||||
|value: RocList<u64>| (value.capacity(), value)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn call_function_in_empty_list() {
|
||||
|
|
|
@ -2035,3 +2035,51 @@ fn destructure_pattern_assigned_from_thunk_tag() {
|
|||
RocStr
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn release_excess_capacity() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.reserve "" 50
|
||||
|> Str.releaseExcessCapacity
|
||||
"#
|
||||
),
|
||||
(RocStr::empty().capacity(), RocStr::empty()),
|
||||
RocStr,
|
||||
|value: RocStr| (value.capacity(), value)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn release_excess_capacity_with_len() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
"123456789012345678901234567890"
|
||||
|> Str.reserve 50
|
||||
|> Str.releaseExcessCapacity
|
||||
"#
|
||||
),
|
||||
(30, "123456789012345678901234567890".into()),
|
||||
RocStr,
|
||||
|value: RocStr| (value.capacity(), value)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn release_excess_capacity_empty() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Str.releaseExcessCapacity ""
|
||||
"#
|
||||
),
|
||||
(RocStr::empty().capacity(), RocStr::empty()),
|
||||
RocStr,
|
||||
|value: RocStr| (value.capacity(), value)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -60,7 +60,10 @@ impl FromWasm32Memory for RocStr {
|
|||
let str_words: &[u32; 3] = unsafe { std::mem::transmute(&str_bytes) };
|
||||
|
||||
let big_elem_ptr = str_words[Builtin::WRAPPER_PTR as usize] as usize;
|
||||
let big_length = str_words[Builtin::WRAPPER_LEN as usize] as usize;
|
||||
// If the str is a seamless slice, it's highest bit will be set to 1.
|
||||
// We need to remove that bit or we will get an incorrect negative length.
|
||||
// Since wasm length is 32bits, and with i32::MAX (0 followed by all 1s in 32 bit).
|
||||
let big_length = str_words[Builtin::WRAPPER_LEN as usize] as usize & (i32::MAX as usize);
|
||||
let big_capacity = str_words[Builtin::WRAPPER_CAPACITY as usize] as usize;
|
||||
|
||||
let last_byte = str_bytes[11];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue