Skip to content
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
10 changes: 10 additions & 0 deletions baml_language/crates/baml_base/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ pub struct TyAttr {
}

impl TyAttr {
/// The all-`Unset` attribute set — a `const` equal to
/// [`TyAttr::default`], usable where a `&'static TyAttr` is needed (e.g.
/// the `ty_family!`-generated `attr()` accessor's fallback for variants
/// that carry no attribute of their own).
pub const EMPTY: TyAttr = TyAttr {
sap_parse_without_null: TyAttrValue::Unset,
sap_pending_never: TyAttrValue::Unset,
sap_in_progress_never: TyAttrValue::Unset,
};

/// Return the canonical names of all attributes that are `Set`.
pub fn attr_names(&self) -> Vec<&'static str> {
let mut names = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion baml_language/crates/baml_compiler2_emit/src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,7 @@ mod tests {
kind: StatementKind::Assign {
destination: Place::Local(Local(0)),
value: Rvalue::Array(
baml_type::TyTemplate::Concrete(baml_type::RuntimeTy::unknown()),
baml_type::TyTemplate::from(baml_type::RealizedTy::unknown()),
vec![
Operand::copy_local(target),
Operand::Constant(Constant::Int(1)),
Expand Down
290 changes: 186 additions & 104 deletions baml_language/crates/baml_compiler2_emit/src/emit.rs

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions baml_language/crates/baml_compiler2_emit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ fn build_packages(
.find(|(an, _)| an == name)
.map(|(_, t)| t.clone())
.unwrap_or_else(|| {
baml_type::TyTemplate::Concrete(baml_type::RuntimeTy::BuiltinUnknown {
baml_type::TyTemplate::from(baml_type::RealizedTy::BuiltinUnknown {
attr: TyAttr::default(),
})
});
Expand Down Expand Up @@ -590,13 +590,13 @@ fn build_packages(
// The implementor pattern is the class at its own parameters; bounds
// come from the class's generic parameters. Shared by all its blocks.
let for_ty_pattern = if generics.is_empty() {
baml_type::TyTemplate::Concrete(baml_type::RuntimeTy::Class(
baml_type::TyTemplate::from(baml_type::RealizedTy::Class(
class_tn.clone(),
Vec::new(),
TyAttr::default(),
))
} else {
baml_type::TyTemplate::Class(
baml_type::TyTemplate::class(
class_tn.clone(),
(0..u32::try_from(generics.len()).expect("generic arity fits u32"))
.map(baml_type::TyTemplate::TypeArgRef)
Expand Down Expand Up @@ -983,7 +983,7 @@ pub fn generate_project_bytecode_with_opt(
let mut fields = Vec::new();
// Class-level generic params, used to resolve `T`-references in
// field type expressions to `TyTemplate::TypeArgRef(N)`. When
// empty, `tir2_to_template` produces `TyTemplate::Concrete(...)`
// empty, `tir2_to_template` produces a `Concrete`-equivalent leaf
// for every leaf and `field_template == Concrete(field_type)`.
let class_generic_params: Vec<baml_base::Name> = class_data.generic_params.clone();
// BEP-044: collect only the class's actual runtime fields.
Expand Down Expand Up @@ -1019,7 +1019,12 @@ pub fn generate_project_bytecode_with_opt(
let null_ty = baml_type::RuntimeTy::Null {
attr: baml_type::TyAttr::default(),
};
(null_ty.clone(), baml_type::TyTemplate::Concrete(null_ty))
(
null_ty.clone(),
baml_type::TyTemplate::from(baml_type::RealizedTy::Null {
attr: baml_type::TyAttr::default(),
}),
)
}
};
let (field_desc, field_alias, field_skip) = extract_schema_attrs(attrs.as_slice());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ pub(crate) fn walk_rvalue_pull<S: PullSink>(sink: &mut S, rvalue: &Rvalue) -> Re
// produced by the array-literal lowering (which emits the typed
// `Rvalue::Array`); this arm is a defensive fallback.
sink.alloc_array(
&TyTemplate::Concrete(baml_type::RuntimeTy::unknown()),
&TyTemplate::from(baml_type::RealizedTy::unknown()),
fields.len(),
)
}
Expand Down
16 changes: 8 additions & 8 deletions baml_language/crates/baml_compiler2_emit/src/stack_carry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ impl StackEffectSink for StackCarryPullSink<'_> {
#[cfg(test)]
mod tests {
use baml_compiler2_mir::{AggregateKind, BasicBlock, LocalDecl, Statement};
use baml_type::{TyAttr, TyTemplate};
use baml_type::{RealizedTy, TyAttr, TyTemplate};

use super::*;

Expand Down Expand Up @@ -1532,7 +1532,7 @@ mod tests {

let ok = simulate_aggregate_operand_pull_stack(
&Rvalue::Array(
TyTemplate::Concrete(RuntimeTy::unknown()),
TyTemplate::from(RealizedTy::unknown()),
vec![
Operand::copy_local(carried),
Operand::copy_local(sibling),
Expand Down Expand Up @@ -1586,8 +1586,8 @@ mod tests {

let ok = simulate_aggregate_operand_pull_stack(
&Rvalue::Map(
TyTemplate::Concrete(RuntimeTy::string()),
TyTemplate::Concrete(RuntimeTy::unknown()),
TyTemplate::from(RealizedTy::string()),
TyTemplate::from(RealizedTy::unknown()),
vec![
(
Operand::Constant(Constant::String("a".to_string())),
Expand All @@ -1614,8 +1614,8 @@ mod tests {
let key = Local(1);
let value = Local(2);
let rvalue = Rvalue::Map(
TyTemplate::Concrete(RuntimeTy::string()),
TyTemplate::Concrete(RuntimeTy::unknown()),
TyTemplate::from(RealizedTy::string()),
TyTemplate::from(RealizedTy::unknown()),
vec![(Operand::copy_local(key), Operand::copy_local(value))],
);

Expand All @@ -1634,7 +1634,7 @@ mod tests {

let ok = simulate_aggregate_operand_pull_stack(
&Rvalue::Array(
TyTemplate::Concrete(RuntimeTy::unknown()),
TyTemplate::from(RealizedTy::unknown()),
vec![
Operand::copy_local(real_prefix),
Operand::copy_local(carried),
Expand Down Expand Up @@ -1664,7 +1664,7 @@ mod tests {
&Rvalue::Aggregate {
kind: AggregateKind::Class {
name: "Box".to_string(),
type_arg_templates: vec![TyTemplate::Concrete(int_ty())],
type_arg_templates: vec![TyTemplate::from(baml_type::RealizedTy::int())],
},
fields: vec![Operand::copy_local(sibling), Operand::copy_local(carried)],
},
Expand Down
12 changes: 6 additions & 6 deletions baml_language/crates/baml_compiler2_mir/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,9 +730,9 @@ pub enum Rvalue {
///
/// The type is stored as a `TyTemplate` so that generic class checks like
/// `value is Foo<T>` (where `T` is a type parameter in scope) resolve
/// correctly at runtime via `TypeArgRef` substitution. For fully-concrete
/// types the template is `TyTemplate::Concrete(ty)`, which the emitter
/// handles on the same fast path as before.
/// correctly at runtime via `TypeArgRef` substitution. A fully-realized
/// template narrows to a `RealizedTy`, which the emitter handles on the
/// same tag / class-identity fast path as before.
IsType {
operand: Operand,
ty_template: TyTemplate,
Expand Down Expand Up @@ -793,9 +793,9 @@ pub enum Rvalue {

/// Materialize a `Ty` from a `TyTemplate`.
///
/// For concrete templates (`TyTemplate::Concrete`), the `Ty` is baked in
/// at compile time. For templates containing `TypeArgRef(N)`, the VM
/// substitutes `frame.type_args[N]` at execution time.
/// For a fully-realized template, the `Ty` is baked in at compile time.
/// For templates containing `TypeArgRef(N)`, the VM substitutes
/// `frame.type_args[N]` at execution time.
///
/// Emitted by the `reflect.type_of<T>()` intrinsic.
/// Lowers to `Instruction::LoadType(const_idx)` in bytecode.
Expand Down
Loading
Loading