Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
7f30ca7
Merge branch 'feat-typing' into feat-numeric-types
Soulthym Jul 29, 2025
474de8a
docs(typing): add a NOTE for BinType::infer_bin_ty_sub, for issue #432
Soulthym Jul 29, 2025
1255bc9
chores(typing): make format
Soulthym Jul 29, 2025
9f17e24
fix(typing): adapt to old parser/ast/types api
Soulthym Jul 30, 2025
926d666
feat(typing): impl Typing for Span<T: Typing>
Soulthym Jul 30, 2025
74af2b2
feat(typing): allow forwarding of idents in sty! macro
Soulthym Jul 30, 2025
5a8af93
refactor(typing): default impl for Kind for Kind::Value Types
Soulthym Jul 30, 2025
bdec887
feat(typing): impl Typing for Vec<T>
Soulthym Jul 30, 2025
cc98758
feat(typing): Aggregate Kind variant + rework Show + impl Typing for …
Soulthym Jul 31, 2025
41a3ff4
refactor(typing): rename int to uint
Soulthym Jul 31, 2025
4891f5a
feat(typing): add an optional span to the TypeError enum
Soulthym Jul 31, 2025
3ad4b90
fix(typing): properly rename Int to UInt
Soulthym Jul 31, 2025
3402d8f
feat(typing): impl Display for TypeError
Soulthym Aug 1, 2025
60fb953
refactor(typing): integrate into codebase
Soulthym Aug 1, 2025
e7fadd4
chores: cargo clippy + fmt
Soulthym Aug 1, 2025
ee8b4a7
fix(typing): fix access::Default on TraceBinding
Soulthym Aug 5, 2025
6fee06e
fix(typing): fix TraceSegment::kind()
Soulthym Aug 5, 2025
68b28ab
feat(typing): update subtyping rules: make `?` and `_` top types
Soulthym Aug 5, 2025
80e5609
fix(typing): fix trace_type macro when len == 1
Soulthym Aug 5, 2025
99d9403
Revert "fix(typing): fix access::Default on TraceBinding"
Soulthym Aug 5, 2025
72c2eba
chores(typing): make lint
Soulthym Aug 5, 2025
4f3e939
fix(mir): fix type-mismatch check on ListComprehension in translate
Soulthym Aug 6, 2025
c60f25f
feat(mir): better error reporting for translate on bin exprs + ? case
Soulthym Aug 6, 2025
636c77a
fix(parser): fix BindingType.ty() + .kind() + sema's call handling
Soulthym Aug 6, 2025
5e0cf1c
fix(typing): re-infer BinExpr bin_ty after updating its arguments
Soulthym Aug 7, 2025
a37b3d3
fix(typing): sema: report diagnostic on non-constant exponents
Soulthym Aug 7, 2025
b2c75b6
feat(typing): assert_bool primitive
Soulthym Aug 8, 2025
c8cfad3
fix(mir/translate): fix inserted enf expr
Soulthym Aug 8, 2025
9419d39
refactor(typing): rename typing crate to air_types
Soulthym Aug 26, 2025
16195e1
Merge remote-tracking branch 'upstream/next' into feat-numeric-types-…
Soulthym Sep 10, 2025
3210f36
feat(types): FunctionType::check_args_kinds
Soulthym Sep 11, 2025
1ceaadc
feat: implement typing for MIR nodes
Leo-Besancon Sep 12, 2025
46f8065
refactor: rename none::None to stale::Stale
Leo-Besancon Sep 15, 2025
f68eb25
fix: us correct op for infer_bin_ty_*
Leo-Besancon Sep 15, 2025
7efee31
refactor(types): change *_mut api + support for RefCell, Ref, and RefMut
Soulthym Sep 17, 2025
e21c2d2
refactor(types): update ast, expose Typ* traits through Link
Soulthym Sep 17, 2025
3eaf4d5
Merge branch 'feat-numeric-types-update-leo' into feat-numeric-types-…
Soulthym Sep 17, 2025
d57ae6e
feat(types): implement typing for the whole pipeline
Soulthym Sep 18, 2025
fe751bb
fix(types): fix Trace* Typing impl
Soulthym Sep 18, 2025
3c18d05
fix(types): various bug fixes
Soulthym Sep 18, 2025
49339d6
fix(types): more bug fixes, remove unused debugging
Soulthym Sep 18, 2025
7d49a85
fix(types): fix Evaluator argument types
Soulthym Sep 19, 2025
4020b8a
feat(mir): Cast primitive + translate assert_bool
Soulthym Sep 24, 2025
bd2df16
refactor(types): rename assert_bool -> as_bool
Soulthym Sep 24, 2025
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
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"air",
"codegen/winterfell",
"codegen/ace",
"types",
]
resolver = "2"

Expand All @@ -22,3 +23,4 @@ rust-version = "1.89"
anyhow = "1.0"
miden-diagnostics = "0.1"
thiserror = "2.0"
air-types = { version = "1.0", path = "types" }
12 changes: 4 additions & 8 deletions air/src/passes/translate_from_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl AirBuilder<'_> {
));
};

