higher alignment requirement on rocstr/roclist

This commit is contained in:
Folkert 2021-09-04 15:18:37 +02:00
parent 6beff62ece
commit 1d17a21d1f
3 changed files with 12 additions and 8 deletions

View file

@ -1150,8 +1150,8 @@ fn strToBytes(arg: RocStr) RocList {
} }
const FromUtf8Result = extern struct { const FromUtf8Result = extern struct {
byte_index: usize,
string: RocStr, string: RocStr,
byte_index: usize,
is_ok: bool, is_ok: bool,
problem_code: Utf8ByteProblem, problem_code: Utf8ByteProblem,
}; };

View file

@ -295,8 +295,8 @@ pub fn str_from_utf8_range<'a, 'ctx, 'env>(
let record_type = env.context.struct_type( let record_type = env.context.struct_type(
&[ &[
env.ptr_int().into(),
super::convert::zig_str_type(env).into(), super::convert::zig_str_type(env).into(),
env.ptr_int().into(),
env.context.bool_type().into(), env.context.bool_type().into(),
ctx.i8_type().into(), ctx.i8_type().into(),
], ],
@ -343,8 +343,8 @@ pub fn str_from_utf8<'a, 'ctx, 'env>(
let record_type = env.context.struct_type( let record_type = env.context.struct_type(
&[ &[
env.ptr_int().into(),
super::convert::zig_str_type(env).into(), super::convert::zig_str_type(env).into(),
env.ptr_int().into(),
env.context.bool_type().into(), env.context.bool_type().into(),
ctx.i8_type().into(), ctx.i8_type().into(),
], ],

View file

@ -1151,10 +1151,13 @@ impl<'a> Builtin<'a> {
Float64 => align_of::<f64>() as u32, Float64 => align_of::<f64>() as u32,
Float32 => align_of::<f32>() as u32, Float32 => align_of::<f32>() as u32,
Float16 => align_of::<i16>() as u32, Float16 => align_of::<i16>() as u32,
Str | EmptyStr => pointer_size,
Dict(_, _) | EmptyDict => pointer_size, Dict(_, _) | EmptyDict => pointer_size,
Set(_) | EmptySet => pointer_size, Set(_) | EmptySet => pointer_size,
List(_) | EmptyList => pointer_size, // we often treat these as i128 (64-bit systems)
// or i64 (32-bit systems). For that to be safe
// they must be aligned to allow such access
List(_) | EmptyList => 2 * pointer_size,
Str | EmptyStr => 2 * pointer_size,
} }
} }
@ -1240,9 +1243,10 @@ impl<'a> Builtin<'a> {
Builtin::Str => pointer_size, Builtin::Str => pointer_size,
Builtin::Dict(k, v) => k Builtin::Dict(k, v) => k
.alignment_bytes(pointer_size) .alignment_bytes(pointer_size)
.max(v.alignment_bytes(pointer_size)), .max(v.alignment_bytes(pointer_size))
Builtin::Set(k) => k.alignment_bytes(pointer_size), .max(pointer_size),
Builtin::List(e) => e.alignment_bytes(pointer_size), Builtin::Set(k) => k.alignment_bytes(pointer_size).max(pointer_size),
Builtin::List(e) => e.alignment_bytes(pointer_size).max(pointer_size),
Builtin::EmptyStr | Builtin::EmptyList | Builtin::EmptyDict | Builtin::EmptySet => { Builtin::EmptyStr | Builtin::EmptyList | Builtin::EmptyDict | Builtin::EmptySet => {
unreachable!("not heap-allocated") unreachable!("not heap-allocated")
} }