mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
Add sfe_to_memcpy
This commit is contained in:
parent
e7b391cd6b
commit
77bf2547ac
1 changed files with 27 additions and 0 deletions
|
@ -78,6 +78,22 @@ impl<'a> Layout<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn safe_to_memcpy(&self) -> bool {
|
||||
use Layout::*;
|
||||
|
||||
match self {
|
||||
Builtin(builtin) => builtin.safe_to_memcpy(),
|
||||
Struct(fields) => fields
|
||||
.iter()
|
||||
.all(|(_, field_layout)| field_layout.safe_to_memcpy()),
|
||||
Tag(tags) => tags.iter().all(|tag_layout| tag_layout.safe_to_memcpy()),
|
||||
FunctionPointer(_, _) => {
|
||||
// Function pointers are immutable and can always be safely copied
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stack_size(&self, pointer_size: u32) -> u32 {
|
||||
use Layout::*;
|
||||
|
||||
|
@ -138,6 +154,17 @@ impl<'a> Builtin<'a> {
|
|||
List(_) | EmptyList => Builtin::LIST_WORDS * pointer_size,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn safe_to_memcpy(&self) -> bool {
|
||||
use Builtin::*;
|
||||
|
||||
match self {
|
||||
Int64 | Float64 | Bool(_, _) | Byte(_) | EmptyStr | EmptyMap | EmptyList | EmptySet => {
|
||||
true
|
||||
}
|
||||
Str | Map(_, _) | Set(_) | List(_) => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue