fixing another problem with const

This commit is contained in:
Jakub Doka 2024-11-10 12:03:15 +01:00
parent 7865d692a1
commit c353d28be0
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
2 changed files with 35 additions and 12 deletions

View file

@ -2433,7 +2433,9 @@ impl<'a> Codegen<'a> {
self.ci.nodes.graphviz_in_browser(self.ty_display(ty::Id::VOID)); self.ci.nodes.graphviz_in_browser(self.ty_display(ty::Id::VOID));
}); });
debug_assert!( debug_assert!(
self.ci.nodes[region].kind != Kind::Load || self.ci.nodes[region].ty.is_pointer(), self.ci.nodes[region].kind != Kind::Load
|| self.ci.nodes[region].kind == Kind::Stck
|| self.ci.nodes[region].ty.is_pointer(),
"{:?} {} {}", "{:?} {} {}",
self.ci.nodes.graphviz_in_browser(self.ty_display(ty::Id::VOID)), self.ci.nodes.graphviz_in_browser(self.ty_display(ty::Id::VOID)),
self.file().path, self.file().path,
@ -3817,11 +3819,14 @@ impl<'a> Codegen<'a> {
let f = &self.files[c.file.index()]; let f = &self.files[c.file.index()];
let Expr::BinOp { left, right, .. } = c.ast.get(f) else { unreachable!() }; let Expr::BinOp { left, right, .. } = c.ast.get(f) else { unreachable!() };
left.find_pattern_path(c.name, right, |expr, is_ct| { let mut value = left
.find_pattern_path(c.name, right, |expr, is_ct| {
debug_assert!(is_ct); debug_assert!(is_ct);
self.expr_ctx(expr, ctx) self.raw_expr_ctx(expr, ctx)
}) })
.unwrap_or_else(|_| unreachable!()) .unwrap_or_else(|_| unreachable!())?;
self.strip_var(&mut value);
Some(value)
} }
fn add_clobbers(&mut self, value: Value, clobbered_aliases: &mut BitSet) { fn add_clobbers(&mut self, value: Value, clobbered_aliases: &mut BitSet) {

View file

@ -50,7 +50,7 @@ impl HbvmBackend {
) -> (usize, bool) { ) -> (usize, bool) {
let mut ralloc = mem::take(&mut self.ralloc); let mut ralloc = mem::take(&mut self.ralloc);
let fuc = Function::new(nodes, tys, sig); let fuc = Function::new(nodes, tys, files, sig);
log::info!("{:?}", fuc); log::info!("{:?}", fuc);
if !fuc.tail { if !fuc.tail {
mem::swap( mem::swap(
@ -447,6 +447,7 @@ pub struct Function<'a> {
sig: Sig, sig: Sig,
nodes: &'a mut Nodes, nodes: &'a mut Nodes,
tys: &'a Types, tys: &'a Types,
files: &'a [parser::Ast],
tail: bool, tail: bool,
visited: BitSet, visited: BitSet,
backrefs: Vec<u16>, backrefs: Vec<u16>,
@ -471,10 +472,11 @@ impl core::fmt::Debug for Function<'_> {
} }
impl<'a> Function<'a> { impl<'a> Function<'a> {
fn new(nodes: &'a mut Nodes, tys: &'a Types, sig: Sig) -> Self { fn new(nodes: &'a mut Nodes, tys: &'a Types, files: &'a [parser::Ast], sig: Sig) -> Self {
let mut s = Self { let mut s = Self {
tys, tys,
sig, sig,
files,
tail: true, tail: true,
visited: Default::default(), visited: Default::default(),
backrefs: vec![u16::MAX; nodes.values.len()], backrefs: vec![u16::MAX; nodes.values.len()],
@ -523,13 +525,27 @@ impl<'a> Function<'a> {
regalloc2::Operand::reg_def(self.rg(nid)) regalloc2::Operand::reg_def(self.rg(nid))
} }
fn rg(&self, nid: Nid) -> regalloc2::VReg { fn rg(&mut self, nid: Nid) -> regalloc2::VReg {
debug_assert!( debug_assert!(
!self.nodes.is_cfg(nid) || matches!(self.nodes[nid].kind, Kind::Call { .. }), !self.nodes.is_cfg(nid) || matches!(self.nodes[nid].kind, Kind::Call { .. }),
"{:?}", "{:?}",
self.nodes[nid] self.nodes[nid]
); );
debug_assert_eq!(self.nodes[nid].lock_rc, 0, "{nid} {:?}", self.nodes[nid]); debug_assert_eq!(
{ self.nodes[nid].lock_rc },
0,
"{nid} {:?} {:?} {:?}",
self.nodes[nid].clone(),
nid,
{
self.nodes[nid].lock_rc = u16::MAX - 1;
self.nodes.graphviz_in_browser(ty::Display::new(
self.tys,
self.files,
ty::Id::VOID,
));
}
);
debug_assert!(self.nodes[nid].kind != Kind::Phi || self.nodes[nid].ty != ty::Id::VOID); debug_assert!(self.nodes[nid].kind != Kind::Phi || self.nodes[nid].ty != ty::Id::VOID);
regalloc2::VReg::new(nid as _, regalloc2::RegClass::Int) regalloc2::VReg::new(nid as _, regalloc2::RegClass::Int)
} }
@ -665,8 +681,9 @@ impl<'a> Function<'a> {
match parama.next(ty, self.tys) { match parama.next(ty, self.tys) {
None => {} None => {}
Some(PLoc::Reg(r, _) | PLoc::WideReg(r, _) | PLoc::Ref(r, _)) => { Some(PLoc::Reg(r, _) | PLoc::WideReg(r, _) | PLoc::Ref(r, _)) => {
let a = self.rg(arg);
self.add_instr(NEVER, vec![regalloc2::Operand::reg_fixed_def( self.add_instr(NEVER, vec![regalloc2::Operand::reg_fixed_def(
self.rg(arg), a,
regalloc2::PReg::new(r as _, regalloc2::RegClass::Int), regalloc2::PReg::new(r as _, regalloc2::RegClass::Int),
)]); )]);
} }
@ -674,8 +691,9 @@ impl<'a> Function<'a> {
} }
if let Some(PLoc::Ref(r, ..)) = ret { if let Some(PLoc::Ref(r, ..)) = ret {
let m = self.rg(MEM);
self.add_instr(NEVER, vec![regalloc2::Operand::reg_fixed_def( self.add_instr(NEVER, vec![regalloc2::Operand::reg_fixed_def(
self.rg(MEM), m,
regalloc2::PReg::new(r as _, regalloc2::RegClass::Int), regalloc2::PReg::new(r as _, regalloc2::RegClass::Int),
)]); )]);
} }