Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev backend: roc panic #5699

Merged
merged 25 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/windows_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ jobs:

# Why are these tests not build with previous command? => fingerprint error. Use `CARGO_LOG=cargo::core::compiler::fingerprint=info` to investigate
- name: Build specific tests without running. Twice for zig lld-link error.
run: cargo test --locked --release --no-run -p roc_ident -p roc_region -p roc_collections -p roc_can -p roc_types -p roc_solve -p roc_mono -p roc_gen_dev -p roc_gen_wasm -p roc_serialize -p roc_editor -p roc_linker -p roc_cli || cargo test --locked --release --no-run -p roc_ident -p roc_region -p roc_collections -p roc_can -p roc_types -p roc_solve -p roc_mono -p roc_gen_dev -p roc_gen_wasm -p roc_serialize -p roc_editor -p roc_linker -p roc_cli
run: cargo test --locked --release --no-run -p roc_ident -p roc_region -p roc_collections -p roc_can -p roc_types -p roc_solve -p roc_mono -p roc_gen_dev -p roc_gen_wasm -p roc_serialize -p roc_editor -p roc_linker -p roc_cli -p test_gen || cargo test --locked --release --no-run -p roc_ident -p roc_region -p roc_collections -p roc_can -p roc_types -p roc_solve -p roc_mono -p roc_gen_dev -p roc_gen_wasm -p roc_serialize -p roc_editor -p roc_linker -p roc_cli -p test_gen

- name: Test setjmp/longjmp logic
run: cargo test-gen-dev --locked --release nat_alias && cargo test-gen-dev --locked --release a_crash

- name: Actually run the tests.
run: cargo test --locked --release -p roc_ident -p roc_region -p roc_collections -p roc_can -p roc_types -p roc_solve -p roc_mono -p roc_gen_dev -p roc_gen_wasm -p roc_serialize -p roc_editor -p roc_linker -p roc_cli
run: cargo test --locked --release -p roc_ident -p roc_region -p roc_collections -p roc_can -p roc_types -p roc_solve -p roc_mono -p roc_gen_dev -p roc_gen_wasm -p roc_serialize -p roc_editor -p roc_linker -p roc_cli

24 changes: 23 additions & 1 deletion crates/compiler/gen_dev/src/generic64/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,18 @@ impl CallConv<AArch64GeneralReg, AArch64FloatReg, AArch64Assembler> for AArch64C
) {
todo!("Loading returned complex symbols for AArch64");
}

fn setjmp(_buf: &mut Vec<'_, u8>) {
todo!()
}

fn longjmp(_buf: &mut Vec<'_, u8>) {
todo!()
}

fn roc_panic(_buf: &mut Vec<'_, u8>, _relocs: &mut Vec<'_, Relocation>) {
todo!()
}
}

impl Assembler<AArch64GeneralReg, AArch64FloatReg> for AArch64Assembler {
Expand Down Expand Up @@ -529,7 +541,17 @@ impl Assembler<AArch64GeneralReg, AArch64FloatReg> for AArch64Assembler {
_fn_name: String,
_dst: AArch64GeneralReg,
) {
todo!("calling functions literal for AArch64");
todo!("function pointer for AArch64");
}

#[inline(always)]
fn data_pointer(
_buf: &mut Vec<'_, u8>,
_relocs: &mut Vec<'_, Relocation>,
_fn_name: String,
_dst: AArch64GeneralReg,
) {
todo!("data pointer for AArch64");
}

#[inline(always)]
Expand Down
71 changes: 70 additions & 1 deletion crates/compiler/gen_dev/src/generic64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ pub trait CallConv<GeneralReg: RegTrait, FloatReg: RegTrait, ASM: Assembler<Gene
sym: &Symbol,
layout: &InLayout<'a>,
);

fn setjmp(buf: &mut Vec<'_, u8>);
fn longjmp(buf: &mut Vec<'_, u8>);
fn roc_panic(buf: &mut Vec<'_, u8>, relocs: &mut Vec<'_, Relocation>);
}

pub enum CompareOperation {
Expand Down Expand Up @@ -238,6 +242,13 @@ pub trait Assembler<GeneralReg: RegTrait, FloatReg: RegTrait>: Sized + Copy {
dst: GeneralReg,
);

fn data_pointer(
buf: &mut Vec<'_, u8>,
relocs: &mut Vec<'_, Relocation>,
fn_name: String,
dst: GeneralReg,
);

/// Jumps by an offset of offset bytes unconditionally.
/// It should always generate the same number of bytes to enable replacement if offset changes.
/// It returns the base offset to calculate the jump from (generally the instruction after the jump).
Expand Down Expand Up @@ -714,6 +725,9 @@ impl<
fn interner(&self) -> &STLayoutInterner<'a> {
self.layout_interner
}
fn relocations_mut(&mut self) -> &mut Vec<'a, Relocation> {
&mut self.relocs
}
fn module_interns_helpers_mut(
&mut self,
) -> (
Expand Down Expand Up @@ -887,12 +901,47 @@ impl<
(out.into_bump_slice(), offset)
}

fn build_roc_setjmp(&mut self) -> &'a [u8] {
let mut out = bumpalo::vec![in self.env.arena];

CC::setjmp(&mut out);

out.into_bump_slice()
}

fn build_roc_longjmp(&mut self) -> &'a [u8] {
let mut out = bumpalo::vec![in self.env.arena];

CC::longjmp(&mut out);

out.into_bump_slice()
}

fn build_roc_panic(&mut self) -> (&'a [u8], Vec<'a, Relocation>) {
let mut out = bumpalo::vec![in self.env.arena];
let mut relocs = bumpalo::vec![in self.env.arena];

CC::roc_panic(&mut out, &mut relocs);

(out.into_bump_slice(), relocs)
}

fn build_fn_pointer(&mut self, dst: &Symbol, fn_name: String) {
let reg = self.storage_manager.claim_general_reg(&mut self.buf, dst);

ASM::function_pointer(&mut self.buf, &mut self.relocs, fn_name, reg)
}

fn build_data_pointer(&mut self, dst: &Symbol, data_name: String) {
let reg = self.storage_manager.claim_general_reg(&mut self.buf, dst);

// now, this gives a pointer to the value
ASM::data_pointer(&mut self.buf, &mut self.relocs, data_name, reg);

// dereference
ASM::mov_reg64_mem64_offset32(&mut self.buf, reg, reg, 0);
}

fn build_fn_call(
&mut self,
dst: &Symbol,
Expand Down Expand Up @@ -4215,7 +4264,18 @@ impl<
Builtin::Int(int_width) => match int_width {
IntWidth::I128 | IntWidth::U128 => {
// can we treat this as 2 u64's?
todo!()
storage_manager.with_tmp_general_reg(
buf,
|storage_manager, buf, tmp_reg| {
let base_offset = storage_manager.claim_stack_area(&dst, 16);

ASM::mov_reg64_mem64_offset32(buf, tmp_reg, ptr_reg, offset);
ASM::mov_base32_reg64(buf, base_offset, tmp_reg);

ASM::mov_reg64_mem64_offset32(buf, tmp_reg, ptr_reg, offset + 8);
ASM::mov_base32_reg64(buf, base_offset + 8, tmp_reg);
},
);
}
IntWidth::I64 | IntWidth::U64 => {
let dst_reg = storage_manager.claim_general_reg(buf, &dst);
Expand Down Expand Up @@ -4253,6 +4313,15 @@ impl<
}
Builtin::Decimal => {
// same as 128-bit integer
storage_manager.with_tmp_general_reg(buf, |storage_manager, buf, tmp_reg| {
let base_offset = storage_manager.claim_stack_area(&dst, 16);

ASM::mov_reg64_mem64_offset32(buf, tmp_reg, ptr_reg, offset);
ASM::mov_base32_reg64(buf, base_offset, tmp_reg);

ASM::mov_reg64_mem64_offset32(buf, tmp_reg, ptr_reg, offset + 8);
ASM::mov_base32_reg64(buf, base_offset + 8, tmp_reg);
});
}
Builtin::Str | Builtin::List(_) => {
storage_manager.with_tmp_general_reg(buf, |storage_manager, buf, tmp_reg| {
Expand Down
8 changes: 7 additions & 1 deletion crates/compiler/gen_dev/src/generic64/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,13 @@ impl<
}
}
}
Builtin::Decimal => todo!(),
Builtin::Decimal => {
let (from_offset, size) = self.stack_offset_and_size(sym);
debug_assert_eq!(from_offset % 8, 0);
debug_assert_eq!(size % 8, 0);
debug_assert_eq!(size, layout_interner.stack_size(*layout));
self.copy_to_stack_offset(buf, size, from_offset, to_offset)
}
Builtin::Str | Builtin::List(_) => {
let (from_offset, size) = self.stack_offset_and_size(sym);
debug_assert_eq!(size, layout_interner.stack_size(*layout));
Expand Down
Loading
Loading