mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 07:41:12 +00:00
fix miscompilation for wasm
This commit is contained in:
parent
813b22a106
commit
988ab8775b
2 changed files with 10 additions and 11 deletions
|
@ -5,6 +5,7 @@ use core::convert::From;
|
||||||
use core::{fmt, mem, ptr, slice};
|
use core::{fmt, mem, ptr, slice};
|
||||||
use std::alloc::{alloc, dealloc, Layout};
|
use std::alloc::{alloc, dealloc, Layout};
|
||||||
use std::os::raw::c_char;
|
use std::os::raw::c_char;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
/// A string which can store identifiers using the small string optimization.
|
/// A string which can store identifiers using the small string optimization.
|
||||||
/// It relies on the invariant that it cannot store null characters to store
|
/// It relies on the invariant that it cannot store null characters to store
|
||||||
|
@ -102,13 +103,8 @@ impl IdentStr {
|
||||||
unsafe { mem::transmute::<[u8; mem::size_of::<Self>()], Self>(bytes) }
|
unsafe { mem::transmute::<[u8; mem::size_of::<Self>()], Self>(bytes) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_array_string(
|
#[allow(clippy::should_implement_trait)]
|
||||||
array_string: arrayvec::ArrayString<{ Self::SMALL_STR_BYTES }>,
|
pub fn from_str(str: &str) -> Self {
|
||||||
) -> Self {
|
|
||||||
Self::small_str_from_bytes(array_string.as_bytes())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn from_str(str: &str) -> Self {
|
|
||||||
let slice = str.as_bytes();
|
let slice = str.as_bytes();
|
||||||
let len = slice.len();
|
let len = slice.len();
|
||||||
|
|
||||||
|
|
|
@ -636,12 +636,15 @@ impl IdentIds {
|
||||||
pub fn gen_unique(&mut self) -> IdentId {
|
pub fn gen_unique(&mut self) -> IdentId {
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
let mut temp: arrayvec::ArrayString<15> = arrayvec::ArrayString::new();
|
let index: u32 = self.next_generated_name;
|
||||||
write!(temp, "{}", self.next_generated_name).unwrap();
|
|
||||||
let ident = Ident(IdentStr::from_array_string(temp));
|
|
||||||
|
|
||||||
self.next_generated_name += 1;
|
self.next_generated_name += 1;
|
||||||
|
|
||||||
|
// "4294967296" is 10 characters
|
||||||
|
let mut buffer: arrayvec::ArrayString<10> = arrayvec::ArrayString::new();
|
||||||
|
|
||||||
|
write!(buffer, "{}", index).unwrap();
|
||||||
|
let ident = Ident(IdentStr::from_str(buffer.as_str()));
|
||||||
|
|
||||||
self.add(ident)
|
self.add(ident)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue