forked from AbleOS/ableos
fixing inlining related bugs
This commit is contained in:
parent
e221a28a46
commit
a023e29d51
|
@ -626,3 +626,40 @@ min := fn(a: int, b: int): int {
|
||||||
return b + (c & c >> SHIFT)
|
return b + (c & c >> SHIFT)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### inline_test
|
||||||
|
```hb
|
||||||
|
Point := struct {x: int, y: int}
|
||||||
|
Buffer := struct {}
|
||||||
|
ColorBGRA := Point
|
||||||
|
|
||||||
|
line := fn(buffer: Buffer, p0: Point, p1: Point, color: ColorBGRA, thickness: int): void {
|
||||||
|
if true {
|
||||||
|
if p0.x > p1.x {
|
||||||
|
@inline(line_low, buffer, p1, p0, color)
|
||||||
|
} else {
|
||||||
|
@inline(line_low, buffer, p0, p1, color)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if p0.y > p1.y {
|
||||||
|
@inline(line_high, buffer, p1, p0, color)
|
||||||
|
} else {
|
||||||
|
@inline(line_high, buffer, p0, p1, color)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
line_low := fn(buffer: Buffer, p0: Point, p1: Point, color: ColorBGRA): void {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
line_high := fn(buffer: Buffer, p0: Point, p1: Point, color: ColorBGRA): void {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
main := fn(): int {
|
||||||
|
line(.(), .(0, 0), .(0, 0), .(0, 0), 10)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
|
@ -637,7 +637,7 @@ impl Loc {
|
||||||
fn get_reg(&self) -> reg::Id {
|
fn get_reg(&self) -> reg::Id {
|
||||||
match self {
|
match self {
|
||||||
Self::Rt { reg, .. } => reg.as_ref(),
|
Self::Rt { reg, .. } => reg.as_ref(),
|
||||||
_ => unreachable!(),
|
_ => reg::Id::from(0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -744,6 +744,7 @@ struct ItemCtx {
|
||||||
id: ty::Kind,
|
id: ty::Kind,
|
||||||
ret: Option<ty::Id>,
|
ret: Option<ty::Id>,
|
||||||
ret_reg: reg::Id,
|
ret_reg: reg::Id,
|
||||||
|
inline_ret_loc: Loc,
|
||||||
|
|
||||||
task_base: usize,
|
task_base: usize,
|
||||||
snap: Snapshot,
|
snap: Snapshot,
|
||||||
|
@ -1535,17 +1536,17 @@ impl Codegen {
|
||||||
|
|
||||||
let ret_reloc_base = self.ci.ret_relocs.len();
|
let ret_reloc_base = self.ci.ret_relocs.len();
|
||||||
|
|
||||||
let loc = self.alloc_ret(sig.ret, ctx, false);
|
let loc = self.alloc_ret(sig.ret, ctx, true);
|
||||||
let prev_ret_reg = std::mem::replace(&mut self.ci.ret_reg, loc.get_reg());
|
let prev_ret_reg = std::mem::replace(&mut self.ci.inline_ret_loc, loc);
|
||||||
self.expr(body);
|
self.expr(body);
|
||||||
self.ci.ret_reg = prev_ret_reg;
|
let loc = std::mem::replace(&mut self.ci.inline_ret_loc, prev_ret_reg);
|
||||||
|
|
||||||
//if let Some(last_ret) = self.ci.ret_relocs.last()
|
if let Some(last_ret) = self.ci.ret_relocs.last()
|
||||||
// && last_ret.offset as usize + self.ci.snap.code == self.output.code.len() - 5
|
&& last_ret.offset as usize + self.ci.snap.code == self.output.code.len() - 5
|
||||||
//{
|
{
|
||||||
// self.output.code.truncate(self.output.code.len() - 5);
|
self.output.code.truncate(self.output.code.len() - 5);
|
||||||
// self.ci.ret_relocs.pop();
|
self.ci.ret_relocs.pop();
|
||||||
//}
|
}
|
||||||
let len = self.output.code.len() as u32;
|
let len = self.output.code.len() as u32;
|
||||||
for mut rel in self.ci.ret_relocs.drain(ret_reloc_base..) {
|
for mut rel in self.ci.ret_relocs.drain(ret_reloc_base..) {
|
||||||
rel.offset += self.ci.snap.code as u32;
|
rel.offset += self.ci.snap.code as u32;
|
||||||
|
@ -1975,6 +1976,9 @@ impl Codegen {
|
||||||
if let Some(val) = val {
|
if let Some(val) = val {
|
||||||
let size = self.ci.ret.map_or(17, |ty| self.tys.size_of(ty));
|
let size = self.ci.ret.map_or(17, |ty| self.tys.size_of(ty));
|
||||||
let loc = match size {
|
let loc = match size {
|
||||||
|
_ if self.ci.inline_ret_loc != Loc::default() => {
|
||||||
|
Some(self.ci.inline_ret_loc.as_ref())
|
||||||
|
}
|
||||||
0 => None,
|
0 => None,
|
||||||
1..=16 => Some(Loc::reg(1)),
|
1..=16 => Some(Loc::reg(1)),
|
||||||
_ => Some(Loc::reg(self.ci.ret_reg.as_ref()).into_derefed()),
|
_ => Some(Loc::reg(self.ci.ret_reg.as_ref()).into_derefed()),
|
||||||
|
@ -2006,6 +2010,7 @@ impl Codegen {
|
||||||
let jump_offset = self.local_offset();
|
let jump_offset = self.local_offset();
|
||||||
self.output.emit(jeq(reg.get(), 0, 0));
|
self.output.emit(jeq(reg.get(), 0, 0));
|
||||||
self.ci.free_loc(cond.loc);
|
self.ci.free_loc(cond.loc);
|
||||||
|
self.ci.regs.free(reg);
|
||||||
|
|
||||||
log::dbg!("if-then");
|
log::dbg!("if-then");
|
||||||
let then_unreachable = self.expr(then).is_none();
|
let then_unreachable = self.expr(then).is_none();
|
||||||
|
@ -3465,5 +3470,6 @@ mod tests {
|
||||||
// structs_in_registers => README;
|
// structs_in_registers => README;
|
||||||
comptime_function_from_another_file => README;
|
comptime_function_from_another_file => README;
|
||||||
inline => README;
|
inline => README;
|
||||||
|
inline_test => README;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
0
hblang/tests/codegen_tests_inline_test.txt
Normal file
0
hblang/tests/codegen_tests_inline_test.txt
Normal file
60
rustc-ice-2024-09-02T01_00_44-1001645.txt
Normal file
60
rustc-ice-2024-09-02T01_00_44-1001645.txt
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
thread 'main' panicked at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/std/src/thread/mod.rs:1592:40:
|
||||||
|
called `Option::unwrap()` on a `None` value
|
||||||
|
stack backtrace:
|
||||||
|
0: 0x72eebd94e655 - std::backtrace_rs::backtrace::libunwind::trace::h80e3b94cbd6b7880
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
|
||||||
|
1: 0x72eebd94e655 - std::backtrace_rs::backtrace::trace_unsynchronized::h16ad4e2ce618cca4
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
|
||||||
|
2: 0x72eebd94e655 - std::backtrace::Backtrace::create::h2237e34e4d94fd3f
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/std/src/backtrace.rs:331:13
|
||||||
|
3: 0x72eebd94e5a5 - std::backtrace::Backtrace::force_capture::h546bf0691b546a53
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/std/src/backtrace.rs:312:9
|
||||||
|
4: 0x72eeb9e08481 - std[4f18a6f40454bd49]::panicking::update_hook::<alloc[41823d762b0fa74e]::boxed::Box<rustc_driver_impl[af16f08a9d11636]::install_ice_hook::{closure#0}>>::{closure#0}
|
||||||
|
5: 0x72eebd96967f - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::haa44c2956b1bd51c
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/alloc/src/boxed.rs:2078:9
|
||||||
|
6: 0x72eebd96967f - std::panicking::rust_panic_with_hook::hbf6178baa52721f9
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/std/src/panicking.rs:804:13
|
||||||
|
7: 0x72eebd969273 - std::panicking::begin_panic_handler::{{closure}}::hab58fc1731670d4c
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/std/src/panicking.rs:663:13
|
||||||
|
8: 0x72eebd966af9 - std::sys::backtrace::__rust_end_short_backtrace::h5237252f6772769b
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/std/src/sys/backtrace.rs:171:18
|
||||||
|
9: 0x72eebd968f34 - rust_begin_unwind
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/std/src/panicking.rs:661:5
|
||||||
|
10: 0x72eebd9b22e3 - core::panicking::panic_fmt::hea2003cd03a74d6c
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/core/src/panicking.rs:74:14
|
||||||
|
11: 0x72eebd9b236c - core::panicking::panic::hb580cc4fc421f3c8
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/core/src/panicking.rs:148:5
|
||||||
|
12: 0x72eebd9b20d9 - core::option::unwrap_failed::ha8ca2f24e398bc62
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/core/src/option.rs:2013:5
|
||||||
|
13: 0x72eebc2d9e4f - rustc_driver_impl[af16f08a9d11636]::run_compiler
|
||||||
|
14: 0x72eebc2d7bec - rustc_driver_impl[af16f08a9d11636]::main
|
||||||
|
15: 0x5b4126957c07 - rustc_main[ab1568c316c01211]::main
|
||||||
|
16: 0x5b4126957bf3 - std[4f18a6f40454bd49]::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
|
||||||
|
17: 0x5b4126957be9 - <std[4f18a6f40454bd49]::rt::lang_start<()>::{closure#0} as core[bcb08d550d2d303]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
|
||||||
|
18: 0x72eebd94b43d - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h8ee6b536c2e4e076
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/core/src/ops/function.rs:284:13
|
||||||
|
19: 0x72eebd94b43d - std::panicking::try::do_call::h5c8c98de8ed5bd5b
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/std/src/panicking.rs:553:40
|
||||||
|
20: 0x72eebd94b43d - std::panicking::try::h6315052de0e5fa0e
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/std/src/panicking.rs:517:19
|
||||||
|
21: 0x72eebd94b43d - std::panic::catch_unwind::h1530d3793f92a4bb
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/std/src/panic.rs:350:14
|
||||||
|
22: 0x72eebd94b43d - std::rt::lang_start_internal::{{closure}}::he545ff4063dfc2c8
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/std/src/rt.rs:141:48
|
||||||
|
23: 0x72eebd94b43d - std::panicking::try::do_call::h09c77e8b42da26d9
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/std/src/panicking.rs:553:40
|
||||||
|
24: 0x72eebd94b43d - std::panicking::try::h7a9b2c58b7302b3b
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/std/src/panicking.rs:517:19
|
||||||
|
25: 0x72eebd94b43d - std::panic::catch_unwind::h464a2cd7183a7af5
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/std/src/panic.rs:350:14
|
||||||
|
26: 0x72eebd94b43d - std::rt::lang_start_internal::h99fdbebdafe8d634
|
||||||
|
at /rustc/20ae37c18df95f9246c019b04957d23b4164bf7a/library/std/src/rt.rs:141:20
|
||||||
|
27: 0x5b4126957d27 - main
|
||||||
|
28: 0x72eeb6834e08 - <unknown>
|
||||||
|
29: 0x72eeb6834ecc - __libc_start_main
|
||||||
|
30: 0x5b4126957c30 - <unknown>
|
||||||
|
31: 0x0 - <unknown>
|
||||||
|
|
||||||
|
|
||||||
|
rustc version: 1.81.0-nightly (20ae37c18 2024-07-07)
|
||||||
|
platform: x86_64-unknown-linux-gnu
|
Loading…
Reference in a new issue