let ConstantValue::Felt(rhs_value) = constant_value else {
let ConstantValue::Scalar(rhs_value) = constant_value else {
return Err(CompileError::SemanticAnalysis(
SemanticAnalysisError::InvalidExpr(
ast::InvalidExprError::NonConstantExponent(rhs.span()),
Expand All @@ -267,7 +267,7 @@ impl AirBuilder<'_> {

let value = match mir_value {
MirValue::Constant(constant_value) => {
if let ConstantValue::Felt(felt) = constant_value {
if let ConstantValue::Scalar(felt) = constant_value {
crate::ir::Value::Constant(*felt)
} else {
unreachable!()
Expand Down Expand Up @@ -323,7 +323,7 @@ impl AirBuilder<'_> {

let value = match mir_value {
MirValue::Constant(constant_value) => {
if let ConstantValue::Felt(felt) = constant_value {
if let ConstantValue::Scalar(felt) = constant_value {
crate::ir::Value::Constant(*felt)
} else {
unreachable!()
Expand Down Expand Up @@ -610,11 +610,7 @@ impl AirBuilder<'_> {
.emit();
return Err(CompileError::Failed);
}
MirTraceAccess {
segment: trace_access_binding.segment,
column: trace_access_binding.offset,
row_offset: 0,
}
MirTraceAccess::new(trace_access_binding.segment, trace_access_binding.offset, 0)
},
SpannedMirValue {
value: MirValue::BusAccess(bus_access), ..
Expand Down
2 changes: 1 addition & 1 deletion air/src/tests/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,5 @@ fn err_ic_trace_cols_group_used_as_scalar() {
enf a[0]' = a + clk;
}";

expect_diagnostic(source, "type mismatch");
expect_diagnostic(source, "invalid binary expression");
}
3 changes: 2 additions & 1 deletion mir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ edition.workspace = true
[dependencies]
air-parser = { package = "air-parser", path = "../parser", version = "0.5" }
air-pass = { package = "air-pass", path = "../pass", version = "0.5" }
air-types.workspace = true
anyhow = { workspace = true }
derive-ir = { package = "air-derive-ir", path = "./derive-ir", version = "0.5" }
miden-core = { package = "miden-core", version = "0.13", default-features = false }
miden-diagnostics = { workspace = true }
pretty_assertions = "1.4"
rand = "0.9"
thiserror = { workspace = true }
winter-math = { package = "winter-math", version = "0.12", default-features = false }
winter-math = { package = "winter-math", version = "0.12", default-features = false }
12 changes: 8 additions & 4 deletions mir/derive-ir/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,20 +564,24 @@ fn make_build_method(
match enum_wrapper {
EnumWrapper::Op => quote! {
pub fn build(&self) -> crate::ir::Link<Op> {
Op::#name(
let mut op = Op::#name(
#name {
#(#fields),*
}
).into()
);
op.finalize_hook();
op.into()
}
},
EnumWrapper::Root => quote! {
pub fn build(&self) -> crate::ir::Link<Root> {
Root::#name(
let mut root = Root::#name(
#name {
#(#fields),*
}
).into()
);
root.finalize_hook();
root.into()
}
},
}
Expand Down
20 changes: 20 additions & 0 deletions mir/src/ir/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::{
rc::{Rc, Weak},
};

use air_types::Typing;
use air_types::*;
use miden_diagnostics::{SourceSpan, Spanned};

/// A wrapper around a `Rc<RefCell<T>>` to allow custom trait implementations.
Expand Down Expand Up @@ -110,6 +112,24 @@ where
}
}

impl<T: Typing> Typing for Link<T> {
fn ty(&self) -> Option<Type> {
self.borrow().ty()
}
}

impl<T: ScalarTypeMut> ScalarTypeMut for Link<T> {
fn update_scalar_ty_unchecked(&mut self, new_ty: Option<ScalarType>) {
self.borrow_mut().update_scalar_ty_unchecked(new_ty);
}
}

impl<T: TypeMut> TypeMut for Link<T> {
fn update_ty_unchecked(&mut self, new_ty: Option<Type>) {
self.borrow_mut().update_ty_unchecked(new_ty);
}
}

/// A wrapper around a `Option<Weak<RefCell<T>>>` to allow custom trait implementations.
/// Used instead of `Link` where a `Link` would create a cyclIc reference.
pub struct BackLink<T> {
Expand Down
7 changes: 7 additions & 0 deletions mir/src/ir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ mod nodes;
mod owner;
mod quad_eval;
mod utils;
pub extern crate air_types;
pub extern crate derive_ir;

#[allow(unused_imports)]
pub use air_types::*;
pub use bus::Bus;
pub use derive_ir::Builder;
pub use graph::Graph;
Expand Down Expand Up @@ -113,3 +116,7 @@ pub trait Builder {
/// Create a new empty builder that exposes all fields
fn builder() -> Self::Empty;
}

pub trait BuilderHook {
fn finalize_hook(&mut self) {}
}
22 changes: 16 additions & 6 deletions mir/src/ir/node.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::ops::Deref;

use miden_diagnostics::{SourceSpan, Spanned};
use miden_diagnostics::Spanned;

use crate::ir::{BackLink, Child, Link, Op, Owner, Parent, Root};
use crate::ir::{BackLink, Child, Link, Op, Owner, Parent, Root, Stale};

/// All the nodes that can be in the MIR Graph
/// Combines all [Root] and [Op] variants
Expand Down Expand Up @@ -33,7 +33,8 @@ pub enum Node {
BusOp(BackLink<Op>),
Parameter(BackLink<Op>),
Value(BackLink<Op>),
None(SourceSpan),
Cast(BackLink<Op>),
None(Stale),
}

impl Default for Node {
Expand Down Expand Up @@ -64,6 +65,7 @@ impl PartialEq for Node {
(Node::BusOp(lhs), Node::BusOp(rhs)) => lhs.to_link() == rhs.to_link(),
(Node::Parameter(lhs), Node::Parameter(rhs)) => lhs.to_link() == rhs.to_link(),
(Node::Value(lhs), Node::Value(rhs)) => lhs.to_link() == rhs.to_link(),
(Node::Cast(lhs), Node::Cast(rhs)) => lhs.to_link() == rhs.to_link(),
(Node::None(_), Node::None(_)) => true,
_ => false,
}
Expand Down Expand Up @@ -92,6 +94,7 @@ impl std::hash::Hash for Node {
Node::BusOp(b) => b.to_link().hash(state),
Node::Parameter(p) => p.to_link().hash(state),
Node::Value(v) => v.to_link().hash(state),
Node::Cast(c) => c.to_link().hash(state),
Node::None(_) => (),
}
}
Expand Down Expand Up @@ -119,6 +122,7 @@ impl Parent for Node {
Node::BusOp(b) => b.children(),
Node::Parameter(_p) => Link::default(),
Node::Value(_v) => Link::default(),
Node::Cast(c) => c.children(),
Node::None(_) => Link::default(),
}
}
Expand Down Expand Up @@ -146,6 +150,7 @@ impl Child for Node {
Node::BusOp(b) => b.get_parents(),
Node::Parameter(p) => p.get_parents(),
Node::Value(v) => v.get_parents(),
Node::Cast(c) => c.get_parents(),
Node::None(_) => Vec::default(),
}
}
Expand All @@ -169,6 +174,7 @@ impl Child for Node {
Node::BusOp(b) => b.add_parent(parent),
Node::Parameter(p) => p.add_parent(parent),
Node::Value(v) => v.add_parent(parent),
Node::Cast(c) => c.add_parent(parent),
Node::None(_) => (),
}
}
Expand All @@ -192,6 +198,7 @@ impl Child for Node {
Node::BusOp(b) => b.remove_parent(parent),
Node::Parameter(p) => p.remove_parent(parent),
Node::Value(v) => v.remove_parent(parent),
Node::Cast(c) => c.remove_parent(parent),
Node::None(_) => (),
}
}
Expand Down Expand Up @@ -220,17 +227,18 @@ impl Link<Node> {
Op::BusOp(_) => Node::BusOp(BackLink::from(op_inner_val)),
Op::Parameter(_) => Node::Parameter(BackLink::from(op_inner_val)),
Op::Value(_) => Node::Value(BackLink::from(op_inner_val)),
Op::None(span) => Node::None(*span),
Op::Cast(_) => Node::Cast(BackLink::from(op_inner_val)),
Op::None(none) => Node::None(none.clone()),
};
} else if let Some(root_inner_val) = self.as_root() {
to_update = match root_inner_val.clone().borrow().deref() {
Root::Function(_) => Node::Function(BackLink::from(root_inner_val)),
Root::Evaluator(_) => Node::Evaluator(BackLink::from(root_inner_val)),
Root::None(span) => Node::None(*span),
Root::None(none) => Node::None(none.clone()),
};
} else {
// If the [Node] is stale, we set it to None
to_update = Node::None(self.span());
to_update = Node::None(Stale { span: self.span(), ty: None });
}

*self.borrow_mut() = to_update;
Expand Down Expand Up @@ -276,6 +284,7 @@ impl Link<Node> {
Node::BusOp(_) => None,
Node::Parameter(_) => None,
Node::Value(_) => None,
Node::Cast(_) => None,
Node::None(_) => None,
}
}
Expand All @@ -301,6 +310,7 @@ impl Link<Node> {
Node::BusOp(inner) => inner.to_link(),
Node::Parameter(inner) => inner.to_link(),
Node::Value(inner) => inner.to_link(),
Node::Cast(inner) => inner.to_link(),
Node::None(_) => None,
}
}
Expand Down
2 changes: 2 additions & 0 deletions mir/src/ir/nodes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
pub mod stale;
mod op;
mod ops;
mod root;
mod roots;

use std::cell::{Ref, RefMut};

pub use stale::*;
pub use op::Op;
pub use ops::*;
pub use root::Root;
Expand Down
Loading