mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
Prefix string constants with REFCOUNT_MAX
This commit is contained in:
parent
c2a2ff2957
commit
22ccb6eca4
2 changed files with 14 additions and 7 deletions
|
@ -4,7 +4,7 @@ use code_builder::Align;
|
||||||
use roc_collections::all::MutMap;
|
use roc_collections::all::MutMap;
|
||||||
use roc_module::low_level::LowLevel;
|
use roc_module::low_level::LowLevel;
|
||||||
use roc_module::symbol::{Interns, Symbol};
|
use roc_module::symbol::{Interns, Symbol};
|
||||||
use roc_mono::gen_refcount::RefcountProcGenerator;
|
use roc_mono::gen_refcount::{RefcountProcGenerator, REFCOUNT_MAX};
|
||||||
use roc_mono::ir::{CallType, Expr, JoinPointId, Literal, Proc, Stmt};
|
use roc_mono::ir::{CallType, Expr, JoinPointId, Literal, Proc, Stmt};
|
||||||
use roc_mono::layout::{Builtin, Layout, LayoutIds};
|
use roc_mono::layout::{Builtin, Layout, LayoutIds};
|
||||||
|
|
||||||
|
@ -799,10 +799,13 @@ impl<'a> WasmBackend<'a> {
|
||||||
None => {
|
None => {
|
||||||
let const_segment_bytes = &mut self.module.data.segments[CONST_SEGMENT_INDEX].init;
|
let const_segment_bytes = &mut self.module.data.segments[CONST_SEGMENT_INDEX].init;
|
||||||
|
|
||||||
// Store the string in the data section, to be loaded on module instantiation
|
// Store the string in the data section
|
||||||
// RocStr `elements` field will point to that constant data, not the heap
|
// Prefix it with a special refcount value (treated as "infinity")
|
||||||
let segment_offset = const_segment_bytes.len() as u32;
|
// The string's `elements` field points at the data after the refcount
|
||||||
let elements_addr = segment_offset + CONST_SEGMENT_BASE_ADDR;
|
let refcount_max_bytes: [u8; 4] = (REFCOUNT_MAX as i32).to_le_bytes();
|
||||||
|
const_segment_bytes.extend_from_slice(&refcount_max_bytes);
|
||||||
|
let elements_offset = const_segment_bytes.len() as u32;
|
||||||
|
let elements_addr = elements_offset + CONST_SEGMENT_BASE_ADDR;
|
||||||
const_segment_bytes.extend_from_slice(string.as_bytes());
|
const_segment_bytes.extend_from_slice(string.as_bytes());
|
||||||
|
|
||||||
// Generate linker info
|
// Generate linker info
|
||||||
|
@ -815,7 +818,7 @@ impl<'a> WasmBackend<'a> {
|
||||||
flags: 0,
|
flags: 0,
|
||||||
name,
|
name,
|
||||||
segment_index: CONST_SEGMENT_INDEX as u32,
|
segment_index: CONST_SEGMENT_INDEX as u32,
|
||||||
segment_offset,
|
segment_offset: elements_offset,
|
||||||
size: string.len() as u32,
|
size: string.len() as u32,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,10 @@ const LAYOUT_UNIT: Layout = Layout::Struct(&[]);
|
||||||
const LAYOUT_PTR: Layout = Layout::RecursivePointer;
|
const LAYOUT_PTR: Layout = Layout::RecursivePointer;
|
||||||
const LAYOUT_U32: Layout = Layout::Builtin(Builtin::Int(IntWidth::U32));
|
const LAYOUT_U32: Layout = Layout::Builtin(Builtin::Int(IntWidth::U32));
|
||||||
|
|
||||||
|
/// "Infinite" reference count, for static values
|
||||||
|
/// Ref counts are encoded as negative numbers where isize::MIN represents 1
|
||||||
|
pub const REFCOUNT_MAX: usize = 0;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
pub enum RefcountOp {
|
pub enum RefcountOp {
|
||||||
Inc,
|
Inc,
|
||||||
|
@ -288,7 +292,7 @@ impl<'a> RefcountProcGenerator<'a> {
|
||||||
op: LowLevel::RefCountGetPtr,
|
op: LowLevel::RefCountGetPtr,
|
||||||
update_mode: UpdateModeId::BACKEND_DUMMY,
|
update_mode: UpdateModeId::BACKEND_DUMMY,
|
||||||
},
|
},
|
||||||
arguments: self.arena.alloc([string]),
|
arguments: self.arena.alloc([elements]),
|
||||||
});
|
});
|
||||||
let rc_ptr_stmt = |next| Stmt::Let(rc_ptr, rc_ptr_expr, LAYOUT_PTR, next);
|
let rc_ptr_stmt = |next| Stmt::Let(rc_ptr, rc_ptr_expr, LAYOUT_PTR, next);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue