mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
Use roc_target over target_lexicon
Tailors a target class for our needs. Replaces tons of uses across the entire compiler. This is a base for later adding new targets like thumb.
This commit is contained in:
parent
185262510c
commit
6dc5bfb1b7
72 changed files with 1008 additions and 1371 deletions
|
@ -1,4 +1,4 @@
|
|||
use roc_target::TargetInfo;
|
||||
use roc_target::Target;
|
||||
|
||||
use super::{InLayout, LayoutRepr, UnionLayout};
|
||||
|
||||
|
@ -27,16 +27,16 @@ impl Erased {
|
|||
false
|
||||
}
|
||||
|
||||
pub fn stack_size_without_alignment(&self, target_info: TargetInfo) -> u32 {
|
||||
(target_info.ptr_width() as u32) * 3
|
||||
pub fn stack_size_without_alignment(&self, target: Target) -> u32 {
|
||||
(target.ptr_width() as u32) * 3
|
||||
}
|
||||
|
||||
pub fn alignment_bytes(&self, target_info: TargetInfo) -> u32 {
|
||||
target_info.ptr_width() as u32
|
||||
pub fn alignment_bytes(&self, target: Target) -> u32 {
|
||||
target.ptr_width() as u32
|
||||
}
|
||||
|
||||
pub fn allocation_alignment_bytes(&self, target_info: TargetInfo) -> u32 {
|
||||
target_info.ptr_width() as u32
|
||||
pub fn allocation_alignment_bytes(&self, target: Target) -> u32 {
|
||||
target.ptr_width() as u32
|
||||
}
|
||||
|
||||
pub fn is_refcounted(&self) -> bool {
|
||||
|
|
|
@ -10,7 +10,7 @@ use parking_lot::{Mutex, RwLock};
|
|||
use roc_builtins::bitcode::{FloatWidth, IntWidth};
|
||||
use roc_collections::{default_hasher, BumpMap};
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_target::TargetInfo;
|
||||
use roc_target::Target;
|
||||
|
||||
use crate::layout::LayoutRepr;
|
||||
|
||||
|
@ -208,7 +208,7 @@ pub trait LayoutInterner<'a>: Sized {
|
|||
self.get_repr(a) == self.get_repr(b)
|
||||
}
|
||||
|
||||
fn target_info(&self) -> TargetInfo;
|
||||
fn target(&self) -> Target;
|
||||
|
||||
fn alignment_bytes(&self, layout: InLayout<'a>) -> u32 {
|
||||
self.get_repr(layout).alignment_bytes(self)
|
||||
|
@ -545,7 +545,7 @@ struct GlobalLayoutInternerInner<'a> {
|
|||
map: Mutex<BumpMap<Layout<'a>, InLayout<'a>>>,
|
||||
normalized_lambda_set_map: Mutex<BumpMap<LambdaSet<'a>, LambdaSet<'a>>>,
|
||||
vec: RwLock<Vec<Layout<'a>>>,
|
||||
target_info: TargetInfo,
|
||||
target: Target,
|
||||
}
|
||||
|
||||
/// A derivative of a [GlobalLayoutInterner] interner that provides caching desirable for
|
||||
|
@ -564,7 +564,7 @@ pub struct TLLayoutInterner<'a> {
|
|||
normalized_lambda_set_map: BumpMap<LambdaSet<'a>, LambdaSet<'a>>,
|
||||
/// Cache of interned values from the parent for local access.
|
||||
vec: RefCell<Vec<Option<Layout<'a>>>>,
|
||||
target_info: TargetInfo,
|
||||
target: Target,
|
||||
}
|
||||
|
||||
/// A single-threaded interner, with no concurrency properties.
|
||||
|
@ -576,7 +576,7 @@ pub struct STLayoutInterner<'a> {
|
|||
map: BumpMap<Layout<'a>, InLayout<'a>>,
|
||||
normalized_lambda_set_map: BumpMap<LambdaSet<'a>, LambdaSet<'a>>,
|
||||
vec: Vec<Layout<'a>>,
|
||||
target_info: TargetInfo,
|
||||
target: Target,
|
||||
}
|
||||
|
||||
/// Interner constructed with an exclusive lock over [GlobalLayoutInterner]
|
||||
|
@ -584,7 +584,7 @@ struct LockedGlobalInterner<'a, 'r> {
|
|||
map: &'r mut BumpMap<Layout<'a>, InLayout<'a>>,
|
||||
normalized_lambda_set_map: &'r mut BumpMap<LambdaSet<'a>, LambdaSet<'a>>,
|
||||
vec: &'r mut Vec<Layout<'a>>,
|
||||
target_info: TargetInfo,
|
||||
target: Target,
|
||||
}
|
||||
|
||||
/// Generic hasher for a value, to be used by all interners.
|
||||
|
@ -614,8 +614,8 @@ fn make_normalized_lamdba_set<'a>(
|
|||
|
||||
impl<'a> GlobalLayoutInterner<'a> {
|
||||
/// Creates a new global interner with the given capacity.
|
||||
pub fn with_capacity(cap: usize, target_info: TargetInfo) -> Self {
|
||||
STLayoutInterner::with_capacity(cap, target_info).into_global()
|
||||
pub fn with_capacity(cap: usize, target: Target) -> Self {
|
||||
STLayoutInterner::with_capacity(cap, target).into_global()
|
||||
}
|
||||
|
||||
/// Creates a derivative [TLLayoutInterner] pointing back to this global interner.
|
||||
|
@ -625,7 +625,7 @@ impl<'a> GlobalLayoutInterner<'a> {
|
|||
map: Default::default(),
|
||||
normalized_lambda_set_map: Default::default(),
|
||||
vec: Default::default(),
|
||||
target_info: self.0.target_info,
|
||||
target: self.0.target,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -637,7 +637,7 @@ impl<'a> GlobalLayoutInterner<'a> {
|
|||
map,
|
||||
normalized_lambda_set_map,
|
||||
vec,
|
||||
target_info,
|
||||
target,
|
||||
} = match Arc::try_unwrap(self.0) {
|
||||
Ok(inner) => inner,
|
||||
Err(li) => return Err(Self(li)),
|
||||
|
@ -649,7 +649,7 @@ impl<'a> GlobalLayoutInterner<'a> {
|
|||
map,
|
||||
normalized_lambda_set_map,
|
||||
vec,
|
||||
target_info,
|
||||
target,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -703,7 +703,7 @@ impl<'a> GlobalLayoutInterner<'a> {
|
|||
map: &mut map,
|
||||
normalized_lambda_set_map: &mut normalized_lambda_set_map,
|
||||
vec: &mut vec,
|
||||
target_info: self.0.target_info,
|
||||
target: self.0.target,
|
||||
};
|
||||
reify::reify_lambda_set_captures(arena, &mut interner, slot, normalized.set)
|
||||
} else {
|
||||
|
@ -765,7 +765,7 @@ impl<'a> GlobalLayoutInterner<'a> {
|
|||
map: &mut map,
|
||||
normalized_lambda_set_map: &mut normalized_lambda_set_map,
|
||||
vec: &mut vec,
|
||||
target_info: self.0.target_info,
|
||||
target: self.0.target,
|
||||
};
|
||||
let full_layout = reify::reify_recursive_layout(arena, &mut interner, slot, normalized);
|
||||
|
||||
|
@ -927,19 +927,19 @@ impl<'a> LayoutInterner<'a> for TLLayoutInterner<'a> {
|
|||
value
|
||||
}
|
||||
|
||||
fn target_info(&self) -> TargetInfo {
|
||||
self.target_info
|
||||
fn target(&self) -> Target {
|
||||
self.target
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> STLayoutInterner<'a> {
|
||||
/// Creates a new single threaded interner with the given capacity.
|
||||
pub fn with_capacity(cap: usize, target_info: TargetInfo) -> Self {
|
||||
pub fn with_capacity(cap: usize, target: Target) -> Self {
|
||||
let mut interner = Self {
|
||||
map: BumpMap::with_capacity_and_hasher(cap, default_hasher()),
|
||||
normalized_lambda_set_map: BumpMap::with_capacity_and_hasher(cap, default_hasher()),
|
||||
vec: Vec::with_capacity(cap),
|
||||
target_info,
|
||||
target,
|
||||
};
|
||||
fill_reserved_layouts(&mut interner);
|
||||
interner
|
||||
|
@ -954,13 +954,13 @@ impl<'a> STLayoutInterner<'a> {
|
|||
map,
|
||||
normalized_lambda_set_map,
|
||||
vec,
|
||||
target_info,
|
||||
target,
|
||||
} = self;
|
||||
GlobalLayoutInterner(Arc::new(GlobalLayoutInternerInner {
|
||||
map: Mutex::new(map),
|
||||
normalized_lambda_set_map: Mutex::new(normalized_lambda_set_map),
|
||||
vec: RwLock::new(vec),
|
||||
target_info,
|
||||
target,
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -1072,8 +1072,8 @@ macro_rules! st_impl {
|
|||
self.vec[index]
|
||||
}
|
||||
|
||||
fn target_info(&self) -> TargetInfo {
|
||||
self.target_info
|
||||
fn target(&self) -> Target{
|
||||
self.target
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1758,13 +1758,13 @@ pub mod dbg_stable {
|
|||
mod insert_lambda_set {
|
||||
use bumpalo::Bump;
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_target::TargetInfo;
|
||||
use roc_target::Target;
|
||||
|
||||
use crate::layout::{LambdaSet, Layout, LayoutRepr, SemanticRepr};
|
||||
|
||||
use super::{GlobalLayoutInterner, InLayout, LayoutInterner, NeedsRecursionPointerFixup};
|
||||
|
||||
const TARGET_INFO: TargetInfo = TargetInfo::default_x86_64();
|
||||
const TARGET: Target = Target::LinuxX64;
|
||||
const TEST_SET: &&[(Symbol, &[InLayout])] =
|
||||
&(&[(Symbol::ATTR_ATTR, &[Layout::UNIT] as &[_])] as &[_]);
|
||||
const TEST_ARGS: &&[InLayout] = &(&[Layout::UNIT] as &[_]);
|
||||
|
@ -1776,7 +1776,7 @@ mod insert_lambda_set {
|
|||
fn two_threads_write() {
|
||||
for _ in 0..100 {
|
||||
let mut arenas: Vec<_> = std::iter::repeat_with(Bump::new).take(10).collect();
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET_INFO);
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET);
|
||||
let set = TEST_SET;
|
||||
let repr = Layout::UNIT;
|
||||
std::thread::scope(|s| {
|
||||
|
@ -1797,7 +1797,7 @@ mod insert_lambda_set {
|
|||
#[test]
|
||||
fn insert_then_reintern() {
|
||||
let arena = &Bump::new();
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET_INFO);
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET);
|
||||
let mut interner = global.fork();
|
||||
|
||||
let lambda_set =
|
||||
|
@ -1812,7 +1812,7 @@ mod insert_lambda_set {
|
|||
#[test]
|
||||
fn write_global_then_single_threaded() {
|
||||
let arena = &Bump::new();
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET_INFO);
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET);
|
||||
let set = TEST_SET;
|
||||
let repr = Layout::UNIT;
|
||||
|
||||
|
@ -1832,7 +1832,7 @@ mod insert_lambda_set {
|
|||
#[test]
|
||||
fn write_single_threaded_then_global() {
|
||||
let arena = &Bump::new();
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET_INFO);
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET);
|
||||
let mut st_interner = global.unwrap().unwrap();
|
||||
|
||||
let set = TEST_SET;
|
||||
|
@ -1852,13 +1852,13 @@ mod insert_lambda_set {
|
|||
#[cfg(test)]
|
||||
mod insert_recursive_layout {
|
||||
use bumpalo::Bump;
|
||||
use roc_target::TargetInfo;
|
||||
use roc_target::Target;
|
||||
|
||||
use crate::layout::{Builtin, InLayout, Layout, LayoutRepr, SemanticRepr, UnionLayout};
|
||||
|
||||
use super::{GlobalLayoutInterner, LayoutInterner};
|
||||
|
||||
const TARGET_INFO: TargetInfo = TargetInfo::default_x86_64();
|
||||
const TARGET: Target = Target::LinuxX64;
|
||||
|
||||
fn make_layout<'a>(arena: &'a Bump, interner: &mut impl LayoutInterner<'a>) -> Layout<'a> {
|
||||
let list_rec = Layout {
|
||||
|
@ -1905,7 +1905,7 @@ mod insert_recursive_layout {
|
|||
#[test]
|
||||
fn write_two_threads() {
|
||||
let arena = &Bump::new();
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET_INFO);
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET);
|
||||
let layout = {
|
||||
let mut interner = global.fork();
|
||||
make_layout(arena, &mut interner)
|
||||
|
@ -1927,7 +1927,7 @@ mod insert_recursive_layout {
|
|||
#[test]
|
||||
fn write_twice_thread_local_single_thread() {
|
||||
let arena = &Bump::new();
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET_INFO);
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET);
|
||||
let mut interner = global.fork();
|
||||
let layout = make_layout(arena, &mut interner);
|
||||
|
||||
|
@ -1943,7 +1943,7 @@ mod insert_recursive_layout {
|
|||
#[test]
|
||||
fn write_twice_single_thread() {
|
||||
let arena = &Bump::new();
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET_INFO);
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET);
|
||||
let mut interner = GlobalLayoutInterner::unwrap(global).unwrap();
|
||||
let layout = make_layout(arena, &mut interner);
|
||||
|
||||
|
@ -1960,7 +1960,7 @@ mod insert_recursive_layout {
|
|||
fn many_threads_read_write() {
|
||||
for _ in 0..100 {
|
||||
let mut arenas: Vec<_> = std::iter::repeat_with(Bump::new).take(10).collect();
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET_INFO);
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET);
|
||||
std::thread::scope(|s| {
|
||||
let mut handles = Vec::with_capacity(10);
|
||||
for arena in arenas.iter_mut() {
|
||||
|
@ -1983,7 +1983,7 @@ mod insert_recursive_layout {
|
|||
#[test]
|
||||
fn insert_then_reintern() {
|
||||
let arena = &Bump::new();
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET_INFO);
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET);
|
||||
let mut interner = global.fork();
|
||||
|
||||
let layout = make_layout(arena, &mut interner);
|
||||
|
@ -1996,7 +1996,7 @@ mod insert_recursive_layout {
|
|||
#[test]
|
||||
fn write_global_then_single_threaded() {
|
||||
let arena = &Bump::new();
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET_INFO);
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET);
|
||||
let layout = {
|
||||
let mut interner = global.fork();
|
||||
make_layout(arena, &mut interner)
|
||||
|
@ -2018,7 +2018,7 @@ mod insert_recursive_layout {
|
|||
#[test]
|
||||
fn write_single_threaded_then_global() {
|
||||
let arena = &Bump::new();
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET_INFO);
|
||||
let global = GlobalLayoutInterner::with_capacity(2, TARGET);
|
||||
let mut st_interner = global.unwrap().unwrap();
|
||||
|
||||
let layout = make_layout(arena, &mut st_interner);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue