removing idk for scalar values (antipattern)
This commit is contained in:
parent
db62434736
commit
9c90adbfe8
|
@ -527,6 +527,14 @@ main := fn(): uint {
|
||||||
|
|
||||||
### Purely Testing Examples
|
### Purely Testing Examples
|
||||||
|
|
||||||
|
#### reading_idk
|
||||||
|
```hb
|
||||||
|
main := fn(): int {
|
||||||
|
a := @as(int, idk)
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#### nonexistent_ident_import
|
#### nonexistent_ident_import
|
||||||
```hb
|
```hb
|
||||||
main := @use("foo.hb").main
|
main := @use("foo.hb").main
|
||||||
|
|
|
@ -692,7 +692,6 @@ impl Nodes {
|
||||||
Kind::Load => write!(out, "load: "),
|
Kind::Load => write!(out, "load: "),
|
||||||
Kind::Stre => write!(out, "stre: "),
|
Kind::Stre => write!(out, "stre: "),
|
||||||
Kind::Mem => write!(out, " mem: "),
|
Kind::Mem => write!(out, " mem: "),
|
||||||
Kind::Idk => write!(out, " idk: "),
|
|
||||||
Kind::Extend => write!(out, " ext: "),
|
Kind::Extend => write!(out, " ext: "),
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
|
@ -1062,8 +1061,6 @@ pub enum Kind {
|
||||||
args: ty::Tuple,
|
args: ty::Tuple,
|
||||||
},
|
},
|
||||||
// [ctrl]
|
// [ctrl]
|
||||||
Idk,
|
|
||||||
// [ctrl]
|
|
||||||
Stck,
|
Stck,
|
||||||
// [ctrl, memory]
|
// [ctrl, memory]
|
||||||
Load,
|
Load,
|
||||||
|
@ -1661,7 +1658,6 @@ impl ItemCtx {
|
||||||
let offset = fuc.nodes[nid].offset;
|
let offset = fuc.nodes[nid].offset;
|
||||||
self.emit(instrs::addi64(atr(allocs[0]), base, offset as _));
|
self.emit(instrs::addi64(atr(allocs[0]), base, offset as _));
|
||||||
}
|
}
|
||||||
Kind::Idk => {}
|
|
||||||
Kind::Load => {
|
Kind::Load => {
|
||||||
let mut region = node.inputs[1];
|
let mut region = node.inputs[1];
|
||||||
let mut offset = 0;
|
let mut offset = 0;
|
||||||
|
@ -2168,7 +2164,15 @@ impl<'a> Codegen<'a> {
|
||||||
let stck = self.ci.nodes.new_node(ty, Kind::Stck, [VOID, MEM]);
|
let stck = self.ci.nodes.new_node(ty, Kind::Stck, [VOID, MEM]);
|
||||||
Some(Value::ptr(stck).ty(ty))
|
Some(Value::ptr(stck).ty(ty))
|
||||||
} else {
|
} else {
|
||||||
Some(self.ci.nodes.new_node_lit(ty, Kind::Idk, [VOID]))
|
self.report(
|
||||||
|
pos,
|
||||||
|
fa!(
|
||||||
|
"type '{}' cannot be uninitialized, use a zero \
|
||||||
|
value instead ('@bitcast(0)' in case of pointers)",
|
||||||
|
self.ty_display(ty)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
Value::NEVER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expr::Bool { value, .. } => Some(self.ci.nodes.new_node_lit(
|
Expr::Bool { value, .. } => Some(self.ci.nodes.new_node_lit(
|
||||||
|
@ -2376,6 +2380,7 @@ impl<'a> Codegen<'a> {
|
||||||
}
|
}
|
||||||
Expr::BinOp { left, op: TokenKind::Decl, right, .. } => {
|
Expr::BinOp { left, op: TokenKind::Decl, right, .. } => {
|
||||||
let mut right = self.expr(right)?;
|
let mut right = self.expr(right)?;
|
||||||
|
|
||||||
if right.ty.loc(self.tys) == Loc::Stack {
|
if right.ty.loc(self.tys) == Loc::Stack {
|
||||||
let stck = self.ci.nodes.new_node_nop(right.ty, Kind::Stck, [VOID, MEM]);
|
let stck = self.ci.nodes.new_node_nop(right.ty, Kind::Stck, [VOID, MEM]);
|
||||||
self.store_mem(stck, right.ty, right.id);
|
self.store_mem(stck, right.ty, right.id);
|
||||||
|
@ -2417,9 +2422,7 @@ impl<'a> Codegen<'a> {
|
||||||
|
|
||||||
match lhs.ty.expand() {
|
match lhs.ty.expand() {
|
||||||
_ if lhs.ty.is_pointer() || lhs.ty.is_integer() || lhs.ty == ty::Id::BOOL => {
|
_ if lhs.ty.is_pointer() || lhs.ty.is_integer() || lhs.ty == ty::Id::BOOL => {
|
||||||
if mem::take(&mut lhs.ptr) {
|
self.strip_ptr(&mut lhs);
|
||||||
lhs.id = self.load_mem(lhs.id, lhs.ty);
|
|
||||||
}
|
|
||||||
self.ci.nodes.lock(lhs.id);
|
self.ci.nodes.lock(lhs.id);
|
||||||
let rhs = self.expr_ctx(right, Ctx::default().with_ty(lhs.ty));
|
let rhs = self.expr_ctx(right, Ctx::default().with_ty(lhs.ty));
|
||||||
self.ci.nodes.unlock(lhs.id);
|
self.ci.nodes.unlock(lhs.id);
|
||||||
|
@ -3400,12 +3403,20 @@ impl<'a> Codegen<'a> {
|
||||||
fn expr_ctx(&mut self, expr: &Expr, ctx: Ctx) -> Option<Value> {
|
fn expr_ctx(&mut self, expr: &Expr, ctx: Ctx) -> Option<Value> {
|
||||||
let mut n = self.raw_expr_ctx(expr, ctx)?;
|
let mut n = self.raw_expr_ctx(expr, ctx)?;
|
||||||
self.strip_var(&mut n);
|
self.strip_var(&mut n);
|
||||||
if mem::take(&mut n.ptr) {
|
self.strip_ptr(&mut n);
|
||||||
n.id = self.load_mem(n.id, n.ty);
|
|
||||||
}
|
|
||||||
Some(n)
|
Some(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn expr(&mut self, expr: &Expr) -> Option<Value> {
|
||||||
|
self.expr_ctx(expr, Default::default())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn strip_ptr(&mut self, target: &mut Value) {
|
||||||
|
if mem::take(&mut target.ptr) {
|
||||||
|
target.id = self.load_mem(target.id, target.ty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn offset(&mut self, val: Nid, off: Offset) -> Nid {
|
fn offset(&mut self, val: Nid, off: Offset) -> Nid {
|
||||||
if off == 0 {
|
if off == 0 {
|
||||||
return val;
|
return val;
|
||||||
|
@ -3424,10 +3435,6 @@ impl<'a> Codegen<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expr(&mut self, expr: &Expr) -> Option<Value> {
|
|
||||||
self.expr_ctx(expr, Default::default())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn jump_to(&mut self, pos: Pos, id: usize) -> Option<Value> {
|
fn jump_to(&mut self, pos: Pos, id: usize) -> Option<Value> {
|
||||||
let Some(mut loob) = self.ci.loops.last_mut() else {
|
let Some(mut loob) = self.ci.loops.last_mut() else {
|
||||||
self.report(pos, "break outside a loop");
|
self.report(pos, "break outside a loop");
|
||||||
|
@ -3574,9 +3581,7 @@ impl<'a> Codegen<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(oper) = to_correct {
|
if let Some(oper) = to_correct {
|
||||||
if mem::take(&mut oper.ptr) {
|
self.strip_ptr(oper);
|
||||||
oper.id = self.load_mem(oper.id, oper.ty);
|
|
||||||
}
|
|
||||||
oper.ty = upcasted;
|
oper.ty = upcasted;
|
||||||
oper.id = self.ci.nodes.new_node(upcasted, Kind::Extend, [VOID, oper.id]);
|
oper.id = self.ci.nodes.new_node(upcasted, Kind::Extend, [VOID, oper.id]);
|
||||||
if matches!(op, TokenKind::Add | TokenKind::Sub)
|
if matches!(op, TokenKind::Add | TokenKind::Sub)
|
||||||
|
@ -3625,9 +3630,7 @@ impl<'a> Codegen<'a> {
|
||||||
self.ty_display(src.ty),
|
self.ty_display(src.ty),
|
||||||
self.ty_display(upcasted)
|
self.ty_display(upcasted)
|
||||||
);
|
);
|
||||||
if mem::take(&mut src.ptr) {
|
self.strip_ptr(src);
|
||||||
src.id = self.load_mem(src.id, src.ty);
|
|
||||||
}
|
|
||||||
src.ty = upcasted;
|
src.ty = upcasted;
|
||||||
src.id = self.ci.nodes.new_node(upcasted, Kind::Extend, [VOID, src.id]);
|
src.id = self.ci.nodes.new_node(upcasted, Kind::Extend, [VOID, src.id]);
|
||||||
}
|
}
|
||||||
|
@ -4133,10 +4136,6 @@ impl<'a> Function<'a> {
|
||||||
let ops = vec![self.drg(nid)];
|
let ops = vec![self.drg(nid)];
|
||||||
self.add_instr(nid, ops);
|
self.add_instr(nid, ops);
|
||||||
}
|
}
|
||||||
Kind::Idk => {
|
|
||||||
let ops = vec![self.drg(nid)];
|
|
||||||
self.add_instr(nid, ops);
|
|
||||||
}
|
|
||||||
Kind::Phi | Kind::Arg | Kind::Mem => {}
|
Kind::Phi | Kind::Arg | Kind::Mem => {}
|
||||||
Kind::Load { .. } if node.ty.loc(self.tys) == Loc::Stack => {
|
Kind::Load { .. } if node.ty.loc(self.tys) == Loc::Stack => {
|
||||||
self.nodes.lock(nid)
|
self.nodes.lock(nid)
|
||||||
|
@ -4764,6 +4763,7 @@ mod tests {
|
||||||
fb_driver;
|
fb_driver;
|
||||||
|
|
||||||
// Purely Testing Examples;
|
// Purely Testing Examples;
|
||||||
|
reading_idk;
|
||||||
nonexistent_ident_import;
|
nonexistent_ident_import;
|
||||||
big_array_crash;
|
big_array_crash;
|
||||||
returning_global_struct;
|
returning_global_struct;
|
||||||
|
|
3
lang/tests/son_tests_reading_idk.txt
Normal file
3
lang/tests/son_tests_reading_idk.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
test.hb:3:16: type 'int' cannot be uninitialized, use a zero value instead ('@bitcast(0)' in case of pointers)
|
||||||
|
a := @as(int, idk)
|
||||||
|
^
|
Loading…
Reference in a new issue