From 7fce96842477eec457cffd2b52e97330c66c0efa Mon Sep 17 00:00:00 2001 From: 2kai2kai2 Date: Mon, 20 Jul 2026 14:37:30 -0700 Subject: [PATCH 01/10] LSP actions should use ItemTree firewall queries --- .../src/item_data/functions.rs | 37 ++ .../src/item_data/interfaces.rs | 23 +- .../crates/baml_lsp2_actions/src/actions.rs | 5 +- .../baml_lsp2_actions/src/annotations.rs | 7 +- .../crates/baml_lsp2_actions/src/check.rs | 403 ++++++++++-------- .../baml_lsp2_actions/src/completions.rs | 53 +-- .../baml_lsp2_actions/src/definition.rs | 116 +++-- .../crates/baml_lsp2_actions/src/describe.rs | 215 ++++++---- .../crates/baml_lsp2_actions/src/lib.rs | 4 +- .../crates/baml_lsp2_actions/src/outline.rs | 50 ++- .../crates/baml_lsp2_actions/src/type_info.rs | 62 ++- .../crates/baml_lsp2_actions/src/usages.rs | 55 +-- .../crates/baml_lsp2_actions/src/utils.rs | 116 +++++ .../semantic_tokens/type_aliases_jinja.baml | 36 +- .../syntax/class/type_aliases_jinja.baml | 44 +- .../functions_v2/prompt_errors/prompt1.baml | 34 +- .../syntax/template_string/bad_calls.baml | 48 +-- 17 files changed, 777 insertions(+), 531 deletions(-) diff --git a/baml_language/crates/baml_compiler2_ppir/src/item_data/functions.rs b/baml_language/crates/baml_compiler2_ppir/src/item_data/functions.rs index 5fa8647c650..98b19b16d3b 100644 --- a/baml_language/crates/baml_compiler2_ppir/src/item_data/functions.rs +++ b/baml_language/crates/baml_compiler2_ppir/src/item_data/functions.rs @@ -97,6 +97,43 @@ pub fn function_llm_meta<'db>( }) } +/// The span-carrying Jinja prompt of an LLM (`{ client …; prompt … }`) function, +/// for prompt-template validation. +/// +/// This is the body-ish sibling of [`function_llm_meta`]: because its value +/// carries the prompt's source span, it re-runs whenever the prompt text *or its +/// position* changes — it does not offer the span-free early cutoff +/// `function_llm_meta` does. It mirrors [`function_body`](crate::function_body)'s +/// span-carrying tracked shape and exists so prompt validation can front the item +/// tree without reading it directly. +/// +/// `None` for a non-LLM function or an LLM function without a `prompt`. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct LlmPromptBody { + pub text: String, + pub span: TextRange, +} + +/// The [`LlmPromptBody`] for one function, or `None` when it has no LLM prompt. +#[salsa::tracked] +pub fn function_llm_prompt<'db>( + db: &'db dyn crate::Db, + function: FunctionLoc<'db>, +) -> Option> { + let item_tree = crate::file_item_tree(db, function.file(db)); + item_tree[function.id(db)] + .declarative_meta + .as_ref() + .and_then(|ast::DeclarativeMeta::Llm(llm)| { + llm.prompt.as_ref().map(|prompt| { + std::sync::Arc::new(LlmPromptBody { + text: prompt.text.clone(), + span: prompt.span, + }) + }) + }) +} + /// Span-free semantic data for a function's *elaborated* signature — the /// canonical callable view TIR consumes. /// diff --git a/baml_language/crates/baml_compiler2_ppir/src/item_data/interfaces.rs b/baml_language/crates/baml_compiler2_ppir/src/item_data/interfaces.rs index ae5890cbb03..33b72c90760 100644 --- a/baml_language/crates/baml_compiler2_ppir/src/item_data/interfaces.rs +++ b/baml_language/crates/baml_compiler2_ppir/src/item_data/interfaces.rs @@ -59,6 +59,8 @@ pub struct InterfaceSourceMap { pub span: TextRange, /// Spans for every node in [`InterfaceData::type_refs`]. pub type_refs: TypeRefSourceMap, + /// Name span per field, parallel to [`InterfaceData::fields`]. + pub field_name_spans: Vec, /// Parallel to [`InterfaceData::associated_types`]. pub associated_type_spans: Vec, /// Parallel to [`InterfaceData::required_methods`]. @@ -74,6 +76,8 @@ pub struct AssociatedTypeSourceMap { #[derive(Debug, Clone, PartialEq, Eq)] pub struct InterfaceMethodSigSourceMap { pub span: TextRange, + /// Span of just the method's name. + pub name_span: TextRange, /// One span per parameter, parallel to `InterfaceMethodSigData::params`. pub param_spans: Vec, } @@ -106,7 +110,18 @@ fn lower<'db>( ) -> (InterfaceData<'db>, InterfaceSourceMap) { let file = interface.file(db); let item_tree = crate::file_item_tree(db, file); + let item_source_map = crate::file_item_tree_source_map(db, file); let data = &item_tree[interface.id(db)]; + // Name spans for fields / required methods live in the item-tree source map + // (parallel to `fields` / `required_methods`), like a class's field spans. + let field_name_spans = item_source_map + .interface_field_spans + .get(&interface.id(db)) + .cloned() + .unwrap_or_default(); + let method_name_spans = item_source_map + .interface_method_spans + .get(&interface.id(db)); let mut type_refs = TypeRefBuilder::new(); @@ -193,6 +208,7 @@ fn lower<'db>( InterfaceSourceMap { span: data.span, type_refs: spans, + field_name_spans, associated_type_spans: data .associated_types .iter() @@ -204,8 +220,13 @@ fn lower<'db>( required_method_spans: data .required_methods .iter() - .map(|method| InterfaceMethodSigSourceMap { + .enumerate() + .map(|(i, method)| InterfaceMethodSigSourceMap { span: method.span, + name_span: method_name_spans + .and_then(|spans| spans.get(i)) + .copied() + .unwrap_or_default(), param_spans: method.params.iter().map(|param| param.span).collect(), }) .collect(), diff --git a/baml_language/crates/baml_lsp2_actions/src/actions.rs b/baml_language/crates/baml_lsp2_actions/src/actions.rs index d043bf83dae..3a7f2c5a50d 100644 --- a/baml_language/crates/baml_lsp2_actions/src/actions.rs +++ b/baml_language/crates/baml_lsp2_actions/src/actions.rs @@ -22,7 +22,7 @@ use baml_base::SourceFile; use baml_compiler_parser::syntax_tree; use baml_compiler_syntax::{SyntaxElement, SyntaxKind, SyntaxNode, ast::StringLiteral}; use baml_compiler2_ast::ast::FunctionOrigin; -use baml_compiler2_hir::{contributions::Definition, file_item_tree, file_symbol_contributions}; +use baml_compiler2_hir::{contributions::Definition, file_symbol_contributions}; use rowan::ast::AstNode; use text_size::TextRange; @@ -78,8 +78,7 @@ pub fn file_actions(db: &dyn Db, file: SourceFile) -> Vec { for (name, contrib) in &contribs.values { match contrib.definition { Definition::Function(loc) => { - let item_tree = file_item_tree(db, loc.file(db)); - let func = &item_tree[loc.id(db)]; + let func = baml_compiler2_ppir::item_data::function_data(db, loc); if !matches!(func.origin, FunctionOrigin::UserDefined) { continue; } diff --git a/baml_language/crates/baml_lsp2_actions/src/annotations.rs b/baml_language/crates/baml_lsp2_actions/src/annotations.rs index bf3c2be328f..c8246c919bb 100644 --- a/baml_language/crates/baml_lsp2_actions/src/annotations.rs +++ b/baml_language/crates/baml_lsp2_actions/src/annotations.rs @@ -57,7 +57,7 @@ use baml_compiler2_ast::{ Expr, ExprId, Stmt, ast::{AstSourceMap, ExprBody, FunctionBodyDef, FunctionOrigin}, }; -use baml_compiler2_hir::{body::FunctionBody, loc::FunctionLoc, scope::FileScopeId}; +use baml_compiler2_hir::{body::FunctionBody, scope::FileScopeId}; use baml_compiler2_tir::{inference::infer_scope_types, ty::Ty}; use text_size::TextSize; @@ -108,13 +108,12 @@ pub struct InlineAnnotation { /// with this module. #[salsa::tracked(returns(ref))] pub fn file_annotations(db: &dyn Db, file: SourceFile) -> Vec { - let item_tree = baml_compiler2_hir::file_item_tree(db, file); let index = baml_compiler2_hir::file_semantic_index(db, file); let mut out: Vec = Vec::new(); - for (func_local_id, func_data) in &item_tree.functions { - let func_loc = FunctionLoc::new(db, file, *func_local_id); + for &func_loc in baml_compiler2_ppir::item_data::file_functions(db, file) { + let func_data = baml_compiler2_ppir::item_data::function_data(db, func_loc); // Process user-written functions and methods, plus the synthesized // `$init_test*` registration functions (so test/testset bodies — which diff --git a/baml_language/crates/baml_lsp2_actions/src/check.rs b/baml_language/crates/baml_lsp2_actions/src/check.rs index ee84478a61b..38ba1d6aeae 100644 --- a/baml_language/crates/baml_lsp2_actions/src/check.rs +++ b/baml_language/crates/baml_lsp2_actions/src/check.rs @@ -164,7 +164,6 @@ pub fn check_file(db: &dyn Db, file: SourceFile) -> Vec { } } - let item_tree = baml_compiler2_hir::file_item_tree(db, file); let pkg_info = baml_compiler2_hir::file_package::file_package(db, file); let pkg_id = baml_compiler2_hir::package::PackageId::new(db, pkg_info.package.clone()); let res_ctx = baml_compiler2_tir::package_interface::package_resolution_context(db, pkg_id); @@ -191,7 +190,7 @@ pub fn check_file(db: &dyn Db, file: SourceFile) -> Vec { diagnostics.extend(check_jinja_templates( db, file_id, - &item_tree, + file, pkg_items, &pkg_info.namespace_path, source_text, @@ -199,11 +198,17 @@ pub fn check_file(db: &dyn Db, file: SourceFile) -> Vec { // ── 6. Function signature diagnostics ──────────────────────────────────── // + // FIXME(lsp-validation-antipattern): this re-implements TIR signature + // checking off the item-data firewall. Validation logic belongs in TIR/HIR + // with check.rs only surfacing diagnostics; it stays here because the + // default-signature diagnostics it emits have no TIR home yet. + // // Build a method → enclosing class list so we can merge class generic params. let mut method_to_class = Vec::new(); - for (class_id, class_data) in &item_tree.classes { - for &method_id in &class_data.methods { - method_to_class.push((method_id, *class_id)); + for &class_loc in baml_compiler2_ppir::item_data::file_classes(db, file) { + let class_data = baml_compiler2_ppir::item_data::class_data(db, class_loc); + for &method_loc in &class_data.methods { + method_to_class.push((method_loc, class_loc)); } } // Out-of-body `implement Interface for Type` methods: their `Self` resolves @@ -211,41 +216,38 @@ pub fn check_file(db: &dyn Db, file: SourceFile) -> Vec { // (`$rust_function`/builtin) impl methods skip the scope-inference path, so // without this their signatures would leave `Self` unresolved here. let mut method_to_impl = Vec::new(); - for impl_id in &item_tree.free_impls { - let Some(block) = item_tree.impls.get(impl_id) else { - continue; - }; - for &method_id in &block.methods { - method_to_impl.push((method_id, block)); + for &impl_loc in baml_compiler2_ppir::item_data::file_free_impls(db, file) { + let block = baml_compiler2_ppir::item_data::impl_block_data(db, impl_loc); + for &method_loc in &block.methods { + method_to_impl.push((method_loc, impl_loc)); } } - for (local_id, func_data) in &item_tree.functions { - let func_loc = baml_compiler2_hir::loc::FunctionLoc::new(db, file, *local_id); - // Expression-body functions already have their signatures checked - // during scope inference (step 3). Only check non-expr bodies here. - // Read the body discriminant straight off the item tree already in - // hand — the `function_body` query clones the whole `ExprBody` arena - // on execution, far too expensive for a body-kind test. + for &func_loc in baml_compiler2_ppir::item_data::file_functions(db, file) { + let func_data = baml_compiler2_ppir::item_data::function_data(db, func_loc); + // Expression-body functions already have their signatures checked during + // scope inference (step 3); only check non-expr bodies here. `function_body` + // is tracked (its `Arc` is cached per revision), so this body-kind test is + // O(1) on repeat rather than re-cloning the `ExprBody` arena each call. if matches!( - func_data.body, - Some(baml_compiler2_ast::FunctionBodyDef::Expr(..)) + baml_compiler2_ppir::function_body(db, func_loc).as_ref(), + baml_compiler2_hir::body::FunctionBody::Expr(..) ) { continue; } - let sig = baml_compiler2_hir::signature::function_signature(db, func_loc); + let func_source_map = baml_compiler2_ppir::item_data::function_source_map(db, func_loc); let mut type_errors = Vec::new(); let mut param_types = Vec::new(); // Compute the effective generic params: method params + enclosing class params. let mut generic_params = func_data.generic_params.clone(); - let enclosing_class_id = method_to_class + let enclosing_class = method_to_class .iter() - .find(|(mid, _)| mid == local_id) - .map(|(_, class_id)| *class_id); - if let Some(class_id) = enclosing_class_id { - let class_data = &item_tree[class_id]; + .find(|(mid, _)| *mid == func_loc) + .map(|(_, class_loc)| *class_loc); + if let Some(class_loc) = enclosing_class { + let class_data = baml_compiler2_ppir::item_data::class_data(db, class_loc); // Prepend class generic params (class params come first, method params after) let mut merged = class_data.generic_params.clone(); merged.extend(generic_params); @@ -255,29 +257,37 @@ pub fn check_file(db: &dyn Db, file: SourceFile) -> Vec { // `Self` is the `for` target and the block's generic params are in scope. let enclosing_impl = method_to_impl .iter() - .find(|(mid, _)| mid == local_id) + .find(|(mid, _)| *mid == func_loc) .map(|(_, imp)| *imp); - if let Some(imp) = enclosing_impl - && let baml_compiler2_hir::item_tree::ImplSubject::Free { generics, .. } = &imp.subject + let enclosing_impl_data = + enclosing_impl.map(|imp| baml_compiler2_ppir::item_data::impl_block_data(db, imp)); + if let Some(block) = enclosing_impl_data + && let baml_compiler2_ppir::item_data::ImplSubjectData::Free { generics, .. } = + &block.subject { let mut merged: Vec = generics.iter().map(|g| g.name.clone()).collect(); merged.extend(generic_params); generic_params = merged; } // Pre-resolve `Self` to the enclosing impl's `for` target before lowering - // signature types, mirroring the body path in `tir::inference`. - let self_replacement = enclosing_impl.and_then(|imp| match &imp.subject { - baml_compiler2_hir::item_tree::ImplSubject::Free { for_target, .. } => { - Some(for_target.clone()) + // signature types, mirroring the body path in `tir::inference`. The + // for-target lives in the impl block's own type-ref arena. + let self_replacement: Option<( + &baml_compiler2_hir::type_ref::TypeRefStore, + baml_compiler2_hir::type_ref::TypeRefId, + )> = enclosing_impl_data.and_then(|block| match &block.subject { + baml_compiler2_ppir::item_data::ImplSubjectData::Free { for_target, .. } => { + Some((&block.type_refs, *for_target)) } - baml_compiler2_hir::item_tree::ImplSubject::InClass { .. } => None, + baml_compiler2_ppir::item_data::ImplSubjectData::InClass { .. } => None, }); // BEP-044: `Self` in an out-of-body impl method's signature is the impl's // `for` target. The lowering context carries it as `self_ty`, so `Self` // resolves during lowering (no textual substitution). - let self_ty: Option = self_replacement.as_ref().map(|for_target| { - baml_compiler2_tir::lower_type_expr::lower_type_expr( - for_target, + let self_ty: Option = self_replacement.map(|(store, id)| { + baml_compiler2_tir::lower_type_expr::lower_type_ref( + store, + id, &baml_compiler2_tir::lower_type_expr::ScopeCtx { db, package_items: pkg_items, @@ -289,12 +299,13 @@ pub fn check_file(db: &dyn Db, file: SourceFile) -> Vec { &mut Vec::new(), ) }); - let lower_sig_te = |te: &baml_compiler2_ast::TypeExpr, - generic_params: &[Name], - diags: &mut Vec| + let lower_sig_ref = |id: baml_compiler2_hir::type_ref::TypeRefId, + generic_params: &[Name], + diags: &mut Vec| -> Ty { - baml_compiler2_tir::lower_type_expr::lower_type_expr( - te, + baml_compiler2_tir::lower_type_expr::lower_type_ref( + &func_data.type_refs, + id, &baml_compiler2_tir::lower_type_expr::ScopeCtx { db, package_items: pkg_items, @@ -307,43 +318,35 @@ pub fn check_file(db: &dyn Db, file: SourceFile) -> Vec { ) }; - // Check return type — use the span from the item tree's TypeExpr. - if let Some(ret_te) = &sig.return_type { - lower_sig_te(ret_te, &generic_params, &mut type_errors); + // Check return type — anchor diagnostics at the return type's source span. + if let Some(ret_id) = func_data.return_type { + lower_sig_ref(ret_id, &generic_params, &mut type_errors); if !type_errors.is_empty() { - if let Some(ret_spanned) = &func_data.return_type { - for error in type_errors.drain(..) { - diagnostics.push( - Diagnostic::error( - tir_type_error_to_diagnostic_id(&error), - error.to_string(), - ) - .with_primary_span(Span { - file_id, - range: ret_spanned.span, - }) - .with_phase(DiagnosticPhase::Type), - ); - } + let range = func_source_map.type_refs.span(ret_id); + for error in type_errors.drain(..) { + diagnostics.push( + Diagnostic::error( + tir_type_error_to_diagnostic_id(&error), + error.to_string(), + ) + .with_primary_span(Span { file_id, range }) + .with_phase(DiagnosticPhase::Type), + ); } } } - // Check parameter types — use the type_expr span, not the whole param span. - for (i, param) in sig.params.iter().enumerate() { + // Check parameter types — anchor diagnostics at each annotation's span. + for param in &func_data.params { type_errors.clear(); - let param_ty = if param.name.as_str() == "self" - && matches!( - param.ty.kind, - baml_compiler2_ast::TypeExprKind::Unknown { .. } - ) { + let param_ty = if param.name.as_str() == "self" && param.type_ref.is_none() { // `self`'s type is the enclosing receiver: the class for an in-body // method, or the impl's `for` target for an out-of-body // `implement I for C` method (mirroring the body path in // `tir::inference`). Falling back to `Unknown` would otherwise // leave `self` untyped in the latter case. - if let Some(class_id) = enclosing_class_id.as_ref() { - let class_data = &item_tree[*class_id]; + if let Some(class_loc) = enclosing_class { + let class_data = baml_compiler2_ppir::item_data::class_data(db, class_loc); pkg_items .lookup_type(&pkg_info.namespace_path, &class_data.name) .map(|def| { @@ -371,9 +374,10 @@ pub fn check_file(db: &dyn Db, file: SourceFile) -> Vec { .unwrap_or(Ty::Unknown { attr: TyAttr::default(), }) - } else if let Some(for_target) = &self_replacement { - baml_compiler2_tir::lower_type_expr::lower_type_expr( - for_target, + } else if let Some((store, id)) = self_replacement { + baml_compiler2_tir::lower_type_expr::lower_type_ref( + store, + id, &baml_compiler2_tir::lower_type_expr::ScopeCtx { db, package_items: pkg_items, @@ -390,32 +394,33 @@ pub fn check_file(db: &dyn Db, file: SourceFile) -> Vec { attr: TyAttr::default(), } } + } else if let Some(param_id) = param.type_ref { + lower_sig_ref(param_id, &generic_params, &mut type_errors) } else { - lower_sig_te(¶m.ty, &generic_params, &mut type_errors) + // A missing annotation lowered to the `Unknown` sentinel, which + // yields `Ty::Unknown` with no diagnostic. + Ty::Unknown { + attr: TyAttr::default(), + } }; if !type_errors.is_empty() { - if let Some(param) = func_data.params.get(i) { - if let Some(type_spanned) = ¶m.type_expr { - for error in type_errors.drain(..) { - diagnostics.push( - Diagnostic::error( - tir_type_error_to_diagnostic_id(&error), - error.to_string(), - ) - .with_primary_span(Span { - file_id, - range: type_spanned.span, - }) - .with_phase(DiagnosticPhase::Type), - ); - } + if let Some(type_id) = param.type_ref { + let range = func_source_map.type_refs.span(type_id); + for error in type_errors.drain(..) { + diagnostics.push( + Diagnostic::error( + tir_type_error_to_diagnostic_id(&error), + error.to_string(), + ) + .with_primary_span(Span { file_id, range }) + .with_phase(DiagnosticPhase::Type), + ); } } } param_types.push((param.name.clone(), param_ty)); } - let func_loc = baml_compiler2_hir::loc::FunctionLoc::new(db, file, *local_id); if let Some(scope_id) = baml_compiler2_ppir::item_data::function_scope(db, func_loc) { let context = baml_compiler2_tir::infer_context::InferContext::new(db, scope_id); let mut builder = baml_compiler2_tir::builder::TypeInferenceBuilder::new( @@ -660,7 +665,6 @@ fn impl_diagnostic_spans( #[derive(Debug, Clone)] struct ResolvedInterfaceData<'db> { loc: baml_compiler2_hir::loc::InterfaceLoc<'db>, - iface: baml_compiler2_hir::item_tree::Interface, qtn: QualifiedTypeName, } @@ -676,11 +680,31 @@ fn resolve_interface_path<'db>( pkg_items, namespace_path, )?; - let item_tree = baml_compiler2_hir::file_item_tree(db, resolved.loc.file(db)); - let iface = item_tree.interfaces.get(&resolved.loc.id(db))?.clone(); Some(ResolvedInterfaceData { loc: resolved.loc, - iface, + qtn: resolved.qtn, + }) +} + +/// The `TypeRef`-arena twin of [`resolve_interface_path`], for walking a +/// `requires` target held as firewall data (`interface_data(…).type_refs` plus a +/// `TypeRefId`) rather than an AST node. +fn resolve_interface_ref<'db>( + db: &'db dyn Db, + store: &baml_compiler2_hir::type_ref::TypeRefStore, + target: baml_compiler2_hir::type_ref::TypeRefId, + pkg_items: &baml_compiler2_hir::package::PackageItems<'db>, + namespace_path: &[Name], +) -> Option> { + let resolved = baml_compiler2_tir::interfaces::resolve_ref_to_interface_identity( + db, + store, + target, + pkg_items, + namespace_path, + )?; + Some(ResolvedInterfaceData { + loc: resolved.loc, qtn: resolved.qtn, }) } @@ -1184,8 +1208,8 @@ fn associated_type_projection_sources_for_interface_bound( if !visited.insert(current.qtn.clone()) { continue; } - if current - .iface + let iface = baml_compiler2_ppir::item_data::interface_data(db, current.loc); + if iface .associated_types .iter() .any(|assoc| assoc.name == *member) @@ -1197,10 +1221,14 @@ fn associated_type_projection_sources_for_interface_bound( let current_pkg_id = baml_compiler2_hir::package::PackageId::new(db, current_pkg.package.clone()); let current_pkg_items = baml_compiler2_hir::package::package_items(db, current_pkg_id); - for parent in ¤t.iface.requires { - if let Some(parent) = - resolve_interface_path(db, parent, current_pkg_items, ¤t_pkg.namespace_path) - { + for &parent in &iface.requires { + if let Some(parent) = resolve_interface_ref( + db, + &iface.type_refs, + parent, + current_pkg_items, + ¤t_pkg.namespace_path, + ) { stack.push(parent); } } @@ -1212,7 +1240,7 @@ fn associated_type_projection_sources_for_interface_bound( fn check_jinja_templates( db: &dyn Db, file_id: FileId, - item_tree: &baml_compiler2_hir::item_tree::ItemTree, + file: SourceFile, pkg_items: &baml_compiler2_hir::package::PackageItems<'_>, namespace_path: &[Name], source_text: &str, @@ -1220,11 +1248,11 @@ fn check_jinja_templates( let base_types = build_jinja_types(db, pkg_items, namespace_path); let mut diagnostics = Vec::new(); - for func_data in item_tree.functions.values() { + for &func_loc in baml_compiler2_ppir::item_data::file_functions(db, file) { diagnostics.extend(check_llm_prompt_template( db, file_id, - func_data, + func_loc, pkg_items, namespace_path, &base_types, @@ -1232,7 +1260,8 @@ fn check_jinja_templates( )); } - for template in item_tree.template_strings.values() { + for &template_loc in baml_compiler2_ppir::item_data::file_template_strings(db, file) { + let template = baml_compiler2_ppir::item_data::template_string_data(db, template_loc); let Some(body) = &template.body else { continue; }; @@ -1241,16 +1270,16 @@ fn check_jinja_templates( types.start_scope(); for param in &template.params { let ty = param - .type_expr - .as_ref() - .map(|type_expr| { - jinja_type_from_type_expr(db, type_expr, pkg_items, namespace_path) + .type_ref + .map(|id| { + jinja_type_from_type_ref(db, &template.type_refs, id, pkg_items, namespace_path) }) .unwrap_or(sys_jinja_types::Type::Unknown); types.add_variable(param.name.as_str(), ty); } - let range_hint = template.span; + let range_hint = + baml_compiler2_ppir::item_data::template_string_source_map(db, template_loc).span; diagnostics.extend(render_jinja_validation_result( file_id, source_text, @@ -1266,26 +1295,25 @@ fn check_jinja_templates( fn check_llm_prompt_template( db: &dyn Db, file_id: FileId, - func_data: &baml_compiler2_hir::item_tree::Function, + func_loc: baml_compiler2_hir::loc::FunctionLoc<'_>, pkg_items: &baml_compiler2_hir::package::PackageItems<'_>, namespace_path: &[Name], base_types: &sys_jinja_types::PredefinedTypes, source_text: &str, ) -> Vec { - let Some(baml_compiler2_ast::DeclarativeMeta::Llm(llm)) = &func_data.declarative_meta else { - return Vec::new(); - }; - let Some(prompt) = &llm.prompt else { + let Some(prompt) = baml_compiler2_ppir::item_data::function_llm_prompt(db, func_loc) else { return Vec::new(); }; + let func_data = baml_compiler2_ppir::item_data::function_data(db, func_loc); let mut types = base_types.clone(); types.start_scope(); for param in &func_data.params { let ty = param - .type_expr - .as_ref() - .map(|type_expr| jinja_type_from_type_expr(db, type_expr, pkg_items, namespace_path)) + .type_ref + .map(|id| { + jinja_type_from_type_ref(db, &func_data.type_refs, id, pkg_items, namespace_path) + }) .unwrap_or(sys_jinja_types::Type::Unknown); types.add_variable(param.name.as_str(), ty); } @@ -1319,8 +1347,7 @@ fn build_jinja_types( continue; }; let file = class_loc.file(db); - let item_tree = baml_compiler2_ppir::file_item_tree(db, file); - let class_data = &item_tree[class_loc.id(db)]; + let class_data = baml_compiler2_ppir::item_data::class_data(db, class_loc); let class_namespace = baml_compiler2_hir::file_package::file_package(db, file).namespace_path; let fields = class_data @@ -1328,10 +1355,15 @@ fn build_jinja_types( .iter() .map(|field| { let ty = field - .type_expr - .as_ref() - .map(|type_expr| { - jinja_type_from_type_expr(db, type_expr, pkg_items, &class_namespace) + .type_ref + .map(|id| { + jinja_type_from_type_ref( + db, + &class_data.type_refs, + id, + pkg_items, + &class_namespace, + ) }) .unwrap_or(sys_jinja_types::Type::Unknown); (field.name.to_string(), ty) @@ -1344,8 +1376,7 @@ fn build_jinja_types( let Definition::Enum(enum_loc) = *def else { continue; }; - let item_tree = baml_compiler2_ppir::file_item_tree(db, enum_loc.file(db)); - let enum_data = &item_tree[enum_loc.id(db)]; + let enum_data = baml_compiler2_ppir::item_data::enum_data(db, enum_loc); types.add_enum( enum_data.name.as_str(), enum_data @@ -1361,14 +1392,19 @@ fn build_jinja_types( continue; }; let file = alias_loc.file(db); - let item_tree = baml_compiler2_ppir::file_item_tree(db, file); - let alias_data = &item_tree[alias_loc.id(db)]; - if let Some(type_expr) = &alias_data.type_expr { + let alias_data = baml_compiler2_ppir::item_data::type_alias_data(db, alias_loc); + if let Some(id) = alias_data.value { let alias_namespace = baml_compiler2_hir::file_package::file_package(db, file).namespace_path; types.add_alias( alias_data.name.as_str(), - jinja_type_from_type_expr(db, type_expr, pkg_items, &alias_namespace), + jinja_type_from_type_ref( + db, + &alias_data.type_refs, + id, + pkg_items, + &alias_namespace, + ), ); } } @@ -1378,8 +1414,7 @@ fn build_jinja_types( continue; }; let file = template_loc.file(db); - let item_tree = baml_compiler2_ppir::file_item_tree(db, file); - let template = &item_tree[template_loc.id(db)]; + let template = baml_compiler2_ppir::item_data::template_string_data(db, template_loc); let template_namespace = baml_compiler2_hir::file_package::file_package(db, file).namespace_path; let args = template @@ -1387,10 +1422,15 @@ fn build_jinja_types( .iter() .map(|param| { let ty = param - .type_expr - .as_ref() - .map(|type_expr| { - jinja_type_from_type_expr(db, type_expr, pkg_items, &template_namespace) + .type_ref + .map(|id| { + jinja_type_from_type_ref( + db, + &template.type_refs, + id, + pkg_items, + &template_namespace, + ) }) .unwrap_or(sys_jinja_types::Type::Unknown); (param.name.to_string(), ty) @@ -1402,82 +1442,88 @@ fn build_jinja_types( types } -fn jinja_type_from_type_expr( +fn jinja_type_from_type_ref( db: &dyn Db, - type_expr: &baml_compiler2_ast::TypeExpr, + store: &baml_compiler2_hir::type_ref::TypeRefStore, + id: baml_compiler2_hir::type_ref::TypeRefId, pkg_items: &baml_compiler2_hir::package::PackageItems<'_>, namespace_path: &[Name], ) -> sys_jinja_types::Type { - jinja_type_from_type_expr_inner( + jinja_type_from_type_ref_inner( db, - type_expr, + store, + id, pkg_items, namespace_path, &mut HashSet::new(), ) } -fn jinja_type_from_type_expr_inner( +fn jinja_type_from_type_ref_inner( db: &dyn Db, - type_expr: &baml_compiler2_ast::TypeExpr, + store: &baml_compiler2_hir::type_ref::TypeRefStore, + id: baml_compiler2_hir::type_ref::TypeRefId, pkg_items: &baml_compiler2_hir::package::PackageItems<'_>, namespace_path: &[Name], resolving_aliases: &mut HashSet, ) -> sys_jinja_types::Type { - use baml_compiler2_ast::TypeExprKind; - use baml_compiler2_hir::contributions::Definition; + use baml_compiler2_hir::{contributions::Definition, type_ref::TypeRefKind}; use sys_jinja_types::Type; - match &type_expr.kind { - TypeExprKind::Int { .. } => Type::Int, - TypeExprKind::Bigint { .. } => Type::Bigint, - TypeExprKind::Float { .. } => Type::Float, - TypeExprKind::String { .. } => Type::String, - TypeExprKind::Bool { .. } => Type::Bool, - TypeExprKind::Null { .. } => Type::None, - TypeExprKind::Media { kind, .. } => match kind { + match &store[id].kind { + TypeRefKind::Int => Type::Int, + TypeRefKind::Bigint => Type::Bigint, + TypeRefKind::Float => Type::Float, + TypeRefKind::String => Type::String, + TypeRefKind::Bool => Type::Bool, + TypeRefKind::Null => Type::None, + TypeRefKind::Media { kind } => match kind { baml_base::MediaKind::Image => Type::Image, baml_base::MediaKind::Audio => Type::Audio, _ => Type::Unknown, }, - TypeExprKind::Literal { value, .. } => Type::Literal(value.clone()), - TypeExprKind::Optional { inner, .. } => Type::merge([ + TypeRefKind::Literal { value } => Type::Literal(value.clone()), + TypeRefKind::Optional { inner } => Type::merge([ Type::None, - jinja_type_from_type_expr_inner( + jinja_type_from_type_ref_inner( db, - inner, + store, + *inner, pkg_items, namespace_path, resolving_aliases, ), ]), - TypeExprKind::List { inner, .. } => Type::List(Box::new(jinja_type_from_type_expr_inner( + TypeRefKind::List { inner } => Type::List(Box::new(jinja_type_from_type_ref_inner( db, - inner, + store, + *inner, pkg_items, namespace_path, resolving_aliases, ))), - TypeExprKind::Map { value, .. } => Type::Map( + TypeRefKind::Map { value, .. } => Type::Map( Box::new(Type::String), - Box::new(jinja_type_from_type_expr_inner( + Box::new(jinja_type_from_type_ref_inner( db, - value, + store, + *value, pkg_items, namespace_path, resolving_aliases, )), ), - TypeExprKind::Union { variants, .. } => Type::merge(variants.iter().map(|variant| { - jinja_type_from_type_expr_inner( + TypeRefKind::Union { variants } => Type::merge(variants.iter().map(|&variant| { + jinja_type_from_type_ref_inner( db, + store, variant, pkg_items, namespace_path, resolving_aliases, ) })), - TypeExprKind::Path { segments, .. } if !segments.is_empty() => { + TypeRefKind::Path { segments, .. } if !segments.is_empty() => { let (lookup_namespace, name) = jinja_lookup_path(namespace_path, segments); let key = format!( "{}::{}", @@ -1497,17 +1543,16 @@ fn jinja_type_from_type_expr_inner( return Type::RecursiveTypeAlias(name); } let file = alias_loc.file(db); - let item_tree = baml_compiler2_ppir::file_item_tree(db, file); - let alias = &item_tree[alias_loc.id(db)]; + let alias = baml_compiler2_ppir::item_data::type_alias_data(db, alias_loc); let alias_namespace = baml_compiler2_hir::file_package::file_package(db, file).namespace_path; let resolved = alias - .type_expr - .as_ref() - .map(|spanned| { - jinja_type_from_type_expr_inner( + .value + .map(|value_id| { + jinja_type_from_type_ref_inner( db, - spanned, + &alias.type_refs, + value_id, pkg_items, &alias_namespace, resolving_aliases, @@ -1524,19 +1569,19 @@ fn jinja_type_from_type_expr_inner( _ => Type::Unknown, } } - TypeExprKind::Function { .. } | TypeExprKind::AssociatedTypeProjection { .. } => { + TypeRefKind::Function { .. } | TypeRefKind::AssociatedTypeProjection { .. } => { Type::Unknown } - TypeExprKind::Uint8Array { .. } - | TypeExprKind::Never { .. } - | TypeExprKind::Void { .. } - | TypeExprKind::BuiltinUnknown { .. } - | TypeExprKind::Type { .. } - | TypeExprKind::Rust { .. } - | TypeExprKind::Error { .. } - | TypeExprKind::Unknown { .. } - | TypeExprKind::Infer { .. } - | TypeExprKind::Path { .. } => Type::Unknown, + TypeRefKind::Uint8Array + | TypeRefKind::Never + | TypeRefKind::Void + | TypeRefKind::BuiltinUnknown + | TypeRefKind::Type + | TypeRefKind::Rust + | TypeRefKind::Error + | TypeRefKind::Unknown + | TypeRefKind::Infer + | TypeRefKind::Path { .. } => Type::Unknown, } } diff --git a/baml_language/crates/baml_lsp2_actions/src/completions.rs b/baml_language/crates/baml_lsp2_actions/src/completions.rs index 0e15f458617..6c9ffd6b5c6 100644 --- a/baml_language/crates/baml_lsp2_actions/src/completions.rs +++ b/baml_language/crates/baml_lsp2_actions/src/completions.rs @@ -28,7 +28,7 @@ //! - `package_items(builtin_pkg_id)` — builtin definitions from the `baml` //! and `env` packages. //! - `resolve_class_fields(class_loc)` — fields for field-access completions. -//! - `file_item_tree(file)[enum_loc.id]` — variants for field-access on enums. +//! - `enum_data(enum_loc)` — variants for field-access on enums. use std::collections::HashSet; @@ -981,12 +981,10 @@ fn completions_for_class_methods( class_loc: baml_compiler2_hir::loc::ClassLoc<'_>, mode: BuiltinMethodMode, ) -> Vec { - let item_tree = baml_compiler2_hir::file_item_tree(db, class_loc.file(db)); - let class_data = &item_tree[class_loc.id(db)]; + let class_data = baml_compiler2_ppir::item_data::class_data(db, class_loc); let mut items = Vec::new(); - for method_id in &class_data.methods { - let func_loc = FunctionLoc::new(db, class_loc.file(db), *method_id); + for &func_loc in &class_data.methods { let has_self = method_has_self_param(db, func_loc); if mode != BuiltinMethodMode::All && !matches!( @@ -997,7 +995,7 @@ fn completions_for_class_methods( continue; } - let method = &item_tree[*method_id]; + let method = baml_compiler2_ppir::item_data::function_data(db, func_loc); items.push( Completion::new(method.name.as_str(), CompletionKind::Method) .with_detail(format_builtin_method_signature(db, func_loc, mode)) @@ -1142,11 +1140,10 @@ fn completions_for_ty_members(db: &dyn Db, file: SourceFile, ty: &Ty) -> Vec Vec Vec) -> Option { match def { Definition::Class(class_loc) => { - let item_tree = baml_compiler2_hir::file_item_tree(db, class_loc.file(db)); - let class = &item_tree[class_loc.id(db)]; + let class = baml_compiler2_ppir::item_data::class_data(db, class_loc); let pkg_info = baml_compiler2_hir::file_package::file_package(db, class_loc.file(db)); Some(Ty::Class( baml_compiler2_tir::ty::QualifiedTypeName::new( @@ -1228,8 +1223,7 @@ fn definition_to_ty(db: &dyn Db, def: Definition<'_>) -> Option { )) } Definition::Enum(enum_loc) => { - let item_tree = baml_compiler2_hir::file_item_tree(db, enum_loc.file(db)); - let enum_data = &item_tree[enum_loc.id(db)]; + let enum_data = baml_compiler2_ppir::item_data::enum_data(db, enum_loc); let pkg_info = baml_compiler2_hir::file_package::file_package(db, enum_loc.file(db)); Some(Ty::Enum( baml_compiler2_tir::ty::QualifiedTypeName::new( @@ -1260,7 +1254,6 @@ fn local_variable_ty( match site { baml_compiler2_hir::semantic_index::DefinitionSite::Parameter(param_idx) => { // Get declared type from function or lambda signature. - let item_tree = baml_compiler2_hir::file_item_tree(db, file); let scope_id = index.scope_at_offset(at_offset, None); let ancestors = index.ancestor_scopes(scope_id); @@ -1277,12 +1270,13 @@ fn local_variable_ty( ScopeKind::Function => { // Function parameter — look up from function signature. let func_scope_range = enclosing_scope_data.range; - let (func_local_id, _) = item_tree - .functions + let func_loc = baml_compiler2_ppir::item_data::file_functions(db, file) .iter() - .find(|(_, f)| f.span == func_scope_range)?; - let func_loc = - baml_compiler2_hir::loc::FunctionLoc::new(db, file, *func_local_id); + .copied() + .find(|&loc| { + baml_compiler2_ppir::item_data::function_source_map(db, loc).span + == func_scope_range + })?; let sig = baml_compiler2_hir::signature::function_signature(db, func_loc); sig.params.get(param_idx).map(|param| { let pkg_info = baml_compiler2_hir::file_package::file_package(db, file); @@ -1347,7 +1341,6 @@ fn find_binding_ty_for_local( site: baml_compiler2_hir::semantic_index::DefinitionSite, ) -> Option { let index = baml_compiler2_hir::file_semantic_index(db, file); - let item_tree = baml_compiler2_hir::file_item_tree(db, file); let pat_id = match site { baml_compiler2_hir::semantic_index::DefinitionSite::Statement(stmt_id) => { @@ -1373,11 +1366,12 @@ fn find_binding_ty_for_local( // 2. Start from the outermost Function scope → find its body. let func_range = func_range?; - let (func_local_id, _) = item_tree - .functions + let func_loc = baml_compiler2_ppir::item_data::file_functions(db, file) .iter() - .find(|(_, f)| f.span == func_range)?; - let func_loc = FunctionLoc::new(db, file, *func_local_id); + .copied() + .find(|&loc| { + baml_compiler2_ppir::item_data::function_source_map(db, loc).span == func_range + })?; let body = baml_compiler2_hir::body::function_body(db, func_loc); let baml_compiler2_hir::body::FunctionBody::Expr(ref top_body) = *body else { return None; @@ -1553,8 +1547,7 @@ fn completions_for_value_position( (CompletionKind::RetryPolicy, "retry_policy".to_string()) } Definition::Let(loc) => { - let item_tree = baml_compiler2_hir::file_item_tree(db, loc.file(db)); - match item_tree[loc.id(db)].origin { + match baml_compiler2_ppir::item_data::let_data(db, *loc).origin { baml_compiler2_ast::ast::LetOrigin::Client => { (CompletionKind::Client, "client".to_string()) } diff --git a/baml_language/crates/baml_lsp2_actions/src/definition.rs b/baml_language/crates/baml_lsp2_actions/src/definition.rs index bbc2f567b88..3b1fae7c349 100644 --- a/baml_language/crates/baml_lsp2_actions/src/definition.rs +++ b/baml_language/crates/baml_lsp2_actions/src/definition.rs @@ -25,6 +25,7 @@ use baml_base::{Name, SourceFile}; use baml_compiler_syntax::SyntaxKind; use baml_compiler2_hir::semantic_index::DefinitionSite; +use baml_compiler2_ppir::item_data; use text_size::{TextRange, TextSize}; use crate::{Db, utils}; @@ -102,8 +103,9 @@ pub fn definition_at(db: &dyn Db, file: SourceFile, offset: TextSize) -> Option< /// Resolve a local variable's definition site to a `Location`. /// -/// Finds the enclosing function by matching the scope range against `item_tree` -/// functions, then uses the appropriate source map to get the span. +/// Finds the enclosing function by matching the scope range against each +/// function's declaration span, then uses the appropriate source map to get the +/// span. fn local_definition_location( db: &dyn Db, file: SourceFile, @@ -111,7 +113,6 @@ fn local_definition_location( site: DefinitionSite, ) -> Option { let index = baml_compiler2_hir::file_semantic_index(db, file); - let item_tree = baml_compiler2_hir::file_item_tree(db, file); // Find the enclosing Function scope to locate the function in the item tree. let scope_id = index.scope_at_offset(at_offset, None); @@ -127,13 +128,10 @@ fn local_definition_location( let func_scope_range = index.scopes[enclosing_func_scope.index() as usize].range; - // Find the function in the item tree by matching the scope range. - let (func_local_id, _) = item_tree - .functions + // Find the function by matching the scope range against its declaration span. + let func_loc = *item_data::file_functions(db, file) .iter() - .find(|(_, f)| f.span == func_scope_range)?; - - let func_loc = baml_compiler2_hir::loc::FunctionLoc::new(db, file, *func_local_id); + .find(|func_loc| item_data::function_source_map(db, **func_loc).span == func_scope_range)?; match site { DefinitionSite::Statement(stmt_id) => { @@ -169,17 +167,16 @@ fn resolve_member_at( token_text: &str, ) -> Option { let index = baml_compiler2_hir::file_semantic_index(db, file); - let item_tree = baml_compiler2_hir::file_item_tree(db, file); let scope_id = index.scope_at_offset(offset, None); let scope = &index.scopes[scope_id.index() as usize]; match scope.kind { // ── Cursor on a field/variant definition ────────────────────── baml_compiler2_hir::scope::ScopeKind::Class => { - resolve_field_definition(db, file, &item_tree, scope.name.as_ref(), token_text) + resolve_field_definition(db, file, scope.name.as_ref(), token_text) } baml_compiler2_hir::scope::ScopeKind::Enum => { - resolve_variant_definition(db, file, &item_tree, scope.name.as_ref(), token_text) + resolve_variant_definition(db, file, scope.name.as_ref(), token_text) } // ── Cursor in a function body ───────────────────────────────── @@ -198,11 +195,14 @@ fn resolve_member_at( let func_scope = &index.scopes[enclosing_func_scope.index() as usize]; - // Find the matching function in the item tree - let (func_local_id, _) = item_tree.functions.iter().find(|(_, f)| { - f.span == func_scope.range && func_scope.name.as_ref() == Some(&f.name) - })?; - let func_loc = baml_compiler2_hir::loc::FunctionLoc::new(db, file, *func_local_id); + // Find the matching function by its declaration span and name. + let func_loc = *item_data::file_functions(db, file) + .iter() + .find(|func_loc| { + item_data::function_source_map(db, **func_loc).span == func_scope.range + && func_scope.name.as_ref() + == Some(&item_data::function_data(db, **func_loc).name) + })?; // Get inference, body, source map let func_scope_id = index.scope_ids[enclosing_func_scope.index() as usize]; @@ -244,20 +244,19 @@ fn resolve_member_at( fn resolve_field_definition( db: &dyn Db, file: SourceFile, - item_tree: &baml_compiler2_hir::item_tree::ItemTree, class_name: Option<&Name>, token_text: &str, ) -> Option { let class_name = class_name?; - let source_map = baml_compiler2_hir::file_item_tree_source_map(db, file); - for (class_id, class) in &item_tree.classes { + for class_loc in item_data::file_classes(db, file) { + let class = item_data::class_data(db, *class_loc); if class.name == *class_name { - let field_spans = source_map.class_field_spans.get(class_id)?; + let source_map = item_data::class_source_map(db, *class_loc); for (i, field) in class.fields.iter().enumerate() { if field.name.as_str() == token_text { return Some(Location { file, - range: field_spans[i], + range: source_map.field_name_spans[i], }); } } @@ -270,20 +269,19 @@ fn resolve_field_definition( fn resolve_variant_definition( db: &dyn Db, file: SourceFile, - item_tree: &baml_compiler2_hir::item_tree::ItemTree, enum_name: Option<&Name>, token_text: &str, ) -> Option { let enum_name = enum_name?; - let source_map = baml_compiler2_hir::file_item_tree_source_map(db, file); - for (enum_id, enum_def) in &item_tree.enums { + for enum_loc in item_data::file_enums(db, file) { + let enum_def = item_data::enum_data(db, *enum_loc); if enum_def.name == *enum_name { - let variant_spans = source_map.enum_variant_spans.get(enum_id)?; + let source_map = item_data::enum_source_map(db, *enum_loc); for (i, variant) in enum_def.variants.iter().enumerate() { if variant.name.as_str() == token_text { return Some(Location { file, - range: variant_spans[i], + range: source_map.variant_name_spans[i], }); } } @@ -379,14 +377,12 @@ fn resolve_field_access_at( // the pre-expansion tree and would panic on index here. PPIR carries it, // and a `$stream` field's name-span is the original class field's, so // goto-definition still lands on the user-authored field. - let target_item_tree = baml_compiler2_ppir::file_item_tree(db, target_file); - let target_source_map = baml_compiler2_ppir::file_item_tree_source_map(db, target_file); - let class = &target_item_tree[class_loc.id(db)]; + let class = item_data::class_data(db, *class_loc); let field_idx = class.fields.iter().position(|f| f.name == *field_name)?; - let field_spans = target_source_map.class_field_spans.get(&class_loc.id(db))?; + let source_map = item_data::class_source_map(db, *class_loc); Some(Location { file: target_file, - range: field_spans[field_idx], + range: source_map.field_name_spans[field_idx], }) } MemberResolution::Variant { @@ -394,17 +390,15 @@ fn resolve_field_access_at( variant_name, } => { let target_file = enum_loc.file(db); - let target_item_tree = baml_compiler2_hir::file_item_tree(db, target_file); - let target_source_map = baml_compiler2_hir::file_item_tree_source_map(db, target_file); - let enum_def = &target_item_tree[enum_loc.id(db)]; + let enum_def = item_data::enum_data(db, *enum_loc); let variant_idx = enum_def .variants .iter() .position(|v| v.name == *variant_name)?; - let variant_spans = target_source_map.enum_variant_spans.get(&enum_loc.id(db))?; + let source_map = item_data::enum_source_map(db, *enum_loc); Some(Location { file: target_file, - range: variant_spans[variant_idx], + range: source_map.variant_name_spans[variant_idx], }) } MemberResolution::Free { func_loc } => { @@ -418,15 +412,12 @@ fn resolve_field_access_at( MemberResolution::BoundMethod { func_loc, .. } | MemberResolution::UnboundMethod { func_loc, .. } | MemberResolution::InterfaceConcreteMethod { func_loc, .. } => { - // Methods are not in FileSymbolContributions — use ItemTreeSourceMap. + // Methods are not in FileSymbolContributions — use the function source map. let target_file = func_loc.file(db); - let target_source_map = baml_compiler2_hir::file_item_tree_source_map(db, target_file); - let name_range = target_source_map - .function_name_spans - .get(&func_loc.id(db))?; + let name_span = item_data::function_source_map(db, *func_loc).name_span; Some(Location { file: target_file, - range: *name_range, + range: name_span, }) } MemberResolution::InterfaceVirtualMethod { iface_loc, method } => { @@ -434,47 +425,38 @@ fn resolve_field_access_at( // known statically, so navigate to the declaration in the interface — // the required signature, or the default method's definition. let target_file = iface_loc.file(db); - let target_item_tree = baml_compiler2_hir::file_item_tree(db, target_file); - let target_source_map = baml_compiler2_hir::file_item_tree_source_map(db, target_file); - let iface = &target_item_tree[iface_loc.id(db)]; + let iface = item_data::interface_data(db, *iface_loc); if let Some(method_idx) = iface .required_methods .iter() .position(|m| m.name == *method) { - let method_spans = target_source_map - .interface_method_spans - .get(&iface_loc.id(db))?; + let source_map = item_data::interface_source_map(db, *iface_loc); return Some(Location { file: target_file, - range: method_spans[method_idx], + range: source_map.required_method_spans[method_idx].name_span, }); } - let default_id = iface + let default_loc = *iface .default_methods .iter() - .copied() - .find(|&fn_id| target_item_tree[fn_id].name == *method)?; - let name_range = target_source_map.function_name_spans.get(&default_id)?; + .find(|&&fn_loc| item_data::function_data(db, fn_loc).name == *method)?; + let name_span = item_data::function_source_map(db, default_loc).name_span; Some(Location { file: target_file, - range: *name_range, + range: name_span, }) } MemberResolution::InterfaceVirtualField { iface_loc, field } => { // A virtual interface-field access: navigate to the field declaration // in the declaring interface. let target_file = iface_loc.file(db); - let target_item_tree = baml_compiler2_hir::file_item_tree(db, target_file); - let target_source_map = baml_compiler2_hir::file_item_tree_source_map(db, target_file); - let iface = &target_item_tree[iface_loc.id(db)]; + let iface = item_data::interface_data(db, *iface_loc); let field_idx = iface.fields.iter().position(|f| f.name == *field)?; - let field_spans = target_source_map - .interface_field_spans - .get(&iface_loc.id(db))?; + let source_map = item_data::interface_source_map(db, *iface_loc); Some(Location { file: target_file, - range: field_spans[field_idx], + range: source_map.field_name_spans[field_idx], }) } } @@ -519,19 +501,17 @@ fn resolve_constructor_field_at( return None; }; - // Look up field name_span in ItemTreeSourceMap + // Look up field name_span via the class source map. let target_file = class_loc.file(db); - let target_item_tree = baml_compiler2_hir::file_item_tree(db, target_file); - let target_source_map = baml_compiler2_hir::file_item_tree_source_map(db, target_file); - let class = &target_item_tree[class_loc.id(db)]; + let class = item_data::class_data(db, class_loc); let field_idx = class .fields .iter() .position(|f| f.name.as_str() == token_text)?; - let field_spans = target_source_map.class_field_spans.get(&class_loc.id(db))?; + let source_map = item_data::class_source_map(db, class_loc); return Some(Location { file: target_file, - range: field_spans[field_idx], + range: source_map.field_name_spans[field_idx], }); } } diff --git a/baml_language/crates/baml_lsp2_actions/src/describe.rs b/baml_language/crates/baml_lsp2_actions/src/describe.rs index 0a13f7d7fce..72340f9b0a3 100644 --- a/baml_language/crates/baml_lsp2_actions/src/describe.rs +++ b/baml_language/crates/baml_lsp2_actions/src/describe.rs @@ -6,7 +6,8 @@ //! dependencies, and reference sites. //! //! This is a regular function (not a Salsa query). Internally it calls -//! Salsa-cached queries (`file_outline`, `file_item_tree`, `syntax_tree`, etc.). +//! Salsa-cached queries (`file_outline`, the `item_data` firewall, `syntax_tree`, +//! etc.). use baml_base::SourceFile; use baml_compiler_syntax::SyntaxKind; @@ -424,11 +425,11 @@ fn describe_locals(db: &dyn Db, files: &[SourceFile], name: &str) -> Vec Vec Vec Vec Vec Vec Vec Vec( /// Build a `DepRef` pointing to a function. fn make_function_dep( db: &dyn crate::Db, - file: SourceFile, - func_id: baml_compiler2_hir::ids::LocalItemId, + func_loc: baml_compiler2_hir::loc::FunctionLoc<'_>, func_name: &str, ) -> DepRef { - let item_tree = baml_compiler2_hir::file_item_tree(db, file); - let source_map = baml_compiler2_hir::file_item_tree_source_map(db, file); - let name_span = source_map - .function_name_spans - .get(&func_id) - .copied() - .unwrap_or_else(|| item_tree[func_id].span); + let file = func_loc.file(db); + let source_map = baml_compiler2_ppir::item_data::function_source_map(db, func_loc); + // `function_source_map` fills a missing name span with `TextRange::default()` + // (empty at offset 0); a real named function's name span is never that, so + // fall back to the full declaration span in that (spanless) case. + let name_span = if source_map.name_span == TextRange::default() { + source_map.span + } else { + source_map.name_span + }; DepRef { name: func_name.to_string(), kind: DefinitionKind::Function, @@ -868,8 +871,7 @@ fn collect_class_methods_impl( use baml_compiler2_tir::package_interface::ExportedType; let file = class_loc.file(db); - let item_tree = baml_compiler2_hir::file_item_tree(db, file); - let class_data = &item_tree[class_loc.id(db)]; + let class_data = baml_compiler2_ppir::item_data::class_data(db, class_loc); // Resolved param/return/throws types come from the package interface, which // lowers class methods 1:1 with `class_data.methods` (same order, including @@ -886,8 +888,8 @@ fn collect_class_methods_impl( let file_path = file_path_string(db, file); let mut out = Vec::new(); - for (idx, method_id) in class_data.methods.iter().enumerate() { - let m = &item_tree[*method_id]; + for (idx, &method_loc) in class_data.methods.iter().enumerate() { + let m = baml_compiler2_ppir::item_data::function_data(db, method_loc); if matches!( m.origin, baml_compiler2_ast::ast::FunctionOrigin::AutoDerive @@ -898,7 +900,7 @@ fn collect_class_methods_impl( let signature = render_method_signature( db, file, - m, + method_loc, exported.and_then(|ms| exported_method(ms, idx, &m.name)), ); let docstring = m @@ -911,7 +913,7 @@ fn collect_class_methods_impl( docstring, file, file_path: file_path.clone(), - item_range: m.span, + item_range: baml_compiler2_ppir::item_data::function_source_map(db, method_loc).span, is_instance, }); } @@ -926,9 +928,10 @@ fn collect_class_methods_impl( fn render_method_signature( db: &dyn Db, file: SourceFile, - m: &baml_compiler2_hir::item_tree::Function, + func_loc: baml_compiler2_hir::loc::FunctionLoc<'_>, exported: Option<&baml_compiler2_tir::package_interface::ExportedFunction>, ) -> String { + let m = baml_compiler2_ppir::item_data::function_data(db, func_loc); let params: Vec = m .params .iter() @@ -941,9 +944,12 @@ fn render_method_signature( let ty = exported .and_then(|ef| ef.params.get(i)) .map(|fp| crate::utils::display_ty_canonical_for_file(db, file, &fp.ty)) - .or_else(|| p.type_expr.as_ref().map(crate::utils::display_type_expr)) + .or_else(|| { + p.type_ref + .map(|id| crate::utils::display_type_ref(&m.type_refs, id)) + }) .unwrap_or_else(|| "unknown".to_string()); - let opt = if p.default.is_some() { "?" } else { "" }; + let opt = if p.has_default { "?" } else { "" }; format!("{pname}{opt}: {ty}") }) .collect(); @@ -951,7 +957,10 @@ fn render_method_signature( let ret = if m.return_type.is_some() { let ty = exported .map(|ef| crate::utils::display_ty_canonical_for_file(db, file, &ef.return_type)) - .or_else(|| m.return_type.as_ref().map(crate::utils::display_type_expr)) + .or_else(|| { + m.return_type + .map(|id| crate::utils::display_type_ref(&m.type_refs, id)) + }) .unwrap_or_default(); format!(" -> {ty}") } else { @@ -970,8 +979,12 @@ fn render_method_signature( Some(_) => String::new(), None => m .throws - .as_ref() - .map(|te| format!(" throws {}", crate::utils::display_type_expr(te))) + .map(|id| { + format!( + " throws {}", + crate::utils::display_type_ref(&m.type_refs, id) + ) + }) .unwrap_or_default(), }; @@ -1036,19 +1049,19 @@ fn describe_class_method( use baml_compiler2_tir::package_interface::ExportedType; let file = class_loc.file(db); - let item_tree = baml_compiler2_hir::file_item_tree(db, file); - let class_data = &item_tree[class_loc.id(db)]; + let class_data = baml_compiler2_ppir::item_data::class_data(db, class_loc); // Locate the (non-auto-derived) method by name. - let (idx, method_id) = class_data.methods.iter().enumerate().find(|(_, mid)| { - let m = &item_tree[**mid]; + let (idx, &method_loc) = class_data.methods.iter().enumerate().find(|(_, mid)| { + let m = baml_compiler2_ppir::item_data::function_data(db, **mid); m.name.as_str() == member_name && !matches!( m.origin, baml_compiler2_ast::ast::FunctionOrigin::AutoDerive ) })?; - let m = &item_tree[*method_id]; + let m = baml_compiler2_ppir::item_data::function_data(db, method_loc); + let method_span = baml_compiler2_ppir::item_data::function_source_map(db, method_loc).span; let pkg_info = baml_compiler2_hir::file_package::file_package(db, file); let pkg_id = baml_compiler2_hir::package::PackageId::new(db, pkg_info.package.clone()); @@ -1059,20 +1072,20 @@ fn describe_class_method( ExportedType::Class { methods, .. } => exported_method(methods, idx, &m.name), _ => None, }); - let signature = render_method_signature(db, file, m, ef); + let signature = render_method_signature(db, file, method_loc, ef); // Drill-in shows the body; a builtin native body is elided to the signature. let full_body = if matches!( - m.body, - Some(baml_compiler2_ast::ast::FunctionBodyDef::Builtin(_)) + baml_compiler2_ppir::function_body(db, method_loc).as_ref(), + baml_compiler2_hir::body::FunctionBody::Builtin(_) ) { signature.clone() } else { - clean_body_source(db, file, m.span) + clean_body_source(db, file, method_span) }; - let name_span = function_def_name_span(db, file, m.span, member_name) - .unwrap_or_else(|| TextRange::empty(m.span.start())); + let name_span = function_def_name_span(db, file, method_span, member_name) + .unwrap_or_else(|| TextRange::empty(method_span.start())); // The owning class is the container. let container = @@ -1086,7 +1099,7 @@ fn describe_class_method( } }); - let references = find_references(db, files, file, name_span, m.span); + let references = find_references(db, files, file, name_span, method_span); Some(SymbolDescription { name: m.name.as_str().to_string(), @@ -1094,7 +1107,7 @@ fn describe_class_method( file_path: file_path_string(db, file), file, name_span, - item_range: m.span, + item_range: method_span, shape: signature.clone(), full_body, docstring: m.docstring.clone(), @@ -1164,14 +1177,13 @@ fn collect_method_signature_deps( use baml_compiler2_tir::package_interface::ExportedType; let file = class_loc.file(db); - let item_tree = baml_compiler2_hir::file_item_tree(db, file); - let class_data = &item_tree[class_loc.id(db)]; + let class = baml_compiler2_ppir::item_data::class_data(db, class_loc); let pkg_info = baml_compiler2_hir::file_package::file_package(db, file); let pkg_id = baml_compiler2_hir::package::PackageId::new(db, pkg_info.package.clone()); let iface = baml_compiler2_tir::package_interface::package_interface(db, pkg_id); let Some(methods) = iface - .lookup_type(&pkg_info.namespace_path, &class_data.name) + .lookup_type(&pkg_info.namespace_path, &class.name) .and_then(|t| match t { ExportedType::Class { methods, .. } => Some(methods), _ => None, @@ -1180,8 +1192,8 @@ fn collect_method_signature_deps( return; }; - for (idx, method_id) in class_data.methods.iter().enumerate() { - let m = &item_tree[*method_id]; + for (idx, method_loc) in class.methods.iter().enumerate() { + let m = baml_compiler2_ppir::item_data::function_data(db, *method_loc); if matches!( m.origin, baml_compiler2_ast::ast::FunctionOrigin::AutoDerive @@ -1375,29 +1387,26 @@ fn find_dependencies( // Enums are self-contained, no type dependencies. } baml_compiler2_hir::contributions::Definition::Interface(iface_loc) => { - let item_tree = baml_compiler2_hir::file_item_tree(db, file); - let iface = &item_tree[iface_loc.id(db)]; + let iface = baml_compiler2_ppir::item_data::interface_data(db, iface_loc); for field in &iface.fields { - if let Some(te) = &field.type_expr { - collect_type_expr_deps(db, file, te, &mut deps, &mut seen); + if let Some(id) = field.type_ref { + collect_type_ref_deps(db, file, &iface.type_refs, id, &mut deps, &mut seen); } } - for parent in &iface.requires { - collect_type_expr_deps(db, file, parent, &mut deps, &mut seen); + for &parent in &iface.requires { + collect_type_ref_deps(db, file, &iface.type_refs, parent, &mut deps, &mut seen); } } baml_compiler2_hir::contributions::Definition::TypeAlias(alias_loc) => { - // Walk the alias's target type expression. - let item_tree = baml_compiler2_hir::file_item_tree(db, file); - let alias = &item_tree[alias_loc.id(db)]; - if let Some(spanned_te) = &alias.type_expr { - collect_type_expr_deps(db, file, spanned_te, &mut deps, &mut seen); + // Walk the alias's target type reference. + let alias = baml_compiler2_ppir::item_data::type_alias_data(db, alias_loc); + if let Some(id) = alias.value { + collect_type_ref_deps(db, file, &alias.type_refs, id, &mut deps, &mut seen); } } baml_compiler2_hir::contributions::Definition::Client(client_loc) => { // Surface the retry policy reference if present. - let item_tree = baml_compiler2_hir::file_item_tree(db, file); - let client = &item_tree[client_loc.id(db)]; + let client = baml_compiler2_ppir::item_data::client_data(db, client_loc); if let Some(ref policy_name) = client.retry_policy_name { let name_str = policy_name.as_str().to_string(); if seen.insert(name_str.clone()) { @@ -1409,8 +1418,7 @@ fn find_dependencies( } baml_compiler2_hir::contributions::Definition::Test(test_loc) => { // Extract the test's function references. - let item_tree = baml_compiler2_hir::file_item_tree(db, file); - let test = &item_tree[test_loc.id(db)]; + let test = baml_compiler2_ppir::item_data::test_data(db, test_loc); for func_name in &test.function_refs { let name_str = func_name.as_str().to_string(); if seen.insert(name_str.clone()) { @@ -1491,6 +1499,70 @@ fn collect_type_expr_deps( } } +/// Span-free twin of [`collect_type_expr_deps`], walking a `TypeRefStore` arena +/// (the firewall's item-data type-reference representation) instead of a spanned +/// `ast::TypeExpr`. Behavior is identical: only the last path segment is treated +/// as a candidate dependency name; associated-type projections and primitives +/// contribute none. +fn collect_type_ref_deps( + db: &dyn Db, + file: SourceFile, + store: &baml_compiler2_hir::type_ref::TypeRefStore, + id: baml_compiler2_hir::type_ref::TypeRefId, + deps: &mut Vec, + seen: &mut std::collections::HashSet, +) { + use baml_compiler2_hir::type_ref::TypeRefKind; + match &store[id].kind { + TypeRefKind::Path { + segments, + generic_args, + .. + } => { + if let Some(last) = segments.last() { + let name_str = last.as_str().to_string(); + if seen.insert(name_str.clone()) { + // Try to resolve this name to find its definition. + if let Some(dep) = resolve_dep(db, file, &name_str) { + deps.push(dep); + } + } + } + for &ga in generic_args { + collect_type_ref_deps(db, file, store, ga, deps, seen); + } + } + TypeRefKind::Optional { inner } | TypeRefKind::List { inner } => { + collect_type_ref_deps(db, file, store, *inner, deps, seen); + } + TypeRefKind::Map { key, value } => { + collect_type_ref_deps(db, file, store, *key, deps, seen); + collect_type_ref_deps(db, file, store, *value, deps, seen); + } + TypeRefKind::Union { variants } => { + for &v in variants { + collect_type_ref_deps(db, file, store, v, deps, seen); + } + } + TypeRefKind::Function { + params, + ret, + throws, + } => { + for p in params { + collect_type_ref_deps(db, file, store, p.ty, deps, seen); + } + collect_type_ref_deps(db, file, store, *ret, deps, seen); + if let Some(throws) = throws { + collect_type_ref_deps(db, file, store, *throws, deps, seen); + } + } + // Primitives, literals, and associated-type projections have no + // user-defined deps (matching `collect_type_expr_deps`). + _ => {} + } +} + /// Walk a resolved Ty and collect user-defined type names as `DepRefs`. /// Resolve a qualified type name to a dependency via outline search and push it /// (deduped). Only **local** (user-package) types are surfaced: builtin and @@ -1752,10 +1824,9 @@ fn builtin_signature_range( let Definition::Function(func_loc) = def? else { return None; }; - let item_tree = baml_compiler2_hir::file_item_tree(db, func_loc.file(db)); if !matches!( - item_tree[func_loc.id(db)].body, - Some(baml_compiler2_ast::ast::FunctionBodyDef::Builtin(_)) + baml_compiler2_ppir::function_body(db, func_loc).as_ref(), + baml_compiler2_hir::body::FunctionBody::Builtin(_) ) { return None; } diff --git a/baml_language/crates/baml_lsp2_actions/src/lib.rs b/baml_language/crates/baml_lsp2_actions/src/lib.rs index 6a9cdfe9023..31ea6017c97 100644 --- a/baml_language/crates/baml_lsp2_actions/src/lib.rs +++ b/baml_language/crates/baml_lsp2_actions/src/lib.rs @@ -12,8 +12,8 @@ //! ## Phase 2 //! //! - `file_outline(db, file) -> &Vec` — Salsa tracked query that -//! builds a hierarchical symbol tree from `file_symbol_contributions` and -//! `file_item_tree`. Cached per file revision. +//! builds a hierarchical symbol tree from `file_symbol_contributions` and the +//! item-data firewall queries. Cached per file revision. //! - `search_symbols(db, files, query) -> Vec` — regular function //! that iterates files calling `file_outline` and filters by query string. //! Used for `workspace/symbol` and as a helper for `textDocument/documentSymbol`. diff --git a/baml_language/crates/baml_lsp2_actions/src/outline.rs b/baml_language/crates/baml_lsp2_actions/src/outline.rs index c1fd6223632..bb10a48940e 100644 --- a/baml_language/crates/baml_lsp2_actions/src/outline.rs +++ b/baml_language/crates/baml_lsp2_actions/src/outline.rs @@ -6,8 +6,8 @@ //! functions" rule. It is a Salsa tracked query because: //! //! - Both `textDocument/documentSymbol` and `workspace/symbol` need it. -//! - It depends only on `file_symbol_contributions` + `file_item_tree`, -//! both of which are Salsa-cached per file revision. +//! - It depends only on `file_symbol_contributions` + the PPIR item-data +//! firewall queries, all of which are Salsa-cached per file revision. //! - Workspace symbol search iterates all files — caching per-file outlines //! avoids redundant work. //! @@ -15,7 +15,8 @@ //! //! Top-level items come from `file_symbol_contributions` (which carries the //! `name_span` for each item). Children (class fields, enum variants, methods) -//! come from the corresponding entry in `file_item_tree`. +//! come from the corresponding PPIR item-data firewall query +//! (`class_data`/`class_source_map`, `enum_data`/`enum_source_map`, …). //! //! Note: `ClassField` and `EnumVariant` in the item tree do not carry a source //! span of their own (Risk #1 from the plan). For Phase 2, children use a @@ -23,9 +24,10 @@ //! to `ClassField` / `EnumVariant` in the HIR item tree. use baml_base::SourceFile; -use baml_compiler2_hir::{ - contributions::DefinitionKind, file_item_tree, file_item_tree_source_map, - file_symbol_contributions, +use baml_compiler2_hir::{contributions::DefinitionKind, file_symbol_contributions}; +use baml_compiler2_ppir::item_data::{ + class_data, class_source_map, enum_data, enum_source_map, function_data, function_source_map, + let_data, }; use text_size::TextRange; @@ -55,16 +57,14 @@ pub struct OutlineItem { /// Hierarchical symbol outline for a single file. /// /// Salsa tracked query — cached per file revision. Both `file_symbol_contributions` -/// and `file_item_tree` are Salsa-cached, so this query is cheap to re-evaluate -/// when the file hasn't changed. +/// and the PPIR item-data firewall queries are Salsa-cached, so this query is +/// cheap to re-evaluate when the file hasn't changed. /// /// Returns `Vec` in the order contributions appear (types first, /// then values, preserving declaration order within each group). #[salsa::tracked(returns(ref))] pub fn file_outline(db: &dyn Db, file: SourceFile) -> Vec { let contribs = file_symbol_contributions(db, file); - let item_tree = file_item_tree(db, file); - let source_map = file_item_tree_source_map(db, file); let mut items: Vec = Vec::new(); @@ -74,8 +74,8 @@ pub fn file_outline(db: &dyn Db, file: SourceFile) -> Vec { let children = match contrib.definition { Definition::Class(class_loc) => { - let class = &item_tree[class_loc.id(db)]; - let field_spans = source_map.class_field_spans.get(&class_loc.id(db)); + let class = class_data(db, class_loc); + let field_name_spans = &class_source_map(db, class_loc).field_name_spans; let mut child_items: Vec = Vec::new(); @@ -84,20 +84,21 @@ pub fn file_outline(db: &dyn Db, file: SourceFile) -> Vec { child_items.push(OutlineItem { name: field.name.to_string(), kind: DefinitionKind::Field, - name_span: field_spans - .and_then(|spans| spans.get(i).copied()) + name_span: field_name_spans + .get(i) + .copied() .unwrap_or_else(|| TextRange::empty(TextRange::default().start())), children: Vec::new(), }); } - // Methods — look up in item_tree via their LocalItemId. + // Methods — resolve each `FunctionLoc` via the firewall. // Skip auto-derived methods (e.g. synthesized `to_json` / // `from_json`): they have no source-level span, so attempting // to describe them via `describe_item_member` would fail when // it tries to slice the source text. - for method_id in &class.methods { - let method = &item_tree[*method_id]; + for method_loc in &class.methods { + let method = function_data(db, *method_loc); if matches!( method.origin, baml_compiler2_ast::ast::FunctionOrigin::AutoDerive @@ -107,7 +108,9 @@ pub fn file_outline(db: &dyn Db, file: SourceFile) -> Vec { child_items.push(OutlineItem { name: method.name.to_string(), kind: DefinitionKind::Method, - name_span: TextRange::empty(method.span.start()), + name_span: TextRange::empty( + function_source_map(db, *method_loc).span.start(), + ), children: Vec::new(), }); } @@ -116,8 +119,8 @@ pub fn file_outline(db: &dyn Db, file: SourceFile) -> Vec { } Definition::Enum(enum_loc) => { - let enum_def = &item_tree[enum_loc.id(db)]; - let variant_spans = source_map.enum_variant_spans.get(&enum_loc.id(db)); + let enum_def = enum_data(db, enum_loc); + let variant_name_spans = &enum_source_map(db, enum_loc).variant_name_spans; enum_def .variants @@ -126,8 +129,9 @@ pub fn file_outline(db: &dyn Db, file: SourceFile) -> Vec { .map(|(i, v)| OutlineItem { name: v.name.to_string(), kind: DefinitionKind::Variant, - name_span: variant_spans - .and_then(|spans| spans.get(i).copied()) + name_span: variant_name_spans + .get(i) + .copied() .unwrap_or_else(|| TextRange::empty(TextRange::default().start())), children: Vec::new(), }) @@ -155,7 +159,7 @@ pub fn file_outline(db: &dyn Db, file: SourceFile) -> Vec { // (Client or RetryPolicy) rather than the generic `Let` kind. let kind = match contrib.definition { baml_compiler2_hir::contributions::Definition::Let(loc) => { - match item_tree[loc.id(db)].origin { + match let_data(db, loc).origin { baml_compiler2_ast::ast::LetOrigin::Client => DefinitionKind::Client, baml_compiler2_ast::ast::LetOrigin::RetryPolicy => DefinitionKind::RetryPolicy, baml_compiler2_ast::ast::LetOrigin::Source => DefinitionKind::Let, diff --git a/baml_language/crates/baml_lsp2_actions/src/type_info.rs b/baml_language/crates/baml_lsp2_actions/src/type_info.rs index acb4d3fd7bf..66e7a0c2a26 100644 --- a/baml_language/crates/baml_lsp2_actions/src/type_info.rs +++ b/baml_language/crates/baml_lsp2_actions/src/type_info.rs @@ -13,7 +13,7 @@ //! with field names and types from `resolve_class_fields`. //! //! - `ResolvedName::Item(Definition::Enum(_))` — builds `TypeInfo::Enum` -//! with variant names from the item tree. +//! with variant names from `enum_data`. //! //! - `ResolvedName::Item(Definition::TypeAlias(_))` — builds `TypeInfo::TypeAlias` //! with the expansion type from `resolve_type_alias`. @@ -380,8 +380,7 @@ pub fn type_info_for_definition(db: &dyn Db, def: Definition<'_>) -> TypeInfo { } Definition::Class(class_loc) => { - let item_tree = baml_compiler2_hir::file_item_tree(db, class_loc.file(db)); - let class_data = &item_tree[class_loc.id(db)]; + let class_data = baml_compiler2_ppir::item_data::class_data(db, class_loc); let class_name = class_data.name.as_str().to_string(); // Use resolved field types (Salsa-cached), rendered canonically so @@ -397,10 +396,13 @@ pub fn type_info_for_definition(db: &dyn Db, def: Definition<'_>) -> TypeInfo { ) }) .collect(); + // `implements` targets and associated-type bindings are unresolved + // type references rendered via the arena-backed `TypeRef` renderer + // (byte-identical to `ast::TypeExpr`'s `Display`). let implements = class_data .implements .iter() - .map(render_implements_block) + .map(|block| render_implements_block(block, &class_data.type_refs)) .collect(); let qtn = baml_compiler2_tir::lower_type_expr::qualify_def(db, def, &class_data.name); @@ -425,8 +427,7 @@ pub fn type_info_for_definition(db: &dyn Db, def: Definition<'_>) -> TypeInfo { } Definition::Enum(enum_loc) => { - let item_tree = baml_compiler2_hir::file_item_tree(db, enum_loc.file(db)); - let enum_data = &item_tree[enum_loc.id(db)]; + let enum_data = baml_compiler2_ppir::item_data::enum_data(db, enum_loc); let variants = enum_data .variants .iter() @@ -439,8 +440,7 @@ pub fn type_info_for_definition(db: &dyn Db, def: Definition<'_>) -> TypeInfo { } Definition::Interface(iface_loc) => { - let item_tree = baml_compiler2_hir::file_item_tree(db, iface_loc.file(db)); - let iface = &item_tree[iface_loc.id(db)]; + let iface = baml_compiler2_ppir::item_data::interface_data(db, iface_loc); TypeInfo::OtherItem { name: iface.name.as_str().to_string(), kind: "interface", @@ -448,8 +448,7 @@ pub fn type_info_for_definition(db: &dyn Db, def: Definition<'_>) -> TypeInfo { } Definition::TypeAlias(alias_loc) => { - let item_tree = baml_compiler2_hir::file_item_tree(db, alias_loc.file(db)); - let alias_data = &item_tree[alias_loc.id(db)]; + let alias_data = baml_compiler2_ppir::item_data::type_alias_data(db, alias_loc); let alias_name = alias_data.name.as_str().to_string(); // Use the resolved (lowered) type for display. @@ -463,16 +462,14 @@ pub fn type_info_for_definition(db: &dyn Db, def: Definition<'_>) -> TypeInfo { } Definition::TemplateString(ts_loc) => { - let item_tree = baml_compiler2_hir::file_item_tree(db, ts_loc.file(db)); - let ts_data = &item_tree[ts_loc.id(db)]; + let ts_data = baml_compiler2_ppir::item_data::template_string_data(db, ts_loc); TypeInfo::TemplateString { name: ts_data.name.as_str().to_string(), } } Definition::Client(loc) => { - let item_tree = baml_compiler2_hir::file_item_tree(db, loc.file(db)); - let data = &item_tree[loc.id(db)]; + let data = baml_compiler2_ppir::item_data::client_data(db, loc); TypeInfo::OtherItem { name: data.name.as_str().to_string(), kind: "client", @@ -480,8 +477,7 @@ pub fn type_info_for_definition(db: &dyn Db, def: Definition<'_>) -> TypeInfo { } Definition::Test(loc) => { - let item_tree = baml_compiler2_hir::file_item_tree(db, loc.file(db)); - let data = &item_tree[loc.id(db)]; + let data = baml_compiler2_ppir::item_data::test_data(db, loc); TypeInfo::OtherItem { name: data.name.as_str().to_string(), kind: "test", @@ -489,8 +485,7 @@ pub fn type_info_for_definition(db: &dyn Db, def: Definition<'_>) -> TypeInfo { } Definition::RetryPolicy(loc) => { - let item_tree = baml_compiler2_hir::file_item_tree(db, loc.file(db)); - let data = &item_tree[loc.id(db)]; + let data = baml_compiler2_ppir::item_data::retry_policy_data(db, loc); TypeInfo::OtherItem { name: data.name.as_str().to_string(), kind: "retry_policy", @@ -498,8 +493,7 @@ pub fn type_info_for_definition(db: &dyn Db, def: Definition<'_>) -> TypeInfo { } Definition::Let(loc) => { - let item_tree = baml_compiler2_hir::file_item_tree(db, loc.file(db)); - let data = &item_tree[loc.id(db)]; + let data = baml_compiler2_ppir::item_data::let_data(db, loc); let kind = match data.origin { baml_compiler2_ast::ast::LetOrigin::Client => "client", baml_compiler2_ast::ast::LetOrigin::RetryPolicy => "retry_policy", @@ -513,7 +507,10 @@ pub fn type_info_for_definition(db: &dyn Db, def: Definition<'_>) -> TypeInfo { } } -fn render_implements_block(block: &baml_compiler2_hir::item_tree::ImplementsBlock) -> String { +fn render_implements_block( + block: &baml_compiler2_ppir::item_data::ImplementsData, + store: &baml_compiler2_hir::type_ref::TypeRefStore, +) -> String { let mut members = Vec::new(); members.extend(block.field_links.iter().map(|link| { @@ -525,22 +522,22 @@ fn render_implements_block(block: &baml_compiler2_hir::item_tree::ImplementsBloc })); members.extend(block.associated_type_bindings.iter().map(|binding| { let ty = binding - .type_expr - .as_ref() - .map(std::string::ToString::to_string) + .type_ref + .map(|id| store.display(id).to_string()) .unwrap_or_else(|| "unknown".to_string()); format!("type {} = {}", binding.name.as_str(), ty) })); + let target = store.display(block.target); if members.is_empty() { - format!("implements {} {{}}", block.target) + format!("implements {target} {{}}") } else { let members = members .into_iter() .map(|member| format!(" {member}")) .collect::>() .join("\n"); - format!("implements {} {{\n{members}\n}}", block.target) + format!("implements {target} {{\n{members}\n}}") } } @@ -627,7 +624,6 @@ fn local_type_info( site: DefinitionSite, ) -> Option { let index = baml_compiler2_hir::file_semantic_index(db, file); - let item_tree = baml_compiler2_hir::file_item_tree(db, file); // Find the enclosing Function scope. let scope_id = index.scope_at_offset(at_offset, None); @@ -643,13 +639,13 @@ fn local_type_info( let func_scope_range = index.scopes[enclosing_func_scope.index() as usize].range; - // Match scope range to a function in the item tree. - let (func_local_id, _) = item_tree - .functions + // Match scope range to a function via the firewall enumeration. + let func_loc = baml_compiler2_ppir::item_data::file_functions(db, file) .iter() - .find(|(_, f)| f.span == func_scope_range)?; - - let func_loc = baml_compiler2_hir::loc::FunctionLoc::new(db, file, *func_local_id); + .copied() + .find(|&loc| { + baml_compiler2_ppir::item_data::function_source_map(db, loc).span == func_scope_range + })?; match site { DefinitionSite::Parameter(param_idx) => { diff --git a/baml_language/crates/baml_lsp2_actions/src/usages.rs b/baml_language/crates/baml_lsp2_actions/src/usages.rs index ac6437e1213..00b2d3b9d1f 100644 --- a/baml_language/crates/baml_lsp2_actions/src/usages.rs +++ b/baml_language/crates/baml_lsp2_actions/src/usages.rs @@ -21,9 +21,7 @@ use baml_base::{Name, SourceFile}; use baml_compiler_syntax::SyntaxKind; use baml_compiler2_ast::{Expr, ExprBody}; -use baml_compiler2_hir::{ - body::FunctionBody, loc::FunctionLoc, scope::ScopeKind, semantic_index::BindingId, -}; +use baml_compiler2_hir::{body::FunctionBody, scope::ScopeKind, semantic_index::BindingId}; use baml_compiler2_tir::resolve::{ResolvedName, resolve_name_at}; use rowan::NodeOrToken; use text_size::{TextRange, TextSize}; @@ -166,8 +164,6 @@ fn find_local_usages( target_binding: BindingId, ) -> Vec { let index = baml_compiler2_hir::file_semantic_index(db, file); - let item_tree = baml_compiler2_hir::file_item_tree(db, file); - // Find the enclosing Function scope. let scope_id = index.scope_at_offset(at_offset, None); let enclosing_func_scope = index @@ -184,20 +180,16 @@ fn find_local_usages( return Vec::new(); }; - let func_scope_range = index.scopes[enclosing_func_scope.index() as usize].range; - - // Find the function in the item tree by matching its span. - let func_entry = item_tree - .functions - .iter() - .find(|(_, f)| f.span == func_scope_range); - - let Some((func_local_id, _)) = func_entry else { + // The recorded item↔scope link, not a span match (which cannot tell a + // function from its companions — they share one span). A template-string + // scope has a non-Function owner and returns early here. + let owner_scope = index.scope_ids[enclosing_func_scope.index() as usize]; + let Some(baml_compiler2_ppir::item_data::ScopeOwner::Function(func_loc)) = + baml_compiler2_ppir::item_data::scope_owner(db, owner_scope) + else { return Vec::new(); }; - let func_loc = FunctionLoc::new(db, file, *func_local_id); - // We need an expression body and source map. let body = baml_compiler2_hir::body::function_body(db, func_loc); let FunctionBody::Expr(expr_body) = body.as_ref() else { @@ -308,7 +300,6 @@ fn find_field_definition_usages( use baml_compiler2_tir::ty::Ty; let index = baml_compiler2_hir::file_semantic_index(db, file); - let item_tree = baml_compiler2_hir::file_item_tree(db, file); let scope_id = index.scope_at_offset(offset, None); let scope = &index.scopes[scope_id.index() as usize]; @@ -316,16 +307,15 @@ fn find_field_definition_usages( if !matches!(scope.kind, ScopeKind::Class) { return Vec::new(); } - let class_name = match &scope.name { - Some(n) => n.clone(), - None => return Vec::new(), - }; - // Find the ClassLoc for this class - let class_entry = item_tree.classes.iter().find(|(_, c)| c.name == class_name); - let Some((class_local_id, class_data)) = class_entry else { + // The class that opened this scope, from the recorded item↔scope link. + let owner_scope = index.scope_ids[scope_id.index() as usize]; + let Some(baml_compiler2_ppir::item_data::ScopeOwner::Class(class_loc)) = + baml_compiler2_ppir::item_data::scope_owner(db, owner_scope) + else { return Vec::new(); }; + let class_data = baml_compiler2_ppir::item_data::class_data(db, class_loc); // Verify the cursor is actually on this field let field_match = class_data @@ -336,8 +326,6 @@ fn find_field_definition_usages( return Vec::new(); } - let class_loc = baml_compiler2_hir::loc::ClassLoc::new(db, file, *class_local_id); - // Collect all source files let source_files = collect_source_files(db, file); @@ -351,7 +339,6 @@ fn find_field_definition_usages( } let sf_index = baml_compiler2_hir::file_semantic_index(db, sf); - let sf_item_tree = baml_compiler2_hir::file_item_tree(db, sf); // Scan each function scope in the file for (scope_idx, scope) in sf_index.scopes.iter().enumerate() { @@ -359,16 +346,14 @@ fn find_field_definition_usages( continue; } - // Find matching function in item tree - let func_entry = sf_item_tree - .functions - .iter() - .find(|(_, f)| f.span == scope.range && scope.name.as_ref() == Some(&f.name)); - let Some((func_local_id, _)) = func_entry else { + // The function that opened this scope, via the recorded item↔scope + // link (template-string scopes have a non-Function owner → skipped). + let owner_scope = sf_index.scope_ids[scope_idx]; + let Some(baml_compiler2_ppir::item_data::ScopeOwner::Function(func_loc)) = + baml_compiler2_ppir::item_data::scope_owner(db, owner_scope) + else { continue; }; - - let func_loc = baml_compiler2_hir::loc::FunctionLoc::new(db, sf, *func_local_id); let body = baml_compiler2_hir::body::function_body(db, func_loc); let baml_compiler2_hir::body::FunctionBody::Expr(expr_body) = body.as_ref() else { continue; diff --git a/baml_language/crates/baml_lsp2_actions/src/utils.rs b/baml_language/crates/baml_lsp2_actions/src/utils.rs index 9319e6797df..a298424a2ce 100644 --- a/baml_language/crates/baml_lsp2_actions/src/utils.rs +++ b/baml_language/crates/baml_lsp2_actions/src/utils.rs @@ -400,3 +400,119 @@ pub fn display_type_expr(te: &TypeExpr) -> String { }; humanize_type_string(&rendered) } + +fn type_ref_needs_postfix_parens( + store: &baml_compiler2_hir::type_ref::TypeRefStore, + id: baml_compiler2_hir::type_ref::TypeRefId, +) -> bool { + use baml_compiler2_hir::type_ref::TypeRefKind; + matches!( + store[id].kind, + TypeRefKind::Union { .. } | TypeRefKind::Function { .. } + ) +} + +fn display_type_ref_as_postfix_base( + store: &baml_compiler2_hir::type_ref::TypeRefStore, + id: baml_compiler2_hir::type_ref::TypeRefId, +) -> String { + let rendered = display_type_ref(store, id); + if type_ref_needs_postfix_parens(store, id) { + format!("({rendered})") + } else { + rendered + } +} + +fn display_type_ref_as_function_result( + store: &baml_compiler2_hir::type_ref::TypeRefStore, + id: baml_compiler2_hir::type_ref::TypeRefId, +) -> String { + use baml_compiler2_hir::type_ref::TypeRefKind; + let rendered = display_type_ref(store, id); + if matches!(store[id].kind, TypeRefKind::Function { .. }) { + format!("({rendered})") + } else { + rendered + } +} + +/// The firewall-arena twin of [`display_type_expr`]: format a `TypeRef` as a +/// brief source-level type string (last path segment only, generics dropped), +/// arm-for-arm identical to [`display_type_expr`]. For callers holding firewall +/// data (`FunctionData::type_refs`, `InterfaceData::type_refs`, …) rather than +/// AST nodes. NOTE: this is deliberately NOT +/// [`TypeRefStore::display`](baml_compiler2_hir::type_ref::TypeRefStore::display), +/// which is the *full* `Display` form (whole path + generic args). +pub fn display_type_ref( + store: &baml_compiler2_hir::type_ref::TypeRefStore, + id: baml_compiler2_hir::type_ref::TypeRefId, +) -> String { + use baml_compiler2_hir::type_ref::TypeRefKind as K; + let rendered = match &store[id].kind { + K::Path { segments, .. } => segments + .last() + .map(|n| n.as_str().to_string()) + .unwrap_or_else(|| "unknown".to_string()), + // A projection has no brief form — render it fully, matching the AST path's + // `te.to_string()`. + K::AssociatedTypeProjection { .. } => store.display(id).to_string(), + K::Int => "int".to_string(), + K::Bigint => "bigint".to_string(), + K::Float => "float".to_string(), + K::String => "string".to_string(), + K::Bool => "bool".to_string(), + K::Null => "null".to_string(), + K::Uint8Array => "uint8array".to_string(), + K::Media { kind } => format!("{kind:?}").to_lowercase(), + K::Optional { inner } => format!("{}?", display_type_ref_as_postfix_base(store, *inner)), + K::List { inner } => format!("{}[]", display_type_ref_as_postfix_base(store, *inner)), + K::Map { key, value } => format!( + "map<{}, {}>", + display_type_ref(store, *key), + display_type_ref(store, *value) + ), + K::Union { variants } => variants + .iter() + .map(|&v| display_type_ref(store, v)) + .collect::>() + .join(" | "), + K::Literal { value } => value.to_string(), + K::Function { + params, + ret, + throws, + } => { + let ps: Vec = params + .iter() + .map(|p| { + p.name + .as_ref() + .map(|n| { + let optional = if p.optional { "?" } else { "" }; + format!("{}{}: {}", n, optional, display_type_ref(store, p.ty)) + }) + .unwrap_or_else(|| display_type_ref(store, p.ty)) + }) + .collect(); + let throws = throws + .map(|t| display_type_ref(store, t)) + .map(|throws| format!(" throws {throws}")) + .unwrap_or_default(); + format!( + "({}) -> {}{}", + ps.join(", "), + display_type_ref_as_function_result(store, *ret), + throws + ) + } + K::BuiltinUnknown => "unknown".to_string(), + K::Never => "never".to_string(), + K::Void => "void".to_string(), + K::Type => "type".to_string(), + K::Rust => "$rust_type".to_string(), + K::Infer => "_".to_string(), + K::Error | K::Unknown => "unknown".to_string(), + }; + humanize_type_string(&rendered) +} diff --git a/baml_language/crates/baml_lsp2_actions_tests/test_files/semantic_tokens/type_aliases_jinja.baml b/baml_language/crates/baml_lsp2_actions_tests/test_files/semantic_tokens/type_aliases_jinja.baml index 965ad5adc9f..11a9119e276 100644 --- a/baml_language/crates/baml_lsp2_actions_tests/test_files/semantic_tokens/type_aliases_jinja.baml +++ b/baml_language/crates/baml_lsp2_actions_tests/test_files/semantic_tokens/type_aliases_jinja.baml @@ -64,15 +64,15 @@ function InvalidAlias(i: I) -> string { //---- //- diagnostics -// warning: cannot access property 'value' on 'j': union contains non-class type map[string, recursive type alias JsonValue] -// ╭─[ type_aliases_jinja.baml:23:15 ] -// │ -// 23 │ prompt #"{{ j.value }}"# -// │ ───┬─── -// │ ╰───── cannot access property 'value' on 'j': union contains non-class type map[string, recursive type alias JsonValue] -// │ -// │ Note: Error code: E0074 -// ────╯ +// warning: 'pid' is a type alias ProjectId (resolves to int), expected class +// ╭─[ type_aliases_jinja.baml:5:20 ] +// │ +// 5 │ prompt #"Pid: {{ pid.id }}. Generate a fake name for it."# +// │ ───┬── +// │ ╰──── 'pid' is a type alias ProjectId (resolves to int), expected class +// │ +// │ Note: Error code: E0073 +// ───╯ // warning: 'c' is a type alias C (resolves to type alias B (resolves to type alias A (resolves to float))), expected class // ╭─[ type_aliases_jinja.baml:14:15 ] // │ @@ -82,6 +82,15 @@ function InvalidAlias(i: I) -> string { // │ // │ Note: Error code: E0073 // ────╯ +// warning: cannot access property 'value' on 'j': union contains non-class type map[string, recursive type alias JsonValue] +// ╭─[ type_aliases_jinja.baml:23:15 ] +// │ +// 23 │ prompt #"{{ j.value }}"# +// │ ───┬─── +// │ ╰───── cannot access property 'value' on 'j': union contains non-class type map[string, recursive type alias JsonValue] +// │ +// │ Note: Error code: E0074 +// ────╯ // warning: 'i' is a type alias I (resolves to type alias J (resolves to recursive type alias I)), expected class // ╭─[ type_aliases_jinja.baml:31:15 ] // │ @@ -91,15 +100,6 @@ function InvalidAlias(i: I) -> string { // │ // │ Note: Error code: E0073 // ────╯ -// warning: 'pid' is a type alias ProjectId (resolves to int), expected class -// ╭─[ type_aliases_jinja.baml:5:20 ] -// │ -// 5 │ prompt #"Pid: {{ pid.id }}. Generate a fake name for it."# -// │ ───┬── -// │ ╰──── 'pid' is a type alias ProjectId (resolves to int), expected class -// │ -// │ Note: Error code: E0073 -// ───╯ // //- semantic_tokens // type_aliases_jinja.baml:1:1 (keyword) len=4 "type" diff --git a/baml_language/crates/baml_lsp2_actions_tests/test_files/syntax/class/type_aliases_jinja.baml b/baml_language/crates/baml_lsp2_actions_tests/test_files/syntax/class/type_aliases_jinja.baml index 11e5124cb0b..bdd886fc68a 100644 --- a/baml_language/crates/baml_lsp2_actions_tests/test_files/syntax/class/type_aliases_jinja.baml +++ b/baml_language/crates/baml_lsp2_actions_tests/test_files/syntax/class/type_aliases_jinja.baml @@ -64,39 +64,39 @@ function InvalidAlias(i: I) -> string { //---- //- diagnostics -// warning: cannot access property 'value' on 'j': union contains non-class type map[string, recursive type alias JsonValue] -// ╭─[ class_type_aliases_jinja.baml:23:15 ] -// │ -// 23 │ prompt #"{{ j.value }}"# -// │ ───┬─── -// │ ╰───── cannot access property 'value' on 'j': union contains non-class type map[string, recursive type alias JsonValue] -// │ -// │ Note: Error code: E0074 -// ────╯ +// warning: 'pid' is a type alias ProjectId (resolves to int), expected class +// ╭─[ class_type_aliases_jinja.baml:5:20 ] +// │ +// 5 │ prompt #"Pid: {{ pid.id }}. Generate a fake name for it."# +// │ ───┬── +// │ ╰──── 'pid' is a type alias ProjectId (resolves to int), expected class +// │ +// │ Note: Error code: E0073 +// ───╯ // warning: 'c' is a type alias C (resolves to type alias B (resolves to type alias A (resolves to float))), expected class // ╭─[ class_type_aliases_jinja.baml:14:15 ] // │ // 14 │ prompt #"{{ c.value }}"# -// │ ───┬─── +// │ ───┬─── // │ ╰───── 'c' is a type alias C (resolves to type alias B (resolves to type alias A (resolves to float))), expected class -// │ +// │ // │ Note: Error code: E0073 // ────╯ +// warning: cannot access property 'value' on 'j': union contains non-class type map[string, recursive type alias JsonValue] +// ╭─[ class_type_aliases_jinja.baml:23:15 ] +// │ +// 23 │ prompt #"{{ j.value }}"# +// │ ───┬─── +// │ ╰───── cannot access property 'value' on 'j': union contains non-class type map[string, recursive type alias JsonValue] +// │ +// │ Note: Error code: E0074 +// ────╯ // warning: 'i' is a type alias I (resolves to type alias J (resolves to recursive type alias I)), expected class // ╭─[ class_type_aliases_jinja.baml:31:15 ] // │ // 31 │ prompt #"{{ i.value }}"# -// │ ───┬─── +// │ ───┬─── // │ ╰───── 'i' is a type alias I (resolves to type alias J (resolves to recursive type alias I)), expected class -// │ +// │ // │ Note: Error code: E0073 // ────╯ -// warning: 'pid' is a type alias ProjectId (resolves to int), expected class -// ╭─[ class_type_aliases_jinja.baml:5:20 ] -// │ -// 5 │ prompt #"Pid: {{ pid.id }}. Generate a fake name for it."# -// │ ───┬── -// │ ╰──── 'pid' is a type alias ProjectId (resolves to int), expected class -// │ -// │ Note: Error code: E0073 -// ───╯ diff --git a/baml_language/crates/baml_lsp2_actions_tests/test_files/syntax/functions_v2/prompt_errors/prompt1.baml b/baml_language/crates/baml_lsp2_actions_tests/test_files/syntax/functions_v2/prompt_errors/prompt1.baml index 19a713e1b6d..4cbaffcea18 100644 --- a/baml_language/crates/baml_lsp2_actions_tests/test_files/syntax/functions_v2/prompt_errors/prompt1.baml +++ b/baml_language/crates/baml_lsp2_actions_tests/test_files/syntax/functions_v2/prompt_errors/prompt1.baml @@ -77,48 +77,48 @@ function Bar1(a: string) -> int { //---- //- diagnostics +// warning: Function 'Foo' expects 0 arguments, but got 1 +// ╭─[ functions_v2_prompt_errors_prompt1.baml:24:8 ] +// │ +// 24 │ {{ Foo(a) }} +// │ ───┬── +// │ ╰──── Function 'Foo' expects 0 arguments, but got 1 +// │ +// │ Note: Error code: E0080 +// ────╯ // warning: Function 'Foo' referenced without parentheses. Did you mean 'Foo()'? // ╭─[ functions_v2_prompt_errors_prompt1.baml:32:18 ] // │ // 32 │ {% set b = Foo %} -// │ ─┬─ +// │ ─┬─ // │ ╰─── Function 'Foo' referenced without parentheses. Did you mean 'Foo()'? -// │ +// │ // │ Note: Error code: E0071 // ────╯ // warning: Function 'Foo2' referenced without parentheses. Did you mean 'Foo2()'? // ╭─[ functions_v2_prompt_errors_prompt1.baml:34:18 ] // │ // 34 │ {% set b = Foo2 %} -// │ ──┬─ +// │ ──┬─ // │ ╰─── Function 'Foo2' referenced without parentheses. Did you mean 'Foo2()'? -// │ +// │ // │ Note: Error code: E0071 // ────╯ // warning: 'b' is undefined, expected function // ╭─[ functions_v2_prompt_errors_prompt1.baml:37:8 ] // │ // 37 │ {{ b() }} -// │ ─┬─ +// │ ─┬─ // │ ╰─── 'b' is undefined, expected function -// │ -// │ Note: Error code: E0073 -// ────╯ -// warning: Function 'Foo' expects 0 arguments, but got 1 -// ╭─[ functions_v2_prompt_errors_prompt1.baml:24:8 ] // │ -// 24 │ {{ Foo(a) }} -// │ ───┬── -// │ ╰──── Function 'Foo' expects 0 arguments, but got 1 -// │ -// │ Note: Error code: E0080 +// │ Note: Error code: E0073 // ────╯ // warning: Variable `b` does not exist. Did you mean one of these: `_`, `baml`, `ctx`? // ╭─[ functions_v2_prompt_errors_prompt1.baml:6:12 ] // │ // 6 │ This! {{ b}} -// │ ┬ +// │ ┬ // │ ╰── Variable `b` does not exist. Did you mean one of these: `_`, `baml`, `ctx`? -// │ +// │ // │ Note: Error code: E0070 // ───╯ diff --git a/baml_language/crates/baml_lsp2_actions_tests/test_files/syntax/template_string/bad_calls.baml b/baml_language/crates/baml_lsp2_actions_tests/test_files/syntax/template_string/bad_calls.baml index c065770557b..0f30b4208b8 100644 --- a/baml_language/crates/baml_lsp2_actions_tests/test_files/syntax/template_string/bad_calls.baml +++ b/baml_language/crates/baml_lsp2_actions_tests/test_files/syntax/template_string/bad_calls.baml @@ -81,48 +81,48 @@ template_string BadCall4 #" //---- //- diagnostics +// warning: Function 'WithParams' expects 1 arguments, but got 2 +// ╭─[ template_string_bad_calls.baml:6:6 ] +// │ +// 6 │ {{ WithParams(a=2, b=2) }} +// │ ──────────┬───────── +// │ ╰─────────── Function 'WithParams' expects 1 arguments, but got 2 +// │ +// │ Note: Error code: E0080 +// ───╯ +// warning: Function 'WithParams' expects argument 'a' to be of type int, but got literal["a"] +// ╭─[ template_string_bad_calls.baml:10:6 ] +// │ +// 10 │ {{ WithParams("a") }} +// │ ───────┬─────── +// │ ╰───────── Function 'WithParams' expects argument 'a' to be of type int, but got literal["a"] +// │ +// │ Note: Error code: E0083 +// ────╯ // warning: Function 'WithParams' expects 1 arguments, but got 0 // ╭─[ template_string_bad_calls.baml:14:6 ] // │ // 14 │ {{ WithParams() }} -// │ ──────┬───── +// │ ──────┬───── // │ ╰─────── Function 'WithParams' expects 1 arguments, but got 0 -// │ +// │ // │ Note: Error code: E0080 // ────╯ // warning: Variable `Random` does not exist. Did you mean one of these: `_`, `baml`, `ctx`? // ╭─[ template_string_bad_calls.baml:18:6 ] // │ // 18 │ {{ Random(2) }} -// │ ───┬── +// │ ───┬── // │ ╰──── Variable `Random` does not exist. Did you mean one of these: `_`, `baml`, `ctx`? -// │ +// │ // │ Note: Error code: E0070 // ────╯ // warning: 'Random' is undefined, expected function // ╭─[ template_string_bad_calls.baml:18:6 ] // │ // 18 │ {{ Random(2) }} -// │ ────┬──── +// │ ────┬──── // │ ╰────── 'Random' is undefined, expected function -// │ -// │ Note: Error code: E0073 -// ────╯ -// warning: Function 'WithParams' expects 1 arguments, but got 2 -// ╭─[ template_string_bad_calls.baml:6:6 ] -// │ -// 6 │ {{ WithParams(a=2, b=2) }} -// │ ──────────┬───────── -// │ ╰─────────── Function 'WithParams' expects 1 arguments, but got 2 -// │ -// │ Note: Error code: E0080 -// ───╯ -// warning: Function 'WithParams' expects argument 'a' to be of type int, but got literal["a"] -// ╭─[ template_string_bad_calls.baml:10:6 ] // │ -// 10 │ {{ WithParams("a") }} -// │ ───────┬─────── -// │ ╰───────── Function 'WithParams' expects argument 'a' to be of type int, but got literal["a"] -// │ -// │ Note: Error code: E0083 +// │ Note: Error code: E0073 // ────╯ From 6e4e8b46aa2c25a0510f988ac731732b90ec9caf Mon Sep 17 00:00:00 2001 From: 2kai2kai2 Date: Mon, 20 Jul 2026 15:33:46 -0700 Subject: [PATCH 02/10] `baml_project` should use ItemTree firewall queries --- .../crates/baml_project/src/client_codegen.rs | 144 ++++++++++-------- 1 file changed, 83 insertions(+), 61 deletions(-) diff --git a/baml_language/crates/baml_project/src/client_codegen.rs b/baml_language/crates/baml_project/src/client_codegen.rs index 306f1c1cde1..1c876eaa28a 100644 --- a/baml_language/crates/baml_project/src/client_codegen.rs +++ b/baml_language/crates/baml_project/src/client_codegen.rs @@ -1,19 +1,15 @@ //! Conversion from the compiler2 HIR/TIR to `SymbolPool`. //! -//! Walks the HIR item trees for user-defined files, resolves types via TIR, -//! and populates a codegen-ready `SymbolPool` suitable for language-specific -//! code generators (e.g. `sdkgen_python_pydantic2`). +//! Walks each user-defined file via the `ppir` item-data firewall (enumeration +//! queries plus `*_data` lookups), resolves types via TIR, and populates a +//! codegen-ready `SymbolPool` suitable for language-specific code generators +//! such as `sdkgen_python_pydantic2`. use std::collections::HashMap; use baml_codegen_types::{self as cg, Origin, SymbolPool}; use baml_compiler2_ast::{self as ast, FunctionOrigin}; -use baml_compiler2_hir::{ - compiler2_all_files, file_package, - ids::{FunctionMarker, LocalItemId}, - loc::FunctionLoc, - package::PackageId, -}; +use baml_compiler2_hir::{compiler2_all_files, file_package, loc::FunctionLoc, package::PackageId}; use baml_compiler2_tir::{ lower_type_expr, normalize::find_recursive_aliases, @@ -126,46 +122,45 @@ pub fn build_symbol_pool(db: &ProjectDatabase) -> SymbolPool { let alias_map: &HashMap = alias_map; let recursive_aliases: &std::collections::HashSet = recursive_aliases; - let item_tree = baml_compiler2_ppir::file_item_tree(db, source_file); let source_file_path: String = source_file.path(db).to_string_lossy().into_owned(); - // Collect function IDs that are not package-level functions so the + // Collect function locs that are not package-level functions so the // free-function walk below can skip them. Class methods, interface - // default methods, and out-of-body implements methods all live in - // `item_tree.functions`, but none of them are directly callable as - // `..` from generated SDKs. - let mut non_free_function_ids: std::collections::HashSet> = + // default methods, and out-of-body implements methods are all functions, + // but none of them are directly callable as `..` from + // generated SDKs. + let mut non_free_function_locs: std::collections::HashSet = std::collections::HashSet::new(); - for class in item_tree.classes.values() { - for m in &class.methods { - non_free_function_ids.insert(*m); + for &class_loc in baml_compiler2_ppir::item_data::file_classes(db, source_file) { + for &m in &baml_compiler2_ppir::item_data::class_data(db, class_loc).methods { + non_free_function_locs.insert(m); } } - for interface in item_tree.interfaces.values() { - for m in &interface.default_methods { - non_free_function_ids.insert(*m); + for &iface_loc in baml_compiler2_ppir::item_data::file_interfaces(db, source_file) { + for &m in &baml_compiler2_ppir::item_data::interface_data(db, iface_loc).default_methods + { + non_free_function_locs.insert(m); } } - for impl_id in &item_tree.free_impls { - let Some(block) = item_tree.impls.get(impl_id) else { - continue; - }; - for m in &block.methods { - non_free_function_ids.insert(*m); + for &impl_loc in baml_compiler2_ppir::item_data::file_free_impls(db, source_file) { + for &m in &baml_compiler2_ppir::item_data::impl_block_data(db, impl_loc).methods { + non_free_function_locs.insert(m); } } // Classes - for class in item_tree.classes.values() { + for &class_loc in baml_compiler2_ppir::item_data::file_classes(db, source_file) { + let class = baml_compiler2_ppir::item_data::class_data(db, class_loc); let cg_name = cg::Name::new(pkg.clone(), ns_path.clone(), class.name.clone()); let class_generic_params: Vec = class.generic_params.clone(); let properties = class .fields .iter() .filter_map(|field| { - let ty = resolve_type_expr( + let ty = resolve_type_ref( db, - field.type_expr.as_ref(), + &class.type_refs, + field.type_ref, pkg_items, &pkg_info.namespace_path, &class_generic_params, @@ -186,10 +181,8 @@ pub fn build_symbol_pool(db: &ProjectDatabase) -> SymbolPool { // `$build_request`) are independent `Function` entries that // sit alongside their parent method in the same vec; their // shared span keeps them adjacent after sorting. - for method_id in &class.methods { - let Some(method) = item_tree.functions.get(method_id) else { - continue; - }; + for &method_loc in &class.methods { + let method = baml_compiler2_ppir::item_data::function_data(db, method_loc); // Auto-derived methods (`to_json` / `from_json` synthesized // by `auto_derive_json`) are language-level plumbing, not @@ -200,8 +193,8 @@ pub fn build_symbol_pool(db: &ProjectDatabase) -> SymbolPool { } if matches!( - method.body.as_ref(), - Some(ast::FunctionBodyDef::Builtin(ast::BuiltinKind::Intrinsic)) + baml_compiler2_ppir::function_body(db, method_loc).as_ref(), + baml_compiler2_hir::body::FunctionBody::Builtin(ast::BuiltinKind::Intrinsic) ) { continue; } @@ -216,7 +209,6 @@ pub fn build_symbol_pool(db: &ProjectDatabase) -> SymbolPool { MethodKind::Static }; - let method_loc = FunctionLoc::new(db, source_file, *method_id); // Same elaboration as free functions (see the free-function // path). The method's own `generic_params` are its user + // synthetic effect params; the enclosing class's params join @@ -285,7 +277,11 @@ pub fn build_symbol_pool(db: &ProjectDatabase) -> SymbolPool { watchers: Vec::new(), origin: Origin { source_file_path: source_file_path.clone(), - span_start: u32::from(method.span.start()), + span_start: u32::from( + baml_compiler2_ppir::item_data::function_source_map(db, method_loc) + .span + .start(), + ), }, }; @@ -307,14 +303,19 @@ pub fn build_symbol_pool(db: &ProjectDatabase) -> SymbolPool { instance_methods: Vec::new(), origin: Origin { source_file_path: source_file_path.clone(), - span_start: u32::from(class.span.start()), + span_start: u32::from( + baml_compiler2_ppir::item_data::class_source_map(db, class_loc) + .span + .start(), + ), }, }), ); } // Enums - for enum_def in item_tree.enums.values() { + for &enum_loc in baml_compiler2_ppir::item_data::file_enums(db, source_file) { + let enum_def = baml_compiler2_ppir::item_data::enum_data(db, enum_loc); let cg_name = cg::Name::new(pkg.clone(), ns_path.clone(), enum_def.name.clone()); let variants = enum_def .variants @@ -333,17 +334,23 @@ pub fn build_symbol_pool(db: &ProjectDatabase) -> SymbolPool { variants, origin: Origin { source_file_path: source_file_path.clone(), - span_start: u32::from(enum_def.span.start()), + span_start: u32::from( + baml_compiler2_ppir::item_data::enum_source_map(db, enum_loc) + .span + .start(), + ), }, }), ); } // Type aliases - for alias in item_tree.type_aliases.values() { - if let Some(resolved) = resolve_type_expr( + for &alias_loc in baml_compiler2_ppir::item_data::file_type_aliases(db, source_file) { + let alias = baml_compiler2_ppir::item_data::type_alias_data(db, alias_loc); + if let Some(resolved) = resolve_type_ref( db, - alias.type_expr.as_ref(), + &alias.type_refs, + alias.value, pkg_items, &pkg_info.namespace_path, &[], @@ -367,21 +374,28 @@ pub fn build_symbol_pool(db: &ProjectDatabase) -> SymbolPool { recursive: is_recursive, origin: Origin { source_file_path: source_file_path.clone(), - span_start: u32::from(alias.span.start()), + span_start: u32::from( + baml_compiler2_ppir::item_data::type_alias_source_map( + db, alias_loc, + ) + .span + .start(), + ), }, }), ); } } - // Top-level functions — methods are skipped via `method_ids` so they - // don't double-emit. Companion functions (names containing `$`) flow - // through as their own pool entries; parent and companion alike are + // Top-level functions — methods are skipped via `non_free_function_locs` + // so they don't double-emit. Companion functions (names containing `$`) + // flow through as their own pool entries; parent and companion alike are // inserted directly, keyed on the suffixed name. - for (id, func) in &item_tree.functions { - if non_free_function_ids.contains(id) { + for &func_loc in baml_compiler2_ppir::item_data::file_functions(db, source_file) { + if non_free_function_locs.contains(&func_loc) { continue; } + let func = baml_compiler2_ppir::item_data::function_data(db, func_loc); // Internal-origin functions (e.g. `$new` synthesized for // primitive clients) are runtime plumbing, not user-callable — @@ -391,8 +405,8 @@ pub fn build_symbol_pool(db: &ProjectDatabase) -> SymbolPool { } if matches!( - func.body.as_ref(), - Some(ast::FunctionBodyDef::Builtin(ast::BuiltinKind::Intrinsic)) + baml_compiler2_ppir::function_body(db, func_loc).as_ref(), + baml_compiler2_hir::body::FunctionBody::Builtin(ast::BuiltinKind::Intrinsic) ) { continue; } @@ -405,7 +419,6 @@ pub fn build_symbol_pool(db: &ProjectDatabase) -> SymbolPool { // bodies, etc.) are valid too. `FunctionOrigin::Internal` is // already filtered above. - let func_loc = FunctionLoc::new(db, source_file, *id); // Source the signature from the *elaborated* HIR data, not the raw // item tree: elaboration mints a synthetic effect param for every // callback parameter that omits a `throws` clause and rewrites that @@ -482,7 +495,11 @@ pub fn build_symbol_pool(db: &ProjectDatabase) -> SymbolPool { watchers: Vec::new(), origin: Origin { source_file_path: source_file_path.clone(), - span_start: u32::from(func.span.start()), + span_start: u32::from( + baml_compiler2_ppir::item_data::function_source_map(db, func_loc) + .span + .start(), + ), }, }; @@ -511,22 +528,26 @@ pub fn build_symbol_pool(db: &ProjectDatabase) -> SymbolPool { // Type resolution // --------------------------------------------------------------------------- -/// Resolve an optional `TypeExpr` to a codegen `Ty`. +/// Resolve an optional type reference (from an item's firewall `type_refs` +/// arena) to a codegen `Ty`. /// -/// Returns `None` if the type expression is missing. -fn resolve_type_expr( +/// Returns `None` if `id` is `None` (the annotation was omitted). +#[expect(clippy::too_many_arguments)] +fn resolve_type_ref( db: &ProjectDatabase, - spanned: Option<&baml_compiler2_ast::TypeExpr>, + store: &baml_compiler2_hir::type_ref::TypeRefStore, + id: Option, package_items: &baml_compiler2_hir::package::PackageItems<'_>, ns_context: &[Name], generic_params: &[Name], alias_map: &HashMap, recursive_aliases: &std::collections::HashSet, ) -> Option { - let spanned = spanned?; + let id = id?; let mut diagnostics = Vec::new(); - let tir_ty = lower_type_expr::lower_type_expr( - spanned, + let tir_ty = lower_type_expr::lower_type_ref( + store, + id, &lower_type_expr::ScopeCtx { db, package_items, @@ -674,6 +695,7 @@ fn convert_tir_leaf(ty: &TirTy) -> cg::Ty { mod tests { use std::path::Path; + use baml_compiler2_hir::ids::{FunctionMarker, LocalItemId}; use baml_type::TyAttrValue; use super::*; From 90f35459145b29c139ea41955eb9348379e1d58b Mon Sep 17 00:00:00 2001 From: 2kai2kai2 Date: Mon, 20 Jul 2026 15:41:21 -0700 Subject: [PATCH 03/10] `bex_project` should use ItemTree firewall queries --- baml_language/crates/bex_project/src/seed.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/baml_language/crates/bex_project/src/seed.rs b/baml_language/crates/bex_project/src/seed.rs index 9116bac1d6b..060ea4ddd31 100644 --- a/baml_language/crates/bex_project/src/seed.rs +++ b/baml_language/crates/bex_project/src/seed.rs @@ -405,7 +405,7 @@ fn load_callable_throws( #[cfg(test)] mod tests { use baml_db::{ - Name, baml_compiler2_hir, + Name, baml_compiler2_hir, baml_compiler2_ppir, baml_compiler2_tir::{ callable::callable_throws, package_interface, throw_inference::file_throw_facts, }, @@ -515,9 +515,11 @@ mod tests { fn first_func_throws(db: &ProjectDatabase, file: &str) -> String { let sf = source_file(db, file); - let it = baml_compiler2_hir::file_item_tree(db, sf); - let local_id = *it.functions.keys().next().expect("one function"); - let loc = baml_compiler2_hir::loc::FunctionLoc::new(db, sf, local_id); + // The fixture defines exactly one function; the firewall enumeration is + // source-ordered, so the first loc is that function. + let loc = *baml_compiler2_ppir::item_data::file_functions(db, sf) + .first() + .expect("one function"); format!("{:?}", callable_throws(db, loc)) } From 0cf63480cadeb141b8f79bb188e21c5573e1d974 Mon Sep 17 00:00:00 2001 From: 2kai2kai2 Date: Tue, 21 Jul 2026 10:40:27 -0700 Subject: [PATCH 04/10] `baml_tests` should use ItemTree firewall queries This churns a lot of snapshots by switching to a consistent source-span-based order instead of a localized Fx hash order --- baml_language/crates/baml_tests/build.rs | 21 +- ...s__compiles____assert_std____04_5_mir.snap | 229 +- ...sts__compiles____baml_std____04_5_mir.snap | 10742 ++++++++-------- ...__compiles____testing_std____04_5_mir.snap | 4093 +++--- ...mpiles__anyfunction_reflect__04_5_mir.snap | 70 +- ...mpiles__backtick_decl_slots__04_5_mir.snap | 122 + ...__compiles__backtick_dedent__04_5_mir.snap | 125 +- ..._compiles__backtick_strings__04_5_mir.snap | 423 +- ...sts__compiles__bigint_arith__04_5_mir.snap | 34 +- ...tests__compiles__bigint_cmp__04_5_mir.snap | 30 +- ...piles__byte_string_literals__04_5_mir.snap | 74 +- ...compiles__catch_all_keyword__04_5_mir.snap | 112 +- ..._compiles__catch_all_panics__04_5_mir.snap | 72 +- ...ests__compiles__catch_throw__04_5_mir.snap | 168 +- ...l_tests__compiles__closures__04_5_mir.snap | 400 +- ...__compiles__comment_in_type__04_5_mir.snap | 348 +- ..._compiles__deep_method_call__04_5_mir.snap | 14 +- ...mpiles__generic_field_chain__04_5_mir.snap | 38 +- ...ests__compiles__is_operator__04_5_mir.snap | 140 +- ..._compiles__json_alias_basic__04_5_mir.snap | 119 +- ...cross_namespace_static_call__04_5_mir.snap | 19 +- ...piles__json_llm_return_type__04_5_mir.snap | 117 +- ..._parse_stringify_intrinsics__04_5_mir.snap | 84 +- ...son_to_from_string_concrete__04_5_mir.snap | 16 +- ...__compiles__lambda_advanced__04_5_mir.snap | 1481 ++- ...sts__compiles__lambda_basic__04_5_mir.snap | 144 +- ..._compiles__lambda_fat_arrow__04_5_mir.snap | 142 +- ...mpiles__lambda_field_access__04_5_mir.snap | 98 +- ...__compiles__lexical_scoping__04_5_mir.snap | 166 +- ...s__literal_union_arithmetic__04_5_mir.snap | 137 +- ...les__literal_union_widening__04_5_mir.snap | 32 +- ...compiles__llm_image_outputs__04_5_mir.snap | 312 +- ...parse_catchable_parse_error__04_5_mir.snap | 120 +- ...__method_explicit_type_args__04_5_mir.snap | 31 +- ..._namespaces_type_resolution__04_5_mir.snap | 786 +- ...iles__numeric_invariance_ok__04_5_mir.snap | 42 +- ...numeric_literal_method_call__04_5_mir.snap | 28 +- ..._compiles__o1_allowed_roles__04_5_mir.snap | 18 +- ...ptional_function_parameters__04_5_mir.snap | 491 +- ...compiles__parser_statements__04_5_mir.snap | 380 +- ...lass_destructure_namespaces__04_5_mir.snap | 220 +- ...sts__compiles__patterns_new__04_5_mir.snap | 692 +- ...eflect_type_of_user_generic__04_5_mir.snap | 18 +- ...__scientific_notation_float__04_5_mir.snap | 24 +- ...tream_llm_inferred_typeargs__04_5_mir.snap | 92 + ...piles__testset_vibes_nested__04_5_mir.snap | 451 +- ...__compiles__type_annotation__04_5_mir.snap | 24 +- ...mpiles__type_builder_errors__04_5_mir.snap | 98 + ...compiles__type_builder_test__04_5_mir.snap | 97 + 49 files changed, 12584 insertions(+), 11150 deletions(-) diff --git a/baml_language/crates/baml_tests/build.rs b/baml_language/crates/baml_tests/build.rs index a54bc04669b..ca13f9934ed 100644 --- a/baml_language/crates/baml_tests/build.rs +++ b/baml_language/crates/baml_tests/build.rs @@ -769,11 +769,9 @@ fn generate_mir_test(project: &TestProject, stdlib_package_filter: Option<&str>) .collect(); baml_files.sort_by_key(|f| f.path(&db).to_string_lossy().to_string()); for sf in baml_files { - let item_tree = file_item_tree(&db, sf); - let mut functions: Vec<_> = item_tree.functions.iter().collect(); - functions.sort_by_key(|(_, f)| f.name.as_str().to_string()); - for (local_id, _func_data) in functions { - let func_loc = FunctionLoc::new(&db, sf, *local_id); + let mut functions = file_functions(&db, sf).to_vec(); + functions.sort_by_key(|loc| function_source_map(&db, *loc).span.start()); + for func_loc in functions { let mir = lower_function(&db, func_loc, OptLevel::Two); writeln!(output, "{}", display_function(&mir)).unwrap(); } @@ -787,8 +785,8 @@ fn generate_mir_test(project: &TestProject, stdlib_package_filter: Option<&str>) quote! { #[test] fn test_04_5_mir() { - use baml_compiler2_hir::{file_item_tree, loc::FunctionLoc}; use baml_compiler2_mir::{OptLevel, lower_function, pretty::display_function}; + use baml_compiler2_ppir::item_data::{file_functions, function_source_map}; let mut db = ProjectDatabase::new(); let _root = db.set_project_root(std::path::Path::new(".")); @@ -800,11 +798,12 @@ fn generate_mir_test(project: &TestProject, stdlib_package_filter: Option<&str>) writeln!(output, "=== MIR2 ===").unwrap(); for source_file in &source_files { - let item_tree = file_item_tree(&db, *source_file); - let mut functions: Vec<_> = item_tree.functions.iter().collect(); - functions.sort_by_key(|(_, f)| f.name.as_str().to_string()); - for (local_id, _func_data) in functions { - let func_loc = FunctionLoc::new(&db, *source_file, *local_id); + // Dump in source order (by declaration span) — an intrinsic, + // salsa-enumeration-independent key, so the snapshot never churns + // on a firewall/tie-break change the way a name sort would. + let mut functions = file_functions(&db, *source_file).to_vec(); + functions.sort_by_key(|loc| function_source_map(&db, *loc).span.start()); + for func_loc in functions { let mir = lower_function(&db, func_loc, OptLevel::Two); writeln!(output, "{}", display_function(&mir)).unwrap(); } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/__assert_std__/baml_tests__compiles____assert_std____04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/__assert_std__/baml_tests__compiles____assert_std____04_5_mir.snap index 1aaed491874..b2f1da10ba0 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/__assert_std__/baml_tests__compiles____assert_std____04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/__assert_std__/baml_tests__compiles____assert_std____04_5_mir.snap @@ -1,10 +1,123 @@ --- source: crates/baml_tests/src/generated_tests.rs -assertion_line: 4168 --- === MIR2 === === MIR2 (package assert) === +fn assert.is_true(condition: bool) -> null { + // Locals: + let _0: null // _0 // return + let _1: bool // condition // param + let _2: bool + + bb0: { + _2 = !copy _1; + branch copy _2 -> [bb2, bb1]; + } + + bb1: { + _0 = const null; + goto -> bb3; + } + + bb2: { + _0 = call const fn baml.sys.panic(const "assertion failed: expected true") -> [bb3]; + } + + bb3: { + return; + } +} + +fn assert.not_null(value: unknown) -> null { + // Locals: + let _0: null // _0 // return + let _1: unknown // value // param + let _2: bool + + bb0: { + _2 = call const fn baml.ops.equals_equals(copy _1, const null) -> [bb1]; + } + + bb1: { + branch copy _2 -> [bb3, bb2]; + } + + bb2: { + _0 = const null; + goto -> bb4; + } + + bb3: { + _0 = call const fn baml.sys.panic(const "assertion failed: expected non-null value") -> [bb4]; + } + + bb4: { + return; + } +} + +fn assert.format_operand(value: unknown) -> string { + // Locals: + let _0: string // _0 // return + let _1: unknown // value // param + + bb0: { + _0 = call const fn baml.String.from(copy _1) -> [bb1]; + } + + bb1: { + return; + } +} + +fn assert.equal(actual: unknown, expected: unknown) -> null { + // Locals: + let _0: null // _0 // return + let _1: unknown // actual // param + let _2: unknown // expected // param + let _3: bool + let _4: bool + let _5: string + let _6: string + let _7: string + let _8: string + let _9: string + + bb0: { + _4 = call const fn baml.ops.equals_equals(copy _1, copy _2) -> [bb1]; + } + + bb1: { + _3 = !copy _4; + branch copy _3 -> [bb3, bb2]; + } + + bb2: { + _0 = const null; + goto -> bb6; + } + + bb3: { + _8 = call const fn assert.format_operand(copy _1) -> [bb4]; + } + + bb4: { + _7 = const "assertion failed: left = " + copy _8; + _6 = copy _7 + const ", right = "; + _9 = call const fn assert.format_operand(copy _2) -> [bb5]; + } + + bb5: { + _5 = copy _6 + copy _9; + _0 = call const fn baml.sys.panic(copy _5) -> [bb6]; + } + + bb6: { + return; + } +} + fn assert.approx_equal(actual: float, expected: float, eps: float) -> null { // Locals: let _0: null // _0 // return @@ -139,117 +252,3 @@ fn assert.contains(haystack: string, needle: string) -> null { return; } } - -fn assert.equal(actual: unknown, expected: unknown) -> null { - // Locals: - let _0: null // _0 // return - let _1: unknown // actual // param - let _2: unknown // expected // param - let _3: bool - let _4: bool - let _5: string - let _6: string - let _7: string - let _8: string - let _9: string - - bb0: { - _4 = call const fn baml.ops.equals_equals(copy _1, copy _2) -> [bb1]; - } - - bb1: { - _3 = !copy _4; - branch copy _3 -> [bb3, bb2]; - } - - bb2: { - _0 = const null; - goto -> bb6; - } - - bb3: { - _8 = call const fn assert.format_operand(copy _1) -> [bb4]; - } - - bb4: { - _7 = const "assertion failed: left = " + copy _8; - _6 = copy _7 + const ", right = "; - _9 = call const fn assert.format_operand(copy _2) -> [bb5]; - } - - bb5: { - _5 = copy _6 + copy _9; - _0 = call const fn baml.sys.panic(copy _5) -> [bb6]; - } - - bb6: { - return; - } -} - -fn assert.format_operand(value: unknown) -> string { - // Locals: - let _0: string // _0 // return - let _1: unknown // value // param - - bb0: { - _0 = call const fn baml.String.from(copy _1) -> [bb1]; - } - - bb1: { - return; - } -} - -fn assert.is_true(condition: bool) -> null { - // Locals: - let _0: null // _0 // return - let _1: bool // condition // param - let _2: bool - - bb0: { - _2 = !copy _1; - branch copy _2 -> [bb2, bb1]; - } - - bb1: { - _0 = const null; - goto -> bb3; - } - - bb2: { - _0 = call const fn baml.sys.panic(const "assertion failed: expected true") -> [bb3]; - } - - bb3: { - return; - } -} - -fn assert.not_null(value: unknown) -> null { - // Locals: - let _0: null // _0 // return - let _1: unknown // value // param - let _2: bool - - bb0: { - _2 = call const fn baml.ops.equals_equals(copy _1, const null) -> [bb1]; - } - - bb1: { - branch copy _2 -> [bb3, bb2]; - } - - bb2: { - _0 = const null; - goto -> bb4; - } - - bb3: { - _0 = call const fn baml.sys.panic(const "assertion failed: expected non-null value") -> [bb4]; - } - - bb4: { - return; - } -} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____04_5_mir.snap index a02a0dc7ad7..8c89f4e061d 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____04_5_mir.snap @@ -6,29 +6,21 @@ source: crates/baml_tests/src/generated_tests.rs === MIR2 (package baml) === fn baml.Bigint.abs = builtin(vm) -fn baml.Bigint.clamp = builtin(vm) - -fn baml.Bigint.ilog = builtin(vm) - -fn baml.Bigint.isqrt = builtin(vm) +fn baml.Bigint.min = builtin(vm) fn baml.Bigint.max = builtin(vm) -fn baml.Bigint.min = builtin(vm) +fn baml.Bigint.clamp = builtin(vm) -fn baml.Bigint.parse = builtin(vm) +fn baml.Bigint.isqrt = builtin(vm) fn baml.Bigint.pow = builtin(vm) -fn baml.Bigint.random = builtin(vm) - -fn baml._compare_shim = builtin(vm) - -fn baml._float_total_cmp = builtin(vm) +fn baml.Bigint.ilog = builtin(vm) -fn baml._is_primitive_array = builtin(vm) +fn baml.Bigint.parse = builtin(vm) -fn baml._rust_sort = builtin(vm) +fn baml.Bigint.random = builtin(vm) fn baml.Comparable$for$int.compare(self: int, other: Self) -> int { // Locals: @@ -68,25 +60,10 @@ fn baml.Comparable$for$int.compare(self: int, other: Self) -> int { } } -fn baml.Comparable$for$float.compare(self: float, other: Self) -> int { - // Locals: - let _0: int // _0 // return - let _1: float // self // param - let _2: Self // other // param - - bb0: { - _0 = call const fn baml._float_total_cmp(copy _1, copy _2) -> [bb1]; - } - - bb1: { - return; - } -} - -fn baml.Comparable$for$string.compare(self: string, other: Self) -> int { +fn baml.Comparable$for$bigint.compare(self: bigint, other: Self) -> int { // Locals: let _0: int // _0 // return - let _1: string // self // param + let _1: bigint // self // param let _2: Self // other // param let _3: bool let _4: bool @@ -121,10 +98,10 @@ fn baml.Comparable$for$string.compare(self: string, other: Self) -> int { } } -fn baml.Comparable$for$bigint.compare(self: bigint, other: Self) -> int { +fn baml.Comparable$for$string.compare(self: string, other: Self) -> int { // Locals: let _0: int // _0 // return - let _1: bigint // self // param + let _1: string // self // param let _2: Self // other // param let _3: bool let _4: bool @@ -214,113 +191,91 @@ fn .(a: T, b: T) -> null { } } -fn baml._mean_float = builtin(vm) - -fn baml._median_float = builtin(vm) - -fn baml._sum_float = builtin(vm) - -fn baml._sum_int = builtin(vm) +fn baml._compare_shim = builtin(vm) -fn baml.Array.at = builtin(vm) +fn baml.Comparable$for$float.compare(self: float, other: Self) -> int { + // Locals: + let _0: int // _0 // return + let _1: float // self // param + let _2: Self // other // param -fn baml.Map.clear = builtin(vm) + bb0: { + _0 = call const fn baml._float_total_cmp(copy _1, copy _2) -> [bb1]; + } -fn baml.Array.clear = builtin(vm) + bb1: { + return; + } +} -fn baml.Array.concat = builtin(vm) +fn baml._float_total_cmp = builtin(vm) -fn baml.Map.delete = builtin(vm) +fn baml._is_primitive_array = builtin(vm) -fn baml.Array.every = builtin(vm) +fn baml._rust_sort = builtin(vm) fn baml.Array.filled = builtin(vm) -fn baml.Array.filter = builtin(vm) - -fn baml.Array.filter_map(self: baml.Array, fn: (T) -> null | U throws E) -> U[] { +fn baml.Array.generate(length: int, f: (int) -> T throws E) -> T[] { // Locals: - let _0: U[] // _0 // return - let _1: baml.Array // self // param - let _2: (T) -> null | U throws E // fn // param - let _3: U[] // out - let _4: T[] - let _5: int - let _6: type - let _7: baml.iter.Iterator - let _8: unknown - let _9: bool - let _10: T - let _11: T // x - let _12: null | U - let _13: T - let _14: bool - let _15: U // y - let _16: int - let _17: U + let _0: T[] // _0 // return + let _1: int // length // param + let _2: (int) -> T throws E // f // param + let _3: T[] // out + let _4: int // i + let _5: bool + let _6: int + let _7: int + let _8: T + let _9: int bb0: { - _3 = []: #1[]; - _5 = len(_1); + _3 = []: #0[]; + _4 = const 0_i64; goto -> bb1; } bb1: { - _6 = load_type(#0); - _4 = call const fn baml.Array.slice(copy _1, const 0_i64, copy _5) -> [bb2]; + _6 = copy _4; + _5 = copy _6 < copy _1; + branch copy _5 -> [bb4, bb2]; } bb2: { - _7 = virtual_call iter as baml.iter.Iterable(copy _4) -> [bb3]; + _0 = copy _3; + goto -> bb3; } bb3: { - _8 = virtual_call next as baml.iter.Iterator(copy _7) -> [bb4]; + return; } bb4: { - _9 = is_type(copy _8, baml.iter.Done); - branch copy _9 -> [bb8, bb5]; + _9 = copy _4; + _8 = call copy _2(copy _9) -> [bb5]; } bb5: { - _10 = copy _8; - fresh_cell(_11); - _11 = copy _10; - _13 = copy _11; - _12 = call copy _2(copy _13) -> [bb6]; + _7 = call const fn baml.Array.push(copy _3, copy _8) -> [bb6]; } bb6: { - _14 = copy _12 == const null; - branch copy _14 -> [bb3, bb7]; - } - - bb7: { - _15 = copy _12; - _17 = copy _15; - _16 = call const fn baml.Array.push(copy _3, copy _17) -> [bb3]; - } - - bb8: { - _0 = copy _3; - goto -> bb9; - } - - bb9: { - return; + _4 = copy _4 + const 1_i64; + goto -> bb1; } } -fn baml.Array.find = builtin(vm) +fn baml.Array.length = builtin(vm) -fn baml.Array.find_index = builtin(vm) +fn baml.Array.at = builtin(vm) -fn baml.Array.find_last = builtin(vm) +fn baml.Array.push = builtin(vm) -fn baml.Array.find_last_index = builtin(vm) +fn baml.Array.pop = builtin(vm) -fn baml.Array.flat_map = builtin(vm) +fn baml.Array.remove_at = builtin(vm) + +fn baml.Array.concat = builtin(vm) fn baml.Array.for_each(self: baml.Array, fn: (T) -> void throws E) -> void { // Locals: @@ -379,128 +334,87 @@ fn baml.Array.for_each(self: baml.Array, fn: (T) -> void throws E) -> void { } } -fn baml.Array.generate(length: int, f: (int) -> T throws E) -> T[] { +fn baml.Array.filter = builtin(vm) + +fn baml.Array.filter_map(self: baml.Array, fn: (T) -> null | U throws E) -> U[] { // Locals: - let _0: T[] // _0 // return - let _1: int // length // param - let _2: (int) -> T throws E // f // param - let _3: T[] // out - let _4: int // i - let _5: bool - let _6: int - let _7: int - let _8: T - let _9: int + let _0: U[] // _0 // return + let _1: baml.Array // self // param + let _2: (T) -> null | U throws E // fn // param + let _3: U[] // out + let _4: T[] + let _5: int + let _6: type + let _7: baml.iter.Iterator + let _8: unknown + let _9: bool + let _10: T + let _11: T // x + let _12: null | U + let _13: T + let _14: bool + let _15: U // y + let _16: int + let _17: U bb0: { - _3 = []: #0[]; - _4 = const 0_i64; + _3 = []: #1[]; + _5 = len(_1); goto -> bb1; } bb1: { - _6 = copy _4; - _5 = copy _6 < copy _1; - branch copy _5 -> [bb4, bb2]; + _6 = load_type(#0); + _4 = call const fn baml.Array.slice(copy _1, const 0_i64, copy _5) -> [bb2]; } bb2: { - _0 = copy _3; - goto -> bb3; + _7 = virtual_call iter as baml.iter.Iterable(copy _4) -> [bb3]; } bb3: { - return; + _8 = virtual_call next as baml.iter.Iterator(copy _7) -> [bb4]; } bb4: { - _9 = copy _4; - _8 = call copy _2(copy _9) -> [bb5]; + _9 = is_type(copy _8, baml.iter.Done); + branch copy _9 -> [bb8, bb5]; } bb5: { - _7 = call const fn baml.Array.push(copy _3, copy _8) -> [bb6]; + _10 = copy _8; + fresh_cell(_11); + _11 = copy _10; + _13 = copy _11; + _12 = call copy _2(copy _13) -> [bb6]; } bb6: { - _4 = copy _4 + const 1_i64; - goto -> bb1; + _14 = copy _12 == const null; + branch copy _14 -> [bb3, bb7]; } -} - -fn baml.Map.get = builtin(vm) - -fn baml.Map.get_or_insert = builtin(vm) -fn baml.Map.has = builtin(vm) - -fn baml.Array.includes = builtin(vm) - -fn baml.Array.index_of = builtin(vm) - -fn baml.Array.insert = builtin(vm) - -fn baml.Array.join = builtin(vm) - -fn baml.Map.keys = builtin(vm) + bb7: { + _15 = copy _12; + _17 = copy _15; + _16 = call const fn baml.Array.push(copy _3, copy _17) -> [bb3]; + } -fn baml.Array.last_index_of = builtin(vm) + bb8: { + _0 = copy _3; + goto -> bb9; + } -fn baml.Map.length = builtin(vm) + bb9: { + return; + } +} -fn baml.Array.length = builtin(vm) +fn baml.Array.reverse = builtin(vm) -fn baml.Array.map = builtin(vm) +fn baml.Array.sort_by = builtin(vm) -fn baml.FloatStats$for$float[].mean(self: float[]) -> float { - // Locals: - let _0: float // _0 // return - let _1: float[] // self // param - - bb0: { - _0 = call const fn baml._mean_float(copy _1) -> [bb1]; - } - - bb1: { - return; - } -} - -fn baml.FloatStats$for$float[].median(self: float[]) -> float { - // Locals: - let _0: float // _0 // return - let _1: float[] // self // param - - bb0: { - _0 = call const fn baml._median_float(copy _1) -> [bb1]; - } - - bb1: { - return; - } -} - -fn baml.Array.pop = builtin(vm) - -fn baml.Array.push = builtin(vm) - -fn baml.Array.reduce = builtin(vm) - -fn baml.Array.remove_at = builtin(vm) - -fn baml.Array.reverse = builtin(vm) - -fn baml.Map.set = builtin(vm) - -fn baml.Array.shift = builtin(vm) - -fn baml.Array.slice = builtin(vm) - -fn baml.Array.some = builtin(vm) - -fn baml.Array.sort_by = builtin(vm) - -fn baml.Array.sort_by_key(self: baml.Array, key: (T) -> U throws E) -> T[] { +fn baml.Array.sort_by_key(self: baml.Array, key: (T) -> U throws E) -> T[] { // Locals: let _0: T[] // _0 // return let _1: baml.Array // self // param @@ -766,8 +680,76 @@ fn .(i: int, j: int) -> null { } } +fn baml.Array.slice = builtin(vm) + +fn baml.Array.join = builtin(vm) + +fn baml.Array.map = builtin(vm) + +fn baml.Array.some = builtin(vm) + +fn baml.Array.every = builtin(vm) + +fn baml.Array.find = builtin(vm) + +fn baml.Array.find_index = builtin(vm) + +fn baml.Array.find_last = builtin(vm) + +fn baml.Array.find_last_index = builtin(vm) + +fn baml.Array.includes = builtin(vm) + +fn baml.Array.index_of = builtin(vm) + +fn baml.Array.last_index_of = builtin(vm) + +fn baml.Array.reduce = builtin(vm) + +fn baml.Array.flat_map = builtin(vm) + +fn baml.Array.clear = builtin(vm) + +fn baml.Array.shift = builtin(vm) + +fn baml.Array.unshift = builtin(vm) + +fn baml.Array.insert = builtin(vm) + fn baml.Array.splice = builtin(vm) +fn baml.Map.length = builtin(vm) + +fn baml.Map.has = builtin(vm) + +fn baml.Map.keys = builtin(vm) + +fn baml.Map.values = builtin(vm) + +fn baml.Map.set = builtin(vm) + +fn baml.Map.get = builtin(vm) + +fn baml.Map.delete = builtin(vm) + +fn baml.Map.get_or_insert = builtin(vm) + +fn baml.Map.clear = builtin(vm) + +fn baml.Summable$for$int[].sum(self: int[]) -> int { + // Locals: + let _0: int // _0 // return + let _1: int[] // self // param + + bb0: { + _0 = call const fn baml._sum_int(copy _1) -> [bb1]; + } + + bb1: { + return; + } +} + fn baml.Summable$for$float[].sum(self: float[]) -> float { // Locals: let _0: float // _0 // return @@ -782,13 +764,13 @@ fn baml.Summable$for$float[].sum(self: float[]) -> float { } } -fn baml.Summable$for$int[].sum(self: int[]) -> int { +fn baml.FloatStats$for$float[].mean(self: float[]) -> float { // Locals: - let _0: int // _0 // return - let _1: int[] // self // param + let _0: float // _0 // return + let _1: float[] // self // param bb0: { - _0 = call const fn baml._sum_int(copy _1) -> [bb1]; + _0 = call const fn baml._mean_float(copy _1) -> [bb1]; } bb1: { @@ -796,29 +778,13 @@ fn baml.Summable$for$int[].sum(self: int[]) -> int { } } -fn baml.Array.unshift = builtin(vm) - -fn baml.Map.values = builtin(vm) - -fn baml._cleanup_begin = builtin(vm) - -fn baml._from_json_shim = builtin(vm) - -fn baml._to_json_default = builtin(vm) - -fn baml._to_json_shim = builtin(vm) - -fn baml._to_string_default = builtin(vm) - -fn baml._to_string_shim = builtin(vm) - -fn baml.ToJson.to_json(self: baml.ToJson) -> int | float | string | bool | null | baml.json.json[] | map { +fn baml.FloatStats$for$float[].median(self: float[]) -> float { // Locals: - let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return - let _1: baml.ToJson // self // param + let _0: float // _0 // return + let _1: float[] // self // param bb0: { - _0 = call const fn baml._to_json_default(copy _1) -> [bb1]; + _0 = call const fn baml._median_float(copy _1) -> [bb1]; } bb1: { @@ -826,6 +792,14 @@ fn baml.ToJson.to_json(self: baml.ToJson) -> int | float | string | bool | null } } +fn baml._sum_int = builtin(vm) + +fn baml._sum_float = builtin(vm) + +fn baml._mean_float = builtin(vm) + +fn baml._median_float = builtin(vm) + fn baml.ToString.to_string(self: baml.ToString) -> string { // Locals: let _0: string // _0 // return @@ -840,53 +814,39 @@ fn baml.ToString.to_string(self: baml.ToString) -> string { } } -fn baml.deep_copy = builtin(vm) - -fn baml.deep_equals = builtin(vm) - -fn baml._trunc_to_int = builtin(vm) - -fn baml.Float.abs = builtin(vm) - -fn baml.Float.acos = builtin(vm) - -fn baml.Float.acosh = builtin(vm) - -fn baml.Float.asin = builtin(vm) - -fn baml.Float.asinh = builtin(vm) - -fn baml.Float.atan = builtin(vm) - -fn baml.Float.atan2 = builtin(vm) - -fn baml.Float.atanh = builtin(vm) - -fn baml.Float.ceil = builtin(vm) +fn baml._to_string_default = builtin(vm) -fn baml.Float.clamp = builtin(vm) +fn baml._to_string_shim = builtin(vm) -fn baml.Float.cos = builtin(vm) +fn baml._cleanup_begin = builtin(vm) -fn baml.Float.cosh = builtin(vm) +fn baml.ToJson.to_json(self: baml.ToJson) -> int | float | string | bool | null | baml.json.json[] | map { + // Locals: + let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return + let _1: baml.ToJson // self // param -fn baml.Float.e = builtin(vm) + bb0: { + _0 = call const fn baml._to_json_default(copy _1) -> [bb1]; + } -fn baml.Float.floor = builtin(vm) + bb1: { + return; + } +} -fn baml.Float.fract = builtin(vm) +fn baml._to_json_default = builtin(vm) -fn baml.Float.golden_ratio = builtin(vm) +fn baml._to_json_shim = builtin(vm) -fn baml.Float.hypot = builtin(vm) +fn baml._from_json_shim = builtin(vm) -fn baml.Float.iceil = builtin(vm) +fn baml.deep_copy = builtin(vm) -fn baml.Float.ifloor = builtin(vm) +fn baml.deep_equals = builtin(vm) -fn baml.Float.inf = builtin(vm) +fn baml.Float.is_nan = builtin(vm) -fn baml.Float.iround = builtin(vm) +fn baml.Float.is_infinite = builtin(vm) fn baml.Float.is_finite(self: baml.Float) -> bool { // Locals: @@ -919,54 +879,80 @@ fn baml.Float.is_finite(self: baml.Float) -> bool { } } -fn baml.Float.is_infinite = builtin(vm) - -fn baml.Float.is_nan = builtin(vm) - -fn baml.Float.itrunc = builtin(vm) +fn baml.Float.abs = builtin(vm) -fn baml.Float.log = builtin(vm) +fn baml.Float.min = builtin(vm) fn baml.Float.max = builtin(vm) -fn baml.Float.min = builtin(vm) +fn baml.Float.clamp = builtin(vm) -fn baml.Float.nan = builtin(vm) +fn baml.Float.floor = builtin(vm) -fn baml.Float.parse = builtin(vm) +fn baml.Float.ceil = builtin(vm) -fn baml.Float.pi = builtin(vm) +fn baml.Float.round = builtin(vm) -fn baml.Float.pow = builtin(vm) +fn baml.Float.trunc = builtin(vm) -fn baml.Float.random = builtin(vm) +fn baml.Float.fract = builtin(vm) -fn baml.Float.round = builtin(vm) +fn baml.Float.ifloor = builtin(vm) -fn baml.Float.sin = builtin(vm) +fn baml.Float.iceil = builtin(vm) -fn baml.Float.sinh = builtin(vm) +fn baml.Float.iround = builtin(vm) + +fn baml.Float.itrunc = builtin(vm) fn baml.Float.sqrt = builtin(vm) -fn baml.Float.tan = builtin(vm) +fn baml.Float.pow = builtin(vm) -fn baml.Float.tanh = builtin(vm) +fn baml.Float.log = builtin(vm) -fn baml.Float.to_degrees(self: baml.Float) -> float { - // Locals: - let _0: float // _0 // return - let _1: baml.Float // self // param - let _2: float - let _3: float +fn baml.Float.hypot = builtin(vm) - bb0: { - _2 = copy _1 * const 180_f64; - _3 = call const fn baml.Float.pi() -> [bb1]; - } +fn baml.Float.sin = builtin(vm) + +fn baml.Float.cos = builtin(vm) + +fn baml.Float.tan = builtin(vm) + +fn baml.Float.asin = builtin(vm) + +fn baml.Float.acos = builtin(vm) + +fn baml.Float.atan = builtin(vm) + +fn baml.Float.atan2 = builtin(vm) + +fn baml.Float.sinh = builtin(vm) + +fn baml.Float.cosh = builtin(vm) + +fn baml.Float.tanh = builtin(vm) + +fn baml.Float.asinh = builtin(vm) + +fn baml.Float.acosh = builtin(vm) + +fn baml.Float.atanh = builtin(vm) + +fn baml.Float.to_radians(self: baml.Float) -> float { + // Locals: + let _0: float // _0 // return + let _1: baml.Float // self // param + let _2: float + let _3: float + + bb0: { + _3 = call const fn baml.Float.pi() -> [bb1]; + } bb1: { - _0 = copy _2 / copy _3; + _2 = copy _1 * copy _3; + _0 = copy _2 / const 180_f64; goto -> bb2; } @@ -975,7 +961,7 @@ fn baml.Float.to_degrees(self: baml.Float) -> float { } } -fn baml.Float.to_radians(self: baml.Float) -> float { +fn baml.Float.to_degrees(self: baml.Float) -> float { // Locals: let _0: float // _0 // return let _1: baml.Float // self // param @@ -983,12 +969,12 @@ fn baml.Float.to_radians(self: baml.Float) -> float { let _3: float bb0: { + _2 = copy _1 * const 180_f64; _3 = call const fn baml.Float.pi() -> [bb1]; } bb1: { - _2 = copy _1 * copy _3; - _0 = copy _2 / const 180_f64; + _0 = copy _2 / copy _3; goto -> bb2; } @@ -997,25 +983,51 @@ fn baml.Float.to_radians(self: baml.Float) -> float { } } -fn baml.Float.trunc = builtin(vm) +fn baml.Float.parse = builtin(vm) + +fn baml.Float.random = builtin(vm) + +fn baml.Float.pi = builtin(vm) + +fn baml.Float.e = builtin(vm) + +fn baml.Float.golden_ratio = builtin(vm) + +fn baml.Float.nan = builtin(vm) + +fn baml.Float.inf = builtin(vm) + +fn baml._trunc_to_int = builtin(vm) fn baml.Int.abs = builtin(vm) +fn baml.Int.min = builtin(vm) + +fn baml.Int.max = builtin(vm) + fn baml.Int.clamp = builtin(vm) -fn baml.Int.count_ones = builtin(vm) +fn baml.Int.isqrt = builtin(vm) -fn baml.Int.count_zeros = builtin(vm) +fn baml.Int.pow = builtin(vm) fn baml.Int.ilog = builtin(vm) -fn baml.Int.isqrt = builtin(vm) +fn baml.Int.leading_zeros = builtin(vm) fn baml.Int.leading_ones = builtin(vm) -fn baml.Int.leading_zeros = builtin(vm) +fn baml.Int.trailing_zeros = builtin(vm) -fn baml.Int.max = builtin(vm) +fn baml.Int.trailing_ones = builtin(vm) + +fn baml.Int.count_zeros = builtin(vm) + +fn baml.Int.count_ones = builtin(vm) + +fn baml.Int.parse = builtin(vm) + +fn baml.Int.random = builtin(vm) fn baml.Int.max_value() -> int { // Locals: @@ -1031,8 +1043,6 @@ fn baml.Int.max_value() -> int { } } -fn baml.Int.min = builtin(vm) - fn baml.Int.min_value() -> int { // Locals: let _0: int // _0 // return @@ -1047,136 +1057,313 @@ fn baml.Int.min_value() -> int { } } -fn baml.Int.parse = builtin(vm) +fn baml.csv.CsvRecord.get(self: baml.csv.CsvRecord, column: string) -> null | T { + // Locals: + let _0: null | T // _0 // return + let _1: baml.csv.CsvRecord // self // param + let _2: string // column // param + let _3: type -fn baml.Int.pow = builtin(vm) + bb0: { + _3 = load_type(#0); + _0 = call const fn baml.csv._cell_by_name(copy _1, copy _2) -> [bb1]; + } -fn baml.Int.random = builtin(vm) + bb1: { + return; + } +} -fn baml.Int.trailing_ones = builtin(vm) +fn baml.csv.CsvRecord.get_at(self: baml.csv.CsvRecord, index: int) -> null | T { + // Locals: + let _0: null | T // _0 // return + let _1: baml.csv.CsvRecord // self // param + let _2: int // index // param + let _3: type -fn baml.Int.trailing_zeros = builtin(vm) + bb0: { + _3 = load_type(#0); + _0 = call const fn baml.csv._cell_by_index(copy _1, copy _2) -> [bb1]; + } -fn baml.csv._buffer = builtin(vm) + bb1: { + return; + } +} -fn baml.csv.CsvWriter._bytes_written = builtin(vm) +fn baml.csv.CsvRecord.fields = builtin(vm) -fn baml.csv._cell_by_index = builtin(vm) +fn baml.csv.CsvRecord.length = builtin(vm) -fn baml.csv._cell_by_name = builtin(vm) +fn baml.csv.CsvRecord.position = builtin(vm) -fn baml.csv._decode_record = builtin(vm) +fn baml.csv.CsvRecord.decode(self: baml.csv.CsvRecord) -> T { + // Locals: + let _0: T // _0 // return + let _1: baml.csv.CsvRecord // self // param + let _2: type -fn baml.csv.CsvWriter._emit(self: baml.csv.CsvWriter, out: string) -> null { + bb0: { + _2 = load_type(#0); + _0 = call const fn baml.csv._decode_record(copy _1) -> [bb1]; + } + + bb1: { + return; + } +} + +fn baml.csv.CsvRecord.to_map = builtin(vm) + +fn baml.csv.CsvReader.root.iter.Iterable.iter(self: baml.csv.CsvReader) -> baml.iter.Iterator { // Locals: - let _0: null // _0 // return - let _1: baml.csv.CsvWriter // self // param - let _2: string // out // param - let _3: null | baml.fs.File - let _4: bool - let _5: baml.fs.File // f - let _6: bool - let _7: int - let _8: int - let _9: unknown // _ - let _10: bool - let _11: string - let _12: string // message - let _13: baml.errors.Io - let _14: string - let _15: string + let _0: baml.iter.Iterator // _0 // return + let _1: baml.csv.CsvReader // self // param bb0: { - _3 = copy _1.1; - _4 = copy _3 == const null; - branch copy _4 -> [bb5, bb1]; + _0 = copy _1; + goto -> bb1; } bb1: { - _5 = copy _3; - _7 = call const fn baml.String.length(copy _2) -> [bb2]; + return; + } +} + +fn baml.csv.CsvReader.root.iter.Iterator.next(self: baml.csv.CsvReader) -> baml.csv.CsvRecord | baml.iter.Done { + // Locals: + let _0: baml.csv.CsvRecord | baml.iter.Done // _0 // return + let _1: baml.csv.CsvReader // self // param + let _2: baml.csv.CsvNeedData | baml.csv.CsvRecord | baml.csv.CsvSkip | baml.iter.Done + let _3: int + let _4: baml.csv.CsvRecord // rec + let _5: baml.iter.Done // d + let _6: baml.csv.CsvSkip // s + let _7: null + let _8: null | ((baml.csv.CsvError) -> null throws never) + let _9: bool + let _10: (baml.csv.CsvError) -> null throws never // cb + let _11: (baml.csv.CsvError) -> null throws never + let _12: baml.csv.CsvError + let _13: null + + bb0: { + goto -> bb1; + } + + bb1: { + branch const true -> [bb3, bb2]; } bb2: { - _6 = copy _7 > const 0_i64; - branch copy _6 -> [bb3, bb4]; + _0 = call const fn baml.sys.panic(const "unreachable: CsvReader.next loop ended") -> [bb12]; } bb3: { - _8 = sys_op const fn baml.fs.File.write(copy _5, copy _2) -> bb4 unwind bb7; + _2 = call const fn baml.csv.CsvReader._poll(copy _1) -> [bb4]; } bb4: { - _0 = const null; - goto -> bb6; + _3 = type_tag(_2); + switch copy _3 [CsvRecord: bb11, Done: bb10, CsvSkip: bb7, CsvNeedData: bb6, otherwise: bb5] (exhaustive); } bb5: { - _0 = const null; - goto -> bb6; + unreachable; } bb6: { - return; + _13 = call const fn baml.csv.CsvReader._read_chunk(copy _1) -> [bb1]; } bb7: { - _10 = is_type(copy _9, baml.errors.InvalidArgument); - branch copy _10 -> [bb9, bb8]; + _6 = copy _2; + _8 = copy _1.2; + _9 = copy _8 == const null; + branch copy _9 -> [bb9, bb8]; } bb8: { - rethrow copy _9; + _10 = copy _8; + _11 = copy _10; + _12 = copy _6.0; + _7 = call copy _11(copy _12) -> [bb1]; } bb9: { - _11 = copy _9.0; - _12 = copy _11; - _15 = copy _12; - _14 = const "underlying file handle is closed: " + copy _15; - _13 = baml.errors.Io { copy _14 }; - throw copy _13; + _7 = const null; + goto -> bb1; } -} - -fn baml.csv.CsvWriter._encode_header = builtin(vm) -fn baml.csv.CsvWriter._encode_record = builtin(vm) + bb10: { + _5 = copy _2; + _0 = copy _5; + goto -> bb12; + } -fn baml.csv._encode_row = builtin(vm) + bb11: { + _4 = copy _2; + _0 = copy _4; + goto -> bb12; + } -fn baml.csv._encode_rows = builtin(vm) + bb12: { + return; + } +} -fn baml.csv._error(kind: baml.csv.CsvErrorKind, message: string) -> baml.csv.CsvError { +fn baml.csv.CsvReader.headers(self: baml.csv.CsvReader) -> null | string[] { // Locals: - let _0: baml.csv.CsvError // _0 // return - let _1: baml.csv.CsvErrorKind // kind // param - let _2: string // message // param - - bb0: { - _0 = baml.csv.CsvError { copy _1, copy _2, const null, const null, const null, const null, const null, const null }; + let _0: null | string[] // _0 // return + let _1: baml.csv.CsvReader // self // param + let _2: baml.csv.CsvHeaders | baml.csv.CsvNeedData + let _3: bool + let _4: baml.csv.CsvHeaders // h + let _5: null + + bb0: { goto -> bb1; } bb1: { + branch const true -> [bb3, bb2]; + } + + bb2: { + _0 = call const fn baml.sys.panic(const "unreachable: CsvReader.headers loop ended") -> [bb7]; + } + + bb3: { + _2 = call const fn baml.csv.CsvReader._poll_headers(copy _1) -> [bb4]; + } + + bb4: { + _3 = is_type(copy _2, baml.csv.CsvHeaders); + branch copy _3 -> [bb6, bb5]; + } + + bb5: { + _5 = call const fn baml.csv.CsvReader._read_chunk(copy _1) -> [bb1]; + } + + bb6: { + _4 = copy _2; + _0 = copy _4.0; + goto -> bb7; + } + + bb7: { return; } } -fn baml.csv.CsvReader._feed = builtin(vm) +fn baml.csv.CsvReader.rows(self: baml.csv.CsvReader) -> baml.iter.Iterator { + // Locals: + let _0: baml.iter.Iterator // _0 // return + let _1: baml.csv.CsvReader // self // param + let _2: null | string[] + let _3: null + let _4: type -fn baml.csv.CsvReader._feed_eof = builtin(vm) + bb0: { + _2 = call const fn baml.csv.CsvReader.headers(copy _1) -> [bb1]; + } -fn baml.csv.CsvWriter._mark_closed = builtin(vm) + bb1: { + _4 = load_type(#0); + _3 = call const fn baml.csv._validate_columns(copy _1) -> [bb2]; + } -fn baml.csv.CsvReader._mark_closed = builtin(vm) + bb2: { + _0 = baml.csv.CsvRows<#0> { copy _1 }; + goto -> bb3; + } -fn baml.csv.CsvReader._mark_exhausted = builtin(vm) + bb3: { + return; + } +} + +fn baml.csv.CsvReader.skipped = builtin(vm) + +fn baml.csv.CsvReader.skipped_count = builtin(vm) + +fn baml.csv.CsvReader.position = builtin(vm) + +fn baml.csv.CsvReader.close(self: baml.csv.CsvReader) -> null { + // Locals: + let _0: null // _0 // return + let _1: baml.csv.CsvReader // self // param + let _2: null + let _3: null | baml.fs.File + let _4: bool + let _5: baml.fs.File // f + let _6: bool + let _7: null + let _8: unknown // _ + let _9: bool + + bb0: { + _2 = call const fn baml.csv.CsvReader._mark_closed(copy _1) -> [bb1]; + } + + bb1: { + _3 = copy _1.1; + _4 = copy _3 == const null; + branch copy _4 -> [bb4, bb2]; + } + + bb2: { + _5 = copy _3; + _6 = copy _1.3; + branch copy _6 -> [bb3, bb8]; + } + + bb3: { + _7 = sys_op const fn baml.fs.File.close(copy _5) -> bb8 unwind bb5; + } + + bb4: { + _0 = const null; + goto -> bb9; + } + + bb5: { + _9 = is_type(copy _8, baml.errors.InvalidArgument); + branch copy _9 -> [bb7, bb6]; + } + + bb6: { + rethrow copy _8; + } + + bb7: { + _7 = const null; + goto -> bb8; + } + + bb8: { + _0 = const null; + goto -> bb9; + } + + bb9: { + return; + } +} fn baml.csv.CsvReader._poll = builtin(vm) fn baml.csv.CsvReader._poll_headers = builtin(vm) +fn baml.csv.CsvReader._feed = builtin(vm) + +fn baml.csv.CsvReader._feed_eof = builtin(vm) + +fn baml.csv.CsvReader._mark_closed = builtin(vm) + +fn baml.csv.CsvReader._mark_exhausted = builtin(vm) + fn baml.csv.CsvReader._read_chunk(self: baml.csv.CsvReader) -> null { // Locals: let _0: null // _0 // return @@ -1284,120 +1471,233 @@ fn baml.csv.CsvReader._read_chunk(self: baml.csv.CsvReader) -> null { } } -fn baml.csv._reader = builtin(vm) - -fn baml.csv._to_markdown = builtin(vm) - -fn baml.csv._to_markdown_records = builtin(vm) - -fn baml.csv._try_decode = builtin(vm) - -fn baml.csv._validate_columns = builtin(vm) - -fn baml.csv._writer = builtin(vm) - -fn baml.csv.buffer(options: null | baml.csv.WriterOptions) -> baml.csv.CsvWriter { +fn baml.csv.CsvRows.root.iter.Iterable.iter(self: baml.csv.CsvRows) -> baml.iter.Iterator { // Locals: - let _0: baml.csv.CsvWriter // _0 // return - let _1: null | baml.csv.WriterOptions // options // param - let _2: bool + let _0: baml.iter.Iterator // _0 // return + let _1: baml.csv.CsvRows // self // param bb0: { - _2 = copy _1 == const ; - branch copy _2 -> [bb1, bb2]; + _0 = copy _1; + goto -> bb1; } bb1: { - _1 = const null; - goto -> bb2; - } - - bb2: { - _0 = call const fn baml.csv._buffer(copy _1) -> [bb3]; - } - - bb3: { return; } } -fn baml.csv.CsvWriter.close(self: baml.csv.CsvWriter) -> null { +fn baml.csv.CsvRows.root.iter.Iterator.next(self: baml.csv.CsvRows) -> baml.iter.Done | T { // Locals: - let _0: null // _0 // return - let _1: baml.csv.CsvWriter // self // param - let _2: null - let _3: null | baml.fs.File + let _0: baml.iter.Done | T // _0 // return + let _1: baml.csv.CsvRows // self // param + let _2: baml.csv.CsvRecord | baml.iter.Done + let _3: baml.csv.CsvReader let _4: bool - let _5: baml.fs.File // f - let _6: bool - let _7: null - let _8: unknown // _ - let _9: bool + let _5: baml.iter.Done // d + let _6: baml.csv.CsvRecord // rec + let _7: baml.csv.CsvSkip | T + let _8: baml.csv.CsvRecord + let _9: baml.csv.CsvReader + let _10: type + let _11: bool + let _12: baml.csv.CsvSkip // s + let _13: null + let _14: null | ((baml.csv.CsvError) -> null throws never) + let _15: bool + let _16: (baml.csv.CsvError) -> null throws never // cb + let _17: (baml.csv.CsvError) -> null throws never + let _18: baml.csv.CsvError + let _19: T // v bb0: { - _2 = call const fn baml.csv.CsvWriter._mark_closed(copy _1) -> [bb1]; + goto -> bb1; } bb1: { - _3 = copy _1.1; - _4 = copy _3 == const null; - branch copy _4 -> [bb4, bb2]; + branch const true -> [bb3, bb2]; } bb2: { - _5 = copy _3; - _6 = copy _1.2; - branch copy _6 -> [bb3, bb8]; + _0 = call const fn baml.sys.panic(const "unreachable: CsvRows.next loop ended") -> [bb12]; } bb3: { - _7 = sys_op const fn baml.fs.File.close(copy _5) -> bb8 unwind bb5; + _3 = copy _1.0; + _2 = virtual_call next as baml.iter.Iterator(copy _3) -> [bb4]; } bb4: { - _0 = const null; - goto -> bb9; + _4 = is_type(copy _2, baml.iter.Done); + branch copy _4 -> [bb11, bb5]; } bb5: { - _9 = is_type(copy _8, baml.errors.InvalidArgument); - branch copy _9 -> [bb7, bb6]; + _6 = copy _2; + _8 = copy _6; + _9 = copy _1.0; + _10 = load_type(#0); + _7 = call const fn baml.csv._try_decode(copy _8, copy _9) -> [bb6]; } bb6: { - rethrow copy _8; + _11 = is_type(copy _7, baml.csv.CsvSkip); + branch copy _11 -> [bb8, bb7]; } bb7: { - _7 = const null; - goto -> bb8; + _19 = copy _7; + _0 = copy _19; + goto -> bb12; } bb8: { - _0 = const null; - goto -> bb9; + _12 = copy _7; + _14 = copy _1.0.2; + _15 = copy _14 == const null; + branch copy _15 -> [bb10, bb9]; } bb9: { - return; + _16 = copy _14; + _17 = copy _16; + _18 = copy _12.0; + _13 = call copy _17(copy _18) -> [bb1]; } -} -fn baml.csv.CsvReader.close(self: baml.csv.CsvReader) -> null { - // Locals: - let _0: null // _0 // return - let _1: baml.csv.CsvReader // self // param - let _2: null - let _3: null | baml.fs.File - let _4: bool - let _5: baml.fs.File // f - let _6: bool - let _7: null - let _8: unknown // _ + bb10: { + _13 = const null; + goto -> bb1; + } + + bb11: { + _5 = copy _2; + _0 = copy _5; + goto -> bb12; + } + + bb12: { + return; + } +} + +fn baml.csv.CsvWriter.write_record(self: baml.csv.CsvWriter, record: (int | bigint | float | string | bool | null)[]) -> null { + // Locals: + let _0: null // _0 // return + let _1: baml.csv.CsvWriter // self // param + let _2: (int | bigint | float | string | bool | null)[] // record // param + let _3: string + + bb0: { + _3 = call const fn baml.csv.CsvWriter._encode_record(copy _1, copy _2) -> [bb1]; + } + + bb1: { + _0 = call const fn baml.csv.CsvWriter._emit(copy _1, copy _3) -> [bb2]; + } + + bb2: { + return; + } +} + +fn baml.csv.CsvWriter.write_row(self: baml.csv.CsvWriter, row: T) -> null { + // Locals: + let _0: null // _0 // return + let _1: baml.csv.CsvWriter // self // param + let _2: T // row // param + let _3: string + let _4: type + + bb0: { + _4 = load_type(#0); + _3 = call const fn baml.csv._encode_row(copy _1, copy _2) -> [bb1]; + } + + bb1: { + _0 = call const fn baml.csv.CsvWriter._emit(copy _1, copy _3) -> [bb2]; + } + + bb2: { + return; + } +} + +fn baml.csv.CsvWriter.write_rows(self: baml.csv.CsvWriter, rows: T[]) -> null { + // Locals: + let _0: null // _0 // return + let _1: baml.csv.CsvWriter // self // param + let _2: T[] // rows // param + let _3: string + let _4: type + + bb0: { + _4 = load_type(#0); + _3 = call const fn baml.csv._encode_rows(copy _1, copy _2) -> [bb1]; + } + + bb1: { + _0 = call const fn baml.csv.CsvWriter._emit(copy _1, copy _3) -> [bb2]; + } + + bb2: { + return; + } +} + +fn baml.csv.CsvWriter.write_header(self: baml.csv.CsvWriter, names: string[]) -> null { + // Locals: + let _0: null // _0 // return + let _1: baml.csv.CsvWriter // self // param + let _2: string[] // names // param + let _3: string + + bb0: { + _3 = call const fn baml.csv.CsvWriter._encode_header(copy _1, copy _2) -> [bb1]; + } + + bb1: { + _0 = call const fn baml.csv.CsvWriter._emit(copy _1, copy _3) -> [bb2]; + } + + bb2: { + return; + } +} + +fn baml.csv.CsvWriter.records_written = builtin(vm) + +fn baml.csv.CsvWriter.text = builtin(vm) + +fn baml.csv.CsvWriter.flush(self: baml.csv.CsvWriter) -> null { + // Locals: + let _0: null // _0 // return + let _1: baml.csv.CsvWriter // self // param + + bb0: { + _0 = const null; + goto -> bb1; + } + + bb1: { + return; + } +} + +fn baml.csv.CsvWriter.close(self: baml.csv.CsvWriter) -> null { + // Locals: + let _0: null // _0 // return + let _1: baml.csv.CsvWriter // self // param + let _2: null + let _3: null | baml.fs.File + let _4: bool + let _5: baml.fs.File // f + let _6: bool + let _7: null + let _8: unknown // _ let _9: bool bb0: { - _2 = call const fn baml.csv.CsvReader._mark_closed(copy _1) -> [bb1]; + _2 = call const fn baml.csv.CsvWriter._mark_closed(copy _1) -> [bb1]; } bb1: { @@ -1408,7 +1708,7 @@ fn baml.csv.CsvReader.close(self: baml.csv.CsvReader) -> null { bb2: { _5 = copy _3; - _6 = copy _1.3; + _6 = copy _1.2; branch copy _6 -> [bb3, bb8]; } @@ -1445,11 +1745,117 @@ fn baml.csv.CsvReader.close(self: baml.csv.CsvReader) -> null { } } -fn baml.csv.create(path: string, options: null | baml.csv.WriterOptions) -> baml.csv.CsvWriter { +fn baml.csv.CsvWriter._encode_record = builtin(vm) + +fn baml.csv.CsvWriter._encode_header = builtin(vm) + +fn baml.csv.CsvWriter._bytes_written = builtin(vm) + +fn baml.csv.CsvWriter._mark_closed = builtin(vm) + +fn baml.csv.CsvWriter._emit(self: baml.csv.CsvWriter, out: string) -> null { // Locals: - let _0: baml.csv.CsvWriter // _0 // return + let _0: null // _0 // return + let _1: baml.csv.CsvWriter // self // param + let _2: string // out // param + let _3: null | baml.fs.File + let _4: bool + let _5: baml.fs.File // f + let _6: bool + let _7: int + let _8: int + let _9: unknown // _ + let _10: bool + let _11: string + let _12: string // message + let _13: baml.errors.Io + let _14: string + let _15: string + + bb0: { + _3 = copy _1.1; + _4 = copy _3 == const null; + branch copy _4 -> [bb5, bb1]; + } + + bb1: { + _5 = copy _3; + _7 = call const fn baml.String.length(copy _2) -> [bb2]; + } + + bb2: { + _6 = copy _7 > const 0_i64; + branch copy _6 -> [bb3, bb4]; + } + + bb3: { + _8 = sys_op const fn baml.fs.File.write(copy _5, copy _2) -> bb4 unwind bb7; + } + + bb4: { + _0 = const null; + goto -> bb6; + } + + bb5: { + _0 = const null; + goto -> bb6; + } + + bb6: { + return; + } + + bb7: { + _10 = is_type(copy _9, baml.errors.InvalidArgument); + branch copy _10 -> [bb9, bb8]; + } + + bb8: { + rethrow copy _9; + } + + bb9: { + _11 = copy _9.0; + _12 = copy _11; + _15 = copy _12; + _14 = const "underlying file handle is closed: " + copy _15; + _13 = baml.errors.Io { copy _14 }; + throw copy _13; + } +} + +fn baml.csv.reader(source: string | uint8array | baml.fs.File, options: null | baml.csv.ReaderOptions) -> baml.csv.CsvReader { + // Locals: + let _0: baml.csv.CsvReader // _0 // return + let _1: string | uint8array | baml.fs.File // source // param + let _2: null | baml.csv.ReaderOptions // options // param + let _3: bool + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const null; + goto -> bb2; + } + + bb2: { + _0 = call const fn baml.csv._reader(copy _1, copy _2, const false) -> [bb3]; + } + + bb3: { + return; + } +} + +fn baml.csv.open(path: string, options: null | baml.csv.ReaderOptions) -> baml.csv.CsvReader { + // Locals: + let _0: baml.csv.CsvReader // _0 // return let _1: string // path // param - let _2: null | baml.csv.WriterOptions // options // param + let _2: null | baml.csv.ReaderOptions // options // param let _3: bool let _4: baml.fs.File // f let _5: unknown // _ @@ -1471,12 +1877,12 @@ fn baml.csv.create(path: string, options: null | baml.csv.WriterOptions) -> baml } bb2: { - _4 = sys_op const fn baml.fs.open(copy _1, const "w") -> bb3 unwind bb5; + _4 = sys_op const fn baml.fs.open(copy _1, const "r") -> bb3 unwind bb5; } bb3: { _11 = copy _4; - _0 = call const fn baml.csv._writer(copy _11, copy _2, const true) -> [bb4]; + _0 = call const fn baml.csv._reader(copy _11, copy _2, const true) -> [bb4]; } bb4: { @@ -1501,14 +1907,151 @@ fn baml.csv.create(path: string, options: null | baml.csv.WriterOptions) -> baml } } -fn baml.csv.decode(source: string | uint8array, options: null | baml.csv.ReaderOptions) -> T[] { +fn baml.csv.read(path: string, options: null | baml.csv.ReaderOptions) -> T[] { // Locals: let _0: T[] // _0 // return - let _1: string | uint8array // source // param + let _1: string // path // param let _2: null | baml.csv.ReaderOptions // options // param let _3: bool - let _4: unknown // _ - let _5: baml.iter.Iterator + let _4: baml.csv.CsvReader // r + let _5: T[] // result + let _6: baml.iter.Iterator + let _7: type + let _8: null + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const null; + goto -> bb2; + } + + bb2: { + _4 = call const fn baml.csv.open(copy _1, copy _2) -> [bb3]; + } + + bb3: { + _7 = load_type(#0); + _6 = call const fn baml.csv.CsvReader.rows(copy _4) -> [bb4]; + } + + bb4: { + _5 = virtual_call collect as baml.iter.Iterator(copy _6) -> [bb5]; + } + + bb5: { + _8 = call const fn baml.csv.CsvReader.close(copy _4) -> [bb6]; + } + + bb6: { + _0 = copy _5; + goto -> bb7; + } + + bb7: { + return; + } +} + +fn baml.csv.parse(source: string | uint8array, options: null | baml.csv.ReaderOptions) -> string[][] { + // Locals: + let _0: string[][] // _0 // return + let _1: string | uint8array // source // param + let _2: null | baml.csv.ReaderOptions // options // param + let _3: bool + let _4: unknown // _ + let _5: baml.csv.CsvReader // r + let _6: string[][] // out + let _7: baml.csv.CsvRecord | baml.iter.Done + let _8: bool + let _9: baml.csv.CsvRecord // rec + let _10: int + let _11: string[] + let _12: bool + let _13: string + let _14: string // message + let _15: string + let _16: string + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const null; + goto -> bb2; + } + + bb2: { + _5 = call const fn baml.csv.reader(copy _1, copy _2) -> [bb3, unwind: bb10]; + } + + bb3: { + _6 = []: string[][]; + goto -> bb4; + } + + bb4: { + branch const true -> [bb5, bb9]; + } + + bb5: { + _7 = virtual_call next as baml.iter.Iterator(copy _5) -> [bb6, unwind: bb10]; + } + + bb6: { + _8 = is_type(copy _7, baml.iter.Done); + branch copy _8 -> [bb9, bb7]; + } + + bb7: { + _9 = copy _7; + _11 = call const fn baml.csv.CsvRecord.fields(copy _9) -> [bb8, unwind: bb10]; + } + + bb8: { + _10 = call const fn baml.Array.push(copy _6, copy _11) -> [bb4, unwind: bb10]; + } + + bb9: { + _0 = copy _6; + goto -> bb13; + } + + bb10: { + _12 = is_type(copy _4, baml.errors.Io); + branch copy _12 -> [bb12, bb11]; + } + + bb11: { + rethrow copy _4; + } + + bb12: { + _13 = copy _4.0; + _14 = copy _13; + _16 = copy _14; + _15 = const "unreachable: in-memory CSV source raised Io: " + copy _16; + _0 = call const fn baml.sys.panic(copy _15) -> [bb13]; + } + + bb13: { + return; + } +} + +fn baml.csv.decode(source: string | uint8array, options: null | baml.csv.ReaderOptions) -> T[] { + // Locals: + let _0: T[] // _0 // return + let _1: string | uint8array // source // param + let _2: null | baml.csv.ReaderOptions // options // param + let _3: bool + let _4: unknown // _ + let _5: baml.iter.Iterator let _6: baml.csv.CsvReader let _7: type let _8: bool @@ -1562,20 +2105,73 @@ fn baml.csv.decode(source: string | uint8array, options: null | baml.csv.ReaderO } } -fn baml.csv.CsvRecord.decode(self: baml.csv.CsvRecord) -> T { +fn baml.csv.decode_optional(source: string | uint8array, options: null | baml.csv.ReaderOptions) -> null | T { // Locals: - let _0: T // _0 // return - let _1: baml.csv.CsvRecord // self // param - let _2: type + let _0: null | T // _0 // return + let _1: string | uint8array // source // param + let _2: null | baml.csv.ReaderOptions // options // param + let _3: bool + let _4: T[] // all + let _5: type + let _6: bool + let _7: int + let _8: baml.csv.CsvError + let _9: string + let _10: string + let _11: int + let _12: type bb0: { - _2 = load_type(#0); - _0 = call const fn baml.csv._decode_record(copy _1) -> [bb1]; + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } bb1: { + _2 = const null; + goto -> bb2; + } + + bb2: { + _5 = load_type(#0); + _4 = call const fn baml.csv.decode(copy _1, copy _2) -> [bb3]; + } + + bb3: { + _7 = len(_4); + goto -> bb4; + } + + bb4: { + _6 = copy _7 > const 1_i64; + branch copy _6 -> [bb7, bb5]; + } + + bb5: { + _12 = load_type(#0); + _0 = call const fn baml.Array.at(copy _4, const 0_i64) -> [bb6]; + } + + bb6: { return; } + + bb7: { + _11 = len(_4); + goto -> bb8; + } + + bb8: { + _10 = call const fn baml.json.stringify(copy _11) -> [bb9]; + } + + bb9: { + _9 = const "expected at most one data record, found " + copy _10; + _8 = call const fn baml.csv._error(const baml.csv.CsvErrorKind.TooManyRows, copy _9) -> [bb10]; + } + + bb10: { + throw copy _8; + } } fn baml.csv.decode_one(source: string | uint8array, options: null | baml.csv.ReaderOptions) -> T { @@ -1686,21 +2282,12 @@ fn baml.csv.decode_one(source: string | uint8array, options: null | baml.csv.Rea } } -fn baml.csv.decode_optional(source: string | uint8array, options: null | baml.csv.ReaderOptions) -> null | T { +fn baml.csv.writer(file: baml.fs.File, options: null | baml.csv.WriterOptions) -> baml.csv.CsvWriter { // Locals: - let _0: null | T // _0 // return - let _1: string | uint8array // source // param - let _2: null | baml.csv.ReaderOptions // options // param + let _0: baml.csv.CsvWriter // _0 // return + let _1: baml.fs.File // file // param + let _2: null | baml.csv.WriterOptions // options // param let _3: bool - let _4: T[] // all - let _5: type - let _6: bool - let _7: int - let _8: baml.csv.CsvError - let _9: string - let _10: string - let _11: int - let _12: type bb0: { _3 = copy _2 == const ; @@ -1713,898 +2300,875 @@ fn baml.csv.decode_optional(source: string | uint8array, options: null | baml.cs } bb2: { - _5 = load_type(#0); - _4 = call const fn baml.csv.decode(copy _1, copy _2) -> [bb3]; + _0 = call const fn baml.csv._writer(copy _1, copy _2, const false) -> [bb3]; } bb3: { - _7 = len(_4); - goto -> bb4; + return; } +} - bb4: { - _6 = copy _7 > const 1_i64; - branch copy _6 -> [bb7, bb5]; +fn baml.csv.create(path: string, options: null | baml.csv.WriterOptions) -> baml.csv.CsvWriter { + // Locals: + let _0: baml.csv.CsvWriter // _0 // return + let _1: string // path // param + let _2: null | baml.csv.WriterOptions // options // param + let _3: bool + let _4: baml.fs.File // f + let _5: unknown // _ + let _6: bool + let _7: string + let _8: string // message + let _9: baml.errors.Io + let _10: string + let _11: baml.fs.File + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } - bb5: { - _12 = load_type(#0); - _0 = call const fn baml.Array.at(copy _4, const 0_i64) -> [bb6]; + bb1: { + _2 = const null; + goto -> bb2; } - bb6: { - return; - } - - bb7: { - _11 = len(_4); - goto -> bb8; + bb2: { + _4 = sys_op const fn baml.fs.open(copy _1, const "w") -> bb3 unwind bb5; } - bb8: { - _10 = call const fn baml.json.stringify(copy _11) -> [bb9]; + bb3: { + _11 = copy _4; + _0 = call const fn baml.csv._writer(copy _11, copy _2, const true) -> [bb4]; } - bb9: { - _9 = const "expected at most one data record, found " + copy _10; - _8 = call const fn baml.csv._error(const baml.csv.CsvErrorKind.TooManyRows, copy _9) -> [bb10]; + bb4: { + return; } - bb10: { - throw copy _8; + bb5: { + _6 = is_type(copy _5, baml.errors.InvalidArgument); + branch copy _6 -> [bb7, bb6]; } -} -fn baml.csv.CsvRecord.fields = builtin(vm) - -fn baml.csv.CsvWriter.flush(self: baml.csv.CsvWriter) -> null { - // Locals: - let _0: null // _0 // return - let _1: baml.csv.CsvWriter // self // param - - bb0: { - _0 = const null; - goto -> bb1; + bb6: { + rethrow copy _5; } - bb1: { - return; + bb7: { + _7 = copy _5.0; + _8 = copy _7; + _10 = copy _8; + _9 = baml.errors.Io { copy _10 }; + throw copy _9; } } -fn baml.csv.CsvRecord.get(self: baml.csv.CsvRecord, column: string) -> null | T { +fn baml.csv.buffer(options: null | baml.csv.WriterOptions) -> baml.csv.CsvWriter { // Locals: - let _0: null | T // _0 // return - let _1: baml.csv.CsvRecord // self // param - let _2: string // column // param - let _3: type + let _0: baml.csv.CsvWriter // _0 // return + let _1: null | baml.csv.WriterOptions // options // param + let _2: bool bb0: { - _3 = load_type(#0); - _0 = call const fn baml.csv._cell_by_name(copy _1, copy _2) -> [bb1]; + _2 = copy _1 == const ; + branch copy _2 -> [bb1, bb2]; } bb1: { - return; + _1 = const null; + goto -> bb2; } -} - -fn baml.csv.CsvRecord.get_at(self: baml.csv.CsvRecord, index: int) -> null | T { - // Locals: - let _0: null | T // _0 // return - let _1: baml.csv.CsvRecord // self // param - let _2: int // index // param - let _3: type - bb0: { - _3 = load_type(#0); - _0 = call const fn baml.csv._cell_by_index(copy _1, copy _2) -> [bb1]; + bb2: { + _0 = call const fn baml.csv._buffer(copy _1) -> [bb3]; } - bb1: { + bb3: { return; } } -fn baml.csv.CsvReader.headers(self: baml.csv.CsvReader) -> null | string[] { +fn baml.csv.write(path: string, rows: T[], options: null | baml.csv.WriterOptions) -> int { // Locals: - let _0: null | string[] // _0 // return - let _1: baml.csv.CsvReader // self // param - let _2: baml.csv.CsvHeaders | baml.csv.CsvNeedData - let _3: bool - let _4: baml.csv.CsvHeaders // h - let _5: null + let _0: int // _0 // return + let _1: string // path // param + let _2: T[] // rows // param + let _3: null | baml.csv.WriterOptions // options // param + let _4: bool + let _5: baml.csv.CsvWriter // w + let _6: null + let _7: type + let _8: null bb0: { - goto -> bb1; + _4 = copy _3 == const ; + branch copy _4 -> [bb1, bb2]; } bb1: { - branch const true -> [bb3, bb2]; + _3 = const null; + goto -> bb2; } bb2: { - _0 = call const fn baml.sys.panic(const "unreachable: CsvReader.headers loop ended") -> [bb7]; + _5 = call const fn baml.csv.create(copy _1, copy _3) -> [bb3]; } bb3: { - _2 = call const fn baml.csv.CsvReader._poll_headers(copy _1) -> [bb4]; + _7 = load_type(#0); + _6 = call const fn baml.csv.CsvWriter.write_rows(copy _5, copy _2) -> [bb4]; } bb4: { - _3 = is_type(copy _2, baml.csv.CsvHeaders); - branch copy _3 -> [bb6, bb5]; + _8 = call const fn baml.csv.CsvWriter.close(copy _5) -> [bb5]; } bb5: { - _5 = call const fn baml.csv.CsvReader._read_chunk(copy _1) -> [bb1]; + _0 = call const fn baml.csv.CsvWriter._bytes_written(copy _5) -> [bb6]; } bb6: { - _4 = copy _2; - _0 = copy _4.0; - goto -> bb7; - } - - bb7: { return; } } -fn baml.csv.CsvReader.root.iter.Iterable.iter(self: baml.csv.CsvReader) -> baml.iter.Iterator { +fn baml.csv.stringify(rows: T[], options: null | baml.csv.WriterOptions) -> string { // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: baml.csv.CsvReader // self // param + let _0: string // _0 // return + let _1: T[] // rows // param + let _2: null | baml.csv.WriterOptions // options // param + let _3: bool + let _4: unknown // _ + let _5: baml.csv.CsvWriter // w + let _6: null + let _7: type + let _8: bool + let _9: string + let _10: string // message + let _11: string + let _12: string bb0: { - _0 = copy _1; - goto -> bb1; + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } bb1: { - return; + _2 = const null; + goto -> bb2; } -} -fn baml.csv.CsvRows.root.iter.Iterable.iter(self: baml.csv.CsvRows) -> baml.iter.Iterator { - // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: baml.csv.CsvRows // self // param + bb2: { + _5 = call const fn baml.csv.buffer(copy _2) -> [bb3, unwind: bb5]; + } - bb0: { - _0 = copy _1; - goto -> bb1; + bb3: { + _7 = load_type(#0); + _6 = call const fn baml.csv.CsvWriter.write_rows(copy _5, copy _1) -> [bb4, unwind: bb5]; } - bb1: { + bb4: { + _0 = call const fn baml.csv.CsvWriter.text(copy _5) -> [bb8, unwind: bb5]; + } + + bb5: { + _8 = is_type(copy _4, baml.errors.Io); + branch copy _8 -> [bb7, bb6]; + } + + bb6: { + rethrow copy _4; + } + + bb7: { + _9 = copy _4.0; + _10 = copy _9; + _12 = copy _10; + _11 = const "unreachable: buffer writer raised Io: " + copy _12; + _0 = call const fn baml.sys.panic(copy _11) -> [bb8]; + } + + bb8: { return; } } -fn baml.csv.CsvRecord.length = builtin(vm) - -fn baml.csv.CsvRows.root.iter.Iterator.next(self: baml.csv.CsvRows) -> baml.iter.Done | T { +fn baml.csv.stringify_records(records: (int | bigint | float | string | bool | null)[][], options: null | baml.csv.WriterOptions) -> string { // Locals: - let _0: baml.iter.Done | T // _0 // return - let _1: baml.csv.CsvRows // self // param - let _2: baml.csv.CsvRecord | baml.iter.Done - let _3: baml.csv.CsvReader - let _4: bool - let _5: baml.iter.Done // d - let _6: baml.csv.CsvRecord // rec - let _7: baml.csv.CsvSkip | T - let _8: baml.csv.CsvRecord - let _9: baml.csv.CsvReader - let _10: type - let _11: bool - let _12: baml.csv.CsvSkip // s - let _13: null - let _14: null | ((baml.csv.CsvError) -> null throws never) - let _15: bool - let _16: (baml.csv.CsvError) -> null throws never // cb - let _17: (baml.csv.CsvError) -> null throws never - let _18: baml.csv.CsvError - let _19: T // v + let _0: string // _0 // return + let _1: (int | bigint | float | string | bool | null)[][] // records // param + let _2: null | baml.csv.WriterOptions // options // param + let _3: bool + let _4: unknown // _ + let _5: baml.csv.CsvWriter // w + let _6: baml.iter.Iterator + let _7: unknown + let _8: bool + let _9: (int | bigint | float | string | bool | null)[] + let _10: (null | bool | int | bigint | float | string)[] // rec + let _11: null + let _12: (int | bigint | float | string | bool | null)[] + let _13: bool + let _14: string + let _15: string // message + let _16: string + let _17: string bb0: { - goto -> bb1; + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } bb1: { - branch const true -> [bb3, bb2]; + _2 = const null; + goto -> bb2; } bb2: { - _0 = call const fn baml.sys.panic(const "unreachable: CsvRows.next loop ended") -> [bb12]; + _5 = call const fn baml.csv.buffer(copy _2) -> [bb3, unwind: bb8]; } bb3: { - _3 = copy _1.0; - _2 = virtual_call next as baml.iter.Iterator(copy _3) -> [bb4]; + _6 = virtual_call iter as baml.iter.Iterable(copy _1) -> [bb4, unwind: bb8]; } bb4: { - _4 = is_type(copy _2, baml.iter.Done); - branch copy _4 -> [bb11, bb5]; + _7 = virtual_call next as baml.iter.Iterator(copy _6) -> [bb5, unwind: bb8]; } bb5: { - _6 = copy _2; - _8 = copy _6; - _9 = copy _1.0; - _10 = load_type(#0); - _7 = call const fn baml.csv._try_decode(copy _8, copy _9) -> [bb6]; + _8 = is_type(copy _7, baml.iter.Done); + branch copy _8 -> [bb7, bb6]; } bb6: { - _11 = is_type(copy _7, baml.csv.CsvSkip); - branch copy _11 -> [bb8, bb7]; + _9 = copy _7; + fresh_cell(_10); + _10 = copy _9; + _12 = copy _10; + _11 = call const fn baml.csv.CsvWriter.write_record(copy _5, copy _12) -> [bb4, unwind: bb8]; } bb7: { - _19 = copy _7; - _0 = copy _19; - goto -> bb12; + _0 = call const fn baml.csv.CsvWriter.text(copy _5) -> [bb11, unwind: bb8]; } bb8: { - _12 = copy _7; - _14 = copy _1.0.2; - _15 = copy _14 == const null; - branch copy _15 -> [bb10, bb9]; + _13 = is_type(copy _4, baml.errors.Io); + branch copy _13 -> [bb10, bb9]; } bb9: { - _16 = copy _14; - _17 = copy _16; - _18 = copy _12.0; - _13 = call copy _17(copy _18) -> [bb1]; + rethrow copy _4; } bb10: { - _13 = const null; - goto -> bb1; + _14 = copy _4.0; + _15 = copy _14; + _17 = copy _15; + _16 = const "unreachable: buffer writer raised Io: " + copy _17; + _0 = call const fn baml.sys.panic(copy _16) -> [bb11]; } bb11: { - _5 = copy _2; - _0 = copy _5; - goto -> bb12; - } - - bb12: { return; } } -fn baml.csv.CsvReader.root.iter.Iterator.next(self: baml.csv.CsvReader) -> baml.csv.CsvRecord | baml.iter.Done { +fn baml.csv.to_markdown(rows: T[], max_rows: int) -> string { // Locals: - let _0: baml.csv.CsvRecord | baml.iter.Done // _0 // return - let _1: baml.csv.CsvReader // self // param - let _2: baml.csv.CsvNeedData | baml.csv.CsvRecord | baml.csv.CsvSkip | baml.iter.Done - let _3: int - let _4: baml.csv.CsvRecord // rec - let _5: baml.iter.Done // d - let _6: baml.csv.CsvSkip // s - let _7: null - let _8: null | ((baml.csv.CsvError) -> null throws never) - let _9: bool - let _10: (baml.csv.CsvError) -> null throws never // cb - let _11: (baml.csv.CsvError) -> null throws never - let _12: baml.csv.CsvError - let _13: null + let _0: string // _0 // return + let _1: T[] // rows // param + let _2: int // max_rows // param + let _3: bool + let _4: type bb0: { - goto -> bb1; + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } bb1: { - branch const true -> [bb3, bb2]; + _2 = const 100_i64; + goto -> bb2; } bb2: { - _0 = call const fn baml.sys.panic(const "unreachable: CsvReader.next loop ended") -> [bb12]; + _4 = load_type(#0); + _0 = call const fn baml.csv._to_markdown(copy _1, copy _2) -> [bb3]; } bb3: { - _2 = call const fn baml.csv.CsvReader._poll(copy _1) -> [bb4]; + return; } +} - bb4: { - _3 = type_tag(_2); - switch copy _3 [CsvRecord: bb11, Done: bb10, CsvSkip: bb7, CsvNeedData: bb6, otherwise: bb5] (exhaustive); - } +fn baml.csv.to_markdown_records(records: string[][], headers: null | string[], max_rows: int) -> string { + // Locals: + let _0: string // _0 // return + let _1: string[][] // records // param + let _2: null | string[] // headers // param + let _3: int // max_rows // param + let _4: bool + let _5: bool - bb5: { - unreachable; + bb0: { + _4 = copy _2 == const ; + branch copy _4 -> [bb1, bb2]; } - bb6: { - _13 = call const fn baml.csv.CsvReader._read_chunk(copy _1) -> [bb1]; + bb1: { + _2 = const null; + goto -> bb2; } - bb7: { - _6 = copy _2; - _8 = copy _1.2; - _9 = copy _8 == const null; - branch copy _9 -> [bb9, bb8]; + bb2: { + _5 = copy _3 == const ; + branch copy _5 -> [bb3, bb4]; } - bb8: { - _10 = copy _8; - _11 = copy _10; - _12 = copy _6.0; - _7 = call copy _11(copy _12) -> [bb1]; + bb3: { + _3 = const 100_i64; + goto -> bb4; } - bb9: { - _7 = const null; - goto -> bb1; + bb4: { + _0 = call const fn baml.csv._to_markdown_records(copy _1, copy _2, copy _3) -> [bb5]; } - bb10: { - _5 = copy _2; - _0 = copy _5; - goto -> bb12; + bb5: { + return; } +} - bb11: { - _4 = copy _2; - _0 = copy _4; - goto -> bb12; +fn baml.csv._reader = builtin(vm) + +fn baml.csv._writer = builtin(vm) + +fn baml.csv._buffer = builtin(vm) + +fn baml.csv._validate_columns = builtin(vm) + +fn baml.csv._try_decode = builtin(vm) + +fn baml.csv._decode_record = builtin(vm) + +fn baml.csv._cell_by_name = builtin(vm) + +fn baml.csv._cell_by_index = builtin(vm) + +fn baml.csv._encode_row = builtin(vm) + +fn baml.csv._encode_rows = builtin(vm) + +fn baml.csv._to_markdown = builtin(vm) + +fn baml.csv._to_markdown_records = builtin(vm) + +fn baml.csv._error(kind: baml.csv.CsvErrorKind, message: string) -> baml.csv.CsvError { + // Locals: + let _0: baml.csv.CsvError // _0 // return + let _1: baml.csv.CsvErrorKind // kind // param + let _2: string // message // param + + bb0: { + _0 = baml.csv.CsvError { copy _1, copy _2, const null, const null, const null, const null, const null, const null }; + goto -> bb1; } - bb12: { + bb1: { return; } } -fn baml.csv.open(path: string, options: null | baml.csv.ReaderOptions) -> baml.csv.CsvReader { +fn baml.env.get = builtin(io) + +fn baml.env.get_or_panic(key: string) -> string { // Locals: - let _0: baml.csv.CsvReader // _0 // return - let _1: string // path // param - let _2: null | baml.csv.ReaderOptions // options // param + let _0: string // _0 // return + let _1: string // key // param + let _2: string | null let _3: bool - let _4: baml.fs.File // f - let _5: unknown // _ - let _6: bool - let _7: string - let _8: string // message - let _9: baml.errors.Io - let _10: string - let _11: baml.fs.File + let _4: string bb0: { - _3 = copy _2 == const ; - branch copy _3 -> [bb1, bb2]; + _2 = sys_op const fn baml.env.get(copy _1) -> bb1; } bb1: { - _2 = const null; - goto -> bb2; + _0 = copy _2; + _3 = copy _2 == const null; + branch copy _3 -> [bb2, bb3]; } bb2: { - _4 = sys_op const fn baml.fs.open(copy _1, const "r") -> bb3 unwind bb5; + _4 = const "env var not found: " + copy _1; + _0 = call const fn baml.sys.panic(copy _4) -> [bb3]; } bb3: { - _11 = copy _4; - _0 = call const fn baml.csv._reader(copy _11, copy _2, const true) -> [bb4]; - } - - bb4: { return; } - - bb5: { - _6 = is_type(copy _5, baml.errors.InvalidArgument); - branch copy _6 -> [bb7, bb6]; - } - - bb6: { - rethrow copy _5; - } - - bb7: { - _7 = copy _5.0; - _8 = copy _7; - _10 = copy _8; - _9 = baml.errors.Io { copy _10 }; - throw copy _9; - } } -fn baml.csv.parse(source: string | uint8array, options: null | baml.csv.ReaderOptions) -> string[][] { +fn baml.env.get_or_panic_lenient(key: string, lenient: bool) -> string { // Locals: - let _0: string[][] // _0 // return - let _1: string | uint8array // source // param - let _2: null | baml.csv.ReaderOptions // options // param - let _3: bool - let _4: unknown // _ - let _5: baml.csv.CsvReader // r - let _6: string[][] // out - let _7: baml.csv.CsvRecord | baml.iter.Done - let _8: bool - let _9: baml.csv.CsvRecord // rec - let _10: int - let _11: string[] - let _12: bool - let _13: string - let _14: string // message - let _15: string - let _16: string + let _0: string // _0 // return + let _1: string // key // param + let _2: bool // lenient // param + let _3: string | null + let _4: bool bb0: { - _3 = copy _2 == const ; - branch copy _3 -> [bb1, bb2]; + branch copy _2 -> [bb2, bb1]; } bb1: { - _2 = const null; - goto -> bb2; + _0 = call const fn baml.env.get_or_panic(copy _1) -> [bb5]; } bb2: { - _5 = call const fn baml.csv.reader(copy _1, copy _2) -> [bb3, unwind: bb10]; + _3 = sys_op const fn baml.env.get(copy _1) -> bb3; } bb3: { - _6 = []: string[][]; - goto -> bb4; + _0 = copy _3; + _4 = copy _3 == const null; + branch copy _4 -> [bb4, bb5]; } bb4: { - branch const true -> [bb5, bb9]; + _0 = const ""; + goto -> bb5; } bb5: { - _7 = virtual_call next as baml.iter.Iterator(copy _5) -> [bb6, unwind: bb10]; + return; } +} - bb6: { - _8 = is_type(copy _7, baml.iter.Done); - branch copy _8 -> [bb9, bb7]; +fn baml.errors.ErrorContext.root_cause(self: baml.errors.ErrorContext) -> baml.errors.ErrorContext { + // Locals: + let _0: baml.errors.ErrorContext // _0 // return + let _1: baml.errors.ErrorContext // self // param + let _2: null | baml.errors.ErrorContext + let _3: bool + let _4: baml.errors.ErrorContext // c + + bb0: { + _2 = copy _1.2; + _3 = copy _2 == const null; + branch copy _3 -> [bb2, bb1]; } - bb7: { - _9 = copy _7; - _11 = call const fn baml.csv.CsvRecord.fields(copy _9) -> [bb8, unwind: bb10]; + bb1: { + _4 = copy _2; + _0 = call const fn baml.errors.ErrorContext.root_cause(copy _4) -> [bb3]; } - bb8: { - _10 = call const fn baml.Array.push(copy _6, copy _11) -> [bb4, unwind: bb10]; + bb2: { + _0 = copy _1; + goto -> bb3; } - bb9: { - _0 = copy _6; - goto -> bb13; + bb3: { + return; } +} - bb10: { - _12 = is_type(copy _4, baml.errors.Io); - branch copy _12 -> [bb12, bb11]; +fn baml.errors.ErrorContext.baml.ToString.to_string(self: baml.errors.ErrorContext) -> string { + // Locals: + let _0: string // _0 // return + let _1: baml.errors.ErrorContext // self // param + + bb0: { + _0 = call const fn baml.errors.ErrorContext._to_string_impl(copy _1) -> [bb1]; } - bb11: { - rethrow copy _4; + bb1: { + return; } +} - bb12: { - _13 = copy _4.0; - _14 = copy _13; - _16 = copy _14; - _15 = const "unreachable: in-memory CSV source raised Io: " + copy _16; - _0 = call const fn baml.sys.panic(copy _15) -> [bb13]; +fn baml.errors.ErrorContext._to_string_impl = builtin(vm) + +fn baml.errors.StackTrace.baml.ToString.to_string(self: baml.errors.StackTrace) -> string { + // Locals: + let _0: string // _0 // return + let _1: baml.errors.StackTrace // self // param + + bb0: { + _0 = call const fn baml.errors.StackTrace._to_string_impl(copy _1) -> [bb1]; } - bb13: { + bb1: { return; } } -fn baml.csv.CsvReader.position = builtin(vm) +fn baml.errors.StackTrace._to_string_impl = builtin(vm) -fn baml.csv.CsvRecord.position = builtin(vm) +fn baml.fs.File.text = builtin(io) -fn baml.csv.read(path: string, options: null | baml.csv.ReaderOptions) -> T[] { +fn baml.fs.File.bytes = builtin(io) + +fn baml.fs.File.read = builtin(io) + +fn baml.fs.File.read_bytes = builtin(io) + +fn baml.fs.File.close = builtin(io) + +fn baml.fs.File.seek_from = builtin(io) + +fn baml.fs.File.write = builtin(io) + +fn baml.fs.File.write_bytes = builtin(io) + +fn baml.fs.open = builtin(io) + +fn baml.fs.exists = builtin(io) + +fn baml.fs.remove = builtin(io) + +fn baml.fs.size = builtin(io) + +fn baml.fs.read = builtin(io) + +fn baml.fs.write = builtin(io) + +fn baml.fs.write_bytes = builtin(io) + +fn baml.fs.read_dir = builtin(io) + +fn baml.fs.mkdir = builtin(io) + +fn baml.fs.remove_dir = builtin(io) + +fn baml.fs.remove_dir_all = builtin(io) + +fn baml.future.Future.cancel = builtin(vm) + +fn baml.future.Future.is_settled = builtin(vm) + +fn baml.future.Future.is_cancelled = builtin(vm) + +fn baml.future.Future.is_result = builtin(vm) + +fn baml.future.Future.is_error = builtin(vm) + +fn baml.future.Future.state = builtin(vm) + +fn baml.future.all_complete(futures: future[]) -> future { // Locals: - let _0: T[] // _0 // return - let _1: string // path // param - let _2: null | baml.csv.ReaderOptions // options // param - let _3: bool - let _4: baml.csv.CsvReader // r - let _5: T[] // result - let _6: baml.iter.Iterator - let _7: type - let _8: null + let _0: future // _0 // return + let _1: future[] // futures // param [captured] + let _2: null + let _3: null bb0: { - _3 = copy _2 == const ; - branch copy _3 -> [bb1, bb2]; + _2 = make_closure lambda[0]<2 type_args>(copy _1); + _3 = spawn copy _2 name=const null -> bb1; } bb1: { - _2 = const null; + _0 = copy _3; goto -> bb2; } bb2: { - _4 = call const fn baml.csv.open(copy _1, copy _2) -> [bb3]; + return; } +} - bb3: { - _7 = load_type(#0); - _6 = call const fn baml.csv.CsvReader.rows(copy _4) -> [bb4]; - } +// lambda[0] +fn .() -> null { + // Locals: + let _0: null // _0 // return + let _1: (future) -> T throws E + let _2: type + let _3: type + let _4: type - bb4: { - _5 = virtual_call collect as baml.iter.Iterator(copy _6) -> [bb5]; + bb0: { + _1 = make_closure lambda[0]<2 type_args>(); + _2 = load_type(#0); + _3 = load_type(#1); + _4 = load_type(future<#0, #1>); + _0 = call const fn baml.Array.map(copy capture[0], copy _1) -> [bb1]; } - bb5: { - _8 = call const fn baml.csv.CsvReader.close(copy _4) -> [bb6]; + bb1: { + return; } +} - bb6: { - _0 = copy _5; - goto -> bb7; +// lambda[0] +fn ., 1)>(f: null) -> null { + // Locals: + let _0: null // _0 // return + let _1: null // f // param + + bb0: { + _0 = await _1 -> [bb1]; } - bb7: { + bb1: { return; } } -fn baml.csv.reader(source: string | uint8array | baml.fs.File, options: null | baml.csv.ReaderOptions) -> baml.csv.CsvReader { +fn baml.future.all(futures: future[]) -> future { // Locals: - let _0: baml.csv.CsvReader // _0 // return - let _1: string | uint8array | baml.fs.File // source // param - let _2: null | baml.csv.ReaderOptions // options // param - let _3: bool + let _0: future // _0 // return + let _1: future[] // futures // param [captured] + let _2: null + let _3: null bb0: { - _3 = copy _2 == const ; - branch copy _3 -> [bb1, bb2]; + _2 = make_closure lambda[0]<2 type_args>(copy _1); + _3 = spawn copy _2 name=const null -> bb1; } bb1: { - _2 = const null; + _0 = copy _3; goto -> bb2; } bb2: { - _0 = call const fn baml.csv._reader(copy _1, copy _2, const false) -> [bb3]; - } - - bb3: { return; } } -fn baml.csv.CsvWriter.records_written = builtin(vm) - -fn baml.csv.CsvReader.rows(self: baml.csv.CsvReader) -> baml.iter.Iterator { +// lambda[0] +fn .() -> null { // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: baml.csv.CsvReader // self // param - let _2: null | string[] - let _3: null + let _0: null // _0 // return + let _1: (future) -> T throws E + let _2: type + let _3: type let _4: type bb0: { - _2 = call const fn baml.csv.CsvReader.headers(copy _1) -> [bb1]; + _1 = make_closure lambda[0]<2 type_args>(copy capture[0]); + _2 = load_type(#0); + _3 = load_type(#1); + _4 = load_type(future<#0, #1>); + _0 = call const fn baml.Array.map(copy capture[0], copy _1) -> [bb1]; } bb1: { - _4 = load_type(#0); - _3 = call const fn baml.csv._validate_columns(copy _1) -> [bb2]; - } - - bb2: { - _0 = baml.csv.CsvRows<#0> { copy _1 }; - goto -> bb3; - } - - bb3: { return; } } -fn baml.csv.CsvReader.skipped = builtin(vm) - -fn baml.csv.CsvReader.skipped_count = builtin(vm) - -fn baml.csv.stringify(rows: T[], options: null | baml.csv.WriterOptions) -> string { +// lambda[0] +fn ., 1)>(f: null) -> null { // Locals: - let _0: string // _0 // return - let _1: T[] // rows // param - let _2: null | baml.csv.WriterOptions // options // param - let _3: bool - let _4: unknown // _ - let _5: baml.csv.CsvWriter // w - let _6: null + let _0: null // _0 // return + let _1: null // f // param + let _2: unknown // e + let _3: E // e + let _4: bool[] + let _5: (future) -> bool throws E + let _6: type let _7: type - let _8: bool - let _9: string - let _10: string // message - let _11: string - let _12: string + let _8: type + let _9: int // j + let _10: bool + let _11: int + let _12: int + let _13: future // g + let _14: future[] + let _15: int + let _16: bool + let _17: null | T + let _18: unknown // drained + let _19: null + let _20: int bb0: { - _3 = copy _2 == const ; - branch copy _3 -> [bb1, bb2]; + _0 = await _1 -> [bb1, unwind: bb2]; } bb1: { - _2 = const null; - goto -> bb2; + return; } bb2: { - _5 = call const fn baml.csv.buffer(copy _2) -> [bb3, unwind: bb5]; + throw_if_panic copy _2 -> bb3; } bb3: { - _7 = load_type(#0); - _6 = call const fn baml.csv.CsvWriter.write_rows(copy _5, copy _1) -> [bb4, unwind: bb5]; - } - - bb4: { - _0 = call const fn baml.csv.CsvWriter.text(copy _5) -> [bb8, unwind: bb5]; - } - - bb5: { - _8 = is_type(copy _4, baml.errors.Io); - branch copy _8 -> [bb7, bb6]; - } - - bb6: { - rethrow copy _4; - } - - bb7: { - _9 = copy _4.0; - _10 = copy _9; - _12 = copy _10; - _11 = const "unreachable: buffer writer raised Io: " + copy _12; - _0 = call const fn baml.sys.panic(copy _11) -> [bb8]; - } - - bb8: { - return; - } -} - -fn baml.csv.stringify_records(records: (int | bigint | float | string | bool | null)[][], options: null | baml.csv.WriterOptions) -> string { - // Locals: - let _0: string // _0 // return - let _1: (int | bigint | float | string | bool | null)[][] // records // param - let _2: null | baml.csv.WriterOptions // options // param - let _3: bool - let _4: unknown // _ - let _5: baml.csv.CsvWriter // w - let _6: baml.iter.Iterator - let _7: unknown - let _8: bool - let _9: (int | bigint | float | string | bool | null)[] - let _10: (null | bool | int | bigint | float | string)[] // rec - let _11: null - let _12: (int | bigint | float | string | bool | null)[] - let _13: bool - let _14: string - let _15: string // message - let _16: string - let _17: string - - bb0: { - _3 = copy _2 == const ; - branch copy _3 -> [bb1, bb2]; - } - - bb1: { - _2 = const null; - goto -> bb2; - } - - bb2: { - _5 = call const fn baml.csv.buffer(copy _2) -> [bb3, unwind: bb8]; - } - - bb3: { - _6 = virtual_call iter as baml.iter.Iterable(copy _1) -> [bb4, unwind: bb8]; + _3 = copy _2; + _5 = make_closure lambda[0]<2 type_args>(); + _6 = load_type(bool); + _7 = load_type(#1); + _8 = load_type(future<#0, #1>); + _4 = call const fn baml.Array.map(copy capture[0], copy _5) -> [bb4]; } bb4: { - _7 = virtual_call next as baml.iter.Iterator(copy _6) -> [bb5, unwind: bb8]; + _9 = const 0_i64; + goto -> bb8; } bb5: { - _8 = is_type(copy _7, baml.iter.Done); - branch copy _8 -> [bb7, bb6]; + throw_if_panic copy _18 -> bb6; } bb6: { - _9 = copy _7; - fresh_cell(_10); - _10 = copy _9; - _12 = copy _10; - _11 = call const fn baml.csv.CsvWriter.write_record(copy _5, copy _12) -> [bb4, unwind: bb8]; + _17 = const null; + goto -> bb7; } bb7: { - _0 = call const fn baml.csv.CsvWriter.text(copy _5) -> [bb11, unwind: bb8]; + _20 = copy _9; + _9 = copy _20 + const 1_i64; + goto -> bb8; } bb8: { - _13 = is_type(copy _4, baml.errors.Io); - branch copy _13 -> [bb10, bb9]; + _11 = copy _9; + _12 = len(capture[0]); + goto -> bb9; } bb9: { - rethrow copy _4; + _10 = copy _11 < copy _12; + branch copy _10 -> [bb11, bb10]; } bb10: { - _14 = copy _4.0; - _15 = copy _14; - _17 = copy _15; - _16 = const "unreachable: buffer writer raised Io: " + copy _17; - _0 = call const fn baml.sys.panic(copy _16) -> [bb11]; + throw copy _3; } bb11: { - return; + _14 = copy capture[0]; + _15 = copy _9; + _13 = copy _14[_15]; + _16 = call const fn baml.future.Future.is_error(copy _13) -> [bb12]; } -} -fn baml.csv.CsvWriter.text = builtin(vm) + bb12: { + branch copy _16 -> [bb13, bb7]; + } -fn baml.csv.CsvRecord.to_map = builtin(vm) + bb13: { + _19 = copy _13; + _17 = await _19 -> [bb7, unwind: bb5]; + } +} -fn baml.csv.to_markdown(rows: T[], max_rows: int) -> string { +// lambda[0] +fn ., 1)>, 2)>(g: null) -> null { // Locals: - let _0: string // _0 // return - let _1: T[] // rows // param - let _2: int // max_rows // param - let _3: bool - let _4: type + let _0: null // _0 // return + let _1: null // g // param bb0: { - _3 = copy _2 == const ; - branch copy _3 -> [bb1, bb2]; + _0 = call const fn baml.future.Future.cancel(copy _1) -> [bb1]; } bb1: { - _2 = const 100_i64; - goto -> bb2; - } - - bb2: { - _4 = load_type(#0); - _0 = call const fn baml.csv._to_markdown(copy _1, copy _2) -> [bb3]; - } - - bb3: { return; } } -fn baml.csv.to_markdown_records(records: string[][], headers: null | string[], max_rows: int) -> string { +fn baml.future.__await_any = builtin(await_any) + +fn baml.future.race(futures: future[]) -> future { // Locals: - let _0: string // _0 // return - let _1: string[][] // records // param - let _2: null | string[] // headers // param - let _3: int // max_rows // param - let _4: bool - let _5: bool + let _0: future // _0 // return + let _1: future[] // futures // param [captured] + let _2: null + let _3: null bb0: { - _4 = copy _2 == const ; - branch copy _4 -> [bb1, bb2]; + _2 = make_closure lambda[0]<2 type_args>(copy _1); + _3 = spawn copy _2 name=const null -> bb1; } bb1: { - _2 = const null; + _0 = copy _3; goto -> bb2; } bb2: { - _5 = copy _3 == const ; - branch copy _5 -> [bb3, bb4]; - } - - bb3: { - _3 = const 100_i64; - goto -> bb4; - } - - bb4: { - _0 = call const fn baml.csv._to_markdown_records(copy _1, copy _2, copy _3) -> [bb5]; - } - - bb5: { return; } } -fn baml.csv.write(path: string, rows: T[], options: null | baml.csv.WriterOptions) -> int { +// lambda[0] +fn .() -> null { // Locals: - let _0: int // _0 // return - let _1: string // path // param - let _2: T[] // rows // param - let _3: null | baml.csv.WriterOptions // options // param - let _4: bool - let _5: baml.csv.CsvWriter // w - let _6: null + let _0: null // _0 // return + let _1: int // i + let _2: future[] + let _3: bool[] + let _4: (future) -> bool throws E + let _5: type + let _6: type let _7: type let _8: null + let _9: future[] + let _10: int bb0: { - _4 = copy _3 == const ; - branch copy _4 -> [bb1, bb2]; + _2 = copy capture[0]; + _1 = await_any copy _2 -> [bb1]; } bb1: { - _3 = const null; - goto -> bb2; + _4 = make_closure lambda[0]<2 type_args>(); + _5 = load_type(bool); + _6 = load_type(#1); + _7 = load_type(future<#0, #1>); + _3 = call const fn baml.Array.map(copy capture[0], copy _4) -> [bb2]; } bb2: { - _5 = call const fn baml.csv.create(copy _1, copy _3) -> [bb3]; + _9 = copy capture[0]; + _10 = copy _1; + _8 = copy _9[_10]; + _0 = await _8 -> [bb3]; } bb3: { - _7 = load_type(#0); - _6 = call const fn baml.csv.CsvWriter.write_rows(copy _5, copy _2) -> [bb4]; - } - - bb4: { - _8 = call const fn baml.csv.CsvWriter.close(copy _5) -> [bb5]; - } - - bb5: { - _0 = call const fn baml.csv.CsvWriter._bytes_written(copy _5) -> [bb6]; - } - - bb6: { return; } } -fn baml.csv.CsvWriter.write_header(self: baml.csv.CsvWriter, names: string[]) -> null { +// lambda[0] +fn ., 1)>(f: null) -> null { // Locals: let _0: null // _0 // return - let _1: baml.csv.CsvWriter // self // param - let _2: string[] // names // param - let _3: string + let _1: null // f // param bb0: { - _3 = call const fn baml.csv.CsvWriter._encode_header(copy _1, copy _2) -> [bb1]; + _0 = call const fn baml.future.Future.cancel(copy _1) -> [bb1]; } bb1: { - _0 = call const fn baml.csv.CsvWriter._emit(copy _1, copy _3) -> [bb2]; - } - - bb2: { return; } } -fn baml.csv.CsvWriter.write_record(self: baml.csv.CsvWriter, record: (int | bigint | float | string | bool | null)[]) -> null { +fn baml.future.any(futures: future[]) -> future> { // Locals: - let _0: null // _0 // return - let _1: baml.csv.CsvWriter // self // param - let _2: (int | bigint | float | string | bool | null)[] // record // param - let _3: string + let _0: future> // _0 // return + let _1: future[] // futures // param [captured] + let _2: null + let _3: null bb0: { - _3 = call const fn baml.csv.CsvWriter._encode_record(copy _1, copy _2) -> [bb1]; + _2 = make_closure lambda[0]<2 type_args>(copy _1); + _3 = spawn copy _2 name=const null -> bb1; } bb1: { - _0 = call const fn baml.csv.CsvWriter._emit(copy _1, copy _3) -> [bb2]; + _0 = copy _3; + goto -> bb2; } bb2: { @@ -2612,196 +3176,265 @@ fn baml.csv.CsvWriter.write_record(self: baml.csv.CsvWriter, record: (int | bigi } } -fn baml.csv.CsvWriter.write_row(self: baml.csv.CsvWriter, row: T) -> null { +// lambda[0] +fn .() -> null { // Locals: let _0: null // _0 // return - let _1: baml.csv.CsvWriter // self // param - let _2: T // row // param - let _3: string - let _4: type + let _1: T[] // winners + let _2: future[] // remaining + let _3: bool + let _4: int + let _5: int // i + let _6: future[] + let _7: future // f + let _8: future[] + let _9: int + let _10: bool + let _11: int + let _12: T + let _13: unknown // e + let _14: null + let _15: Err // e + let _16: baml.future.AllFailed // failure + let _17: Err[] + let _18: Err + let _19: bool + let _20: null | T + let _21: unknown // e + let _22: null + let _23: future[] + let _24: int + let _25: type + let _26: future[] + let _27: int + let _28: int + let _29: int + let _30: type + let _31: type + let _32: bool + let _33: int + let _34: Err[] // errors + let _35: int // j + let _36: bool + let _37: int + let _38: int + let _39: future // g + let _40: future[] + let _41: int + let _42: bool + let _43: null | T + let _44: unknown // e + let _45: null + let _46: Err // e + let _47: int + let _48: Err + let _49: int + let _50: baml.future.AllFailed // failure + let _51: Err[] + let _52: bool[] + let _53: (future) -> bool throws E + let _54: type + let _55: type + let _56: type + let _57: T[] + let _58: 0 bb0: { - _4 = load_type(#0); - _3 = call const fn baml.csv._encode_row(copy _1, copy _2) -> [bb1]; + _1 = []: #0[]; + _2 = copy capture[0]; + goto -> bb7; } bb1: { - _0 = call const fn baml.csv.CsvWriter._emit(copy _1, copy _3) -> [bb2]; + throw_if_panic copy _21 -> bb2; } bb2: { - return; + _20 = const null; + goto -> bb3; } -} - -fn baml.csv.CsvWriter.write_rows(self: baml.csv.CsvWriter, rows: T[]) -> null { - // Locals: - let _0: null // _0 // return - let _1: baml.csv.CsvWriter // self // param - let _2: T[] // rows // param - let _3: string - let _4: type - bb0: { - _4 = load_type(#0); - _3 = call const fn baml.csv._encode_rows(copy _1, copy _2) -> [bb1]; + bb3: { + _24 = copy _5; + _25 = load_type(future<#0, #1>); + _23 = call const fn baml.Array.slice(copy _2, const 0_i64, copy _24) -> [bb4]; } - bb1: { - _0 = call const fn baml.csv.CsvWriter._emit(copy _1, copy _3) -> [bb2]; + bb4: { + _28 = copy _5; + _27 = copy _28 + const 1_i64; + _29 = len(_2); + goto -> bb5; } - bb2: { - return; + bb5: { + _30 = load_type(future<#0, #1>); + _26 = call const fn baml.Array.slice(copy _2, copy _27, copy _29) -> [bb6]; } -} -fn baml.csv.writer(file: baml.fs.File, options: null | baml.csv.WriterOptions) -> baml.csv.CsvWriter { - // Locals: - let _0: baml.csv.CsvWriter // _0 // return - let _1: baml.fs.File // file // param - let _2: null | baml.csv.WriterOptions // options // param - let _3: bool + bb6: { + _31 = load_type(future<#0, #1>); + _2 = call const fn baml.Array.concat(copy _23, copy _26) -> [bb7]; + } - bb0: { - _3 = copy _2 == const ; - branch copy _3 -> [bb1, bb2]; + bb7: { + _4 = len(_2); + goto -> bb8; } - bb1: { - _2 = const null; - goto -> bb2; + bb8: { + _3 = copy _4 > const 0_i64; + branch copy _3 -> [bb9, bb19]; } - bb2: { - _0 = call const fn baml.csv._writer(copy _1, copy _2, const false) -> [bb3]; + bb9: { + _6 = copy _2; + _5 = await_any copy _6 -> [bb10]; } - bb3: { - return; + bb10: { + _8 = copy _2; + _9 = copy _5; + _7 = copy _8[_9]; + _10 = call const fn baml.future.Future.is_result(copy _7) -> [bb11]; } -} -fn baml.env.get = builtin(io) + bb11: { + branch copy _10 -> [bb15, bb12]; + } -fn baml.env.get_or_panic(key: string) -> string { - // Locals: - let _0: string // _0 // return - let _1: string // key // param - let _2: string | null - let _3: bool - let _4: string + bb12: { + _19 = call const fn baml.future.Future.is_error(copy _7) -> [bb13]; + } - bb0: { - _2 = sys_op const fn baml.env.get(copy _1) -> bb1; + bb13: { + branch copy _19 -> [bb14, bb3]; } - bb1: { - _0 = copy _2; - _3 = copy _2 == const null; - branch copy _3 -> [bb2, bb3]; + bb14: { + _22 = copy _7; + _20 = await _22 -> [bb3, unwind: bb1]; } - bb2: { - _4 = const "env var not found: " + copy _1; - _0 = call const fn baml.sys.panic(copy _4) -> [bb3]; + bb15: { + _14 = copy _7; + _12 = await _14 -> [bb18, unwind: bb16]; } - bb3: { - return; + bb16: { + throw_if_panic copy _13 -> bb17; } -} -fn baml.env.get_or_panic_lenient(key: string, lenient: bool) -> string { - // Locals: - let _0: string // _0 // return - let _1: string // key // param - let _2: bool // lenient // param - let _3: string | null - let _4: bool + bb17: { + _15 = copy _13; + _18 = copy _15; + _17 = [copy _18]: #1[]; + _16 = baml.future.AllFailed<#1> { copy _17 }; + throw copy _16; + } - bb0: { - branch copy _2 -> [bb2, bb1]; + bb18: { + _11 = call const fn baml.Array.push(copy _1, copy _12) -> [bb19]; } - bb1: { - _0 = call const fn baml.env.get_or_panic(copy _1) -> [bb5]; + bb19: { + _33 = len(_1); + goto -> bb20; } - bb2: { - _3 = sys_op const fn baml.env.get(copy _1) -> bb3; + bb20: { + _32 = copy _33 == const 0_i64; + branch copy _32 -> [bb24, bb21]; } - bb3: { - _0 = copy _3; - _4 = copy _3 == const null; - branch copy _4 -> [bb4, bb5]; + bb21: { + _53 = make_closure lambda[0]<2 type_args>(); + _54 = load_type(bool); + _55 = load_type(never); + _56 = load_type(future<#0, #1>); + _52 = call const fn baml.Array.map(copy capture[0], copy _53) -> [bb22]; } - bb4: { - _0 = const ""; - goto -> bb5; + bb22: { + _57 = copy _1; + _58 = const 0_i64; + _0 = copy _57[_58]; + goto -> bb23; } - bb5: { + bb23: { return; } -} - -fn baml.errors.ErrorContext._to_string_impl = builtin(vm) - -fn baml.errors.ErrorContext.root_cause(self: baml.errors.ErrorContext) -> baml.errors.ErrorContext { - // Locals: - let _0: baml.errors.ErrorContext // _0 // return - let _1: baml.errors.ErrorContext // self // param - let _2: null | baml.errors.ErrorContext - let _3: bool - let _4: baml.errors.ErrorContext // c - bb0: { - _2 = copy _1.2; - _3 = copy _2 == const null; - branch copy _3 -> [bb2, bb1]; + bb24: { + _34 = []: #1[]; + _35 = const 0_i64; + goto -> bb29; } - bb1: { - _4 = copy _2; - _0 = call const fn baml.errors.ErrorContext.root_cause(copy _4) -> [bb3]; + bb25: { + throw_if_panic copy _44 -> bb26; } - bb2: { - _0 = copy _1; - goto -> bb3; + bb26: { + _46 = copy _44; + _48 = copy _46; + _47 = call const fn baml.Array.push(copy _34, copy _48) -> [bb27]; } - bb3: { - return; + bb27: { + _43 = const null; + goto -> bb28; } -} -fn baml.errors.ErrorContext.baml.ToString.to_string(self: baml.errors.ErrorContext) -> string { - // Locals: - let _0: string // _0 // return - let _1: baml.errors.ErrorContext // self // param + bb28: { + _49 = copy _35; + _35 = copy _49 + const 1_i64; + goto -> bb29; + } - bb0: { - _0 = call const fn baml.errors.ErrorContext._to_string_impl(copy _1) -> [bb1]; + bb29: { + _37 = copy _35; + _38 = len(capture[0]); + goto -> bb30; } - bb1: { - return; + bb30: { + _36 = copy _37 < copy _38; + branch copy _36 -> [bb32, bb31]; } -} -fn baml.errors.StackTrace._to_string_impl = builtin(vm) + bb31: { + _51 = copy _34; + _50 = baml.future.AllFailed<#1> { copy _51 }; + throw copy _50; + } -fn baml.errors.StackTrace.baml.ToString.to_string(self: baml.errors.StackTrace) -> string { + bb32: { + _40 = copy capture[0]; + _41 = copy _35; + _39 = copy _40[_41]; + _42 = call const fn baml.future.Future.is_error(copy _39) -> [bb33]; + } + + bb33: { + branch copy _42 -> [bb34, bb28]; + } + + bb34: { + _45 = copy _39; + _43 = await _45 -> [bb28, unwind: bb25]; + } +} + +// lambda[0] +fn ., 1)>(g: null) -> null { // Locals: - let _0: string // _0 // return - let _1: baml.errors.StackTrace // self // param + let _0: null // _0 // return + let _1: null // g // param bb0: { - _0 = call const fn baml.errors.StackTrace._to_string_impl(copy _1) -> [bb1]; + _0 = call const fn baml.future.Future.cancel(copy _1) -> [bb1]; } bb1: { @@ -2809,240 +3442,331 @@ fn baml.errors.StackTrace.baml.ToString.to_string(self: baml.errors.StackTrace) } } -fn baml.fs.File.bytes = builtin(io) +fn baml.glob.Glob.scan = builtin(io) -fn baml.fs.File.close = builtin(io) +fn baml.glob.Glob.matches = builtin(io) -fn baml.fs.exists = builtin(io) +fn baml.glob.new = builtin(io) -fn baml.fs.mkdir = builtin(io) +fn baml.host.call_host_value = builtin(io) -fn baml.fs.open = builtin(io) +fn baml.http.Response.text = builtin(io) -fn baml.fs.read = builtin(io) +fn baml.http.Response.bytes = builtin(io) -fn baml.fs.File.read = builtin(io) +fn baml.http.Response.ok(self: baml.http.Response) -> bool { + // Locals: + let _0: bool // _0 // return + let _1: baml.http.Response // self // param + let _2: bool + let _3: int + let _4: int -fn baml.fs.File.read_bytes = builtin(io) + bb0: { + _3 = copy _1.0; + _2 = copy _3 >= const 200_i64; + _0 = short_circuit(&&) copy _2 -> [eval: bb1, join: bb2]; + } -fn baml.fs.read_dir = builtin(io) + bb1: { + _4 = copy _1.0; + _0 = copy _4 < const 300_i64; + goto -> bb2; + } -fn baml.fs.remove = builtin(io) + bb2: { + return; + } +} -fn baml.fs.remove_dir = builtin(io) +fn baml.http.Response.new = builtin(io) -fn baml.fs.remove_dir_all = builtin(io) +fn baml.http.Response.new_streaming = builtin(io) -fn baml.fs.File.seek_from = builtin(io) +fn baml.http.Response.write = builtin(io) -fn baml.fs.size = builtin(io) +fn baml.http.Response.end = builtin(io) -fn baml.fs.File.text = builtin(io) +fn baml.http.SseStream.next = builtin(io) -fn baml.fs.File.write = builtin(io) +fn baml.http.SseStream.close = builtin(io) -fn baml.fs.write = builtin(io) +fn baml.http._timeout_nanos(timeout: null | baml.time.Duration) -> bigint { + // Locals: + let _0: bigint // _0 // return + let _1: null | baml.time.Duration // timeout // param + let _2: bool + let _3: baml.time.Duration // t -fn baml.fs.File.write_bytes = builtin(io) + bb0: { + _2 = copy _1 == const null; + branch copy _2 -> [bb2, bb1]; + } -fn baml.fs.write_bytes = builtin(io) + bb1: { + _3 = copy _1; + _0 = call const fn baml.time.Duration.to_nanoseconds(copy _3) -> [bb3]; + } -fn baml.future.__await_any = builtin(await_any) + bb2: { + _0 = const 0n; + goto -> bb3; + } -fn baml.future.all(futures: future[]) -> future { + bb3: { + return; + } +} + +fn baml.http.fetch(url: string, timeout: null | baml.time.Duration) -> baml.http.Response { // Locals: - let _0: future // _0 // return - let _1: future[] // futures // param [captured] - let _2: null - let _3: null + let _0: baml.http.Response // _0 // return + let _1: string // url // param + let _2: null | baml.time.Duration // timeout // param + let _3: bool + let _4: bigint bb0: { - _2 = make_closure lambda[0]<2 type_args>(copy _1); - _3 = spawn copy _2 name=const null -> bb1; + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } bb1: { - _0 = copy _3; + _2 = const null; goto -> bb2; } bb2: { + _4 = call const fn baml.http._timeout_nanos(copy _2) -> [bb3]; + } + + bb3: { + _0 = sys_op const fn baml.http._fetch(copy _1, copy _4) -> bb4; + } + + bb4: { return; } } -// lambda[0] -fn .() -> null { +fn baml.http._fetch = builtin(io) + +fn baml.http.send(request: baml.http.Request, timeout: null | baml.time.Duration) -> baml.http.Response { // Locals: - let _0: null // _0 // return - let _1: (future) -> T throws E - let _2: type - let _3: type - let _4: type + let _0: baml.http.Response // _0 // return + let _1: baml.http.Request // request // param + let _2: null | baml.time.Duration // timeout // param + let _3: bool + let _4: bigint bb0: { - _1 = make_closure lambda[0]<2 type_args>(copy capture[0]); - _2 = load_type(#0); - _3 = load_type(#1); - _4 = load_type(future<#0, #1>); - _0 = call const fn baml.Array.map(copy capture[0], copy _1) -> [bb1]; + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } bb1: { + _2 = const null; + goto -> bb2; + } + + bb2: { + _4 = call const fn baml.http._timeout_nanos(copy _2) -> [bb3]; + } + + bb3: { + _0 = sys_op const fn baml.http._send(copy _1, copy _4) -> bb4; + } + + bb4: { return; } } -// lambda[0] -fn ., 1)>(f: null) -> null { +fn baml.http._send = builtin(io) + +fn baml.http.fetch_sse = builtin(io) + +fn baml.http.Server.bind = builtin(io) + +fn baml.http.Server.serve(self: baml.http.Server, handler: (baml.http.Request) -> baml.http.Response throws never, tls_config: null | baml.http.TlsConfig, allow_http1: bool, allow_http2: bool, max_body_size: int, max_connections: int, header_read_timeout: baml.time.Duration) -> never { // Locals: - let _0: null // _0 // return - let _1: null // f // param - let _2: unknown // e - let _3: E // e - let _4: bool[] - let _5: (future) -> bool throws E - let _6: type - let _7: type - let _8: type - let _9: int // j + let _0: never // _0 // return + let _1: baml.http.Server // self // param + let _2: (baml.http.Request) -> baml.http.Response throws never // handler // param + let _3: null | baml.http.TlsConfig // tls_config // param + let _4: bool // allow_http1 // param + let _5: bool // allow_http2 // param + let _6: int // max_body_size // param + let _7: int // max_connections // param + let _8: baml.time.Duration // header_read_timeout // param + let _9: bool let _10: bool - let _11: int - let _12: int - let _13: future // g - let _14: future[] - let _15: int - let _16: bool - let _17: null | T - let _18: unknown // drained - let _19: null - let _20: int + let _11: bool + let _12: bool + let _13: bool + let _14: bool + let _15: bigint bb0: { - _0 = await _1 -> [bb1, unwind: bb2]; + _9 = copy _3 == const ; + branch copy _9 -> [bb1, bb2]; } bb1: { - return; + _3 = const null; + goto -> bb2; } bb2: { - throw_if_panic copy _2 -> bb3; + _10 = copy _4 == const ; + branch copy _10 -> [bb3, bb4]; } bb3: { - _3 = copy _2; - _5 = make_closure lambda[0]<2 type_args>(); - _6 = load_type(bool); - _7 = load_type(#1); - _8 = load_type(future<#0, #1>); - _4 = call const fn baml.Array.map(copy capture[0], copy _5) -> [bb4]; + _4 = const true; + goto -> bb4; } bb4: { - _9 = const 0_i64; - goto -> bb8; + _11 = copy _5 == const ; + branch copy _11 -> [bb5, bb6]; } bb5: { - throw_if_panic copy _18 -> bb6; + _5 = const true; + goto -> bb6; } bb6: { - _17 = const null; - goto -> bb7; + _12 = copy _6 == const ; + branch copy _12 -> [bb7, bb8]; } bb7: { - _20 = copy _9; - _9 = copy _20 + const 1_i64; + _6 = const 104857600_i64; goto -> bb8; } bb8: { - _11 = copy _9; - _12 = len(capture[0]); - goto -> bb9; + _13 = copy _7 == const ; + branch copy _13 -> [bb9, bb10]; } bb9: { - _10 = copy _11 < copy _12; - branch copy _10 -> [bb11, bb10]; + _7 = const 1024_i64; + goto -> bb10; } bb10: { - throw copy _3; + _14 = copy _8 == const ; + branch copy _14 -> [bb11, bb12]; } bb11: { - _14 = copy capture[0]; - _15 = copy _9; - _13 = copy _14[_15]; - _16 = call const fn baml.future.Future.is_error(copy _13) -> [bb12]; + _8 = call const fn baml.time.Duration.from_seconds(const 30n) -> [bb12]; } bb12: { - branch copy _16 -> [bb13, bb7]; + _15 = call const fn baml.time.Duration.to_nanoseconds(copy _8) -> [bb13]; } bb13: { - _19 = copy _13; - _17 = await _19 -> [bb7, unwind: bb5]; + _0 = sys_op const fn baml.http.Server._serve(copy _1, copy _2, copy _3, copy _4, copy _5, copy _6, copy _7, copy _15) -> bb14; + } + + bb14: { + return; } } -// lambda[0] -fn ., 1)>, 2)>(g: null) -> null { +fn baml.http.Server._serve = builtin(io) + +fn baml.http.TlsConfig.new(cert_pem: uint8array, key_pem: uint8array, allow_tls1_2: bool, handshake_timeout: baml.time.Duration) -> baml.http.TlsConfig { // Locals: - let _0: null // _0 // return - let _1: null // g // param + let _0: baml.http.TlsConfig // _0 // return + let _1: uint8array // cert_pem // param + let _2: uint8array // key_pem // param + let _3: bool // allow_tls1_2 // param + let _4: baml.time.Duration // handshake_timeout // param + let _5: bool + let _6: bool + let _7: bigint bb0: { - _0 = call const fn baml.future.Future.cancel(copy _1) -> [bb1]; + _5 = copy _3 == const ; + branch copy _5 -> [bb1, bb2]; } bb1: { + _3 = const true; + goto -> bb2; + } + + bb2: { + _6 = copy _4 == const ; + branch copy _6 -> [bb3, bb4]; + } + + bb3: { + _4 = call const fn baml.time.Duration.from_seconds(const 10n) -> [bb4]; + } + + bb4: { + _7 = call const fn baml.time.Duration.to_nanoseconds(copy _4) -> [bb5]; + } + + bb5: { + _0 = sys_op const fn baml.http.TlsConfig._new(copy _1, copy _2, copy _3, copy _7) -> bb6; + } + + bb6: { return; } } -fn baml.future.all_complete(futures: future[]) -> future { +fn baml.http.TlsConfig._new = builtin(io) + +fn baml.id.current = builtin(vm) + +fn baml.id.new = builtin(vm) + +fn baml.id.set = builtin(vm) + +fn baml.io.input = builtin(io) + +fn baml.io.print = builtin(io) + +fn baml.io.println = builtin(io) + +fn baml.io.eprint = builtin(io) + +fn baml.io.eprintln = builtin(io) + +fn baml.iter.Iterator.map(self: baml.iter.Iterator, fn: (Item) -> R throws E2) -> baml.iter.Iterator { // Locals: - let _0: future // _0 // return - let _1: future[] // futures // param [captured] - let _2: null - let _3: null + let _0: baml.iter.Iterator // _0 // return + let _1: baml.iter.Iterator // self // param + let _2: (Item) -> R throws E2 // fn // param bb0: { - _2 = make_closure lambda[0]<2 type_args>(copy _1); - _3 = spawn copy _2 name=const null -> bb1; + _0 = baml.iter.Map<#0, #2, #1, #3> { copy _1, copy _2 }; + goto -> bb1; } bb1: { - _0 = copy _3; - goto -> bb2; - } - - bb2: { return; } } -// lambda[0] -fn .() -> null { +fn baml.iter.Iterator.filter(self: baml.iter.Iterator, predicate: (Item) -> bool throws E2) -> baml.iter.Iterator { // Locals: - let _0: null // _0 // return - let _1: (future) -> T throws E - let _2: type - let _3: type - let _4: type + let _0: baml.iter.Iterator // _0 // return + let _1: baml.iter.Iterator // self // param + let _2: (Item) -> bool throws E2 // predicate // param bb0: { - _1 = make_closure lambda[0]<2 type_args>(); - _2 = load_type(#0); - _3 = load_type(#1); - _4 = load_type(future<#0, #1>); - _0 = call const fn baml.Array.map(copy capture[0], copy _1) -> [bb1]; + _0 = baml.iter.Filter<#0, #1, #2> { copy _1, copy _2 }; + goto -> bb1; } bb1: { @@ -3050,14 +3774,15 @@ fn .() -> null { } } -// lambda[0] -fn ., 1)>(f: null) -> null { +fn baml.iter.Iterator.filter_map(self: baml.iter.Iterator, fn: (Item) -> null | R throws E2) -> baml.iter.Iterator { // Locals: - let _0: null // _0 // return - let _1: null // f // param + let _0: baml.iter.Iterator // _0 // return + let _1: baml.iter.Iterator // self // param + let _2: (Item) -> null | R throws E2 // fn // param bb0: { - _0 = await _1 -> [bb1]; + _0 = baml.iter.FilterMap<#0, #2, #1, #3> { copy _1, copy _2 }; + goto -> bb1; } bb1: { @@ -3065,869 +3790,812 @@ fn ., 1)>(f: null) -> null { } } -fn baml.future.any(futures: future[]) -> future> { +fn baml.iter.Iterator.flat_map(self: baml.iter.Iterator, fn: (Item) -> baml.iter.Iterable throws E2) -> baml.iter.Iterator { // Locals: - let _0: future> // _0 // return - let _1: future[] // futures // param [captured] - let _2: null - let _3: null + let _0: baml.iter.Iterator // _0 // return + let _1: baml.iter.Iterator // self // param + let _2: (Item) -> baml.iter.Iterable throws E2 // fn // param + let _3: baml.iter.Done bb0: { - _2 = make_closure lambda[0]<2 type_args>(copy _1); - _3 = spawn copy _2 name=const null -> bb1; + _3 = baml.iter.Done { }; + _0 = baml.iter.FlatMap<#0, #2, #1, #3, #4> { copy _1, copy _2, copy _3 }; + goto -> bb1; } bb1: { - _0 = copy _3; - goto -> bb2; + return; } +} - bb2: { +fn baml.iter.Iterator.step_by(self: baml.iter.Iterator, n: int) -> baml.iter.Iterator { + // Locals: + let _0: baml.iter.Iterator // _0 // return + let _1: baml.iter.Iterator // self // param + let _2: int // n // param + + bb0: { + _0 = baml.iter.StepBy<#0, #1> { copy _1, copy _2, const true }; + goto -> bb1; + } + + bb1: { return; } } -// lambda[0] -fn .() -> null { +fn baml.iter.Iterator.chain(self: baml.iter.Iterator, other: baml.iter.Iterable) -> baml.iter.Iterator { // Locals: - let _0: null // _0 // return - let _1: T[] // winners - let _2: future[] // remaining - let _3: bool - let _4: int - let _5: int // i - let _6: future[] - let _7: future // f - let _8: future[] - let _9: int - let _10: bool - let _11: int - let _12: T - let _13: unknown // e - let _14: null - let _15: Err // e - let _16: baml.future.AllFailed // failure - let _17: Err[] - let _18: Err - let _19: bool - let _20: null | T - let _21: unknown // e - let _22: null - let _23: future[] - let _24: int - let _25: type - let _26: future[] - let _27: int - let _28: int - let _29: int - let _30: type - let _31: type - let _32: bool - let _33: int - let _34: Err[] // errors - let _35: int // j - let _36: bool - let _37: int - let _38: int - let _39: future // g - let _40: future[] - let _41: int - let _42: bool - let _43: null | T - let _44: unknown // e - let _45: null - let _46: Err // e - let _47: int - let _48: Err - let _49: int - let _50: baml.future.AllFailed // failure - let _51: Err[] - let _52: bool[] - let _53: (future) -> bool throws E - let _54: type - let _55: type - let _56: type - let _57: T[] - let _58: 0 + let _0: baml.iter.Iterator // _0 // return + let _1: baml.iter.Iterator // self // param + let _2: baml.iter.Iterable // other // param + let _3: baml.iter.Iterator bb0: { - _1 = []: #0[]; - _2 = copy capture[0]; - goto -> bb7; + _3 = virtual_call iter as baml.iter.Iterable(copy _2) -> [bb1]; } bb1: { - throw_if_panic copy _21 -> bb2; + _0 = baml.iter.Chain<#0, #1, #2> { copy _1, copy _3, const false }; + goto -> bb2; } bb2: { - _20 = const null; - goto -> bb3; + return; } +} - bb3: { - _24 = copy _5; - _25 = load_type(future<#0, #1>); - _23 = call const fn baml.Array.slice(copy _2, const 0_i64, copy _24) -> [bb4]; - } +fn baml.iter.Iterator.peekable(self: baml.iter.Iterator) -> baml.iter.Peekable { + // Locals: + let _0: baml.iter.Peekable // _0 // return + let _1: baml.iter.Iterator // self // param + let _2: baml.iter.Done - bb4: { - _28 = copy _5; - _27 = copy _28 + const 1_i64; - _29 = len(_2); - goto -> bb5; + bb0: { + _2 = baml.iter.Done { }; + _0 = baml.iter.Peekable<#0, #1> { copy _1, copy _2, const false }; + goto -> bb1; } - bb5: { - _30 = load_type(future<#0, #1>); - _26 = call const fn baml.Array.slice(copy _2, copy _27, copy _29) -> [bb6]; + bb1: { + return; } +} - bb6: { - _31 = load_type(future<#0, #1>); - _2 = call const fn baml.Array.concat(copy _23, copy _26) -> [bb7]; - } +fn baml.iter.Iterator.collect(self: baml.iter.Iterator) -> Item[] { + // Locals: + let _0: Item[] // _0 // return + let _1: baml.iter.Iterator // self // param + let _2: Item[] // r + let _3: int + let _4: baml.iter.Done | Item + let _5: bool + let _6: Item // x + let _7: Item - bb7: { - _4 = len(_2); - goto -> bb8; + bb0: { + _2 = []: #0[]; + goto -> bb1; } - bb8: { - _3 = copy _4 > const 0_i64; - branch copy _3 -> [bb9, bb19]; + bb1: { + branch const true -> [bb2, bb5]; } - bb9: { - _6 = copy _2; - _5 = await_any copy _6 -> [bb10]; + bb2: { + _4 = virtual_call next as baml.iter.Iterator(copy _1) -> [bb3]; } - bb10: { - _8 = copy _2; - _9 = copy _5; - _7 = copy _8[_9]; - _10 = call const fn baml.future.Future.is_result(copy _7) -> [bb11]; + bb3: { + _5 = is_type(copy _4, baml.iter.Done); + branch copy _5 -> [bb5, bb4]; } - bb11: { - branch copy _10 -> [bb15, bb12]; + bb4: { + _6 = copy _4; + _7 = copy _6; + _3 = call const fn baml.Array.push(copy _2, copy _7) -> [bb1]; } - bb12: { - _19 = call const fn baml.future.Future.is_error(copy _7) -> [bb13]; + bb5: { + _0 = copy _2; + goto -> bb6; } - bb13: { - branch copy _19 -> [bb14, bb3]; + bb6: { + return; } +} - bb14: { - _22 = copy _7; - _20 = await _22 -> [bb3, unwind: bb1]; +fn baml.iter.Iterator.reduce(self: baml.iter.Iterator, fn: (A, Item) -> A throws E2, initial: A) -> A { + // Locals: + let _0: A // _0 // return + let _1: baml.iter.Iterator // self // param + let _2: (A, Item) -> A throws E2 // fn // param + let _3: A // initial // param + let _4: A // acc + let _5: baml.iter.Done | Item + let _6: bool + let _7: Item // x + let _8: A + let _9: Item + + bb0: { + _4 = copy _3; + goto -> bb1; } - bb15: { - _14 = copy _7; - _12 = await _14 -> [bb18, unwind: bb16]; + bb1: { + branch const true -> [bb2, bb5]; } - bb16: { - throw_if_panic copy _13 -> bb17; + bb2: { + _5 = virtual_call next as baml.iter.Iterator(copy _1) -> [bb3]; } - bb17: { - _15 = copy _13; - _18 = copy _15; - _17 = [copy _18]: #1[]; - _16 = baml.future.AllFailed<#1> { copy _17 }; - throw copy _16; + bb3: { + _6 = is_type(copy _5, baml.iter.Done); + branch copy _6 -> [bb5, bb4]; } - bb18: { - _11 = call const fn baml.Array.push(copy _1, copy _12) -> [bb19]; + bb4: { + _7 = copy _5; + _8 = copy _4; + _9 = copy _7; + _4 = call copy _2(copy _8, copy _9) -> [bb1]; } - bb19: { - _33 = len(_1); - goto -> bb20; + bb5: { + _0 = copy _4; + goto -> bb6; } - bb20: { - _32 = copy _33 == const 0_i64; - branch copy _32 -> [bb24, bb21]; + bb6: { + return; } +} - bb21: { - _53 = make_closure lambda[0]<2 type_args>(); - _54 = load_type(bool); - _55 = load_type(never); - _56 = load_type(future<#0, #1>); - _52 = call const fn baml.Array.map(copy capture[0], copy _53) -> [bb22]; +fn baml.iter.Iterator.count(self: baml.iter.Iterator) -> int { + // Locals: + let _0: int // _0 // return + let _1: baml.iter.Iterator // self // param + let _2: int // n + let _3: baml.iter.Done | Item + let _4: bool + + bb0: { + _2 = const 0_i64; + goto -> bb1; } - bb22: { - _57 = copy _1; - _58 = const 0_i64; - _0 = copy _57[_58]; - goto -> bb23; + bb1: { + branch const true -> [bb2, bb5]; } - bb23: { - return; + bb2: { + _3 = virtual_call next as baml.iter.Iterator(copy _1) -> [bb3]; } - bb24: { - _34 = []: #1[]; - _35 = const 0_i64; - goto -> bb29; + bb3: { + _4 = is_type(copy _3, baml.iter.Done); + branch copy _4 -> [bb5, bb4]; } - bb25: { - throw_if_panic copy _44 -> bb26; + bb4: { + _2 = copy _2 + const 1_i64; + goto -> bb1; } - bb26: { - _46 = copy _44; - _48 = copy _46; - _47 = call const fn baml.Array.push(copy _34, copy _48) -> [bb27]; + bb5: { + _0 = copy _2; + goto -> bb6; } - bb27: { - _43 = const null; - goto -> bb28; + bb6: { + return; } +} - bb28: { - _49 = copy _35; - _35 = copy _49 + const 1_i64; - goto -> bb29; +fn baml.iter.Iterator.for_each(self: baml.iter.Iterator, fn: (Item) -> void throws E2) -> void { + // Locals: + let _0: void // _0 // return + let _1: baml.iter.Iterator // self // param + let _2: (Item) -> void throws E2 // fn // param + let _3: baml.iter.Done | Item + let _4: bool + let _5: Item // x + let _6: void + let _7: Item + + bb0: { + goto -> bb1; } - bb29: { - _37 = copy _35; - _38 = len(capture[0]); - goto -> bb30; + bb1: { + branch const true -> [bb2, bb5]; } - bb30: { - _36 = copy _37 < copy _38; - branch copy _36 -> [bb32, bb31]; + bb2: { + _3 = virtual_call next as baml.iter.Iterator(copy _1) -> [bb3]; } - bb31: { - _51 = copy _34; - _50 = baml.future.AllFailed<#1> { copy _51 }; - throw copy _50; + bb3: { + _4 = is_type(copy _3, baml.iter.Done); + branch copy _4 -> [bb5, bb4]; } - bb32: { - _40 = copy capture[0]; - _41 = copy _35; - _39 = copy _40[_41]; - _42 = call const fn baml.future.Future.is_error(copy _39) -> [bb33]; + bb4: { + _5 = copy _3; + _7 = copy _5; + _6 = call copy _2(copy _7) -> [bb1]; } - bb33: { - branch copy _42 -> [bb34, bb28]; + bb5: { + _0 = const null; + goto -> bb6; } - bb34: { - _45 = copy _39; - _43 = await _45 -> [bb28, unwind: bb25]; + bb6: { + return; } } -// lambda[0] -fn ., 1)>(g: null) -> null { +fn baml.iter.Iterator.some(self: baml.iter.Iterator, predicate: (Item) -> bool throws E2) -> bool { // Locals: - let _0: null // _0 // return - let _1: null // g // param + let _0: bool // _0 // return + let _1: baml.iter.Iterator // self // param + let _2: (Item) -> bool throws E2 // predicate // param + let _3: baml.iter.Done | Item + let _4: bool + let _5: Item // x + let _6: bool + let _7: Item bb0: { - _0 = call const fn baml.future.Future.cancel(copy _1) -> [bb1]; + goto -> bb1; } bb1: { - return; + branch const true -> [bb2, bb7]; } -} - -fn baml.future.Future.cancel = builtin(vm) -fn baml.future.Future.is_cancelled = builtin(vm) + bb2: { + _3 = virtual_call next as baml.iter.Iterator(copy _1) -> [bb3]; + } -fn baml.future.Future.is_error = builtin(vm) - -fn baml.future.Future.is_result = builtin(vm) + bb3: { + _4 = is_type(copy _3, baml.iter.Done); + branch copy _4 -> [bb7, bb4]; + } -fn baml.future.Future.is_settled = builtin(vm) + bb4: { + _5 = copy _3; + _7 = copy _5; + _6 = call copy _2(copy _7) -> [bb5]; + } -fn baml.future.race(futures: future[]) -> future { - // Locals: - let _0: future // _0 // return - let _1: future[] // futures // param [captured] - let _2: null - let _3: null + bb5: { + branch copy _6 -> [bb6, bb1]; + } - bb0: { - _2 = make_closure lambda[0]<2 type_args>(copy _1); - _3 = spawn copy _2 name=const null -> bb1; + bb6: { + _0 = const true; + goto -> bb8; } - bb1: { - _0 = copy _3; - goto -> bb2; + bb7: { + _0 = const false; + goto -> bb8; } - bb2: { + bb8: { return; } } -// lambda[0] -fn .() -> null { +fn baml.iter.Iterator.every(self: baml.iter.Iterator, predicate: (Item) -> bool throws E2) -> bool { // Locals: - let _0: null // _0 // return - let _1: int // i - let _2: future[] - let _3: bool[] - let _4: (future) -> bool throws E - let _5: type - let _6: type - let _7: type - let _8: null - let _9: future[] - let _10: int + let _0: bool // _0 // return + let _1: baml.iter.Iterator // self // param + let _2: (Item) -> bool throws E2 // predicate // param + let _3: baml.iter.Done | Item + let _4: bool + let _5: Item // x + let _6: bool + let _7: bool + let _8: Item bb0: { - _2 = copy capture[0]; - _1 = await_any copy _2 -> [bb1]; + goto -> bb1; } bb1: { - _4 = make_closure lambda[0]<2 type_args>(); - _5 = load_type(bool); - _6 = load_type(#1); - _7 = load_type(future<#0, #1>); - _3 = call const fn baml.Array.map(copy capture[0], copy _4) -> [bb2]; + branch const true -> [bb2, bb7]; } bb2: { - _9 = copy capture[0]; - _10 = copy _1; - _8 = copy _9[_10]; - _0 = await _8 -> [bb3]; + _3 = virtual_call next as baml.iter.Iterator(copy _1) -> [bb3]; } bb3: { - return; - } -} - -// lambda[0] -fn ., 1)>(f: null) -> null { - // Locals: - let _0: null // _0 // return - let _1: null // f // param - - bb0: { - _0 = call const fn baml.future.Future.cancel(copy _1) -> [bb1]; + _4 = is_type(copy _3, baml.iter.Done); + branch copy _4 -> [bb7, bb4]; } - bb1: { - return; + bb4: { + _5 = copy _3; + _8 = copy _5; + _7 = call copy _2(copy _8) -> [bb5]; } -} - -fn baml.future.Future.state = builtin(vm) -fn baml.glob.Glob.matches = builtin(io) - -fn baml.glob.new = builtin(io) - -fn baml.glob.Glob.scan = builtin(io) - -fn baml.host.call_host_value = builtin(io) - -fn baml.http._fetch = builtin(io) - -fn baml.http._send = builtin(io) - -fn baml.http._timeout_nanos(timeout: null | baml.time.Duration) -> bigint { - // Locals: - let _0: bigint // _0 // return - let _1: null | baml.time.Duration // timeout // param - let _2: bool - let _3: baml.time.Duration // t - - bb0: { - _2 = copy _1 == const null; - branch copy _2 -> [bb2, bb1]; + bb5: { + _6 = !copy _7; + branch copy _6 -> [bb6, bb1]; } - bb1: { - _3 = copy _1; - _0 = call const fn baml.time.Duration.to_nanoseconds(copy _3) -> [bb3]; + bb6: { + _0 = const false; + goto -> bb8; } - bb2: { - _0 = const 0n; - goto -> bb3; + bb7: { + _0 = const true; + goto -> bb8; } - bb3: { + bb8: { return; } } -fn baml.http.Response.bytes = builtin(io) - -fn baml.http.SseStream.close = builtin(io) - -fn baml.http.Response.end = builtin(io) - -fn baml.http.fetch(url: string, timeout: null | baml.time.Duration) -> baml.http.Response { +fn baml.iter.Iterator.find(self: baml.iter.Iterator, predicate: (Item) -> bool throws E2) -> null | Item { // Locals: - let _0: baml.http.Response // _0 // return - let _1: string // url // param - let _2: null | baml.time.Duration // timeout // param - let _3: bool - let _4: bigint + let _0: null | Item // _0 // return + let _1: baml.iter.Iterator // self // param + let _2: (Item) -> bool throws E2 // predicate // param + let _3: baml.iter.Done | Item + let _4: bool + let _5: Item // x + let _6: bool + let _7: Item bb0: { - _3 = copy _2 == const ; - branch copy _3 -> [bb1, bb2]; + goto -> bb1; } bb1: { - _2 = const null; - goto -> bb2; + branch const true -> [bb2, bb7]; } bb2: { - _4 = call const fn baml.http._timeout_nanos(copy _2) -> [bb3]; + _3 = virtual_call next as baml.iter.Iterator(copy _1) -> [bb3]; } bb3: { - _0 = sys_op const fn baml.http._fetch(copy _1, copy _4) -> bb4; + _4 = is_type(copy _3, baml.iter.Done); + branch copy _4 -> [bb7, bb4]; } bb4: { - return; + _5 = copy _3; + _7 = copy _5; + _6 = call copy _2(copy _7) -> [bb5]; } -} -fn baml.http.fetch_sse = builtin(io) + bb5: { + branch copy _6 -> [bb6, bb1]; + } -fn baml.http.Response.new = builtin(io) + bb6: { + _0 = copy _5; + goto -> bb8; + } -fn baml.http.Response.new_streaming = builtin(io) + bb7: { + _0 = const null; + goto -> bb8; + } -fn baml.http.SseStream.next = builtin(io) + bb8: { + return; + } +} -fn baml.http.Response.ok(self: baml.http.Response) -> bool { +fn baml.iter.flatten(src: baml.iter.Iterator) -> baml.iter.Iterator { // Locals: - let _0: bool // _0 // return - let _1: baml.http.Response // self // param - let _2: bool - let _3: int - let _4: int + let _0: baml.iter.Iterator // _0 // return + let _1: baml.iter.Iterator // src // param + let _2: baml.iter.Done bb0: { - _3 = copy _1.0; - _2 = copy _3 >= const 200_i64; - _0 = short_circuit(&&) copy _2 -> [eval: bb1, join: bb2]; + _2 = baml.iter.Done { }; + _0 = baml.iter.Flatten<#3, #0, #1, #2> { copy _1, copy _2 }; + goto -> bb1; } bb1: { - _4 = copy _1.0; - _0 = copy _4 < const 300_i64; - goto -> bb2; - } - - bb2: { return; } } -fn baml.http.send(request: baml.http.Request, timeout: null | baml.time.Duration) -> baml.http.Response { +fn baml.iter.ArrayIterator.new(arr: T[]) -> baml.iter.ArrayIterator { // Locals: - let _0: baml.http.Response // _0 // return - let _1: baml.http.Request // request // param - let _2: null | baml.time.Duration // timeout // param - let _3: bool - let _4: bigint + let _0: baml.iter.ArrayIterator // _0 // return + let _1: T[] // arr // param bb0: { - _3 = copy _2 == const ; - branch copy _3 -> [bb1, bb2]; + _0 = baml.iter.ArrayIterator<#0> { copy _1, const 0_i64 }; + goto -> bb1; } bb1: { - _2 = const null; - goto -> bb2; + return; } +} - bb2: { - _4 = call const fn baml.http._timeout_nanos(copy _2) -> [bb3]; - } +fn baml.iter.ArrayIterator.Iterable.iter(self: baml.iter.ArrayIterator) -> baml.iter.Iterator { + // Locals: + let _0: baml.iter.Iterator // _0 // return + let _1: baml.iter.ArrayIterator // self // param - bb3: { - _0 = sys_op const fn baml.http._send(copy _1, copy _4) -> bb4; + bb0: { + _0 = copy _1; + goto -> bb1; } - bb4: { + bb1: { return; } } -fn baml.http.Response.text = builtin(io) - -fn baml.http.Response.write = builtin(io) - -fn baml.http.TlsConfig._new = builtin(io) - -fn baml.http.Server._serve = builtin(io) - -fn baml.http.Server.bind = builtin(io) - -fn baml.http.TlsConfig.new(cert_pem: uint8array, key_pem: uint8array, allow_tls1_2: bool, handshake_timeout: baml.time.Duration) -> baml.http.TlsConfig { +fn baml.iter.ArrayIterator.Iterator.next(self: baml.iter.ArrayIterator) -> baml.iter.Done | T { // Locals: - let _0: baml.http.TlsConfig // _0 // return - let _1: uint8array // cert_pem // param - let _2: uint8array // key_pem // param - let _3: bool // allow_tls1_2 // param - let _4: baml.time.Duration // handshake_timeout // param - let _5: bool - let _6: bool - let _7: bigint + let _0: baml.iter.Done | T // _0 // return + let _1: baml.iter.ArrayIterator // self // param + let _2: bool + let _3: int + let _4: int + let _5: (T[]) -> int throws never + let _6: null | T // item + let _7: (T[], int) -> null | T throws never + let _8: int + let _9: type + let _10: T // value bb0: { - _5 = copy _3 == const ; - branch copy _5 -> [bb1, bb2]; + _3 = copy _1.1; + _5 = copy _1.0; + _4 = len(_5); + goto -> bb1; } bb1: { - _3 = const true; - goto -> bb2; + _2 = copy _3 >= copy _4; + branch copy _2 -> [bb4, bb2]; } bb2: { - _6 = copy _4 == const ; - branch copy _6 -> [bb3, bb4]; + _7 = copy _1.0; + _8 = copy _1.1; + _9 = load_type(#0); + _6 = call const fn baml.Array.at(copy _7, copy _8) -> [bb3]; } bb3: { - _4 = call const fn baml.time.Duration.from_seconds(const 10n) -> [bb4]; + _1.1 = copy _1.1 + const 1_i64; + _10 = copy _6; + _0 = copy _10; + goto -> bb5; } bb4: { - _7 = call const fn baml.time.Duration.to_nanoseconds(copy _4) -> [bb5]; + _0 = baml.iter.Done { }; + goto -> bb5; } bb5: { - _0 = sys_op const fn baml.http.TlsConfig._new(copy _1, copy _2, copy _3, copy _7) -> bb6; - } - - bb6: { return; } } -fn baml.http.Server.serve(self: baml.http.Server, handler: (baml.http.Request) -> baml.http.Response throws never, tls_config: null | baml.http.TlsConfig, allow_http1: bool, allow_http2: bool, max_body_size: int, max_connections: int, header_read_timeout: baml.time.Duration) -> never { +fn baml.iter.Range.new(min: int, max: int, step: int) -> baml.iter.Range { // Locals: - let _0: never // _0 // return - let _1: baml.http.Server // self // param - let _2: (baml.http.Request) -> baml.http.Response throws never // handler // param - let _3: null | baml.http.TlsConfig // tls_config // param - let _4: bool // allow_http1 // param - let _5: bool // allow_http2 // param - let _6: int // max_body_size // param - let _7: int // max_connections // param - let _8: baml.time.Duration // header_read_timeout // param - let _9: bool - let _10: bool - let _11: bool - let _12: bool - let _13: bool - let _14: bool - let _15: bigint + let _0: baml.iter.Range // _0 // return + let _1: int // min // param + let _2: int // max // param + let _3: int // step // param + let _4: bool bb0: { - _9 = copy _3 == const ; - branch copy _9 -> [bb1, bb2]; + _4 = copy _3 == const ; + branch copy _4 -> [bb1, bb2]; } bb1: { - _3 = const null; + _3 = const 1_i64; goto -> bb2; } bb2: { - _10 = copy _4 == const ; - branch copy _10 -> [bb3, bb4]; + _0 = baml.iter.Range { copy _1, copy _2, copy _3 }; + goto -> bb3; } bb3: { - _4 = const true; - goto -> bb4; + return; } +} - bb4: { - _11 = copy _5 == const ; - branch copy _11 -> [bb5, bb6]; - } +fn baml.iter.Range.Iterable.iter(self: baml.iter.Range) -> baml.iter.Iterator { + // Locals: + let _0: baml.iter.Iterator // _0 // return + let _1: baml.iter.Range // self // param - bb5: { - _5 = const true; - goto -> bb6; + bb0: { + _0 = copy _1; + goto -> bb1; } - bb6: { - _12 = copy _6 == const ; - branch copy _12 -> [bb7, bb8]; + bb1: { + return; } +} - bb7: { - _6 = const 104857600_i64; - goto -> bb8; +fn baml.iter.Range.Iterator.next(self: baml.iter.Range) -> int | baml.iter.Done { + // Locals: + let _0: int | baml.iter.Done // _0 // return + let _1: baml.iter.Range // self // param + let _2: bool + let _3: int + let _4: int + let _5: int // cur + let _6: int + + bb0: { + _3 = copy _1.0; + _4 = copy _1.1; + _2 = copy _3 < copy _4; + branch copy _2 -> [bb2, bb1]; } - bb8: { - _13 = copy _7 == const ; - branch copy _13 -> [bb9, bb10]; + bb1: { + _0 = baml.iter.Done { }; + goto -> bb3; } - bb9: { - _7 = const 1024_i64; - goto -> bb10; + bb2: { + _5 = copy _1.0; + _6 = copy _1.2; + _1.0 = copy _1.0 + copy _6; + _0 = copy _5; + goto -> bb3; } - bb10: { - _14 = copy _8 == const ; - branch copy _14 -> [bb11, bb12]; + bb3: { + return; } +} - bb11: { - _8 = call const fn baml.time.Duration.from_seconds(const 30n) -> [bb12]; +fn baml.iter.Repeat.new(value: T, count: int) -> baml.iter.Repeat { + // Locals: + let _0: baml.iter.Repeat // _0 // return + let _1: T // value // param + let _2: int // count // param + let _3: bool + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } - bb12: { - _15 = call const fn baml.time.Duration.to_nanoseconds(copy _8) -> [bb13]; + bb1: { + _2 = const -1_i64; + goto -> bb2; } - bb13: { - _0 = sys_op const fn baml.http.Server._serve(copy _1, copy _2, copy _3, copy _4, copy _5, copy _6, copy _7, copy _15) -> bb14; + bb2: { + _0 = baml.iter.Repeat<#0> { copy _1, copy _2 }; + goto -> bb3; } - bb14: { + bb3: { return; } } -fn baml.id.current = builtin(vm) - -fn baml.id.new = builtin(vm) - -fn baml.id.set = builtin(vm) - -fn baml.io.eprint = builtin(io) - -fn baml.io.eprintln = builtin(io) - -fn baml.io.input = builtin(io) - -fn baml.io.print = builtin(io) - -fn baml.io.println = builtin(io) - -fn baml.iter.Iterator.chain(self: baml.iter.Iterator, other: baml.iter.Iterable) -> baml.iter.Iterator { +fn baml.iter.Repeat.Iterable.iter(self: baml.iter.Repeat) -> baml.iter.Iterator { // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: baml.iter.Iterator // self // param - let _2: baml.iter.Iterable // other // param - let _3: baml.iter.Iterator + let _0: baml.iter.Iterator // _0 // return + let _1: baml.iter.Repeat // self // param bb0: { - _3 = virtual_call iter as baml.iter.Iterable(copy _2) -> [bb1]; + _0 = copy _1; + goto -> bb1; } bb1: { - _0 = baml.iter.Chain<#0, #1, #2> { copy _1, copy _3, const false }; - goto -> bb2; - } - - bb2: { return; } } -fn baml.iter.Iterator.collect(self: baml.iter.Iterator) -> Item[] { +fn baml.iter.Repeat.Iterator.next(self: baml.iter.Repeat) -> baml.iter.Done | T { // Locals: - let _0: Item[] // _0 // return - let _1: baml.iter.Iterator // self // param - let _2: Item[] // r + let _0: baml.iter.Done | T // _0 // return + let _1: baml.iter.Repeat // self // param + let _2: bool let _3: int - let _4: baml.iter.Done | Item - let _5: bool - let _6: Item // x - let _7: Item + let _4: bool + let _5: int bb0: { - _2 = []: #0[]; - goto -> bb1; + _3 = copy _1.1; + _2 = copy _3 < const 0_i64; + branch copy _2 -> [bb4, bb1]; } bb1: { - branch const true -> [bb2, bb5]; + _5 = copy _1.1; + _4 = copy _5 > const 0_i64; + branch copy _4 -> [bb3, bb2]; } bb2: { - _4 = virtual_call next as baml.iter.Iterator(copy _1) -> [bb3]; + _0 = baml.iter.Done { }; + goto -> bb5; } bb3: { - _5 = is_type(copy _4, baml.iter.Done); - branch copy _5 -> [bb5, bb4]; + _1.1 = copy _1.1 - const 1_i64; + _0 = copy _1.0; + goto -> bb5; } bb4: { - _6 = copy _4; - _7 = copy _6; - _3 = call const fn baml.Array.push(copy _2, copy _7) -> [bb1]; + _0 = copy _1.0; + goto -> bb5; } bb5: { - _0 = copy _2; - goto -> bb6; - } - - bb6: { return; } } -fn baml.iter.Iterator.count(self: baml.iter.Iterator) -> int { +fn baml.iter.Map.Iterable.iter(self: baml.iter.Map) -> baml.iter.Iterator { // Locals: - let _0: int // _0 // return - let _1: baml.iter.Iterator // self // param - let _2: int // n - let _3: baml.iter.Done | Item - let _4: bool + let _0: baml.iter.Iterator // _0 // return + let _1: baml.iter.Map // self // param bb0: { - _2 = const 0_i64; + _0 = copy _1; goto -> bb1; } bb1: { - branch const true -> [bb2, bb5]; + return; } +} - bb2: { - _3 = virtual_call next as baml.iter.Iterator(copy _1) -> [bb3]; +fn baml.iter.Map.Iterator.next(self: baml.iter.Map) -> baml.iter.Done | R { + // Locals: + let _0: baml.iter.Done | R // _0 // return + let _1: baml.iter.Map // self // param + let _2: baml.iter.Done | T + let _3: baml.iter.Iterator + let _4: bool + let _5: T // x + let _6: (T) -> R throws E2 + let _7: T + + bb0: { + _3 = copy _1.0; + _2 = virtual_call next as baml.iter.Iterator(copy _3) -> [bb1]; + } + + bb1: { + _4 = is_type(copy _2, baml.iter.Done); + branch copy _4 -> [bb3, bb2]; + } + + bb2: { + _5 = copy _2; + _6 = copy _1.1; + _7 = copy _5; + _0 = call copy _6(copy _7) -> [bb4]; } bb3: { - _4 = is_type(copy _3, baml.iter.Done); - branch copy _4 -> [bb5, bb4]; + _0 = baml.iter.Done { }; + goto -> bb4; } bb4: { - _2 = copy _2 + const 1_i64; - goto -> bb1; + return; } +} - bb5: { - _0 = copy _2; - goto -> bb6; +fn baml.iter.Filter.Iterable.iter(self: baml.iter.Filter) -> baml.iter.Iterator { + // Locals: + let _0: baml.iter.Iterator // _0 // return + let _1: baml.iter.Filter // self // param + + bb0: { + _0 = copy _1; + goto -> bb1; } - bb6: { + bb1: { return; } } -fn baml.iter.Iterator.every(self: baml.iter.Iterator, predicate: (Item) -> bool throws E2) -> bool { +fn baml.iter.Filter.Iterator.next(self: baml.iter.Filter) -> baml.iter.Done | T { // Locals: - let _0: bool // _0 // return - let _1: baml.iter.Iterator // self // param - let _2: (Item) -> bool throws E2 // predicate // param - let _3: baml.iter.Done | Item + let _0: baml.iter.Done | T // _0 // return + let _1: baml.iter.Filter // self // param + let _2: baml.iter.Done | T + let _3: baml.iter.Iterator let _4: bool - let _5: Item // x + let _5: T // x let _6: bool - let _7: bool - let _8: Item + let _7: (T) -> bool throws E2 + let _8: T bb0: { goto -> bb1; } bb1: { - branch const true -> [bb2, bb7]; + branch const true -> [bb3, bb2]; } bb2: { - _3 = virtual_call next as baml.iter.Iterator(copy _1) -> [bb3]; + _0 = baml.iter.Done { }; + goto -> bb9; } bb3: { - _4 = is_type(copy _3, baml.iter.Done); - branch copy _4 -> [bb7, bb4]; + _3 = copy _1.0; + _2 = virtual_call next as baml.iter.Iterator(copy _3) -> [bb4]; } bb4: { - _5 = copy _3; - _8 = copy _5; - _7 = call copy _2(copy _8) -> [bb5]; + _4 = is_type(copy _2, baml.iter.Done); + branch copy _4 -> [bb8, bb5]; } bb5: { - _6 = !copy _7; - branch copy _6 -> [bb6, bb1]; + _5 = copy _2; + _7 = copy _1.1; + _8 = copy _5; + _6 = call copy _7(copy _8) -> [bb6]; } bb6: { - _0 = const false; - goto -> bb8; + branch copy _6 -> [bb7, bb1]; } bb7: { - _0 = const true; - goto -> bb8; + _0 = copy _5; + goto -> bb9; } bb8: { - return; - } -} - -fn baml.iter.Iterator.filter(self: baml.iter.Iterator, predicate: (Item) -> bool throws E2) -> baml.iter.Iterator { - // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: baml.iter.Iterator // self // param - let _2: (Item) -> bool throws E2 // predicate // param - - bb0: { - _0 = baml.iter.Filter<#0, #1, #2> { copy _1, copy _2 }; - goto -> bb1; + _0 = baml.iter.Done { }; + goto -> bb9; } - bb1: { + bb9: { return; } } -fn baml.iter.Iterator.filter_map(self: baml.iter.Iterator, fn: (Item) -> null | R throws E2) -> baml.iter.Iterator { +fn baml.iter.FilterMap.Iterable.iter(self: baml.iter.FilterMap) -> baml.iter.Iterator { // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: baml.iter.Iterator // self // param - let _2: (Item) -> null | R throws E2 // fn // param + let _0: baml.iter.Iterator // _0 // return + let _1: baml.iter.FilterMap // self // param bb0: { - _0 = baml.iter.FilterMap<#0, #2, #1, #3> { copy _1, copy _2 }; + _0 = copy _1; goto -> bb1; } @@ -3936,86 +4604,78 @@ fn baml.iter.Iterator.filter_map(self: baml.iter.Iterator, fn: (Item) -> null | } } -fn baml.iter.Iterator.find(self: baml.iter.Iterator, predicate: (Item) -> bool throws E2) -> null | Item { +fn baml.iter.FilterMap.Iterator.next(self: baml.iter.FilterMap) -> baml.iter.Done | R { // Locals: - let _0: null | Item // _0 // return - let _1: baml.iter.Iterator // self // param - let _2: (Item) -> bool throws E2 // predicate // param - let _3: baml.iter.Done | Item + let _0: baml.iter.Done | R // _0 // return + let _1: baml.iter.FilterMap // self // param + let _2: baml.iter.Done | T + let _3: baml.iter.Iterator let _4: bool - let _5: Item // x - let _6: bool - let _7: Item + let _5: T // x + let _6: null | R + let _7: (T) -> null | R throws E2 + let _8: T + let _9: bool + let _10: R // y bb0: { goto -> bb1; } bb1: { - branch const true -> [bb2, bb7]; + branch const true -> [bb3, bb2]; } bb2: { - _3 = virtual_call next as baml.iter.Iterator(copy _1) -> [bb3]; + _0 = baml.iter.Done { }; + goto -> bb9; } bb3: { - _4 = is_type(copy _3, baml.iter.Done); - branch copy _4 -> [bb7, bb4]; + _3 = copy _1.0; + _2 = virtual_call next as baml.iter.Iterator(copy _3) -> [bb4]; } bb4: { - _5 = copy _3; - _7 = copy _5; - _6 = call copy _2(copy _7) -> [bb5]; + _4 = is_type(copy _2, baml.iter.Done); + branch copy _4 -> [bb8, bb5]; } bb5: { - branch copy _6 -> [bb6, bb1]; + _5 = copy _2; + _7 = copy _1.1; + _8 = copy _5; + _6 = call copy _7(copy _8) -> [bb6]; } bb6: { - _0 = copy _5; - goto -> bb8; + _9 = copy _6 == const null; + branch copy _9 -> [bb1, bb7]; } bb7: { - _0 = const null; - goto -> bb8; + _10 = copy _6; + _0 = copy _10; + goto -> bb9; } bb8: { - return; - } -} - -fn baml.iter.Iterator.flat_map(self: baml.iter.Iterator, fn: (Item) -> baml.iter.Iterable throws E2) -> baml.iter.Iterator { - // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: baml.iter.Iterator // self // param - let _2: (Item) -> baml.iter.Iterable throws E2 // fn // param - let _3: baml.iter.Done - - bb0: { - _3 = baml.iter.Done { }; - _0 = baml.iter.FlatMap<#0, #2, #1, #3, #4> { copy _1, copy _2, copy _3 }; - goto -> bb1; + _0 = baml.iter.Done { }; + goto -> bb9; } - bb1: { + bb9: { return; } } -fn baml.iter.flatten(src: baml.iter.Iterator) -> baml.iter.Iterator { +fn baml.iter.FlatMap.Iterable.iter(self: baml.iter.FlatMap) -> baml.iter.Iterator { // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: baml.iter.Iterator // src // param - let _2: baml.iter.Done + let _0: baml.iter.Iterator // _0 // return + let _1: baml.iter.FlatMap // self // param bb0: { - _2 = baml.iter.Done { }; - _0 = baml.iter.Flatten<#3, #0, #1, #2> { copy _1, copy _2 }; + _0 = copy _1; goto -> bb1; } @@ -4024,99 +4684,115 @@ fn baml.iter.flatten(src: baml.iter.Iterator) -> baml.iter. } } -fn baml.iter.Iterator.for_each(self: baml.iter.Iterator, fn: (Item) -> void throws E2) -> void { +fn baml.iter.FlatMap.Iterator.next(self: baml.iter.FlatMap) -> baml.iter.Done | R { // Locals: - let _0: void // _0 // return - let _1: baml.iter.Iterator // self // param - let _2: (Item) -> void throws E2 // fn // param - let _3: baml.iter.Done | Item - let _4: bool - let _5: Item // x - let _6: void - let _7: Item + let _0: baml.iter.Done | R // _0 // return + let _1: baml.iter.FlatMap // self // param + let _2: baml.iter.Done | baml.iter.Iterator + let _3: bool + let _4: baml.iter.Iterator // cur + let _5: baml.iter.Done | R + let _6: bool + let _7: R // y + let _8: bool + let _9: baml.iter.Done | T + let _10: baml.iter.Iterator + let _11: bool + let _12: T // x + let _13: baml.iter.Iterator // it + let _14: baml.iter.Iterable + let _15: (T) -> baml.iter.Iterable throws E2 + let _16: T bb0: { goto -> bb1; } bb1: { - branch const true -> [bb2, bb5]; + branch const true -> [bb3, bb2]; } bb2: { - _3 = virtual_call next as baml.iter.Iterator(copy _1) -> [bb3]; + _0 = baml.iter.Done { }; + goto -> bb15; } bb3: { - _4 = is_type(copy _3, baml.iter.Done); - branch copy _4 -> [bb5, bb4]; + _2 = copy _1.2; + _3 = is_type(copy _2, baml.iter.Iterator); + branch copy _3 -> [bb12, bb4]; } bb4: { - _5 = copy _3; - _7 = copy _5; - _6 = call copy _2(copy _7) -> [bb1]; + _8 = is_type(copy _2, baml.iter.Done); + branch copy _8 -> [bb6, bb5]; } bb5: { - _0 = const null; - goto -> bb6; + unreachable; } bb6: { - return; + _10 = copy _1.0; + _9 = virtual_call next as baml.iter.Iterator(copy _10) -> [bb7]; } -} - -fn baml.iter.Chain.Iterable.iter(self: baml.iter.Chain) -> baml.iter.Iterator { - // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: baml.iter.Chain // self // param - bb0: { - _0 = copy _1; - goto -> bb1; + bb7: { + _11 = is_type(copy _9, baml.iter.Done); + branch copy _11 -> [bb11, bb8]; } - bb1: { - return; - } -} + bb8: { + _12 = copy _9; + _15 = copy _1.1; + _16 = copy _12; + _14 = call copy _15(copy _16) -> [bb9]; + } -fn baml.iter.ArrayIterator.Iterable.iter(self: baml.iter.ArrayIterator) -> baml.iter.Iterator { - // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: baml.iter.ArrayIterator // self // param + bb9: { + _13 = virtual_call iter as baml.iter.Iterable(copy _14) -> [bb10]; + } - bb0: { - _0 = copy _1; + bb10: { + _1.2 = copy _13; goto -> bb1; } - bb1: { - return; + bb11: { + _0 = baml.iter.Done { }; + goto -> bb15; } -} -fn baml.iter.Map.Iterable.iter(self: baml.iter.Map) -> baml.iter.Iterator { - // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: baml.iter.Map // self // param + bb12: { + _4 = copy _2; + _5 = virtual_call next as baml.iter.Iterator(copy _4) -> [bb13]; + } - bb0: { - _0 = copy _1; - goto -> bb1; + bb13: { + _6 = is_type(copy _5, baml.iter.Done); + branch copy _6 -> [bb16, bb14]; } - bb1: { + bb14: { + _7 = copy _5; + _0 = copy _7; + goto -> bb15; + } + + bb15: { return; } + + bb16: { + _1.2 = baml.iter.Done { }; + goto -> bb1; + } } -fn baml.iter.FlatMap.Iterable.iter(self: baml.iter.FlatMap) -> baml.iter.Iterator { +fn baml.iter.Flatten.Iterable.iter(self: baml.iter.Flatten) -> baml.iter.Iterator { // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: baml.iter.FlatMap // self // param + let _0: baml.iter.Iterator // _0 // return + let _1: baml.iter.Flatten // self // param bb0: { _0 = copy _1; @@ -4128,105 +4804,141 @@ fn baml.iter.FlatMap.Iterable.iter(self: baml.iter.FlatMap) -> baml.iter.Iterato } } -fn baml.iter.StepBy.Iterable.iter(self: baml.iter.StepBy) -> baml.iter.Iterator { +fn baml.iter.Flatten.Iterator.next(self: baml.iter.Flatten) -> baml.iter.Done | R { // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: baml.iter.StepBy // self // param + let _0: baml.iter.Done | R // _0 // return + let _1: baml.iter.Flatten // self // param + let _2: baml.iter.Done | baml.iter.Iterator + let _3: bool + let _4: baml.iter.Iterator // cur + let _5: baml.iter.Done | R + let _6: bool + let _7: R // y + let _8: bool + let _9: baml.iter.Done | I + let _10: baml.iter.Iterator + let _11: bool + let _12: I // x + let _13: baml.iter.Iterator // it bb0: { - _0 = copy _1; goto -> bb1; } bb1: { - return; + branch const true -> [bb3, bb2]; } -} -fn baml.iter.Iterable$for$string.iter(self: string) -> baml.iter.Iterator { - // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: string // self // param - let _2: string[] + bb2: { + _0 = baml.iter.Done { }; + goto -> bb14; + } - bb0: { - _2 = call const fn baml.String.chars(copy _1) -> [bb1]; + bb3: { + _2 = copy _1.1; + _3 = is_type(copy _2, baml.iter.Iterator); + branch copy _3 -> [bb11, bb4]; } - bb1: { - _0 = virtual_call iter as baml.iter.Iterable(copy _2) -> [bb2]; + bb4: { + _8 = is_type(copy _2, baml.iter.Done); + branch copy _8 -> [bb6, bb5]; } - bb2: { - return; + bb5: { + unreachable; } -} -fn baml.iter.Repeat.Iterable.iter(self: baml.iter.Repeat) -> baml.iter.Iterator { - // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: baml.iter.Repeat // self // param + bb6: { + _10 = copy _1.0; + _9 = virtual_call next as baml.iter.Iterator(copy _10) -> [bb7]; + } - bb0: { - _0 = copy _1; + bb7: { + _11 = is_type(copy _9, baml.iter.Done); + branch copy _11 -> [bb10, bb8]; + } + + bb8: { + _12 = copy _9; + _13 = virtual_call iter as baml.iter.Iterable(copy _12) -> [bb9]; + } + + bb9: { + _1.1 = copy _13; goto -> bb1; } - bb1: { - return; + bb10: { + _0 = baml.iter.Done { }; + goto -> bb14; } -} -fn baml.iter.FilterMap.Iterable.iter(self: baml.iter.FilterMap) -> baml.iter.Iterator { - // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: baml.iter.FilterMap // self // param + bb11: { + _4 = copy _2; + _5 = virtual_call next as baml.iter.Iterator(copy _4) -> [bb12]; + } - bb0: { - _0 = copy _1; - goto -> bb1; + bb12: { + _6 = is_type(copy _5, baml.iter.Done); + branch copy _6 -> [bb15, bb13]; } - bb1: { + bb13: { + _7 = copy _5; + _0 = copy _7; + goto -> bb14; + } + + bb14: { return; } + + bb15: { + _1.1 = baml.iter.Done { }; + goto -> bb1; + } } -fn baml.iter.Peekable.Iterable.iter(self: baml.iter.Peekable) -> baml.iter.Iterator { +fn baml.iter.Peekable.peek(self: baml.iter.Peekable) -> baml.iter.Done | T { // Locals: - let _0: baml.iter.Iterator // _0 // return + let _0: baml.iter.Done | T // _0 // return let _1: baml.iter.Peekable // self // param + let _2: bool + let _3: baml.iter.Done | T // v + let _4: baml.iter.Iterator bb0: { - _0 = copy _1; - goto -> bb1; + _2 = copy _1.2; + branch copy _2 -> [bb3, bb1]; } bb1: { - return; + _4 = copy _1.0; + _3 = virtual_call next as baml.iter.Iterator(copy _4) -> [bb2]; } -} -fn baml.iter.Iterable$for$T[].iter(self: T[]) -> baml.iter.Iterator { - // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: T[] // self // param - let _2: type + bb2: { + _1.1 = copy _3; + _1.2 = const true; + _0 = copy _3; + goto -> bb4; + } - bb0: { - _2 = load_type(#0); - _0 = call const fn baml.iter.ArrayIterator.new(copy _1) -> [bb1]; + bb3: { + _0 = copy _1.1; + goto -> bb4; } - bb1: { + bb4: { return; } } -fn baml.iter.Range.Iterable.iter(self: baml.iter.Range) -> baml.iter.Iterator { +fn baml.iter.Peekable.Iterable.iter(self: baml.iter.Peekable) -> baml.iter.Iterator { // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: baml.iter.Range // self // param + let _0: baml.iter.Iterator // _0 // return + let _1: baml.iter.Peekable // self // param bb0: { _0 = copy _1; @@ -4238,25 +4950,41 @@ fn baml.iter.Range.Iterable.iter(self: baml.iter.Range) -> baml.iter.Iterator baml.iter.Iterator { +fn baml.iter.Peekable.Iterator.next(self: baml.iter.Peekable) -> baml.iter.Done | T { // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: baml.iter.Filter // self // param + let _0: baml.iter.Done | T // _0 // return + let _1: baml.iter.Peekable // self // param + let _2: bool + let _3: baml.iter.Done | T // v + let _4: baml.iter.Iterator bb0: { - _0 = copy _1; - goto -> bb1; + _2 = copy _1.2; + branch copy _2 -> [bb2, bb1]; } bb1: { + _4 = copy _1.0; + _0 = virtual_call next as baml.iter.Iterator(copy _4) -> [bb3]; + } + + bb2: { + _3 = copy _1.1; + _1.1 = baml.iter.Done { }; + _1.2 = const false; + _0 = copy _3; + goto -> bb3; + } + + bb3: { return; } } -fn baml.iter.Flatten.Iterable.iter(self: baml.iter.Flatten) -> baml.iter.Iterator { +fn baml.iter.StepBy.Iterable.iter(self: baml.iter.StepBy) -> baml.iter.Iterator { // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: baml.iter.Flatten // self // param + let _0: baml.iter.Iterator // _0 // return + let _1: baml.iter.StepBy // self // param bb0: { _0 = copy _1; @@ -4268,181 +4996,69 @@ fn baml.iter.Flatten.Iterable.iter(self: baml.iter.Flatten) -> baml.iter.Iterato } } -fn baml.iter.Iterator.map(self: baml.iter.Iterator, fn: (Item) -> R throws E2) -> baml.iter.Iterator { +fn baml.iter.StepBy.Iterator.next(self: baml.iter.StepBy) -> baml.iter.Done | T { // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: baml.iter.Iterator // self // param - let _2: (Item) -> R throws E2 // fn // param + let _0: baml.iter.Done | T // _0 // return + let _1: baml.iter.StepBy // self // param + let _2: bool + let _3: baml.iter.Iterator + let _4: int // i + let _5: bool + let _6: int + let _7: int + let _8: int + let _9: baml.iter.Done | T + let _10: baml.iter.Iterator + let _11: bool + let _12: baml.iter.Iterator bb0: { - _0 = baml.iter.Map<#0, #2, #1, #3> { copy _1, copy _2 }; - goto -> bb1; + _2 = copy _1.2; + branch copy _2 -> [bb8, bb1]; } bb1: { - return; - } -} - -fn baml.iter.Range.new(min: int, max: int, step: int) -> baml.iter.Range { - // Locals: - let _0: baml.iter.Range // _0 // return - let _1: int // min // param - let _2: int // max // param - let _3: int // step // param - let _4: bool - - bb0: { - _4 = copy _3 == const ; - branch copy _4 -> [bb1, bb2]; - } - - bb1: { - _3 = const 1_i64; - goto -> bb2; - } - - bb2: { - _0 = baml.iter.Range { copy _1, copy _2, copy _3 }; - goto -> bb3; - } - - bb3: { - return; - } -} - -fn baml.iter.ArrayIterator.new(arr: T[]) -> baml.iter.ArrayIterator { - // Locals: - let _0: baml.iter.ArrayIterator // _0 // return - let _1: T[] // arr // param - - bb0: { - _0 = baml.iter.ArrayIterator<#0> { copy _1, const 0_i64 }; - goto -> bb1; - } - - bb1: { - return; - } -} - -fn baml.iter.Repeat.new(value: T, count: int) -> baml.iter.Repeat { - // Locals: - let _0: baml.iter.Repeat // _0 // return - let _1: T // value // param - let _2: int // count // param - let _3: bool - - bb0: { - _3 = copy _2 == const ; - branch copy _3 -> [bb1, bb2]; - } - - bb1: { - _2 = const -1_i64; - goto -> bb2; - } - - bb2: { - _0 = baml.iter.Repeat<#0> { copy _1, copy _2 }; - goto -> bb3; - } - - bb3: { - return; - } -} - -fn baml.iter.Range.Iterator.next(self: baml.iter.Range) -> int | baml.iter.Done { - // Locals: - let _0: int | baml.iter.Done // _0 // return - let _1: baml.iter.Range // self // param - let _2: bool - let _3: int - let _4: int - let _5: int // cur - let _6: int - - bb0: { - _3 = copy _1.0; - _4 = copy _1.1; - _2 = copy _3 < copy _4; - branch copy _2 -> [bb2, bb1]; - } - - bb1: { - _0 = baml.iter.Done { }; - goto -> bb3; - } - - bb2: { - _5 = copy _1.0; - _6 = copy _1.2; - _1.0 = copy _1.0 + copy _6; - _0 = copy _5; - goto -> bb3; - } - - bb3: { - return; - } -} - -fn baml.iter.Filter.Iterator.next(self: baml.iter.Filter) -> baml.iter.Done | T { - // Locals: - let _0: baml.iter.Done | T // _0 // return - let _1: baml.iter.Filter // self // param - let _2: baml.iter.Done | T - let _3: baml.iter.Iterator - let _4: bool - let _5: T // x - let _6: bool - let _7: (T) -> bool throws E2 - let _8: T - - bb0: { - goto -> bb1; - } - - bb1: { - branch const true -> [bb3, bb2]; + _4 = const 0_i64; + goto -> bb2; } bb2: { - _0 = baml.iter.Done { }; - goto -> bb9; + _6 = copy _4; + _8 = copy _1.1; + _7 = copy _8 - const 1_i64; + _5 = copy _6 < copy _7; + branch copy _5 -> [bb4, bb3]; } bb3: { - _3 = copy _1.0; - _2 = virtual_call next as baml.iter.Iterator(copy _3) -> [bb4]; + _12 = copy _1.0; + _0 = virtual_call next as baml.iter.Iterator(copy _12) -> [bb9]; } bb4: { - _4 = is_type(copy _2, baml.iter.Done); - branch copy _4 -> [bb8, bb5]; + _10 = copy _1.0; + _9 = virtual_call next as baml.iter.Iterator(copy _10) -> [bb5]; } bb5: { - _5 = copy _2; - _7 = copy _1.1; - _8 = copy _5; - _6 = call copy _7(copy _8) -> [bb6]; + _11 = is_type(copy _9, baml.iter.Done); + branch copy _11 -> [bb7, bb6]; } bb6: { - branch copy _6 -> [bb7, bb1]; + _4 = copy _4 + const 1_i64; + goto -> bb2; } bb7: { - _0 = copy _5; + _0 = baml.iter.Done { }; goto -> bb9; } bb8: { - _0 = baml.iter.Done { }; - goto -> bb9; + _1.2 = const false; + _3 = copy _1.0; + _0 = virtual_call next as baml.iter.Iterator(copy _3) -> [bb9]; } bb9: { @@ -4450,100 +5066,19 @@ fn baml.iter.Filter.Iterator.next(self: baml.iter.Filter) -> baml.iter.Done | T } } -fn baml.iter.Flatten.Iterator.next(self: baml.iter.Flatten) -> baml.iter.Done | R { +fn baml.iter.Chain.Iterable.iter(self: baml.iter.Chain) -> baml.iter.Iterator { // Locals: - let _0: baml.iter.Done | R // _0 // return - let _1: baml.iter.Flatten // self // param - let _2: baml.iter.Done | baml.iter.Iterator - let _3: bool - let _4: baml.iter.Iterator // cur - let _5: baml.iter.Done | R - let _6: bool - let _7: R // y - let _8: bool - let _9: baml.iter.Done | I - let _10: baml.iter.Iterator - let _11: bool - let _12: I // x - let _13: baml.iter.Iterator // it + let _0: baml.iter.Iterator // _0 // return + let _1: baml.iter.Chain // self // param bb0: { + _0 = copy _1; goto -> bb1; } bb1: { - branch const true -> [bb3, bb2]; - } - - bb2: { - _0 = baml.iter.Done { }; - goto -> bb14; - } - - bb3: { - _2 = copy _1.1; - _3 = is_type(copy _2, baml.iter.Iterator); - branch copy _3 -> [bb11, bb4]; - } - - bb4: { - _8 = is_type(copy _2, baml.iter.Done); - branch copy _8 -> [bb6, bb5]; - } - - bb5: { - unreachable; - } - - bb6: { - _10 = copy _1.0; - _9 = virtual_call next as baml.iter.Iterator(copy _10) -> [bb7]; - } - - bb7: { - _11 = is_type(copy _9, baml.iter.Done); - branch copy _11 -> [bb10, bb8]; - } - - bb8: { - _12 = copy _9; - _13 = virtual_call iter as baml.iter.Iterable(copy _12) -> [bb9]; - } - - bb9: { - _1.1 = copy _13; - goto -> bb1; - } - - bb10: { - _0 = baml.iter.Done { }; - goto -> bb14; - } - - bb11: { - _4 = copy _2; - _5 = virtual_call next as baml.iter.Iterator(copy _4) -> [bb12]; - } - - bb12: { - _6 = is_type(copy _5, baml.iter.Done); - branch copy _6 -> [bb15, bb13]; - } - - bb13: { - _7 = copy _5; - _0 = copy _7; - goto -> bb14; - } - - bb14: { return; } - - bb15: { - _1.1 = baml.iter.Done { }; - goto -> bb1; - } } fn baml.iter.Chain.Iterator.next(self: baml.iter.Chain) -> baml.iter.Done | T { @@ -4595,608 +5130,595 @@ fn baml.iter.Chain.Iterator.next(self: baml.iter.Chain) -> baml.iter.Done | T { } } -fn baml.iter.ArrayIterator.Iterator.next(self: baml.iter.ArrayIterator) -> baml.iter.Done | T { +fn baml.iter.Iterable$for$T[].iter(self: T[]) -> baml.iter.Iterator { // Locals: - let _0: baml.iter.Done | T // _0 // return - let _1: baml.iter.ArrayIterator // self // param - let _2: bool - let _3: int - let _4: int - let _5: (T[]) -> int throws never - let _6: null | T // item - let _7: (T[], int) -> null | T throws never - let _8: int - let _9: type - let _10: T // value + let _0: baml.iter.Iterator // _0 // return + let _1: T[] // self // param + let _2: type bb0: { - _3 = copy _1.1; - _5 = copy _1.0; - _4 = len(_5); - goto -> bb1; + _2 = load_type(#0); + _0 = call const fn baml.iter.ArrayIterator.new(copy _1) -> [bb1]; } bb1: { - _2 = copy _3 >= copy _4; - branch copy _2 -> [bb4, bb2]; - } - - bb2: { - _7 = copy _1.0; - _8 = copy _1.1; - _9 = load_type(#0); - _6 = call const fn baml.Array.at(copy _7, copy _8) -> [bb3]; - } - - bb3: { - _1.1 = copy _1.1 + const 1_i64; - _10 = copy _6; - _0 = copy _10; - goto -> bb5; - } - - bb4: { - _0 = baml.iter.Done { }; - goto -> bb5; - } - - bb5: { return; } } -fn baml.iter.Map.Iterator.next(self: baml.iter.Map) -> baml.iter.Done | R { +fn baml.iter.Iterable$for$string.iter(self: string) -> baml.iter.Iterator { // Locals: - let _0: baml.iter.Done | R // _0 // return - let _1: baml.iter.Map // self // param - let _2: baml.iter.Done | T - let _3: baml.iter.Iterator - let _4: bool - let _5: T // x - let _6: (T) -> R throws E2 - let _7: T + let _0: baml.iter.Iterator // _0 // return + let _1: string // self // param + let _2: string[] bb0: { - _3 = copy _1.0; - _2 = virtual_call next as baml.iter.Iterator(copy _3) -> [bb1]; + _2 = call const fn baml.String.chars(copy _1) -> [bb1]; } bb1: { - _4 = is_type(copy _2, baml.iter.Done); - branch copy _4 -> [bb3, bb2]; + _0 = virtual_call iter as baml.iter.Iterable(copy _2) -> [bb2]; } bb2: { - _5 = copy _2; - _6 = copy _1.1; - _7 = copy _5; - _0 = call copy _6(copy _7) -> [bb4]; - } - - bb3: { - _0 = baml.iter.Done { }; - goto -> bb4; - } - - bb4: { return; } } -fn baml.iter.FlatMap.Iterator.next(self: baml.iter.FlatMap) -> baml.iter.Done | R { +fn baml.json.parse = builtin(vm) + +fn baml.json.stringify = builtin(vm) + +fn baml.json.stringify_pretty = builtin(vm) + +fn baml.json.to_string = builtin(vm) + +fn baml.json.to_json = builtin(vm) + +fn baml.json.from(value: T) -> int | float | string | bool | null | baml.json.json[] | map { // Locals: - let _0: baml.iter.Done | R // _0 // return - let _1: baml.iter.FlatMap // self // param - let _2: baml.iter.Done | baml.iter.Iterator - let _3: bool - let _4: baml.iter.Iterator // cur - let _5: baml.iter.Done | R - let _6: bool - let _7: R // y - let _8: bool - let _9: baml.iter.Done | T - let _10: baml.iter.Iterator - let _11: bool - let _12: T // x - let _13: baml.iter.Iterator // it - let _14: baml.iter.Iterable - let _15: (T) -> baml.iter.Iterable throws E2 - let _16: T + let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return + let _1: T // value // param + let _2: type bb0: { - goto -> bb1; + _2 = load_type(#0); + _0 = call const fn baml._to_json_shim(copy _1) -> [bb1]; } bb1: { - branch const true -> [bb3, bb2]; + return; } +} - bb2: { - _0 = baml.iter.Done { }; - goto -> bb15; - } +fn baml.json.from_string = builtin(vm) - bb3: { - _2 = copy _1.2; - _3 = is_type(copy _2, baml.iter.Iterator); - branch copy _3 -> [bb12, bb4]; - } +fn baml.json.from_json = builtin(vm) - bb4: { - _8 = is_type(copy _2, baml.iter.Done); - branch copy _8 -> [bb6, bb5]; - } +fn baml.json.to(j: int | float | string | bool | null | baml.json.json[] | map) -> T { + // Locals: + let _0: T // _0 // return + let _1: int | float | string | bool | null | baml.json.json[] | map // j // param + let _2: type - bb5: { - unreachable; + bb0: { + _2 = load_type(#0); + _0 = call const fn baml._from_json_shim(copy _1) -> [bb1]; } - bb6: { - _10 = copy _1.0; - _9 = virtual_call next as baml.iter.Iterator(copy _10) -> [bb7]; + bb1: { + return; } +} - bb7: { - _11 = is_type(copy _9, baml.iter.Done); - branch copy _11 -> [bb11, bb8]; - } +fn baml.json.field = builtin(vm) - bb8: { - _12 = copy _9; - _15 = copy _1.1; - _16 = copy _12; - _14 = call copy _15(copy _16) -> [bb9]; - } +fn baml.json.serialize(v: T) -> string { + // Locals: + let _0: string // _0 // return + let _1: T // v // param + let _2: int | float | string | bool | null | baml.json.json[] | map + let _3: type - bb9: { - _13 = virtual_call iter as baml.iter.Iterable(copy _14) -> [bb10]; + bb0: { + _3 = load_type(#0); + _2 = call const fn baml.json.to_json(copy _1) -> [bb1]; } - bb10: { - _1.2 = copy _13; - goto -> bb1; + bb1: { + _0 = call const fn baml.json.stringify(copy _2) -> [bb2]; } - bb11: { - _0 = baml.iter.Done { }; - goto -> bb15; + bb2: { + return; } +} - bb12: { - _4 = copy _2; - _5 = virtual_call next as baml.iter.Iterator(copy _4) -> [bb13]; - } +fn baml.json.deserialize(s: string) -> T { + // Locals: + let _0: T // _0 // return + let _1: string // s // param + let _2: int | float | string | bool | null | baml.json.json[] | map + let _3: type - bb13: { - _6 = is_type(copy _5, baml.iter.Done); - branch copy _6 -> [bb16, bb14]; + bb0: { + _2 = call const fn baml.json.parse(copy _1) -> [bb1]; } - bb14: { - _7 = copy _5; - _0 = copy _7; - goto -> bb15; + bb1: { + _3 = load_type(#0); + _0 = call const fn baml.json.from_json(copy _2) -> [bb2]; } - bb15: { + bb2: { return; } - - bb16: { - _1.2 = baml.iter.Done { }; - goto -> bb1; - } } -fn baml.iter.StepBy.Iterator.next(self: baml.iter.StepBy) -> baml.iter.Done | T { +fn baml.llm.PlannerState.rr_local_offset(self: baml.llm.PlannerState, client_name: string) -> int { // Locals: - let _0: baml.iter.Done | T // _0 // return - let _1: baml.iter.StepBy // self // param - let _2: bool - let _3: baml.iter.Iterator - let _4: int // i - let _5: bool - let _6: int - let _7: int - let _8: int - let _9: baml.iter.Done | T - let _10: baml.iter.Iterator - let _11: bool - let _12: baml.iter.Iterator + let _0: int // _0 // return + let _1: baml.llm.PlannerState // self // param + let _2: string // client_name // param + let _3: int // offset + let _4: string[] + let _5: baml.iter.Iterator + let _6: unknown + let _7: bool + let _8: string + let _9: string // seen_name + let _10: bool + let _11: string bb0: { - _2 = copy _1.2; - branch copy _2 -> [bb8, bb1]; + _3 = const 0_i64; + _4 = copy _1.0; + _5 = virtual_call iter as baml.iter.Iterable(copy _4) -> [bb1]; } bb1: { - _4 = const 0_i64; - goto -> bb2; + _6 = virtual_call next as baml.iter.Iterator(copy _5) -> [bb2]; } bb2: { - _6 = copy _4; - _8 = copy _1.1; - _7 = copy _8 - const 1_i64; - _5 = copy _6 < copy _7; - branch copy _5 -> [bb4, bb3]; + _7 = is_type(copy _6, baml.iter.Done); + branch copy _7 -> [bb5, bb3]; } bb3: { - _12 = copy _1.0; - _0 = virtual_call next as baml.iter.Iterator(copy _12) -> [bb9]; + _8 = copy _6; + fresh_cell(_9); + _9 = copy _8; + _11 = copy _9; + _10 = copy _11 == copy _2; + branch copy _10 -> [bb4, bb1]; } bb4: { - _10 = copy _1.0; - _9 = virtual_call next as baml.iter.Iterator(copy _10) -> [bb5]; + _3 = copy _3 + const 1_i64; + goto -> bb1; } bb5: { - _11 = is_type(copy _9, baml.iter.Done); - branch copy _11 -> [bb7, bb6]; + _0 = copy _3; + goto -> bb6; } bb6: { - _4 = copy _4 + const 1_i64; - goto -> bb2; + return; } +} - bb7: { - _0 = baml.iter.Done { }; - goto -> bb9; +fn baml.llm.PlannerState.rr_pick_index(self: baml.llm.PlannerState, client_name: string, counter: int, sub_client_count: int) -> int { + // Locals: + let _0: int // _0 // return + let _1: baml.llm.PlannerState // self // param + let _2: string // client_name // param + let _3: int // counter // param + let _4: int // sub_client_count // param + let _5: int // local_offset + let _6: int + let _7: (string[], string) -> int throws never + let _8: type + let _9: int + let _10: int + + bb0: { + _5 = call const fn baml.llm.PlannerState.rr_local_offset(copy _1, copy _2) -> [bb1]; } - bb8: { - _1.2 = const false; - _3 = copy _1.0; - _0 = virtual_call next as baml.iter.Iterator(copy _3) -> [bb9]; + bb1: { + _7 = copy _1.0; + _8 = load_type(string); + _6 = call const fn baml.Array.push(copy _7, copy _2) -> [bb2]; } - bb9: { + bb2: { + _10 = copy _5; + _9 = copy _3 + copy _10; + _0 = copy _9 % copy _4; + goto -> bb3; + } + + bb3: { return; } } -fn baml.iter.Repeat.Iterator.next(self: baml.iter.Repeat) -> baml.iter.Done | T { +fn baml.llm.prompt_template_for(function_name: string, prompt_closure: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never)) -> string { // Locals: - let _0: baml.iter.Done | T // _0 // return - let _1: baml.iter.Repeat // self // param - let _2: bool - let _3: int - let _4: bool - let _5: int + let _0: string // _0 // return + let _1: string // function_name // param + let _2: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never) // prompt_closure // param + let _3: bool bb0: { - _3 = copy _1.1; - _2 = copy _3 < const 0_i64; - branch copy _2 -> [bb4, bb1]; + _3 = copy _2 == const null; + branch copy _3 -> [bb2, bb1]; } bb1: { - _5 = copy _1.1; - _4 = copy _5 > const 0_i64; - branch copy _4 -> [bb3, bb2]; + _0 = const ""; + goto -> bb3; } bb2: { - _0 = baml.iter.Done { }; - goto -> bb5; + _0 = sys_op const fn baml.llm.get_jinja_template(copy _1) -> bb3; } bb3: { - _1.1 = copy _1.1 - const 1_i64; - _0 = copy _1.0; - goto -> bb5; - } - - bb4: { - _0 = copy _1.0; - goto -> bb5; - } - - bb5: { return; } } -fn baml.iter.FilterMap.Iterator.next(self: baml.iter.FilterMap) -> baml.iter.Done | R { +fn baml.llm.render_prompt(client: baml.llm.Client, function_name: string, args: map, prompt_closure: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never)) -> baml.llm.PromptAst { // Locals: - let _0: baml.iter.Done | R // _0 // return - let _1: baml.iter.FilterMap // self // param - let _2: baml.iter.Done | T - let _3: baml.iter.Iterator - let _4: bool - let _5: T // x - let _6: null | R - let _7: (T) -> null | R throws E2 - let _8: T - let _9: bool - let _10: R // y + let _0: baml.llm.PromptAst // _0 // return + let _1: baml.llm.Client // client // param + let _2: string // function_name // param + let _3: map // args // param + let _4: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never) // prompt_closure // param + let _5: bool + let _6: type // return_type + let _7: baml.llm.PrimitiveClient // primitive_client + let _8: string // template + let _9: string + let _10: type bb0: { - goto -> bb1; + _5 = copy _4 == const ; + branch copy _5 -> [bb1, bb2]; } bb1: { - branch const true -> [bb3, bb2]; + _4 = const null; + goto -> bb2; } bb2: { - _0 = baml.iter.Done { }; - goto -> bb9; + _6 = sys_op const fn baml.llm.get_return_type(copy _2) -> bb3; } bb3: { - _3 = copy _1.0; - _2 = virtual_call next as baml.iter.Iterator(copy _3) -> [bb4]; + _7 = call const fn baml.llm.Client.to_primitive_client(copy _1, const true) -> [bb4]; } bb4: { - _4 = is_type(copy _2, baml.iter.Done); - branch copy _4 -> [bb8, bb5]; + _8 = call const fn baml.llm.prompt_template_for(copy _2, copy _4) -> [bb5]; } bb5: { - _5 = copy _2; - _7 = copy _1.1; - _8 = copy _5; - _6 = call copy _7(copy _8) -> [bb6]; - } - - bb6: { - _9 = copy _6 == const null; - branch copy _9 -> [bb1, bb7]; - } - - bb7: { + _9 = copy _8; _10 = copy _6; - _0 = copy _10; - goto -> bb9; - } - - bb8: { - _0 = baml.iter.Done { }; - goto -> bb9; + _0 = call const fn baml.llm.PrimitiveClient.render_specialized_prompt(copy _7, copy _9, copy _3, copy _10, copy _4) -> [bb6]; } - bb9: { + bb6: { return; } } -fn baml.iter.Peekable.Iterator.next(self: baml.iter.Peekable) -> baml.iter.Done | T { +fn baml.llm.build_request(client: baml.llm.Client, function_name: string, args: map, prompt_closure: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never)) -> baml.http.Request { // Locals: - let _0: baml.iter.Done | T // _0 // return - let _1: baml.iter.Peekable // self // param - let _2: bool - let _3: baml.iter.Done | T // v - let _4: baml.iter.Iterator + let _0: baml.http.Request // _0 // return + let _1: baml.llm.Client // client // param + let _2: string // function_name // param + let _3: map // args // param + let _4: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never) // prompt_closure // param + let _5: bool + let _6: type // return_type + let _7: baml.llm.PrimitiveClient // primitive_client + let _8: string // template + let _9: baml.llm.PromptAst // specialized_prompt + let _10: string + let _11: type + let _12: baml.llm.PromptAst + let _13: type bb0: { - _2 = copy _1.2; - branch copy _2 -> [bb2, bb1]; + _5 = copy _4 == const ; + branch copy _5 -> [bb1, bb2]; } bb1: { - _4 = copy _1.0; - _0 = virtual_call next as baml.iter.Iterator(copy _4) -> [bb3]; + _4 = const null; + goto -> bb2; } bb2: { - _3 = copy _1.1; - _1.1 = baml.iter.Done { }; - _1.2 = const false; - _0 = copy _3; - goto -> bb3; + _6 = sys_op const fn baml.llm.get_return_type(copy _2) -> bb3; } bb3: { + _7 = call const fn baml.llm.Client.to_primitive_client(copy _1, const ) -> [bb4]; + } + + bb4: { + _8 = call const fn baml.llm.prompt_template_for(copy _2, copy _4) -> [bb5]; + } + + bb5: { + _10 = copy _8; + _11 = copy _6; + _9 = call const fn baml.llm.PrimitiveClient.render_specialized_prompt(copy _7, copy _10, copy _3, copy _11, copy _4) -> [bb6]; + } + + bb6: { + _12 = copy _9; + _13 = copy _6; + _0 = sys_op const fn baml.llm.PrimitiveClient.build_request(copy _7, copy _12, copy _13) -> bb7; + } + + bb7: { return; } } -fn baml.iter.Peekable.peek(self: baml.iter.Peekable) -> baml.iter.Done | T { +fn baml.llm.build_request_stream(client: baml.llm.Client, function_name: string, args: map, prompt_closure: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never)) -> baml.http.Request { // Locals: - let _0: baml.iter.Done | T // _0 // return - let _1: baml.iter.Peekable // self // param - let _2: bool - let _3: baml.iter.Done | T // v - let _4: baml.iter.Iterator + let _0: baml.http.Request // _0 // return + let _1: baml.llm.Client // client // param + let _2: string // function_name // param + let _3: map // args // param + let _4: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never) // prompt_closure // param + let _5: bool + let _6: type // return_type + let _7: baml.llm.PrimitiveClient // primitive_client + let _8: string // template + let _9: baml.llm.PromptAst // specialized_prompt + let _10: string + let _11: type + let _12: baml.llm.PromptAst + let _13: type bb0: { - _2 = copy _1.2; - branch copy _2 -> [bb3, bb1]; + _5 = copy _4 == const ; + branch copy _5 -> [bb1, bb2]; } bb1: { - _4 = copy _1.0; - _3 = virtual_call next as baml.iter.Iterator(copy _4) -> [bb2]; + _4 = const null; + goto -> bb2; } bb2: { - _1.1 = copy _3; - _1.2 = const true; - _0 = copy _3; - goto -> bb4; + _6 = sys_op const fn baml.llm.get_return_type(copy _2) -> bb3; } bb3: { - _0 = copy _1.1; - goto -> bb4; + _7 = call const fn baml.llm.Client.to_primitive_client(copy _1, const ) -> [bb4]; } bb4: { - return; + _8 = call const fn baml.llm.prompt_template_for(copy _2, copy _4) -> [bb5]; } -} -fn baml.iter.Iterator.peekable(self: baml.iter.Iterator) -> baml.iter.Peekable { - // Locals: - let _0: baml.iter.Peekable // _0 // return - let _1: baml.iter.Iterator // self // param - let _2: baml.iter.Done + bb5: { + _10 = copy _8; + _11 = copy _6; + _9 = call const fn baml.llm.PrimitiveClient.render_specialized_prompt(copy _7, copy _10, copy _3, copy _11, copy _4) -> [bb6]; + } - bb0: { - _2 = baml.iter.Done { }; - _0 = baml.iter.Peekable<#0, #1> { copy _1, copy _2, const false }; - goto -> bb1; + bb6: { + _12 = copy _9; + _13 = copy _6; + _0 = sys_op const fn baml.llm.PrimitiveClient.build_request_stream(copy _7, copy _12, copy _13) -> bb7; } - bb1: { + bb7: { return; } } -fn baml.iter.Iterator.reduce(self: baml.iter.Iterator, fn: (A, Item) -> A throws E2, initial: A) -> A { +fn baml.llm.parse(json: string) -> TFinal { // Locals: - let _0: A // _0 // return - let _1: baml.iter.Iterator // self // param - let _2: (A, Item) -> A throws E2 // fn // param - let _3: A // initial // param - let _4: A // acc - let _5: baml.iter.Done | Item - let _6: bool - let _7: Item // x - let _8: A - let _9: Item + let _0: TFinal // _0 // return + let _1: string // json // param + let _2: baml.llm.StreamCache // cache + let _3: type + let _4: type + let _5: unknown // _ + let _6: baml.llm.StreamCache + let _7: type + let _8: type + let _9: bool + let _10: string + let _11: string // message + let _12: baml.errors.ParseError + let _13: string bb0: { - _4 = copy _3; + _3 = load_type(#0); goto -> bb1; } bb1: { - branch const true -> [bb2, bb5]; + _4 = load_type(#1); + goto -> bb2; } bb2: { - _5 = virtual_call next as baml.iter.Iterator(copy _1) -> [bb3]; + _2 = sys_op const fn baml.llm.StreamCache.new(copy _3, copy _4) -> bb3; } bb3: { - _6 = is_type(copy _5, baml.iter.Done); - branch copy _6 -> [bb5, bb4]; + _6 = copy _2; + _7 = load_type(#0); + _8 = load_type(#1); + _0 = sys_op const fn baml.llm.__sap_parse_final(copy _1, copy _6, copy _7, copy _8) -> bb4 unwind bb5; } bb4: { - _7 = copy _5; - _8 = copy _4; - _9 = copy _7; - _4 = call copy _2(copy _8, copy _9) -> [bb1]; + return; } bb5: { - _0 = copy _4; - goto -> bb6; + _9 = is_type(copy _5, baml.errors.LlmClient); + branch copy _9 -> [bb7, bb6]; } bb6: { - return; + rethrow copy _5; + } + + bb7: { + _10 = copy _5.0; + _11 = copy _10; + _13 = copy _11; + _12 = baml.errors.ParseError { copy _13 }; + throw copy _12; } } -fn baml.iter.Iterator.some(self: baml.iter.Iterator, predicate: (Item) -> bool throws E2) -> bool { +fn baml.llm.call_llm_function(client: baml.llm.Client, function_name: string, args: map, prompt_closure: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never)) -> T { // Locals: - let _0: bool // _0 // return - let _1: baml.iter.Iterator // self // param - let _2: (Item) -> bool throws E2 // predicate // param - let _3: baml.iter.Done | Item - let _4: bool - let _5: Item // x - let _6: bool - let _7: Item + let _0: T // _0 // return + let _1: baml.llm.Client // client // param + let _2: string // function_name // param + let _3: map // args // param + let _4: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never) // prompt_closure // param + let _5: bool + let _6: string // jinja_string + let _7: bool + let _8: baml.llm.ExecutionContext // context + let _9: string + let _10: T // result + let _11: baml.llm.ExecutionContext + let _12: type bb0: { - goto -> bb1; + _5 = copy _4 == const ; + branch copy _5 -> [bb1, bb2]; } bb1: { - branch const true -> [bb2, bb7]; + _4 = const null; + goto -> bb2; } bb2: { - _3 = virtual_call next as baml.iter.Iterator(copy _1) -> [bb3]; + _7 = copy _4 == const null; + branch copy _7 -> [bb4, bb3]; } bb3: { - _4 = is_type(copy _3, baml.iter.Done); - branch copy _4 -> [bb7, bb4]; + _6 = const ""; + goto -> bb5; } bb4: { - _5 = copy _3; - _7 = copy _5; - _6 = call copy _2(copy _7) -> [bb5]; + _6 = sys_op const fn baml.llm.get_jinja_template(copy _2) -> bb5; } bb5: { - branch copy _6 -> [bb6, bb1]; + _9 = copy _6; + _8 = baml.llm.ExecutionContext { copy _9, copy _3, copy _2, copy _4 }; + _11 = copy _8; + _12 = load_type(#0); + _10 = call const fn baml.llm.Client.execute_oneshot(copy _1, copy _11, const 0_i64) -> [bb6]; } bb6: { - _0 = const true; - goto -> bb8; + _0 = copy _10; + goto -> bb7; } bb7: { - _0 = const false; - goto -> bb8; - } - - bb8: { return; } } -fn baml.iter.Iterator.step_by(self: baml.iter.Iterator, n: int) -> baml.iter.Iterator { +fn baml.llm.stream_llm_function(client: baml.llm.Client, function_name: string, args: map, prompt_closure: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never)) -> baml.llm.Stream { // Locals: - let _0: baml.iter.Iterator // _0 // return - let _1: baml.iter.Iterator // self // param - let _2: int // n // param + let _0: baml.llm.Stream // _0 // return + let _1: baml.llm.Client // client // param + let _2: string // function_name // param + let _3: map // args // param + let _4: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never) // prompt_closure // param + let _5: bool + let _6: string // jinja_string + let _7: bool + let _8: baml.llm.ExecutionContext // context + let _9: string + let _10: baml.llm.Stream // result + let _11: baml.llm.ExecutionContext + let _12: type + let _13: type bb0: { - _0 = baml.iter.StepBy<#0, #1> { copy _1, copy _2, const true }; - goto -> bb1; + _5 = copy _4 == const ; + branch copy _5 -> [bb1, bb2]; } bb1: { - return; + _4 = const null; + goto -> bb2; } -} -fn baml.json.deserialize(s: string) -> T { - // Locals: - let _0: T // _0 // return - let _1: string // s // param - let _2: int | float | string | bool | null | baml.json.json[] | map - let _3: type + bb2: { + _7 = copy _4 == const null; + branch copy _7 -> [bb4, bb3]; + } - bb0: { - _2 = call const fn baml.json.parse(copy _1) -> [bb1]; + bb3: { + _6 = const ""; + goto -> bb5; } - bb1: { - _3 = load_type(#0); - _0 = call const fn baml.json.from_json(copy _2) -> [bb2]; + bb4: { + _6 = sys_op const fn baml.llm.get_jinja_template(copy _2) -> bb5; } - bb2: { + bb5: { + _9 = copy _6; + _8 = baml.llm.ExecutionContext { copy _9, copy _3, copy _2, copy _4 }; + _11 = copy _8; + _12 = load_type(#0); + _13 = load_type(#1); + _10 = call const fn baml.llm.Client.execute_stream(copy _1, copy _11, const 0_i64) -> [bb6]; + } + + bb6: { + _0 = copy _10; + goto -> bb7; + } + + bb7: { return; } } -fn baml.json.field = builtin(vm) +fn baml.llm.PromptAst.text = builtin(io) -fn baml.json.from(value: T) -> int | float | string | bool | null | baml.json.json[] | map { +fn baml.llm.PromptAst.messages = builtin(io) + +fn baml.llm.PromptAst.baml.ToString.to_string(self: baml.llm.PromptAst) -> string { // Locals: - let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return - let _1: T // value // param - let _2: type + let _0: string // _0 // return + let _1: baml.llm.PromptAst // self // param bb0: { - _2 = load_type(#0); - _0 = call const fn baml._to_json_shim(copy _1) -> [bb1]; + _0 = sys_op const fn baml.llm.PromptAst.text(copy _1) -> bb1; } bb1: { @@ -5204,162 +5726,133 @@ fn baml.json.from(value: T) -> int | float | string | bool | null | baml.json.js } } -fn baml.json.from_json = builtin(vm) - -fn baml.json.from_string = builtin(vm) - -fn baml.json.parse = builtin(vm) +fn baml.llm.Context.output_format_with = builtin(io) -fn baml.json.serialize(v: T) -> string { +fn baml.llm.RetryPolicy.initial_delay_or_default(self: baml.llm.RetryPolicy) -> float { // Locals: - let _0: string // _0 // return - let _1: T // v // param - let _2: int | float | string | bool | null | baml.json.json[] | map - let _3: type + let _0: float // _0 // return + let _1: baml.llm.RetryPolicy // self // param + let _2: int + let _3: int | null + let _4: bool bb0: { - _3 = load_type(#0); - _2 = call const fn baml.json.to_json(copy _1) -> [bb1]; + _3 = copy _1.1; + _2 = copy _3; + _4 = copy _3 == const null; + branch copy _4 -> [bb1, bb2]; } bb1: { - _0 = call const fn baml.json.stringify(copy _2) -> [bb2]; + _2 = const 200_i64; + goto -> bb2; } bb2: { + _0 = copy _2 + const 0_f64; + goto -> bb3; + } + + bb3: { return; } } -fn baml.json.stringify = builtin(vm) - -fn baml.json.stringify_pretty = builtin(vm) - -fn baml.json.to(j: int | float | string | bool | null | baml.json.json[] | map) -> T { +fn baml.llm.RetryPolicy.multiplier_or_default(self: baml.llm.RetryPolicy) -> float { // Locals: - let _0: T // _0 // return - let _1: int | float | string | bool | null | baml.json.json[] | map // j // param - let _2: type + let _0: float // _0 // return + let _1: baml.llm.RetryPolicy // self // param + let _2: float | null + let _3: bool bb0: { - _2 = load_type(#0); - _0 = call const fn baml._from_json_shim(copy _1) -> [bb1]; + _2 = copy _1.2; + _0 = copy _2; + _3 = copy _2 == const null; + branch copy _3 -> [bb1, bb2]; } bb1: { + _0 = const 1.5_f64; + goto -> bb2; + } + + bb2: { return; } } -fn baml.json.to_json = builtin(vm) +fn baml.llm.RetryPolicy.max_delay_or_default(self: baml.llm.RetryPolicy) -> float { + // Locals: + let _0: float // _0 // return + let _1: baml.llm.RetryPolicy // self // param + let _2: int + let _3: int | null + let _4: bool -fn baml.json.to_string = builtin(vm) - -fn baml.llm.build_request(client: baml.llm.Client, function_name: string, args: map, prompt_closure: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never)) -> baml.http.Request { - // Locals: - let _0: baml.http.Request // _0 // return - let _1: baml.llm.Client // client // param - let _2: string // function_name // param - let _3: map // args // param - let _4: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never) // prompt_closure // param - let _5: bool - let _6: type // return_type - let _7: baml.llm.PrimitiveClient // primitive_client - let _8: string // template - let _9: baml.llm.PromptAst // specialized_prompt - let _10: string - let _11: type - let _12: baml.llm.PromptAst - let _13: type - - bb0: { - _5 = copy _4 == const ; - branch copy _5 -> [bb1, bb2]; - } + bb0: { + _3 = copy _1.3; + _2 = copy _3; + _4 = copy _3 == const null; + branch copy _4 -> [bb1, bb2]; + } bb1: { - _4 = const null; + _2 = const 10000_i64; goto -> bb2; } bb2: { - _6 = sys_op const fn baml.llm.get_return_type(copy _2) -> bb3; + _0 = copy _2 + const 0_f64; + goto -> bb3; } bb3: { - _7 = call const fn baml.llm.Client.to_primitive_client(copy _1, const ) -> [bb4]; - } - - bb4: { - _8 = call const fn baml.llm.prompt_template_for(copy _2, copy _4) -> [bb5]; - } - - bb5: { - _10 = copy _8; - _11 = copy _6; - _9 = call const fn baml.llm.PrimitiveClient.render_specialized_prompt(copy _7, copy _10, copy _3, copy _11, copy _4) -> [bb6]; - } - - bb6: { - _12 = copy _9; - _13 = copy _6; - _0 = sys_op const fn baml.llm.PrimitiveClient.build_request(copy _7, copy _12, copy _13) -> bb7; - } - - bb7: { return; } } -fn baml.llm.build_request_stream(client: baml.llm.Client, function_name: string, args: map, prompt_closure: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never)) -> baml.http.Request { +fn baml.llm.Client.to_primitive_client(self: baml.llm.Client, lenient: bool) -> baml.llm.PrimitiveClient { // Locals: - let _0: baml.http.Request // _0 // return - let _1: baml.llm.Client // client // param - let _2: string // function_name // param - let _3: map // args // param - let _4: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never) // prompt_closure // param - let _5: bool - let _6: type // return_type - let _7: baml.llm.PrimitiveClient // primitive_client - let _8: string // template - let _9: baml.llm.PromptAst // specialized_prompt - let _10: string - let _11: type - let _12: baml.llm.PromptAst - let _13: type + let _0: baml.llm.PrimitiveClient // _0 // return + let _1: baml.llm.Client // self // param + let _2: bool // lenient // param + let _3: bool + let _4: bool + let _5: (baml.String, string) -> bool throws never + let _6: string + let _7: (bool) -> baml.llm.PrimitiveClient throws baml.errors.InvalidArgument bb0: { - _5 = copy _4 == const ; - branch copy _5 -> [bb1, bb2]; + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } bb1: { - _4 = const null; + _2 = const false; goto -> bb2; } bb2: { - _6 = sys_op const fn baml.llm.get_return_type(copy _2) -> bb3; + _5 = copy _1.0; + _4 = call const fn baml.String.includes(copy _5, const "/") -> [bb3]; } bb3: { - _7 = call const fn baml.llm.Client.to_primitive_client(copy _1, const ) -> [bb4]; + branch copy _4 -> [bb6, bb4]; } bb4: { - _8 = call const fn baml.llm.prompt_template_for(copy _2, copy _4) -> [bb5]; + _7 = sys_op const fn baml.llm.Client.get_constructor(copy _1) -> bb5; } bb5: { - _10 = copy _8; - _11 = copy _6; - _9 = call const fn baml.llm.PrimitiveClient.render_specialized_prompt(copy _7, copy _10, copy _3, copy _11, copy _4) -> [bb6]; + _0 = call copy _7(copy _2) -> [bb7]; } bb6: { - _12 = copy _9; - _13 = copy _6; - _0 = sys_op const fn baml.llm.PrimitiveClient.build_request_stream(copy _7, copy _12, copy _13) -> bb7; + _6 = copy _1.0; + _0 = sys_op const fn baml.llm.from_shorthand(copy _6) -> bb7; } bb7: { @@ -5367,1073 +5860,487 @@ fn baml.llm.build_request_stream(client: baml.llm.Client, function_name: string, } } -fn baml.llm.call_llm_function(client: baml.llm.Client, function_name: string, args: map, prompt_closure: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never)) -> T { +fn baml.llm.Client.get_constructor = builtin(io) + +fn baml.llm.Client.build_attempt(self: baml.llm.Client) -> baml.llm.OrchestrationStep[] { // Locals: - let _0: T // _0 // return - let _1: baml.llm.Client // client // param - let _2: string // function_name // param - let _3: map // args // param - let _4: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never) // prompt_closure // param - let _5: bool - let _6: string // jinja_string - let _7: bool - let _8: baml.llm.ExecutionContext // context - let _9: string - let _10: T // result - let _11: baml.llm.ExecutionContext - let _12: type + let _0: baml.llm.OrchestrationStep[] // _0 // return + let _1: baml.llm.Client // self // param + let _2: baml.llm.PlannerState // planner_state + let _3: string[] + let _4: baml.llm.PlannerState bb0: { - _5 = copy _4 == const ; - branch copy _5 -> [bb1, bb2]; + _3 = []: string[]; + _2 = baml.llm.PlannerState { copy _3 }; + _4 = copy _2; + _0 = call const fn baml.llm.Client.build_attempt_with_state(copy _1, copy _4) -> [bb1]; } bb1: { - _4 = const null; - goto -> bb2; + return; + } +} + +fn baml.llm.Client.build_attempt_with_state(self: baml.llm.Client, planner_state: baml.llm.PlannerState) -> baml.llm.OrchestrationStep[] { + // Locals: + let _0: baml.llm.OrchestrationStep[] // _0 // return + let _1: baml.llm.Client // self // param + let _2: baml.llm.PlannerState // planner_state // param + let _3: baml.llm.ClientType + let _4: int + let _5: baml.llm.PrimitiveClient // primitive + let _6: baml.llm.OrchestrationStep + let _7: baml.llm.PrimitiveClient + let _8: baml.llm.OrchestrationStep[] // steps + let _9: baml.llm.Client[] + let _10: baml.iter.Iterator + let _11: unknown + let _12: bool + let _13: baml.llm.Client + let _14: baml.llm.Client // sub + let _15: baml.llm.OrchestrationStep[] + let _16: baml.iter.Iterator + let _17: unknown + let _18: bool + let _19: baml.llm.OrchestrationStep + let _20: baml.llm.OrchestrationStep // step + let _21: void + let _22: baml.llm.OrchestrationStep + let _23: bool + let _24: int + let _25: (baml.llm.Client[]) -> int throws never + let _26: int // idx + let _27: string + let _28: int + let _29: int + let _30: (baml.llm.Client[]) -> int throws never + let _31: baml.llm.Client + let _32: baml.llm.Client[] + let _33: int + + bb0: { + _3 = copy _1.1; + _4 = discriminant(_3); + switch copy _4 [ClientType.Primitive: bb17, ClientType.Fallback: bb8, ClientType.RoundRobin: bb2, otherwise: bb1] (exhaustive); + } + + bb1: { + unreachable; } bb2: { - _7 = copy _4 == const null; - branch copy _7 -> [bb4, bb3]; + _25 = copy _1.2; + _24 = len(_25); + goto -> bb3; } bb3: { - _6 = const ""; - goto -> bb5; + _23 = copy _24 == const 0_i64; + branch copy _23 -> [bb7, bb4]; } bb4: { - _6 = sys_op const fn baml.llm.get_jinja_template(copy _2) -> bb5; + _27 = copy _1.0; + _28 = copy _1.4; + _30 = copy _1.2; + _29 = len(_30); + goto -> bb5; } bb5: { - _9 = copy _6; - _8 = baml.llm.ExecutionContext { copy _9, copy _3, copy _2, copy _4 }; - _11 = copy _8; - _12 = load_type(#0); - _10 = call const fn baml.llm.Client.execute_oneshot(copy _1, copy _11, const 0_i64) -> [bb6]; + _26 = call const fn baml.llm.PlannerState.rr_pick_index(copy _2, copy _27, copy _28, copy _29) -> [bb6]; } bb6: { - _0 = copy _10; - goto -> bb7; + _32 = copy _1.2; + _33 = copy _26; + _31 = copy _32[_33]; + _0 = call const fn baml.llm.Client.build_plan_with_state(copy _31, copy _2) -> [bb19]; } bb7: { - return; + _0 = []: baml.llm.OrchestrationStep[]; + goto -> bb19; } -} - -fn baml.llm.parse(json: string) -> TFinal { - // Locals: - let _0: TFinal // _0 // return - let _1: string // json // param - let _2: baml.llm.StreamCache // cache - let _3: type - let _4: type - let _5: unknown // _ - let _6: baml.llm.StreamCache - let _7: type - let _8: type - let _9: bool - let _10: string - let _11: string // message - let _12: baml.errors.ParseError - let _13: string - bb0: { - _3 = load_type(#0); - goto -> bb1; + bb8: { + _8 = []: baml.llm.OrchestrationStep[]; + _9 = copy _1.2; + _10 = virtual_call iter as baml.iter.Iterable(copy _9) -> [bb9]; } - bb1: { - _4 = load_type(#1); - goto -> bb2; + bb9: { + _11 = virtual_call next as baml.iter.Iterator(copy _10) -> [bb10]; } - bb2: { - _2 = sys_op const fn baml.llm.StreamCache.new(copy _3, copy _4) -> bb3; + bb10: { + _12 = is_type(copy _11, baml.iter.Done); + branch copy _12 -> [bb16, bb11]; } - bb3: { - _6 = copy _2; - _7 = load_type(#0); - _8 = load_type(#1); - _0 = sys_op const fn baml.llm.__sap_parse_final(copy _1, copy _6, copy _7, copy _8) -> bb4 unwind bb5; + bb11: { + _13 = copy _11; + fresh_cell(_14); + _14 = copy _13; + _15 = call const fn baml.llm.Client.build_plan_with_state(copy _14, copy _2) -> [bb12]; } - bb4: { - return; + bb12: { + _16 = virtual_call iter as baml.iter.Iterable(copy _15) -> [bb13]; } - bb5: { - _9 = is_type(copy _5, baml.errors.LlmClient); - branch copy _9 -> [bb7, bb6]; - } - - bb6: { - rethrow copy _5; - } - - bb7: { - _10 = copy _5.0; - _11 = copy _10; - _13 = copy _11; - _12 = baml.errors.ParseError { copy _13 }; - throw copy _12; - } -} - -fn baml.llm.prompt_template_for(function_name: string, prompt_closure: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never)) -> string { - // Locals: - let _0: string // _0 // return - let _1: string // function_name // param - let _2: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never) // prompt_closure // param - let _3: bool - - bb0: { - _3 = copy _2 == const null; - branch copy _3 -> [bb2, bb1]; - } - - bb1: { - _0 = const ""; - goto -> bb3; - } - - bb2: { - _0 = sys_op const fn baml.llm.get_jinja_template(copy _1) -> bb3; - } - - bb3: { - return; - } -} - -fn baml.llm.render_prompt(client: baml.llm.Client, function_name: string, args: map, prompt_closure: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never)) -> baml.llm.PromptAst { - // Locals: - let _0: baml.llm.PromptAst // _0 // return - let _1: baml.llm.Client // client // param - let _2: string // function_name // param - let _3: map // args // param - let _4: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never) // prompt_closure // param - let _5: bool - let _6: type // return_type - let _7: baml.llm.PrimitiveClient // primitive_client - let _8: string // template - let _9: string - let _10: type - - bb0: { - _5 = copy _4 == const ; - branch copy _5 -> [bb1, bb2]; - } - - bb1: { - _4 = const null; - goto -> bb2; - } - - bb2: { - _6 = sys_op const fn baml.llm.get_return_type(copy _2) -> bb3; - } - - bb3: { - _7 = call const fn baml.llm.Client.to_primitive_client(copy _1, const true) -> [bb4]; - } - - bb4: { - _8 = call const fn baml.llm.prompt_template_for(copy _2, copy _4) -> [bb5]; - } - - bb5: { - _9 = copy _8; - _10 = copy _6; - _0 = call const fn baml.llm.PrimitiveClient.render_specialized_prompt(copy _7, copy _9, copy _3, copy _10, copy _4) -> [bb6]; - } - - bb6: { - return; - } -} - -fn baml.llm.PlannerState.rr_local_offset(self: baml.llm.PlannerState, client_name: string) -> int { - // Locals: - let _0: int // _0 // return - let _1: baml.llm.PlannerState // self // param - let _2: string // client_name // param - let _3: int // offset - let _4: string[] - let _5: baml.iter.Iterator - let _6: unknown - let _7: bool - let _8: string - let _9: string // seen_name - let _10: bool - let _11: string - - bb0: { - _3 = const 0_i64; - _4 = copy _1.0; - _5 = virtual_call iter as baml.iter.Iterable(copy _4) -> [bb1]; - } - - bb1: { - _6 = virtual_call next as baml.iter.Iterator(copy _5) -> [bb2]; - } - - bb2: { - _7 = is_type(copy _6, baml.iter.Done); - branch copy _7 -> [bb5, bb3]; - } - - bb3: { - _8 = copy _6; - fresh_cell(_9); - _9 = copy _8; - _11 = copy _9; - _10 = copy _11 == copy _2; - branch copy _10 -> [bb4, bb1]; - } - - bb4: { - _3 = copy _3 + const 1_i64; - goto -> bb1; - } - - bb5: { - _0 = copy _3; - goto -> bb6; - } - - bb6: { - return; - } -} - -fn baml.llm.PlannerState.rr_pick_index(self: baml.llm.PlannerState, client_name: string, counter: int, sub_client_count: int) -> int { - // Locals: - let _0: int // _0 // return - let _1: baml.llm.PlannerState // self // param - let _2: string // client_name // param - let _3: int // counter // param - let _4: int // sub_client_count // param - let _5: int // local_offset - let _6: int - let _7: (string[], string) -> int throws never - let _8: type - let _9: int - let _10: int - - bb0: { - _5 = call const fn baml.llm.PlannerState.rr_local_offset(copy _1, copy _2) -> [bb1]; - } - - bb1: { - _7 = copy _1.0; - _8 = load_type(string); - _6 = call const fn baml.Array.push(copy _7, copy _2) -> [bb2]; - } - - bb2: { - _10 = copy _5; - _9 = copy _3 + copy _10; - _0 = copy _9 % copy _4; - goto -> bb3; - } - - bb3: { - return; - } -} - -fn baml.llm.stream_llm_function(client: baml.llm.Client, function_name: string, args: map, prompt_closure: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never)) -> baml.llm.Stream { - // Locals: - let _0: baml.llm.Stream // _0 // return - let _1: baml.llm.Client // client // param - let _2: string // function_name // param - let _3: map // args // param - let _4: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never) // prompt_closure // param - let _5: bool - let _6: string // jinja_string - let _7: bool - let _8: baml.llm.ExecutionContext // context - let _9: string - let _10: baml.llm.Stream // result - let _11: baml.llm.ExecutionContext - let _12: type - let _13: type - - bb0: { - _5 = copy _4 == const ; - branch copy _5 -> [bb1, bb2]; - } - - bb1: { - _4 = const null; - goto -> bb2; - } - - bb2: { - _7 = copy _4 == const null; - branch copy _7 -> [bb4, bb3]; - } - - bb3: { - _6 = const ""; - goto -> bb5; - } - - bb4: { - _6 = sys_op const fn baml.llm.get_jinja_template(copy _2) -> bb5; - } - - bb5: { - _9 = copy _6; - _8 = baml.llm.ExecutionContext { copy _9, copy _3, copy _2, copy _4 }; - _11 = copy _8; - _12 = load_type(#0); - _13 = load_type(#1); - _10 = call const fn baml.llm.Client.execute_stream(copy _1, copy _11, const 0_i64) -> [bb6]; - } - - bb6: { - _0 = copy _10; - goto -> bb7; - } - - bb7: { - return; - } -} - -fn baml.llm.Client.__make_stream(self: baml.llm.Client, sse: baml.http.SseStream) -> baml.llm.Stream { - // Locals: - let _0: baml.llm.Stream // _0 // return - let _1: baml.llm.Client // self // param - let _2: baml.http.SseStream // sse // param - let _3: baml.llm.PrimitiveClient // primitive - let _4: baml.llm.StreamAccumulator // acc - let _5: baml.llm.StreamCache // cache - let _6: type - let _7: type - let _8: baml.llm.PrimitiveClient - let _9: baml.llm.StreamAccumulator - let _10: baml.llm.StreamCache - - bb0: { - _3 = call const fn baml.llm.Client.to_primitive_client(copy _1, const ) -> [bb1]; - } - - bb1: { - _4 = sys_op const fn baml.llm.PrimitiveClient.new_stream_accumulator(copy _3) -> bb2; - } - - bb2: { - _6 = load_type(#0); - goto -> bb3; - } - - bb3: { - _7 = load_type(#1); - goto -> bb4; - } - - bb4: { - _5 = sys_op const fn baml.llm.StreamCache.new(copy _6, copy _7) -> bb5; - } - - bb5: { - _8 = copy _3; - _9 = copy _4; - _10 = copy _5; - _0 = baml.llm.Stream<#0, #1> { copy _8, copy _9, copy _2, copy _10 }; - goto -> bb6; - } - - bb6: { - return; - } -} - -fn baml.llm.__sap_parse_final = builtin(io) - -fn baml.llm.__sap_parse_partial = builtin(io) - -fn baml.llm.StreamAccumulator.add_events = builtin(io) - -fn baml.llm.assemble_prompt_ast = builtin(io) - -fn baml.llm.Client.build_attempt(self: baml.llm.Client) -> baml.llm.OrchestrationStep[] { - // Locals: - let _0: baml.llm.OrchestrationStep[] // _0 // return - let _1: baml.llm.Client // self // param - let _2: baml.llm.PlannerState // planner_state - let _3: string[] - let _4: baml.llm.PlannerState - - bb0: { - _3 = []: string[]; - _2 = baml.llm.PlannerState { copy _3 }; - _4 = copy _2; - _0 = call const fn baml.llm.Client.build_attempt_with_state(copy _1, copy _4) -> [bb1]; - } - - bb1: { - return; - } -} - -fn baml.llm.Client.build_attempt_with_state(self: baml.llm.Client, planner_state: baml.llm.PlannerState) -> baml.llm.OrchestrationStep[] { - // Locals: - let _0: baml.llm.OrchestrationStep[] // _0 // return - let _1: baml.llm.Client // self // param - let _2: baml.llm.PlannerState // planner_state // param - let _3: baml.llm.ClientType - let _4: int - let _5: baml.llm.PrimitiveClient // primitive - let _6: baml.llm.OrchestrationStep - let _7: baml.llm.PrimitiveClient - let _8: baml.llm.OrchestrationStep[] // steps - let _9: baml.llm.Client[] - let _10: baml.iter.Iterator - let _11: unknown - let _12: bool - let _13: baml.llm.Client - let _14: baml.llm.Client // sub - let _15: baml.llm.OrchestrationStep[] - let _16: baml.iter.Iterator - let _17: unknown - let _18: bool - let _19: baml.llm.OrchestrationStep - let _20: baml.llm.OrchestrationStep // step - let _21: void - let _22: baml.llm.OrchestrationStep - let _23: bool - let _24: int - let _25: (baml.llm.Client[]) -> int throws never - let _26: int // idx - let _27: string - let _28: int - let _29: int - let _30: (baml.llm.Client[]) -> int throws never - let _31: baml.llm.Client - let _32: baml.llm.Client[] - let _33: int - - bb0: { - _3 = copy _1.1; - _4 = discriminant(_3); - switch copy _4 [ClientType.Primitive: bb17, ClientType.Fallback: bb8, ClientType.RoundRobin: bb2, otherwise: bb1] (exhaustive); - } - - bb1: { - unreachable; - } - - bb2: { - _25 = copy _1.2; - _24 = len(_25); - goto -> bb3; - } - - bb3: { - _23 = copy _24 == const 0_i64; - branch copy _23 -> [bb7, bb4]; - } - - bb4: { - _27 = copy _1.0; - _28 = copy _1.4; - _30 = copy _1.2; - _29 = len(_30); - goto -> bb5; - } - - bb5: { - _26 = call const fn baml.llm.PlannerState.rr_pick_index(copy _2, copy _27, copy _28, copy _29) -> [bb6]; - } - - bb6: { - _32 = copy _1.2; - _33 = copy _26; - _31 = copy _32[_33]; - _0 = call const fn baml.llm.Client.build_plan_with_state(copy _31, copy _2) -> [bb19]; - } - - bb7: { - _0 = []: baml.llm.OrchestrationStep[]; - goto -> bb19; - } - - bb8: { - _8 = []: baml.llm.OrchestrationStep[]; - _9 = copy _1.2; - _10 = virtual_call iter as baml.iter.Iterable(copy _9) -> [bb9]; - } - - bb9: { - _11 = virtual_call next as baml.iter.Iterator(copy _10) -> [bb10]; - } - - bb10: { - _12 = is_type(copy _11, baml.iter.Done); - branch copy _12 -> [bb16, bb11]; - } - - bb11: { - _13 = copy _11; - fresh_cell(_14); - _14 = copy _13; - _15 = call const fn baml.llm.Client.build_plan_with_state(copy _14, copy _2) -> [bb12]; - } - - bb12: { - _16 = virtual_call iter as baml.iter.Iterable(copy _15) -> [bb13]; - } - - bb13: { - _17 = virtual_call next as baml.iter.Iterator(copy _16) -> [bb14]; - } - - bb14: { - _18 = is_type(copy _17, baml.iter.Done); - branch copy _18 -> [bb9, bb15]; - } - - bb15: { - _19 = copy _17; - fresh_cell(_20); - _20 = copy _19; - _22 = copy _20; - _21 = call const fn baml.Array.push(copy _8, copy _22) -> [bb13]; - } - - bb16: { - _0 = copy _8; - goto -> bb19; - } - - bb17: { - _5 = call const fn baml.llm.Client.to_primitive_client(copy _1, const ) -> [bb18]; - } - - bb18: { - _7 = copy _5; - _6 = baml.llm.OrchestrationStep { copy _7, const 0_i64 }; - _0 = [copy _6]: baml.llm.OrchestrationStep[]; - goto -> bb19; - } - - bb19: { - return; - } -} - -fn baml.llm.build_output_format = builtin(io) - -fn baml.llm.Client.build_plan(self: baml.llm.Client) -> baml.llm.OrchestrationStep[] { - // Locals: - let _0: baml.llm.OrchestrationStep[] // _0 // return - let _1: baml.llm.Client // self // param - let _2: baml.llm.PlannerState // planner_state - let _3: string[] - let _4: baml.llm.PlannerState - - bb0: { - _3 = []: string[]; - _2 = baml.llm.PlannerState { copy _3 }; - _4 = copy _2; - _0 = call const fn baml.llm.Client.build_plan_with_state(copy _1, copy _4) -> [bb1]; - } - - bb1: { - return; - } -} - -fn baml.llm.Client.build_plan_with_state(self: baml.llm.Client, planner_state: baml.llm.PlannerState) -> baml.llm.OrchestrationStep[] { - // Locals: - let _0: baml.llm.OrchestrationStep[] // _0 // return - let _1: baml.llm.Client // self // param - let _2: baml.llm.PlannerState // planner_state // param - let _3: null | baml.llm.RetryPolicy - let _4: bool - let _5: baml.llm.RetryPolicy // r - let _6: baml.llm.OrchestrationStep[] // result - let _7: float // current_delay - let _8: int // attempt - let _9: bool - let _10: int - let _11: int - let _12: int // delay - let _13: bool - let _14: int - let _15: float - let _16: float // next - let _17: float - let _18: float - let _19: bool - let _20: float - let _21: float - let _22: baml.llm.OrchestrationStep[] // inner - let _23: baml.llm.OrchestrationStep[] - let _24: baml.iter.Iterator - let _25: unknown - let _26: bool - let _27: baml.llm.OrchestrationStep - let _28: baml.llm.OrchestrationStep // step - let _29: int - let _30: baml.llm.OrchestrationStep - let _31: baml.llm.PrimitiveClient - let _32: int - - bb0: { - _3 = copy _1.3; - _4 = is_type(copy _3, baml.llm.RetryPolicy); - branch copy _4 -> [bb2, bb1]; - } - - bb1: { - _0 = call const fn baml.llm.Client.build_attempt_with_state(copy _1, copy _2) -> [bb6]; - } - - bb2: { - _5 = copy _3; - _6 = []: baml.llm.OrchestrationStep[]; - _7 = call const fn baml.llm.RetryPolicy.initial_delay_or_default(copy _5) -> [bb3]; - } - - bb3: { - _8 = const 0_i64; - goto -> bb4; - } - - bb4: { - _10 = copy _8; - _11 = copy _5.0; - _9 = copy _10 <= copy _11; - branch copy _9 -> [bb7, bb5]; - } - - bb5: { - _0 = copy _6; - goto -> bb6; - } - - bb6: { - return; - } - - bb7: { - _12 = const 0_i64; - _14 = copy _8; - _13 = copy _14 > const 0_i64; - branch copy _13 -> [bb8, bb14]; - } - - bb8: { - _15 = copy _7; - _12 = call const fn baml._trunc_to_int(copy _15) -> [bb9]; - } - - bb9: { - _17 = copy _7; - _18 = call const fn baml.llm.RetryPolicy.multiplier_or_default(copy _5) -> [bb10]; - } - - bb10: { - _16 = copy _17 * copy _18; - _20 = copy _16; - _21 = call const fn baml.llm.RetryPolicy.max_delay_or_default(copy _5) -> [bb11]; - } - - bb11: { - _19 = copy _20 > copy _21; - branch copy _19 -> [bb13, bb12]; - } - - bb12: { - _7 = copy _16; - goto -> bb14; - } - - bb13: { - _7 = call const fn baml.llm.RetryPolicy.max_delay_or_default(copy _5) -> [bb14]; + bb13: { + _17 = virtual_call next as baml.iter.Iterator(copy _16) -> [bb14]; } bb14: { - _22 = call const fn baml.llm.Client.build_attempt_with_state(copy _1, copy _2) -> [bb15]; - } - - bb15: { - _23 = copy _22; - _24 = virtual_call iter as baml.iter.Iterable(copy _23) -> [bb16]; - } - - bb16: { - _25 = virtual_call next as baml.iter.Iterator(copy _24) -> [bb17]; - } - - bb17: { - _26 = is_type(copy _25, baml.iter.Done); - branch copy _26 -> [bb19, bb18]; - } - - bb18: { - _27 = copy _25; - fresh_cell(_28); - _28 = copy _27; - _31 = copy _28.0; - _32 = copy _12; - _30 = baml.llm.OrchestrationStep { copy _31, copy _32 }; - _29 = call const fn baml.Array.push(copy _6, copy _30) -> [bb16]; - } - - bb19: { - _8 = copy _8 + const 1_i64; - goto -> bb4; - } -} - -fn baml.llm.build_prompt_context(primitive: baml.llm.PrimitiveClient, return_type: type) -> baml.llm.Context { - // Locals: - let _0: baml.llm.Context // _0 // return - let _1: baml.llm.PrimitiveClient // primitive // param - let _2: type // return_type // param - let _3: baml.llm.ContextClient - let _4: string - let _5: string - let _6: string - let _7: string | null - let _8: bool - let _9: string[] - let _10: null | string[] - let _11: bool - let _12: map - let _13: string - let _14: baml.llm.OutputFormat - - bb0: { - _4 = copy _1.0; - _5 = copy _1.1; - _7 = copy _1.2.6; - _6 = copy _7; - _8 = copy _7 == const null; - branch copy _8 -> [bb1, bb2]; - } - - bb1: { - _6 = const "system"; - goto -> bb2; - } - - bb2: { - _10 = copy _1.2.7; - _9 = copy _10; - _11 = copy _10 == const null; - branch copy _11 -> [bb3, bb4]; - } - - bb3: { - _9 = []: string[]; - goto -> bb4; - } - - bb4: { - _3 = baml.llm.ContextClient { copy _4, copy _5, copy _6, copy _9 }; - _12 = { }: map; - _13 = sys_op const fn baml.llm.render_output_format(copy _2) -> bb5; - } - - bb5: { - _14 = sys_op const fn baml.llm.build_output_format(copy _2) -> bb6; - } - - bb6: { - _0 = baml.llm.Context { copy _3, copy _12, copy _13, copy _14 }; - goto -> bb7; - } - - bb7: { - return; - } -} - -fn baml.llm.PrimitiveClient.build_request = builtin(io) - -fn baml.llm.PrimitiveClient.build_request_stream = builtin(io) - -fn baml.llm.StreamAccumulator.content = builtin(io) - -fn baml.llm.Client.execute_once_oneshot(self: baml.llm.Client, context: baml.llm.ExecutionContext, active_delay_ms: int) -> T { - // Locals: - let _0: T // _0 // return - let _1: baml.llm.Client // self // param - let _2: baml.llm.ExecutionContext // context // param - let _3: int // active_delay_ms // param - let _4: baml.llm.ClientType - let _5: int - let _6: baml.llm.PrimitiveClient // primitive - let _7: type // return_type - let _8: baml.llm.PromptAst // specialized - let _9: string - let _10: map - let _11: type - let _12: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never) - let _13: baml.http.Request // http_request - let _14: baml.llm.PromptAst - let _15: type - let _16: baml.http.Response // http_response - let _17: baml.http.Request - let _18: bool - let _19: string // body - let _20: T // result - let _21: unknown // e - let _22: string - let _23: type - let _24: void - let _25: bool - let _26: baml.time.Duration - let _27: bigint - let _28: string // error_body - let _29: unknown // e - let _30: void - let _31: bool - let _32: baml.time.Duration - let _33: bigint - let _34: baml.errors.DevOther - let _35: string - let _36: string - let _37: baml.llm.Client[] - let _38: baml.iter.Iterator - let _39: unknown - let _40: bool - let _41: baml.llm.Client - let _42: baml.llm.Client // sub - let _43: T // result2 - let _44: unknown // e - let _45: type - let _46: baml.errors.DevOther - let _47: bool - let _48: int - let _49: (baml.llm.Client[]) -> int throws never - let _50: baml.errors.DevOther - let _51: int // idx - let _52: int - let _53: int - let _54: (baml.llm.Client[]) -> int throws never - let _55: T // result3 - let _56: baml.llm.Client - let _57: baml.llm.Client[] - let _58: int - let _59: type + _18 = is_type(copy _17, baml.iter.Done); + branch copy _18 -> [bb9, bb15]; + } + + bb15: { + _19 = copy _17; + fresh_cell(_20); + _20 = copy _19; + _22 = copy _20; + _21 = call const fn baml.Array.push(copy _8, copy _22) -> [bb13]; + } + + bb16: { + _0 = copy _8; + goto -> bb19; + } + + bb17: { + _5 = call const fn baml.llm.Client.to_primitive_client(copy _1, const ) -> [bb18]; + } + + bb18: { + _7 = copy _5; + _6 = baml.llm.OrchestrationStep { copy _7, const 0_i64 }; + _0 = [copy _6]: baml.llm.OrchestrationStep[]; + goto -> bb19; + } + + bb19: { + return; + } +} + +fn baml.llm.Client.build_plan(self: baml.llm.Client) -> baml.llm.OrchestrationStep[] { + // Locals: + let _0: baml.llm.OrchestrationStep[] // _0 // return + let _1: baml.llm.Client // self // param + let _2: baml.llm.PlannerState // planner_state + let _3: string[] + let _4: baml.llm.PlannerState bb0: { - _4 = copy _1.1; - _5 = discriminant(_4); - switch copy _5 [ClientType.Primitive: bb9, ClientType.Fallback: bb8, ClientType.RoundRobin: bb2, otherwise: bb1] (exhaustive); + _3 = []: string[]; + _2 = baml.llm.PlannerState { copy _3 }; + _4 = copy _2; + _0 = call const fn baml.llm.Client.build_plan_with_state(copy _1, copy _4) -> [bb1]; } bb1: { - unreachable; + return; + } +} + +fn baml.llm.Client.build_plan_with_state(self: baml.llm.Client, planner_state: baml.llm.PlannerState) -> baml.llm.OrchestrationStep[] { + // Locals: + let _0: baml.llm.OrchestrationStep[] // _0 // return + let _1: baml.llm.Client // self // param + let _2: baml.llm.PlannerState // planner_state // param + let _3: null | baml.llm.RetryPolicy + let _4: bool + let _5: baml.llm.RetryPolicy // r + let _6: baml.llm.OrchestrationStep[] // result + let _7: float // current_delay + let _8: int // attempt + let _9: bool + let _10: int + let _11: int + let _12: int // delay + let _13: bool + let _14: int + let _15: float + let _16: float // next + let _17: float + let _18: float + let _19: bool + let _20: float + let _21: float + let _22: baml.llm.OrchestrationStep[] // inner + let _23: baml.llm.OrchestrationStep[] + let _24: baml.iter.Iterator + let _25: unknown + let _26: bool + let _27: baml.llm.OrchestrationStep + let _28: baml.llm.OrchestrationStep // step + let _29: int + let _30: baml.llm.OrchestrationStep + let _31: baml.llm.PrimitiveClient + let _32: int + + bb0: { + _3 = copy _1.3; + _4 = is_type(copy _3, baml.llm.RetryPolicy); + branch copy _4 -> [bb2, bb1]; + } + + bb1: { + _0 = call const fn baml.llm.Client.build_attempt_with_state(copy _1, copy _2) -> [bb6]; } bb2: { - _49 = copy _1.2; - _48 = len(_49); - goto -> bb3; + _5 = copy _3; + _6 = []: baml.llm.OrchestrationStep[]; + _7 = call const fn baml.llm.RetryPolicy.initial_delay_or_default(copy _5) -> [bb3]; } bb3: { - _47 = copy _48 == const 0_i64; - branch copy _47 -> [bb7, bb4]; + _8 = const 0_i64; + goto -> bb4; } bb4: { - _52 = copy _1.4; - _54 = copy _1.2; - _53 = len(_54); - goto -> bb5; + _10 = copy _8; + _11 = copy _5.0; + _9 = copy _10 <= copy _11; + branch copy _9 -> [bb7, bb5]; } bb5: { - _51 = copy _52 % copy _53; - _1.4 = copy _1.4 + const 1_i64; - _57 = copy _1.2; - _58 = copy _51; - _56 = copy _57[_58]; - _59 = load_type(#0); - _55 = call const fn baml.llm.Client.execute_oneshot(copy _56, copy _2, copy _3) -> [bb6]; + _0 = copy _6; + goto -> bb6; } bb6: { - _0 = copy _55; - goto -> bb38; + return; } bb7: { - _50 = baml.errors.DevOther { const "RoundRobin client has no sub-clients" }; - throw copy _50; + _12 = const 0_i64; + _14 = copy _8; + _13 = copy _14 > const 0_i64; + branch copy _13 -> [bb8, bb14]; } bb8: { - _37 = copy _1.2; - _38 = virtual_call iter as baml.iter.Iterable(copy _37) -> [bb34]; + _15 = copy _7; + _12 = call const fn baml._trunc_to_int(copy _15) -> [bb9]; } bb9: { - _6 = call const fn baml.llm.Client.to_primitive_client(copy _1, const ) -> [bb10]; + _17 = copy _7; + _18 = call const fn baml.llm.RetryPolicy.multiplier_or_default(copy _5) -> [bb10]; } bb10: { - _7 = load_type(#0); - goto -> bb11; + _16 = copy _17 * copy _18; + _20 = copy _16; + _21 = call const fn baml.llm.RetryPolicy.max_delay_or_default(copy _5) -> [bb11]; } bb11: { - _9 = copy _2.0; - _10 = copy _2.1; - _11 = copy _7; - _12 = copy _2.3; - _8 = call const fn baml.llm.PrimitiveClient.render_specialized_prompt(copy _6, copy _9, copy _10, copy _11, copy _12) -> [bb12]; + _19 = copy _20 > copy _21; + branch copy _19 -> [bb13, bb12]; } bb12: { - _14 = copy _8; - _15 = copy _7; - _13 = sys_op const fn baml.llm.PrimitiveClient.build_request(copy _6, copy _14, copy _15) -> bb13; + _7 = copy _16; + goto -> bb14; } bb13: { - _17 = copy _13; - _16 = call const fn baml.http.send(copy _17, const ) -> [bb14]; + _7 = call const fn baml.llm.RetryPolicy.max_delay_or_default(copy _5) -> [bb14]; } bb14: { - _18 = call const fn baml.http.Response.ok(copy _16) -> [bb15]; + _22 = call const fn baml.llm.Client.build_attempt_with_state(copy _1, copy _2) -> [bb15]; } bb15: { - branch copy _18 -> [bb17, bb16]; + _23 = copy _22; + _24 = virtual_call iter as baml.iter.Iterable(copy _23) -> [bb16]; } bb16: { - _28 = sys_op const fn baml.http.Response.text(copy _16) -> bb28 unwind bb26; + _25 = virtual_call next as baml.iter.Iterator(copy _24) -> [bb17]; } bb17: { - _19 = sys_op const fn baml.http.Response.text(copy _16) -> bb18; + _26 = is_type(copy _25, baml.iter.Done); + branch copy _26 -> [bb19, bb18]; } bb18: { - _22 = copy _19; - _23 = load_type(#0); - _20 = sys_op const fn baml.llm.PrimitiveClient.parse(copy _6, copy _22, copy _23) -> bb19 unwind bb20; + _27 = copy _25; + fresh_cell(_28); + _28 = copy _27; + _31 = copy _28.0; + _32 = copy _12; + _30 = baml.llm.OrchestrationStep { copy _31, copy _32 }; + _29 = call const fn baml.Array.push(copy _6, copy _30) -> [bb16]; } bb19: { - _0 = copy _20; - goto -> bb38; + _8 = copy _8 + const 1_i64; + goto -> bb4; } +} - bb20: { - throw_if_panic copy _21 -> bb21; +fn baml.llm.Client.execute_stream(self: baml.llm.Client, context: baml.llm.ExecutionContext, inherited_delay_ms: int) -> baml.llm.Stream { + // Locals: + let _0: baml.llm.Stream // _0 // return + let _1: baml.llm.Client // self // param + let _2: baml.llm.ExecutionContext // context // param + let _3: int // inherited_delay_ms // param + let _4: null | baml.llm.RetryPolicy + let _5: bool + let _6: baml.llm.RetryPolicy // r + let _7: float // current_delay + let _8: int // attempt + let _9: bool + let _10: int + let _11: int + let _12: int // attempt_delay + let _13: bool + let _14: int + let _15: float + let _16: float // next + let _17: float + let _18: float + let _19: bool + let _20: float + let _21: float + let _22: bool + let _23: int + let _24: int + let _25: baml.llm.Stream // result2 + let _26: unknown // e + let _27: int + let _28: type + let _29: type + let _30: baml.errors.DevOther + let _31: baml.llm.Stream // result + let _32: type + let _33: type + + bb0: { + _4 = copy _1.3; + _5 = is_type(copy _4, baml.llm.RetryPolicy); + branch copy _5 -> [bb3, bb1]; } - bb21: { - _25 = copy _3 > const 0_i64; - branch copy _25 -> [bb23, bb22]; + bb1: { + _32 = load_type(#0); + _33 = load_type(#1); + _31 = call const fn baml.llm.Client.execute_once_stream(copy _1, copy _2, copy _3) -> [bb2]; } - bb22: { - _24 = const null; - goto -> bb25; + bb2: { + _0 = copy _31; + goto -> bb20; } - bb23: { - _27 = copy _3 * const 1000000n; - _26 = call const fn baml.time.Duration.from_nanoseconds(copy _27) -> [bb24]; + bb3: { + _6 = copy _4; + _7 = call const fn baml.llm.RetryPolicy.initial_delay_or_default(copy _6) -> [bb4]; } - bb24: { - _24 = sys_op const fn baml.sys.sleep(copy _26) -> bb25; + bb4: { + _8 = const 0_i64; + goto -> bb7; + } + + bb5: { + throw_if_panic copy _26 -> bb6; + } + + bb6: { + _8 = copy _8 + const 1_i64; + goto -> bb7; } - bb25: { - rethrow copy _21; + bb7: { + _10 = copy _8; + _11 = copy _6.0; + _9 = copy _10 <= copy _11; + branch copy _9 -> [bb9, bb8]; } - bb26: { - throw_if_panic copy _29 -> bb27; + bb8: { + _30 = baml.errors.DevOther { const "All orchestration steps failed" }; + throw copy _30; } - bb27: { - _28 = const ""; - goto -> bb28; + bb9: { + _12 = copy _3; + _14 = copy _8; + _13 = copy _14 > const 0_i64; + branch copy _13 -> [bb10, bb16]; } - bb28: { - _31 = copy _3 > const 0_i64; - branch copy _31 -> [bb30, bb29]; + bb10: { + _15 = copy _7; + _12 = call const fn baml._trunc_to_int(copy _15) -> [bb11]; } - bb29: { - _30 = const null; - goto -> bb32; + bb11: { + _17 = copy _7; + _18 = call const fn baml.llm.RetryPolicy.multiplier_or_default(copy _6) -> [bb12]; } - bb30: { - _33 = copy _3 * const 1000000n; - _32 = call const fn baml.time.Duration.from_nanoseconds(copy _33) -> [bb31]; + bb12: { + _16 = copy _17 * copy _18; + _20 = copy _16; + _21 = call const fn baml.llm.RetryPolicy.max_delay_or_default(copy _6) -> [bb13]; } - bb31: { - _30 = sys_op const fn baml.sys.sleep(copy _32) -> bb32; + bb13: { + _19 = copy _20 > copy _21; + branch copy _19 -> [bb15, bb14]; } - bb32: { - _36 = copy _28; - _35 = const "HTTP request failed: " + copy _36; - _34 = baml.errors.DevOther { copy _35 }; - throw copy _34; + bb14: { + _7 = copy _16; + goto -> bb16; } - bb33: { - throw_if_panic copy _44 -> bb34; + bb15: { + _7 = call const fn baml.llm.RetryPolicy.max_delay_or_default(copy _6) -> [bb16]; } - bb34: { - _39 = virtual_call next as baml.iter.Iterator(copy _38) -> [bb35]; + bb16: { + _23 = copy _8; + _24 = copy _6.0; + _22 = copy _23 == copy _24; + branch copy _22 -> [bb17, bb18]; } - bb35: { - _40 = is_type(copy _39, baml.iter.Done); - branch copy _40 -> [bb39, bb36]; + bb17: { + _12 = copy _3; + goto -> bb18; } - bb36: { - _41 = copy _39; - fresh_cell(_42); - _42 = copy _41; - _45 = load_type(#0); - _43 = call const fn baml.llm.Client.execute_oneshot(copy _42, copy _2, copy _3) -> [bb37, unwind: bb33]; + bb18: { + _27 = copy _12; + _28 = load_type(#0); + _29 = load_type(#1); + _25 = call const fn baml.llm.Client.execute_once_stream(copy _1, copy _2, copy _27) -> [bb19, unwind: bb5]; } - bb37: { - _0 = copy _43; - goto -> bb38; + bb19: { + _0 = copy _25; + goto -> bb20; } - bb38: { + bb20: { return; } - - bb39: { - _46 = baml.errors.DevOther { const "All orchestration steps failed" }; - throw copy _46; - } } fn baml.llm.Client.execute_once_stream(self: baml.llm.Client, context: baml.llm.ExecutionContext, active_delay_ms: int) -> baml.llm.Stream { @@ -6618,156 +6525,58 @@ fn baml.llm.Client.execute_once_stream(self: baml.llm.Client, context: baml.llm. } } -fn baml.llm.Client.execute_oneshot(self: baml.llm.Client, context: baml.llm.ExecutionContext, inherited_delay_ms: int) -> T { +fn baml.llm.Client.__make_stream(self: baml.llm.Client, sse: baml.http.SseStream) -> baml.llm.Stream { // Locals: - let _0: T // _0 // return + let _0: baml.llm.Stream // _0 // return let _1: baml.llm.Client // self // param - let _2: baml.llm.ExecutionContext // context // param - let _3: int // inherited_delay_ms // param - let _4: null | baml.llm.RetryPolicy - let _5: bool - let _6: baml.llm.RetryPolicy // r - let _7: float // current_delay - let _8: int // attempt - let _9: bool - let _10: int - let _11: int - let _12: int // attempt_delay - let _13: bool - let _14: int - let _15: float - let _16: float // next - let _17: float - let _18: float - let _19: bool - let _20: float - let _21: float - let _22: bool - let _23: int - let _24: int - let _25: T // result2 - let _26: unknown // e - let _27: int - let _28: type - let _29: baml.errors.DevOther - let _30: T // result - let _31: type + let _2: baml.http.SseStream // sse // param + let _3: baml.llm.PrimitiveClient // primitive + let _4: baml.llm.StreamAccumulator // acc + let _5: baml.llm.StreamCache // cache + let _6: type + let _7: type + let _8: baml.llm.PrimitiveClient + let _9: baml.llm.StreamAccumulator + let _10: baml.llm.StreamCache bb0: { - _4 = copy _1.3; - _5 = is_type(copy _4, baml.llm.RetryPolicy); - branch copy _5 -> [bb3, bb1]; + _3 = call const fn baml.llm.Client.to_primitive_client(copy _1, const ) -> [bb1]; } bb1: { - _31 = load_type(#0); - _30 = call const fn baml.llm.Client.execute_once_oneshot(copy _1, copy _2, copy _3) -> [bb2]; + _4 = sys_op const fn baml.llm.PrimitiveClient.new_stream_accumulator(copy _3) -> bb2; } bb2: { - _0 = copy _30; - goto -> bb20; + _6 = load_type(#0); + goto -> bb3; } bb3: { - _6 = copy _4; - _7 = call const fn baml.llm.RetryPolicy.initial_delay_or_default(copy _6) -> [bb4]; + _7 = load_type(#1); + goto -> bb4; } bb4: { - _8 = const 0_i64; - goto -> bb7; + _5 = sys_op const fn baml.llm.StreamCache.new(copy _6, copy _7) -> bb5; } bb5: { - throw_if_panic copy _26 -> bb6; + _8 = copy _3; + _9 = copy _4; + _10 = copy _5; + _0 = baml.llm.Stream<#0, #1> { copy _8, copy _9, copy _2, copy _10 }; + goto -> bb6; } bb6: { - _8 = copy _8 + const 1_i64; - goto -> bb7; - } - - bb7: { - _10 = copy _8; - _11 = copy _6.0; - _9 = copy _10 <= copy _11; - branch copy _9 -> [bb9, bb8]; - } - - bb8: { - _29 = baml.errors.DevOther { const "All orchestration steps failed" }; - throw copy _29; - } - - bb9: { - _12 = copy _3; - _14 = copy _8; - _13 = copy _14 > const 0_i64; - branch copy _13 -> [bb10, bb16]; - } - - bb10: { - _15 = copy _7; - _12 = call const fn baml._trunc_to_int(copy _15) -> [bb11]; - } - - bb11: { - _17 = copy _7; - _18 = call const fn baml.llm.RetryPolicy.multiplier_or_default(copy _6) -> [bb12]; - } - - bb12: { - _16 = copy _17 * copy _18; - _20 = copy _16; - _21 = call const fn baml.llm.RetryPolicy.max_delay_or_default(copy _6) -> [bb13]; - } - - bb13: { - _19 = copy _20 > copy _21; - branch copy _19 -> [bb15, bb14]; - } - - bb14: { - _7 = copy _16; - goto -> bb16; - } - - bb15: { - _7 = call const fn baml.llm.RetryPolicy.max_delay_or_default(copy _6) -> [bb16]; - } - - bb16: { - _23 = copy _8; - _24 = copy _6.0; - _22 = copy _23 == copy _24; - branch copy _22 -> [bb17, bb18]; - } - - bb17: { - _12 = copy _3; - goto -> bb18; - } - - bb18: { - _27 = copy _12; - _28 = load_type(#0); - _25 = call const fn baml.llm.Client.execute_once_oneshot(copy _1, copy _2, copy _27) -> [bb19, unwind: bb5]; - } - - bb19: { - _0 = copy _25; - goto -> bb20; - } - - bb20: { return; } } -fn baml.llm.Client.execute_stream(self: baml.llm.Client, context: baml.llm.ExecutionContext, inherited_delay_ms: int) -> baml.llm.Stream { +fn baml.llm.Client.execute_oneshot(self: baml.llm.Client, context: baml.llm.ExecutionContext, inherited_delay_ms: int) -> T { // Locals: - let _0: baml.llm.Stream // _0 // return + let _0: T // _0 // return let _1: baml.llm.Client // self // param let _2: baml.llm.ExecutionContext // context // param let _3: int // inherited_delay_ms // param @@ -6792,15 +6601,13 @@ fn baml.llm.Client.execute_stream(self: baml.llm.Client, context: baml.llm.Execu let _22: bool let _23: int let _24: int - let _25: baml.llm.Stream // result2 + let _25: T // result2 let _26: unknown // e let _27: int let _28: type - let _29: type - let _30: baml.errors.DevOther - let _31: baml.llm.Stream // result - let _32: type - let _33: type + let _29: baml.errors.DevOther + let _30: T // result + let _31: type bb0: { _4 = copy _1.3; @@ -6809,13 +6616,12 @@ fn baml.llm.Client.execute_stream(self: baml.llm.Client, context: baml.llm.Execu } bb1: { - _32 = load_type(#0); - _33 = load_type(#1); - _31 = call const fn baml.llm.Client.execute_once_stream(copy _1, copy _2, copy _3) -> [bb2]; + _31 = load_type(#0); + _30 = call const fn baml.llm.Client.execute_once_oneshot(copy _1, copy _2, copy _3) -> [bb2]; } bb2: { - _0 = copy _31; + _0 = copy _30; goto -> bb20; } @@ -6846,8 +6652,8 @@ fn baml.llm.Client.execute_stream(self: baml.llm.Client, context: baml.llm.Execu } bb8: { - _30 = baml.errors.DevOther { const "All orchestration steps failed" }; - throw copy _30; + _29 = baml.errors.DevOther { const "All orchestration steps failed" }; + throw copy _29; } bb9: { @@ -6902,8 +6708,7 @@ fn baml.llm.Client.execute_stream(self: baml.llm.Client, context: baml.llm.Execu bb18: { _27 = copy _12; _28 = load_type(#0); - _29 = load_type(#1); - _25 = call const fn baml.llm.Client.execute_once_stream(copy _1, copy _2, copy _27) -> [bb19, unwind: bb5]; + _25 = call const fn baml.llm.Client.execute_once_oneshot(copy _1, copy _2, copy _27) -> [bb19, unwind: bb5]; } bb19: { @@ -6916,252 +6721,290 @@ fn baml.llm.Client.execute_stream(self: baml.llm.Client, context: baml.llm.Execu } } -fn baml.llm.Stream.final(self: baml.llm.Stream) -> TFinal { +fn baml.llm.Client.execute_once_oneshot(self: baml.llm.Client, context: baml.llm.ExecutionContext, active_delay_ms: int) -> T { // Locals: - let _0: TFinal // _0 // return - let _1: baml.llm.Stream // self // param - let _2: bool - let _3: bool - let _4: () -> bool throws baml.errors.LlmClient - let _5: string // next - let _6: string | null - let _7: () -> string | null throws baml.errors.Io - let _8: bool - let _9: string // next - let _10: null - let _11: (string) -> null throws baml.errors.LlmClient - let _12: string - let _13: bool - let _14: () -> bool throws baml.errors.LlmClient - let _15: null - let _16: () -> null throws never - let _17: null - let _18: string | null - let _19: () -> string | null throws baml.errors.LlmClient - let _20: bool - let _21: baml.errors.LlmClient - let _22: string // reason - let _23: (string) -> null throws baml.errors.LlmClient - let _24: string - let _25: string // content - let _26: () -> string throws baml.errors.LlmClient - let _27: string - let _28: baml.llm.StreamCache - let _29: type - let _30: type + let _0: T // _0 // return + let _1: baml.llm.Client // self // param + let _2: baml.llm.ExecutionContext // context // param + let _3: int // active_delay_ms // param + let _4: baml.llm.ClientType + let _5: int + let _6: baml.llm.PrimitiveClient // primitive + let _7: type // return_type + let _8: baml.llm.PromptAst // specialized + let _9: string + let _10: map + let _11: type + let _12: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never) + let _13: baml.http.Request // http_request + let _14: baml.llm.PromptAst + let _15: type + let _16: baml.http.Response // http_response + let _17: baml.http.Request + let _18: bool + let _19: string // body + let _20: T // result + let _21: unknown // e + let _22: string + let _23: type + let _24: void + let _25: bool + let _26: baml.time.Duration + let _27: bigint + let _28: string // error_body + let _29: unknown // e + let _30: void + let _31: bool + let _32: baml.time.Duration + let _33: bigint + let _34: baml.errors.DevOther + let _35: string + let _36: string + let _37: baml.llm.Client[] + let _38: baml.iter.Iterator + let _39: unknown + let _40: bool + let _41: baml.llm.Client + let _42: baml.llm.Client // sub + let _43: T // result2 + let _44: unknown // e + let _45: type + let _46: baml.errors.DevOther + let _47: bool + let _48: int + let _49: (baml.llm.Client[]) -> int throws never + let _50: baml.errors.DevOther + let _51: int // idx + let _52: int + let _53: int + let _54: (baml.llm.Client[]) -> int throws never + let _55: T // result3 + let _56: baml.llm.Client + let _57: baml.llm.Client[] + let _58: int + let _59: type bb0: { - goto -> bb1; + _4 = copy _1.1; + _5 = discriminant(_4); + switch copy _5 [ClientType.Primitive: bb9, ClientType.Fallback: bb8, ClientType.RoundRobin: bb2, otherwise: bb1] (exhaustive); } bb1: { - _4 = copy _1.1; - _3 = sys_op const fn baml.llm.StreamAccumulator.is_done(copy _4) -> bb2; + unreachable; } bb2: { - _2 = !copy _3; - branch copy _2 -> [bb3, bb10]; + _49 = copy _1.2; + _48 = len(_49); + goto -> bb3; } bb3: { - _7 = copy _1.2; - _6 = sys_op const fn baml.http.SseStream.next(copy _7) -> bb4; + _47 = copy _48 == const 0_i64; + branch copy _47 -> [bb7, bb4]; } bb4: { - _8 = copy _6 == const null; - branch copy _8 -> [bb10, bb5]; + _52 = copy _1.4; + _54 = copy _1.2; + _53 = len(_54); + goto -> bb5; } bb5: { - _9 = copy _6; - _5 = copy _9; - goto -> bb6; + _51 = copy _52 % copy _53; + _1.4 = copy _1.4 + const 1_i64; + _57 = copy _1.2; + _58 = copy _51; + _56 = copy _57[_58]; + _59 = load_type(#0); + _55 = call const fn baml.llm.Client.execute_oneshot(copy _56, copy _2, copy _3) -> [bb6]; } bb6: { - _11 = copy _1.1; - _12 = copy _5; - _10 = sys_op const fn baml.llm.StreamAccumulator.add_events(copy _11, copy _12) -> bb7; + _0 = copy _55; + goto -> bb38; } bb7: { - _14 = copy _1.1; - _13 = sys_op const fn baml.llm.StreamAccumulator.is_done(copy _14) -> bb8; + _50 = baml.errors.DevOther { const "RoundRobin client has no sub-clients" }; + throw copy _50; } bb8: { - branch copy _13 -> [bb9, bb1]; + _37 = copy _1.2; + _38 = virtual_call iter as baml.iter.Iterable(copy _37) -> [bb34]; } bb9: { - _16 = copy _1.2; - _15 = sys_op const fn baml.http.SseStream.close(copy _16) -> bb10; + _6 = call const fn baml.llm.Client.to_primitive_client(copy _1, const ) -> [bb10]; } bb10: { - _19 = copy _1.1; - _18 = sys_op const fn baml.llm.StreamAccumulator.finish_reason(copy _19) -> bb11; + _7 = load_type(#0); + goto -> bb11; } bb11: { - _20 = copy _18 == const null; - branch copy _20 -> [bb16, bb12]; + _9 = copy _2.0; + _10 = copy _2.1; + _11 = copy _7; + _12 = copy _2.3; + _8 = call const fn baml.llm.PrimitiveClient.render_specialized_prompt(copy _6, copy _9, copy _10, copy _11, copy _12) -> [bb12]; } bb12: { - _22 = copy _18; - _23 = copy _1.0; - _24 = copy _22; - _17 = sys_op const fn baml.llm.PrimitiveClient.validate_finish_reason(copy _23, copy _24) -> bb13; + _14 = copy _8; + _15 = copy _7; + _13 = sys_op const fn baml.llm.PrimitiveClient.build_request(copy _6, copy _14, copy _15) -> bb13; } bb13: { - _26 = copy _1.1; - _25 = sys_op const fn baml.llm.StreamAccumulator.content(copy _26) -> bb14; + _17 = copy _13; + _16 = call const fn baml.http.send(copy _17, const ) -> [bb14]; } bb14: { - _27 = copy _25; - _28 = copy _1.3; - _29 = load_type(#0); - _30 = load_type(#1); - _0 = sys_op const fn baml.llm.__sap_parse_final(copy _27, copy _28, copy _29, copy _30) -> bb15; + _18 = call const fn baml.http.Response.ok(copy _16) -> [bb15]; } bb15: { - return; + branch copy _18 -> [bb17, bb16]; } bb16: { - _21 = baml.errors.LlmClient { const "Streaming finished without finish_reason" }; - throw copy _21; + _28 = sys_op const fn baml.http.Response.text(copy _16) -> bb28 unwind bb26; } -} -fn baml.llm.StreamAccumulator.finish_reason = builtin(io) + bb17: { + _19 = sys_op const fn baml.http.Response.text(copy _16) -> bb18; + } -fn baml.llm.from_shorthand = builtin(io) + bb18: { + _22 = copy _19; + _23 = load_type(#0); + _20 = sys_op const fn baml.llm.PrimitiveClient.parse(copy _6, copy _22, copy _23) -> bb19 unwind bb20; + } -fn baml.llm.Client.get_constructor = builtin(io) + bb19: { + _0 = copy _20; + goto -> bb38; + } -fn baml.llm.get_jinja_template = builtin(io) + bb20: { + throw_if_panic copy _21 -> bb21; + } -fn baml.llm.get_return_type = builtin(io) + bb21: { + _25 = copy _3 > const 0_i64; + branch copy _25 -> [bb23, bb22]; + } -fn baml.llm.RetryPolicy.initial_delay_or_default(self: baml.llm.RetryPolicy) -> float { - // Locals: - let _0: float // _0 // return - let _1: baml.llm.RetryPolicy // self // param - let _2: int - let _3: int | null - let _4: bool + bb22: { + _24 = const null; + goto -> bb25; + } - bb0: { - _3 = copy _1.1; - _2 = copy _3; - _4 = copy _3 == const null; - branch copy _4 -> [bb1, bb2]; + bb23: { + _27 = copy _3 * const 1000000n; + _26 = call const fn baml.time.Duration.from_nanoseconds(copy _27) -> [bb24]; } - bb1: { - _2 = const 200_i64; - goto -> bb2; + bb24: { + _24 = sys_op const fn baml.sys.sleep(copy _26) -> bb25; } - bb2: { - _0 = copy _2 + const 0_f64; - goto -> bb3; + bb25: { + rethrow copy _21; } - bb3: { - return; + bb26: { + throw_if_panic copy _29 -> bb27; + } + + bb27: { + _28 = const ""; + goto -> bb28; + } + + bb28: { + _31 = copy _3 > const 0_i64; + branch copy _31 -> [bb30, bb29]; + } + + bb29: { + _30 = const null; + goto -> bb32; } -} - -fn baml.llm.StreamAccumulator.input_tokens = builtin(io) -fn baml.llm.StreamAccumulator.is_done = builtin(io) + bb30: { + _33 = copy _3 * const 1000000n; + _32 = call const fn baml.time.Duration.from_nanoseconds(copy _33) -> [bb31]; + } -fn baml.llm.make_role(name: string) -> baml.llm.Role { - // Locals: - let _0: baml.llm.Role // _0 // return - let _1: string // name // param - let _2: map + bb31: { + _30 = sys_op const fn baml.sys.sleep(copy _32) -> bb32; + } - bb0: { - _2 = { }: map; - _0 = baml.llm.Role { copy _1, copy _2 }; - goto -> bb1; + bb32: { + _36 = copy _28; + _35 = const "HTTP request failed: " + copy _36; + _34 = baml.errors.DevOther { copy _35 }; + throw copy _34; } - bb1: { - return; + bb33: { + throw_if_panic copy _44 -> bb34; } -} -fn baml.llm.RetryPolicy.max_delay_or_default(self: baml.llm.RetryPolicy) -> float { - // Locals: - let _0: float // _0 // return - let _1: baml.llm.RetryPolicy // self // param - let _2: int - let _3: int | null - let _4: bool + bb34: { + _39 = virtual_call next as baml.iter.Iterator(copy _38) -> [bb35]; + } - bb0: { - _3 = copy _1.3; - _2 = copy _3; - _4 = copy _3 == const null; - branch copy _4 -> [bb1, bb2]; + bb35: { + _40 = is_type(copy _39, baml.iter.Done); + branch copy _40 -> [bb39, bb36]; } - bb1: { - _2 = const 10000_i64; - goto -> bb2; + bb36: { + _41 = copy _39; + fresh_cell(_42); + _42 = copy _41; + _45 = load_type(#0); + _43 = call const fn baml.llm.Client.execute_oneshot(copy _42, copy _2, copy _3) -> [bb37, unwind: bb33]; } - bb2: { - _0 = copy _2 + const 0_f64; - goto -> bb3; + bb37: { + _0 = copy _43; + goto -> bb38; } - bb3: { + bb38: { return; } + + bb39: { + _46 = baml.errors.DevOther { const "All orchestration steps failed" }; + throw copy _46; + } } -fn baml.llm.PromptAst.messages = builtin(io) +fn baml.llm.StreamAccumulator.add_events = builtin(io) -fn baml.llm.StreamAccumulator.model = builtin(io) +fn baml.llm.StreamAccumulator.content = builtin(io) -fn baml.llm.RetryPolicy.multiplier_or_default(self: baml.llm.RetryPolicy) -> float { - // Locals: - let _0: float // _0 // return - let _1: baml.llm.RetryPolicy // self // param - let _2: float | null - let _3: bool +fn baml.llm.StreamAccumulator.is_done = builtin(io) - bb0: { - _2 = copy _1.2; - _0 = copy _2; - _3 = copy _2 == const null; - branch copy _3 -> [bb1, bb2]; - } +fn baml.llm.StreamAccumulator.model = builtin(io) - bb1: { - _0 = const 1.5_f64; - goto -> bb2; - } +fn baml.llm.StreamAccumulator.finish_reason = builtin(io) - bb2: { - return; - } -} +fn baml.llm.StreamAccumulator.input_tokens = builtin(io) -fn baml.llm.StreamCache.new = builtin(io) +fn baml.llm.StreamAccumulator.output_tokens = builtin(io) -fn baml.llm.PrimitiveClient.new_stream_accumulator = builtin(io) +fn baml.llm.StreamCache.new = builtin(io) fn baml.llm.Stream.next(self: baml.llm.Stream) -> baml.stream.StreamFinished | TStream { // Locals: @@ -7276,63 +7119,193 @@ fn baml.llm.Stream.next(self: baml.llm.Stream) -> baml.stream.StreamFinished | T } } -fn baml.llm.Context.output_format_with = builtin(io) - -fn baml.llm.StreamAccumulator.output_tokens = builtin(io) - -fn baml.llm.PrimitiveClient.parse = builtin(io) - -fn baml.llm.prompt(body: ((string) -> baml.llm.Role throws never, baml.llm.Context) -> baml.TaggedString throws never) -> (baml.llm.Context) -> baml.llm.PromptAst throws never { +fn baml.llm.Stream.final(self: baml.llm.Stream) -> TFinal { // Locals: - let _0: (baml.llm.Context) -> baml.llm.PromptAst throws never // _0 // return - let _1: ((string) -> baml.llm.Role throws never, baml.llm.Context) -> baml.TaggedString throws never // body // param [captured] - let _2: (baml.llm.Context) -> baml.llm.PromptAst throws never // render + let _0: TFinal // _0 // return + let _1: baml.llm.Stream // self // param + let _2: bool + let _3: bool + let _4: () -> bool throws baml.errors.LlmClient + let _5: string // next + let _6: string | null + let _7: () -> string | null throws baml.errors.Io + let _8: bool + let _9: string // next + let _10: null + let _11: (string) -> null throws baml.errors.LlmClient + let _12: string + let _13: bool + let _14: () -> bool throws baml.errors.LlmClient + let _15: null + let _16: () -> null throws never + let _17: null + let _18: string | null + let _19: () -> string | null throws baml.errors.LlmClient + let _20: bool + let _21: baml.errors.LlmClient + let _22: string // reason + let _23: (string) -> null throws baml.errors.LlmClient + let _24: string + let _25: string // content + let _26: () -> string throws baml.errors.LlmClient + let _27: string + let _28: baml.llm.StreamCache + let _29: type + let _30: type bb0: { - _2 = make_closure lambda[0](copy _1); - _0 = copy _2; goto -> bb1; } bb1: { + _4 = copy _1.1; + _3 = sys_op const fn baml.llm.StreamAccumulator.is_done(copy _4) -> bb2; + } + + bb2: { + _2 = !copy _3; + branch copy _2 -> [bb3, bb10]; + } + + bb3: { + _7 = copy _1.2; + _6 = sys_op const fn baml.http.SseStream.next(copy _7) -> bb4; + } + + bb4: { + _8 = copy _6 == const null; + branch copy _8 -> [bb10, bb5]; + } + + bb5: { + _9 = copy _6; + _5 = copy _9; + goto -> bb6; + } + + bb6: { + _11 = copy _1.1; + _12 = copy _5; + _10 = sys_op const fn baml.llm.StreamAccumulator.add_events(copy _11, copy _12) -> bb7; + } + + bb7: { + _14 = copy _1.1; + _13 = sys_op const fn baml.llm.StreamAccumulator.is_done(copy _14) -> bb8; + } + + bb8: { + branch copy _13 -> [bb9, bb1]; + } + + bb9: { + _16 = copy _1.2; + _15 = sys_op const fn baml.http.SseStream.close(copy _16) -> bb10; + } + + bb10: { + _19 = copy _1.1; + _18 = sys_op const fn baml.llm.StreamAccumulator.finish_reason(copy _19) -> bb11; + } + + bb11: { + _20 = copy _18 == const null; + branch copy _20 -> [bb16, bb12]; + } + + bb12: { + _22 = copy _18; + _23 = copy _1.0; + _24 = copy _22; + _17 = sys_op const fn baml.llm.PrimitiveClient.validate_finish_reason(copy _23, copy _24) -> bb13; + } + + bb13: { + _26 = copy _1.1; + _25 = sys_op const fn baml.llm.StreamAccumulator.content(copy _26) -> bb14; + } + + bb14: { + _27 = copy _25; + _28 = copy _1.3; + _29 = load_type(#0); + _30 = load_type(#1); + _0 = sys_op const fn baml.llm.__sap_parse_final(copy _27, copy _28, copy _29, copy _30) -> bb15; + } + + bb15: { return; } + + bb16: { + _21 = baml.errors.LlmClient { const "Streaming finished without finish_reason" }; + throw copy _21; + } } -// lambda[0] -fn .(ctx: baml.llm.Context) -> null { +fn baml.llm.PrimitiveClient.render_prompt = builtin(io) + +fn baml.llm.PrimitiveClient.specialize_prompt = builtin(io) + +fn baml.llm.PrimitiveClient.render_specialized_prompt(self: baml.llm.PrimitiveClient, template: string, args: map, return_type: type, prompt_closure: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never)) -> baml.llm.PromptAst { // Locals: - let _0: null // _0 // return - let _1: baml.llm.Context // ctx // param - let _2: baml.TaggedString // t - let _3: ((string) -> baml.llm.Role throws never, baml.llm.Context) -> baml.TaggedString throws never - let _4: string[] - let _5: unknown[] - let _6: unknown[] + let _0: baml.llm.PromptAst // _0 // return + let _1: baml.llm.PrimitiveClient // self // param + let _2: string // template // param + let _3: map // args // param + let _4: type // return_type // param + let _5: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never) // prompt_closure // param + let _6: baml.llm.PromptAst // prompt + let _7: bool + let _8: (baml.llm.Context) -> baml.llm.PromptAst throws never // closure + let _9: (baml.llm.Context) -> baml.llm.PromptAst throws never + let _10: baml.llm.Context + let _11: baml.llm.PromptAst bb0: { - _3 = copy capture[0]; - _2 = call copy _3(const fn baml.llm.make_role, copy _1) -> [bb1]; + _7 = copy _5 == const null; + branch copy _7 -> [bb3, bb1]; } bb1: { - _4 = copy _2.0; - _6 = copy _2.1; - _5 = call const fn baml.llm.render_prompt_values(copy _6) -> [bb2]; + _8 = copy _5; + _9 = copy _8; + _10 = call const fn baml.llm.build_prompt_context(copy _1, copy _4) -> [bb2]; } bb2: { - _0 = sys_op const fn baml.llm.assemble_prompt_ast(copy _4, copy _5) -> bb3; + _6 = call copy _9(copy _10) -> [bb4]; } bb3: { + _6 = sys_op const fn baml.llm.PrimitiveClient.render_prompt(copy _1, copy _2, copy _3, copy _4) -> bb4; + } + + bb4: { + _11 = copy _6; + _0 = sys_op const fn baml.llm.PrimitiveClient.specialize_prompt(copy _1, copy _11) -> bb5; + } + + bb5: { return; } } -fn baml.llm.render_output_format = builtin(io) +fn baml.llm.PrimitiveClient.build_request = builtin(io) -fn baml.llm.PrimitiveClient.render_prompt = builtin(io) +fn baml.llm.PrimitiveClient.build_request_stream = builtin(io) + +fn baml.llm.PrimitiveClient.new_stream_accumulator = builtin(io) + +fn baml.llm.PrimitiveClient.validate_finish_reason = builtin(io) + +fn baml.llm.PrimitiveClient.parse = builtin(io) + +fn baml.llm.from_shorthand = builtin(io) + +fn baml.llm.get_jinja_template = builtin(io) + +fn baml.llm.assemble_prompt_ast = builtin(io) fn baml.llm.render_prompt_values(values: unknown[]) -> unknown[] { // Locals: @@ -7395,181 +7368,200 @@ fn baml.llm.render_prompt_values(values: unknown[]) -> unknown[] { } } -fn baml.llm.PrimitiveClient.render_specialized_prompt(self: baml.llm.PrimitiveClient, template: string, args: map, return_type: type, prompt_closure: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never)) -> baml.llm.PromptAst { +fn baml.llm.render_output_format = builtin(io) + +fn baml.llm.build_output_format = builtin(io) + +fn baml.llm.build_prompt_context(primitive: baml.llm.PrimitiveClient, return_type: type) -> baml.llm.Context { // Locals: - let _0: baml.llm.PromptAst // _0 // return - let _1: baml.llm.PrimitiveClient // self // param - let _2: string // template // param - let _3: map // args // param - let _4: type // return_type // param - let _5: null | ((baml.llm.Context) -> baml.llm.PromptAst throws never) // prompt_closure // param - let _6: baml.llm.PromptAst // prompt - let _7: bool - let _8: (baml.llm.Context) -> baml.llm.PromptAst throws never // closure - let _9: (baml.llm.Context) -> baml.llm.PromptAst throws never - let _10: baml.llm.Context - let _11: baml.llm.PromptAst + let _0: baml.llm.Context // _0 // return + let _1: baml.llm.PrimitiveClient // primitive // param + let _2: type // return_type // param + let _3: baml.llm.ContextClient + let _4: string + let _5: string + let _6: string + let _7: string | null + let _8: bool + let _9: string[] + let _10: null | string[] + let _11: bool + let _12: map + let _13: string + let _14: baml.llm.OutputFormat bb0: { - _7 = copy _5 == const null; - branch copy _7 -> [bb3, bb1]; + _4 = copy _1.0; + _5 = copy _1.1; + _7 = copy _1.2.6; + _6 = copy _7; + _8 = copy _7 == const null; + branch copy _8 -> [bb1, bb2]; } bb1: { - _8 = copy _5; - _9 = copy _8; - _10 = call const fn baml.llm.build_prompt_context(copy _1, copy _4) -> [bb2]; + _6 = const "system"; + goto -> bb2; } bb2: { - _6 = call copy _9(copy _10) -> [bb4]; + _10 = copy _1.2.7; + _9 = copy _10; + _11 = copy _10 == const null; + branch copy _11 -> [bb3, bb4]; } bb3: { - _6 = sys_op const fn baml.llm.PrimitiveClient.render_prompt(copy _1, copy _2, copy _3, copy _4) -> bb4; + _9 = []: string[]; + goto -> bb4; } bb4: { - _11 = copy _6; - _0 = sys_op const fn baml.llm.PrimitiveClient.specialize_prompt(copy _1, copy _11) -> bb5; + _3 = baml.llm.ContextClient { copy _4, copy _5, copy _6, copy _9 }; + _12 = { }: map; + _13 = sys_op const fn baml.llm.render_output_format(copy _2) -> bb5; } bb5: { - return; + _14 = sys_op const fn baml.llm.build_output_format(copy _2) -> bb6; } -} -fn baml.llm.PrimitiveClient.specialize_prompt = builtin(io) + bb6: { + _0 = baml.llm.Context { copy _3, copy _12, copy _13, copy _14 }; + goto -> bb7; + } -fn baml.llm.PromptAst.text = builtin(io) + bb7: { + return; + } +} -fn baml.llm.Client.to_primitive_client(self: baml.llm.Client, lenient: bool) -> baml.llm.PrimitiveClient { +fn baml.llm.make_role(name: string) -> baml.llm.Role { // Locals: - let _0: baml.llm.PrimitiveClient // _0 // return - let _1: baml.llm.Client // self // param - let _2: bool // lenient // param - let _3: bool - let _4: bool - let _5: (baml.String, string) -> bool throws never - let _6: string - let _7: (bool) -> baml.llm.PrimitiveClient throws baml.errors.InvalidArgument + let _0: baml.llm.Role // _0 // return + let _1: string // name // param + let _2: map bb0: { - _3 = copy _2 == const ; - branch copy _3 -> [bb1, bb2]; + _2 = { }: map; + _0 = baml.llm.Role { copy _1, copy _2 }; + goto -> bb1; } bb1: { - _2 = const false; - goto -> bb2; - } - - bb2: { - _5 = copy _1.0; - _4 = call const fn baml.String.includes(copy _5, const "/") -> [bb3]; - } - - bb3: { - branch copy _4 -> [bb6, bb4]; - } - - bb4: { - _7 = sys_op const fn baml.llm.Client.get_constructor(copy _1) -> bb5; + return; } +} - bb5: { - _0 = call copy _7(copy _2) -> [bb7]; - } +fn baml.llm.prompt(body: ((string) -> baml.llm.Role throws never, baml.llm.Context) -> baml.TaggedString throws never) -> (baml.llm.Context) -> baml.llm.PromptAst throws never { + // Locals: + let _0: (baml.llm.Context) -> baml.llm.PromptAst throws never // _0 // return + let _1: ((string) -> baml.llm.Role throws never, baml.llm.Context) -> baml.TaggedString throws never // body // param [captured] + let _2: (baml.llm.Context) -> baml.llm.PromptAst throws never // render - bb6: { - _6 = copy _1.0; - _0 = sys_op const fn baml.llm.from_shorthand(copy _6) -> bb7; + bb0: { + _2 = make_closure lambda[0](copy _1); + _0 = copy _2; + goto -> bb1; } - bb7: { + bb1: { return; } } -fn baml.llm.PromptAst.baml.ToString.to_string(self: baml.llm.PromptAst) -> string { +// lambda[0] +fn .(ctx: baml.llm.Context) -> null { // Locals: - let _0: string // _0 // return - let _1: baml.llm.PromptAst // self // param + let _0: null // _0 // return + let _1: baml.llm.Context // ctx // param + let _2: baml.TaggedString // t + let _3: ((string) -> baml.llm.Role throws never, baml.llm.Context) -> baml.TaggedString throws never + let _4: string[] + let _5: unknown[] + let _6: unknown[] bb0: { - _0 = sys_op const fn baml.llm.PromptAst.text(copy _1) -> bb1; + _3 = copy capture[0]; + _2 = call copy _3(const fn baml.llm.make_role, copy _1) -> [bb1]; } bb1: { + _4 = copy _2.0; + _6 = copy _2.1; + _5 = call const fn baml.llm.render_prompt_values(copy _6) -> [bb2]; + } + + bb2: { + _0 = sys_op const fn baml.llm.assemble_prompt_ast(copy _4, copy _5) -> bb3; + } + + bb3: { return; } } -fn baml.llm.PrimitiveClient.validate_finish_reason = builtin(io) - -fn baml.media.Video.base64 = builtin(vm) +fn baml.llm.get_return_type = builtin(io) -fn baml.media.Pdf.base64 = builtin(vm) +fn baml.llm.__sap_parse_final = builtin(io) -fn baml.media.Image.base64 = builtin(vm) +fn baml.llm.__sap_parse_partial = builtin(io) -fn baml.media.Audio.base64 = builtin(vm) +fn baml.media.Pdf.url = builtin(vm) fn baml.media.Pdf.file = builtin(vm) -fn baml.media.Image.file = builtin(vm) +fn baml.media.Pdf.base64 = builtin(vm) -fn baml.media.Audio.file = builtin(vm) +fn baml.media.Pdf.mime_type = builtin(vm) -fn baml.media.Video.file = builtin(vm) +fn baml.media.Pdf.from_url = builtin(vm) -fn baml.media.Video.from_base64 = builtin(vm) +fn baml.media.Pdf.from_file = builtin(vm) fn baml.media.Pdf.from_base64 = builtin(vm) -fn baml.media.Image.from_base64 = builtin(vm) +fn baml.media.Audio.url = builtin(vm) -fn baml.media.Audio.from_base64 = builtin(vm) +fn baml.media.Audio.file = builtin(vm) -fn baml.media.Video.from_file = builtin(vm) +fn baml.media.Audio.base64 = builtin(vm) -fn baml.media.Pdf.from_file = builtin(vm) +fn baml.media.Audio.mime_type = builtin(vm) -fn baml.media.Image.from_file = builtin(vm) +fn baml.media.Audio.from_url = builtin(vm) fn baml.media.Audio.from_file = builtin(vm) -fn baml.media.Video.from_url = builtin(vm) - -fn baml.media.Pdf.from_url = builtin(vm) +fn baml.media.Audio.from_base64 = builtin(vm) -fn baml.media.Image.from_url = builtin(vm) +fn baml.media.Video.url = builtin(vm) -fn baml.media.Audio.from_url = builtin(vm) +fn baml.media.Video.file = builtin(vm) -fn baml.media.Pdf.mime_type = builtin(vm) +fn baml.media.Video.base64 = builtin(vm) -fn baml.media.Image.mime_type = builtin(vm) +fn baml.media.Video.mime_type = builtin(vm) -fn baml.media.Audio.mime_type = builtin(vm) +fn baml.media.Video.from_url = builtin(vm) -fn baml.media.Video.mime_type = builtin(vm) +fn baml.media.Video.from_file = builtin(vm) -fn baml.media.Pdf.url = builtin(vm) +fn baml.media.Video.from_base64 = builtin(vm) fn baml.media.Image.url = builtin(vm) -fn baml.media.Audio.url = builtin(vm) +fn baml.media.Image.file = builtin(vm) -fn baml.media.Video.url = builtin(vm) +fn baml.media.Image.base64 = builtin(vm) -fn baml.net.TcpStream._connect = builtin(io) +fn baml.media.Image.mime_type = builtin(vm) -fn baml.net.TcpStream._read = builtin(io) +fn baml.media.Image.from_url = builtin(vm) -fn baml.net.UdpSocket._recv_from = builtin(io) +fn baml.media.Image.from_file = builtin(vm) -fn baml.net.UdpSocket._send_to = builtin(io) +fn baml.media.Image.from_base64 = builtin(vm) fn baml.net._timeout_nanos(timeout: null | baml.time.Duration) -> bigint { // Locals: @@ -7598,20 +7590,6 @@ fn baml.net._timeout_nanos(timeout: null | baml.time.Duration) -> bigint { } } -fn baml.net.TcpStream._write = builtin(io) - -fn baml.net.TcpListener.accept = builtin(io) - -fn baml.net.TcpListener.bind = builtin(io) - -fn baml.net.UdpSocket.bind = builtin(io) - -fn baml.net.TcpStream.close = builtin(io) - -fn baml.net.TcpListener.close = builtin(io) - -fn baml.net.UdpSocket.close = builtin(io) - fn baml.net.TcpStream.connect(addr: string, timeout: null | baml.time.Duration) -> baml.net.TcpStream { // Locals: let _0: baml.net.TcpStream // _0 // return @@ -7643,6 +7621,8 @@ fn baml.net.TcpStream.connect(addr: string, timeout: null | baml.time.Duration) } } +fn baml.net.TcpStream._connect = builtin(io) + fn baml.net.TcpStream.read(self: baml.net.TcpStream, timeout: null | baml.time.Duration) -> uint8array { // Locals: let _0: uint8array // _0 // return @@ -7674,30 +7654,33 @@ fn baml.net.TcpStream.read(self: baml.net.TcpStream, timeout: null | baml.time.D } } -fn baml.net.UdpSocket.recv_from(self: baml.net.UdpSocket, timeout: null | baml.time.Duration) -> baml.net.Datagram { +fn baml.net.TcpStream._read = builtin(io) + +fn baml.net.TcpStream.write(self: baml.net.TcpStream, data: uint8array, timeout: null | baml.time.Duration) -> null { // Locals: - let _0: baml.net.Datagram // _0 // return - let _1: baml.net.UdpSocket // self // param - let _2: null | baml.time.Duration // timeout // param - let _3: bool - let _4: bigint + let _0: null // _0 // return + let _1: baml.net.TcpStream // self // param + let _2: uint8array // data // param + let _3: null | baml.time.Duration // timeout // param + let _4: bool + let _5: bigint bb0: { - _3 = copy _2 == const ; - branch copy _3 -> [bb1, bb2]; + _4 = copy _3 == const ; + branch copy _4 -> [bb1, bb2]; } bb1: { - _2 = const null; + _3 = const null; goto -> bb2; } bb2: { - _4 = call const fn baml.net._timeout_nanos(copy _2) -> [bb3]; + _5 = call const fn baml.net._timeout_nanos(copy _3) -> [bb3]; } bb3: { - _0 = sys_op const fn baml.net.UdpSocket._recv_from(copy _1, copy _4) -> bb4; + _0 = sys_op const fn baml.net.TcpStream._write(copy _1, copy _2, copy _5) -> bb4; } bb4: { @@ -7705,6 +7688,18 @@ fn baml.net.UdpSocket.recv_from(self: baml.net.UdpSocket, timeout: null | baml.t } } +fn baml.net.TcpStream._write = builtin(io) + +fn baml.net.TcpStream.close = builtin(io) + +fn baml.net.TcpListener.bind = builtin(io) + +fn baml.net.TcpListener.accept = builtin(io) + +fn baml.net.TcpListener.close = builtin(io) + +fn baml.net.UdpSocket.bind = builtin(io) + fn baml.net.UdpSocket.send_to(self: baml.net.UdpSocket, data: uint8array, addr: string, timeout: null | baml.time.Duration) -> int { // Locals: let _0: int // _0 // return @@ -7738,31 +7733,32 @@ fn baml.net.UdpSocket.send_to(self: baml.net.UdpSocket, data: uint8array, addr: } } -fn baml.net.TcpStream.write(self: baml.net.TcpStream, data: uint8array, timeout: null | baml.time.Duration) -> null { +fn baml.net.UdpSocket._send_to = builtin(io) + +fn baml.net.UdpSocket.recv_from(self: baml.net.UdpSocket, timeout: null | baml.time.Duration) -> baml.net.Datagram { // Locals: - let _0: null // _0 // return - let _1: baml.net.TcpStream // self // param - let _2: uint8array // data // param - let _3: null | baml.time.Duration // timeout // param - let _4: bool - let _5: bigint + let _0: baml.net.Datagram // _0 // return + let _1: baml.net.UdpSocket // self // param + let _2: null | baml.time.Duration // timeout // param + let _3: bool + let _4: bigint bb0: { - _4 = copy _3 == const ; - branch copy _4 -> [bb1, bb2]; + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } bb1: { - _3 = const null; + _2 = const null; goto -> bb2; } bb2: { - _5 = call const fn baml.net._timeout_nanos(copy _3) -> [bb3]; + _4 = call const fn baml.net._timeout_nanos(copy _2) -> [bb3]; } bb3: { - _0 = sys_op const fn baml.net.TcpStream._write(copy _1, copy _2, copy _5) -> bb4; + _0 = sys_op const fn baml.net.UdpSocket._recv_from(copy _1, copy _4) -> bb4; } bb4: { @@ -7770,67 +7766,32 @@ fn baml.net.TcpStream.write(self: baml.net.TcpStream, data: uint8array, timeout: } } -fn baml.ops.Equals$for$bigint.eq = builtin(vm) - -fn baml.ops.Equals$for$null.eq(self: null, other: Self) -> bool { - // Locals: - let _0: bool // _0 // return - let _1: null // self // param - let _2: Self // other // param - - bb0: { - _0 = const true; - goto -> bb1; - } +fn baml.net.UdpSocket._recv_from = builtin(io) - bb1: { - return; - } -} +fn baml.net.UdpSocket.close = builtin(io) -fn baml.ops.Equals$for$T[].eq(self: T[], other: Self) -> bool { +fn baml.ops.Equals.neq(self: baml.ops.Equals, other: Self) -> bool { // Locals: let _0: bool // _0 // return - let _1: T[] // self // param + let _1: baml.ops.Equals // self // param let _2: Self // other // param + let _3: bool bb0: { - _0 = call const fn baml.ops.equals_equals(copy _1, copy _2) -> [bb1]; + _3 = virtual_call eq as baml.ops.Equals(copy _1, copy _2) -> [bb1]; } bb1: { - return; - } -} - -fn baml.ops.Equals$for$float.eq = builtin(vm) - -fn baml.ops.Equals$for$string.eq = builtin(vm) - -fn baml.ops.Equals$for$map.eq(self: map, other: Self) -> bool { - // Locals: - let _0: bool // _0 // return - let _1: map // self // param - let _2: Self // other // param - - bb0: { - _0 = call const fn baml.ops.equals_equals(copy _1, copy _2) -> [bb1]; + _0 = !copy _3; + goto -> bb2; } - bb1: { + bb2: { return; } } -fn baml.ops.Equals$for$int.eq = builtin(vm) - -fn baml.ops.Equals$for$bool.eq = builtin(vm) - -fn baml.ops.Equals$for$uint8array.eq = builtin(vm) - -fn baml.ops.equals_equals = builtin(vm) - -fn baml.ops.Compare.ge(self: baml.ops.Compare, other: Self) -> bool { +fn baml.ops.Compare.le(self: baml.ops.Compare, other: Self) -> bool { // Locals: let _0: bool // _0 // return let _1: baml.ops.Compare // self // param @@ -7842,33 +7803,31 @@ fn baml.ops.Compare.ge(self: baml.ops.Compare, other: Self) -> bool { } bb1: { - _0 = !copy _3; - goto -> bb2; + _0 = short_circuit(||) copy _3 -> [eval: bb2, join: bb3]; } bb2: { + _0 = virtual_call eq as baml.ops.Equals(copy _1, copy _2) -> [bb3]; + } + + bb3: { return; } } -fn baml.ops.Compare$for$float.ge = builtin(vm) - -fn baml.ops.Compare$for$string.ge = builtin(vm) - -fn baml.ops.Compare$for$float.gt = builtin(vm) - -fn baml.ops.Compare$for$bool.gt(self: bool, other: Self) -> bool { +fn baml.ops.Compare.gt(self: baml.ops.Compare, other: Self) -> bool { // Locals: let _0: bool // _0 // return - let _1: bool // self // param + let _1: baml.ops.Compare // self // param let _2: Self // other // param + let _3: bool bb0: { - _0 = short_circuit(&&) copy _1 -> [eval: bb1, join: bb2]; + _3 = virtual_call le as baml.ops.Compare(copy _1, copy _2) -> [bb1]; } bb1: { - _0 = !copy _2; + _0 = !copy _3; goto -> bb2; } @@ -7877,7 +7836,7 @@ fn baml.ops.Compare$for$bool.gt(self: bool, other: Self) -> bool { } } -fn baml.ops.Compare.gt(self: baml.ops.Compare, other: Self) -> bool { +fn baml.ops.Compare.ge(self: baml.ops.Compare, other: Self) -> bool { // Locals: let _0: bool // _0 // return let _1: baml.ops.Compare // self // param @@ -7885,7 +7844,7 @@ fn baml.ops.Compare.gt(self: baml.ops.Compare, other: Self) -> bool { let _3: bool bb0: { - _3 = virtual_call le as baml.ops.Compare(copy _1, copy _2) -> [bb1]; + _3 = virtual_call lt as baml.ops.Compare(copy _1, copy _2) -> [bb1]; } bb1: { @@ -7898,52 +7857,62 @@ fn baml.ops.Compare.gt(self: baml.ops.Compare, other: Self) -> bool { } } -fn baml.ops.Compare$for$string.gt = builtin(vm) +fn baml.ops.equals_equals = builtin(vm) + +fn baml.ops.Equals$for$int.eq = builtin(vm) + +fn baml.ops.Compare$for$int.lt = builtin(vm) + +fn baml.ops.Equals$for$bigint.eq = builtin(vm) + +fn baml.ops.Compare$for$bigint.lt = builtin(vm) + +fn baml.ops.Equals$for$float.eq = builtin(vm) + +fn baml.ops.Compare$for$float.lt = builtin(vm) + +fn baml.ops.Compare$for$float.gt = builtin(vm) + +fn baml.ops.Compare$for$float.ge = builtin(vm) fn baml.ops.Compare$for$float.le = builtin(vm) -fn baml.ops.Compare$for$string.le = builtin(vm) +fn baml.ops.Equals$for$bool.eq = builtin(vm) -fn baml.ops.Compare.le(self: baml.ops.Compare, other: Self) -> bool { +fn baml.ops.Compare$for$bool.lt(self: bool, other: Self) -> bool { // Locals: let _0: bool // _0 // return - let _1: baml.ops.Compare // self // param + let _1: bool // self // param let _2: Self // other // param let _3: bool bb0: { - _3 = virtual_call lt as baml.ops.Compare(copy _1, copy _2) -> [bb1]; + _3 = !copy _1; + _0 = short_circuit(&&) copy _3 -> [eval: bb1, join: bb2]; } bb1: { - _0 = short_circuit(||) copy _3 -> [eval: bb2, join: bb3]; + _0 = copy _2; + goto -> bb2; } bb2: { - _0 = virtual_call eq as baml.ops.Equals(copy _1, copy _2) -> [bb3]; - } - - bb3: { return; } } -fn baml.ops.Compare$for$int.lt = builtin(vm) - -fn baml.ops.Compare$for$bool.lt(self: bool, other: Self) -> bool { +fn baml.ops.Compare$for$bool.gt(self: bool, other: Self) -> bool { // Locals: let _0: bool // _0 // return let _1: bool // self // param let _2: Self // other // param - let _3: bool bb0: { - _3 = !copy _1; - _0 = short_circuit(&&) copy _3 -> [eval: bb1, join: bb2]; + _0 = short_circuit(&&) copy _1 -> [eval: bb1, join: bb2]; } bb1: { - _0 = copy _2; + _0 = !copy _2; goto -> bb2; } @@ -7952,29 +7921,18 @@ fn baml.ops.Compare$for$bool.lt(self: bool, other: Self) -> bool { } } -fn baml.ops.Compare$for$bigint.lt = builtin(vm) - -fn baml.ops.Compare$for$string.lt = builtin(vm) - -fn baml.ops.Compare$for$float.lt = builtin(vm) - -fn baml.ops.Equals.neq(self: baml.ops.Equals, other: Self) -> bool { +fn baml.ops.Equals$for$null.eq(self: null, other: Self) -> bool { // Locals: let _0: bool // _0 // return - let _1: baml.ops.Equals // self // param + let _1: null // self // param let _2: Self // other // param - let _3: bool bb0: { - _3 = virtual_call eq as baml.ops.Equals(copy _1, copy _2) -> [bb1]; + _0 = const true; + goto -> bb1; } bb1: { - _0 = !copy _3; - goto -> bb2; - } - - bb2: { return; } } @@ -7995,177 +7953,135 @@ fn baml.ops.Equals$for$null.neq(self: null, other: Self) -> bool { } } -fn baml.ops.__union_add = builtin(vm) - -fn baml.ops.__union_div = builtin(vm) - -fn baml.ops.__union_mul = builtin(vm) - -fn baml.ops.__union_neg = builtin(vm) - -fn baml.ops.__union_rem = builtin(vm) - -fn baml.ops.__union_sub = builtin(vm) - -fn baml.ops.Add$for$float.add = builtin(vm) - -fn baml.ops.Add$for$bigint.add = builtin(vm) - -fn baml.ops.Add$for$int.add = builtin(vm) - -fn baml.ops.Add$for$int.add = builtin(vm) - -fn baml.ops.Add$for$int.add = builtin(vm) - -fn baml.ops.Add$for$float.add = builtin(vm) +fn baml.ops.Equals$for$string.eq = builtin(vm) -fn baml.ops.Add$for$bigint.add = builtin(vm) +fn baml.ops.Compare$for$string.lt = builtin(vm) -fn baml.ops.Divide$for$int.div = builtin(vm) +fn baml.ops.Compare$for$string.gt = builtin(vm) -fn baml.ops.Divide$for$int.div = builtin(vm) +fn baml.ops.Compare$for$string.ge = builtin(vm) -fn baml.ops.Divide$for$int.div = builtin(vm) +fn baml.ops.Compare$for$string.le = builtin(vm) -fn baml.ops.Divide$for$float.div = builtin(vm) +fn baml.ops.Equals$for$uint8array.eq = builtin(vm) -fn baml.ops.Divide$for$bigint.div = builtin(vm) +fn baml.ops.Equals$for$T[].eq(self: T[], other: Self) -> bool { + // Locals: + let _0: bool // _0 // return + let _1: T[] // self // param + let _2: Self // other // param -fn baml.ops.Divide$for$float.div = builtin(vm) + bb0: { + _0 = call const fn baml.ops.equals_equals(copy _1, copy _2) -> [bb1]; + } -fn baml.ops.Divide$for$bigint.div = builtin(vm) + bb1: { + return; + } +} -fn baml.ops.Multiply$for$int.mul = builtin(vm) +fn baml.ops.Equals$for$map.eq(self: map, other: Self) -> bool { + // Locals: + let _0: bool // _0 // return + let _1: map // self // param + let _2: Self // other // param -fn baml.ops.Multiply$for$float.mul = builtin(vm) + bb0: { + _0 = call const fn baml.ops.equals_equals(copy _1, copy _2) -> [bb1]; + } -fn baml.ops.Multiply$for$bigint.mul = builtin(vm) + bb1: { + return; + } +} -fn baml.ops.Multiply$for$float.mul = builtin(vm) +fn baml.ops.Add$for$int.add = builtin(vm) -fn baml.ops.Multiply$for$bigint.mul = builtin(vm) +fn baml.ops.Subtract$for$int.sub = builtin(vm) fn baml.ops.Multiply$for$int.mul = builtin(vm) -fn baml.ops.Multiply$for$int.mul = builtin(vm) - -fn baml.ops.Negate$for$bigint.neg = builtin(vm) +fn baml.ops.Divide$for$int.div = builtin(vm) -fn baml.ops.Negate$for$float.neg = builtin(vm) +fn baml.ops.Remainder$for$int.rem = builtin(vm) fn baml.ops.Negate$for$int.neg = builtin(vm) -fn baml.ops.Remainder$for$float.rem = builtin(vm) +fn baml.ops.Add$for$float.add = builtin(vm) -fn baml.ops.Remainder$for$bigint.rem = builtin(vm) +fn baml.ops.Subtract$for$float.sub = builtin(vm) -fn baml.ops.Remainder$for$float.rem = builtin(vm) +fn baml.ops.Multiply$for$float.mul = builtin(vm) -fn baml.ops.Remainder$for$bigint.rem = builtin(vm) +fn baml.ops.Divide$for$float.div = builtin(vm) -fn baml.ops.Remainder$for$int.rem = builtin(vm) +fn baml.ops.Remainder$for$float.rem = builtin(vm) -fn baml.ops.Remainder$for$int.rem = builtin(vm) +fn baml.ops.Negate$for$float.neg = builtin(vm) -fn baml.ops.Remainder$for$int.rem = builtin(vm) +fn baml.ops.Add$for$float.add = builtin(vm) fn baml.ops.Subtract$for$float.sub = builtin(vm) -fn baml.ops.Subtract$for$bigint.sub = builtin(vm) +fn baml.ops.Multiply$for$float.mul = builtin(vm) -fn baml.ops.Subtract$for$float.sub = builtin(vm) +fn baml.ops.Divide$for$float.div = builtin(vm) -fn baml.ops.Subtract$for$bigint.sub = builtin(vm) +fn baml.ops.Remainder$for$float.rem = builtin(vm) -fn baml.ops.Subtract$for$int.sub = builtin(vm) +fn baml.ops.Add$for$int.add = builtin(vm) fn baml.ops.Subtract$for$int.sub = builtin(vm) -fn baml.ops.Subtract$for$int.sub = builtin(vm) +fn baml.ops.Multiply$for$int.mul = builtin(vm) -fn baml.random.ChaCha20._new = builtin(vm) +fn baml.ops.Divide$for$int.div = builtin(vm) -fn baml.random.Xoshiro256PlusPlus._new = builtin(vm) +fn baml.ops.Remainder$for$int.rem = builtin(vm) -fn baml.random.SystemRandom.get() -> baml.random.SystemRandom { - // Locals: - let _0: baml.random.SystemRandom // _0 // return +fn baml.ops.Add$for$bigint.add = builtin(vm) - bb0: { - _0 = baml.random.SystemRandom { }; - goto -> bb1; - } +fn baml.ops.Subtract$for$bigint.sub = builtin(vm) - bb1: { - return; - } -} +fn baml.ops.Multiply$for$bigint.mul = builtin(vm) -fn baml.random.ChaCha20.new(seed: uint8array) -> baml.random.ChaCha20 { - // Locals: - let _0: baml.random.ChaCha20 // _0 // return - let _1: uint8array // seed // param - let _2: bool - let _3: baml.random.SystemRandom +fn baml.ops.Divide$for$bigint.div = builtin(vm) - bb0: { - _2 = copy _1 == const ; - branch copy _2 -> [bb1, bb3]; - } +fn baml.ops.Remainder$for$bigint.rem = builtin(vm) - bb1: { - _3 = call const fn baml.random.SystemRandom.get() -> [bb2]; - } +fn baml.ops.Negate$for$bigint.neg = builtin(vm) - bb2: { - _1 = virtual_call random as baml.random.Rng(copy _3, const 32_i64) -> [bb3]; - } +fn baml.ops.Add$for$bigint.add = builtin(vm) - bb3: { - _0 = call const fn baml.random.ChaCha20._new(copy _1) -> [bb4]; - } +fn baml.ops.Subtract$for$bigint.sub = builtin(vm) - bb4: { - return; - } -} +fn baml.ops.Multiply$for$bigint.mul = builtin(vm) -fn baml.random.Xoshiro256PlusPlus.new(seed: uint8array) -> baml.random.Xoshiro256PlusPlus { - // Locals: - let _0: baml.random.Xoshiro256PlusPlus // _0 // return - let _1: uint8array // seed // param - let _2: bool - let _3: baml.random.SystemRandom +fn baml.ops.Divide$for$bigint.div = builtin(vm) - bb0: { - _2 = copy _1 == const ; - branch copy _2 -> [bb1, bb3]; - } +fn baml.ops.Remainder$for$bigint.rem = builtin(vm) - bb1: { - _3 = call const fn baml.random.SystemRandom.get() -> [bb2]; - } +fn baml.ops.Add$for$int.add = builtin(vm) - bb2: { - _1 = virtual_call random as baml.random.Rng(copy _3, const 32_i64) -> [bb3]; - } +fn baml.ops.Subtract$for$int.sub = builtin(vm) - bb3: { - _0 = call const fn baml.random.Xoshiro256PlusPlus._new(copy _1) -> [bb4]; - } +fn baml.ops.Multiply$for$int.mul = builtin(vm) - bb4: { - return; - } -} +fn baml.ops.Divide$for$int.div = builtin(vm) -fn baml.random.ChaCha20.Rng.random = builtin(vm) +fn baml.ops.Remainder$for$int.rem = builtin(vm) -fn baml.random.Xoshiro256PlusPlus.Rng.random = builtin(vm) +fn baml.ops.__union_add = builtin(vm) -fn baml.random.SystemRandom.Rng.random = builtin(io) +fn baml.ops.__union_sub = builtin(vm) -fn baml.random.Xoshiro256PlusPlus.Rng.random_int = builtin(vm) +fn baml.ops.__union_mul = builtin(vm) + +fn baml.ops.__union_div = builtin(vm) + +fn baml.ops.__union_rem = builtin(vm) + +fn baml.ops.__union_neg = builtin(vm) fn baml.random.Rng.random_int(self: baml.random.Rng) -> int { // Locals: @@ -8220,67 +8136,149 @@ fn baml.random.Rng.random_int(self: baml.random.Rng) -> int { let _48: int bb0: { - _2 = virtual_call random as baml.random.Rng(copy _1, const 8_i64) -> [bb1]; + _2 = virtual_call random as baml.random.Rng(copy _1, const 8_i64) -> [bb1]; + } + + bb1: { + _13 = copy _2; + _14 = const 0_i64; + _12 = copy _13[_14]; + _11 = copy _12 & const 63_i64; + _10 = copy _11 << const 56_i64; + _17 = copy _2; + _18 = const 1_i64; + _16 = copy _17[_18]; + _15 = copy _16 << const 48_i64; + _9 = copy _10 | copy _15; + _21 = copy _2; + _22 = const 2_i64; + _20 = copy _21[_22]; + _19 = copy _20 << const 40_i64; + _8 = copy _9 | copy _19; + _25 = copy _2; + _26 = const 3_i64; + _24 = copy _25[_26]; + _23 = copy _24 << const 32_i64; + _7 = copy _8 | copy _23; + _29 = copy _2; + _30 = const 4_i64; + _28 = copy _29[_30]; + _27 = copy _28 << const 24_i64; + _6 = copy _7 | copy _27; + _33 = copy _2; + _34 = const 5_i64; + _32 = copy _33[_34]; + _31 = copy _32 << const 16_i64; + _5 = copy _6 | copy _31; + _37 = copy _2; + _38 = const 6_i64; + _36 = copy _37[_38]; + _35 = copy _36 << const 8_i64; + _4 = copy _5 | copy _35; + _40 = copy _2; + _41 = const 7_i64; + _39 = copy _40[_41]; + _3 = copy _4 | copy _39; + _45 = copy _2; + _46 = const 0_i64; + _44 = copy _45[_46]; + _43 = copy _44 & const 64_i64; + _42 = copy _43 == const 0_i64; + branch copy _42 -> [bb3, bb2]; + } + + bb2: { + _48 = copy _3; + _47 = const 0_i64 - copy _48; + _0 = copy _47 - const 1_i64; + goto -> bb4; + } + + bb3: { + _0 = copy _3; + goto -> bb4; + } + + bb4: { + return; + } +} + +fn baml.random.SystemRandom.get() -> baml.random.SystemRandom { + // Locals: + let _0: baml.random.SystemRandom // _0 // return + + bb0: { + _0 = baml.random.SystemRandom { }; + goto -> bb1; + } + + bb1: { + return; + } +} + +fn baml.random.SystemRandom.Rng.random = builtin(io) + +fn baml.random.SystemRandom.Rng.random_int = builtin(io) + +fn baml.random.Xoshiro256PlusPlus.new(seed: uint8array) -> baml.random.Xoshiro256PlusPlus { + // Locals: + let _0: baml.random.Xoshiro256PlusPlus // _0 // return + let _1: uint8array // seed // param + let _2: bool + let _3: baml.random.SystemRandom + + bb0: { + _2 = copy _1 == const ; + branch copy _2 -> [bb1, bb3]; + } + + bb1: { + _3 = call const fn baml.random.SystemRandom.get() -> [bb2]; + } + + bb2: { + _1 = virtual_call random as baml.random.Rng(copy _3, const 32_i64) -> [bb3]; + } + + bb3: { + _0 = call const fn baml.random.Xoshiro256PlusPlus._new(copy _1) -> [bb4]; + } + + bb4: { + return; + } +} + +fn baml.random.Xoshiro256PlusPlus._new = builtin(vm) + +fn baml.random.Xoshiro256PlusPlus.Rng.random = builtin(vm) + +fn baml.random.Xoshiro256PlusPlus.Rng.random_int = builtin(vm) + +fn baml.random.ChaCha20.new(seed: uint8array) -> baml.random.ChaCha20 { + // Locals: + let _0: baml.random.ChaCha20 // _0 // return + let _1: uint8array // seed // param + let _2: bool + let _3: baml.random.SystemRandom + + bb0: { + _2 = copy _1 == const ; + branch copy _2 -> [bb1, bb3]; } bb1: { - _13 = copy _2; - _14 = const 0_i64; - _12 = copy _13[_14]; - _11 = copy _12 & const 63_i64; - _10 = copy _11 << const 56_i64; - _17 = copy _2; - _18 = const 1_i64; - _16 = copy _17[_18]; - _15 = copy _16 << const 48_i64; - _9 = copy _10 | copy _15; - _21 = copy _2; - _22 = const 2_i64; - _20 = copy _21[_22]; - _19 = copy _20 << const 40_i64; - _8 = copy _9 | copy _19; - _25 = copy _2; - _26 = const 3_i64; - _24 = copy _25[_26]; - _23 = copy _24 << const 32_i64; - _7 = copy _8 | copy _23; - _29 = copy _2; - _30 = const 4_i64; - _28 = copy _29[_30]; - _27 = copy _28 << const 24_i64; - _6 = copy _7 | copy _27; - _33 = copy _2; - _34 = const 5_i64; - _32 = copy _33[_34]; - _31 = copy _32 << const 16_i64; - _5 = copy _6 | copy _31; - _37 = copy _2; - _38 = const 6_i64; - _36 = copy _37[_38]; - _35 = copy _36 << const 8_i64; - _4 = copy _5 | copy _35; - _40 = copy _2; - _41 = const 7_i64; - _39 = copy _40[_41]; - _3 = copy _4 | copy _39; - _45 = copy _2; - _46 = const 0_i64; - _44 = copy _45[_46]; - _43 = copy _44 & const 64_i64; - _42 = copy _43 == const 0_i64; - branch copy _42 -> [bb3, bb2]; + _3 = call const fn baml.random.SystemRandom.get() -> [bb2]; } bb2: { - _48 = copy _3; - _47 = const 0_i64 - copy _48; - _0 = copy _47 - const 1_i64; - goto -> bb4; + _1 = virtual_call random as baml.random.Rng(copy _3, const 32_i64) -> [bb3]; } bb3: { - _0 = copy _3; - goto -> bb4; + _0 = call const fn baml.random.ChaCha20._new(copy _1) -> [bb4]; } bb4: { @@ -8288,27 +8286,33 @@ fn baml.random.Rng.random_int(self: baml.random.Rng) -> int { } } -fn baml.random.SystemRandom.Rng.random_int = builtin(io) - -fn baml.random.ChaCha20.Rng.random_int = builtin(vm) +fn baml.random.ChaCha20._new = builtin(vm) -fn baml.spawn.TaskGroup.active_count = builtin(vm) +fn baml.random.ChaCha20.Rng.random = builtin(vm) -fn baml.spawn.CancelToken.any = builtin(vm) +fn baml.random.ChaCha20.Rng.random_int = builtin(vm) -fn baml.spawn.CancelToken.cancel = builtin(vm) +fn baml.spawn.TaskGroup.new = builtin(vm) fn baml.spawn.TaskGroup.cancel = builtin(vm) -fn baml.spawn.CancelToken.is_cancelled = builtin(vm) +fn baml.spawn.TaskGroup.set_limit = builtin(vm) fn baml.spawn.TaskGroup.limit = builtin(vm) fn baml.spawn.TaskGroup.name = builtin(vm) +fn baml.spawn.TaskGroup.active_count = builtin(vm) + +fn baml.spawn.TaskGroup.queued_count = builtin(vm) + fn baml.spawn.CancelToken.new = builtin(vm) -fn baml.spawn.TaskGroup.new = builtin(vm) +fn baml.spawn.CancelToken.any = builtin(vm) + +fn baml.spawn.CancelToken.cancel = builtin(vm) + +fn baml.spawn.CancelToken.is_cancelled = builtin(vm) fn baml.spawn.options(group: null | baml.spawn.TaskGroup, cancel: null | baml.spawn.CancelToken, detach: bool | null) -> (baml.spawn.SpawnParams) -> baml.spawn.SpawnParams throws never { // Locals: @@ -8425,18 +8429,6 @@ fn .(params: baml.spawn.SpawnParams) -> null { } } -fn baml.spawn.TaskGroup.queued_count = builtin(vm) - -fn baml.spawn.TaskGroup.set_limit = builtin(vm) - -fn baml.sys.argv = builtin(vm) - -fn baml.sys.exec = builtin(io) - -fn baml.sys.exit = builtin(vm) - -fn baml.sys.now_ms = builtin(vm) - fn baml.sys.ShellOutput.ok(self: baml.sys.ShellOutput) -> bool { // Locals: let _0: bool // _0 // return @@ -8454,12 +8446,20 @@ fn baml.sys.ShellOutput.ok(self: baml.sys.ShellOutput) -> bool { } } -fn baml.sys.panic = builtin(vm) +fn baml.sys.exec = builtin(io) fn baml.sys.shell = builtin(io) fn baml.sys.sleep = builtin(io) +fn baml.sys.panic = builtin(vm) + +fn baml.sys.exit = builtin(vm) + +fn baml.sys.now_ms = builtin(vm) + +fn baml.sys.argv = builtin(vm) + fn baml.time.Duration.abs(self: baml.time.Duration) -> baml.time.Duration { // Locals: let _0: baml.time.Duration // _0 // return @@ -8482,37 +8482,35 @@ fn baml.time.Duration.abs(self: baml.time.Duration) -> baml.time.Duration { } } -fn baml.time.Duration.from_hours(h: int | bigint) -> baml.time.Duration { +fn baml.time.Duration.from_nanoseconds(ns: int | bigint) -> baml.time.Duration { // Locals: let _0: baml.time.Duration // _0 // return - let _1: int | bigint // h // param + let _1: int | bigint // ns // param let _2: bigint - let _3: bigint - let _4: bool - let _5: bigint // value - let _6: int // value - let _7: int + let _3: bool + let _4: bigint // value + let _5: int // value + let _6: int bb0: { - _4 = is_type(copy _1, bigint); - branch copy _4 -> [bb2, bb1]; + _3 = is_type(copy _1, bigint); + branch copy _3 -> [bb2, bb1]; } bb1: { - _6 = copy _1; - _7 = copy _6; - _3 = const 0n + copy _7; + _5 = copy _1; + _6 = copy _5; + _2 = const 0n + copy _6; goto -> bb3; } bb2: { - _5 = copy _1; - _3 = copy _5; + _4 = copy _1; + _2 = copy _4; goto -> bb3; } bb3: { - _2 = copy _3 * const 3600000000000n; _0 = baml.time.Duration { copy _2 }; goto -> bb4; } @@ -8602,10 +8600,10 @@ fn baml.time.Duration.from_milliseconds(ms: int | bigint) -> baml.time.Duration } } -fn baml.time.Duration.from_minutes(m: int | bigint) -> baml.time.Duration { +fn baml.time.Duration.from_seconds(s: int | bigint) -> baml.time.Duration { // Locals: let _0: baml.time.Duration // _0 // return - let _1: int | bigint // m // param + let _1: int | bigint // s // param let _2: bigint let _3: bigint let _4: bool @@ -8632,7 +8630,7 @@ fn baml.time.Duration.from_minutes(m: int | bigint) -> baml.time.Duration { } bb3: { - _2 = copy _3 * const 60000000000n; + _2 = copy _3 * const 1000000000n; _0 = baml.time.Duration { copy _2 }; goto -> bb4; } @@ -8642,35 +8640,37 @@ fn baml.time.Duration.from_minutes(m: int | bigint) -> baml.time.Duration { } } -fn baml.time.Duration.from_nanoseconds(ns: int | bigint) -> baml.time.Duration { +fn baml.time.Duration.from_minutes(m: int | bigint) -> baml.time.Duration { // Locals: let _0: baml.time.Duration // _0 // return - let _1: int | bigint // ns // param + let _1: int | bigint // m // param let _2: bigint - let _3: bool - let _4: bigint // value - let _5: int // value - let _6: int + let _3: bigint + let _4: bool + let _5: bigint // value + let _6: int // value + let _7: int bb0: { - _3 = is_type(copy _1, bigint); - branch copy _3 -> [bb2, bb1]; + _4 = is_type(copy _1, bigint); + branch copy _4 -> [bb2, bb1]; } bb1: { - _5 = copy _1; - _6 = copy _5; - _2 = const 0n + copy _6; + _6 = copy _1; + _7 = copy _6; + _3 = const 0n + copy _7; goto -> bb3; } bb2: { - _4 = copy _1; - _2 = copy _4; + _5 = copy _1; + _3 = copy _5; goto -> bb3; } bb3: { + _2 = copy _3 * const 60000000000n; _0 = baml.time.Duration { copy _2 }; goto -> bb4; } @@ -8680,10 +8680,10 @@ fn baml.time.Duration.from_nanoseconds(ns: int | bigint) -> baml.time.Duration { } } -fn baml.time.Duration.from_seconds(s: int | bigint) -> baml.time.Duration { +fn baml.time.Duration.from_hours(h: int | bigint) -> baml.time.Duration { // Locals: let _0: baml.time.Duration // _0 // return - let _1: int | bigint // s // param + let _1: int | bigint // h // param let _2: bigint let _3: bigint let _4: bool @@ -8710,7 +8710,7 @@ fn baml.time.Duration.from_seconds(s: int | bigint) -> baml.time.Duration { } bb3: { - _2 = copy _3 * const 1000000000n; + _2 = copy _3 * const 3600000000000n; _0 = baml.time.Duration { copy _2 }; goto -> bb4; } @@ -8720,15 +8720,13 @@ fn baml.time.Duration.from_seconds(s: int | bigint) -> baml.time.Duration { } } -fn baml.time.Duration.to_hours(self: baml.time.Duration) -> bigint { +fn baml.time.Duration.to_nanoseconds(self: baml.time.Duration) -> bigint { // Locals: let _0: bigint // _0 // return let _1: baml.time.Duration // self // param - let _2: bigint bb0: { - _2 = copy _1.0; - _0 = copy _2 / const 3600000000000_i64; + _0 = copy _1.0; goto -> bb1; } @@ -8771,7 +8769,7 @@ fn baml.time.Duration.to_milliseconds(self: baml.time.Duration) -> bigint { } } -fn baml.time.Duration.to_minutes(self: baml.time.Duration) -> bigint { +fn baml.time.Duration.to_seconds(self: baml.time.Duration) -> bigint { // Locals: let _0: bigint // _0 // return let _1: baml.time.Duration // self // param @@ -8779,7 +8777,7 @@ fn baml.time.Duration.to_minutes(self: baml.time.Duration) -> bigint { bb0: { _2 = copy _1.0; - _0 = copy _2 / const 60000000000_i64; + _0 = copy _2 / const 1000000000_i64; goto -> bb1; } @@ -8788,13 +8786,15 @@ fn baml.time.Duration.to_minutes(self: baml.time.Duration) -> bigint { } } -fn baml.time.Duration.to_nanoseconds(self: baml.time.Duration) -> bigint { +fn baml.time.Duration.to_minutes(self: baml.time.Duration) -> bigint { // Locals: let _0: bigint // _0 // return let _1: baml.time.Duration // self // param + let _2: bigint bb0: { - _0 = copy _1.0; + _2 = copy _1.0; + _0 = copy _2 / const 60000000000_i64; goto -> bb1; } @@ -8803,7 +8803,7 @@ fn baml.time.Duration.to_nanoseconds(self: baml.time.Duration) -> bigint { } } -fn baml.time.Duration.to_seconds(self: baml.time.Duration) -> bigint { +fn baml.time.Duration.to_hours(self: baml.time.Duration) -> bigint { // Locals: let _0: bigint // _0 // return let _1: baml.time.Duration // self // param @@ -8811,7 +8811,7 @@ fn baml.time.Duration.to_seconds(self: baml.time.Duration) -> bigint { bb0: { _2 = copy _1.0; - _0 = copy _2 / const 1000000000_i64; + _0 = copy _2 / const 3600000000000_i64; goto -> bb1; } @@ -8820,27 +8820,26 @@ fn baml.time.Duration.to_seconds(self: baml.time.Duration) -> bigint { } } -fn baml.time.Instant._to_string_impl = builtin(vm) +fn baml.time.Instant.now = builtin(io) -fn baml.time.Instant.abs_diff(self: baml.time.Instant, other: baml.time.Instant) -> baml.time.Duration { +fn baml.time.Instant.elapsed(self: baml.time.Instant) -> baml.time.Duration { // Locals: let _0: baml.time.Duration // _0 // return let _1: baml.time.Instant // self // param - let _2: baml.time.Instant // other // param + let _2: bigint let _3: bigint - let _4: bigint + let _4: baml.time.Instant let _5: bigint - let _6: bigint bb0: { - _5 = copy _1.0; - _6 = copy _2.0; - _4 = copy _5 - copy _6; - _3 = call const fn baml.Bigint.abs(copy _4) -> [bb1]; + _4 = sys_op const fn baml.time.Instant.now() -> bb1; } bb1: { - _0 = baml.time.Duration { copy _3 }; + _3 = copy _4.0; + _5 = copy _1.0; + _2 = copy _3 - copy _5; + _0 = baml.time.Duration { copy _2 }; goto -> bb2; } @@ -8849,46 +8848,47 @@ fn baml.time.Instant.abs_diff(self: baml.time.Instant, other: baml.time.Instant) } } -fn baml.time.Instant.elapsed(self: baml.time.Instant) -> baml.time.Duration { +fn baml.time.Instant.parse = builtin(vm) + +fn baml.time.Instant.baml.ToString.to_string(self: baml.time.Instant) -> string { // Locals: - let _0: baml.time.Duration // _0 // return + let _0: string // _0 // return let _1: baml.time.Instant // self // param - let _2: bigint - let _3: bigint - let _4: baml.time.Instant - let _5: bigint + let _2: unknown // _ + let _3: bool + let _4: string + let _5: string // message + let _6: string + let _7: string bb0: { - _4 = sys_op const fn baml.time.Instant.now() -> bb1; + _0 = call const fn baml.time.Instant._to_string_impl(copy _1) -> [bb4, unwind: bb1]; } bb1: { - _3 = copy _4.0; - _5 = copy _1.0; - _2 = copy _3 - copy _5; - _0 = baml.time.Duration { copy _2 }; - goto -> bb2; + _3 = is_type(copy _2, baml.errors.InvalidArgument); + branch copy _3 -> [bb3, bb2]; } bb2: { - return; + rethrow copy _2; } -} - -fn baml.time.Instant.epoch() -> baml.time.Instant { - // Locals: - let _0: baml.time.Instant // _0 // return - bb0: { - _0 = baml.time.Instant { const 0n }; - goto -> bb1; + bb3: { + _4 = copy _2.0; + _5 = copy _4; + _7 = copy _5; + _6 = const "Instant.to_string: " + copy _7; + _0 = call const fn baml.sys.panic(copy _6) -> [bb4]; } - bb1: { + bb4: { return; } } +fn baml.time.Instant._to_string_impl = builtin(vm) + fn baml.time.Instant.baml.FromJson.from_json(j: int | float | string | bool | null | baml.json.json[] | map) -> Self { // Locals: let _0: Self // _0 // return @@ -8938,69 +8938,40 @@ fn baml.time.Instant.baml.FromJson.from_json(j: int | float | string | bool | nu } } -fn baml.time.Instant.from_timestamp_microseconds(us: bigint) -> baml.time.Instant { - // Locals: - let _0: baml.time.Instant // _0 // return - let _1: bigint // us // param - let _2: bigint - - bb0: { - _2 = copy _1 * const 1000_i64; - _0 = baml.time.Instant { copy _2 }; - goto -> bb1; - } - - bb1: { - return; - } -} - -fn baml.time.Instant.from_timestamp_milliseconds(ms: bigint) -> baml.time.Instant { +fn baml.time.Instant.baml.ToJson.to_json(self: baml.time.Instant) -> int | float | string | bool | null | baml.json.json[] | map { // Locals: - let _0: baml.time.Instant // _0 // return - let _1: bigint // ms // param - let _2: bigint + let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return + let _1: baml.time.Instant // self // param + let _2: unknown // _ + let _3: bool + let _4: string + let _5: string // message + let _6: baml.json.JsonSerializationError + let _7: string bb0: { - _2 = copy _1 * const 1000000_i64; - _0 = baml.time.Instant { copy _2 }; - goto -> bb1; + _0 = call const fn baml.time.Instant._to_string_impl(copy _1) -> [bb1, unwind: bb2]; } bb1: { return; } -} - -fn baml.time.Instant.from_timestamp_nanoseconds(ns: bigint) -> baml.time.Instant { - // Locals: - let _0: baml.time.Instant // _0 // return - let _1: bigint // ns // param - - bb0: { - _0 = baml.time.Instant { copy _1 }; - goto -> bb1; - } - bb1: { - return; + bb2: { + _3 = is_type(copy _2, baml.errors.InvalidArgument); + branch copy _3 -> [bb4, bb3]; } -} - -fn baml.time.Instant.from_timestamp_seconds(s: bigint) -> baml.time.Instant { - // Locals: - let _0: baml.time.Instant // _0 // return - let _1: bigint // s // param - let _2: bigint - bb0: { - _2 = copy _1 * const 1000000000_i64; - _0 = baml.time.Instant { copy _2 }; - goto -> bb1; + bb3: { + rethrow copy _2; } - bb1: { - return; + bb4: { + _4 = copy _2.0; + _5 = copy _4; + _7 = copy _5; + _6 = baml.json.JsonSerializationError { copy _7, const "", const null }; + throw copy _6; } } @@ -9066,93 +9037,40 @@ fn baml.time.Instant.min(self: baml.time.Instant, other: baml.time.Instant) -> b } } -fn baml.time.Instant.now = builtin(io) - -fn baml.time.Instant.parse = builtin(vm) - -fn baml.time.Instant.baml.ToJson.to_json(self: baml.time.Instant) -> int | float | string | bool | null | baml.json.json[] | map { - // Locals: - let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return - let _1: baml.time.Instant // self // param - let _2: unknown // _ - let _3: bool - let _4: string - let _5: string // message - let _6: baml.json.JsonSerializationError - let _7: string - - bb0: { - _0 = call const fn baml.time.Instant._to_string_impl(copy _1) -> [bb1, unwind: bb2]; - } - - bb1: { - return; - } - - bb2: { - _3 = is_type(copy _2, baml.errors.InvalidArgument); - branch copy _3 -> [bb4, bb3]; - } - - bb3: { - rethrow copy _2; - } - - bb4: { - _4 = copy _2.0; - _5 = copy _4; - _7 = copy _5; - _6 = baml.json.JsonSerializationError { copy _7, const "", const null }; - throw copy _6; - } -} - -fn baml.time.Instant.baml.ToString.to_string(self: baml.time.Instant) -> string { +fn baml.time.Instant.abs_diff(self: baml.time.Instant, other: baml.time.Instant) -> baml.time.Duration { // Locals: - let _0: string // _0 // return + let _0: baml.time.Duration // _0 // return let _1: baml.time.Instant // self // param - let _2: unknown // _ - let _3: bool - let _4: string - let _5: string // message - let _6: string - let _7: string + let _2: baml.time.Instant // other // param + let _3: bigint + let _4: bigint + let _5: bigint + let _6: bigint bb0: { - _0 = call const fn baml.time.Instant._to_string_impl(copy _1) -> [bb4, unwind: bb1]; + _5 = copy _1.0; + _6 = copy _2.0; + _4 = copy _5 - copy _6; + _3 = call const fn baml.Bigint.abs(copy _4) -> [bb1]; } bb1: { - _3 = is_type(copy _2, baml.errors.InvalidArgument); - branch copy _3 -> [bb3, bb2]; + _0 = baml.time.Duration { copy _3 }; + goto -> bb2; } bb2: { - rethrow copy _2; - } - - bb3: { - _4 = copy _2.0; - _5 = copy _4; - _7 = copy _5; - _6 = const "Instant.to_string: " + copy _7; - _0 = call const fn baml.sys.panic(copy _6) -> [bb4]; - } - - bb4: { return; } } -fn baml.time.Instant.to_timestamp_microseconds(self: baml.time.Instant) -> bigint { +fn baml.time.Instant.from_timestamp_nanoseconds(ns: bigint) -> baml.time.Instant { // Locals: - let _0: bigint // _0 // return - let _1: baml.time.Instant // self // param - let _2: bigint + let _0: baml.time.Instant // _0 // return + let _1: bigint // ns // param bb0: { - _2 = copy _1.0; - _0 = copy _2 / const 1000_i64; + _0 = baml.time.Instant { copy _1 }; goto -> bb1; } @@ -9161,15 +9079,15 @@ fn baml.time.Instant.to_timestamp_microseconds(self: baml.time.Instant) -> bigin } } -fn baml.time.Instant.to_timestamp_milliseconds(self: baml.time.Instant) -> bigint { +fn baml.time.Instant.from_timestamp_microseconds(us: bigint) -> baml.time.Instant { // Locals: - let _0: bigint // _0 // return - let _1: baml.time.Instant // self // param + let _0: baml.time.Instant // _0 // return + let _1: bigint // us // param let _2: bigint bb0: { - _2 = copy _1.0; - _0 = copy _2 / const 1000000_i64; + _2 = copy _1 * const 1000_i64; + _0 = baml.time.Instant { copy _2 }; goto -> bb1; } @@ -9178,13 +9096,15 @@ fn baml.time.Instant.to_timestamp_milliseconds(self: baml.time.Instant) -> bigin } } -fn baml.time.Instant.to_timestamp_nanoseconds(self: baml.time.Instant) -> bigint { +fn baml.time.Instant.from_timestamp_milliseconds(ms: bigint) -> baml.time.Instant { // Locals: - let _0: bigint // _0 // return - let _1: baml.time.Instant // self // param + let _0: baml.time.Instant // _0 // return + let _1: bigint // ms // param + let _2: bigint bb0: { - _0 = copy _1.0; + _2 = copy _1 * const 1000000_i64; + _0 = baml.time.Instant { copy _2 }; goto -> bb1; } @@ -9193,147 +9113,107 @@ fn baml.time.Instant.to_timestamp_nanoseconds(self: baml.time.Instant) -> bigint } } -fn baml.time.Instant.to_timestamp_seconds(self: baml.time.Instant) -> bigint { +fn baml.time.Instant.from_timestamp_seconds(s: bigint) -> baml.time.Instant { // Locals: - let _0: bigint // _0 // return - let _1: baml.time.Instant // self // param + let _0: baml.time.Instant // _0 // return + let _1: bigint // s // param let _2: bigint bb0: { - _2 = copy _1.0; - _0 = copy _2 / const 1000000000_i64; + _2 = copy _1 * const 1000000000_i64; + _0 = baml.time.Instant { copy _2 }; goto -> bb1; } bb1: { - return; - } -} - -fn baml.time.PlainDate._to_plain_datetime = builtin(vm) - -fn baml.time.PlainDate._to_string_impl = builtin(vm) - -fn baml.time.PlainDate.day = builtin(vm) - -fn baml.time.PlainDate.from_components = builtin(vm) - -fn baml.time.PlainDate.baml.FromJson.from_json(j: int | float | string | bool | null | baml.json.json[] | map) -> Self { - // Locals: - let _0: Self // _0 // return - let _1: int | float | string | bool | null | baml.json.json[] | map // j // param - let _2: bool - let _3: unknown // _ - let _4: bool - let _5: string - let _6: string // message - let _7: baml.json.JsonDecodeError - let _8: string - let _9: baml.json.JsonDecodeError - - bb0: { - _2 = is_type(copy _1, string); - branch copy _2 -> [bb2, bb1]; - } - - bb1: { - _9 = baml.json.JsonDecodeError { const "Expected ISO 8601 date string", const "" }; - throw copy _9; - } - - bb2: { - _0 = call const fn baml.time.PlainDate.parse(copy _1) -> [bb3, unwind: bb4]; - } - - bb3: { - return; - } - - bb4: { - _4 = is_type(copy _3, baml.errors.ParseError); - branch copy _4 -> [bb6, bb5]; - } - - bb5: { - rethrow copy _3; - } - - bb6: { - _5 = copy _3.0; - _6 = copy _5; - _8 = copy _6; - _7 = baml.json.JsonDecodeError { copy _8, const "" }; - throw copy _7; + return; } } -fn baml.time.PlainDate.month = builtin(vm) +fn baml.time.Instant.to_timestamp_nanoseconds(self: baml.time.Instant) -> bigint { + // Locals: + let _0: bigint // _0 // return + let _1: baml.time.Instant // self // param -fn baml.time.PlainDate.parse = builtin(vm) + bb0: { + _0 = copy _1.0; + goto -> bb1; + } -fn baml.time.PlainDate.baml.ToJson.to_json(self: baml.time.PlainDate) -> int | float | string | bool | null | baml.json.json[] | map { + bb1: { + return; + } +} + +fn baml.time.Instant.to_timestamp_microseconds(self: baml.time.Instant) -> bigint { // Locals: - let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return - let _1: baml.time.PlainDate // self // param - let _2: unknown // _ - let _3: bool - let _4: string - let _5: string // message - let _6: baml.json.JsonSerializationError - let _7: string + let _0: bigint // _0 // return + let _1: baml.time.Instant // self // param + let _2: bigint bb0: { - _0 = call const fn baml.time.PlainDate._to_string_impl(copy _1) -> [bb1, unwind: bb2]; + _2 = copy _1.0; + _0 = copy _2 / const 1000_i64; + goto -> bb1; } bb1: { return; } +} - bb2: { - _3 = is_type(copy _2, baml.errors.InvalidArgument); - branch copy _3 -> [bb4, bb3]; - } +fn baml.time.Instant.to_timestamp_milliseconds(self: baml.time.Instant) -> bigint { + // Locals: + let _0: bigint // _0 // return + let _1: baml.time.Instant // self // param + let _2: bigint - bb3: { - rethrow copy _2; + bb0: { + _2 = copy _1.0; + _0 = copy _2 / const 1000000_i64; + goto -> bb1; } - bb4: { - _4 = copy _2.0; - _5 = copy _4; - _7 = copy _5; - _6 = baml.json.JsonSerializationError { copy _7, const "", const null }; - throw copy _6; + bb1: { + return; } } -fn baml.time.PlainDate.to_plain_datetime(self: baml.time.PlainDate, time: null | baml.time.PlainTime) -> baml.time.PlainDateTime { +fn baml.time.Instant.to_timestamp_seconds(self: baml.time.Instant) -> bigint { // Locals: - let _0: baml.time.PlainDateTime // _0 // return - let _1: baml.time.PlainDate // self // param - let _2: null | baml.time.PlainTime // time // param - let _3: bool + let _0: bigint // _0 // return + let _1: baml.time.Instant // self // param + let _2: bigint bb0: { - _3 = copy _2 == const ; - branch copy _3 -> [bb1, bb2]; + _2 = copy _1.0; + _0 = copy _2 / const 1000000000_i64; + goto -> bb1; } bb1: { - _2 = const null; - goto -> bb2; + return; } +} - bb2: { - _0 = call const fn baml.time.PlainDate._to_plain_datetime(copy _1, copy _2) -> [bb3]; +fn baml.time.Instant.epoch() -> baml.time.Instant { + // Locals: + let _0: baml.time.Instant // _0 // return + + bb0: { + _0 = baml.time.Instant { const 0n }; + goto -> bb1; } - bb3: { + bb1: { return; } } +fn baml.time.PlainDate.from_components = builtin(vm) + +fn baml.time.PlainDate.parse = builtin(vm) + fn baml.time.PlainDate.baml.ToString.to_string(self: baml.time.PlainDate) -> string { // Locals: let _0: string // _0 // return @@ -9371,103 +9251,43 @@ fn baml.time.PlainDate.baml.ToString.to_string(self: baml.time.PlainDate) -> str } } -fn baml.time.PlainDate.year = builtin(vm) - -fn baml.time.PlainDateTime._from_components = builtin(vm) - -fn baml.time.PlainDateTime._to_string_impl = builtin(vm) - -fn baml.time.PlainDateTime.day = builtin(vm) +fn baml.time.PlainDate._to_string_impl = builtin(vm) -fn baml.time.PlainDateTime.from_components(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int, microsecond: int, nanosecond: int) -> baml.time.PlainDateTime { +fn baml.time.PlainDate.to_plain_datetime(self: baml.time.PlainDate, time: null | baml.time.PlainTime) -> baml.time.PlainDateTime { // Locals: let _0: baml.time.PlainDateTime // _0 // return - let _1: int // year // param - let _2: int // month // param - let _3: int // day // param - let _4: int // hour // param - let _5: int // minute // param - let _6: int // second // param - let _7: int // millisecond // param - let _8: int // microsecond // param - let _9: int // nanosecond // param - let _10: bool - let _11: bool - let _12: bool - let _13: bool - let _14: bool - let _15: bool + let _1: baml.time.PlainDate // self // param + let _2: null | baml.time.PlainTime // time // param + let _3: bool bb0: { - _10 = copy _4 == const ; - branch copy _10 -> [bb1, bb2]; + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } bb1: { - _4 = const 0_i64; + _2 = const null; goto -> bb2; } bb2: { - _11 = copy _5 == const ; - branch copy _11 -> [bb3, bb4]; + _0 = call const fn baml.time.PlainDate._to_plain_datetime(copy _1, copy _2) -> [bb3]; } bb3: { - _5 = const 0_i64; - goto -> bb4; - } - - bb4: { - _12 = copy _6 == const ; - branch copy _12 -> [bb5, bb6]; - } - - bb5: { - _6 = const 0_i64; - goto -> bb6; - } - - bb6: { - _13 = copy _7 == const ; - branch copy _13 -> [bb7, bb8]; - } - - bb7: { - _7 = const 0_i64; - goto -> bb8; - } - - bb8: { - _14 = copy _8 == const ; - branch copy _14 -> [bb9, bb10]; - } - - bb9: { - _8 = const 0_i64; - goto -> bb10; + return; } +} - bb10: { - _15 = copy _9 == const ; - branch copy _15 -> [bb11, bb12]; - } +fn baml.time.PlainDate._to_plain_datetime = builtin(vm) - bb11: { - _9 = const 0_i64; - goto -> bb12; - } +fn baml.time.PlainDate.year = builtin(vm) - bb12: { - _0 = call const fn baml.time.PlainDateTime._from_components(copy _1, copy _2, copy _3, copy _4, copy _5, copy _6, copy _7, copy _8, copy _9) -> [bb13]; - } +fn baml.time.PlainDate.month = builtin(vm) - bb13: { - return; - } -} +fn baml.time.PlainDate.day = builtin(vm) -fn baml.time.PlainDateTime.baml.FromJson.from_json(j: int | float | string | bool | null | baml.json.json[] | map) -> Self { +fn baml.time.PlainDate.baml.FromJson.from_json(j: int | float | string | bool | null | baml.json.json[] | map) -> Self { // Locals: let _0: Self // _0 // return let _1: int | float | string | bool | null | baml.json.json[] | map // j // param @@ -9486,12 +9306,12 @@ fn baml.time.PlainDateTime.baml.FromJson.from_json(j: int | float | string | boo } bb1: { - _9 = baml.json.JsonDecodeError { const "Expected zoneless ISO 8601 string", const "" }; + _9 = baml.json.JsonDecodeError { const "Expected ISO 8601 date string", const "" }; throw copy _9; } bb2: { - _0 = call const fn baml.time.PlainDateTime.parse(copy _1) -> [bb3, unwind: bb4]; + _0 = call const fn baml.time.PlainDate.parse(copy _1) -> [bb3, unwind: bb4]; } bb3: { @@ -9507,93 +9327,19 @@ fn baml.time.PlainDateTime.baml.FromJson.from_json(j: int | float | string | boo rethrow copy _3; } - bb6: { - _5 = copy _3.0; - _6 = copy _5; - _8 = copy _6; - _7 = baml.json.JsonDecodeError { copy _8, const "" }; - throw copy _7; - } -} - -fn baml.time.PlainDateTime.hour = builtin(vm) - -fn baml.time.PlainDateTime.max(self: baml.time.PlainDateTime, other: baml.time.PlainDateTime) -> baml.time.PlainDateTime { - // Locals: - let _0: baml.time.PlainDateTime // _0 // return - let _1: baml.time.PlainDateTime // self // param - let _2: baml.time.PlainDateTime // other // param - let _3: bool - let _4: bigint - let _5: bigint - - bb0: { - _4 = copy _2.0; - _5 = copy _1.0; - _3 = copy _4 > copy _5; - branch copy _3 -> [bb2, bb1]; - } - - bb1: { - _0 = copy _1; - goto -> bb3; - } - - bb2: { - _0 = copy _2; - goto -> bb3; - } - - bb3: { - return; - } -} - -fn baml.time.PlainDateTime.millisecond = builtin(vm) - -fn baml.time.PlainDateTime.min(self: baml.time.PlainDateTime, other: baml.time.PlainDateTime) -> baml.time.PlainDateTime { - // Locals: - let _0: baml.time.PlainDateTime // _0 // return - let _1: baml.time.PlainDateTime // self // param - let _2: baml.time.PlainDateTime // other // param - let _3: bool - let _4: bigint - let _5: bigint - - bb0: { - _4 = copy _2.0; - _5 = copy _1.0; - _3 = copy _4 < copy _5; - branch copy _3 -> [bb2, bb1]; - } - - bb1: { - _0 = copy _1; - goto -> bb3; - } - - bb2: { - _0 = copy _2; - goto -> bb3; - } - - bb3: { - return; + bb6: { + _5 = copy _3.0; + _6 = copy _5; + _8 = copy _6; + _7 = baml.json.JsonDecodeError { copy _8, const "" }; + throw copy _7; } } -fn baml.time.PlainDateTime.minute = builtin(vm) - -fn baml.time.PlainDateTime.month = builtin(vm) - -fn baml.time.PlainDateTime.parse = builtin(vm) - -fn baml.time.PlainDateTime.second = builtin(vm) - -fn baml.time.PlainDateTime.baml.ToJson.to_json(self: baml.time.PlainDateTime) -> int | float | string | bool | null | baml.json.json[] | map { +fn baml.time.PlainDate.baml.ToJson.to_json(self: baml.time.PlainDate) -> int | float | string | bool | null | baml.json.json[] | map { // Locals: let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return - let _1: baml.time.PlainDateTime // self // param + let _1: baml.time.PlainDate // self // param let _2: unknown // _ let _3: bool let _4: string @@ -9602,7 +9348,7 @@ fn baml.time.PlainDateTime.baml.ToJson.to_json(self: baml.time.PlainDateTime) -> let _7: string bb0: { - _0 = call const fn baml.time.PlainDateTime._to_string_impl(copy _1) -> [bb1, unwind: bb2]; + _0 = call const fn baml.time.PlainDate._to_string_impl(copy _1) -> [bb1, unwind: bb2]; } bb1: { @@ -9627,9 +9373,97 @@ fn baml.time.PlainDateTime.baml.ToJson.to_json(self: baml.time.PlainDateTime) -> } } -fn baml.time.PlainDateTime.to_plain_date = builtin(vm) +fn baml.time.PlainDateTime.from_components(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int, microsecond: int, nanosecond: int) -> baml.time.PlainDateTime { + // Locals: + let _0: baml.time.PlainDateTime // _0 // return + let _1: int // year // param + let _2: int // month // param + let _3: int // day // param + let _4: int // hour // param + let _5: int // minute // param + let _6: int // second // param + let _7: int // millisecond // param + let _8: int // microsecond // param + let _9: int // nanosecond // param + let _10: bool + let _11: bool + let _12: bool + let _13: bool + let _14: bool + let _15: bool -fn baml.time.PlainDateTime.to_plain_time = builtin(vm) + bb0: { + _10 = copy _4 == const ; + branch copy _10 -> [bb1, bb2]; + } + + bb1: { + _4 = const 0_i64; + goto -> bb2; + } + + bb2: { + _11 = copy _5 == const ; + branch copy _11 -> [bb3, bb4]; + } + + bb3: { + _5 = const 0_i64; + goto -> bb4; + } + + bb4: { + _12 = copy _6 == const ; + branch copy _12 -> [bb5, bb6]; + } + + bb5: { + _6 = const 0_i64; + goto -> bb6; + } + + bb6: { + _13 = copy _7 == const ; + branch copy _13 -> [bb7, bb8]; + } + + bb7: { + _7 = const 0_i64; + goto -> bb8; + } + + bb8: { + _14 = copy _8 == const ; + branch copy _14 -> [bb9, bb10]; + } + + bb9: { + _8 = const 0_i64; + goto -> bb10; + } + + bb10: { + _15 = copy _9 == const ; + branch copy _15 -> [bb11, bb12]; + } + + bb11: { + _9 = const 0_i64; + goto -> bb12; + } + + bb12: { + _0 = call const fn baml.time.PlainDateTime._from_components(copy _1, copy _2, copy _3, copy _4, copy _5, copy _6, copy _7, copy _8, copy _9) -> [bb13]; + } + + bb13: { + return; + } +} + +fn baml.time.PlainDateTime._from_components = builtin(vm) + +fn baml.time.PlainDateTime.parse = builtin(vm) fn baml.time.PlainDateTime.baml.ToString.to_string(self: baml.time.PlainDateTime) -> string { // Locals: @@ -9668,6 +9502,8 @@ fn baml.time.PlainDateTime.baml.ToString.to_string(self: baml.time.PlainDateTime } } +fn baml.time.PlainDateTime._to_string_impl = builtin(vm) + fn baml.time.PlainDateTime.to_zoned(self: baml.time.PlainDateTime, timezone: string | baml.time.TimeZoneOffset, disambiguation: "compatible" | "earlier" | "later" | "reject") -> baml.time.ZonedDateTime { // Locals: let _0: baml.time.ZonedDateTime // _0 // return @@ -9814,40 +9650,200 @@ fn baml.time.PlainDateTime.to_zoned(self: baml.time.PlainDateTime, timezone: str goto -> bb20; } - bb20: { - _0 = baml.time.ZonedDateTime { copy _24, const null, copy _2 }; - goto -> bb24; + bb20: { + _0 = baml.time.ZonedDateTime { copy _24, const null, copy _2 }; + goto -> bb24; + } + + bb21: { + _19 = baml.time.UnknownTimezoneError { copy _2 }; + throw copy _19; + } + + bb22: { + _14 = baml.time.UnknownTimezoneError { copy _2 }; + throw copy _14; + } + + bb23: { + _7 = copy _1.0; + _8 = copy _2.0; + _6 = copy _7 - copy _8; + _9 = copy _2.0; + _0 = baml.time.ZonedDateTime { copy _6, copy _9, const null }; + goto -> bb24; + } + + bb24: { + return; + } +} + +fn baml.time.PlainDateTime.max(self: baml.time.PlainDateTime, other: baml.time.PlainDateTime) -> baml.time.PlainDateTime { + // Locals: + let _0: baml.time.PlainDateTime // _0 // return + let _1: baml.time.PlainDateTime // self // param + let _2: baml.time.PlainDateTime // other // param + let _3: bool + let _4: bigint + let _5: bigint + + bb0: { + _4 = copy _2.0; + _5 = copy _1.0; + _3 = copy _4 > copy _5; + branch copy _3 -> [bb2, bb1]; + } + + bb1: { + _0 = copy _1; + goto -> bb3; + } + + bb2: { + _0 = copy _2; + goto -> bb3; + } + + bb3: { + return; + } +} + +fn baml.time.PlainDateTime.min(self: baml.time.PlainDateTime, other: baml.time.PlainDateTime) -> baml.time.PlainDateTime { + // Locals: + let _0: baml.time.PlainDateTime // _0 // return + let _1: baml.time.PlainDateTime // self // param + let _2: baml.time.PlainDateTime // other // param + let _3: bool + let _4: bigint + let _5: bigint + + bb0: { + _4 = copy _2.0; + _5 = copy _1.0; + _3 = copy _4 < copy _5; + branch copy _3 -> [bb2, bb1]; + } + + bb1: { + _0 = copy _1; + goto -> bb3; + } + + bb2: { + _0 = copy _2; + goto -> bb3; + } + + bb3: { + return; + } +} + +fn baml.time.PlainDateTime.to_plain_date = builtin(vm) + +fn baml.time.PlainDateTime.to_plain_time = builtin(vm) + +fn baml.time.PlainDateTime.year = builtin(vm) + +fn baml.time.PlainDateTime.month = builtin(vm) + +fn baml.time.PlainDateTime.day = builtin(vm) + +fn baml.time.PlainDateTime.hour = builtin(vm) + +fn baml.time.PlainDateTime.minute = builtin(vm) + +fn baml.time.PlainDateTime.second = builtin(vm) + +fn baml.time.PlainDateTime.millisecond = builtin(vm) + +fn baml.time.PlainDateTime.baml.FromJson.from_json(j: int | float | string | bool | null | baml.json.json[] | map) -> Self { + // Locals: + let _0: Self // _0 // return + let _1: int | float | string | bool | null | baml.json.json[] | map // j // param + let _2: bool + let _3: unknown // _ + let _4: bool + let _5: string + let _6: string // message + let _7: baml.json.JsonDecodeError + let _8: string + let _9: baml.json.JsonDecodeError + + bb0: { + _2 = is_type(copy _1, string); + branch copy _2 -> [bb2, bb1]; + } + + bb1: { + _9 = baml.json.JsonDecodeError { const "Expected zoneless ISO 8601 string", const "" }; + throw copy _9; + } + + bb2: { + _0 = call const fn baml.time.PlainDateTime.parse(copy _1) -> [bb3, unwind: bb4]; + } + + bb3: { + return; + } + + bb4: { + _4 = is_type(copy _3, baml.errors.ParseError); + branch copy _4 -> [bb6, bb5]; } - bb21: { - _19 = baml.time.UnknownTimezoneError { copy _2 }; - throw copy _19; + bb5: { + rethrow copy _3; } - bb22: { - _14 = baml.time.UnknownTimezoneError { copy _2 }; - throw copy _14; + bb6: { + _5 = copy _3.0; + _6 = copy _5; + _8 = copy _6; + _7 = baml.json.JsonDecodeError { copy _8, const "" }; + throw copy _7; } +} - bb23: { - _7 = copy _1.0; - _8 = copy _2.0; - _6 = copy _7 - copy _8; - _9 = copy _2.0; - _0 = baml.time.ZonedDateTime { copy _6, copy _9, const null }; - goto -> bb24; +fn baml.time.PlainDateTime.baml.ToJson.to_json(self: baml.time.PlainDateTime) -> int | float | string | bool | null | baml.json.json[] | map { + // Locals: + let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return + let _1: baml.time.PlainDateTime // self // param + let _2: unknown // _ + let _3: bool + let _4: string + let _5: string // message + let _6: baml.json.JsonSerializationError + let _7: string + + bb0: { + _0 = call const fn baml.time.PlainDateTime._to_string_impl(copy _1) -> [bb1, unwind: bb2]; } - bb24: { + bb1: { return; } -} -fn baml.time.PlainDateTime.year = builtin(vm) + bb2: { + _3 = is_type(copy _2, baml.errors.InvalidArgument); + branch copy _3 -> [bb4, bb3]; + } -fn baml.time.PlainTime._from_components = builtin(vm) + bb3: { + rethrow copy _2; + } -fn baml.time.PlainTime._to_string_impl = builtin(vm) + bb4: { + _4 = copy _2.0; + _5 = copy _4; + _7 = copy _5; + _6 = baml.json.JsonSerializationError { copy _7, const "", const null }; + throw copy _6; + } +} fn baml.time.PlainTime.from_components(hour: int, minute: int, second: int, millisecond: int, microsecond: int, nanosecond: int) -> baml.time.PlainTime { // Locals: @@ -9923,65 +9919,34 @@ fn baml.time.PlainTime.from_components(hour: int, minute: int, second: int, mill } } -fn baml.time.PlainTime.baml.FromJson.from_json(j: int | float | string | bool | null | baml.json.json[] | map) -> Self { +fn baml.time.PlainTime._from_components = builtin(vm) + +fn baml.time.PlainTime.parse = builtin(vm) + +fn baml.time.PlainTime.baml.ToString.to_string(self: baml.time.PlainTime) -> string { // Locals: - let _0: Self // _0 // return - let _1: int | float | string | bool | null | baml.json.json[] | map // j // param - let _2: bool - let _3: unknown // _ - let _4: bool - let _5: string - let _6: string // message - let _7: baml.json.JsonDecodeError - let _8: string - let _9: baml.json.JsonDecodeError + let _0: string // _0 // return + let _1: baml.time.PlainTime // self // param bb0: { - _2 = is_type(copy _1, string); - branch copy _2 -> [bb2, bb1]; + _0 = call const fn baml.time.PlainTime._to_string_impl(copy _1) -> [bb1]; } bb1: { - _9 = baml.json.JsonDecodeError { const "Expected ISO 8601 time string", const "" }; - throw copy _9; - } - - bb2: { - _0 = call const fn baml.time.PlainTime.parse(copy _1) -> [bb3, unwind: bb4]; - } - - bb3: { return; } - - bb4: { - _4 = is_type(copy _3, baml.errors.ParseError); - branch copy _4 -> [bb6, bb5]; - } - - bb5: { - rethrow copy _3; - } - - bb6: { - _5 = copy _3.0; - _6 = copy _5; - _8 = copy _6; - _7 = baml.json.JsonDecodeError { copy _8, const "" }; - throw copy _7; - } } -fn baml.time.PlainTime.hour(self: baml.time.PlainTime) -> int { +fn baml.time.PlainTime._to_string_impl = builtin(vm) + +fn baml.time.PlainTime.to_plain_datetime(self: baml.time.PlainTime, date: baml.time.PlainDate) -> baml.time.PlainDateTime { // Locals: - let _0: int // _0 // return + let _0: baml.time.PlainDateTime // _0 // return let _1: baml.time.PlainTime // self // param - let _2: int + let _2: baml.time.PlainDate // date // param bb0: { - _2 = copy _1.0; - _0 = copy _2 / const 3600000000000_i64; - goto -> bb1; + _0 = call const fn baml.time.PlainDate.to_plain_datetime(copy _2, copy _1) -> [bb1]; } bb1: { @@ -9989,17 +9954,15 @@ fn baml.time.PlainTime.hour(self: baml.time.PlainTime) -> int { } } -fn baml.time.PlainTime.millisecond(self: baml.time.PlainTime) -> int { +fn baml.time.PlainTime.hour(self: baml.time.PlainTime) -> int { // Locals: let _0: int // _0 // return let _1: baml.time.PlainTime // self // param let _2: int - let _3: int bb0: { - _3 = copy _1.0; - _2 = copy _3 / const 1000000_i64; - _0 = copy _2 % const 1000_i64; + _2 = copy _1.0; + _0 = copy _2 / const 3600000000000_i64; goto -> bb1; } @@ -10027,8 +9990,6 @@ fn baml.time.PlainTime.minute(self: baml.time.PlainTime) -> int { } } -fn baml.time.PlainTime.parse = builtin(vm) - fn baml.time.PlainTime.second(self: baml.time.PlainTime) -> int { // Locals: let _0: int // _0 // return @@ -10048,49 +10009,18 @@ fn baml.time.PlainTime.second(self: baml.time.PlainTime) -> int { } } -fn baml.time.PlainTime.baml.ToJson.to_json(self: baml.time.PlainTime) -> int | float | string | bool | null | baml.json.json[] | map { - // Locals: - let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return - let _1: baml.time.PlainTime // self // param - let _2: string - let _3: type - - bb0: { - _2 = virtual_call to_string as baml.ToString(copy _1) -> [bb1]; - } - - bb1: { - _3 = load_type(string); - _0 = call const fn baml.json.from(copy _2) -> [bb2]; - } - - bb2: { - return; - } -} - -fn baml.time.PlainTime.to_plain_datetime(self: baml.time.PlainTime, date: baml.time.PlainDate) -> baml.time.PlainDateTime { - // Locals: - let _0: baml.time.PlainDateTime // _0 // return - let _1: baml.time.PlainTime // self // param - let _2: baml.time.PlainDate // date // param - - bb0: { - _0 = call const fn baml.time.PlainDate.to_plain_datetime(copy _2, copy _1) -> [bb1]; - } - - bb1: { - return; - } -} - -fn baml.time.PlainTime.baml.ToString.to_string(self: baml.time.PlainTime) -> string { +fn baml.time.PlainTime.millisecond(self: baml.time.PlainTime) -> int { // Locals: - let _0: string // _0 // return + let _0: int // _0 // return let _1: baml.time.PlainTime // self // param + let _2: int + let _3: int bb0: { - _0 = call const fn baml.time.PlainTime._to_string_impl(copy _1) -> [bb1]; + _3 = copy _1.0; + _2 = copy _3 / const 1000000_i64; + _0 = copy _2 % const 1000_i64; + goto -> bb1; } bb1: { @@ -10098,115 +10028,82 @@ fn baml.time.PlainTime.baml.ToString.to_string(self: baml.time.PlainTime) -> str } } -fn baml.time._tz_offset_at = builtin(io) - -fn baml.time._tz_to_instant = builtin(io) - -fn baml.time.TimeZoneOffset.from_duration = builtin(vm) - -fn baml.time.TimeZoneOffset.from_timezone(timezone: string, at: baml.time.Instant) -> baml.time.TimeZoneOffset { +fn baml.time.PlainTime.baml.FromJson.from_json(j: int | float | string | bool | null | baml.json.json[] | map) -> Self { // Locals: - let _0: baml.time.TimeZoneOffset // _0 // return - let _1: string // timezone // param - let _2: baml.time.Instant // at // param - let _3: int | null - let _4: bigint - let _5: bool - let _6: baml.time.UnknownTimezoneError - let _7: int | null // offset - let _8: int - let _9: int | null - let _10: bool + let _0: Self // _0 // return + let _1: int | float | string | bool | null | baml.json.json[] | map // j // param + let _2: bool + let _3: unknown // _ + let _4: bool + let _5: string + let _6: string // message + let _7: baml.json.JsonDecodeError + let _8: string + let _9: baml.json.JsonDecodeError bb0: { - _4 = copy _2.0; - _3 = sys_op const fn baml.time._tz_offset_at(copy _1, copy _4) -> bb1; + _2 = is_type(copy _1, string); + branch copy _2 -> [bb2, bb1]; } bb1: { - _5 = copy _3 == const null; - branch copy _5 -> [bb6, bb2]; + _9 = baml.json.JsonDecodeError { const "Expected ISO 8601 time string", const "" }; + throw copy _9; } bb2: { - _7 = copy _3; - _9 = copy _7; - _8 = copy _9; - _10 = copy _9 == const null; - branch copy _10 -> [bb3, bb4]; + _0 = call const fn baml.time.PlainTime.parse(copy _1) -> [bb3, unwind: bb4]; } bb3: { - _8 = const 0_i64; - goto -> bb4; + return; } bb4: { - _0 = baml.time.TimeZoneOffset { copy _8 }; - goto -> bb5; + _4 = is_type(copy _3, baml.errors.ParseError); + branch copy _4 -> [bb6, bb5]; } bb5: { - return; + rethrow copy _3; } bb6: { - _6 = baml.time.UnknownTimezoneError { copy _1 }; - throw copy _6; - } -} - -fn baml.time.TimeZoneOffset.hours(self: baml.time.TimeZoneOffset) -> int { - // Locals: - let _0: int // _0 // return - let _1: baml.time.TimeZoneOffset // self // param - let _2: int - - bb0: { - _2 = copy _1.0; - _0 = copy _2 / const 3600000000000_i64; - goto -> bb1; - } - - bb1: { - return; + _5 = copy _3.0; + _6 = copy _5; + _8 = copy _6; + _7 = baml.json.JsonDecodeError { copy _8, const "" }; + throw copy _7; } } -fn baml.time.TimeZoneOffset.local() -> baml.time.TimeZoneOffset { +fn baml.time.PlainTime.baml.ToJson.to_json(self: baml.time.PlainTime) -> int | float | string | bool | null | baml.json.json[] | map { // Locals: - let _0: baml.time.TimeZoneOffset // _0 // return - let _1: string - let _2: baml.time.Instant + let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return + let _1: baml.time.PlainTime // self // param + let _2: string + let _3: type bb0: { - _1 = sys_op const fn baml.time.system_timezone() -> bb1; + _2 = virtual_call to_string as baml.ToString(copy _1) -> [bb1]; } bb1: { - _2 = sys_op const fn baml.time.Instant.now() -> bb2; + _3 = load_type(string); + _0 = call const fn baml.json.from(copy _2) -> [bb2]; } bb2: { - _0 = call const fn baml.time.TimeZoneOffset.from_timezone(copy _1, copy _2) -> [bb3]; - } - - bb3: { return; } } -fn baml.time.TimeZoneOffset.minutes(self: baml.time.TimeZoneOffset) -> int { +fn baml.time.TimeZoneOffset.utc() -> baml.time.TimeZoneOffset { // Locals: - let _0: int // _0 // return - let _1: baml.time.TimeZoneOffset // self // param - let _2: int - let _3: int + let _0: baml.time.TimeZoneOffset // _0 // return bb0: { - _3 = copy _1.0; - _2 = copy _3 / const 60000000000_i64; - _0 = copy _2 % const 60_i64; + _0 = baml.time.TimeZoneOffset { const 0_i64 }; goto -> bb1; } @@ -10305,7 +10202,82 @@ fn baml.time.TimeZoneOffset.new(hours: int, minutes: int) -> baml.time.TimeZoneO } } -fn baml.time.system_timezone = builtin(io) +fn baml.time.TimeZoneOffset.from_timezone(timezone: string, at: baml.time.Instant) -> baml.time.TimeZoneOffset { + // Locals: + let _0: baml.time.TimeZoneOffset // _0 // return + let _1: string // timezone // param + let _2: baml.time.Instant // at // param + let _3: int | null + let _4: bigint + let _5: bool + let _6: baml.time.UnknownTimezoneError + let _7: int | null // offset + let _8: int + let _9: int | null + let _10: bool + + bb0: { + _4 = copy _2.0; + _3 = sys_op const fn baml.time._tz_offset_at(copy _1, copy _4) -> bb1; + } + + bb1: { + _5 = copy _3 == const null; + branch copy _5 -> [bb6, bb2]; + } + + bb2: { + _7 = copy _3; + _9 = copy _7; + _8 = copy _9; + _10 = copy _9 == const null; + branch copy _10 -> [bb3, bb4]; + } + + bb3: { + _8 = const 0_i64; + goto -> bb4; + } + + bb4: { + _0 = baml.time.TimeZoneOffset { copy _8 }; + goto -> bb5; + } + + bb5: { + return; + } + + bb6: { + _6 = baml.time.UnknownTimezoneError { copy _1 }; + throw copy _6; + } +} + +fn baml.time.TimeZoneOffset.local() -> baml.time.TimeZoneOffset { + // Locals: + let _0: baml.time.TimeZoneOffset // _0 // return + let _1: string + let _2: baml.time.Instant + + bb0: { + _1 = sys_op const fn baml.time.system_timezone() -> bb1; + } + + bb1: { + _2 = sys_op const fn baml.time.Instant.now() -> bb2; + } + + bb2: { + _0 = call const fn baml.time.TimeZoneOffset.from_timezone(copy _1, copy _2) -> [bb3]; + } + + bb3: { + return; + } +} + +fn baml.time.TimeZoneOffset.from_duration = builtin(vm) fn baml.time.TimeZoneOffset.to_duration(self: baml.time.TimeZoneOffset) -> baml.time.Duration { // Locals: @@ -10326,12 +10298,15 @@ fn baml.time.TimeZoneOffset.to_duration(self: baml.time.TimeZoneOffset) -> baml. } } -fn baml.time.TimeZoneOffset.utc() -> baml.time.TimeZoneOffset { +fn baml.time.TimeZoneOffset.hours(self: baml.time.TimeZoneOffset) -> int { // Locals: - let _0: baml.time.TimeZoneOffset // _0 // return + let _0: int // _0 // return + let _1: baml.time.TimeZoneOffset // self // param + let _2: int bb0: { - _0 = baml.time.TimeZoneOffset { const 0_i64 }; + _2 = copy _1.0; + _0 = copy _2 / const 3600000000000_i64; goto -> bb1; } @@ -10340,48 +10315,119 @@ fn baml.time.TimeZoneOffset.utc() -> baml.time.TimeZoneOffset { } } -fn baml.time._format_zoned = builtin(vm) - -fn baml.time.ZonedDateTime._to_string_impl(self: baml.time.ZonedDateTime) -> string { +fn baml.time.TimeZoneOffset.minutes(self: baml.time.TimeZoneOffset) -> int { // Locals: - let _0: string // _0 // return - let _1: baml.time.ZonedDateTime // self // param - let _2: bigint + let _0: int // _0 // return + let _1: baml.time.TimeZoneOffset // self // param + let _2: int let _3: int - let _4: baml.time.TimeZoneOffset - let _5: string | null bb0: { - _2 = copy _1.0; - _4 = call const fn baml.time.ZonedDateTime.timezone_offset(copy _1) -> [bb1]; + _3 = copy _1.0; + _2 = copy _3 / const 60000000000_i64; + _0 = copy _2 % const 60_i64; + goto -> bb1; } bb1: { - _3 = copy _4.0; - _5 = copy _1.2; - _0 = call const fn baml.time._format_zoned(copy _2, copy _3, copy _5) -> [bb2]; + return; + } +} + +fn baml.time.system_timezone = builtin(io) + +fn baml.time._tz_offset_at = builtin(io) + +fn baml.time._tz_to_instant = builtin(io) + +fn baml.time.ZonedDateTime.now() -> baml.time.ZonedDateTime { + // Locals: + let _0: baml.time.ZonedDateTime // _0 // return + let _1: baml.time.Instant + let _2: string + + bb0: { + _1 = sys_op const fn baml.time.Instant.now() -> bb1; + } + + bb1: { + _2 = sys_op const fn baml.time.system_timezone() -> bb2; } bb2: { + _0 = call const fn baml.time.ZonedDateTime.from_instant(copy _1, copy _2) -> [bb3]; + } + + bb3: { return; } } -fn baml.time.ZonedDateTime.day(self: baml.time.ZonedDateTime) -> int { +fn baml.time.ZonedDateTime.now_in(timezone: string | baml.time.TimeZoneOffset) -> baml.time.ZonedDateTime { // Locals: - let _0: int // _0 // return - let _1: baml.time.ZonedDateTime // self // param - let _2: baml.time.PlainDateTime + let _0: baml.time.ZonedDateTime // _0 // return + let _1: string | baml.time.TimeZoneOffset // timezone // param + let _2: baml.time.Instant bb0: { - _2 = call const fn baml.time.ZonedDateTime.to_plain(copy _1) -> [bb1]; + _2 = sys_op const fn baml.time.Instant.now() -> bb1; } bb1: { - _0 = call const fn baml.time.PlainDateTime.day(copy _2) -> [bb2]; + _0 = call const fn baml.time.ZonedDateTime.from_instant(copy _2, copy _1) -> [bb2]; + } + + bb2: { + return; + } +} + +fn baml.time.ZonedDateTime.from_instant(instant: baml.time.Instant, timezone: string | baml.time.TimeZoneOffset) -> baml.time.ZonedDateTime { + // Locals: + let _0: baml.time.ZonedDateTime // _0 // return + let _1: baml.time.Instant // instant // param + let _2: string | baml.time.TimeZoneOffset // timezone // param + let _3: bool + let _4: bigint + let _5: int + let _6: bigint + + bb0: { + _3 = is_type(copy _2, baml.time.TimeZoneOffset); + branch copy _3 -> [bb2, bb1]; + } + + bb1: { + _6 = copy _1.0; + _0 = baml.time.ZonedDateTime { copy _6, const null, copy _2 }; + goto -> bb3; } bb2: { + _4 = copy _1.0; + _5 = copy _2.0; + _0 = baml.time.ZonedDateTime { copy _4, copy _5, const null }; + goto -> bb3; + } + + bb3: { + return; + } +} + +fn baml.time.ZonedDateTime.to_instant(self: baml.time.ZonedDateTime) -> baml.time.Instant { + // Locals: + let _0: baml.time.Instant // _0 // return + let _1: baml.time.ZonedDateTime // self // param + let _2: bigint + + bb0: { + _2 = copy _1.0; + _0 = baml.time.Instant { copy _2 }; + goto -> bb1; + } + + bb1: { return; } } @@ -10484,108 +10530,57 @@ fn baml.time.ZonedDateTime.from_components(timezone: string | baml.time.TimeZone } bb15: { - _0 = call const fn baml.time.PlainDateTime.to_zoned(copy _19, copy _1, copy _11) -> [bb16]; - } - - bb16: { - return; - } -} - -fn baml.time.ZonedDateTime.from_instant(instant: baml.time.Instant, timezone: string | baml.time.TimeZoneOffset) -> baml.time.ZonedDateTime { - // Locals: - let _0: baml.time.ZonedDateTime // _0 // return - let _1: baml.time.Instant // instant // param - let _2: string | baml.time.TimeZoneOffset // timezone // param - let _3: bool - let _4: bigint - let _5: int - let _6: bigint - - bb0: { - _3 = is_type(copy _2, baml.time.TimeZoneOffset); - branch copy _3 -> [bb2, bb1]; - } - - bb1: { - _6 = copy _1.0; - _0 = baml.time.ZonedDateTime { copy _6, const null, copy _2 }; - goto -> bb3; - } - - bb2: { - _4 = copy _1.0; - _5 = copy _2.0; - _0 = baml.time.ZonedDateTime { copy _4, copy _5, const null }; - goto -> bb3; + _0 = call const fn baml.time.PlainDateTime.to_zoned(copy _19, copy _1, copy _11) -> [bb16]; } - bb3: { + bb16: { return; } } -fn baml.time.ZonedDateTime.baml.FromJson.from_json(j: int | float | string | bool | null | baml.json.json[] | map) -> Self { +fn baml.time.ZonedDateTime.parse = builtin(vm) + +fn baml.time.ZonedDateTime.baml.ToString.to_string(self: baml.time.ZonedDateTime) -> string { // Locals: - let _0: Self // _0 // return - let _1: int | float | string | bool | null | baml.json.json[] | map // j // param - let _2: bool - let _3: unknown // _ - let _4: bool - let _5: string - let _6: string // message - let _7: baml.json.JsonDecodeError - let _8: string - let _9: baml.json.JsonDecodeError + let _0: string // _0 // return + let _1: baml.time.ZonedDateTime // self // param + let _2: unknown // _ bb0: { - _2 = is_type(copy _1, string); - branch copy _2 -> [bb2, bb1]; + _0 = call const fn baml.time.ZonedDateTime._to_string_impl(copy _1) -> [bb3, unwind: bb1]; } bb1: { - _9 = baml.json.JsonDecodeError { const "Expected RFC 3339 / RFC 9557 timestamp string", const "" }; - throw copy _9; + throw_if_panic copy _2 -> bb2; } bb2: { - _0 = call const fn baml.time.ZonedDateTime.parse(copy _1) -> [bb3, unwind: bb4]; + _0 = call const fn baml.sys.panic(const "ZonedDateTime.to_string: value cannot be formatted (year out of range, unknown timezone, or IO error)") -> [bb3]; } bb3: { return; } - - bb4: { - _4 = is_type(copy _3, baml.errors.ParseError); - branch copy _4 -> [bb6, bb5]; - } - - bb5: { - rethrow copy _3; - } - - bb6: { - _5 = copy _3.0; - _6 = copy _5; - _8 = copy _6; - _7 = baml.json.JsonDecodeError { copy _8, const "" }; - throw copy _7; - } } -fn baml.time.ZonedDateTime.hour(self: baml.time.ZonedDateTime) -> int { +fn baml.time.ZonedDateTime._to_string_impl(self: baml.time.ZonedDateTime) -> string { // Locals: - let _0: int // _0 // return + let _0: string // _0 // return let _1: baml.time.ZonedDateTime // self // param - let _2: baml.time.PlainDateTime + let _2: bigint + let _3: int + let _4: baml.time.TimeZoneOffset + let _5: string | null bb0: { - _2 = call const fn baml.time.ZonedDateTime.to_plain(copy _1) -> [bb1]; + _2 = copy _1.0; + _4 = call const fn baml.time.ZonedDateTime.timezone_offset(copy _1) -> [bb1]; } bb1: { - _0 = call const fn baml.time.PlainDateTime.hour(copy _2) -> [bb2]; + _3 = copy _4.0; + _5 = copy _1.2; + _0 = call const fn baml.time._format_zoned(copy _2, copy _3, copy _5) -> [bb2]; } bb2: { @@ -10624,25 +10619,6 @@ fn baml.time.ZonedDateTime.max(self: baml.time.ZonedDateTime, other: baml.time.Z } } -fn baml.time.ZonedDateTime.millisecond(self: baml.time.ZonedDateTime) -> int { - // Locals: - let _0: int // _0 // return - let _1: baml.time.ZonedDateTime // self // param - let _2: baml.time.PlainDateTime - - bb0: { - _2 = call const fn baml.time.ZonedDateTime.to_plain(copy _1) -> [bb1]; - } - - bb1: { - _0 = call const fn baml.time.PlainDateTime.millisecond(copy _2) -> [bb2]; - } - - bb2: { - return; - } -} - fn baml.time.ZonedDateTime.min(self: baml.time.ZonedDateTime, other: baml.time.ZonedDateTime) -> baml.time.ZonedDateTime { // Locals: let _0: baml.time.ZonedDateTime // _0 // return @@ -10674,100 +10650,19 @@ fn baml.time.ZonedDateTime.min(self: baml.time.ZonedDateTime, other: baml.time.Z } } -fn baml.time.ZonedDateTime.minute(self: baml.time.ZonedDateTime) -> int { - // Locals: - let _0: int // _0 // return - let _1: baml.time.ZonedDateTime // self // param - let _2: baml.time.PlainDateTime - - bb0: { - _2 = call const fn baml.time.ZonedDateTime.to_plain(copy _1) -> [bb1]; - } - - bb1: { - _0 = call const fn baml.time.PlainDateTime.minute(copy _2) -> [bb2]; - } - - bb2: { - return; - } -} - -fn baml.time.ZonedDateTime.month(self: baml.time.ZonedDateTime) -> int { - // Locals: - let _0: int // _0 // return - let _1: baml.time.ZonedDateTime // self // param - let _2: baml.time.PlainDateTime - - bb0: { - _2 = call const fn baml.time.ZonedDateTime.to_plain(copy _1) -> [bb1]; - } - - bb1: { - _0 = call const fn baml.time.PlainDateTime.month(copy _2) -> [bb2]; - } - - bb2: { - return; - } -} - -fn baml.time.ZonedDateTime.now() -> baml.time.ZonedDateTime { - // Locals: - let _0: baml.time.ZonedDateTime // _0 // return - let _1: baml.time.Instant - let _2: string - - bb0: { - _1 = sys_op const fn baml.time.Instant.now() -> bb1; - } - - bb1: { - _2 = sys_op const fn baml.time.system_timezone() -> bb2; - } - - bb2: { - _0 = call const fn baml.time.ZonedDateTime.from_instant(copy _1, copy _2) -> [bb3]; - } - - bb3: { - return; - } -} - -fn baml.time.ZonedDateTime.now_in(timezone: string | baml.time.TimeZoneOffset) -> baml.time.ZonedDateTime { +fn baml.time.ZonedDateTime.with_timezone(self: baml.time.ZonedDateTime, timezone: string | baml.time.TimeZoneOffset) -> baml.time.ZonedDateTime { // Locals: let _0: baml.time.ZonedDateTime // _0 // return - let _1: string | baml.time.TimeZoneOffset // timezone // param - let _2: baml.time.Instant - - bb0: { - _2 = sys_op const fn baml.time.Instant.now() -> bb1; - } - - bb1: { - _0 = call const fn baml.time.ZonedDateTime.from_instant(copy _2, copy _1) -> [bb2]; - } - - bb2: { - return; - } -} - -fn baml.time.ZonedDateTime.parse = builtin(vm) - -fn baml.time.ZonedDateTime.second(self: baml.time.ZonedDateTime) -> int { - // Locals: - let _0: int // _0 // return let _1: baml.time.ZonedDateTime // self // param - let _2: baml.time.PlainDateTime + let _2: string | baml.time.TimeZoneOffset // timezone // param + let _3: baml.time.Instant bb0: { - _2 = call const fn baml.time.ZonedDateTime.to_plain(copy _1) -> [bb1]; + _3 = call const fn baml.time.ZonedDateTime.to_instant(copy _1) -> [bb1]; } bb1: { - _0 = call const fn baml.time.PlainDateTime.second(copy _2) -> [bb2]; + _0 = call const fn baml.time.ZonedDateTime.from_instant(copy _3, copy _2) -> [bb2]; } bb2: { @@ -10915,120 +10810,28 @@ fn baml.time.ZonedDateTime.timezone_offset(self: baml.time.ZonedDateTime) -> bam bb10: { _14 = baml.time.UnknownTimezoneError { copy _15 }; - throw copy _14; - } - - bb11: { - _5 = copy _1.1; - _4 = copy _5; - _6 = copy _5 == const null; - branch copy _6 -> [bb12, bb13]; - } - - bb12: { - _4 = const 0_i64; - goto -> bb13; - } - - bb13: { - _0 = baml.time.TimeZoneOffset { copy _4 }; - goto -> bb14; - } - - bb14: { - return; - } -} - -fn baml.time.ZonedDateTime.to_instant(self: baml.time.ZonedDateTime) -> baml.time.Instant { - // Locals: - let _0: baml.time.Instant // _0 // return - let _1: baml.time.ZonedDateTime // self // param - let _2: bigint - - bb0: { - _2 = copy _1.0; - _0 = baml.time.Instant { copy _2 }; - goto -> bb1; - } - - bb1: { - return; - } -} - -fn baml.time.ZonedDateTime.baml.ToJson.to_json(self: baml.time.ZonedDateTime) -> int | float | string | bool | null | baml.json.json[] | map { - // Locals: - let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return - let _1: baml.time.ZonedDateTime // self // param - let _2: unknown // _ - let _3: bool - let _4: bool - let _5: bool - let _6: string - let _7: string // message - let _8: baml.json.JsonSerializationError - let _9: string - let _10: string - let _11: string // timezone - let _12: baml.json.JsonSerializationError - let _13: string - let _14: string - let _15: string - let _16: string // message - let _17: baml.json.JsonSerializationError - let _18: string - - bb0: { - _0 = call const fn baml.time.ZonedDateTime._to_string_impl(copy _1) -> [bb1, unwind: bb2]; - } - - bb1: { - return; - } - - bb2: { - _3 = is_type(copy _2, baml.errors.InvalidArgument); - branch copy _3 -> [bb8, bb3]; - } - - bb3: { - _4 = is_type(copy _2, baml.time.UnknownTimezoneError); - branch copy _4 -> [bb7, bb4]; - } - - bb4: { - _5 = is_type(copy _2, baml.errors.Io); - branch copy _5 -> [bb6, bb5]; + throw copy _14; } - bb5: { - rethrow copy _2; + bb11: { + _5 = copy _1.1; + _4 = copy _5; + _6 = copy _5 == const null; + branch copy _6 -> [bb12, bb13]; } - bb6: { - _15 = copy _2.0; - _16 = copy _15; - _18 = copy _16; - _17 = baml.json.JsonSerializationError { copy _18, const "", const null }; - throw copy _17; + bb12: { + _4 = const 0_i64; + goto -> bb13; } - bb7: { - _10 = copy _2.0; - _11 = copy _10; - _14 = copy _11; - _13 = const "unknown timezone: " + copy _14; - _12 = baml.json.JsonSerializationError { copy _13, const "", const null }; - throw copy _12; + bb13: { + _0 = baml.time.TimeZoneOffset { copy _4 }; + goto -> bb14; } - bb8: { - _6 = copy _2.0; - _7 = copy _6; - _9 = copy _7; - _8 = baml.json.JsonSerializationError { copy _9, const "", const null }; - throw copy _8; + bb14: { + return; } } @@ -11058,42 +10861,56 @@ fn baml.time.ZonedDateTime.to_plain(self: baml.time.ZonedDateTime) -> baml.time. } } -fn baml.time.ZonedDateTime.baml.ToString.to_string(self: baml.time.ZonedDateTime) -> string { +fn baml.time.ZonedDateTime.year(self: baml.time.ZonedDateTime) -> int { // Locals: - let _0: string // _0 // return + let _0: int // _0 // return let _1: baml.time.ZonedDateTime // self // param - let _2: unknown // _ + let _2: baml.time.PlainDateTime bb0: { - _0 = call const fn baml.time.ZonedDateTime._to_string_impl(copy _1) -> [bb3, unwind: bb1]; + _2 = call const fn baml.time.ZonedDateTime.to_plain(copy _1) -> [bb1]; } bb1: { - throw_if_panic copy _2 -> bb2; + _0 = call const fn baml.time.PlainDateTime.year(copy _2) -> [bb2]; } bb2: { - _0 = call const fn baml.sys.panic(const "ZonedDateTime.to_string: value cannot be formatted (year out of range, unknown timezone, or IO error)") -> [bb3]; + return; + } +} + +fn baml.time.ZonedDateTime.month(self: baml.time.ZonedDateTime) -> int { + // Locals: + let _0: int // _0 // return + let _1: baml.time.ZonedDateTime // self // param + let _2: baml.time.PlainDateTime + + bb0: { + _2 = call const fn baml.time.ZonedDateTime.to_plain(copy _1) -> [bb1]; } - bb3: { + bb1: { + _0 = call const fn baml.time.PlainDateTime.month(copy _2) -> [bb2]; + } + + bb2: { return; } } -fn baml.time.ZonedDateTime.with_timezone(self: baml.time.ZonedDateTime, timezone: string | baml.time.TimeZoneOffset) -> baml.time.ZonedDateTime { +fn baml.time.ZonedDateTime.day(self: baml.time.ZonedDateTime) -> int { // Locals: - let _0: baml.time.ZonedDateTime // _0 // return + let _0: int // _0 // return let _1: baml.time.ZonedDateTime // self // param - let _2: string | baml.time.TimeZoneOffset // timezone // param - let _3: baml.time.Instant + let _2: baml.time.PlainDateTime bb0: { - _3 = call const fn baml.time.ZonedDateTime.to_instant(copy _1) -> [bb1]; + _2 = call const fn baml.time.ZonedDateTime.to_plain(copy _1) -> [bb1]; } bb1: { - _0 = call const fn baml.time.ZonedDateTime.from_instant(copy _3, copy _2) -> [bb2]; + _0 = call const fn baml.time.PlainDateTime.day(copy _2) -> [bb2]; } bb2: { @@ -11101,7 +10918,7 @@ fn baml.time.ZonedDateTime.with_timezone(self: baml.time.ZonedDateTime, timezone } } -fn baml.time.ZonedDateTime.year(self: baml.time.ZonedDateTime) -> int { +fn baml.time.ZonedDateTime.hour(self: baml.time.ZonedDateTime) -> int { // Locals: let _0: int // _0 // return let _1: baml.time.ZonedDateTime // self // param @@ -11112,7 +10929,7 @@ fn baml.time.ZonedDateTime.year(self: baml.time.ZonedDateTime) -> int { } bb1: { - _0 = call const fn baml.time.PlainDateTime.year(copy _2) -> [bb2]; + _0 = call const fn baml.time.PlainDateTime.hour(copy _2) -> [bb2]; } bb2: { @@ -11120,116 +10937,217 @@ fn baml.time.ZonedDateTime.year(self: baml.time.ZonedDateTime) -> int { } } -fn baml.toml.Table.baml.FromJson.from_json(j: int | float | string | bool | null | baml.json.json[] | map) -> Self { +fn baml.time.ZonedDateTime.minute(self: baml.time.ZonedDateTime) -> int { // Locals: - let _0: Self // _0 // return - let _1: int | float | string | bool | null | baml.json.json[] | map // j // param + let _0: int // _0 // return + let _1: baml.time.ZonedDateTime // self // param + let _2: baml.time.PlainDateTime bb0: { - _0 = call const fn baml.toml.table_from_json(copy _1) -> [bb1]; + _2 = call const fn baml.time.ZonedDateTime.to_plain(copy _1) -> [bb1]; } bb1: { + _0 = call const fn baml.time.PlainDateTime.minute(copy _2) -> [bb2]; + } + + bb2: { return; } } -fn baml.toml.item_from_json(json: int | float | string | bool | null | baml.json.json[] | map) -> int | float | string | bool | baml.time.PlainDate | baml.time.PlainDateTime | baml.time.PlainTime | baml.time.ZonedDateTime | baml.toml.Table | baml.toml.Item[] { +fn baml.time.ZonedDateTime.second(self: baml.time.ZonedDateTime) -> int { // Locals: - let _0: int | float | string | bool | baml.time.PlainDate | baml.time.PlainDateTime | baml.time.PlainTime | baml.time.ZonedDateTime | baml.toml.Table | baml.toml.Item[] // _0 // return - let _1: int | float | string | bool | null | baml.json.json[] | map // json // param - let _2: int - let _3: baml.json.JsonDecodeError - let _4: type - let _5: type - let _6: type + let _0: int // _0 // return + let _1: baml.time.ZonedDateTime // self // param + let _2: baml.time.PlainDateTime bb0: { - _2 = type_tag(_1); - switch copy _2 [bool: bb5, int: bb5, float: bb5, string: bb5, null: bb4, map: bb3, list: bb2, otherwise: bb1] (exhaustive); + _2 = call const fn baml.time.ZonedDateTime.to_plain(copy _1) -> [bb1]; } bb1: { - unreachable; + _0 = call const fn baml.time.PlainDateTime.second(copy _2) -> [bb2]; } bb2: { - _4 = load_type(baml.toml.Item); - _5 = load_type(baml.json.JsonDecodeError); - _6 = load_type(baml.json.json); - _0 = call const fn baml.Array.map(copy _1, const fn baml.toml.item_from_json) -> [bb6]; + return; + } +} + +fn baml.time.ZonedDateTime.millisecond(self: baml.time.ZonedDateTime) -> int { + // Locals: + let _0: int // _0 // return + let _1: baml.time.ZonedDateTime // self // param + let _2: baml.time.PlainDateTime + + bb0: { + _2 = call const fn baml.time.ZonedDateTime.to_plain(copy _1) -> [bb1]; + } + + bb1: { + _0 = call const fn baml.time.PlainDateTime.millisecond(copy _2) -> [bb2]; + } + + bb2: { + return; + } +} + +fn baml.time.ZonedDateTime.baml.FromJson.from_json(j: int | float | string | bool | null | baml.json.json[] | map) -> Self { + // Locals: + let _0: Self // _0 // return + let _1: int | float | string | bool | null | baml.json.json[] | map // j // param + let _2: bool + let _3: unknown // _ + let _4: bool + let _5: string + let _6: string // message + let _7: baml.json.JsonDecodeError + let _8: string + let _9: baml.json.JsonDecodeError + + bb0: { + _2 = is_type(copy _1, string); + branch copy _2 -> [bb2, bb1]; + } + + bb1: { + _9 = baml.json.JsonDecodeError { const "Expected RFC 3339 / RFC 9557 timestamp string", const "" }; + throw copy _9; + } + + bb2: { + _0 = call const fn baml.time.ZonedDateTime.parse(copy _1) -> [bb3, unwind: bb4]; } bb3: { - _0 = call const fn baml.toml.Table.baml.FromJson.from_json(copy _1) -> [bb6]; + return; } bb4: { - _3 = baml.json.JsonDecodeError { const "TOML does not support null", const "" }; - throw copy _3; + _4 = is_type(copy _3, baml.errors.ParseError); + branch copy _4 -> [bb6, bb5]; } bb5: { - _0 = copy _1; - goto -> bb6; + rethrow copy _3; } bb6: { - return; + _5 = copy _3.0; + _6 = copy _5; + _8 = copy _6; + _7 = baml.json.JsonDecodeError { copy _8, const "" }; + throw copy _7; } } -fn baml.toml.item_to_json(item: int | float | string | bool | baml.time.PlainDate | baml.time.PlainDateTime | baml.time.PlainTime | baml.time.ZonedDateTime | baml.toml.Table | baml.toml.Item[]) -> int | float | string | bool | null | baml.json.json[] | map { +fn baml.time.ZonedDateTime.baml.ToJson.to_json(self: baml.time.ZonedDateTime) -> int | float | string | bool | null | baml.json.json[] | map { // Locals: let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return - let _1: int | float | string | bool | baml.time.PlainDate | baml.time.PlainDateTime | baml.time.PlainTime | baml.time.ZonedDateTime | baml.toml.Table | baml.toml.Item[] // item // param - let _2: int - let _3: type - let _4: type - let _5: type + let _1: baml.time.ZonedDateTime // self // param + let _2: unknown // _ + let _3: bool + let _4: bool + let _5: bool + let _6: string + let _7: string // message + let _8: baml.json.JsonSerializationError + let _9: string + let _10: string + let _11: string // timezone + let _12: baml.json.JsonSerializationError + let _13: string + let _14: string + let _15: string + let _16: string // message + let _17: baml.json.JsonSerializationError + let _18: string bb0: { - _2 = type_tag(_1); - switch copy _2 [bool: bb8, int: bb8, float: bb8, string: bb8, Table: bb7, list: bb6, ZonedDateTime: bb5, PlainDateTime: bb4, PlainDate: bb3, PlainTime: bb2, otherwise: bb1] (exhaustive); + _0 = call const fn baml.time.ZonedDateTime._to_string_impl(copy _1) -> [bb1, unwind: bb2]; } bb1: { - unreachable; + return; } bb2: { - _0 = virtual_call to_json as baml.ToJson(copy _1) -> [bb9]; + _3 = is_type(copy _2, baml.errors.InvalidArgument); + branch copy _3 -> [bb8, bb3]; } bb3: { - _0 = virtual_call to_json as baml.ToJson(copy _1) -> [bb9]; + _4 = is_type(copy _2, baml.time.UnknownTimezoneError); + branch copy _4 -> [bb7, bb4]; } bb4: { - _0 = virtual_call to_json as baml.ToJson(copy _1) -> [bb9]; + _5 = is_type(copy _2, baml.errors.Io); + branch copy _5 -> [bb6, bb5]; } bb5: { - _0 = virtual_call to_json as baml.ToJson(copy _1) -> [bb9]; + rethrow copy _2; + } + + bb6: { + _15 = copy _2.0; + _16 = copy _15; + _18 = copy _16; + _17 = baml.json.JsonSerializationError { copy _18, const "", const null }; + throw copy _17; + } + + bb7: { + _10 = copy _2.0; + _11 = copy _10; + _14 = copy _11; + _13 = const "unknown timezone: " + copy _14; + _12 = baml.json.JsonSerializationError { copy _13, const "", const null }; + throw copy _12; + } + + bb8: { + _6 = copy _2.0; + _7 = copy _6; + _9 = copy _7; + _8 = baml.json.JsonSerializationError { copy _9, const "", const null }; + throw copy _8; + } +} + +fn baml.time._format_zoned = builtin(vm) + +fn baml.toml.Table.baml.ToJson.to_json(self: baml.toml.Table) -> int | float | string | bool | null | baml.json.json[] | map { + // Locals: + let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return + let _1: baml.toml.Table // self // param + let _2: map + let _3: type + + bb0: { + _2 = copy _1.0; + _3 = load_type(map); + _0 = call const fn baml.json.from(copy _2) -> [bb1]; } - bb6: { - _3 = load_type(baml.json.json); - _4 = load_type(baml.json.JsonSerializationError); - _5 = load_type(baml.toml.Item); - _0 = call const fn baml.Array.map(copy _1, const fn baml.toml.item_to_json) -> [bb9]; + bb1: { + return; } +} - bb7: { - _0 = virtual_call to_json as baml.ToJson(copy _1) -> [bb9]; - } +fn baml.toml.Table.baml.FromJson.from_json(j: int | float | string | bool | null | baml.json.json[] | map) -> Self { + // Locals: + let _0: Self // _0 // return + let _1: int | float | string | bool | null | baml.json.json[] | map // j // param - bb8: { - _0 = copy _1; - goto -> bb9; + bb0: { + _0 = call const fn baml.toml.table_from_json(copy _1) -> [bb1]; } - bb9: { + bb1: { return; } } @@ -11325,24 +11243,108 @@ fn baml.toml.table_from_json(j: int | float | string | bool | null | baml.json.j } } -fn baml.toml.Table.baml.ToJson.to_json(self: baml.toml.Table) -> int | float | string | bool | null | baml.json.json[] | map { +fn baml.toml.item_to_json(item: int | float | string | bool | baml.time.PlainDate | baml.time.PlainDateTime | baml.time.PlainTime | baml.time.ZonedDateTime | baml.toml.Table | baml.toml.Item[]) -> int | float | string | bool | null | baml.json.json[] | map { // Locals: let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return - let _1: baml.toml.Table // self // param - let _2: map + let _1: int | float | string | bool | baml.time.PlainDate | baml.time.PlainDateTime | baml.time.PlainTime | baml.time.ZonedDateTime | baml.toml.Table | baml.toml.Item[] // item // param + let _2: int let _3: type + let _4: type + let _5: type bb0: { - _2 = copy _1.0; - _3 = load_type(map); - _0 = call const fn baml.json.from(copy _2) -> [bb1]; + _2 = type_tag(_1); + switch copy _2 [bool: bb8, int: bb8, float: bb8, string: bb8, Table: bb7, list: bb6, ZonedDateTime: bb5, PlainDateTime: bb4, PlainDate: bb3, PlainTime: bb2, otherwise: bb1] (exhaustive); + } + + bb1: { + unreachable; + } + + bb2: { + _0 = virtual_call to_json as baml.ToJson(copy _1) -> [bb9]; + } + + bb3: { + _0 = virtual_call to_json as baml.ToJson(copy _1) -> [bb9]; + } + + bb4: { + _0 = virtual_call to_json as baml.ToJson(copy _1) -> [bb9]; + } + + bb5: { + _0 = virtual_call to_json as baml.ToJson(copy _1) -> [bb9]; + } + + bb6: { + _3 = load_type(baml.json.json); + _4 = load_type(baml.json.JsonSerializationError); + _5 = load_type(baml.toml.Item); + _0 = call const fn baml.Array.map(copy _1, const fn baml.toml.item_to_json) -> [bb9]; + } + + bb7: { + _0 = virtual_call to_json as baml.ToJson(copy _1) -> [bb9]; + } + + bb8: { + _0 = copy _1; + goto -> bb9; + } + + bb9: { + return; + } +} + +fn baml.toml.item_from_json(json: int | float | string | bool | null | baml.json.json[] | map) -> int | float | string | bool | baml.time.PlainDate | baml.time.PlainDateTime | baml.time.PlainTime | baml.time.ZonedDateTime | baml.toml.Table | baml.toml.Item[] { + // Locals: + let _0: int | float | string | bool | baml.time.PlainDate | baml.time.PlainDateTime | baml.time.PlainTime | baml.time.ZonedDateTime | baml.toml.Table | baml.toml.Item[] // _0 // return + let _1: int | float | string | bool | null | baml.json.json[] | map // json // param + let _2: int + let _3: baml.json.JsonDecodeError + let _4: type + let _5: type + let _6: type + + bb0: { + _2 = type_tag(_1); + switch copy _2 [bool: bb5, int: bb5, float: bb5, string: bb5, null: bb4, map: bb3, list: bb2, otherwise: bb1] (exhaustive); } bb1: { + unreachable; + } + + bb2: { + _4 = load_type(baml.toml.Item); + _5 = load_type(baml.json.JsonDecodeError); + _6 = load_type(baml.json.json); + _0 = call const fn baml.Array.map(copy _1, const fn baml.toml.item_from_json) -> [bb6]; + } + + bb3: { + _0 = call const fn baml.toml.Table.baml.FromJson.from_json(copy _1) -> [bb6]; + } + + bb4: { + _3 = baml.json.JsonDecodeError { const "TOML does not support null", const "" }; + throw copy _3; + } + + bb5: { + _0 = copy _1; + goto -> bb6; + } + + bb6: { return; } } +fn baml.yaml.parse = builtin(vm) + fn baml.yaml.deserialize(s: string) -> T { // Locals: let _0: T // _0 // return @@ -11364,20 +11366,6 @@ fn baml.yaml.deserialize(s: string) -> T { } } -fn baml.yaml.parse = builtin(vm) - -fn baml.String.byte_length = builtin(vm) - -fn baml.String.char_at = builtin(vm) - -fn baml.String.char_count = builtin(vm) - -fn baml.String.chars = builtin(vm) - -fn baml.String.code_point_at = builtin(vm) - -fn baml.String.ends_with = builtin(vm) - fn baml.String.from(value: T) -> string { // Locals: let _0: string // _0 // return @@ -11394,89 +11382,93 @@ fn baml.String.from(value: T) -> string { } } -fn baml.String.from_code_points = builtin(vm) +fn baml.String.length = builtin(vm) -fn baml.String.from_utf8 = builtin(vm) +fn baml.String.char_count = builtin(vm) -fn baml.String.includes = builtin(vm) +fn baml.String.byte_length = builtin(vm) -fn baml.String.index_of = builtin(vm) +fn baml.String.to_lower_case = builtin(vm) -fn baml.String.is_alphabetic = builtin(vm) +fn baml.String.to_upper_case = builtin(vm) -fn baml.String.is_alphanumeric = builtin(vm) +fn baml.String.trim = builtin(vm) -fn baml.String.is_ascii = builtin(vm) +fn baml.String.trim_start = builtin(vm) -fn baml.String.is_ascii_alphabetic = builtin(vm) +fn baml.String.trim_end = builtin(vm) -fn baml.String.is_ascii_alphanumeric = builtin(vm) +fn baml.String.includes = builtin(vm) -fn baml.String.is_ascii_control = builtin(vm) +fn baml.String.starts_with = builtin(vm) -fn baml.String.is_ascii_graphic = builtin(vm) +fn baml.String.ends_with = builtin(vm) -fn baml.String.is_ascii_hex = builtin(vm) +fn baml.String.split = builtin(vm) -fn baml.String.is_ascii_lowercase = builtin(vm) +fn baml.String.chars = builtin(vm) -fn baml.String.is_ascii_numeric = builtin(vm) +fn baml.String.lines = builtin(vm) -fn baml.String.is_ascii_uppercase = builtin(vm) +fn baml.String.substring = builtin(vm) -fn baml.String.is_ascii_whitespace = builtin(vm) +fn baml.String.replace = builtin(vm) -fn baml.String.is_control = builtin(vm) +fn baml.String.index_of = builtin(vm) -fn baml.String.is_graphic = builtin(vm) +fn baml.String.char_at = builtin(vm) -fn baml.String.is_lowercase = builtin(vm) +fn baml.String.code_point_at = builtin(vm) -fn baml.String.is_numeric = builtin(vm) +fn baml.String.repeat = builtin(vm) -fn baml.String.is_uppercase = builtin(vm) +fn baml.String.matches = builtin(vm) -fn baml.String.is_whitespace = builtin(vm) +fn baml.String.replace_all = builtin(vm) -fn baml.String.length = builtin(vm) +fn baml.String.is_numeric = builtin(vm) -fn baml.String.lines = builtin(vm) +fn baml.String.is_alphabetic = builtin(vm) -fn baml.String.matches = builtin(vm) +fn baml.String.is_alphanumeric = builtin(vm) -fn baml.String.repeat = builtin(vm) +fn baml.String.is_uppercase = builtin(vm) -fn baml.String.replace = builtin(vm) +fn baml.String.is_lowercase = builtin(vm) -fn baml.String.replace_all = builtin(vm) +fn baml.String.is_whitespace = builtin(vm) -fn baml.String.split = builtin(vm) +fn baml.String.is_control = builtin(vm) -fn baml.String.starts_with = builtin(vm) +fn baml.String.is_graphic = builtin(vm) -fn baml.String.substring = builtin(vm) +fn baml.String.is_ascii = builtin(vm) -fn baml.String.to_code_points = builtin(vm) +fn baml.String.is_ascii_numeric = builtin(vm) -fn baml.String.to_lower_case = builtin(vm) +fn baml.String.is_ascii_alphabetic = builtin(vm) -fn baml.String.to_upper_case = builtin(vm) +fn baml.String.is_ascii_alphanumeric = builtin(vm) -fn baml.String.to_utf8 = builtin(vm) +fn baml.String.is_ascii_uppercase = builtin(vm) -fn baml.String.trim = builtin(vm) +fn baml.String.is_ascii_lowercase = builtin(vm) -fn baml.String.trim_end = builtin(vm) +fn baml.String.is_ascii_whitespace = builtin(vm) -fn baml.String.trim_start = builtin(vm) +fn baml.String.is_ascii_control = builtin(vm) -fn baml.TypeValue._to_string_impl = builtin(vm) +fn baml.String.is_ascii_graphic = builtin(vm) -fn baml.TypeValue.implemented_by = builtin(vm) +fn baml.String.is_ascii_hex = builtin(vm) -fn baml.TypeValue.implementors = builtin(vm) +fn baml.String.to_utf8 = builtin(vm) -fn baml.TypeValue.implements = builtin(vm) +fn baml.String.from_utf8 = builtin(vm) + +fn baml.String.to_code_points = builtin(vm) + +fn baml.String.from_code_points = builtin(vm) fn baml.TypeValue.baml.ToString.to_string(self: baml.TypeValue) -> string { // Locals: @@ -11492,38 +11484,44 @@ fn baml.TypeValue.baml.ToString.to_string(self: baml.TypeValue) -> string { } } -fn baml.Uint8Array._to_string_impl = builtin(vm) - -fn baml.Uint8Array.at = builtin(vm) +fn baml.TypeValue._to_string_impl = builtin(vm) -fn baml.Uint8Array.concat = builtin(vm) +fn baml.TypeValue.implements = builtin(vm) -fn baml.Uint8Array.from_array = builtin(vm) +fn baml.TypeValue.implemented_by = builtin(vm) -fn baml.Uint8Array.from_base64 = builtin(vm) +fn baml.TypeValue.implementors = builtin(vm) -fn baml.Uint8Array.from_hex = builtin(vm) +fn baml.Uint8Array.length = builtin(vm) -fn baml.Uint8Array.includes = builtin(vm) +fn baml.Uint8Array.at = builtin(vm) -fn baml.Uint8Array.length = builtin(vm) +fn baml.Uint8Array.push = builtin(vm) fn baml.Uint8Array.pop = builtin(vm) -fn baml.Uint8Array.push = builtin(vm) +fn baml.Uint8Array.concat = builtin(vm) + +fn baml.Uint8Array.includes = builtin(vm) fn baml.Uint8Array.reverse = builtin(vm) fn baml.Uint8Array.slice = builtin(vm) -fn baml.Uint8Array.sort = builtin(vm) +fn baml.Uint8Array.zeroes = builtin(vm) + +fn baml.Uint8Array.from_array = builtin(vm) fn baml.Uint8Array.to_array = builtin(vm) -fn baml.Uint8Array.to_base64 = builtin(vm) +fn baml.Uint8Array.from_hex = builtin(vm) fn baml.Uint8Array.to_hex = builtin(vm) +fn baml.Uint8Array.from_base64 = builtin(vm) + +fn baml.Uint8Array.to_base64 = builtin(vm) + fn baml.Uint8Array.baml.ToString.to_string(self: baml.Uint8Array) -> string { // Locals: let _0: string // _0 // return @@ -11538,4 +11536,6 @@ fn baml.Uint8Array.baml.ToString.to_string(self: baml.Uint8Array) -> string { } } -fn baml.Uint8Array.zeroes = builtin(vm) +fn baml.Uint8Array._to_string_impl = builtin(vm) + +fn baml.Uint8Array.sort = builtin(vm) diff --git a/baml_language/crates/baml_tests/snapshots/compiles/__testing_std__/baml_tests__compiles____testing_std____04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/__testing_std__/baml_tests__compiles____testing_std____04_5_mir.snap index cef95352360..b8af0269829 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/__testing_std__/baml_tests__compiles____testing_std____04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/__testing_std__/baml_tests__compiles____testing_std____04_5_mir.snap @@ -1,18 +1,21 @@ --- source: crates/baml_tests/src/generated_tests.rs -assertion_line: 4966 --- === MIR2 === === MIR2 (package testing) === -fn testing.$invoke_collector(collector: (testing.TestCollector) -> void throws unknown, c: testing.TestCollector) -> void { +fn testing.TestCollector.new(prefix: string) -> testing.TestCollector { // Locals: - let _0: void // _0 // return - let _1: (testing.TestCollector) -> void throws unknown // collector // param - let _2: testing.TestCollector // c // param + let _0: testing.TestCollector // _0 // return + let _1: string // prefix // param + let _2: testing.TestRegistration[] + let _3: testing.TestSetRegistration[] bb0: { - _0 = call copy _1(copy _2) -> [bb1]; + _2 = []: testing.TestRegistration[]; + _3 = []: testing.TestSetRegistration[]; + _0 = testing.TestCollector { copy _1, copy _2, copy _3 }; + goto -> bb1; } bb1: { @@ -20,541 +23,471 @@ fn testing.$invoke_collector(collector: (testing.TestCollector) -> void throws u } } -fn testing._has_selected_descendant(prefix: string, names: string[]) -> bool { +fn testing.TestCollector.register_test(self: testing.TestCollector, name: string, body: () -> void throws unknown, runner: null | ((() -> testing.TestReport throws never) -> (() -> testing.TestReport throws never) throws never)) -> void { // Locals: - let _0: bool // _0 // return - let _1: string // prefix // param - let _2: string[] // names // param - let _3: string // descendant_prefix - let _4: baml.iter.Iterator - let _5: unknown + let _0: void // _0 // return + let _1: testing.TestCollector // self // param + let _2: string // name // param + let _3: () -> void throws unknown // body // param + let _4: null | ((() -> testing.TestReport throws never) -> (() -> testing.TestReport throws never) throws never) // runner // param + let _5: string // full_name let _6: bool let _7: string - let _8: string // selected - let _9: bool - let _10: string + let _8: string + let _9: string + let _10: int // count + let _11: string // hash_prefix + let _12: string + let _13: testing.TestRegistration[] + let _14: baml.iter.Iterator + let _15: unknown + let _16: bool + let _17: testing.TestRegistration + let _18: testing.TestRegistration // t + let _19: bool + let _20: bool + let _21: string + let _22: string + let _23: (baml.String, string) -> bool throws never + let _24: string + let _25: string // final_name + let _26: bool + let _27: int + let _28: string + let _29: string + let _30: string + let _31: int + let _32: int + let _33: type + let _34: int + let _35: (testing.TestRegistration[], testing.TestRegistration) -> int throws never + let _36: testing.TestRegistration + let _37: string + let _38: type bb0: { - _3 = copy _1 + const "/"; - _4 = virtual_call iter as baml.iter.Iterable(copy _2) -> [bb1]; + _7 = copy _1.0; + _6 = copy _7 == const ""; + branch copy _6 -> [bb2, bb1]; } bb1: { - _5 = virtual_call next as baml.iter.Iterator(copy _4) -> [bb2]; + _9 = copy _1.0; + _8 = copy _9 + const "/"; + _5 = copy _8 + copy _2; + goto -> bb3; } bb2: { - _6 = is_type(copy _5, baml.iter.Done); - branch copy _6 -> [bb6, bb3]; + _5 = copy _2; + goto -> bb3; } bb3: { - _7 = copy _5; - fresh_cell(_8); - _8 = copy _7; - _10 = copy _3; - _9 = call const fn baml.String.starts_with(copy _8, copy _10) -> [bb4]; + _10 = const 0_i64; + _12 = copy _5; + _11 = copy _12 + const "#"; + _13 = copy _1.1; + _14 = virtual_call iter as baml.iter.Iterable(copy _13) -> [bb4]; } bb4: { - branch copy _9 -> [bb5, bb1]; + _15 = virtual_call next as baml.iter.Iterator(copy _14) -> [bb5]; } bb5: { - _0 = const true; - goto -> bb7; + _16 = is_type(copy _15, baml.iter.Done); + branch copy _16 -> [bb10, bb6]; } bb6: { - _0 = const false; - goto -> bb7; + _17 = copy _15; + fresh_cell(_18); + _18 = copy _17; + _21 = copy _18.0; + _22 = copy _5; + _20 = copy _21 == copy _22; + _19 = short_circuit(||) copy _20 -> [eval: bb7, join: bb8]; } bb7: { + _23 = copy _18.0; + _24 = copy _11; + _19 = call const fn baml.String.starts_with(copy _23, copy _24) -> [bb8]; + } + + bb8: { + branch copy _19 -> [bb9, bb4]; + } + + bb9: { + _10 = copy _10 + const 1_i64; + goto -> bb4; + } + + bb10: { + _27 = copy _10; + _26 = copy _27 > const 0_i64; + branch copy _26 -> [bb12, bb11]; + } + + bb11: { + _25 = copy _5; + goto -> bb14; + } + + bb12: { + _29 = copy _5; + _28 = copy _29 + const "#"; + _32 = copy _10; + _31 = copy _32 + const 1_i64; + _33 = load_type(int); + _30 = call const fn baml.String.from(copy _31) -> [bb13]; + } + + bb13: { + _25 = copy _28 + copy _30; + goto -> bb14; + } + + bb14: { + _35 = copy _1.1; + _37 = copy _25; + _36 = testing.TestRegistration { copy _37, copy _3, copy _4 }; + _38 = load_type(testing.TestRegistration); + _34 = call const fn baml.Array.push(copy _35, copy _36) -> [bb15]; + } + + bb15: { + _0 = const null; + goto -> bb16; + } + + bb16: { return; } } -fn testing._name_selected(name: string, names: string[]) -> bool { +fn testing.TestCollector.register_test_set(self: testing.TestCollector, name: string, collector: (testing.TestCollector) -> void throws unknown, runner: null | ((testing.TestSetChild[]) -> testing.TestSetReport throws never)) -> void { // Locals: - let _0: bool // _0 // return - let _1: string // name // param - let _2: string[] // names // param - let _3: baml.iter.Iterator - let _4: unknown - let _5: bool - let _6: string - let _7: string // selected - let _8: bool + let _0: void // _0 // return + let _1: testing.TestCollector // self // param + let _2: string // name // param + let _3: (testing.TestCollector) -> void throws unknown // collector // param + let _4: null | ((testing.TestSetChild[]) -> testing.TestSetReport throws never) // runner // param + let _5: string // full_name + let _6: bool + let _7: string + let _8: string let _9: string + let _10: int // count + let _11: string // hash_prefix + let _12: string + let _13: testing.TestSetRegistration[] + let _14: baml.iter.Iterator + let _15: unknown + let _16: bool + let _17: testing.TestSetRegistration + let _18: testing.TestSetRegistration // ts + let _19: bool + let _20: bool + let _21: string + let _22: string + let _23: (baml.String, string) -> bool throws never + let _24: string + let _25: string // final_name + let _26: bool + let _27: int + let _28: string + let _29: string + let _30: string + let _31: int + let _32: int + let _33: type + let _34: int + let _35: (testing.TestSetRegistration[], testing.TestSetRegistration) -> int throws never + let _36: testing.TestSetRegistration + let _37: string + let _38: type bb0: { - _3 = virtual_call iter as baml.iter.Iterable(copy _2) -> [bb1]; + _7 = copy _1.0; + _6 = copy _7 == const ""; + branch copy _6 -> [bb2, bb1]; } bb1: { - _4 = virtual_call next as baml.iter.Iterator(copy _3) -> [bb2]; + _9 = copy _1.0; + _8 = copy _9 + const "/"; + _5 = copy _8 + copy _2; + goto -> bb3; } bb2: { - _5 = is_type(copy _4, baml.iter.Done); - branch copy _5 -> [bb5, bb3]; + _5 = copy _2; + goto -> bb3; } bb3: { - _6 = copy _4; - fresh_cell(_7); - _7 = copy _6; - _9 = copy _7; - _8 = copy _9 == copy _1; - branch copy _8 -> [bb4, bb1]; + _10 = const 0_i64; + _12 = copy _5; + _11 = copy _12 + const "#"; + _13 = copy _1.2; + _14 = virtual_call iter as baml.iter.Iterable(copy _13) -> [bb4]; } bb4: { - _0 = const true; - goto -> bb6; + _15 = virtual_call next as baml.iter.Iterator(copy _14) -> [bb5]; } bb5: { - _0 = const false; - goto -> bb6; + _16 = is_type(copy _15, baml.iter.Done); + branch copy _16 -> [bb10, bb6]; } bb6: { - return; - } -} - -fn testing.aggregate_reports(named_results: testing.NamedChildReport[]) -> testing.TestSetReport { - // Locals: - let _0: testing.TestSetReport // _0 // return - let _1: testing.NamedChildReport[] // named_results // param - let _2: int // passed - let _3: int // failed - let _4: bool // has_error - let _5: string[] // failed_names - let _6: (testing.TestReport | testing.TestSetReport)[] // results - let _7: baml.iter.Iterator - let _8: unknown - let _9: bool - let _10: testing.NamedChildReport - let _11: testing.NamedChildReport // named_result - let _12: testing.TestReport | testing.TestSetReport // result - let _13: int - let _14: testing.TestReport | testing.TestSetReport - let _15: "error" | "fail" | "pass" // outcome - let _16: bool - let _17: testing.TestReport // report - let _18: testing.TestSetReport // report - let _19: bool - let _20: "error" | "fail" | "pass" - let _21: string[] // child_failed_names - let _22: bool - let _23: string - let _24: testing.TestSetReport // report - let _25: bool - let _26: int - let _27: (string[]) -> int throws never - let _28: string - let _29: string[] - let _30: baml.iter.Iterator - let _31: unknown - let _32: bool - let _33: string - let _34: string // name - let _35: void - let _36: string - let _37: bool - let _38: "error" | "fail" | "pass" - let _39: "error" | "fail" | "pass" // outcome - let _40: bool - let _41: bool - let _42: int - let _43: "error" | "fail" | "pass" - let _44: int - let _45: int - let _46: int - let _47: string[] - let _48: (testing.TestReport | testing.TestSetReport)[] - - bb0: { - _2 = const 0_i64; - _3 = const 0_i64; - _4 = const false; - _5 = []: string[]; - _6 = []: testing.TestReport | testing.TestSetReport[]; - _7 = virtual_call iter as baml.iter.Iterable(copy _1) -> [bb1]; - } - - bb1: { - _8 = virtual_call next as baml.iter.Iterator(copy _7) -> [bb2]; - } - - bb2: { - _9 = is_type(copy _8, baml.iter.Done); - branch copy _9 -> [bb23, bb3]; - } - - bb3: { - _10 = copy _8; - fresh_cell(_11); - _11 = copy _10; - _12 = copy _11.1; - _14 = copy _12; - _13 = call const fn baml.Array.push(copy _6, copy _14) -> [bb4]; - } - - bb4: { - _16 = is_type(copy _12, testing.TestReport); - branch copy _16 -> [bb6, bb5]; - } - - bb5: { - _18 = copy _12; - _15 = copy _18.0; - goto -> bb7; - } - - bb6: { - _17 = copy _12; - _15 = copy _17.0; - goto -> bb7; + _17 = copy _15; + fresh_cell(_18); + _18 = copy _17; + _21 = copy _18.0; + _22 = copy _5; + _20 = copy _21 == copy _22; + _19 = short_circuit(||) copy _20 -> [eval: bb7, join: bb8]; } bb7: { - _20 = copy _15; - _19 = call const fn baml.ops.equals_equals(copy _20, const "pass") -> [bb8]; + _23 = copy _18.0; + _24 = copy _11; + _19 = call const fn baml.String.starts_with(copy _23, copy _24) -> [bb8]; } bb8: { - branch copy _19 -> [bb22, bb9]; + branch copy _19 -> [bb9, bb4]; } bb9: { - _3 = copy _3 + const 1_i64; - _22 = is_type(copy _12, testing.TestReport); - branch copy _22 -> [bb14, bb10]; + _10 = copy _10 + const 1_i64; + goto -> bb4; } bb10: { - _24 = copy _12; - _27 = copy _24.4; - _26 = len(_27); - goto -> bb11; + _27 = copy _10; + _26 = copy _27 > const 0_i64; + branch copy _26 -> [bb12, bb11]; } bb11: { - _25 = copy _26 > const 0_i64; - branch copy _25 -> [bb13, bb12]; + _25 = copy _5; + goto -> bb14; } bb12: { - _28 = copy _11.0; - _21 = [copy _28]: string[]; - goto -> bb15; + _29 = copy _5; + _28 = copy _29 + const "#"; + _32 = copy _10; + _31 = copy _32 + const 1_i64; + _33 = load_type(int); + _30 = call const fn baml.String.from(copy _31) -> [bb13]; } bb13: { - _21 = copy _24.4; - goto -> bb15; + _25 = copy _28 + copy _30; + goto -> bb14; } bb14: { - _23 = copy _11.0; - _21 = [copy _23]: string[]; - goto -> bb15; + _35 = copy _1.2; + _37 = copy _25; + _36 = testing.TestSetRegistration { copy _37, copy _3, copy _4 }; + _38 = load_type(testing.TestSetRegistration); + _34 = call const fn baml.Array.push(copy _35, copy _36) -> [bb15]; } bb15: { - _29 = copy _21; - _30 = virtual_call iter as baml.iter.Iterable(copy _29) -> [bb16]; + _0 = const null; + goto -> bb16; } bb16: { - _31 = virtual_call next as baml.iter.Iterator(copy _30) -> [bb17]; - } - - bb17: { - _32 = is_type(copy _31, baml.iter.Done); - branch copy _32 -> [bb19, bb18]; - } - - bb18: { - _33 = copy _31; - fresh_cell(_34); - _34 = copy _33; - _36 = copy _34; - _35 = call const fn baml.Array.push(copy _5, copy _36) -> [bb16]; - } - - bb19: { - _38 = copy _15; - _37 = call const fn baml.ops.equals_equals(copy _38, const "error") -> [bb20]; - } - - bb20: { - branch copy _37 -> [bb21, bb1]; - } - - bb21: { - _4 = const true; - goto -> bb1; - } - - bb22: { - _2 = copy _2 + const 1_i64; - goto -> bb1; - } - - bb23: { - _40 = copy _4; - branch copy _40 -> [bb27, bb24]; - } - - bb24: { - _42 = copy _3; - _41 = copy _42 == const 0_i64; - branch copy _41 -> [bb26, bb25]; - } - - bb25: { - _39 = const "fail"; - goto -> bb28; - } - - bb26: { - _39 = const "pass"; - goto -> bb28; - } - - bb27: { - _39 = const "error"; - goto -> bb28; - } - - bb28: { - _43 = copy _39; - _44 = copy _2; - _45 = copy _3; - _46 = len(_6); - goto -> bb29; - } - - bb29: { - _47 = copy _5; - _48 = copy _6; - _0 = testing.TestSetReport { copy _43, copy _44, copy _45, copy _46, copy _47, copy _48 }; - goto -> bb30; - } - - bb30: { return; } } -fn testing.any_pattern_matches(pats: testing.FilterPat[], function_name: string, test_name: string) -> bool { +fn testing.TestCollector.find_testset(self: testing.TestCollector, name: string) -> testing.TestSetRegistration { // Locals: - let _0: bool // _0 // return - let _1: testing.FilterPat[] // pats // param - let _2: string // function_name // param - let _3: string // test_name // param - let _4: baml.iter.Iterator + let _0: testing.TestSetRegistration // _0 // return + let _1: testing.TestCollector // self // param + let _2: string // name // param + let _3: testing.TestSetRegistration[] + let _4: baml.iter.Iterator let _5: unknown let _6: bool - let _7: testing.FilterPat - let _8: testing.FilterPat // p + let _7: testing.TestSetRegistration + let _8: testing.TestSetRegistration // ts let _9: bool - let _10: bool + let _10: string let _11: string - let _12: string bb0: { - _4 = virtual_call iter as baml.iter.Iterable(copy _1) -> [bb1]; + _3 = copy _1.2; + _4 = virtual_call iter as baml.iter.Iterable(copy _3) -> [bb1]; } bb1: { - _5 = virtual_call next as baml.iter.Iterator(copy _4) -> [bb2]; + _5 = virtual_call next as baml.iter.Iterator(copy _4) -> [bb2]; } bb2: { _6 = is_type(copy _5, baml.iter.Done); - branch copy _6 -> [bb8, bb3]; + branch copy _6 -> [bb6, bb3]; } bb3: { _7 = copy _5; fresh_cell(_8); _8 = copy _7; - _11 = copy _8.0; - _10 = call const fn testing.filter_match(copy _11, copy _2) -> [bb4]; + _10 = copy _8.0; + _9 = copy _10 == copy _2; + branch copy _9 -> [bb4, bb1]; } bb4: { - _9 = short_circuit(&&) copy _10 -> [eval: bb5, join: bb6]; + _0 = copy _8; + goto -> bb5; } bb5: { - _12 = copy _8.1; - _9 = call const fn testing.filter_match(copy _12, copy _3) -> [bb6]; + return; } bb6: { - branch copy _9 -> [bb7, bb1]; - } - - bb7: { - _0 = const true; - goto -> bb9; + _11 = const "TestSet not found: " + copy _2; + throw copy _11; } +} - bb8: { - _0 = const false; - goto -> bb9; - } - - bb9: { - return; - } -} - -fn testing.collect_leaf_messages(results: (testing.TestReport | testing.TestSetReport)[], out: string[]) -> void { +fn testing.TestCollector.find_test(self: testing.TestCollector, name: string) -> testing.TestRegistration { // Locals: - let _0: void // _0 // return - let _1: (testing.TestReport | testing.TestSetReport)[] // results // param - let _2: string[] // out // param - let _3: baml.iter.Iterator - let _4: unknown - let _5: bool - let _6: testing.TestReport | testing.TestSetReport - let _7: testing.TestReport | testing.TestSetReport // r - let _8: bool - let _9: testing.TestReport // tr - let _10: testing.RunReport[] - let _11: baml.iter.Iterator - let _12: unknown - let _13: bool - let _14: testing.RunReport - let _15: testing.RunReport // run - let _16: bool - let _17: "error" | "fail" | "pass" - let _18: bool - let _19: string | null - let _20: bool - let _21: string // m - let _22: int - let _23: string - let _24: testing.TestSetReport // tsr - let _25: void - let _26: (testing.TestReport | testing.TestSetReport)[] + let _0: testing.TestRegistration // _0 // return + let _1: testing.TestCollector // self // param + let _2: string // name // param + let _3: testing.TestRegistration[] + let _4: baml.iter.Iterator + let _5: unknown + let _6: bool + let _7: testing.TestRegistration + let _8: testing.TestRegistration // t + let _9: bool + let _10: string + let _11: string bb0: { - _3 = virtual_call iter as baml.iter.Iterable(copy _1) -> [bb1]; + _3 = copy _1.1; + _4 = virtual_call iter as baml.iter.Iterable(copy _3) -> [bb1]; } bb1: { - _4 = virtual_call next as baml.iter.Iterator(copy _3) -> [bb2]; + _5 = virtual_call next as baml.iter.Iterator(copy _4) -> [bb2]; } bb2: { - _5 = is_type(copy _4, baml.iter.Done); - branch copy _5 -> [bb12, bb3]; + _6 = is_type(copy _5, baml.iter.Done); + branch copy _6 -> [bb6, bb3]; } bb3: { - _6 = copy _4; - fresh_cell(_7); - _7 = copy _6; - _8 = is_type(copy _7, testing.TestReport); - branch copy _8 -> [bb5, bb4]; + _7 = copy _5; + fresh_cell(_8); + _8 = copy _7; + _10 = copy _8.0; + _9 = copy _10 == copy _2; + branch copy _9 -> [bb4, bb1]; } bb4: { - _24 = copy _7; - _26 = copy _24.5; - _25 = call const fn testing.collect_leaf_messages(copy _26, copy _2) -> [bb1]; + _0 = copy _8; + goto -> bb5; } bb5: { - _9 = copy _7; - _10 = copy _9.1; - _11 = virtual_call iter as baml.iter.Iterable(copy _10) -> [bb6]; + return; } bb6: { - _12 = virtual_call next as baml.iter.Iterator(copy _11) -> [bb7]; - } - - bb7: { - _13 = is_type(copy _12, baml.iter.Done); - branch copy _13 -> [bb1, bb8]; + _11 = const "Test not found: " + copy _2; + throw copy _11; } +} - bb8: { - _14 = copy _12; - fresh_cell(_15); - _15 = copy _14; - _17 = copy _15.0; - _18 = call const fn baml.ops.equals_equals(copy _17, const "pass") -> [bb9]; - } +fn testing.$invoke_collector(collector: (testing.TestCollector) -> void throws unknown, c: testing.TestCollector) -> void { + // Locals: + let _0: void // _0 // return + let _1: (testing.TestCollector) -> void throws unknown // collector // param + let _2: testing.TestCollector // c // param - bb9: { - _16 = !copy _18; - branch copy _16 -> [bb10, bb6]; + bb0: { + _0 = call copy _1(copy _2) -> [bb1]; } - bb10: { - _19 = copy _15.2; - _20 = is_type(copy _19, string); - branch copy _20 -> [bb11, bb6]; + bb1: { + return; } +} - bb11: { - _21 = copy _19; - _23 = copy _21; - _22 = call const fn baml.Array.push(copy _2, copy _23) -> [bb6]; - } +fn testing.TestRegistry.new(collector: testing.TestCollector) -> testing.TestRegistry { + // Locals: + let _0: testing.TestRegistry // _0 // return + let _1: testing.TestCollector // collector // param + let _2: map - bb12: { - _0 = const null; - goto -> bb13; + bb0: { + _2 = { }: map; + _0 = testing.TestRegistry { copy _1, copy _2, const 0_i64 }; + goto -> bb1; } - bb13: { + bb1: { return; } } -fn testing.collect_leaf_names(registry: testing.TestRegistry) -> string[] { +fn testing.TestRegistry.serialize(self: testing.TestRegistry) -> (testing.SerializedTest | testing.SerializedTestSet)[] { // Locals: - let _0: string[] // _0 // return - let _1: testing.TestRegistry // registry // param - let _2: string[] // out + let _0: (testing.SerializedTest | testing.SerializedTestSet)[] // _0 // return + let _1: testing.TestRegistry // self // param + let _2: (testing.SerializedTest | testing.SerializedTestSet)[] // items let _3: testing.TestRegistration[] let _4: baml.iter.Iterator let _5: unknown let _6: bool let _7: testing.TestRegistration let _8: testing.TestRegistration // t - let _9: int - let _10: string - let _11: testing.TestSetRegistration[] - let _12: baml.iter.Iterator - let _13: unknown - let _14: bool - let _15: testing.TestSetRegistration - let _16: testing.TestSetRegistration // ts - let _17: string[] - let _18: testing.TestSetRegistration - let _19: baml.iter.Iterator - let _20: unknown - let _21: bool - let _22: string - let _23: string // name - let _24: int - let _25: string + let _9: void + let _10: testing.SerializedTest + let _11: string + let _12: testing.TestSetRegistration[] + let _13: baml.iter.Iterator + let _14: unknown + let _15: bool + let _16: testing.TestSetRegistration + let _17: testing.TestSetRegistration // ts + let _18: void + let _19: null | testing.TestRegistry // expanded + let _20: (map, string) -> null | testing.TestRegistry throws never + let _21: string + let _22: type + let _23: type + let _24: bool + let _25: testing.TestRegistry // sub + let _26: testing.SerializedTestSet + let _27: string + let _28: (testing.SerializedTest | testing.SerializedTestSet)[] + let _29: int + let _30: testing.SerializedTest + let _31: string bb0: { - _2 = []: string[]; + _2 = []: testing.SerializedTest | testing.SerializedTestSet[]; _3 = copy _1.0.1; _4 = virtual_call iter as baml.iter.Iterable(copy _3) -> [bb1]; } @@ -572,51 +505,57 @@ fn testing.collect_leaf_names(registry: testing.TestRegistry) -> string[] { _7 = copy _5; fresh_cell(_8); _8 = copy _7; - _10 = copy _8.0; + _11 = copy _8.0; + _10 = testing.SerializedTest { const "test", copy _11 }; _9 = call const fn baml.Array.push(copy _2, copy _10) -> [bb1]; } bb4: { - _11 = copy _1.0.2; - _12 = virtual_call iter as baml.iter.Iterable(copy _11) -> [bb5]; + _12 = copy _1.0.2; + _13 = virtual_call iter as baml.iter.Iterable(copy _12) -> [bb5]; } bb5: { - _13 = virtual_call next as baml.iter.Iterator(copy _12) -> [bb6]; + _14 = virtual_call next as baml.iter.Iterator(copy _13) -> [bb6]; } bb6: { - _14 = is_type(copy _13, baml.iter.Done); - branch copy _14 -> [bb12, bb7]; + _15 = is_type(copy _14, baml.iter.Done); + branch copy _15 -> [bb12, bb7]; } bb7: { - _15 = copy _13; - fresh_cell(_16); - _16 = copy _15; - _18 = copy _16; - _17 = call const fn testing.collect_subtree_names(copy _1, copy _18) -> [bb8]; + _16 = copy _14; + fresh_cell(_17); + _17 = copy _16; + _20 = copy _1.1; + _21 = copy _17.0; + _22 = load_type(string); + _23 = load_type(testing.TestRegistry); + _19 = call const fn baml.Map.get(copy _20, copy _21) -> [bb8]; } bb8: { - _19 = virtual_call iter as baml.iter.Iterable(copy _17) -> [bb9]; + _24 = is_type(copy _19, testing.TestRegistry); + branch copy _24 -> [bb10, bb9]; } bb9: { - _20 = virtual_call next as baml.iter.Iterator(copy _19) -> [bb10]; + _31 = copy _17.0; + _30 = testing.SerializedTest { const "lazyTestSet", copy _31 }; + _18 = call const fn baml.Array.push(copy _2, copy _30) -> [bb5]; } bb10: { - _21 = is_type(copy _20, baml.iter.Done); - branch copy _21 -> [bb5, bb11]; + _25 = copy _19; + _27 = copy _17.0; + _28 = call const fn testing.TestRegistry.serialize(copy _25) -> [bb11]; } bb11: { - _22 = copy _20; - fresh_cell(_23); - _23 = copy _22; - _25 = copy _23; - _24 = call const fn baml.Array.push(copy _2, copy _25) -> [bb9]; + _29 = copy _25.2; + _26 = testing.SerializedTestSet { copy _27, copy _28, copy _29 }; + _18 = call const fn baml.Array.push(copy _2, copy _26) -> [bb5]; } bb12: { @@ -629,229 +568,120 @@ fn testing.collect_leaf_names(registry: testing.TestRegistry) -> string[] { } } -fn testing.collect_subtree_names(registry: testing.TestRegistry, ts: testing.TestSetRegistration) -> string[] { +fn testing.TestRegistry.run_test(self: testing.TestRegistry, name: string) -> testing.TestReport { // Locals: - let _0: string[] // _0 // return - let _1: testing.TestRegistry // registry // param - let _2: testing.TestSetRegistration // ts // param - let _3: unknown // e - let _4: testing.TestRegistry - let _5: int - let _6: string - let _7: string - let _8: string - let _9: string - - bb0: { - _4 = call const fn testing.TestRegistry.expand_testset_registry(copy _1, copy _2) -> [bb1, unwind: bb2]; - } - - bb1: { - _0 = call const fn testing.collect_leaf_names(copy _4) -> [bb6, unwind: bb2]; - } - - bb2: { - _5 = type_tag(_3); - switch copy _5 [DivisionByZero: bb5, IndexOutOfBounds: bb5, InvalidFieldAccess: bb5, MapKeyNotFound: bb5, StackOverflow: bb5, AssertionFailed: bb5, Unreachable: bb5, Cancelled: bb5, UserPanic: bb5, Exit: bb5, AllocFailure: bb5, HostUnavailable: bb5, NegativeBitShift: bb5, SdkPanic: bb5, HostContractViolation: bb5, IntegerOverflow: bb5, otherwise: bb3]; - } - - bb3: { - throw_if_panic copy _3 -> bb4; - } - - bb4: { - _9 = copy _2.0; - _8 = copy _9 + const "/(failed to expand)"; - _0 = [copy _8]: string[]; - goto -> bb6; - } - - bb5: { - _7 = copy _2.0; - _6 = copy _7 + const "/(failed to expand)"; - _0 = [copy _6]: string[]; - goto -> bb6; - } - - bb6: { - return; - } -} - -fn testing.count_leaves(results: (testing.TestReport | testing.TestSetReport)[], tolerated_by_parent: bool) -> testing.LeafCounts { - // Locals: - let _0: testing.LeafCounts // _0 // return - let _1: (testing.TestReport | testing.TestSetReport)[] // results // param - let _2: bool // tolerated_by_parent // param - let _3: int // passed - let _4: int // failed - let _5: int // tolerated - let _6: int // total - let _7: baml.iter.Iterator - let _8: unknown + let _0: testing.TestReport // _0 // return + let _1: testing.TestRegistry // self // param + let _2: string // name // param + let _3: testing.TestRegistration[] + let _4: baml.iter.Iterator + let _5: unknown + let _6: bool + let _7: testing.TestRegistration + let _8: testing.TestRegistration // t let _9: bool - let _10: testing.TestReport | testing.TestSetReport - let _11: testing.TestReport | testing.TestSetReport // r - let _12: testing.LeafCounts // delta - let _13: bool - let _14: testing.TestReport // tr - let _15: bool - let _16: "error" | "fail" | "pass" - let _17: testing.TestSetReport // tsr - let _18: bool // ft - let _19: "error" | "fail" | "pass" - let _20: bool - let _21: int - let _22: ((testing.TestReport | testing.TestSetReport)[]) -> int throws never - let _23: (testing.TestReport | testing.TestSetReport)[] - let _24: bool + let _10: string + let _11: () -> void throws unknown + let _12: null | ((() -> testing.TestReport throws never) -> (() -> testing.TestReport throws never) throws never) + let _13: string[] + let _14: (map) -> string[] throws never + let _15: type + let _16: type + let _17: baml.iter.Iterator + let _18: unknown + let _19: bool + let _20: string + let _21: string // k + let _22: testing.TestRegistry // sub + let _23: map + let _24: string let _25: bool - let _26: int - let _27: int - let _28: int - let _29: int - let _30: int - let _31: int - let _32: int - let _33: int - let _34: int - let _35: int - let _36: int - let _37: int - let _38: int - let _39: int + let _26: string + let _27: string + let _28: string bb0: { - _3 = const 0_i64; - _4 = const 0_i64; - _5 = const 0_i64; - _6 = const 0_i64; - _7 = virtual_call iter as baml.iter.Iterable(copy _1) -> [bb1]; + _3 = copy _1.0.1; + _4 = virtual_call iter as baml.iter.Iterable(copy _3) -> [bb1]; } bb1: { - _8 = virtual_call next as baml.iter.Iterator(copy _7) -> [bb2]; + _5 = virtual_call next as baml.iter.Iterator(copy _4) -> [bb2]; } bb2: { - _9 = is_type(copy _8, baml.iter.Done); - branch copy _9 -> [bb19, bb3]; + _6 = is_type(copy _5, baml.iter.Done); + branch copy _6 -> [bb5, bb3]; } bb3: { - _10 = copy _8; - fresh_cell(_11); - _11 = copy _10; - _13 = is_type(copy _11, testing.TestReport); - branch copy _13 -> [bb12, bb4]; + _7 = copy _5; + fresh_cell(_8); + _8 = copy _7; + _10 = copy _8.0; + _9 = copy _10 == copy _2; + branch copy _9 -> [bb4, bb1]; } bb4: { - _17 = copy _11; - _18 = short_circuit(||) copy _2 -> [eval: bb5, join: bb6]; + _11 = copy _8.1; + _12 = copy _8.2; + _0 = call const fn testing.run_test(copy _11, copy _12) -> [bb12]; } bb5: { - _19 = copy _17.0; - _18 = call const fn baml.ops.equals_equals(copy _19, const "pass") -> [bb6]; + _14 = copy _1.1; + _15 = load_type(string); + _16 = load_type(testing.TestRegistry); + _13 = call const fn baml.Map.keys(copy _14) -> [bb6]; } bb6: { - _22 = copy _17.5; - _21 = len(_22); - goto -> bb7; + _17 = virtual_call iter as baml.iter.Iterable(copy _13) -> [bb7]; } bb7: { - _20 = copy _21 > const 0_i64; - branch copy _20 -> [bb11, bb8]; + _18 = virtual_call next as baml.iter.Iterator(copy _17) -> [bb8]; } bb8: { - _25 = copy _18; - branch copy _25 -> [bb10, bb9]; + _19 = is_type(copy _18, baml.iter.Done); + branch copy _19 -> [bb13, bb9]; } bb9: { - _29 = copy _17.1; - _30 = copy _17.2; - _31 = copy _17.3; - _12 = testing.LeafCounts { copy _29, copy _30, const 0_i64, copy _31 }; - goto -> bb18; + _20 = copy _18; + fresh_cell(_21); + _21 = copy _20; + _23 = copy _1.1; + _24 = copy _21; + _22 = copy _23[_24]; + _27 = copy _21; + _26 = copy _27 + const "/"; + _25 = call const fn baml.String.starts_with(copy _2, copy _26) -> [bb10]; } bb10: { - _26 = copy _17.1; - _27 = copy _17.2; - _28 = copy _17.3; - _12 = testing.LeafCounts { copy _26, const 0_i64, copy _27, copy _28 }; - goto -> bb18; + branch copy _25 -> [bb11, bb7]; } bb11: { - _23 = copy _17.5; - _24 = copy _18; - _12 = call const fn testing.count_leaves(copy _23, copy _24) -> [bb18]; + _0 = call const fn testing.TestRegistry.run_test(copy _22, copy _2) -> [bb12]; } bb12: { - _14 = copy _11; - _16 = copy _14.0; - _15 = call const fn baml.ops.equals_equals(copy _16, const "pass") -> [bb13]; + return; } bb13: { - branch copy _15 -> [bb17, bb14]; - } - - bb14: { - branch copy _2 -> [bb16, bb15]; - } - - bb15: { - _12 = testing.LeafCounts { const 0_i64, const 1_i64, const 0_i64, const 1_i64 }; - goto -> bb18; - } - - bb16: { - _12 = testing.LeafCounts { const 0_i64, const 0_i64, const 1_i64, const 1_i64 }; - goto -> bb18; - } - - bb17: { - _12 = testing.LeafCounts { const 1_i64, const 0_i64, const 0_i64, const 1_i64 }; - goto -> bb18; - } - - bb18: { - _32 = copy _12.0; - _3 = copy _3 + copy _32; - _33 = copy _12.1; - _4 = copy _4 + copy _33; - _34 = copy _12.2; - _5 = copy _5 + copy _34; - _35 = copy _12.3; - _6 = copy _6 + copy _35; - goto -> bb1; - } - - bb19: { - _36 = copy _3; - _37 = copy _4; - _38 = copy _5; - _39 = copy _6; - _0 = testing.LeafCounts { copy _36, copy _37, copy _38, copy _39 }; - goto -> bb20; - } - - bb20: { - return; + _28 = const "Test not found: " + copy _2; + throw copy _28; } } -fn testing.TestRegistry.expand_set(self: testing.TestRegistry, name: string) -> (testing.SerializedTest | testing.SerializedTestSet)[] { +fn testing.TestRegistry.run_testset(self: testing.TestRegistry, name: string) -> testing.TestSetReport { // Locals: - let _0: (testing.SerializedTest | testing.SerializedTestSet)[] // _0 // return + let _0: testing.TestSetReport // _0 // return let _1: testing.TestRegistry // self // param let _2: string // name // param let _3: testing.TestSetRegistration[] @@ -862,24 +692,26 @@ fn testing.TestRegistry.expand_set(self: testing.TestRegistry, name: string) -> let _8: testing.TestSetRegistration // ts let _9: bool let _10: string - let _11: testing.TestRegistry - let _12: testing.TestSetRegistration - let _13: string[] - let _14: (map) -> string[] throws never - let _15: type - let _16: type - let _17: baml.iter.Iterator - let _18: unknown - let _19: bool - let _20: string - let _21: string // k - let _22: testing.TestRegistry // sub - let _23: map - let _24: string - let _25: bool + let _11: testing.TestSetChild[] + let _12: testing.TestRegistry + let _13: testing.TestSetRegistration + let _14: null | ((testing.TestSetChild[]) -> testing.TestSetReport throws never) + let _15: string[] + let _16: (map) -> string[] throws never + let _17: type + let _18: type + let _19: baml.iter.Iterator + let _20: unknown + let _21: bool + let _22: string + let _23: string // k + let _24: testing.TestRegistry // sub + let _25: map let _26: string - let _27: string + let _27: bool let _28: string + let _29: string + let _30: string bb0: { _3 = copy _1.0.2; @@ -892,7 +724,7 @@ fn testing.TestRegistry.expand_set(self: testing.TestRegistry, name: string) -> bb2: { _6 = is_type(copy _5, baml.iter.Done); - branch copy _6 -> [bb6, bb3]; + branch copy _6 -> [bb7, bb3]; } bb3: { @@ -905,18 +737,252 @@ fn testing.TestRegistry.expand_set(self: testing.TestRegistry, name: string) -> } bb4: { - _12 = copy _8; - _11 = call const fn testing.TestRegistry.expand_testset_registry(copy _1, copy _12) -> [bb5]; + _13 = copy _8; + _12 = call const fn testing.TestRegistry.expand_testset_registry(copy _1, copy _13) -> [bb5]; } bb5: { - _0 = call const fn testing.TestRegistry.serialize(copy _1) -> [bb13]; + _11 = call const fn testing.testset_children(copy _12) -> [bb6]; } bb6: { - _14 = copy _1.1; - _15 = load_type(string); - _16 = load_type(testing.TestRegistry); + _14 = copy _8.2; + _0 = call const fn testing.run_testset(copy _11, copy _14) -> [bb14]; + } + + bb7: { + _16 = copy _1.1; + _17 = load_type(string); + _18 = load_type(testing.TestRegistry); + _15 = call const fn baml.Map.keys(copy _16) -> [bb8]; + } + + bb8: { + _19 = virtual_call iter as baml.iter.Iterable(copy _15) -> [bb9]; + } + + bb9: { + _20 = virtual_call next as baml.iter.Iterator(copy _19) -> [bb10]; + } + + bb10: { + _21 = is_type(copy _20, baml.iter.Done); + branch copy _21 -> [bb15, bb11]; + } + + bb11: { + _22 = copy _20; + fresh_cell(_23); + _23 = copy _22; + _25 = copy _1.1; + _26 = copy _23; + _24 = copy _25[_26]; + _29 = copy _23; + _28 = copy _29 + const "/"; + _27 = call const fn baml.String.starts_with(copy _2, copy _28) -> [bb12]; + } + + bb12: { + branch copy _27 -> [bb13, bb9]; + } + + bb13: { + _0 = call const fn testing.TestRegistry.run_testset(copy _24, copy _2) -> [bb14]; + } + + bb14: { + return; + } + + bb15: { + _30 = const "TestSet not found: " + copy _2; + throw copy _30; + } +} + +fn testing.TestRegistry.run_all(self: testing.TestRegistry) -> testing.TestSetReport { + // Locals: + let _0: testing.TestSetReport // _0 // return + let _1: testing.TestRegistry // self // param + let _2: testing.TestSetChild[] + + bb0: { + _2 = call const fn testing.testset_children(copy _1) -> [bb1]; + } + + bb1: { + _0 = call const fn testing.run_testset(copy _2, const null) -> [bb2]; + } + + bb2: { + return; + } +} + +fn testing.TestRegistry.run_selected(self: testing.TestRegistry, names: string[]) -> testing.TestSetReport { + // Locals: + let _0: testing.TestSetReport // _0 // return + let _1: testing.TestRegistry // self // param + let _2: string[] // names // param + let _3: testing.TestSetChild[] + + bb0: { + _3 = call const fn testing.testset_children_selected(copy _1, copy _2) -> [bb1]; + } + + bb1: { + _0 = call const fn testing.run_testset(copy _3, const null) -> [bb2]; + } + + bb2: { + return; + } +} + +fn testing.TestRegistry.run_filtered(self: testing.TestRegistry, include: string[], exclude: string[]) -> testing.FlatTestReport { + // Locals: + let _0: testing.FlatTestReport // _0 // return + let _1: testing.TestRegistry // self // param + let _2: string[] // include // param + let _3: string[] // exclude // param + let _4: testing.TestSetReport // report + let _5: bool + let _6: bool + let _7: int + let _8: int + let _9: string[] + let _10: testing.TestSetReport + + bb0: { + _7 = len(_2); + goto -> bb1; + } + + bb1: { + _6 = copy _7 == const 0_i64; + _5 = short_circuit(&&) copy _6 -> [eval: bb2, join: bb4]; + } + + bb2: { + _8 = len(_3); + goto -> bb3; + } + + bb3: { + _5 = copy _8 == const 0_i64; + goto -> bb4; + } + + bb4: { + branch copy _5 -> [bb7, bb5]; + } + + bb5: { + _9 = call const fn testing.select_names(copy _1, copy _2, copy _3) -> [bb6]; + } + + bb6: { + _4 = call const fn testing.TestRegistry.run_selected(copy _1, copy _9) -> [bb8]; + } + + bb7: { + _4 = call const fn testing.TestRegistry.run_all(copy _1) -> [bb8]; + } + + bb8: { + _10 = copy _4; + _0 = call const fn testing.flatten_with_tolerated(copy _10) -> [bb9]; + } + + bb9: { + return; + } +} + +fn testing.TestRegistry.list_filtered(self: testing.TestRegistry, include: string[], exclude: string[]) -> string[] { + // Locals: + let _0: string[] // _0 // return + let _1: testing.TestRegistry // self // param + let _2: string[] // include // param + let _3: string[] // exclude // param + + bb0: { + _0 = call const fn testing.select_names(copy _1, copy _2, copy _3) -> [bb1]; + } + + bb1: { + return; + } +} + +fn testing.TestRegistry.expand_set(self: testing.TestRegistry, name: string) -> (testing.SerializedTest | testing.SerializedTestSet)[] { + // Locals: + let _0: (testing.SerializedTest | testing.SerializedTestSet)[] // _0 // return + let _1: testing.TestRegistry // self // param + let _2: string // name // param + let _3: testing.TestSetRegistration[] + let _4: baml.iter.Iterator + let _5: unknown + let _6: bool + let _7: testing.TestSetRegistration + let _8: testing.TestSetRegistration // ts + let _9: bool + let _10: string + let _11: testing.TestRegistry + let _12: testing.TestSetRegistration + let _13: string[] + let _14: (map) -> string[] throws never + let _15: type + let _16: type + let _17: baml.iter.Iterator + let _18: unknown + let _19: bool + let _20: string + let _21: string // k + let _22: testing.TestRegistry // sub + let _23: map + let _24: string + let _25: bool + let _26: string + let _27: string + let _28: string + + bb0: { + _3 = copy _1.0.2; + _4 = virtual_call iter as baml.iter.Iterable(copy _3) -> [bb1]; + } + + bb1: { + _5 = virtual_call next as baml.iter.Iterator(copy _4) -> [bb2]; + } + + bb2: { + _6 = is_type(copy _5, baml.iter.Done); + branch copy _6 -> [bb6, bb3]; + } + + bb3: { + _7 = copy _5; + fresh_cell(_8); + _8 = copy _7; + _10 = copy _8.0; + _9 = copy _10 == copy _2; + branch copy _9 -> [bb4, bb1]; + } + + bb4: { + _12 = copy _8; + _11 = call const fn testing.TestRegistry.expand_testset_registry(copy _1, copy _12) -> [bb5]; + } + + bb5: { + _0 = call const fn testing.TestRegistry.serialize(copy _1) -> [bb13]; + } + + bb6: { + _14 = copy _1.1; + _15 = load_type(string); + _16 = load_type(testing.TestRegistry); _13 = call const fn baml.Map.keys(copy _14) -> [bb7]; } @@ -1059,70 +1125,35 @@ fn testing.TestRegistry.expand_testset_registry(self: testing.TestRegistry, ts: } } -fn testing.expansion_error_report(name: string) -> testing.TestSetReport { +fn testing.testset_children(registry: testing.TestRegistry) -> testing.TestSetChild[] { // Locals: - let _0: testing.TestSetReport // _0 // return - let _1: string // name // param - let _2: string[] - let _3: string - let _4: (testing.TestReport | testing.TestSetReport)[] - - bb0: { - _3 = copy _1 + const "/(testset error)"; - _2 = [copy _3]: string[]; - _4 = []: testing.TestReport | testing.TestSetReport[]; - _0 = testing.TestSetReport { const "error", const 0_i64, const 1_i64, const 1_i64, copy _2, copy _4 }; - goto -> bb1; - } - - bb1: { - return; - } -} - -fn testing.filter_match(expr: string, subject: string) -> bool { - // Locals: - let _0: bool // _0 // return - let _1: string // expr // param - let _2: string // subject // param - let _3: bool - - bb0: { - _3 = copy _1 == const ""; - branch copy _3 -> [bb2, bb1]; - } - - bb1: { - _0 = call const fn testing.glob_match(copy _2, copy _1) -> [bb3]; - } - - bb2: { - _0 = const true; - goto -> bb3; - } - - bb3: { - return; - } -} - -fn testing.TestCollector.find_test(self: testing.TestCollector, name: string) -> testing.TestRegistration { - // Locals: - let _0: testing.TestRegistration // _0 // return - let _1: testing.TestCollector // self // param - let _2: string // name // param + let _0: testing.TestSetChild[] // _0 // return + let _1: testing.TestRegistry // registry // param + let _2: testing.TestSetChild[] // children let _3: testing.TestRegistration[] let _4: baml.iter.Iterator let _5: unknown let _6: bool let _7: testing.TestRegistration let _8: testing.TestRegistration // t - let _9: bool - let _10: string + let _9: void + let _10: testing.TestSetChild let _11: string + let _12: () -> void throws unknown + let _13: null | ((() -> testing.TestReport throws never) -> (() -> testing.TestReport throws never) throws never) + let _14: testing.TestSetRegistration[] + let _15: baml.iter.Iterator + let _16: unknown + let _17: bool + let _18: testing.TestSetRegistration + let _19: testing.TestSetRegistration // ts + let _20: void + let _21: testing.TestSetChild + let _22: testing.TestSetRegistration bb0: { - _3 = copy _1.1; + _2 = []: testing.TestSetChild[]; + _3 = copy _1.0.1; _4 = virtual_call iter as baml.iter.Iterable(copy _3) -> [bb1]; } @@ -1132,494 +1163,304 @@ fn testing.TestCollector.find_test(self: testing.TestCollector, name: string) -> bb2: { _6 = is_type(copy _5, baml.iter.Done); - branch copy _6 -> [bb6, bb3]; + branch copy _6 -> [bb5, bb3]; } bb3: { _7 = copy _5; fresh_cell(_8); _8 = copy _7; - _10 = copy _8.0; - _9 = copy _10 == copy _2; - branch copy _9 -> [bb4, bb1]; + _11 = copy _8.0; + _12 = copy _8.1; + _13 = copy _8.2; + _10 = call const fn testing.test_child(copy _11, copy _12, copy _13) -> [bb4]; } bb4: { - _0 = copy _8; - goto -> bb5; + _9 = call const fn baml.Array.push(copy _2, copy _10) -> [bb1]; } bb5: { - return; + _14 = copy _1.0.2; + _15 = virtual_call iter as baml.iter.Iterable(copy _14) -> [bb6]; } bb6: { - _11 = const "Test not found: " + copy _2; - throw copy _11; - } -} - -fn testing.TestCollector.find_testset(self: testing.TestCollector, name: string) -> testing.TestSetRegistration { - // Locals: - let _0: testing.TestSetRegistration // _0 // return - let _1: testing.TestCollector // self // param - let _2: string // name // param - let _3: testing.TestSetRegistration[] - let _4: baml.iter.Iterator - let _5: unknown - let _6: bool - let _7: testing.TestSetRegistration - let _8: testing.TestSetRegistration // ts - let _9: bool - let _10: string - let _11: string - - bb0: { - _3 = copy _1.2; - _4 = virtual_call iter as baml.iter.Iterable(copy _3) -> [bb1]; + _16 = virtual_call next as baml.iter.Iterator(copy _15) -> [bb7]; } - bb1: { - _5 = virtual_call next as baml.iter.Iterator(copy _4) -> [bb2]; + bb7: { + _17 = is_type(copy _16, baml.iter.Done); + branch copy _17 -> [bb10, bb8]; } - bb2: { - _6 = is_type(copy _5, baml.iter.Done); - branch copy _6 -> [bb6, bb3]; + bb8: { + _18 = copy _16; + fresh_cell(_19); + _19 = copy _18; + _22 = copy _19; + _21 = call const fn testing.testset_child(copy _1, copy _22) -> [bb9]; } - bb3: { - _7 = copy _5; - fresh_cell(_8); - _8 = copy _7; - _10 = copy _8.0; - _9 = copy _10 == copy _2; - branch copy _9 -> [bb4, bb1]; + bb9: { + _20 = call const fn baml.Array.push(copy _2, copy _21) -> [bb6]; } - bb4: { - _0 = copy _8; - goto -> bb5; + bb10: { + _0 = copy _2; + goto -> bb11; } - bb5: { + bb11: { return; } - - bb6: { - _11 = const "TestSet not found: " + copy _2; - throw copy _11; - } } -fn testing.flatten_with_tolerated(report: testing.TestSetReport) -> testing.FlatTestReport { +fn testing.testset_children_selected(registry: testing.TestRegistry, names: string[]) -> testing.TestSetChild[] { // Locals: - let _0: testing.FlatTestReport // _0 // return - let _1: testing.TestSetReport // report // param - let _2: bool // top_tolerated - let _3: "error" | "fail" | "pass" - let _4: testing.LeafCounts // counts - let _5: bool - let _6: int - let _7: ((testing.TestReport | testing.TestSetReport)[]) -> int throws never - let _8: (testing.TestReport | testing.TestSetReport)[] - let _9: bool - let _10: bool - let _11: int - let _12: int - let _13: int - let _14: int - let _15: int - let _16: int - let _17: string[] // messages - let _18: void - let _19: (testing.TestReport | testing.TestSetReport)[] - let _20: string[] - let _21: "error" | "fail" | "pass" - let _22: int - let _23: int - let _24: int - let _25: int - let _26: string[] - let _27: string[] + let _0: testing.TestSetChild[] // _0 // return + let _1: testing.TestRegistry // registry // param + let _2: string[] // names // param + let _3: testing.TestSetChild[] // children + let _4: testing.TestRegistration[] + let _5: baml.iter.Iterator + let _6: unknown + let _7: bool + let _8: testing.TestRegistration + let _9: testing.TestRegistration // t + let _10: void + let _11: bool + let _12: string + let _13: testing.TestSetChild + let _14: string + let _15: () -> void throws unknown + let _16: null | ((() -> testing.TestReport throws never) -> (() -> testing.TestReport throws never) throws never) + let _17: testing.TestSetRegistration[] + let _18: baml.iter.Iterator + let _19: unknown + let _20: bool + let _21: testing.TestSetRegistration + let _22: testing.TestSetRegistration // ts + let _23: void + let _24: bool + let _25: string + let _26: testing.TestSetChild + let _27: testing.TestSetRegistration bb0: { - _3 = copy _1.0; - _2 = call const fn baml.ops.equals_equals(copy _3, const "pass") -> [bb1]; + _3 = []: testing.TestSetChild[]; + _4 = copy _1.0.1; + _5 = virtual_call iter as baml.iter.Iterable(copy _4) -> [bb1]; } bb1: { - _7 = copy _1.5; - _6 = len(_7); - goto -> bb2; + _6 = virtual_call next as baml.iter.Iterator(copy _5) -> [bb2]; } bb2: { - _5 = copy _6 > const 0_i64; - branch copy _5 -> [bb6, bb3]; + _7 = is_type(copy _6, baml.iter.Done); + branch copy _7 -> [bb8, bb3]; } bb3: { - _10 = copy _2; - branch copy _10 -> [bb5, bb4]; + _8 = copy _6; + fresh_cell(_9); + _9 = copy _8; + _12 = copy _9.0; + _11 = call const fn testing._name_selected(copy _12, copy _2) -> [bb4]; } bb4: { - _14 = copy _1.1; - _15 = copy _1.2; - _16 = copy _1.3; - _4 = testing.LeafCounts { copy _14, copy _15, const 0_i64, copy _16 }; - goto -> bb7; + branch copy _11 -> [bb6, bb5]; } bb5: { - _11 = copy _1.1; - _12 = copy _1.2; - _13 = copy _1.3; - _4 = testing.LeafCounts { copy _11, const 0_i64, copy _12, copy _13 }; - goto -> bb7; + _10 = const null; + goto -> bb1; } bb6: { - _8 = copy _1.5; - _9 = copy _2; - _4 = call const fn testing.count_leaves(copy _8, copy _9) -> [bb7]; + _14 = copy _9.0; + _15 = copy _9.1; + _16 = copy _9.2; + _13 = call const fn testing.test_child(copy _14, copy _15, copy _16) -> [bb7]; } bb7: { - _17 = []: string[]; - _19 = copy _1.5; - _20 = copy _17; - _18 = call const fn testing.collect_leaf_messages(copy _19, copy _20) -> [bb8]; + _10 = call const fn baml.Array.push(copy _3, copy _13) -> [bb1]; } bb8: { - _21 = copy _1.0; - _22 = copy _4.0; - _23 = copy _4.1; - _24 = copy _4.2; - _25 = copy _4.3; - _26 = copy _1.4; - _27 = copy _17; - _0 = testing.FlatTestReport { copy _21, copy _22, copy _23, copy _24, copy _25, copy _26, copy _27 }; - goto -> bb9; + _17 = copy _1.0.2; + _18 = virtual_call iter as baml.iter.Iterable(copy _17) -> [bb9]; } bb9: { - return; - } -} - -fn testing.glob_match(subject: string, pattern: string) -> bool { - // Locals: - let _0: bool // _0 // return - let _1: string // subject // param - let _2: string // pattern // param - let _3: string[] // parts - let _4: int // n - let _5: bool - let _6: int - let _7: string // first - let _8: string[] - let _9: 0 - let _10: string // last - let _11: string[] - let _12: int - let _13: int - let _14: bool - let _15: bool - let _16: string - let _17: bool - let _18: bool - let _19: string - let _20: int // start - let _21: int // end_limit - let _22: int - let _23: int - let _24: bool - let _25: int - let _26: int - let _27: int // pos - let _28: int // i - let _29: bool - let _30: int - let _31: int - let _32: int - let _33: string // part - let _34: string[] - let _35: int - let _36: bool - let _37: string - let _38: int | null - let _39: string - let _40: int - let _41: int - let _42: string - let _43: bool - let _44: int // idx - let _45: int - let _46: int - let _47: int - let _48: int - - bb0: { - _3 = call const fn baml.String.split(copy _2, const "*") -> [bb1]; - } - - bb1: { - _4 = len(_3); - goto -> bb2; - } - - bb2: { - _6 = copy _4; - _5 = copy _6 == const 1_i64; - branch copy _5 -> [bb25, bb3]; - } - - bb3: { - _8 = copy _3; - _9 = const 0_i64; - _7 = copy _8[_9]; - _11 = copy _3; - _13 = copy _4; - _12 = copy _13 - const 1_i64; - _10 = copy _11[_12]; - _16 = copy _7; - _15 = call const fn baml.String.starts_with(copy _1, copy _16) -> [bb4]; - } - - bb4: { - _14 = !copy _15; - branch copy _14 -> [bb24, bb5]; - } - - bb5: { - _19 = copy _10; - _18 = call const fn baml.String.ends_with(copy _1, copy _19) -> [bb6]; - } - - bb6: { - _17 = !copy _18; - branch copy _17 -> [bb23, bb7]; - } - - bb7: { - _20 = call const fn baml.String.length(copy _7) -> [bb8]; - } - - bb8: { - _22 = call const fn baml.String.length(copy _1) -> [bb9]; - } - - bb9: { - _23 = call const fn baml.String.length(copy _10) -> [bb10]; + _19 = virtual_call next as baml.iter.Iterator(copy _18) -> [bb10]; } bb10: { - _21 = copy _22 - copy _23; - _25 = copy _20; - _26 = copy _21; - _24 = copy _25 > copy _26; - branch copy _24 -> [bb22, bb11]; + _20 = is_type(copy _19, baml.iter.Done); + branch copy _20 -> [bb16, bb11]; } bb11: { - _27 = copy _20; - _28 = const 1_i64; - goto -> bb12; + _21 = copy _19; + fresh_cell(_22); + _22 = copy _21; + _25 = copy _22.0; + _24 = call const fn testing._has_selected_descendant(copy _25, copy _2) -> [bb12]; } bb12: { - _30 = copy _28; - _32 = copy _4; - _31 = copy _32 - const 1_i64; - _29 = copy _30 < copy _31; - branch copy _29 -> [bb14, bb13]; + branch copy _24 -> [bb14, bb13]; } bb13: { - _0 = const true; - goto -> bb26; + _23 = const null; + goto -> bb9; } bb14: { - _34 = copy _3; - _35 = copy _28; - _33 = copy _34[_35]; - _37 = copy _33; - _36 = copy _37 != const ""; - branch copy _36 -> [bb15, bb21]; + _27 = copy _22; + _26 = call const fn testing.testset_child_selected(copy _1, copy _27, copy _2) -> [bb15]; } bb15: { - _40 = copy _27; - _41 = copy _21; - _39 = call const fn baml.String.substring(copy _1, copy _40, copy _41) -> [bb16]; + _23 = call const fn baml.Array.push(copy _3, copy _26) -> [bb9]; } bb16: { - _42 = copy _33; - _38 = call const fn baml.String.index_of(copy _39, copy _42) -> [bb17]; + _0 = copy _3; + goto -> bb17; } bb17: { - _43 = is_type(copy _38, int); - branch copy _43 -> [bb19, bb18]; + return; } +} - bb18: { - _0 = const false; - goto -> bb26; - } +fn testing.test_child(name: string, body: () -> void throws unknown, runner: null | ((() -> testing.TestReport throws never) -> (() -> testing.TestReport throws never) throws never)) -> testing.TestSetChild { + // Locals: + let _0: testing.TestSetChild // _0 // return + let _1: string // name // param + let _2: () -> void throws unknown // body // param [captured] + let _3: null | ((() -> testing.TestReport throws never) -> (() -> testing.TestReport throws never) throws never) // runner // param [captured] + let _4: () -> testing.TestReport | testing.TestSetReport throws never - bb19: { - _44 = copy _38; - _46 = copy _27; - _47 = copy _44; - _45 = copy _46 + copy _47; - _48 = call const fn baml.String.length(copy _33) -> [bb20]; + bb0: { + _4 = make_closure lambda[0](copy _2, copy _3); + _0 = testing.TestSetChild { copy _1, copy _4 }; + goto -> bb1; } - bb20: { - _27 = copy _45 + copy _48; - goto -> bb21; + bb1: { + return; } +} - bb21: { - _28 = copy _28 + const 1_i64; - goto -> bb12; - } +// lambda[0] +fn .() -> null { + // Locals: + let _0: null // _0 // return + let _1: () -> void throws unknown + let _2: null | ((() -> testing.TestReport throws never) -> (() -> testing.TestReport throws never) throws never) - bb22: { - _0 = const false; - goto -> bb26; + bb0: { + _1 = copy capture[0]; + _2 = copy capture[1]; + _0 = call const fn testing.run_test(copy _1, copy _2) -> [bb1]; } - bb23: { - _0 = const false; - goto -> bb26; + bb1: { + return; } +} - bb24: { - _0 = const false; - goto -> bb26; - } +fn testing.testset_child(registry: testing.TestRegistry, ts: testing.TestSetRegistration) -> testing.TestSetChild { + // Locals: + let _0: testing.TestSetChild // _0 // return + let _1: testing.TestRegistry // registry // param [captured] + let _2: testing.TestSetRegistration // ts // param [captured] + let _3: string + let _4: () -> testing.TestReport | testing.TestSetReport throws never - bb25: { - _0 = copy _1 == copy _2; - goto -> bb26; + bb0: { + _3 = copy _2.0; + _4 = make_closure lambda[0](copy _1, copy _2); + _0 = testing.TestSetChild { copy _3, copy _4 }; + goto -> bb1; } - bb26: { + bb1: { return; } } -fn testing.leaf_selected(name: string, include: testing.FilterPat[], exclude: testing.FilterPat[]) -> bool { +// lambda[0] +fn .() -> null { // Locals: - let _0: bool // _0 // return - let _1: string // name // param - let _2: testing.FilterPat[] // include // param - let _3: testing.FilterPat[] // exclude // param - let _4: testing.NameSplit // split - let _5: bool - let _6: string + let _0: null // _0 // return + let _1: unknown // e + let _2: testing.TestSetChild[] + let _3: testing.TestRegistry + let _4: testing.TestSetRegistration + let _5: null | ((testing.TestSetChild[]) -> testing.TestSetReport throws never) + let _6: int let _7: string - let _8: bool - let _9: int - let _10: string - let _11: string + let _8: string bb0: { - _4 = call const fn testing.split_top(copy _1) -> [bb1]; + _4 = copy capture[1]; + _3 = call const fn testing.TestRegistry.expand_testset_registry(copy capture[0], copy _4) -> [bb1, unwind: bb3]; } bb1: { - _6 = copy _4.0; - _7 = copy _4.1; - _5 = call const fn testing.any_pattern_matches(copy _3, copy _6, copy _7) -> [bb2]; + _2 = call const fn testing.testset_children(copy _3) -> [bb2, unwind: bb3]; } bb2: { - branch copy _5 -> [bb7, bb3]; + _5 = copy capture[1].2; + _0 = call const fn testing.run_testset(copy _2, copy _5) -> [bb7, unwind: bb3]; } bb3: { - _9 = len(_2); - goto -> bb4; + _6 = type_tag(_1); + switch copy _6 [DivisionByZero: bb6, IndexOutOfBounds: bb6, InvalidFieldAccess: bb6, MapKeyNotFound: bb6, StackOverflow: bb6, AssertionFailed: bb6, Unreachable: bb6, Cancelled: bb6, UserPanic: bb6, Exit: bb6, AllocFailure: bb6, HostUnavailable: bb6, NegativeBitShift: bb6, SdkPanic: bb6, HostContractViolation: bb6, IntegerOverflow: bb6, otherwise: bb4]; } bb4: { - _8 = copy _9 == const 0_i64; - branch copy _8 -> [bb6, bb5]; + throw_if_panic copy _1 -> bb5; } bb5: { - _10 = copy _4.0; - _11 = copy _4.1; - _0 = call const fn testing.any_pattern_matches(copy _2, copy _10, copy _11) -> [bb8]; + _8 = copy capture[1].0; + _0 = call const fn testing.expansion_error_report(copy _8) -> [bb7]; } bb6: { - _0 = const true; - goto -> bb8; + _7 = copy capture[1].0; + _0 = call const fn testing.expansion_error_report(copy _7) -> [bb7]; } bb7: { - _0 = const false; - goto -> bb8; - } - - bb8: { - return; - } -} - -fn testing.TestRegistry.list_filtered(self: testing.TestRegistry, include: string[], exclude: string[]) -> string[] { - // Locals: - let _0: string[] // _0 // return - let _1: testing.TestRegistry // self // param - let _2: string[] // include // param - let _3: string[] // exclude // param - - bb0: { - _0 = call const fn testing.select_names(copy _1, copy _2, copy _3) -> [bb1]; - } - - bb1: { - return; - } -} - -fn testing.TestRegistry.new(collector: testing.TestCollector) -> testing.TestRegistry { - // Locals: - let _0: testing.TestRegistry // _0 // return - let _1: testing.TestCollector // collector // param - let _2: map - - bb0: { - _2 = { }: map; - _0 = testing.TestRegistry { copy _1, copy _2, const 0_i64 }; - goto -> bb1; - } - - bb1: { return; } } -fn testing.TestCollector.new(prefix: string) -> testing.TestCollector { +fn testing.testset_child_selected(registry: testing.TestRegistry, ts: testing.TestSetRegistration, names: string[]) -> testing.TestSetChild { // Locals: - let _0: testing.TestCollector // _0 // return - let _1: string // prefix // param - let _2: testing.TestRegistration[] - let _3: testing.TestSetRegistration[] + let _0: testing.TestSetChild // _0 // return + let _1: testing.TestRegistry // registry // param [captured] + let _2: testing.TestSetRegistration // ts // param [captured] + let _3: string[] // names // param [captured] + let _4: string + let _5: () -> testing.TestReport | testing.TestSetReport throws never bb0: { - _2 = []: testing.TestRegistration[]; - _3 = []: testing.TestSetRegistration[]; - _0 = testing.TestCollector { copy _1, copy _2, copy _3 }; + _4 = copy _2.0; + _5 = make_closure lambda[0](copy _1, copy _2, copy _3); + _0 = testing.TestSetChild { copy _4, copy _5 }; goto -> bb1; } @@ -1628,701 +1469,490 @@ fn testing.TestCollector.new(prefix: string) -> testing.TestCollector { } } -fn testing.parse_filter_patterns(raw: string[]) -> testing.FilterPat[] { +// lambda[0] +fn .() -> null { // Locals: - let _0: testing.FilterPat[] // _0 // return - let _1: string[] // raw // param - let _2: testing.FilterPat[] // out - let _3: baml.iter.Iterator - let _4: unknown - let _5: bool - let _6: string - let _7: string // s - let _8: void - let _9: int | null - let _10: bool - let _11: int // idx - let _12: testing.FilterPat - let _13: string - let _14: int - let _15: string - let _16: int - let _17: int - let _18: int - let _19: int - let _20: testing.FilterPat - let _21: string - let _22: testing.FilterPat - let _23: string + let _0: null // _0 // return + let _1: unknown // e + let _2: testing.TestSetChild[] + let _3: testing.TestRegistry + let _4: testing.TestSetRegistration + let _5: string[] + let _6: null | ((testing.TestSetChild[]) -> testing.TestSetReport throws never) + let _7: int + let _8: string + let _9: string bb0: { - _2 = []: testing.FilterPat[]; - _3 = virtual_call iter as baml.iter.Iterable(copy _1) -> [bb1]; + _4 = copy capture[1]; + _3 = call const fn testing.TestRegistry.expand_testset_registry(copy capture[0], copy _4) -> [bb1, unwind: bb3]; } bb1: { - _4 = virtual_call next as baml.iter.Iterator(copy _3) -> [bb2]; + _5 = copy capture[2]; + _2 = call const fn testing.testset_children_selected(copy _3, copy _5) -> [bb2, unwind: bb3]; } bb2: { - _5 = is_type(copy _4, baml.iter.Done); - branch copy _5 -> [bb11, bb3]; + _6 = copy capture[1].2; + _0 = call const fn testing.run_testset(copy _2, copy _6) -> [bb7, unwind: bb3]; } bb3: { - _6 = copy _4; - fresh_cell(_7); - _7 = copy _6; - _9 = call const fn baml.String.index_of(copy _7, const "::") -> [bb4]; + _7 = type_tag(_1); + switch copy _7 [DivisionByZero: bb6, IndexOutOfBounds: bb6, InvalidFieldAccess: bb6, MapKeyNotFound: bb6, StackOverflow: bb6, AssertionFailed: bb6, Unreachable: bb6, Cancelled: bb6, UserPanic: bb6, Exit: bb6, AllocFailure: bb6, HostUnavailable: bb6, NegativeBitShift: bb6, SdkPanic: bb6, HostContractViolation: bb6, IntegerOverflow: bb6, otherwise: bb4]; } bb4: { - _10 = is_type(copy _9, int); - branch copy _10 -> [bb7, bb5]; + throw_if_panic copy _1 -> bb5; } bb5: { - _21 = copy _7; - _20 = testing.FilterPat { copy _21, const "" }; - _19 = call const fn baml.Array.push(copy _2, copy _20) -> [bb6]; + _9 = copy capture[1].0; + _0 = call const fn testing.expansion_error_report(copy _9) -> [bb7]; } bb6: { - _23 = copy _7; - _22 = testing.FilterPat { const "", copy _23 }; - _8 = call const fn baml.Array.push(copy _2, copy _22) -> [bb1]; + _8 = copy capture[1].0; + _0 = call const fn testing.expansion_error_report(copy _8) -> [bb7]; } bb7: { - _11 = copy _9; - _14 = copy _11; - _13 = call const fn baml.String.substring(copy _7, const 0_i64, copy _14) -> [bb8]; - } - - bb8: { - _17 = copy _11; - _16 = copy _17 + const 2_i64; - _18 = call const fn baml.String.length(copy _7) -> [bb9]; - } - - bb9: { - _15 = call const fn baml.String.substring(copy _7, copy _16, copy _18) -> [bb10]; - } - - bb10: { - _12 = testing.FilterPat { copy _13, copy _15 }; - _8 = call const fn baml.Array.push(copy _2, copy _12) -> [bb1]; - } - - bb11: { - _0 = copy _2; - goto -> bb12; - } - - bb12: { return; } } -fn testing.TestCollector.register_test(self: testing.TestCollector, name: string, body: () -> void throws unknown, runner: null | ((() -> testing.TestReport throws never) -> (() -> testing.TestReport throws never) throws never)) -> void { +fn testing._name_selected(name: string, names: string[]) -> bool { // Locals: - let _0: void // _0 // return - let _1: testing.TestCollector // self // param - let _2: string // name // param - let _3: () -> void throws unknown // body // param - let _4: null | ((() -> testing.TestReport throws never) -> (() -> testing.TestReport throws never) throws never) // runner // param - let _5: string // full_name - let _6: bool - let _7: string - let _8: string + let _0: bool // _0 // return + let _1: string // name // param + let _2: string[] // names // param + let _3: baml.iter.Iterator + let _4: unknown + let _5: bool + let _6: string + let _7: string // selected + let _8: bool let _9: string - let _10: int // count - let _11: string // hash_prefix - let _12: string - let _13: testing.TestRegistration[] - let _14: baml.iter.Iterator - let _15: unknown - let _16: bool - let _17: testing.TestRegistration - let _18: testing.TestRegistration // t - let _19: bool - let _20: bool - let _21: string - let _22: string - let _23: (baml.String, string) -> bool throws never - let _24: string - let _25: string // final_name - let _26: bool - let _27: int - let _28: string - let _29: string - let _30: string - let _31: int - let _32: int - let _33: type - let _34: int - let _35: (testing.TestRegistration[], testing.TestRegistration) -> int throws never - let _36: testing.TestRegistration - let _37: string - let _38: type bb0: { - _7 = copy _1.0; - _6 = copy _7 == const ""; - branch copy _6 -> [bb2, bb1]; + _3 = virtual_call iter as baml.iter.Iterable(copy _2) -> [bb1]; } bb1: { - _9 = copy _1.0; - _8 = copy _9 + const "/"; - _5 = copy _8 + copy _2; - goto -> bb3; + _4 = virtual_call next as baml.iter.Iterator(copy _3) -> [bb2]; } bb2: { - _5 = copy _2; - goto -> bb3; + _5 = is_type(copy _4, baml.iter.Done); + branch copy _5 -> [bb5, bb3]; } bb3: { - _10 = const 0_i64; - _12 = copy _5; - _11 = copy _12 + const "#"; - _13 = copy _1.1; - _14 = virtual_call iter as baml.iter.Iterable(copy _13) -> [bb4]; + _6 = copy _4; + fresh_cell(_7); + _7 = copy _6; + _9 = copy _7; + _8 = copy _9 == copy _1; + branch copy _8 -> [bb4, bb1]; } bb4: { - _15 = virtual_call next as baml.iter.Iterator(copy _14) -> [bb5]; + _0 = const true; + goto -> bb6; } bb5: { - _16 = is_type(copy _15, baml.iter.Done); - branch copy _16 -> [bb10, bb6]; + _0 = const false; + goto -> bb6; } bb6: { - _17 = copy _15; - fresh_cell(_18); - _18 = copy _17; - _21 = copy _18.0; - _22 = copy _5; - _20 = copy _21 == copy _22; - _19 = short_circuit(||) copy _20 -> [eval: bb7, join: bb8]; - } - - bb7: { - _23 = copy _18.0; - _24 = copy _11; - _19 = call const fn baml.String.starts_with(copy _23, copy _24) -> [bb8]; - } - - bb8: { - branch copy _19 -> [bb9, bb4]; - } - - bb9: { - _10 = copy _10 + const 1_i64; - goto -> bb4; - } - - bb10: { - _27 = copy _10; - _26 = copy _27 > const 0_i64; - branch copy _26 -> [bb12, bb11]; - } - - bb11: { - _25 = copy _5; - goto -> bb14; - } - - bb12: { - _29 = copy _5; - _28 = copy _29 + const "#"; - _32 = copy _10; - _31 = copy _32 + const 1_i64; - _33 = load_type(int); - _30 = call const fn baml.String.from(copy _31) -> [bb13]; - } - - bb13: { - _25 = copy _28 + copy _30; - goto -> bb14; - } - - bb14: { - _35 = copy _1.1; - _37 = copy _25; - _36 = testing.TestRegistration { copy _37, copy _3, copy _4 }; - _38 = load_type(testing.TestRegistration); - _34 = call const fn baml.Array.push(copy _35, copy _36) -> [bb15]; - } - - bb15: { - _0 = const null; - goto -> bb16; - } - - bb16: { return; } } -fn testing.TestCollector.register_test_set(self: testing.TestCollector, name: string, collector: (testing.TestCollector) -> void throws unknown, runner: null | ((testing.TestSetChild[]) -> testing.TestSetReport throws never)) -> void { +fn testing._has_selected_descendant(prefix: string, names: string[]) -> bool { // Locals: - let _0: void // _0 // return - let _1: testing.TestCollector // self // param - let _2: string // name // param - let _3: (testing.TestCollector) -> void throws unknown // collector // param - let _4: null | ((testing.TestSetChild[]) -> testing.TestSetReport throws never) // runner // param - let _5: string // full_name + let _0: bool // _0 // return + let _1: string // prefix // param + let _2: string[] // names // param + let _3: string // descendant_prefix + let _4: baml.iter.Iterator + let _5: unknown let _6: bool let _7: string - let _8: string - let _9: string - let _10: int // count - let _11: string // hash_prefix - let _12: string - let _13: testing.TestSetRegistration[] - let _14: baml.iter.Iterator - let _15: unknown - let _16: bool - let _17: testing.TestSetRegistration - let _18: testing.TestSetRegistration // ts - let _19: bool - let _20: bool - let _21: string - let _22: string - let _23: (baml.String, string) -> bool throws never - let _24: string - let _25: string // final_name - let _26: bool - let _27: int - let _28: string - let _29: string - let _30: string - let _31: int - let _32: int - let _33: type - let _34: int - let _35: (testing.TestSetRegistration[], testing.TestSetRegistration) -> int throws never - let _36: testing.TestSetRegistration - let _37: string - let _38: type + let _8: string // selected + let _9: bool + let _10: string bb0: { - _7 = copy _1.0; - _6 = copy _7 == const ""; - branch copy _6 -> [bb2, bb1]; + _3 = copy _1 + const "/"; + _4 = virtual_call iter as baml.iter.Iterable(copy _2) -> [bb1]; } bb1: { - _9 = copy _1.0; - _8 = copy _9 + const "/"; - _5 = copy _8 + copy _2; - goto -> bb3; + _5 = virtual_call next as baml.iter.Iterator(copy _4) -> [bb2]; } bb2: { - _5 = copy _2; - goto -> bb3; + _6 = is_type(copy _5, baml.iter.Done); + branch copy _6 -> [bb6, bb3]; } bb3: { - _10 = const 0_i64; - _12 = copy _5; - _11 = copy _12 + const "#"; - _13 = copy _1.2; - _14 = virtual_call iter as baml.iter.Iterable(copy _13) -> [bb4]; + _7 = copy _5; + fresh_cell(_8); + _8 = copy _7; + _10 = copy _3; + _9 = call const fn baml.String.starts_with(copy _8, copy _10) -> [bb4]; } bb4: { - _15 = virtual_call next as baml.iter.Iterator(copy _14) -> [bb5]; + branch copy _9 -> [bb5, bb1]; } bb5: { - _16 = is_type(copy _15, baml.iter.Done); - branch copy _16 -> [bb10, bb6]; + _0 = const true; + goto -> bb7; } bb6: { - _17 = copy _15; - fresh_cell(_18); - _18 = copy _17; - _21 = copy _18.0; - _22 = copy _5; - _20 = copy _21 == copy _22; - _19 = short_circuit(||) copy _20 -> [eval: bb7, join: bb8]; + _0 = const false; + goto -> bb7; } bb7: { - _23 = copy _18.0; - _24 = copy _11; - _19 = call const fn baml.String.starts_with(copy _23, copy _24) -> [bb8]; - } - - bb8: { - branch copy _19 -> [bb9, bb4]; - } - - bb9: { - _10 = copy _10 + const 1_i64; - goto -> bb4; - } - - bb10: { - _27 = copy _10; - _26 = copy _27 > const 0_i64; - branch copy _26 -> [bb12, bb11]; - } - - bb11: { - _25 = copy _5; - goto -> bb14; - } - - bb12: { - _29 = copy _5; - _28 = copy _29 + const "#"; - _32 = copy _10; - _31 = copy _32 + const 1_i64; - _33 = load_type(int); - _30 = call const fn baml.String.from(copy _31) -> [bb13]; - } - - bb13: { - _25 = copy _28 + copy _30; - goto -> bb14; - } - - bb14: { - _35 = copy _1.2; - _37 = copy _25; - _36 = testing.TestSetRegistration { copy _37, copy _3, copy _4 }; - _38 = load_type(testing.TestSetRegistration); - _34 = call const fn baml.Array.push(copy _35, copy _36) -> [bb15]; - } - - bb15: { - _0 = const null; - goto -> bb16; - } - - bb16: { return; } } -fn testing.TestRegistry.run_all(self: testing.TestRegistry) -> testing.TestSetReport { - // Locals: - let _0: testing.TestSetReport // _0 // return - let _1: testing.TestRegistry // self // param - let _2: testing.TestSetChild[] - - bb0: { - _2 = call const fn testing.testset_children(copy _1) -> [bb1]; - } - - bb1: { - _0 = call const fn testing.run_testset(copy _2, const null) -> [bb2]; - } - - bb2: { - return; - } -} - -fn testing.run_children_parallel(children: testing.TestSetChild[]) -> testing.TestSetReport { +fn testing.aggregate_reports(named_results: testing.NamedChildReport[]) -> testing.TestSetReport { // Locals: let _0: testing.TestSetReport // _0 // return - let _1: testing.TestSetChild[] // children // param - let _2: future[] // futures - let _3: baml.iter.Iterator - let _4: unknown - let _5: bool - let _6: testing.TestSetChild - let _7: testing.TestSetChild // child [captured] - let _8: void - let _9: future - let _10: null - let _11: null - let _12: testing.NamedChildReport[] // named_results - let _13: unknown // e - let _14: null - let _15: future[] - let _16: type - let _17: type - let _18: testing.NamedChildReport[] + let _1: testing.NamedChildReport[] // named_results // param + let _2: int // passed + let _3: int // failed + let _4: bool // has_error + let _5: string[] // failed_names + let _6: (testing.TestReport | testing.TestSetReport)[] // results + let _7: baml.iter.Iterator + let _8: unknown + let _9: bool + let _10: testing.NamedChildReport + let _11: testing.NamedChildReport // named_result + let _12: testing.TestReport | testing.TestSetReport // result + let _13: int + let _14: testing.TestReport | testing.TestSetReport + let _15: "error" | "fail" | "pass" // outcome + let _16: bool + let _17: testing.TestReport // report + let _18: testing.TestSetReport // report + let _19: bool + let _20: "error" | "fail" | "pass" + let _21: string[] // child_failed_names + let _22: bool + let _23: string + let _24: testing.TestSetReport // report + let _25: bool + let _26: int + let _27: (string[]) -> int throws never + let _28: string + let _29: string[] + let _30: baml.iter.Iterator + let _31: unknown + let _32: bool + let _33: string + let _34: string // name + let _35: void + let _36: string + let _37: bool + let _38: "error" | "fail" | "pass" + let _39: "error" | "fail" | "pass" // outcome + let _40: bool + let _41: bool + let _42: int + let _43: "error" | "fail" | "pass" + let _44: int + let _45: int + let _46: int + let _47: string[] + let _48: (testing.TestReport | testing.TestSetReport)[] bb0: { - _2 = []: future[]; - _3 = virtual_call iter as baml.iter.Iterable(copy _1) -> [bb1]; + _2 = const 0_i64; + _3 = const 0_i64; + _4 = const false; + _5 = []: string[]; + _6 = []: testing.TestReport | testing.TestSetReport[]; + _7 = virtual_call iter as baml.iter.Iterable(copy _1) -> [bb1]; } bb1: { - _4 = virtual_call next as baml.iter.Iterator(copy _3) -> [bb2]; + _8 = virtual_call next as baml.iter.Iterator(copy _7) -> [bb2]; } bb2: { - _5 = is_type(copy _4, baml.iter.Done); - branch copy _5 -> [bb5, bb3]; + _9 = is_type(copy _8, baml.iter.Done); + branch copy _9 -> [bb23, bb3]; } bb3: { - _6 = copy _4; - fresh_cell(_7); - _7 = copy _6; - _10 = make_closure lambda[0](copy _7); - _11 = spawn copy _10 name=const null -> bb4; + _10 = copy _8; + fresh_cell(_11); + _11 = copy _10; + _12 = copy _11.1; + _14 = copy _12; + _13 = call const fn baml.Array.push(copy _6, copy _14) -> [bb4]; } bb4: { - _9 = copy _11; - _8 = call const fn baml.Array.push(copy _2, copy _9) -> [bb1]; + _16 = is_type(copy _12, testing.TestReport); + branch copy _16 -> [bb6, bb5]; } bb5: { - _15 = copy _2; - _16 = load_type(testing.NamedChildReport); - _17 = load_type(null); - _14 = call const fn baml.future.all_complete(copy _15) -> [bb6, unwind: bb7]; + _18 = copy _12; + _15 = copy _18.0; + goto -> bb7; } bb6: { - _12 = await _14 -> [bb9, unwind: bb7]; + _17 = copy _12; + _15 = copy _17.0; + goto -> bb7; } bb7: { - throw_if_panic copy _13 -> bb8; + _20 = copy _15; + _19 = call const fn baml.ops.equals_equals(copy _20, const "pass") -> [bb8]; } bb8: { - _12 = call const fn baml.sys.panic(const "unexpected test child failure") -> [bb9]; + branch copy _19 -> [bb22, bb9]; } bb9: { - _18 = copy _12; - _0 = call const fn testing.aggregate_reports(copy _18) -> [bb10]; + _3 = copy _3 + const 1_i64; + _22 = is_type(copy _12, testing.TestReport); + branch copy _22 -> [bb14, bb10]; } bb10: { - return; + _24 = copy _12; + _27 = copy _24.4; + _26 = len(_27); + goto -> bb11; } -} -// lambda[0] -fn .() -> null { - // Locals: - let _0: null // _0 // return - let _1: string - let _2: testing.TestReport | testing.TestSetReport - let _3: () -> testing.TestReport | testing.TestSetReport throws never + bb11: { + _25 = copy _26 > const 0_i64; + branch copy _25 -> [bb13, bb12]; + } - bb0: { - _1 = copy capture[0].0; - _3 = copy capture[0].1; - _2 = call copy _3() -> [bb1]; + bb12: { + _28 = copy _11.0; + _21 = [copy _28]: string[]; + goto -> bb15; } - bb1: { - _0 = testing.NamedChildReport { copy _1, copy _2 }; - goto -> bb2; + bb13: { + _21 = copy _24.4; + goto -> bb15; } - bb2: { - return; + bb14: { + _23 = copy _11.0; + _21 = [copy _23]: string[]; + goto -> bb15; } -} -fn testing.TestRegistry.run_filtered(self: testing.TestRegistry, include: string[], exclude: string[]) -> testing.FlatTestReport { - // Locals: - let _0: testing.FlatTestReport // _0 // return - let _1: testing.TestRegistry // self // param - let _2: string[] // include // param - let _3: string[] // exclude // param - let _4: testing.TestSetReport // report - let _5: bool - let _6: bool - let _7: int - let _8: int - let _9: string[] - let _10: testing.TestSetReport + bb15: { + _29 = copy _21; + _30 = virtual_call iter as baml.iter.Iterable(copy _29) -> [bb16]; + } - bb0: { - _7 = len(_2); - goto -> bb1; + bb16: { + _31 = virtual_call next as baml.iter.Iterator(copy _30) -> [bb17]; } - bb1: { - _6 = copy _7 == const 0_i64; - _5 = short_circuit(&&) copy _6 -> [eval: bb2, join: bb4]; + bb17: { + _32 = is_type(copy _31, baml.iter.Done); + branch copy _32 -> [bb19, bb18]; } - bb2: { - _8 = len(_3); - goto -> bb3; + bb18: { + _33 = copy _31; + fresh_cell(_34); + _34 = copy _33; + _36 = copy _34; + _35 = call const fn baml.Array.push(copy _5, copy _36) -> [bb16]; } - bb3: { - _5 = copy _8 == const 0_i64; - goto -> bb4; + bb19: { + _38 = copy _15; + _37 = call const fn baml.ops.equals_equals(copy _38, const "error") -> [bb20]; } - bb4: { - branch copy _5 -> [bb7, bb5]; + bb20: { + branch copy _37 -> [bb21, bb1]; } - bb5: { - _9 = call const fn testing.select_names(copy _1, copy _2, copy _3) -> [bb6]; + bb21: { + _4 = const true; + goto -> bb1; } - bb6: { - _4 = call const fn testing.TestRegistry.run_selected(copy _1, copy _9) -> [bb8]; + bb22: { + _2 = copy _2 + const 1_i64; + goto -> bb1; } - bb7: { - _4 = call const fn testing.TestRegistry.run_all(copy _1) -> [bb8]; + bb23: { + _40 = copy _4; + branch copy _40 -> [bb27, bb24]; } - bb8: { - _10 = copy _4; - _0 = call const fn testing.flatten_with_tolerated(copy _10) -> [bb9]; + bb24: { + _42 = copy _3; + _41 = copy _42 == const 0_i64; + branch copy _41 -> [bb26, bb25]; } - bb9: { - return; + bb25: { + _39 = const "fail"; + goto -> bb28; } -} -fn testing.TestRegistry.run_selected(self: testing.TestRegistry, names: string[]) -> testing.TestSetReport { - // Locals: - let _0: testing.TestSetReport // _0 // return - let _1: testing.TestRegistry // self // param - let _2: string[] // names // param - let _3: testing.TestSetChild[] + bb26: { + _39 = const "pass"; + goto -> bb28; + } - bb0: { - _3 = call const fn testing.testset_children_selected(copy _1, copy _2) -> [bb1]; + bb27: { + _39 = const "error"; + goto -> bb28; } - bb1: { - _0 = call const fn testing.run_testset(copy _3, const null) -> [bb2]; + bb28: { + _43 = copy _39; + _44 = copy _2; + _45 = copy _3; + _46 = len(_6); + goto -> bb29; } - bb2: { + bb29: { + _47 = copy _5; + _48 = copy _6; + _0 = testing.TestSetReport { copy _43, copy _44, copy _45, copy _46, copy _47, copy _48 }; + goto -> bb30; + } + + bb30: { return; } } -fn testing.TestRegistry.run_test(self: testing.TestRegistry, name: string) -> testing.TestReport { +fn testing.run_children_parallel(children: testing.TestSetChild[]) -> testing.TestSetReport { // Locals: - let _0: testing.TestReport // _0 // return - let _1: testing.TestRegistry // self // param - let _2: string // name // param - let _3: testing.TestRegistration[] - let _4: baml.iter.Iterator - let _5: unknown - let _6: bool - let _7: testing.TestRegistration - let _8: testing.TestRegistration // t - let _9: bool - let _10: string - let _11: () -> void throws unknown - let _12: null | ((() -> testing.TestReport throws never) -> (() -> testing.TestReport throws never) throws never) - let _13: string[] - let _14: (map) -> string[] throws never - let _15: type + let _0: testing.TestSetReport // _0 // return + let _1: testing.TestSetChild[] // children // param + let _2: future[] // futures + let _3: baml.iter.Iterator + let _4: unknown + let _5: bool + let _6: testing.TestSetChild + let _7: testing.TestSetChild // child [captured] + let _8: void + let _9: future + let _10: null + let _11: null + let _12: testing.NamedChildReport[] // named_results + let _13: unknown // e + let _14: null + let _15: future[] let _16: type - let _17: baml.iter.Iterator - let _18: unknown - let _19: bool - let _20: string - let _21: string // k - let _22: testing.TestRegistry // sub - let _23: map - let _24: string - let _25: bool - let _26: string - let _27: string - let _28: string + let _17: type + let _18: testing.NamedChildReport[] bb0: { - _3 = copy _1.0.1; - _4 = virtual_call iter as baml.iter.Iterable(copy _3) -> [bb1]; + _2 = []: future[]; + _3 = virtual_call iter as baml.iter.Iterable(copy _1) -> [bb1]; } bb1: { - _5 = virtual_call next as baml.iter.Iterator(copy _4) -> [bb2]; + _4 = virtual_call next as baml.iter.Iterator(copy _3) -> [bb2]; } bb2: { - _6 = is_type(copy _5, baml.iter.Done); - branch copy _6 -> [bb5, bb3]; + _5 = is_type(copy _4, baml.iter.Done); + branch copy _5 -> [bb5, bb3]; } bb3: { - _7 = copy _5; - fresh_cell(_8); - _8 = copy _7; - _10 = copy _8.0; - _9 = copy _10 == copy _2; - branch copy _9 -> [bb4, bb1]; + _6 = copy _4; + fresh_cell(_7); + _7 = copy _6; + _10 = make_closure lambda[0](copy _7); + _11 = spawn copy _10 name=const null -> bb4; } bb4: { - _11 = copy _8.1; - _12 = copy _8.2; - _0 = call const fn testing.run_test(copy _11, copy _12) -> [bb12]; + _9 = copy _11; + _8 = call const fn baml.Array.push(copy _2, copy _9) -> [bb1]; } bb5: { - _14 = copy _1.1; - _15 = load_type(string); - _16 = load_type(testing.TestRegistry); - _13 = call const fn baml.Map.keys(copy _14) -> [bb6]; + _15 = copy _2; + _16 = load_type(testing.NamedChildReport); + _17 = load_type(null); + _14 = call const fn baml.future.all_complete(copy _15) -> [bb6, unwind: bb7]; } bb6: { - _17 = virtual_call iter as baml.iter.Iterable(copy _13) -> [bb7]; + _12 = await _14 -> [bb9, unwind: bb7]; } bb7: { - _18 = virtual_call next as baml.iter.Iterator(copy _17) -> [bb8]; + throw_if_panic copy _13 -> bb8; } bb8: { - _19 = is_type(copy _18, baml.iter.Done); - branch copy _19 -> [bb13, bb9]; + _12 = call const fn baml.sys.panic(const "unexpected test child failure") -> [bb9]; } bb9: { - _20 = copy _18; - fresh_cell(_21); - _21 = copy _20; - _23 = copy _1.1; - _24 = copy _21; - _22 = copy _23[_24]; - _27 = copy _21; - _26 = copy _27 + const "/"; - _25 = call const fn baml.String.starts_with(copy _2, copy _26) -> [bb10]; + _18 = copy _12; + _0 = call const fn testing.aggregate_reports(copy _18) -> [bb10]; } bb10: { - branch copy _25 -> [bb11, bb7]; + return; } +} - bb11: { - _0 = call const fn testing.TestRegistry.run_test(copy _22, copy _2) -> [bb12]; +// lambda[0] +fn .() -> null { + // Locals: + let _0: null // _0 // return + let _1: string + let _2: testing.TestReport | testing.TestSetReport + let _3: () -> testing.TestReport | testing.TestSetReport throws never + + bb0: { + _1 = copy capture[0].0; + _3 = copy capture[0].1; + _2 = call copy _3() -> [bb1]; } - bb12: { - return; + bb1: { + _0 = testing.NamedChildReport { copy _1, copy _2 }; + goto -> bb2; } - bb13: { - _28 = const "Test not found: " + copy _2; - throw copy _28; + bb2: { + return; } } @@ -2488,585 +2118,642 @@ fn testing.run_testset(children: testing.TestSetChild[], runner: null | ((testin } } -fn testing.TestRegistry.run_testset(self: testing.TestRegistry, name: string) -> testing.TestSetReport { +fn testing.expansion_error_report(name: string) -> testing.TestSetReport { // Locals: let _0: testing.TestSetReport // _0 // return - let _1: testing.TestRegistry // self // param - let _2: string // name // param - let _3: testing.TestSetRegistration[] - let _4: baml.iter.Iterator - let _5: unknown - let _6: bool - let _7: testing.TestSetRegistration - let _8: testing.TestSetRegistration // ts - let _9: bool - let _10: string - let _11: testing.TestSetChild[] - let _12: testing.TestRegistry - let _13: testing.TestSetRegistration - let _14: null | ((testing.TestSetChild[]) -> testing.TestSetReport throws never) - let _15: string[] - let _16: (map) -> string[] throws never - let _17: type - let _18: type - let _19: baml.iter.Iterator - let _20: unknown - let _21: bool - let _22: string - let _23: string // k - let _24: testing.TestRegistry // sub - let _25: map - let _26: string - let _27: bool - let _28: string - let _29: string - let _30: string + let _1: string // name // param + let _2: string[] + let _3: string + let _4: (testing.TestReport | testing.TestSetReport)[] bb0: { - _3 = copy _1.0.2; - _4 = virtual_call iter as baml.iter.Iterable(copy _3) -> [bb1]; + _3 = copy _1 + const "/(testset error)"; + _2 = [copy _3]: string[]; + _4 = []: testing.TestReport | testing.TestSetReport[]; + _0 = testing.TestSetReport { const "error", const 0_i64, const 1_i64, const 1_i64, copy _2, copy _4 }; + goto -> bb1; } bb1: { - _5 = virtual_call next as baml.iter.Iterator(copy _4) -> [bb2]; + return; + } +} + +fn testing.split_top(path: string) -> testing.NameSplit { + // Locals: + let _0: testing.NameSplit // _0 // return + let _1: string // path // param + let _2: int | null + let _3: bool + let _4: int // idx + let _5: string + let _6: int + let _7: string + let _8: int + let _9: int + let _10: int + + bb0: { + _2 = call const fn baml.String.index_of(copy _1, const "/") -> [bb1]; + } + + bb1: { + _3 = is_type(copy _2, int); + branch copy _3 -> [bb3, bb2]; } bb2: { - _6 = is_type(copy _5, baml.iter.Done); - branch copy _6 -> [bb7, bb3]; + _0 = testing.NameSplit { const "", copy _1 }; + goto -> bb7; } bb3: { - _7 = copy _5; - fresh_cell(_8); - _8 = copy _7; - _10 = copy _8.0; - _9 = copy _10 == copy _2; - branch copy _9 -> [bb4, bb1]; + _4 = copy _2; + _6 = copy _4; + _5 = call const fn baml.String.substring(copy _1, const 0_i64, copy _6) -> [bb4]; } bb4: { - _13 = copy _8; - _12 = call const fn testing.TestRegistry.expand_testset_registry(copy _1, copy _13) -> [bb5]; + _9 = copy _4; + _8 = copy _9 + const 1_i64; + _10 = call const fn baml.String.length(copy _1) -> [bb5]; } bb5: { - _11 = call const fn testing.testset_children(copy _12) -> [bb6]; + _7 = call const fn baml.String.substring(copy _1, copy _8, copy _10) -> [bb6]; } bb6: { - _14 = copy _8.2; - _0 = call const fn testing.run_testset(copy _11, copy _14) -> [bb14]; + _0 = testing.NameSplit { copy _5, copy _7 }; + goto -> bb7; } bb7: { - _16 = copy _1.1; - _17 = load_type(string); - _18 = load_type(testing.TestRegistry); - _15 = call const fn baml.Map.keys(copy _16) -> [bb8]; + return; + } +} + +fn testing.parse_filter_patterns(raw: string[]) -> testing.FilterPat[] { + // Locals: + let _0: testing.FilterPat[] // _0 // return + let _1: string[] // raw // param + let _2: testing.FilterPat[] // out + let _3: baml.iter.Iterator + let _4: unknown + let _5: bool + let _6: string + let _7: string // s + let _8: void + let _9: int | null + let _10: bool + let _11: int // idx + let _12: testing.FilterPat + let _13: string + let _14: int + let _15: string + let _16: int + let _17: int + let _18: int + let _19: int + let _20: testing.FilterPat + let _21: string + let _22: testing.FilterPat + let _23: string + + bb0: { + _2 = []: testing.FilterPat[]; + _3 = virtual_call iter as baml.iter.Iterable(copy _1) -> [bb1]; + } + + bb1: { + _4 = virtual_call next as baml.iter.Iterator(copy _3) -> [bb2]; + } + + bb2: { + _5 = is_type(copy _4, baml.iter.Done); + branch copy _5 -> [bb11, bb3]; + } + + bb3: { + _6 = copy _4; + fresh_cell(_7); + _7 = copy _6; + _9 = call const fn baml.String.index_of(copy _7, const "::") -> [bb4]; + } + + bb4: { + _10 = is_type(copy _9, int); + branch copy _10 -> [bb7, bb5]; + } + + bb5: { + _21 = copy _7; + _20 = testing.FilterPat { copy _21, const "" }; + _19 = call const fn baml.Array.push(copy _2, copy _20) -> [bb6]; + } + + bb6: { + _23 = copy _7; + _22 = testing.FilterPat { const "", copy _23 }; + _8 = call const fn baml.Array.push(copy _2, copy _22) -> [bb1]; + } + + bb7: { + _11 = copy _9; + _14 = copy _11; + _13 = call const fn baml.String.substring(copy _7, const 0_i64, copy _14) -> [bb8]; } bb8: { - _19 = virtual_call iter as baml.iter.Iterable(copy _15) -> [bb9]; + _17 = copy _11; + _16 = copy _17 + const 2_i64; + _18 = call const fn baml.String.length(copy _7) -> [bb9]; } bb9: { - _20 = virtual_call next as baml.iter.Iterator(copy _19) -> [bb10]; + _15 = call const fn baml.String.substring(copy _7, copy _16, copy _18) -> [bb10]; } bb10: { - _21 = is_type(copy _20, baml.iter.Done); - branch copy _21 -> [bb15, bb11]; + _12 = testing.FilterPat { copy _13, copy _15 }; + _8 = call const fn baml.Array.push(copy _2, copy _12) -> [bb1]; } bb11: { - _22 = copy _20; - fresh_cell(_23); - _23 = copy _22; - _25 = copy _1.1; - _26 = copy _23; - _24 = copy _25[_26]; - _29 = copy _23; - _28 = copy _29 + const "/"; - _27 = call const fn baml.String.starts_with(copy _2, copy _28) -> [bb12]; + _0 = copy _2; + goto -> bb12; } bb12: { - branch copy _27 -> [bb13, bb9]; - } - - bb13: { - _0 = call const fn testing.TestRegistry.run_testset(copy _24, copy _2) -> [bb14]; - } - - bb14: { return; } - - bb15: { - _30 = const "TestSet not found: " + copy _2; - throw copy _30; - } } -fn testing.select_names(registry: testing.TestRegistry, include: string[], exclude: string[]) -> string[] { +fn testing.glob_match(subject: string, pattern: string) -> bool { // Locals: - let _0: string[] // _0 // return - let _1: testing.TestRegistry // registry // param - let _2: string[] // include // param - let _3: string[] // exclude // param - let _4: testing.FilterPat[] // inc - let _5: testing.FilterPat[] // exc - let _6: string[] // out - let _7: string[] - let _8: baml.iter.Iterator - let _9: unknown - let _10: bool - let _11: string - let _12: string // name - let _13: bool - let _14: string - let _15: testing.FilterPat[] - let _16: testing.FilterPat[] - let _17: int - let _18: string + let _0: bool // _0 // return + let _1: string // subject // param + let _2: string // pattern // param + let _3: string[] // parts + let _4: int // n + let _5: bool + let _6: int + let _7: string // first + let _8: string[] + let _9: 0 + let _10: string // last + let _11: string[] + let _12: int + let _13: int + let _14: bool + let _15: bool + let _16: string + let _17: bool + let _18: bool + let _19: string + let _20: int // start + let _21: int // end_limit + let _22: int + let _23: int + let _24: bool + let _25: int + let _26: int + let _27: int // pos + let _28: int // i + let _29: bool + let _30: int + let _31: int + let _32: int + let _33: string // part + let _34: string[] + let _35: int + let _36: bool + let _37: string + let _38: int | null + let _39: string + let _40: int + let _41: int + let _42: string + let _43: bool + let _44: int // idx + let _45: int + let _46: int + let _47: int + let _48: int bb0: { - _4 = call const fn testing.parse_filter_patterns(copy _2) -> [bb1]; + _3 = call const fn baml.String.split(copy _2, const "*") -> [bb1]; } bb1: { - _5 = call const fn testing.parse_filter_patterns(copy _3) -> [bb2]; + _4 = len(_3); + goto -> bb2; } bb2: { - _6 = []: string[]; - _7 = call const fn testing.collect_leaf_names(copy _1) -> [bb3]; + _6 = copy _4; + _5 = copy _6 == const 1_i64; + branch copy _5 -> [bb25, bb3]; } bb3: { - _8 = virtual_call iter as baml.iter.Iterable(copy _7) -> [bb4]; + _8 = copy _3; + _9 = const 0_i64; + _7 = copy _8[_9]; + _11 = copy _3; + _13 = copy _4; + _12 = copy _13 - const 1_i64; + _10 = copy _11[_12]; + _16 = copy _7; + _15 = call const fn baml.String.starts_with(copy _1, copy _16) -> [bb4]; } bb4: { - _9 = virtual_call next as baml.iter.Iterator(copy _8) -> [bb5]; + _14 = !copy _15; + branch copy _14 -> [bb24, bb5]; } bb5: { - _10 = is_type(copy _9, baml.iter.Done); - branch copy _10 -> [bb9, bb6]; + _19 = copy _10; + _18 = call const fn baml.String.ends_with(copy _1, copy _19) -> [bb6]; } bb6: { - _11 = copy _9; - fresh_cell(_12); - _12 = copy _11; - _14 = copy _12; - _15 = copy _4; - _16 = copy _5; - _13 = call const fn testing.leaf_selected(copy _14, copy _15, copy _16) -> [bb7]; + _17 = !copy _18; + branch copy _17 -> [bb23, bb7]; } bb7: { - branch copy _13 -> [bb8, bb4]; + _20 = call const fn baml.String.length(copy _7) -> [bb8]; } bb8: { - _18 = copy _12; - _17 = call const fn baml.Array.push(copy _6, copy _18) -> [bb4]; + _22 = call const fn baml.String.length(copy _1) -> [bb9]; } bb9: { - _0 = copy _6; - goto -> bb10; + _23 = call const fn baml.String.length(copy _10) -> [bb10]; } bb10: { - return; + _21 = copy _22 - copy _23; + _25 = copy _20; + _26 = copy _21; + _24 = copy _25 > copy _26; + branch copy _24 -> [bb22, bb11]; } -} -fn testing.TestRegistry.serialize(self: testing.TestRegistry) -> (testing.SerializedTest | testing.SerializedTestSet)[] { - // Locals: - let _0: (testing.SerializedTest | testing.SerializedTestSet)[] // _0 // return - let _1: testing.TestRegistry // self // param - let _2: (testing.SerializedTest | testing.SerializedTestSet)[] // items - let _3: testing.TestRegistration[] - let _4: baml.iter.Iterator - let _5: unknown - let _6: bool - let _7: testing.TestRegistration - let _8: testing.TestRegistration // t - let _9: void - let _10: testing.SerializedTest - let _11: string - let _12: testing.TestSetRegistration[] - let _13: baml.iter.Iterator - let _14: unknown - let _15: bool - let _16: testing.TestSetRegistration - let _17: testing.TestSetRegistration // ts - let _18: void - let _19: null | testing.TestRegistry // expanded - let _20: (map, string) -> null | testing.TestRegistry throws never - let _21: string - let _22: type - let _23: type - let _24: bool - let _25: testing.TestRegistry // sub - let _26: testing.SerializedTestSet - let _27: string - let _28: (testing.SerializedTest | testing.SerializedTestSet)[] - let _29: int - let _30: testing.SerializedTest - let _31: string + bb11: { + _27 = copy _20; + _28 = const 1_i64; + goto -> bb12; + } - bb0: { - _2 = []: testing.SerializedTest | testing.SerializedTestSet[]; - _3 = copy _1.0.1; - _4 = virtual_call iter as baml.iter.Iterable(copy _3) -> [bb1]; + bb12: { + _30 = copy _28; + _32 = copy _4; + _31 = copy _32 - const 1_i64; + _29 = copy _30 < copy _31; + branch copy _29 -> [bb14, bb13]; } - bb1: { - _5 = virtual_call next as baml.iter.Iterator(copy _4) -> [bb2]; + bb13: { + _0 = const true; + goto -> bb26; } - bb2: { - _6 = is_type(copy _5, baml.iter.Done); - branch copy _6 -> [bb4, bb3]; + bb14: { + _34 = copy _3; + _35 = copy _28; + _33 = copy _34[_35]; + _37 = copy _33; + _36 = copy _37 != const ""; + branch copy _36 -> [bb15, bb21]; } - bb3: { - _7 = copy _5; - fresh_cell(_8); - _8 = copy _7; - _11 = copy _8.0; - _10 = testing.SerializedTest { const "test", copy _11 }; - _9 = call const fn baml.Array.push(copy _2, copy _10) -> [bb1]; + bb15: { + _40 = copy _27; + _41 = copy _21; + _39 = call const fn baml.String.substring(copy _1, copy _40, copy _41) -> [bb16]; } - bb4: { - _12 = copy _1.0.2; - _13 = virtual_call iter as baml.iter.Iterable(copy _12) -> [bb5]; + bb16: { + _42 = copy _33; + _38 = call const fn baml.String.index_of(copy _39, copy _42) -> [bb17]; } - bb5: { - _14 = virtual_call next as baml.iter.Iterator(copy _13) -> [bb6]; + bb17: { + _43 = is_type(copy _38, int); + branch copy _43 -> [bb19, bb18]; } - bb6: { - _15 = is_type(copy _14, baml.iter.Done); - branch copy _15 -> [bb12, bb7]; + bb18: { + _0 = const false; + goto -> bb26; } - bb7: { - _16 = copy _14; - fresh_cell(_17); - _17 = copy _16; - _20 = copy _1.1; - _21 = copy _17.0; - _22 = load_type(string); - _23 = load_type(testing.TestRegistry); - _19 = call const fn baml.Map.get(copy _20, copy _21) -> [bb8]; + bb19: { + _44 = copy _38; + _46 = copy _27; + _47 = copy _44; + _45 = copy _46 + copy _47; + _48 = call const fn baml.String.length(copy _33) -> [bb20]; } - bb8: { - _24 = is_type(copy _19, testing.TestRegistry); - branch copy _24 -> [bb10, bb9]; + bb20: { + _27 = copy _45 + copy _48; + goto -> bb21; } - bb9: { - _31 = copy _17.0; - _30 = testing.SerializedTest { const "lazyTestSet", copy _31 }; - _18 = call const fn baml.Array.push(copy _2, copy _30) -> [bb5]; + bb21: { + _28 = copy _28 + const 1_i64; + goto -> bb12; } - bb10: { - _25 = copy _19; - _27 = copy _17.0; - _28 = call const fn testing.TestRegistry.serialize(copy _25) -> [bb11]; + bb22: { + _0 = const false; + goto -> bb26; } - bb11: { - _29 = copy _25.2; - _26 = testing.SerializedTestSet { copy _27, copy _28, copy _29 }; - _18 = call const fn baml.Array.push(copy _2, copy _26) -> [bb5]; + bb23: { + _0 = const false; + goto -> bb26; } - bb12: { - _0 = copy _2; - goto -> bb13; + bb24: { + _0 = const false; + goto -> bb26; } - bb13: { + bb25: { + _0 = copy _1 == copy _2; + goto -> bb26; + } + + bb26: { return; } } -fn testing.split_top(path: string) -> testing.NameSplit { +fn testing.filter_match(expr: string, subject: string) -> bool { // Locals: - let _0: testing.NameSplit // _0 // return - let _1: string // path // param - let _2: int | null + let _0: bool // _0 // return + let _1: string // expr // param + let _2: string // subject // param let _3: bool - let _4: int // idx - let _5: string - let _6: int - let _7: string - let _8: int - let _9: int - let _10: int bb0: { - _2 = call const fn baml.String.index_of(copy _1, const "/") -> [bb1]; + _3 = copy _1 == const ""; + branch copy _3 -> [bb2, bb1]; } bb1: { - _3 = is_type(copy _2, int); - branch copy _3 -> [bb3, bb2]; + _0 = call const fn testing.glob_match(copy _2, copy _1) -> [bb3]; } bb2: { - _0 = testing.NameSplit { const "", copy _1 }; - goto -> bb7; + _0 = const true; + goto -> bb3; } bb3: { - _4 = copy _2; - _6 = copy _4; - _5 = call const fn baml.String.substring(copy _1, const 0_i64, copy _6) -> [bb4]; - } - - bb4: { - _9 = copy _4; - _8 = copy _9 + const 1_i64; - _10 = call const fn baml.String.length(copy _1) -> [bb5]; - } - - bb5: { - _7 = call const fn baml.String.substring(copy _1, copy _8, copy _10) -> [bb6]; - } - - bb6: { - _0 = testing.NameSplit { copy _5, copy _7 }; - goto -> bb7; - } - - bb7: { return; } } -fn testing.test_child(name: string, body: () -> void throws unknown, runner: null | ((() -> testing.TestReport throws never) -> (() -> testing.TestReport throws never) throws never)) -> testing.TestSetChild { +fn testing.any_pattern_matches(pats: testing.FilterPat[], function_name: string, test_name: string) -> bool { // Locals: - let _0: testing.TestSetChild // _0 // return - let _1: string // name // param - let _2: () -> void throws unknown // body // param [captured] - let _3: null | ((() -> testing.TestReport throws never) -> (() -> testing.TestReport throws never) throws never) // runner // param [captured] - let _4: () -> testing.TestReport | testing.TestSetReport throws never + let _0: bool // _0 // return + let _1: testing.FilterPat[] // pats // param + let _2: string // function_name // param + let _3: string // test_name // param + let _4: baml.iter.Iterator + let _5: unknown + let _6: bool + let _7: testing.FilterPat + let _8: testing.FilterPat // p + let _9: bool + let _10: bool + let _11: string + let _12: string bb0: { - _4 = make_closure lambda[0](copy _2, copy _3); - _0 = testing.TestSetChild { copy _1, copy _4 }; - goto -> bb1; + _4 = virtual_call iter as baml.iter.Iterable(copy _1) -> [bb1]; } bb1: { - return; + _5 = virtual_call next as baml.iter.Iterator(copy _4) -> [bb2]; } -} -// lambda[0] -fn .() -> null { - // Locals: - let _0: null // _0 // return - let _1: () -> void throws unknown - let _2: null | ((() -> testing.TestReport throws never) -> (() -> testing.TestReport throws never) throws never) + bb2: { + _6 = is_type(copy _5, baml.iter.Done); + branch copy _6 -> [bb8, bb3]; + } - bb0: { - _1 = copy capture[0]; - _2 = copy capture[1]; - _0 = call const fn testing.run_test(copy _1, copy _2) -> [bb1]; + bb3: { + _7 = copy _5; + fresh_cell(_8); + _8 = copy _7; + _11 = copy _8.0; + _10 = call const fn testing.filter_match(copy _11, copy _2) -> [bb4]; } - bb1: { - return; + bb4: { + _9 = short_circuit(&&) copy _10 -> [eval: bb5, join: bb6]; } -} -fn testing.testset_child(registry: testing.TestRegistry, ts: testing.TestSetRegistration) -> testing.TestSetChild { - // Locals: - let _0: testing.TestSetChild // _0 // return - let _1: testing.TestRegistry // registry // param [captured] - let _2: testing.TestSetRegistration // ts // param [captured] - let _3: string - let _4: () -> testing.TestReport | testing.TestSetReport throws never + bb5: { + _12 = copy _8.1; + _9 = call const fn testing.filter_match(copy _12, copy _3) -> [bb6]; + } - bb0: { - _3 = copy _2.0; - _4 = make_closure lambda[0](copy _1, copy _2); - _0 = testing.TestSetChild { copy _3, copy _4 }; - goto -> bb1; + bb6: { + branch copy _9 -> [bb7, bb1]; } - bb1: { + bb7: { + _0 = const true; + goto -> bb9; + } + + bb8: { + _0 = const false; + goto -> bb9; + } + + bb9: { return; } } -// lambda[0] -fn .() -> null { +fn testing.leaf_selected(name: string, include: testing.FilterPat[], exclude: testing.FilterPat[]) -> bool { // Locals: - let _0: null // _0 // return - let _1: unknown // e - let _2: testing.TestSetChild[] - let _3: testing.TestRegistry - let _4: testing.TestSetRegistration - let _5: null | ((testing.TestSetChild[]) -> testing.TestSetReport throws never) - let _6: int + let _0: bool // _0 // return + let _1: string // name // param + let _2: testing.FilterPat[] // include // param + let _3: testing.FilterPat[] // exclude // param + let _4: testing.NameSplit // split + let _5: bool + let _6: string let _7: string - let _8: string + let _8: bool + let _9: int + let _10: string + let _11: string bb0: { - _4 = copy capture[1]; - _3 = call const fn testing.TestRegistry.expand_testset_registry(copy capture[0], copy _4) -> [bb1, unwind: bb3]; + _4 = call const fn testing.split_top(copy _1) -> [bb1]; } bb1: { - _2 = call const fn testing.testset_children(copy _3) -> [bb2, unwind: bb3]; + _6 = copy _4.0; + _7 = copy _4.1; + _5 = call const fn testing.any_pattern_matches(copy _3, copy _6, copy _7) -> [bb2]; } bb2: { - _5 = copy capture[1].2; - _0 = call const fn testing.run_testset(copy _2, copy _5) -> [bb7, unwind: bb3]; + branch copy _5 -> [bb7, bb3]; } bb3: { - _6 = type_tag(_1); - switch copy _6 [DivisionByZero: bb6, IndexOutOfBounds: bb6, InvalidFieldAccess: bb6, MapKeyNotFound: bb6, StackOverflow: bb6, AssertionFailed: bb6, Unreachable: bb6, Cancelled: bb6, UserPanic: bb6, Exit: bb6, AllocFailure: bb6, HostUnavailable: bb6, NegativeBitShift: bb6, SdkPanic: bb6, HostContractViolation: bb6, IntegerOverflow: bb6, otherwise: bb4]; + _9 = len(_2); + goto -> bb4; } bb4: { - throw_if_panic copy _1 -> bb5; + _8 = copy _9 == const 0_i64; + branch copy _8 -> [bb6, bb5]; } bb5: { - _8 = copy capture[1].0; - _0 = call const fn testing.expansion_error_report(copy _8) -> [bb7]; + _10 = copy _4.0; + _11 = copy _4.1; + _0 = call const fn testing.any_pattern_matches(copy _2, copy _10, copy _11) -> [bb8]; } bb6: { - _7 = copy capture[1].0; - _0 = call const fn testing.expansion_error_report(copy _7) -> [bb7]; + _0 = const true; + goto -> bb8; } bb7: { - return; - } -} - -fn testing.testset_child_selected(registry: testing.TestRegistry, ts: testing.TestSetRegistration, names: string[]) -> testing.TestSetChild { - // Locals: - let _0: testing.TestSetChild // _0 // return - let _1: testing.TestRegistry // registry // param [captured] - let _2: testing.TestSetRegistration // ts // param [captured] - let _3: string[] // names // param [captured] - let _4: string - let _5: () -> testing.TestReport | testing.TestSetReport throws never - - bb0: { - _4 = copy _2.0; - _5 = make_closure lambda[0](copy _1, copy _2, copy _3); - _0 = testing.TestSetChild { copy _4, copy _5 }; - goto -> bb1; + _0 = const false; + goto -> bb8; } - bb1: { + bb8: { return; } } -// lambda[0] -fn .() -> null { +fn testing.select_names(registry: testing.TestRegistry, include: string[], exclude: string[]) -> string[] { // Locals: - let _0: null // _0 // return - let _1: unknown // e - let _2: testing.TestSetChild[] - let _3: testing.TestRegistry - let _4: testing.TestSetRegistration - let _5: string[] - let _6: null | ((testing.TestSetChild[]) -> testing.TestSetReport throws never) - let _7: int - let _8: string - let _9: string + let _0: string[] // _0 // return + let _1: testing.TestRegistry // registry // param + let _2: string[] // include // param + let _3: string[] // exclude // param + let _4: testing.FilterPat[] // inc + let _5: testing.FilterPat[] // exc + let _6: string[] // out + let _7: string[] + let _8: baml.iter.Iterator + let _9: unknown + let _10: bool + let _11: string + let _12: string // name + let _13: bool + let _14: string + let _15: testing.FilterPat[] + let _16: testing.FilterPat[] + let _17: int + let _18: string bb0: { - _4 = copy capture[1]; - _3 = call const fn testing.TestRegistry.expand_testset_registry(copy capture[0], copy _4) -> [bb1, unwind: bb3]; + _4 = call const fn testing.parse_filter_patterns(copy _2) -> [bb1]; } bb1: { - _5 = copy capture[2]; - _2 = call const fn testing.testset_children_selected(copy _3, copy _5) -> [bb2, unwind: bb3]; + _5 = call const fn testing.parse_filter_patterns(copy _3) -> [bb2]; } bb2: { - _6 = copy capture[1].2; - _0 = call const fn testing.run_testset(copy _2, copy _6) -> [bb7, unwind: bb3]; + _6 = []: string[]; + _7 = call const fn testing.collect_leaf_names(copy _1) -> [bb3]; } bb3: { - _7 = type_tag(_1); - switch copy _7 [DivisionByZero: bb6, IndexOutOfBounds: bb6, InvalidFieldAccess: bb6, MapKeyNotFound: bb6, StackOverflow: bb6, AssertionFailed: bb6, Unreachable: bb6, Cancelled: bb6, UserPanic: bb6, Exit: bb6, AllocFailure: bb6, HostUnavailable: bb6, NegativeBitShift: bb6, SdkPanic: bb6, HostContractViolation: bb6, IntegerOverflow: bb6, otherwise: bb4]; + _8 = virtual_call iter as baml.iter.Iterable(copy _7) -> [bb4]; } bb4: { - throw_if_panic copy _1 -> bb5; + _9 = virtual_call next as baml.iter.Iterator(copy _8) -> [bb5]; } bb5: { - _9 = copy capture[1].0; - _0 = call const fn testing.expansion_error_report(copy _9) -> [bb7]; + _10 = is_type(copy _9, baml.iter.Done); + branch copy _10 -> [bb9, bb6]; } bb6: { - _8 = copy capture[1].0; - _0 = call const fn testing.expansion_error_report(copy _8) -> [bb7]; + _11 = copy _9; + fresh_cell(_12); + _12 = copy _11; + _14 = copy _12; + _15 = copy _4; + _16 = copy _5; + _13 = call const fn testing.leaf_selected(copy _14, copy _15, copy _16) -> [bb7]; } bb7: { + branch copy _13 -> [bb8, bb4]; + } + + bb8: { + _18 = copy _12; + _17 = call const fn baml.Array.push(copy _6, copy _18) -> [bb4]; + } + + bb9: { + _0 = copy _6; + goto -> bb10; + } + + bb10: { return; } } -fn testing.testset_children(registry: testing.TestRegistry) -> testing.TestSetChild[] { +fn testing.collect_leaf_names(registry: testing.TestRegistry) -> string[] { // Locals: - let _0: testing.TestSetChild[] // _0 // return + let _0: string[] // _0 // return let _1: testing.TestRegistry // registry // param - let _2: testing.TestSetChild[] // children + let _2: string[] // out let _3: testing.TestRegistration[] let _4: baml.iter.Iterator let _5: unknown let _6: bool let _7: testing.TestRegistration let _8: testing.TestRegistration // t - let _9: void - let _10: testing.TestSetChild - let _11: string - let _12: () -> void throws unknown - let _13: null | ((() -> testing.TestReport throws never) -> (() -> testing.TestReport throws never) throws never) - let _14: testing.TestSetRegistration[] - let _15: baml.iter.Iterator - let _16: unknown - let _17: bool + let _9: int + let _10: string + let _11: testing.TestSetRegistration[] + let _12: baml.iter.Iterator + let _13: unknown + let _14: bool + let _15: testing.TestSetRegistration + let _16: testing.TestSetRegistration // ts + let _17: string[] let _18: testing.TestSetRegistration - let _19: testing.TestSetRegistration // ts - let _20: void - let _21: testing.TestSetChild - let _22: testing.TestSetRegistration + let _19: baml.iter.Iterator + let _20: unknown + let _21: bool + let _22: string + let _23: string // name + let _24: int + let _25: string bb0: { - _2 = []: testing.TestSetChild[]; + _2 = []: string[]; _3 = copy _1.0.1; _4 = virtual_call iter as baml.iter.Iterable(copy _3) -> [bb1]; } @@ -3077,330 +2764,491 @@ fn testing.testset_children(registry: testing.TestRegistry) -> testing.TestSetCh bb2: { _6 = is_type(copy _5, baml.iter.Done); - branch copy _6 -> [bb5, bb3]; + branch copy _6 -> [bb4, bb3]; } bb3: { _7 = copy _5; fresh_cell(_8); _8 = copy _7; - _11 = copy _8.0; - _12 = copy _8.1; - _13 = copy _8.2; - _10 = call const fn testing.test_child(copy _11, copy _12, copy _13) -> [bb4]; + _10 = copy _8.0; + _9 = call const fn baml.Array.push(copy _2, copy _10) -> [bb1]; } bb4: { - _9 = call const fn baml.Array.push(copy _2, copy _10) -> [bb1]; + _11 = copy _1.0.2; + _12 = virtual_call iter as baml.iter.Iterable(copy _11) -> [bb5]; } bb5: { - _14 = copy _1.0.2; - _15 = virtual_call iter as baml.iter.Iterable(copy _14) -> [bb6]; + _13 = virtual_call next as baml.iter.Iterator(copy _12) -> [bb6]; } bb6: { - _16 = virtual_call next as baml.iter.Iterator(copy _15) -> [bb7]; + _14 = is_type(copy _13, baml.iter.Done); + branch copy _14 -> [bb12, bb7]; } bb7: { - _17 = is_type(copy _16, baml.iter.Done); - branch copy _17 -> [bb10, bb8]; + _15 = copy _13; + fresh_cell(_16); + _16 = copy _15; + _18 = copy _16; + _17 = call const fn testing.collect_subtree_names(copy _1, copy _18) -> [bb8]; } bb8: { - _18 = copy _16; - fresh_cell(_19); - _19 = copy _18; - _22 = copy _19; - _21 = call const fn testing.testset_child(copy _1, copy _22) -> [bb9]; + _19 = virtual_call iter as baml.iter.Iterable(copy _17) -> [bb9]; } bb9: { - _20 = call const fn baml.Array.push(copy _2, copy _21) -> [bb6]; + _20 = virtual_call next as baml.iter.Iterator(copy _19) -> [bb10]; } bb10: { - _0 = copy _2; - goto -> bb11; + _21 = is_type(copy _20, baml.iter.Done); + branch copy _21 -> [bb5, bb11]; } bb11: { + _22 = copy _20; + fresh_cell(_23); + _23 = copy _22; + _25 = copy _23; + _24 = call const fn baml.Array.push(copy _2, copy _25) -> [bb9]; + } + + bb12: { + _0 = copy _2; + goto -> bb13; + } + + bb13: { return; } } -fn testing.testset_children_selected(registry: testing.TestRegistry, names: string[]) -> testing.TestSetChild[] { +fn testing.collect_subtree_names(registry: testing.TestRegistry, ts: testing.TestSetRegistration) -> string[] { // Locals: - let _0: testing.TestSetChild[] // _0 // return + let _0: string[] // _0 // return let _1: testing.TestRegistry // registry // param - let _2: string[] // names // param - let _3: testing.TestSetChild[] // children - let _4: testing.TestRegistration[] - let _5: baml.iter.Iterator - let _6: unknown - let _7: bool - let _8: testing.TestRegistration - let _9: testing.TestRegistration // t - let _10: void - let _11: bool - let _12: string - let _13: testing.TestSetChild - let _14: string - let _15: () -> void throws unknown - let _16: null | ((() -> testing.TestReport throws never) -> (() -> testing.TestReport throws never) throws never) - let _17: testing.TestSetRegistration[] - let _18: baml.iter.Iterator - let _19: unknown + let _2: testing.TestSetRegistration // ts // param + let _3: unknown // e + let _4: testing.TestRegistry + let _5: int + let _6: string + let _7: string + let _8: string + let _9: string + + bb0: { + _4 = call const fn testing.TestRegistry.expand_testset_registry(copy _1, copy _2) -> [bb1, unwind: bb2]; + } + + bb1: { + _0 = call const fn testing.collect_leaf_names(copy _4) -> [bb6, unwind: bb2]; + } + + bb2: { + _5 = type_tag(_3); + switch copy _5 [DivisionByZero: bb5, IndexOutOfBounds: bb5, InvalidFieldAccess: bb5, MapKeyNotFound: bb5, StackOverflow: bb5, AssertionFailed: bb5, Unreachable: bb5, Cancelled: bb5, UserPanic: bb5, Exit: bb5, AllocFailure: bb5, HostUnavailable: bb5, NegativeBitShift: bb5, SdkPanic: bb5, HostContractViolation: bb5, IntegerOverflow: bb5, otherwise: bb3]; + } + + bb3: { + throw_if_panic copy _3 -> bb4; + } + + bb4: { + _9 = copy _2.0; + _8 = copy _9 + const "/(failed to expand)"; + _0 = [copy _8]: string[]; + goto -> bb6; + } + + bb5: { + _7 = copy _2.0; + _6 = copy _7 + const "/(failed to expand)"; + _0 = [copy _6]: string[]; + goto -> bb6; + } + + bb6: { + return; + } +} + +fn testing.count_leaves(results: (testing.TestReport | testing.TestSetReport)[], tolerated_by_parent: bool) -> testing.LeafCounts { + // Locals: + let _0: testing.LeafCounts // _0 // return + let _1: (testing.TestReport | testing.TestSetReport)[] // results // param + let _2: bool // tolerated_by_parent // param + let _3: int // passed + let _4: int // failed + let _5: int // tolerated + let _6: int // total + let _7: baml.iter.Iterator + let _8: unknown + let _9: bool + let _10: testing.TestReport | testing.TestSetReport + let _11: testing.TestReport | testing.TestSetReport // r + let _12: testing.LeafCounts // delta + let _13: bool + let _14: testing.TestReport // tr + let _15: bool + let _16: "error" | "fail" | "pass" + let _17: testing.TestSetReport // tsr + let _18: bool // ft + let _19: "error" | "fail" | "pass" let _20: bool - let _21: testing.TestSetRegistration - let _22: testing.TestSetRegistration // ts - let _23: void + let _21: int + let _22: ((testing.TestReport | testing.TestSetReport)[]) -> int throws never + let _23: (testing.TestReport | testing.TestSetReport)[] let _24: bool - let _25: string - let _26: testing.TestSetChild - let _27: testing.TestSetRegistration + let _25: bool + let _26: int + let _27: int + let _28: int + let _29: int + let _30: int + let _31: int + let _32: int + let _33: int + let _34: int + let _35: int + let _36: int + let _37: int + let _38: int + let _39: int bb0: { - _3 = []: testing.TestSetChild[]; - _4 = copy _1.0.1; - _5 = virtual_call iter as baml.iter.Iterable(copy _4) -> [bb1]; + _3 = const 0_i64; + _4 = const 0_i64; + _5 = const 0_i64; + _6 = const 0_i64; + _7 = virtual_call iter as baml.iter.Iterable(copy _1) -> [bb1]; } bb1: { - _6 = virtual_call next as baml.iter.Iterator(copy _5) -> [bb2]; + _8 = virtual_call next as baml.iter.Iterator(copy _7) -> [bb2]; } bb2: { - _7 = is_type(copy _6, baml.iter.Done); - branch copy _7 -> [bb8, bb3]; + _9 = is_type(copy _8, baml.iter.Done); + branch copy _9 -> [bb19, bb3]; } bb3: { - _8 = copy _6; - fresh_cell(_9); - _9 = copy _8; - _12 = copy _9.0; - _11 = call const fn testing._name_selected(copy _12, copy _2) -> [bb4]; + _10 = copy _8; + fresh_cell(_11); + _11 = copy _10; + _13 = is_type(copy _11, testing.TestReport); + branch copy _13 -> [bb12, bb4]; } bb4: { - branch copy _11 -> [bb6, bb5]; + _17 = copy _11; + _18 = short_circuit(||) copy _2 -> [eval: bb5, join: bb6]; } bb5: { - _10 = const null; - goto -> bb1; + _19 = copy _17.0; + _18 = call const fn baml.ops.equals_equals(copy _19, const "pass") -> [bb6]; } bb6: { - _14 = copy _9.0; - _15 = copy _9.1; - _16 = copy _9.2; - _13 = call const fn testing.test_child(copy _14, copy _15, copy _16) -> [bb7]; + _22 = copy _17.5; + _21 = len(_22); + goto -> bb7; } bb7: { - _10 = call const fn baml.Array.push(copy _3, copy _13) -> [bb1]; + _20 = copy _21 > const 0_i64; + branch copy _20 -> [bb11, bb8]; } bb8: { - _17 = copy _1.0.2; - _18 = virtual_call iter as baml.iter.Iterable(copy _17) -> [bb9]; + _25 = copy _18; + branch copy _25 -> [bb10, bb9]; } bb9: { - _19 = virtual_call next as baml.iter.Iterator(copy _18) -> [bb10]; + _29 = copy _17.1; + _30 = copy _17.2; + _31 = copy _17.3; + _12 = testing.LeafCounts { copy _29, copy _30, const 0_i64, copy _31 }; + goto -> bb18; } bb10: { - _20 = is_type(copy _19, baml.iter.Done); - branch copy _20 -> [bb16, bb11]; + _26 = copy _17.1; + _27 = copy _17.2; + _28 = copy _17.3; + _12 = testing.LeafCounts { copy _26, const 0_i64, copy _27, copy _28 }; + goto -> bb18; } bb11: { - _21 = copy _19; - fresh_cell(_22); - _22 = copy _21; - _25 = copy _22.0; - _24 = call const fn testing._has_selected_descendant(copy _25, copy _2) -> [bb12]; + _23 = copy _17.5; + _24 = copy _18; + _12 = call const fn testing.count_leaves(copy _23, copy _24) -> [bb18]; } bb12: { - branch copy _24 -> [bb14, bb13]; + _14 = copy _11; + _16 = copy _14.0; + _15 = call const fn baml.ops.equals_equals(copy _16, const "pass") -> [bb13]; } bb13: { - _23 = const null; - goto -> bb9; + branch copy _15 -> [bb17, bb14]; } bb14: { - _27 = copy _22; - _26 = call const fn testing.testset_child_selected(copy _1, copy _27, copy _2) -> [bb15]; + branch copy _2 -> [bb16, bb15]; } bb15: { - _23 = call const fn baml.Array.push(copy _3, copy _26) -> [bb9]; + _12 = testing.LeafCounts { const 0_i64, const 1_i64, const 0_i64, const 1_i64 }; + goto -> bb18; } bb16: { - _0 = copy _3; - goto -> bb17; + _12 = testing.LeafCounts { const 0_i64, const 0_i64, const 1_i64, const 1_i64 }; + goto -> bb18; } bb17: { - return; + _12 = testing.LeafCounts { const 1_i64, const 0_i64, const 0_i64, const 1_i64 }; + goto -> bb18; } -} - -fn testing.FailFast() -> (testing.TestSetChild[]) -> testing.TestSetReport throws never { - // Locals: - let _0: (testing.TestSetChild[]) -> testing.TestSetReport throws never // _0 // return - bb0: { - _0 = make_closure lambda[0](); + bb18: { + _32 = copy _12.0; + _3 = copy _3 + copy _32; + _33 = copy _12.1; + _4 = copy _4 + copy _33; + _34 = copy _12.2; + _5 = copy _5 + copy _34; + _35 = copy _12.3; + _6 = copy _6 + copy _35; goto -> bb1; } - bb1: { - return; - } -} - -// lambda[0] -fn .(children: null) -> null { - // Locals: - let _0: null // _0 // return - let _1: null // children // param - - bb0: { - _0 = call const fn testing.run_children_sequential(copy _1, const true) -> [bb1]; + bb19: { + _36 = copy _3; + _37 = copy _4; + _38 = copy _5; + _39 = copy _6; + _0 = testing.LeafCounts { copy _36, copy _37, copy _38, copy _39 }; + goto -> bb20; } - bb1: { + bb20: { return; } } -fn testing.PassRate(threshold: float) -> (testing.TestSetChild[]) -> testing.TestSetReport throws never { +fn testing.flatten_with_tolerated(report: testing.TestSetReport) -> testing.FlatTestReport { // Locals: - let _0: (testing.TestSetChild[]) -> testing.TestSetReport throws never // _0 // return - let _1: float // threshold // param [captured] - let _2: null - let _3: bool - let _4: bool + let _0: testing.FlatTestReport // _0 // return + let _1: testing.TestSetReport // report // param + let _2: bool // top_tolerated + let _3: "error" | "fail" | "pass" + let _4: testing.LeafCounts // counts + let _5: bool + let _6: int + let _7: ((testing.TestReport | testing.TestSetReport)[]) -> int throws never + let _8: (testing.TestReport | testing.TestSetReport)[] + let _9: bool + let _10: bool + let _11: int + let _12: int + let _13: int + let _14: int + let _15: int + let _16: int + let _17: string[] // messages + let _18: void + let _19: (testing.TestReport | testing.TestSetReport)[] + let _20: string[] + let _21: "error" | "fail" | "pass" + let _22: int + let _23: int + let _24: int + let _25: int + let _26: string[] + let _27: string[] bb0: { - _4 = copy _1 < const 0_f64; - _3 = short_circuit(||) copy _4 -> [eval: bb1, join: bb2]; + _3 = copy _1.0; + _2 = call const fn baml.ops.equals_equals(copy _3, const "pass") -> [bb1]; } bb1: { - _3 = copy _1 > const 1_f64; + _7 = copy _1.5; + _6 = len(_7); goto -> bb2; } bb2: { - branch copy _3 -> [bb4, bb3]; + _5 = copy _6 > const 0_i64; + branch copy _5 -> [bb6, bb3]; } bb3: { - _2 = const null; - goto -> bb5; + _10 = copy _2; + branch copy _10 -> [bb5, bb4]; } bb4: { - _2 = call const fn baml.sys.panic(const "testing.PassRate requires 0.0 <= threshold <= 1.0") -> [bb5]; + _14 = copy _1.1; + _15 = copy _1.2; + _16 = copy _1.3; + _4 = testing.LeafCounts { copy _14, copy _15, const 0_i64, copy _16 }; + goto -> bb7; } bb5: { - _0 = make_closure lambda[0](copy _1); - goto -> bb6; + _11 = copy _1.1; + _12 = copy _1.2; + _13 = copy _1.3; + _4 = testing.LeafCounts { copy _11, const 0_i64, copy _12, copy _13 }; + goto -> bb7; } bb6: { + _8 = copy _1.5; + _9 = copy _2; + _4 = call const fn testing.count_leaves(copy _8, copy _9) -> [bb7]; + } + + bb7: { + _17 = []: string[]; + _19 = copy _1.5; + _20 = copy _17; + _18 = call const fn testing.collect_leaf_messages(copy _19, copy _20) -> [bb8]; + } + + bb8: { + _21 = copy _1.0; + _22 = copy _4.0; + _23 = copy _4.1; + _24 = copy _4.2; + _25 = copy _4.3; + _26 = copy _1.4; + _27 = copy _17; + _0 = testing.FlatTestReport { copy _21, copy _22, copy _23, copy _24, copy _25, copy _26, copy _27 }; + goto -> bb9; + } + + bb9: { return; } } -// lambda[0] -fn .(children: null) -> null { +fn testing.collect_leaf_messages(results: (testing.TestReport | testing.TestSetReport)[], out: string[]) -> void { // Locals: - let _0: null // _0 // return - let _1: null // children // param - let _2: testing.TestSetReport // report - let _3: "error" | "fail" | "pass" // outcome - let _4: bool - let _5: int - let _6: bool - let _7: float - let _8: float - let _9: int - let _10: float - let _11: int - let _12: float - let _13: "error" | "fail" | "pass" - let _14: int - let _15: int - let _16: int - let _17: string[] - let _18: (testing.TestReport | testing.TestSetReport)[] + let _0: void // _0 // return + let _1: (testing.TestReport | testing.TestSetReport)[] // results // param + let _2: string[] // out // param + let _3: baml.iter.Iterator + let _4: unknown + let _5: bool + let _6: testing.TestReport | testing.TestSetReport + let _7: testing.TestReport | testing.TestSetReport // r + let _8: bool + let _9: testing.TestReport // tr + let _10: testing.RunReport[] + let _11: baml.iter.Iterator + let _12: unknown + let _13: bool + let _14: testing.RunReport + let _15: testing.RunReport // run + let _16: bool + let _17: "error" | "fail" | "pass" + let _18: bool + let _19: string | null + let _20: bool + let _21: string // m + let _22: int + let _23: string + let _24: testing.TestSetReport // tsr + let _25: void + let _26: (testing.TestReport | testing.TestSetReport)[] bb0: { - _2 = call const fn testing.run_children_parallel(copy _1) -> [bb1]; + _3 = virtual_call iter as baml.iter.Iterable(copy _1) -> [bb1]; } bb1: { - _5 = copy _2.3; - _4 = copy _5 == const 0_i64; - branch copy _4 -> [bb7, bb2]; + _4 = virtual_call next as baml.iter.Iterator(copy _3) -> [bb2]; } bb2: { - _9 = copy _2.1; - _8 = call const fn testing._int_to_float(copy _9) -> [bb3]; + _5 = is_type(copy _4, baml.iter.Done); + branch copy _5 -> [bb12, bb3]; } bb3: { - _11 = copy _2.3; - _10 = call const fn testing._int_to_float(copy _11) -> [bb4]; + _6 = copy _4; + fresh_cell(_7); + _7 = copy _6; + _8 = is_type(copy _7, testing.TestReport); + branch copy _8 -> [bb5, bb4]; } bb4: { - _7 = copy _8 / copy _10; - _12 = copy capture[0]; - _6 = copy _7 >= copy _12; - branch copy _6 -> [bb6, bb5]; + _24 = copy _7; + _26 = copy _24.5; + _25 = call const fn testing.collect_leaf_messages(copy _26, copy _2) -> [bb1]; } bb5: { - _3 = const "fail"; - goto -> bb8; + _9 = copy _7; + _10 = copy _9.1; + _11 = virtual_call iter as baml.iter.Iterable(copy _10) -> [bb6]; } bb6: { - _3 = const "pass"; - goto -> bb8; + _12 = virtual_call next as baml.iter.Iterator(copy _11) -> [bb7]; } bb7: { - _3 = const "pass"; - goto -> bb8; + _13 = is_type(copy _12, baml.iter.Done); + branch copy _13 -> [bb1, bb8]; } bb8: { - _13 = copy _3; - _14 = copy _2.1; - _15 = copy _2.2; - _16 = copy _2.3; - _17 = copy _2.4; - _18 = copy _2.5; - _0 = testing.TestSetReport { copy _13, copy _14, copy _15, copy _16, copy _17, copy _18 }; - goto -> bb9; + _14 = copy _12; + fresh_cell(_15); + _15 = copy _14; + _17 = copy _15.0; + _18 = call const fn baml.ops.equals_equals(copy _17, const "pass") -> [bb9]; } bb9: { + _16 = !copy _18; + branch copy _16 -> [bb10, bb6]; + } + + bb10: { + _19 = copy _15.2; + _20 = is_type(copy _19, string); + branch copy _20 -> [bb11, bb6]; + } + + bb11: { + _21 = copy _19; + _23 = copy _21; + _22 = call const fn baml.Array.push(copy _2, copy _23) -> [bb6]; + } + + bb12: { + _0 = const null; + goto -> bb13; + } + + bb13: { return; } } @@ -3760,6 +3608,128 @@ fn ., 1)>() -> null { } } +fn testing.PassRate(threshold: float) -> (testing.TestSetChild[]) -> testing.TestSetReport throws never { + // Locals: + let _0: (testing.TestSetChild[]) -> testing.TestSetReport throws never // _0 // return + let _1: float // threshold // param [captured] + let _2: null + let _3: bool + let _4: bool + + bb0: { + _4 = copy _1 < const 0_f64; + _3 = short_circuit(||) copy _4 -> [eval: bb1, join: bb2]; + } + + bb1: { + _3 = copy _1 > const 1_f64; + goto -> bb2; + } + + bb2: { + branch copy _3 -> [bb4, bb3]; + } + + bb3: { + _2 = const null; + goto -> bb5; + } + + bb4: { + _2 = call const fn baml.sys.panic(const "testing.PassRate requires 0.0 <= threshold <= 1.0") -> [bb5]; + } + + bb5: { + _0 = make_closure lambda[0](copy _1); + goto -> bb6; + } + + bb6: { + return; + } +} + +// lambda[0] +fn .(children: null) -> null { + // Locals: + let _0: null // _0 // return + let _1: null // children // param + let _2: testing.TestSetReport // report + let _3: "error" | "fail" | "pass" // outcome + let _4: bool + let _5: int + let _6: bool + let _7: float + let _8: float + let _9: int + let _10: float + let _11: int + let _12: float + let _13: "error" | "fail" | "pass" + let _14: int + let _15: int + let _16: int + let _17: string[] + let _18: (testing.TestReport | testing.TestSetReport)[] + + bb0: { + _2 = call const fn testing.run_children_parallel(copy _1) -> [bb1]; + } + + bb1: { + _5 = copy _2.3; + _4 = copy _5 == const 0_i64; + branch copy _4 -> [bb7, bb2]; + } + + bb2: { + _9 = copy _2.1; + _8 = call const fn testing._int_to_float(copy _9) -> [bb3]; + } + + bb3: { + _11 = copy _2.3; + _10 = call const fn testing._int_to_float(copy _11) -> [bb4]; + } + + bb4: { + _7 = copy _8 / copy _10; + _12 = copy capture[0]; + _6 = copy _7 >= copy _12; + branch copy _6 -> [bb6, bb5]; + } + + bb5: { + _3 = const "fail"; + goto -> bb8; + } + + bb6: { + _3 = const "pass"; + goto -> bb8; + } + + bb7: { + _3 = const "pass"; + goto -> bb8; + } + + bb8: { + _13 = copy _3; + _14 = copy _2.1; + _15 = copy _2.2; + _16 = copy _2.3; + _17 = copy _2.4; + _18 = copy _2.5; + _0 = testing.TestSetReport { copy _13, copy _14, copy _15, copy _16, copy _17, copy _18 }; + goto -> bb9; + } + + bb9: { + return; + } +} + fn testing.Sequential() -> (testing.TestSetChild[]) -> testing.TestSetReport throws never { // Locals: let _0: (testing.TestSetChild[]) -> testing.TestSetReport throws never // _0 // return @@ -3789,32 +3759,31 @@ fn .(children: null) -> null { } } -fn testing._int_to_float(value: int) -> float { +fn testing.FailFast() -> (testing.TestSetChild[]) -> testing.TestSetReport throws never { // Locals: - let _0: float // _0 // return - let _1: int // value // param - let _2: unknown // e - let _3: string - let _4: type + let _0: (testing.TestSetChild[]) -> testing.TestSetReport throws never // _0 // return bb0: { - _4 = load_type(int); - _3 = call const fn baml.String.from(copy _1) -> [bb1, unwind: bb2]; + _0 = make_closure lambda[0](); + goto -> bb1; } bb1: { - _0 = call const fn baml.Float.parse(copy _3) -> [bb4, unwind: bb2]; + return; } +} - bb2: { - throw_if_panic copy _2 -> bb3; - } +// lambda[0] +fn .(children: null) -> null { + // Locals: + let _0: null // _0 // return + let _1: null // children // param - bb3: { - _0 = call const fn baml.sys.panic(const "failed to convert int to float") -> [bb4]; + bb0: { + _0 = call const fn testing.run_children_sequential(copy _1, const true) -> [bb1]; } - bb4: { + bb1: { return; } } @@ -3924,3 +3893,33 @@ fn testing.run_children_sequential(children: testing.TestSetChild[], fail_fast: return; } } + +fn testing._int_to_float(value: int) -> float { + // Locals: + let _0: float // _0 // return + let _1: int // value // param + let _2: unknown // e + let _3: string + let _4: type + + bb0: { + _4 = load_type(int); + _3 = call const fn baml.String.from(copy _1) -> [bb1, unwind: bb2]; + } + + bb1: { + _0 = call const fn baml.Float.parse(copy _3) -> [bb4, unwind: bb2]; + } + + bb2: { + throw_if_panic copy _2 -> bb3; + } + + bb3: { + _0 = call const fn baml.sys.panic(const "failed to convert int to float") -> [bb4]; + } + + bb4: { + return; + } +} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/anyfunction_reflect/baml_tests__compiles__anyfunction_reflect__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/anyfunction_reflect/baml_tests__compiles__anyfunction_reflect__04_5_mir.snap index f147ab45013..316736784ce 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/anyfunction_reflect/baml_tests__compiles__anyfunction_reflect__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/anyfunction_reflect/baml_tests__compiles__anyfunction_reflect__04_5_mir.snap @@ -2,20 +2,33 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === -fn user.bare_and_pinned() -> int { +fn user.web_search(q: string) -> Doc[] { // Locals: - let _0: int // _0 // return - let _1: baml.AnyFunction // g + let _0: Doc[] // _0 // return + let _1: string // q // param + let _2: bool + let _3: ToolError + let _4: Doc bb0: { - _1 = const fn user.web_search; - _0 = const 0_i64; - goto -> bb1; + _2 = copy _1 == const "boom"; + branch copy _2 -> [bb3, bb1]; } bb1: { + _4 = user.Doc { copy _1 }; + _0 = [copy _4]: Doc[]; + goto -> bb2; + } + + bb2: { return; } + + bb3: { + _3 = user.ToolError { const "no results" }; + throw copy _3; + } } fn user.current_time() -> string { @@ -32,6 +45,22 @@ fn user.current_time() -> string { } } +fn user.bare_and_pinned() -> int { + // Locals: + let _0: int // _0 // return + let _1: baml.AnyFunction // g + + bb0: { + _1 = const fn user.web_search; + _0 = const 0_i64; + goto -> bb1; + } + + bb1: { + return; + } +} + fn user.heterogeneous_tool_map() -> map> { // Locals: let _0: map> // _0 // return @@ -305,32 +334,3 @@ fn user.typed_dispatch(name: string, args: map) -> string | Doc return; } } - -fn user.web_search(q: string) -> Doc[] { - // Locals: - let _0: Doc[] // _0 // return - let _1: string // q // param - let _2: bool - let _3: ToolError - let _4: Doc - - bb0: { - _2 = copy _1 == const "boom"; - branch copy _2 -> [bb3, bb1]; - } - - bb1: { - _4 = user.Doc { copy _1 }; - _0 = [copy _4]: Doc[]; - goto -> bb2; - } - - bb2: { - return; - } - - bb3: { - _3 = user.ToolError { const "no results" }; - throw copy _3; - } -} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/backtick_decl_slots/baml_tests__compiles__backtick_decl_slots__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/backtick_decl_slots/baml_tests__compiles__backtick_decl_slots__04_5_mir.snap index 2d657da9708..26581aeac96 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/backtick_decl_slots/baml_tests__compiles__backtick_decl_slots__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/backtick_decl_slots/baml_tests__compiles__backtick_decl_slots__04_5_mir.snap @@ -206,6 +206,66 @@ fn .(role: (string) -> baml.llm.Role thro } } +fn user.Greet$parse(json: string, client: baml.llm.Client) -> string { + // Locals: + let _0: string // _0 // return + let _1: string // json // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.Fast; + goto -> bb2; + } + + bb2: { + _4 = load_type(string | null); + _5 = load_type(string); + _0 = call const fn baml.llm.parse(copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.Greet$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client) -> baml.llm.Stream { + // Locals: + let _0: baml.llm.Stream // _0 // return + let _1: baml.http.SseStream // sse // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.Fast; + goto -> bb2; + } + + bb2: { + _4 = load_type(string | null); + _5 = load_type(string); + _0 = call const fn baml.llm.Client.__make_stream(copy _2, copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + fn user.Greet$render_prompt(name: string, client: baml.llm.Client) -> baml.llm.PromptAst { // Locals: let _0: baml.llm.PromptAst // _0 // return @@ -263,3 +323,65 @@ fn .(role: (string) -> baml.llm.Role throws neve return; } } + +fn user.Greet$stream(name: string, client: baml.llm.Client) -> baml.llm.Stream { + // Locals: + let _0: baml.llm.Stream // _0 // return + let _1: string // name // param [captured] + let _2: baml.llm.Client // client // param + let _3: bool + let _4: map + let _5: (baml.llm.Context) -> baml.llm.PromptAst throws never + let _6: ((string) -> baml.llm.Role throws never, baml.llm.Context) -> baml.TaggedString throws never + let _7: type + let _8: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.Fast; + goto -> bb2; + } + + bb2: { + _4 = { const "name": copy _1 }: map; + _6 = make_closure lambda[0](copy _1); + _5 = call const fn baml.llm.prompt(copy _6) -> [bb3]; + } + + bb3: { + _7 = load_type(string | null); + _8 = load_type(string); + _0 = call const fn baml.llm.stream_llm_function(copy _2, const "Greet", copy _4, copy _5) -> [bb4]; + } + + bb4: { + return; + } +} + +// lambda[0] +fn .(role: (string) -> baml.llm.Role throws never, ctx: baml.llm.Context) -> null { + // Locals: + let _0: null // _0 // return + let _1: (string) -> baml.llm.Role throws never // role // param + let _2: baml.llm.Context // ctx // param + let _3: string[] // __tt_parts + let _4: string + let _5: unknown[] // __tt_values + + bb0: { + _3 = [const "Say hello to ", const "."]: string[]; + _4 = copy capture[0]; + _5 = [copy _4]: unknown[]; + _0 = baml.TaggedString { copy _3, copy _5 }; + goto -> bb1; + } + + bb1: { + return; + } +} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/backtick_dedent/baml_tests__compiles__backtick_dedent__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/backtick_dedent/baml_tests__compiles__backtick_dedent__04_5_mir.snap index 9eb526854b4..3d1d5a7f70e 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/backtick_dedent/baml_tests__compiles__backtick_dedent__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/backtick_dedent/baml_tests__compiles__backtick_dedent__04_5_mir.snap @@ -1,6 +1,5 @@ --- source: crates/baml_tests/src/generated_tests.rs -assertion_line: 5660 --- === MIR2 === fn user.FarIndented() -> string { @@ -17,6 +16,68 @@ fn user.FarIndented() -> string { } } +fn user.Ragged() -> string { + // Locals: + let _0: string // _0 // return + + bb0: { + _0 = const "header\n bullet one\n bullet two\nfooter"; + goto -> bb1; + } + + bb1: { + return; + } +} + +fn user.WithBlankLines() -> string { + // Locals: + let _0: string // _0 // return + + bb0: { + _0 = const "para one\n\npara two"; + goto -> bb1; + } + + bb1: { + return; + } +} + +fn user.WithInterps(name: string, count: int) -> string { + // Locals: + let _0: string // _0 // return + let _1: string // name // param + let _2: int // count // param + let _3: string + let _4: string + let _5: string + let _6: type + let _7: string + let _8: type + + bb0: { + _6 = load_type(string); + _5 = call const fn baml.String.from(copy _1) -> [bb1]; + } + + bb1: { + _4 = const "name: " + copy _5; + _3 = copy _4 + const "\ncount: "; + _8 = load_type(int); + _7 = call const fn baml.String.from(copy _2) -> [bb2]; + } + + bb2: { + _0 = copy _3 + copy _7; + goto -> bb3; + } + + bb3: { + return; + } +} + fn user.FirstLineFlush() -> string { // Locals: let _0: string // _0 // return @@ -109,65 +170,3 @@ fn user.MultilineInterpVerbatim() -> string { return; } } - -fn user.Ragged() -> string { - // Locals: - let _0: string // _0 // return - - bb0: { - _0 = const "header\n bullet one\n bullet two\nfooter"; - goto -> bb1; - } - - bb1: { - return; - } -} - -fn user.WithBlankLines() -> string { - // Locals: - let _0: string // _0 // return - - bb0: { - _0 = const "para one\n\npara two"; - goto -> bb1; - } - - bb1: { - return; - } -} - -fn user.WithInterps(name: string, count: int) -> string { - // Locals: - let _0: string // _0 // return - let _1: string // name // param - let _2: int // count // param - let _3: string - let _4: string - let _5: string - let _6: type - let _7: string - let _8: type - - bb0: { - _6 = load_type(string); - _5 = call const fn baml.String.from(copy _1) -> [bb1]; - } - - bb1: { - _4 = const "name: " + copy _5; - _3 = copy _4 + const "\ncount: "; - _8 = load_type(int); - _7 = call const fn baml.String.from(copy _2) -> [bb2]; - } - - bb2: { - _0 = copy _3 + copy _7; - goto -> bb3; - } - - bb3: { - return; - } -} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/backtick_strings/baml_tests__compiles__backtick_strings__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/backtick_strings/baml_tests__compiles__backtick_strings__04_5_mir.snap index a9bfa2092a0..5dc6855a511 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/backtick_strings/baml_tests__compiles__backtick_strings__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/backtick_strings/baml_tests__compiles__backtick_strings__04_5_mir.snap @@ -1,14 +1,27 @@ --- source: crates/baml_tests/src/generated_tests.rs -assertion_line: 6009 --- === MIR2 === -fn user.BacktickEquality() -> bool { +fn user.BacktickOneLiner() -> string { // Locals: - let _0: bool // _0 // return + let _0: string // _0 // return bb0: { - _0 = const true; + _0 = const "hello world"; + goto -> bb1; + } + + bb1: { + return; + } +} + +fn user.BacktickStandardEscapes() -> string { + // Locals: + let _0: string // _0 // return + + bb0: { + _0 = const "line\nbreak\twith\rcr\0nul"; goto -> bb1; } @@ -45,12 +58,54 @@ fn user.BacktickEscapedDollar() -> string { } } -fn user.BacktickEscapedInterpStaysLiteral() -> string { +fn user.BacktickMultiline() -> string { // Locals: let _0: string // _0 // return bb0: { - _0 = const "literal: ${ignored}"; + _0 = const "first line\nsecond line\nthird line"; + goto -> bb1; + } + + bb1: { + return; + } +} + +fn user.BacktickMultilineWithBlankLines() -> string { + // Locals: + let _0: string // _0 // return + + bb0: { + _0 = const "para one\n\npara two"; + goto -> bb1; + } + + bb1: { + return; + } +} + +fn user.BacktickMultiTickTwo() -> string { + // Locals: + let _0: string // _0 // return + + bb0: { + _0 = const "inline `code` here"; + goto -> bb1; + } + + bb1: { + return; + } +} + +fn user.BacktickMultiTickThree() -> string { + // Locals: + let _0: string // _0 // return + + bb0: { + _0 = const "nested ``double`` ticks"; goto -> bb1; } @@ -89,28 +144,64 @@ fn user.BacktickInCondition() -> int { } } -fn user.BacktickInterpBlockBody(items: int[]) -> string { +fn user.BacktickEquality() -> bool { + // Locals: + let _0: bool // _0 // return + + bb0: { + _0 = const true; + goto -> bb1; + } + + bb1: { + return; + } +} + +fn user.BacktickPassThrough(s: string) -> string { // Locals: let _0: string // _0 // return - let _1: int[] // items // param + let _1: string // s // param + + bb0: { + _0 = copy _1; + goto -> bb1; + } + + bb1: { + return; + } +} + +fn user.BacktickLiteralAsArg() -> string { + // Locals: + let _0: string // _0 // return + + bb0: { + _0 = call const fn user.BacktickPassThrough(const "forwarded") -> [bb1]; + } + + bb1: { + return; + } +} + +fn user.BacktickInterpSimple(name: string) -> string { + // Locals: + let _0: string // _0 // return + let _1: string // name // param let _2: string - let _3: int - let _4: int // first - let _5: int[] - let _6: 0 - let _7: type + let _3: string + let _4: type bb0: { - _5 = copy _1; - _6 = const 0_i64; - _4 = copy _5[_6]; - _3 = copy _4; - _7 = load_type(int); - _2 = call const fn baml.String.from(copy _3) -> [bb1]; + _4 = load_type(string); + _3 = call const fn baml.String.from(copy _1) -> [bb1]; } bb1: { - _0 = const "head: " + copy _2; + _2 = const "Hello, " + copy _3; + _0 = copy _2 + const "!"; goto -> bb2; } @@ -119,20 +210,52 @@ fn user.BacktickInterpBlockBody(items: int[]) -> string { } } -fn user.BacktickInterpBool(b: bool) -> string { +fn user.BacktickInterpMultiple(first: string, last: string) -> string { // Locals: let _0: string // _0 // return - let _1: bool // b // param + let _1: string // first // param + let _2: string // last // param + let _3: string + let _4: string + let _5: type + let _6: string + let _7: type + + bb0: { + _5 = load_type(string); + _4 = call const fn baml.String.from(copy _1) -> [bb1]; + } + + bb1: { + _3 = copy _4 + const " "; + _7 = load_type(string); + _6 = call const fn baml.String.from(copy _2) -> [bb2]; + } + + bb2: { + _0 = copy _3 + copy _6; + goto -> bb3; + } + + bb3: { + return; + } +} + +fn user.BacktickInterpInt(n: int) -> string { + // Locals: + let _0: string // _0 // return + let _1: int // n // param let _2: string let _3: type bb0: { - _3 = load_type(bool); + _3 = load_type(int); _2 = call const fn baml.String.from(copy _1) -> [bb1]; } bb1: { - _0 = const "flag: " + copy _2; + _0 = const "count: " + copy _2; goto -> bb2; } @@ -141,28 +264,24 @@ fn user.BacktickInterpBool(b: bool) -> string { } } -fn user.BacktickInterpCallsFn() -> string { +fn user.BacktickInterpBool(b: bool) -> string { // Locals: let _0: string // _0 // return - let _1: string + let _1: bool // b // param let _2: string let _3: type bb0: { - _2 = call const fn user.bangs(const 3_i64) -> [bb1]; + _3 = load_type(bool); + _2 = call const fn baml.String.from(copy _1) -> [bb1]; } bb1: { - _3 = load_type(string); - _1 = call const fn baml.String.from(copy _2) -> [bb2]; + _0 = const "flag: " + copy _2; + goto -> bb2; } bb2: { - _0 = const "done" + copy _1; - goto -> bb3; - } - - bb3: { return; } } @@ -189,20 +308,28 @@ fn user.BacktickInterpFloat(x: float) -> string { } } -fn user.BacktickInterpInt(n: int) -> string { +fn user.BacktickInterpBlockBody(items: int[]) -> string { // Locals: let _0: string // _0 // return - let _1: int // n // param + let _1: int[] // items // param let _2: string - let _3: type + let _3: int + let _4: int // first + let _5: int[] + let _6: 0 + let _7: type bb0: { - _3 = load_type(int); - _2 = call const fn baml.String.from(copy _1) -> [bb1]; + _5 = copy _1; + _6 = const 0_i64; + _4 = copy _5[_6]; + _3 = copy _4; + _7 = load_type(int); + _2 = call const fn baml.String.from(copy _3) -> [bb1]; } bb1: { - _0 = const "count: " + copy _2; + _0 = const "head: " + copy _2; goto -> bb2; } @@ -211,64 +338,57 @@ fn user.BacktickInterpInt(n: int) -> string { } } -fn user.BacktickInterpMultiline(name: string, count: int) -> string { +fn user.bangs(n: int) -> string { // Locals: let _0: string // _0 // return - let _1: string // name // param - let _2: int // count // param + let _1: int // n // param + let _2: bool let _3: string - let _4: string - let _5: string - let _6: type - let _7: string - let _8: type + let _4: int bb0: { - _6 = load_type(string); - _5 = call const fn baml.String.from(copy _1) -> [bb1]; + _2 = copy _1 <= const 0_i64; + branch copy _2 -> [bb3, bb1]; } bb1: { - _4 = const "name: " + copy _5; - _3 = copy _4 + const "\ncount: "; - _8 = load_type(int); - _7 = call const fn baml.String.from(copy _2) -> [bb2]; + _4 = copy _1 - const 1_i64; + _3 = call const fn user.bangs(copy _4) -> [bb2]; } bb2: { - _0 = copy _3 + copy _7; - goto -> bb3; + _0 = const "!" + copy _3; + goto -> bb4; } bb3: { + _0 = const ""; + goto -> bb4; + } + + bb4: { return; } } -fn user.BacktickInterpMultiple(first: string, last: string) -> string { +fn user.BacktickInterpCallsFn() -> string { // Locals: let _0: string // _0 // return - let _1: string // first // param - let _2: string // last // param - let _3: string - let _4: string - let _5: type - let _6: string - let _7: type + let _1: string + let _2: string + let _3: type bb0: { - _5 = load_type(string); - _4 = call const fn baml.String.from(copy _1) -> [bb1]; + _2 = call const fn user.bangs(const 3_i64) -> [bb1]; } bb1: { - _3 = copy _4 + const " "; - _7 = load_type(string); - _6 = call const fn baml.String.from(copy _2) -> [bb2]; + _3 = load_type(string); + _1 = call const fn baml.String.from(copy _2) -> [bb2]; } bb2: { - _0 = copy _3 + copy _6; + _0 = const "done" + copy _1; goto -> bb3; } @@ -277,36 +397,47 @@ fn user.BacktickInterpMultiple(first: string, last: string) -> string { } } -fn user.BacktickInterpSimple(name: string) -> string { +fn user.BacktickInterpMultiline(name: string, count: int) -> string { // Locals: let _0: string // _0 // return let _1: string // name // param - let _2: string + let _2: int // count // param let _3: string - let _4: type + let _4: string + let _5: string + let _6: type + let _7: string + let _8: type bb0: { - _4 = load_type(string); - _3 = call const fn baml.String.from(copy _1) -> [bb1]; + _6 = load_type(string); + _5 = call const fn baml.String.from(copy _1) -> [bb1]; } bb1: { - _2 = const "Hello, " + copy _3; - _0 = copy _2 + const "!"; - goto -> bb2; + _4 = const "name: " + copy _5; + _3 = copy _4 + const "\ncount: "; + _8 = load_type(int); + _7 = call const fn baml.String.from(copy _2) -> [bb2]; } bb2: { + _0 = copy _3 + copy _7; + goto -> bb3; + } + + bb3: { return; } } -fn user.BacktickLiteralAsArg() -> string { +fn user.BacktickEscapedInterpStaysLiteral() -> string { // Locals: let _0: string // _0 // return bb0: { - _0 = call const fn user.BacktickPassThrough(const "forwarded") -> [bb1]; + _0 = const "literal: ${ignored}"; + goto -> bb1; } bb1: { @@ -432,135 +563,3 @@ fn user.BacktickM3IfElseChain(n: int) -> string { return; } } - -fn user.BacktickMultiTickThree() -> string { - // Locals: - let _0: string // _0 // return - - bb0: { - _0 = const "nested ``double`` ticks"; - goto -> bb1; - } - - bb1: { - return; - } -} - -fn user.BacktickMultiTickTwo() -> string { - // Locals: - let _0: string // _0 // return - - bb0: { - _0 = const "inline `code` here"; - goto -> bb1; - } - - bb1: { - return; - } -} - -fn user.BacktickMultiline() -> string { - // Locals: - let _0: string // _0 // return - - bb0: { - _0 = const "first line\nsecond line\nthird line"; - goto -> bb1; - } - - bb1: { - return; - } -} - -fn user.BacktickMultilineWithBlankLines() -> string { - // Locals: - let _0: string // _0 // return - - bb0: { - _0 = const "para one\n\npara two"; - goto -> bb1; - } - - bb1: { - return; - } -} - -fn user.BacktickOneLiner() -> string { - // Locals: - let _0: string // _0 // return - - bb0: { - _0 = const "hello world"; - goto -> bb1; - } - - bb1: { - return; - } -} - -fn user.BacktickPassThrough(s: string) -> string { - // Locals: - let _0: string // _0 // return - let _1: string // s // param - - bb0: { - _0 = copy _1; - goto -> bb1; - } - - bb1: { - return; - } -} - -fn user.BacktickStandardEscapes() -> string { - // Locals: - let _0: string // _0 // return - - bb0: { - _0 = const "line\nbreak\twith\rcr\0nul"; - goto -> bb1; - } - - bb1: { - return; - } -} - -fn user.bangs(n: int) -> string { - // Locals: - let _0: string // _0 // return - let _1: int // n // param - let _2: bool - let _3: string - let _4: int - - bb0: { - _2 = copy _1 <= const 0_i64; - branch copy _2 -> [bb3, bb1]; - } - - bb1: { - _4 = copy _1 - const 1_i64; - _3 = call const fn user.bangs(copy _4) -> [bb2]; - } - - bb2: { - _0 = const "!" + copy _3; - goto -> bb4; - } - - bb3: { - _0 = const ""; - goto -> bb4; - } - - bb4: { - return; - } -} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/bigint_arith/baml_tests__compiles__bigint_arith__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/bigint_arith/baml_tests__compiles__bigint_arith__04_5_mir.snap index 956b24f0984..424de240df7 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/bigint_arith/baml_tests__compiles__bigint_arith__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/bigint_arith/baml_tests__compiles__bigint_arith__04_5_mir.snap @@ -16,12 +16,12 @@ fn user.AddBigints() -> bigint { } } -fn user.BitAndBigints() -> bigint { +fn user.SubBigints() -> bigint { // Locals: let _0: bigint // _0 // return bb0: { - _0 = const 0n; + _0 = const 2n; goto -> bb1; } @@ -30,12 +30,12 @@ fn user.BitAndBigints() -> bigint { } } -fn user.BitOrBigints() -> bigint { +fn user.MulBigints() -> bigint { // Locals: let _0: bigint // _0 // return bb0: { - _0 = const 255n; + _0 = const 6n; goto -> bb1; } @@ -44,12 +44,12 @@ fn user.BitOrBigints() -> bigint { } } -fn user.BitXorBigints() -> bigint { +fn user.DivBigints() -> bigint { // Locals: let _0: bigint // _0 // return bb0: { - _0 = const 85n; + _0 = const 3n; goto -> bb1; } @@ -58,12 +58,12 @@ fn user.BitXorBigints() -> bigint { } } -fn user.DivBigints() -> bigint { +fn user.ModBigints() -> bigint { // Locals: let _0: bigint // _0 // return bb0: { - _0 = const 3n; + _0 = const 1n; goto -> bb1; } @@ -72,12 +72,12 @@ fn user.DivBigints() -> bigint { } } -fn user.ModBigints() -> bigint { +fn user.BitAndBigints() -> bigint { // Locals: let _0: bigint // _0 // return bb0: { - _0 = const 1n; + _0 = const 0n; goto -> bb1; } @@ -86,12 +86,12 @@ fn user.ModBigints() -> bigint { } } -fn user.MulBigints() -> bigint { +fn user.BitOrBigints() -> bigint { // Locals: let _0: bigint // _0 // return bb0: { - _0 = const 6n; + _0 = const 255n; goto -> bb1; } @@ -100,12 +100,12 @@ fn user.MulBigints() -> bigint { } } -fn user.ShlBigints() -> bigint { +fn user.BitXorBigints() -> bigint { // Locals: let _0: bigint // _0 // return bb0: { - _0 = const 16n; + _0 = const 85n; goto -> bb1; } @@ -114,7 +114,7 @@ fn user.ShlBigints() -> bigint { } } -fn user.ShrBigints() -> bigint { +fn user.ShlBigints() -> bigint { // Locals: let _0: bigint // _0 // return @@ -128,12 +128,12 @@ fn user.ShrBigints() -> bigint { } } -fn user.SubBigints() -> bigint { +fn user.ShrBigints() -> bigint { // Locals: let _0: bigint // _0 // return bb0: { - _0 = const 2n; + _0 = const 16n; goto -> bb1; } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/bigint_cmp/baml_tests__compiles__bigint_cmp__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/bigint_cmp/baml_tests__compiles__bigint_cmp__04_5_mir.snap index deb3231d57f..d4bb270ad2c 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/bigint_cmp/baml_tests__compiles__bigint_cmp__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/bigint_cmp/baml_tests__compiles__bigint_cmp__04_5_mir.snap @@ -2,6 +2,20 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === +fn user.EqSameAlloc() -> bool { + // Locals: + let _0: bool // _0 // return + + bb0: { + _0 = const true; + goto -> bb1; + } + + bb1: { + return; + } +} + fn user.EqDistinctAllocs() -> bool { // Locals: let _0: bool // _0 // return @@ -27,7 +41,7 @@ fn user.EqDistinctAllocs() -> bool { } } -fn user.EqSameAlloc() -> bool { +fn user.OrderingLt() -> bool { // Locals: let _0: bool // _0 // return @@ -54,17 +68,3 @@ fn user.OrderingGtEq() -> bool { return; } } - -fn user.OrderingLt() -> bool { - // Locals: - let _0: bool // _0 // return - - bb0: { - _0 = const true; - goto -> bb1; - } - - bb1: { - return; - } -} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/byte_string_literals/baml_tests__compiles__byte_string_literals__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/byte_string_literals/baml_tests__compiles__byte_string_literals__04_5_mir.snap index e7117190099..263e80113e0 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/byte_string_literals/baml_tests__compiles__byte_string_literals__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/byte_string_literals/baml_tests__compiles__byte_string_literals__04_5_mir.snap @@ -18,18 +18,14 @@ fn user.ByteStringBasic() -> int { } } -fn user.ByteStringDirectIndexRead() -> int { +fn user.ByteStringEmpty() -> int { // Locals: let _0: int // _0 // return let _1: uint8array // data - let _2: uint8array - let _3: 0 bb0: { - _1 = b"<3 bytes>"; - _2 = copy _1; - _3 = const 0_i64; - _0 = copy _2[_3]; + _1 = b"<0 bytes>"; + _0 = len(_1); goto -> bb1; } @@ -38,13 +34,13 @@ fn user.ByteStringDirectIndexRead() -> int { } } -fn user.ByteStringEmpty() -> int { +fn user.ByteStringHexEscapes() -> int { // Locals: let _0: int // _0 // return let _1: uint8array // data bb0: { - _1 = b"<0 bytes>"; + _1 = b"<5 bytes>"; _0 = len(_1); goto -> bb1; } @@ -54,16 +50,15 @@ fn user.ByteStringEmpty() -> int { } } -fn user.ByteStringEquality() -> bool { +fn user.ByteStringStandardEscapes() -> int { // Locals: - let _0: bool // _0 // return - let _1: uint8array - let _2: uint8array + let _0: int // _0 // return + let _1: uint8array // data bb0: { - _1 = b"<3 bytes>"; - _2 = b"<3 bytes>"; - _0 = call const fn baml.ops.equals_equals(copy _1, copy _2) -> [bb1]; + _1 = b"<6 bytes>"; + _0 = len(_1); + goto -> bb1; } bb1: { @@ -71,15 +66,14 @@ fn user.ByteStringEquality() -> bool { } } -fn user.ByteStringHexEscapes() -> int { +fn user.ByteStringIndexAccess() -> int | null { // Locals: - let _0: int // _0 // return + let _0: int | null // _0 // return let _1: uint8array // data bb0: { - _1 = b"<5 bytes>"; - _0 = len(_1); - goto -> bb1; + _1 = b"<3 bytes>"; + _0 = call const fn baml.Uint8Array.at(copy _1, const 0_i64) -> [bb1]; } bb1: { @@ -120,14 +114,16 @@ fn user.ByteStringInCondition() -> int { } } -fn user.ByteStringIndexAccess() -> int | null { +fn user.ByteStringEquality() -> bool { // Locals: - let _0: int | null // _0 // return - let _1: uint8array // data + let _0: bool // _0 // return + let _1: uint8array + let _2: uint8array bb0: { _1 = b"<3 bytes>"; - _0 = call const fn baml.Uint8Array.at(copy _1, const 0_i64) -> [bb1]; + _2 = b"<3 bytes>"; + _0 = call const fn baml.ops.equals_equals(copy _1, copy _2) -> [bb1]; } bb1: { @@ -135,14 +131,14 @@ fn user.ByteStringIndexAccess() -> int | null { } } -fn user.ByteStringLiteralAsArg() -> int { +fn user.ByteStringPassAndReturn(data: uint8array) -> int { // Locals: let _0: int // _0 // return - let _1: uint8array + let _1: uint8array // data // param bb0: { - _1 = b"<3 bytes>"; - _0 = call const fn user.ByteStringPassAndReturn(copy _1) -> [bb1]; + _0 = len(_1); + goto -> bb1; } bb1: { @@ -168,13 +164,18 @@ fn user.ByteStringMutate() -> int | null { } } -fn user.ByteStringPassAndReturn(data: uint8array) -> int { +fn user.ByteStringDirectIndexRead() -> int { // Locals: let _0: int // _0 // return - let _1: uint8array // data // param + let _1: uint8array // data + let _2: uint8array + let _3: 0 bb0: { - _0 = len(_1); + _1 = b"<3 bytes>"; + _2 = copy _1; + _3 = const 0_i64; + _0 = copy _2[_3]; goto -> bb1; } @@ -183,15 +184,14 @@ fn user.ByteStringPassAndReturn(data: uint8array) -> int { } } -fn user.ByteStringStandardEscapes() -> int { +fn user.ByteStringLiteralAsArg() -> int { // Locals: let _0: int // _0 // return - let _1: uint8array // data + let _1: uint8array bb0: { - _1 = b"<6 bytes>"; - _0 = len(_1); - goto -> bb1; + _1 = b"<3 bytes>"; + _0 = call const fn user.ByteStringPassAndReturn(copy _1) -> [bb1]; } bb1: { diff --git a/baml_language/crates/baml_tests/snapshots/compiles/catch_all_keyword/baml_tests__compiles__catch_all_keyword__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/catch_all_keyword/baml_tests__compiles__catch_all_keyword__04_5_mir.snap index 7d317c56c2c..cb46700d2c8 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/catch_all_keyword/baml_tests__compiles__catch_all_keyword__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/catch_all_keyword/baml_tests__compiles__catch_all_keyword__04_5_mir.snap @@ -2,43 +2,59 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === -fn user.CatchAllTyped(x: int) -> string { +fn user.MayFailIntOrString(x: int) -> string { // Locals: let _0: string // _0 // return let _1: int // x // param - let _2: unknown // e - let _3: bool - let _4: bool bb0: { - _0 = call const fn user.MayFailIntOrString(copy _1) -> [bb6, unwind: bb1]; + switch copy _1 [0: bb4, 1: bb3, otherwise: bb1]; } bb1: { - _3 = is_type(copy _2, string); - branch copy _3 -> [bb5, bb2]; + _0 = const "ok"; + goto -> bb2; } bb2: { - _4 = is_type(copy _2, int); - branch copy _4 -> [bb4, bb3]; + return; } bb3: { - rethrow copy _2; + throw const 42_i64; } bb4: { - _0 = const "caught int"; - goto -> bb6; + throw const "string error"; } +} - bb5: { +fn user.PartialCatch(x: int) -> string { + // Locals: + let _0: string // _0 // return + let _1: int // x // param + let _2: unknown // e + let _3: bool + + bb0: { + _0 = call const fn user.MayFailIntOrString(copy _1) -> [bb4, unwind: bb1]; + } + + bb1: { + _3 = is_type(copy _2, string); + branch copy _3 -> [bb3, bb2]; + } + + bb2: { + rethrow copy _2; + } + + bb3: { _0 = const "caught string"; - goto -> bb6; + goto -> bb4; } - bb6: { + bb4: { return; } } @@ -67,94 +83,78 @@ fn user.CatchAllWildcard(x: int) -> string { } } -fn user.CatchThenCatchAll(x: int) -> string { +fn user.CatchAllTyped(x: int) -> string { // Locals: let _0: string // _0 // return let _1: int // x // param - let _2: unknown + let _2: unknown // e let _3: bool + let _4: bool bb0: { - _0 = call const fn user.MayFailIntOrString(copy _1) -> [bb5, unwind: bb1]; + _0 = call const fn user.MayFailIntOrString(copy _1) -> [bb6, unwind: bb1]; } bb1: { _3 = is_type(copy _2, string); - branch copy _3 -> [bb4, bb2]; + branch copy _3 -> [bb5, bb2]; } bb2: { - throw_if_panic copy _2 -> bb3; + _4 = is_type(copy _2, int); + branch copy _4 -> [bb4, bb3]; } bb3: { - _0 = const "caught rest"; - goto -> bb5; + rethrow copy _2; } bb4: { - _0 = const "caught string"; - goto -> bb5; + _0 = const "caught int"; + goto -> bb6; } bb5: { - return; - } -} - -fn user.MayFailIntOrString(x: int) -> string { - // Locals: - let _0: string // _0 // return - let _1: int // x // param - - bb0: { - switch copy _1 [0: bb4, 1: bb3, otherwise: bb1]; - } - - bb1: { - _0 = const "ok"; - goto -> bb2; + _0 = const "caught string"; + goto -> bb6; } - bb2: { + bb6: { return; } - - bb3: { - throw const 42_i64; - } - - bb4: { - throw const "string error"; - } } -fn user.PartialCatch(x: int) -> string { +fn user.CatchThenCatchAll(x: int) -> string { // Locals: let _0: string // _0 // return let _1: int // x // param - let _2: unknown // e + let _2: unknown let _3: bool bb0: { - _0 = call const fn user.MayFailIntOrString(copy _1) -> [bb4, unwind: bb1]; + _0 = call const fn user.MayFailIntOrString(copy _1) -> [bb5, unwind: bb1]; } bb1: { _3 = is_type(copy _2, string); - branch copy _3 -> [bb3, bb2]; + branch copy _3 -> [bb4, bb2]; } bb2: { - rethrow copy _2; + throw_if_panic copy _2 -> bb3; } bb3: { - _0 = const "caught string"; - goto -> bb4; + _0 = const "caught rest"; + goto -> bb5; } bb4: { + _0 = const "caught string"; + goto -> bb5; + } + + bb5: { return; } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/catch_all_panics/baml_tests__compiles__catch_all_panics__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/catch_all_panics/baml_tests__compiles__catch_all_panics__04_5_mir.snap index d7c6b005305..821c762980d 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/catch_all_panics/baml_tests__compiles__catch_all_panics__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/catch_all_panics/baml_tests__compiles__catch_all_panics__04_5_mir.snap @@ -2,44 +2,30 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === -fn user.CatchAllPanicsTyped(x: int) -> string { +fn user.MayFailIntOrString(x: int) -> string { // Locals: let _0: string // _0 // return let _1: int // x // param - let _2: unknown // e - let _3: bool - let _4: bool bb0: { - _0 = call const fn user.MayFailIntOrString(copy _1) -> [bb6, unwind: bb1]; + switch copy _1 [0: bb4, 1: bb3, otherwise: bb1]; } bb1: { - _3 = is_type(copy _2, string); - branch copy _3 -> [bb5, bb2]; + _0 = const "ok"; + goto -> bb2; } bb2: { - _4 = is_type(copy _2, int); - branch copy _4 -> [bb4, bb3]; + return; } bb3: { - rethrow copy _2; + throw const 42_i64; } bb4: { - _0 = const "caught int"; - goto -> bb6; - } - - bb5: { - _0 = const "caught string"; - goto -> bb6; - } - - bb6: { - return; + throw const "string error"; } } @@ -63,60 +49,74 @@ fn user.CatchAllPanicsWildcard(x: int) -> string { } } -fn user.CatchThenCatchAllPanics(x: int) -> string { +fn user.CatchAllPanicsTyped(x: int) -> string { // Locals: let _0: string // _0 // return let _1: int // x // param - let _2: unknown + let _2: unknown // e let _3: bool + let _4: bool bb0: { - _0 = call const fn user.MayFailIntOrString(copy _1) -> [bb4, unwind: bb1]; + _0 = call const fn user.MayFailIntOrString(copy _1) -> [bb6, unwind: bb1]; } bb1: { _3 = is_type(copy _2, string); - branch copy _3 -> [bb3, bb2]; + branch copy _3 -> [bb5, bb2]; } bb2: { - _0 = const "caught rest"; - goto -> bb4; + _4 = is_type(copy _2, int); + branch copy _4 -> [bb4, bb3]; } bb3: { - _0 = const "caught string"; - goto -> bb4; + rethrow copy _2; } bb4: { + _0 = const "caught int"; + goto -> bb6; + } + + bb5: { + _0 = const "caught string"; + goto -> bb6; + } + + bb6: { return; } } -fn user.MayFailIntOrString(x: int) -> string { +fn user.CatchThenCatchAllPanics(x: int) -> string { // Locals: let _0: string // _0 // return let _1: int // x // param + let _2: unknown + let _3: bool bb0: { - switch copy _1 [0: bb4, 1: bb3, otherwise: bb1]; + _0 = call const fn user.MayFailIntOrString(copy _1) -> [bb4, unwind: bb1]; } bb1: { - _0 = const "ok"; - goto -> bb2; + _3 = is_type(copy _2, string); + branch copy _3 -> [bb3, bb2]; } bb2: { - return; + _0 = const "caught rest"; + goto -> bb4; } bb3: { - throw const 42_i64; + _0 = const "caught string"; + goto -> bb4; } bb4: { - throw const "string error"; + return; } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/catch_throw/baml_tests__compiles__catch_throw__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/catch_throw/baml_tests__compiles__catch_throw__04_5_mir.snap index 32ef5c68235..4fb602dd1ea 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/catch_throw/baml_tests__compiles__catch_throw__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/catch_throw/baml_tests__compiles__catch_throw__04_5_mir.snap @@ -2,7 +2,7 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === -fn user.AlsoMayFail(x: int) -> string { +fn user.MayFail(x: int) -> string { // Locals: let _0: string // _0 // return let _1: int // x // param @@ -12,7 +12,7 @@ fn user.AlsoMayFail(x: int) -> string { } bb1: { - _0 = const "also ok"; + _0 = const "ok"; goto -> bb2; } @@ -21,75 +21,85 @@ fn user.AlsoMayFail(x: int) -> string { } bb3: { - throw const "secondary error"; + throw const "string error"; } } -fn user.CatchAndRethrow(x: int) -> string { +fn user.MayFailIntOrString(x: int) -> string { // Locals: let _0: string // _0 // return let _1: int // x // param - let _2: unknown // e bb0: { - _0 = call const fn user.MayFail(copy _1) -> [bb1, unwind: bb2]; + switch copy _1 [0: bb4, 1: bb3, otherwise: bb1]; } bb1: { - return; + _0 = const "ok"; + goto -> bb2; } bb2: { - throw_if_panic copy _2 -> bb3; + return; } bb3: { - rethrow copy _2; + throw const 1_i64; + } + + bb4: { + throw const "string error"; } } -fn user.CatchWithFallback(x: int) -> string { +fn user.AlsoMayFail(x: int) -> string { // Locals: let _0: string // _0 // return let _1: int // x // param - let _2: unknown - let _3: bool - let _4: bool bb0: { - _0 = call const fn user.MayFailIntOrString(copy _1) -> [bb6, unwind: bb1]; + switch copy _1 [0: bb3, otherwise: bb1]; } bb1: { - _3 = is_type(copy _2, string); - branch copy _3 -> [bb5, bb2]; + _0 = const "also ok"; + goto -> bb2; } bb2: { - _4 = is_type(copy _2, int); - branch copy _4 -> [bb4, bb3]; + return; } bb3: { - rethrow copy _2; + throw const "secondary error"; } +} - bb4: { - _0 = const "caught int fallback"; - goto -> bb6; +fn user.SingleCatchWildcard(x: int) -> string { + // Locals: + let _0: string // _0 // return + let _1: int // x // param + let _2: unknown // e + + bb0: { + _0 = call const fn user.MayFail(copy _1) -> [bb3, unwind: bb1]; } - bb5: { - _0 = const "caught string"; - goto -> bb6; + bb1: { + throw_if_panic copy _2 -> bb2; } - bb6: { + bb2: { + _0 = const "caught"; + goto -> bb3; + } + + bb3: { return; } } -fn user.CatchWithTypedArm(x: int) -> string { +fn user.SingleCatchTyped(x: int) -> string { // Locals: let _0: string // _0 // return let _1: int // x // param @@ -119,7 +129,7 @@ fn user.CatchWithTypedArm(x: int) -> string { } } -fn user.ChainedCatchClauses(x: int) -> string { +fn user.CatchWithFallback(x: int) -> string { // Locals: let _0: string // _0 // return let _1: int // x // param @@ -146,12 +156,12 @@ fn user.ChainedCatchClauses(x: int) -> string { } bb4: { - _0 = const "second handler"; + _0 = const "caught int fallback"; goto -> bb6; } bb5: { - _0 = const "first handler"; + _0 = const "caught string"; goto -> bb6; } @@ -160,53 +170,33 @@ fn user.ChainedCatchClauses(x: int) -> string { } } -fn user.MayFail(x: int) -> string { - // Locals: - let _0: string // _0 // return - let _1: int // x // param - - bb0: { - switch copy _1 [0: bb3, otherwise: bb1]; - } - - bb1: { - _0 = const "ok"; - goto -> bb2; - } - - bb2: { - return; - } - - bb3: { - throw const "string error"; - } -} - -fn user.MayFailIntOrString(x: int) -> string { +fn user.CatchWithTypedArm(x: int) -> string { // Locals: let _0: string // _0 // return let _1: int // x // param + let _2: unknown // e + let _3: bool bb0: { - switch copy _1 [0: bb4, 1: bb3, otherwise: bb1]; + _0 = call const fn user.MayFail(copy _1) -> [bb4, unwind: bb1]; } bb1: { - _0 = const "ok"; - goto -> bb2; + _3 = is_type(copy _2, string); + branch copy _3 -> [bb3, bb2]; } bb2: { - return; + rethrow copy _2; } bb3: { - throw const 1_i64; + _0 = const "caught string"; + goto -> bb4; } bb4: { - throw const "string error"; + return; } } @@ -290,66 +280,76 @@ fn user.NestedCatch(x: int) -> string { } } -fn user.SingleCatchTyped(x: int) -> string { +fn user.CatchAndRethrow(x: int) -> string { // Locals: let _0: string // _0 // return let _1: int // x // param let _2: unknown // e - let _3: bool bb0: { - _0 = call const fn user.MayFail(copy _1) -> [bb4, unwind: bb1]; + _0 = call const fn user.MayFail(copy _1) -> [bb1, unwind: bb2]; } bb1: { - _3 = is_type(copy _2, string); - branch copy _3 -> [bb3, bb2]; + return; } bb2: { - rethrow copy _2; + throw_if_panic copy _2 -> bb3; } bb3: { - _0 = const "caught string"; - goto -> bb4; + rethrow copy _2; } +} - bb4: { - return; +fn user.ThrowStatement(x: int) -> string { + // Locals: + let _0: string // _0 // return + let _1: int // x // param + + bb0: { + throw const "error"; } } -fn user.SingleCatchWildcard(x: int) -> string { +fn user.ChainedCatchClauses(x: int) -> string { // Locals: let _0: string // _0 // return let _1: int // x // param - let _2: unknown // e + let _2: unknown + let _3: bool + let _4: bool bb0: { - _0 = call const fn user.MayFail(copy _1) -> [bb3, unwind: bb1]; + _0 = call const fn user.MayFailIntOrString(copy _1) -> [bb6, unwind: bb1]; } bb1: { - throw_if_panic copy _2 -> bb2; + _3 = is_type(copy _2, string); + branch copy _3 -> [bb5, bb2]; } bb2: { - _0 = const "caught"; - goto -> bb3; + _4 = is_type(copy _2, int); + branch copy _4 -> [bb4, bb3]; } bb3: { - return; + rethrow copy _2; } -} -fn user.ThrowStatement(x: int) -> string { - // Locals: - let _0: string // _0 // return - let _1: int // x // param + bb4: { + _0 = const "second handler"; + goto -> bb6; + } - bb0: { - throw const "error"; + bb5: { + _0 = const "first handler"; + goto -> bb6; + } + + bb6: { + return; } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/closures/baml_tests__compiles__closures__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/closures/baml_tests__compiles__closures__04_5_mir.snap index 415303eba09..c1ce471a308 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/closures/baml_tests__compiles__closures__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/closures/baml_tests__compiles__closures__04_5_mir.snap @@ -2,36 +2,17 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === -fn user.apply(f: (int, int) -> int throws never, a: int, b: int) -> int { - // Locals: - let _0: int // _0 // return - let _1: (int, int) -> int throws never // f // param - let _2: int // a // param - let _3: int // b // param - - bb0: { - _0 = call copy _1(copy _2, copy _3) -> [bb1]; - } - - bb1: { - return; - } -} - -fn user.apply_to_each(items: Employee[], f: (Employee) -> string throws never) -> string[] { +fn user.Formatter.format(self: Formatter, text: string) -> string { // Locals: - let _0: string[] // _0 // return - let _1: Employee[] // items // param - let _2: (Employee) -> string throws never // f // param - let _3: type - let _4: type - let _5: type + let _0: string // _0 // return + let _1: Formatter // self // param + let _2: string // text // param + let _3: string bb0: { - _3 = load_type(string); - _4 = load_type(unknown); - _5 = load_type(Employee); - _0 = call const fn baml.Array.map(copy _1, copy _2) -> [bb1]; + _3 = copy _1.0; + _0 = copy _3 + copy _2; + goto -> bb1; } bb1: { @@ -39,68 +20,40 @@ fn user.apply_to_each(items: Employee[], f: (Employee) -> string throws never) - } } -fn user.Calculator.compute(self: Calculator, a: int, b: int) -> int { +fn user.RangeCheck.is_valid(self: RangeCheck, n: int) -> bool { // Locals: - let _0: int // _0 // return - let _1: Calculator // self // param - let _2: int // a // param - let _3: int // b // param - let _4: bool - let _5: string + let _0: bool // _0 // return + let _1: RangeCheck // self // param + let _2: int // n // param + let _3: bool + let _4: int + let _5: int bb0: { - _5 = copy _1.0; - _4 = copy _5 == const "add"; - branch copy _4 -> [bb2, bb1]; + _4 = copy _1.0; + _3 = copy _2 >= copy _4; + _0 = short_circuit(&&) copy _3 -> [eval: bb1, join: bb2]; } bb1: { - _0 = copy _2 * copy _3; - goto -> bb3; + _5 = copy _1.1; + _0 = copy _2 <= copy _5; + goto -> bb2; } bb2: { - _0 = copy _2 + copy _3; - goto -> bb3; - } - - bb3: { - return; - } -} - -fn user.Encoder.encode(self: Encoder, data: string) -> string { - // Locals: - let _0: string // _0 // return - let _1: Encoder // self // param - let _2: string // data // param - let _3: string - let _4: string - let _5: string - - bb0: { - _5 = copy _1.0; - _4 = const "[" + copy _5; - _3 = copy _4 + const "]"; - _0 = copy _3 + copy _2; - goto -> bb1; - } - - bb1: { return; } } -fn user.Formatter.format(self: Formatter, text: string) -> string { +fn user.Counter.increment(self: Counter) -> int { // Locals: - let _0: string // _0 // return - let _1: Formatter // self // param - let _2: string // text // param - let _3: string + let _0: int // _0 // return + let _1: Counter // self // param bb0: { - _3 = copy _1.0; - _0 = copy _3 + copy _2; + _1.0 = copy _1.0 + const 1_i64; + _0 = copy _1.0; goto -> bb1; } @@ -150,14 +103,20 @@ fn user.Employee.greet(self: Employee, greeting: string) -> string { } } -fn user.Counter.increment(self: Counter) -> int { +fn user.Encoder.encode(self: Encoder, data: string) -> string { // Locals: - let _0: int // _0 // return - let _1: Counter // self // param + let _0: string // _0 // return + let _1: Encoder // self // param + let _2: string // data // param + let _3: string + let _4: string + let _5: string bb0: { - _1.0 = copy _1.0 + const 1_i64; - _0 = copy _1.0; + _5 = copy _1.0; + _4 = const "[" + copy _5; + _3 = copy _4 + const "]"; + _0 = copy _3 + copy _2; goto -> bb1; } @@ -166,69 +125,47 @@ fn user.Counter.increment(self: Counter) -> int { } } -fn user.RangeCheck.is_valid(self: RangeCheck, n: int) -> bool { +fn user.Box.unwrap(self: Box) -> T { // Locals: - let _0: bool // _0 // return - let _1: RangeCheck // self // param - let _2: int // n // param - let _3: bool - let _4: int - let _5: int + let _0: T // _0 // return + let _1: Box // self // param bb0: { - _4 = copy _1.0; - _3 = copy _2 >= copy _4; - _0 = short_circuit(&&) copy _3 -> [eval: bb1, join: bb2]; + _0 = copy _1.0; + goto -> bb1; } bb1: { - _5 = copy _1.1; - _0 = copy _2 <= copy _5; - goto -> bb2; - } - - bb2: { return; } } -fn user.test_bound_in_lambda() -> string { +fn user.Calculator.compute(self: Calculator, a: int, b: int) -> int { // Locals: - let _0: string // _0 // return - let _1: Employee // emp [captured] - let _2: () -> ((string) -> string throws never) throws never // make_greeter - let _3: (string) -> string throws never // greeter - let _4: () -> ((string) -> string throws never) throws never - let _5: (string) -> string throws never + let _0: int // _0 // return + let _1: Calculator // self // param + let _2: int // a // param + let _3: int // b // param + let _4: bool + let _5: string bb0: { - _1 = user.Employee { const "Alice", const "Smith" }; - _2 = make_closure lambda[0](copy _1); - _4 = copy _2; - _3 = call copy _4() -> [bb1]; + _5 = copy _1.0; + _4 = copy _5 == const "add"; + branch copy _4 -> [bb2, bb1]; } bb1: { - _5 = copy _3; - _0 = call copy _5(const "Hello") -> [bb2]; + _0 = copy _2 * copy _3; + goto -> bb3; } bb2: { - return; - } -} - -// lambda[0] -fn .() -> null { - // Locals: - let _0: null // _0 // return - - bb0: { - _0 = make_bound_method user.Employee.greet(copy capture[0]); - goto -> bb1; + _0 = copy _2 + copy _3; + goto -> bb3; } - bb1: { + bb3: { return; } } @@ -260,6 +197,31 @@ fn user.test_bound_mapper() -> string[] { } } +fn user.test_unbound_in_map() -> string[] { + // Locals: + let _0: string[] // _0 // return + let _1: Employee[] // employees + let _2: Employee + let _3: Employee + let _4: type + let _5: type + let _6: type + + bb0: { + _2 = user.Employee { const "Alice", const "Smith" }; + _3 = user.Employee { const "Bob", const "Jones" }; + _1 = [copy _2, copy _3]: Employee[]; + _4 = load_type(string); + _5 = load_type(never); + _6 = load_type(Employee); + _0 = call const fn baml.Array.map(copy _1, const fn user.Employee.full_name) -> [bb1]; + } + + bb1: { + return; + } +} + fn user.test_bound_validator() -> bool[] { // Locals: let _0: bool[] // _0 // return @@ -307,74 +269,18 @@ fn user.test_field_chain_bind(cfg: Config) -> string { } } -fn user.test_generic_bind() -> int { - // Locals: - let _0: int // _0 // return - let _1: Box // b - let _2: () -> int throws never // get - let _3: () -> int throws never - - bb0: { - _1 = user.Box { const 42_i64 }; - _2 = make_bound_method user.Box.unwrap(copy _1); - _3 = copy _2; - _0 = call copy _3() -> [bb1]; - } - - bb1: { - return; - } -} - -fn user.test_mutation_after_bind() -> int { - // Locals: - let _0: int // _0 // return - let _1: Counter // c - let _2: () -> int throws never // inc - let _3: () -> int throws never - - bb0: { - _1 = user.Counter { const 0_i64 }; - _2 = make_bound_method user.Counter.increment(copy _1); - _1.0 = const 100_i64; - _3 = copy _2; - _0 = call copy _3() -> [bb1]; - } - - bb1: { - return; - } -} - -fn user.test_repeated_bound_calls() -> int { +fn user.apply(f: (int, int) -> int throws never, a: int, b: int) -> int { // Locals: let _0: int // _0 // return - let _1: Counter // c - let _2: () -> int throws never // inc - let _3: int - let _4: () -> int throws never - let _5: int - let _6: () -> int throws never - let _7: () -> int throws never + let _1: (int, int) -> int throws never // f // param + let _2: int // a // param + let _3: int // b // param bb0: { - _1 = user.Counter { const 0_i64 }; - _2 = make_bound_method user.Counter.increment(copy _1); - _4 = copy _2; - _3 = call copy _4() -> [bb1]; + _0 = call copy _1(copy _2, copy _3) -> [bb1]; } bb1: { - _6 = copy _2; - _5 = call copy _6() -> [bb2]; - } - - bb2: { - _7 = copy _2; - _0 = call copy _7() -> [bb3]; - } - - bb3: { return; } } @@ -415,6 +321,27 @@ fn user.test_strategy() -> int[] { } } +fn user.apply_to_each(items: Employee[], f: (Employee) -> string throws never) -> string[] { + // Locals: + let _0: string[] // _0 // return + let _1: Employee[] // items // param + let _2: (Employee) -> string throws never // f // param + let _3: type + let _4: type + let _5: type + + bb0: { + _3 = load_type(string); + _4 = load_type(unknown); + _5 = load_type(Employee); + _0 = call const fn baml.Array.map(copy _1, copy _2) -> [bb1]; + } + + bb1: { + return; + } +} + fn user.test_unbound_higher_order() -> string[] { // Locals: let _0: string[] // _0 // return @@ -434,24 +361,19 @@ fn user.test_unbound_higher_order() -> string[] { } } -fn user.test_unbound_in_map() -> string[] { +fn user.test_mutation_after_bind() -> int { // Locals: - let _0: string[] // _0 // return - let _1: Employee[] // employees - let _2: Employee - let _3: Employee - let _4: type - let _5: type - let _6: type + let _0: int // _0 // return + let _1: Counter // c + let _2: () -> int throws never // inc + let _3: () -> int throws never bb0: { - _2 = user.Employee { const "Alice", const "Smith" }; - _3 = user.Employee { const "Bob", const "Jones" }; - _1 = [copy _2, copy _3]: Employee[]; - _4 = load_type(string); - _5 = load_type(never); - _6 = load_type(Employee); - _0 = call const fn baml.Array.map(copy _1, const fn user.Employee.full_name) -> [bb1]; + _1 = user.Counter { const 0_i64 }; + _2 = make_bound_method user.Counter.increment(copy _1); + _1.0 = const 100_i64; + _3 = copy _2; + _0 = call copy _3() -> [bb1]; } bb1: { @@ -459,13 +381,58 @@ fn user.test_unbound_in_map() -> string[] { } } -fn user.Box.unwrap(self: Box) -> T { +fn user.test_generic_bind() -> int { // Locals: - let _0: T // _0 // return - let _1: Box // self // param + let _0: int // _0 // return + let _1: Box // b + let _2: () -> int throws never // get + let _3: () -> int throws never bb0: { - _0 = copy _1.0; + _1 = user.Box { const 42_i64 }; + _2 = make_bound_method user.Box.unwrap(copy _1); + _3 = copy _2; + _0 = call copy _3() -> [bb1]; + } + + bb1: { + return; + } +} + +fn user.test_bound_in_lambda() -> string { + // Locals: + let _0: string // _0 // return + let _1: Employee // emp [captured] + let _2: () -> ((string) -> string throws never) throws never // make_greeter + let _3: (string) -> string throws never // greeter + let _4: () -> ((string) -> string throws never) throws never + let _5: (string) -> string throws never + + bb0: { + _1 = user.Employee { const "Alice", const "Smith" }; + _2 = make_closure lambda[0](copy _1); + _4 = copy _2; + _3 = call copy _4() -> [bb1]; + } + + bb1: { + _5 = copy _3; + _0 = call copy _5(const "Hello") -> [bb2]; + } + + bb2: { + return; + } +} + +// lambda[0] +fn .() -> null { + // Locals: + let _0: null // _0 // return + + bb0: { + _0 = make_bound_method user.Employee.greet(copy capture[0]); goto -> bb1; } @@ -473,3 +440,36 @@ fn user.Box.unwrap(self: Box) -> T { return; } } + +fn user.test_repeated_bound_calls() -> int { + // Locals: + let _0: int // _0 // return + let _1: Counter // c + let _2: () -> int throws never // inc + let _3: int + let _4: () -> int throws never + let _5: int + let _6: () -> int throws never + let _7: () -> int throws never + + bb0: { + _1 = user.Counter { const 0_i64 }; + _2 = make_bound_method user.Counter.increment(copy _1); + _4 = copy _2; + _3 = call copy _4() -> [bb1]; + } + + bb1: { + _6 = copy _2; + _5 = call copy _6() -> [bb2]; + } + + bb2: { + _7 = copy _2; + _0 = call copy _7() -> [bb3]; + } + + bb3: { + return; + } +} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/comment_in_type/baml_tests__compiles__comment_in_type__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/comment_in_type/baml_tests__compiles__comment_in_type__04_5_mir.snap index f51d7756e8c..29542ac94bb 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/comment_in_type/baml_tests__compiles__comment_in_type__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/comment_in_type/baml_tests__compiles__comment_in_type__04_5_mir.snap @@ -2,28 +2,53 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === -fn user.CommentAfterArrow(client: baml.llm.Client) -> string { +fn user.TestClient$new(lenient: bool) -> null { + // Locals: + let _0: null // _0 // return + let _1: bool // lenient // param + let _2: baml.llm.PrimitiveClientOptions + let _3: map + let _4: map + let _5: map + + bb0: { + _3 = { }: map; + _4 = { }: map; + _5 = { }: map; + _2 = baml.llm.PrimitiveClientOptions { const null, const null, const null, const null, const null, const null, const null, const null, const null, const null, const null, const null, copy _3, copy _4, copy _5 }; + _0 = baml.llm.PrimitiveClient { const "TestClient", const "openai", copy _2 }; + goto -> bb1; + } + + bb1: { + return; + } +} + +fn user.FunctionWithComments(a: string, b: int, client: baml.llm.Client) -> string { // Locals: let _0: string // _0 // return - let _1: baml.llm.Client // client // param - let _2: bool - let _3: map - let _4: type + let _1: string // a // param + let _2: int // b // param + let _3: baml.llm.Client // client // param + let _4: bool + let _5: map + let _6: type bb0: { - _2 = copy _1 == const ; - branch copy _2 -> [bb1, bb2]; + _4 = copy _3 == const ; + branch copy _4 -> [bb1, bb2]; } bb1: { - _1 = const item user.TestClient; + _3 = const item user.TestClient; goto -> bb2; } bb2: { - _3 = { }: map; - _4 = load_type(string); - _0 = call const fn baml.llm.call_llm_function(copy _1, const "CommentAfterArrow", copy _3, const ) -> [bb3]; + _5 = { const "a": copy _1, const "b": copy _2 }: map; + _6 = load_type(string); + _0 = call const fn baml.llm.call_llm_function(copy _3, const "FunctionWithComments", copy _5, const ) -> [bb3]; } bb3: { @@ -31,26 +56,28 @@ fn user.CommentAfterArrow(client: baml.llm.Client) -> string { } } -fn user.CommentAfterArrow$build_request(client: baml.llm.Client) -> baml.http.Request { +fn user.FunctionWithComments$build_request(a: string, b: int, client: baml.llm.Client) -> baml.http.Request { // Locals: let _0: baml.http.Request // _0 // return - let _1: baml.llm.Client // client // param - let _2: bool - let _3: map + let _1: string // a // param + let _2: int // b // param + let _3: baml.llm.Client // client // param + let _4: bool + let _5: map bb0: { - _2 = copy _1 == const ; - branch copy _2 -> [bb1, bb2]; + _4 = copy _3 == const ; + branch copy _4 -> [bb1, bb2]; } bb1: { - _1 = const item user.TestClient; + _3 = const item user.TestClient; goto -> bb2; } bb2: { - _3 = { }: map; - _0 = call const fn baml.llm.build_request(copy _1, const "CommentAfterArrow", copy _3, const ) -> [bb3]; + _5 = { const "a": copy _1, const "b": copy _2 }: map; + _0 = call const fn baml.llm.build_request(copy _3, const "FunctionWithComments", copy _5, const ) -> [bb3]; } bb3: { @@ -58,26 +85,28 @@ fn user.CommentAfterArrow$build_request(client: baml.llm.Client) -> baml.http.Re } } -fn user.CommentAfterArrow$build_request_stream(client: baml.llm.Client) -> baml.http.Request { +fn user.FunctionWithComments$build_request_stream(a: string, b: int, client: baml.llm.Client) -> baml.http.Request { // Locals: let _0: baml.http.Request // _0 // return - let _1: baml.llm.Client // client // param - let _2: bool - let _3: map + let _1: string // a // param + let _2: int // b // param + let _3: baml.llm.Client // client // param + let _4: bool + let _5: map bb0: { - _2 = copy _1 == const ; - branch copy _2 -> [bb1, bb2]; + _4 = copy _3 == const ; + branch copy _4 -> [bb1, bb2]; } bb1: { - _1 = const item user.TestClient; + _3 = const item user.TestClient; goto -> bb2; } bb2: { - _3 = { }: map; - _0 = call const fn baml.llm.build_request_stream(copy _1, const "CommentAfterArrow", copy _3, const ) -> [bb3]; + _5 = { const "a": copy _1, const "b": copy _2 }: map; + _0 = call const fn baml.llm.build_request_stream(copy _3, const "FunctionWithComments", copy _5, const ) -> [bb3]; } bb3: { @@ -85,26 +114,29 @@ fn user.CommentAfterArrow$build_request_stream(client: baml.llm.Client) -> baml. } } -fn user.CommentAfterArrow$render_prompt(client: baml.llm.Client) -> baml.llm.PromptAst { +fn user.FunctionWithComments$parse(json: string, client: baml.llm.Client) -> string { // Locals: - let _0: baml.llm.PromptAst // _0 // return - let _1: baml.llm.Client // client // param - let _2: bool - let _3: map + let _0: string // _0 // return + let _1: string // json // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type bb0: { - _2 = copy _1 == const ; - branch copy _2 -> [bb1, bb2]; + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } bb1: { - _1 = const item user.TestClient; + _2 = const item user.TestClient; goto -> bb2; } bb2: { - _3 = { }: map; - _0 = call const fn baml.llm.render_prompt(copy _1, const "CommentAfterArrow", copy _3, const ) -> [bb3]; + _4 = load_type(string | null); + _5 = load_type(string); + _0 = call const fn baml.llm.parse(copy _1) -> [bb3]; } bb3: { @@ -112,15 +144,44 @@ fn user.CommentAfterArrow$render_prompt(client: baml.llm.Client) -> baml.llm.Pro } } -fn user.FunctionWithComments(a: string, b: int, client: baml.llm.Client) -> string { +fn user.FunctionWithComments$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client) -> baml.llm.Stream { // Locals: - let _0: string // _0 // return + let _0: baml.llm.Stream // _0 // return + let _1: baml.http.SseStream // sse // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.TestClient; + goto -> bb2; + } + + bb2: { + _4 = load_type(string | null); + _5 = load_type(string); + _0 = call const fn baml.llm.Client.__make_stream(copy _2, copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.FunctionWithComments$render_prompt(a: string, b: int, client: baml.llm.Client) -> baml.llm.PromptAst { + // Locals: + let _0: baml.llm.PromptAst // _0 // return let _1: string // a // param let _2: int // b // param let _3: baml.llm.Client // client // param let _4: bool let _5: map - let _6: type bb0: { _4 = copy _3 == const ; @@ -134,8 +195,7 @@ fn user.FunctionWithComments(a: string, b: int, client: baml.llm.Client) -> stri bb2: { _5 = { const "a": copy _1, const "b": copy _2 }: map; - _6 = load_type(string); - _0 = call const fn baml.llm.call_llm_function(copy _3, const "FunctionWithComments", copy _5, const ) -> [bb3]; + _0 = call const fn baml.llm.render_prompt(copy _3, const "FunctionWithComments", copy _5, const ) -> [bb3]; } bb3: { @@ -143,14 +203,16 @@ fn user.FunctionWithComments(a: string, b: int, client: baml.llm.Client) -> stri } } -fn user.FunctionWithComments$build_request(a: string, b: int, client: baml.llm.Client) -> baml.http.Request { +fn user.FunctionWithComments$stream(a: string, b: int, client: baml.llm.Client) -> baml.llm.Stream { // Locals: - let _0: baml.http.Request // _0 // return + let _0: baml.llm.Stream // _0 // return let _1: string // a // param let _2: int // b // param let _3: baml.llm.Client // client // param let _4: bool let _5: map + let _6: type + let _7: type bb0: { _4 = copy _3 == const ; @@ -164,7 +226,9 @@ fn user.FunctionWithComments$build_request(a: string, b: int, client: baml.llm.C bb2: { _5 = { const "a": copy _1, const "b": copy _2 }: map; - _0 = call const fn baml.llm.build_request(copy _3, const "FunctionWithComments", copy _5, const ) -> [bb3]; + _6 = load_type(string | null); + _7 = load_type(string); + _0 = call const fn baml.llm.stream_llm_function(copy _3, const "FunctionWithComments", copy _5, const ) -> [bb3]; } bb3: { @@ -172,28 +236,55 @@ fn user.FunctionWithComments$build_request(a: string, b: int, client: baml.llm.C } } -fn user.FunctionWithComments$build_request_stream(a: string, b: int, client: baml.llm.Client) -> baml.http.Request { +fn user.CommentAfterArrow(client: baml.llm.Client) -> string { + // Locals: + let _0: string // _0 // return + let _1: baml.llm.Client // client // param + let _2: bool + let _3: map + let _4: type + + bb0: { + _2 = copy _1 == const ; + branch copy _2 -> [bb1, bb2]; + } + + bb1: { + _1 = const item user.TestClient; + goto -> bb2; + } + + bb2: { + _3 = { }: map; + _4 = load_type(string); + _0 = call const fn baml.llm.call_llm_function(copy _1, const "CommentAfterArrow", copy _3, const ) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.CommentAfterArrow$build_request(client: baml.llm.Client) -> baml.http.Request { // Locals: let _0: baml.http.Request // _0 // return - let _1: string // a // param - let _2: int // b // param - let _3: baml.llm.Client // client // param - let _4: bool - let _5: map + let _1: baml.llm.Client // client // param + let _2: bool + let _3: map bb0: { - _4 = copy _3 == const ; - branch copy _4 -> [bb1, bb2]; + _2 = copy _1 == const ; + branch copy _2 -> [bb1, bb2]; } bb1: { - _3 = const item user.TestClient; + _1 = const item user.TestClient; goto -> bb2; } bb2: { - _5 = { const "a": copy _1, const "b": copy _2 }: map; - _0 = call const fn baml.llm.build_request_stream(copy _3, const "FunctionWithComments", copy _5, const ) -> [bb3]; + _3 = { }: map; + _0 = call const fn baml.llm.build_request(copy _1, const "CommentAfterArrow", copy _3, const ) -> [bb3]; } bb3: { @@ -201,28 +292,113 @@ fn user.FunctionWithComments$build_request_stream(a: string, b: int, client: bam } } -fn user.FunctionWithComments$render_prompt(a: string, b: int, client: baml.llm.Client) -> baml.llm.PromptAst { +fn user.CommentAfterArrow$build_request_stream(client: baml.llm.Client) -> baml.http.Request { + // Locals: + let _0: baml.http.Request // _0 // return + let _1: baml.llm.Client // client // param + let _2: bool + let _3: map + + bb0: { + _2 = copy _1 == const ; + branch copy _2 -> [bb1, bb2]; + } + + bb1: { + _1 = const item user.TestClient; + goto -> bb2; + } + + bb2: { + _3 = { }: map; + _0 = call const fn baml.llm.build_request_stream(copy _1, const "CommentAfterArrow", copy _3, const ) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.CommentAfterArrow$parse(json: string, client: baml.llm.Client) -> string { + // Locals: + let _0: string // _0 // return + let _1: string // json // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.TestClient; + goto -> bb2; + } + + bb2: { + _4 = load_type(string | null); + _5 = load_type(string); + _0 = call const fn baml.llm.parse(copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.CommentAfterArrow$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client) -> baml.llm.Stream { + // Locals: + let _0: baml.llm.Stream // _0 // return + let _1: baml.http.SseStream // sse // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.TestClient; + goto -> bb2; + } + + bb2: { + _4 = load_type(string | null); + _5 = load_type(string); + _0 = call const fn baml.llm.Client.__make_stream(copy _2, copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.CommentAfterArrow$render_prompt(client: baml.llm.Client) -> baml.llm.PromptAst { // Locals: let _0: baml.llm.PromptAst // _0 // return - let _1: string // a // param - let _2: int // b // param - let _3: baml.llm.Client // client // param - let _4: bool - let _5: map + let _1: baml.llm.Client // client // param + let _2: bool + let _3: map bb0: { - _4 = copy _3 == const ; - branch copy _4 -> [bb1, bb2]; + _2 = copy _1 == const ; + branch copy _2 -> [bb1, bb2]; } bb1: { - _3 = const item user.TestClient; + _1 = const item user.TestClient; goto -> bb2; } bb2: { - _5 = { const "a": copy _1, const "b": copy _2 }: map; - _0 = call const fn baml.llm.render_prompt(copy _3, const "FunctionWithComments", copy _5, const ) -> [bb3]; + _3 = { }: map; + _0 = call const fn baml.llm.render_prompt(copy _1, const "CommentAfterArrow", copy _3, const ) -> [bb3]; } bb3: { @@ -230,25 +406,33 @@ fn user.FunctionWithComments$render_prompt(a: string, b: int, client: baml.llm.C } } -fn user.TestClient$new(lenient: bool) -> null { +fn user.CommentAfterArrow$stream(client: baml.llm.Client) -> baml.llm.Stream { // Locals: - let _0: null // _0 // return - let _1: bool // lenient // param - let _2: baml.llm.PrimitiveClientOptions - let _3: map - let _4: map - let _5: map + let _0: baml.llm.Stream // _0 // return + let _1: baml.llm.Client // client // param + let _2: bool + let _3: map + let _4: type + let _5: type bb0: { - _3 = { }: map; - _4 = { }: map; - _5 = { }: map; - _2 = baml.llm.PrimitiveClientOptions { const null, const null, const null, const null, const null, const null, const null, const null, const null, const null, const null, const null, copy _3, copy _4, copy _5 }; - _0 = baml.llm.PrimitiveClient { const "TestClient", const "openai", copy _2 }; - goto -> bb1; + _2 = copy _1 == const ; + branch copy _2 -> [bb1, bb2]; } bb1: { + _1 = const item user.TestClient; + goto -> bb2; + } + + bb2: { + _3 = { }: map; + _4 = load_type(string | null); + _5 = load_type(string); + _0 = call const fn baml.llm.stream_llm_function(copy _1, const "CommentAfterArrow", copy _3, const ) -> [bb3]; + } + + bb3: { return; } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/deep_method_call/baml_tests__compiles__deep_method_call__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/deep_method_call/baml_tests__compiles__deep_method_call__04_5_mir.snap index f0f2aa8cd8f..48ed7d9013f 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/deep_method_call/baml_tests__compiles__deep_method_call__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/deep_method_call/baml_tests__compiles__deep_method_call__04_5_mir.snap @@ -17,14 +17,15 @@ fn user.B.greet(self: B) -> string { } } -fn user.test_deep_field(a: A) -> string { +fn user.test_deep_method(a: A) -> string { // Locals: let _0: string // _0 // return let _1: A // a // param + let _2: () -> string throws never bb0: { - _0 = copy _1.0.0; - goto -> bb1; + _2 = copy _1.0; + _0 = call const fn user.B.greet(copy _2) -> [bb1]; } bb1: { @@ -32,15 +33,14 @@ fn user.test_deep_field(a: A) -> string { } } -fn user.test_deep_method(a: A) -> string { +fn user.test_deep_field(a: A) -> string { // Locals: let _0: string // _0 // return let _1: A // a // param - let _2: () -> string throws never bb0: { - _2 = copy _1.0; - _0 = call const fn user.B.greet(copy _2) -> [bb1]; + _0 = copy _1.0.0; + goto -> bb1; } bb1: { diff --git a/baml_language/crates/baml_tests/snapshots/compiles/generic_field_chain/baml_tests__compiles__generic_field_chain__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/generic_field_chain/baml_tests__compiles__generic_field_chain__04_5_mir.snap index 111e9b4bee0..83a7d445851 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/generic_field_chain/baml_tests__compiles__generic_field_chain__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/generic_field_chain/baml_tests__compiles__generic_field_chain__04_5_mir.snap @@ -2,17 +2,14 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === -fn user.test_generic_capture(box: Box) -> string { +fn user.test_generic_chain(box: Box) -> string { // Locals: let _0: string // _0 // return - let _1: Box // box // param [captured] - let _2: () -> string throws never // get_name - let _3: () -> string throws never + let _1: Box // box // param bb0: { - _2 = make_closure lambda[0](copy _1); - _3 = copy _2; - _0 = call copy _3() -> [bb1]; + _0 = copy _1.0.0; + goto -> bb1; } bb1: { @@ -20,13 +17,13 @@ fn user.test_generic_capture(box: Box) -> string { } } -// lambda[0] -fn .() -> null { +fn user.test_nested_generic_chain(box: Box>) -> string { // Locals: - let _0: null // _0 // return + let _0: string // _0 // return + let _1: Box> // box // param bb0: { - _0 = copy capture[0].0.0; + _0 = copy _1.0.0.0; goto -> bb1; } @@ -35,14 +32,17 @@ fn .() -> null { } } -fn user.test_generic_chain(box: Box) -> string { +fn user.test_generic_capture(box: Box) -> string { // Locals: let _0: string // _0 // return - let _1: Box // box // param + let _1: Box // box // param [captured] + let _2: () -> string throws never // get_name + let _3: () -> string throws never bb0: { - _0 = copy _1.0.0; - goto -> bb1; + _2 = make_closure lambda[0](copy _1); + _3 = copy _2; + _0 = call copy _3() -> [bb1]; } bb1: { @@ -50,13 +50,13 @@ fn user.test_generic_chain(box: Box) -> string { } } -fn user.test_nested_generic_chain(box: Box>) -> string { +// lambda[0] +fn .() -> null { // Locals: - let _0: string // _0 // return - let _1: Box> // box // param + let _0: null // _0 // return bb0: { - _0 = copy _1.0.0.0; + _0 = copy capture[0].0.0; goto -> bb1; } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/is_operator/baml_tests__compiles__is_operator__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/is_operator/baml_tests__compiles__is_operator__04_5_mir.snap index d443c5b5833..0c99d70eaec 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/is_operator/baml_tests__compiles__is_operator__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/is_operator/baml_tests__compiles__is_operator__04_5_mir.snap @@ -2,63 +2,41 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === -fn user.both_ints(a: int | string, b: int | string) -> bool { +fn user.is_int(v: int | string) -> bool { // Locals: let _0: bool // _0 // return - let _1: int | string // a // param - let _2: int | string // b // param - let _3: bool - let _4: bool - let _5: bool + let _1: int | string // v // param + let _2: bool bb0: { - _4 = is_type(copy _1, int); - branch copy _4 -> [bb2, bb1]; + _2 = is_type(copy _1, int); + branch copy _2 -> [bb2, bb1]; } bb1: { - _3 = const false; + _0 = const false; goto -> bb3; } bb2: { - _3 = const true; + _0 = const true; goto -> bb3; } bb3: { - _0 = short_circuit(&&) copy _3 -> [eval: bb4, join: bb7]; - } - - bb4: { - _5 = is_type(copy _2, int); - branch copy _5 -> [bb6, bb5]; - } - - bb5: { - _0 = const false; - goto -> bb7; - } - - bb6: { - _0 = const true; - goto -> bb7; - } - - bb7: { return; } } -fn user.classify(v: int | string) -> string { +fn user.is_not_string(v: int | string) -> bool { // Locals: - let _0: string // _0 // return + let _0: bool // _0 // return let _1: int | string // v // param let _2: bool let _3: bool bb0: { - _3 = is_type(copy _1, int); + _3 = is_type(copy _1, string); branch copy _3 -> [bb2, bb1]; } @@ -73,110 +51,132 @@ fn user.classify(v: int | string) -> string { } bb3: { - branch copy _2 -> [bb5, bb4]; + _0 = !copy _2; + goto -> bb4; } bb4: { - _0 = const "text"; - goto -> bb6; - } - - bb5: { - _0 = const "number"; - goto -> bb6; - } - - bb6: { return; } } -fn user.is_int(v: int | string) -> bool { +fn user.is_int_or_bool(v: int | string | bool) -> bool { // Locals: let _0: bool // _0 // return - let _1: int | string // v // param + let _1: int | string | bool // v // param let _2: bool + let _3: bool bb0: { _2 = is_type(copy _1, int); - branch copy _2 -> [bb2, bb1]; + branch copy _2 -> [bb3, bb1]; } bb1: { - _0 = const false; - goto -> bb3; + _3 = is_type(copy _1, bool); + branch copy _3 -> [bb3, bb2]; } bb2: { - _0 = const true; - goto -> bb3; + _0 = const false; + goto -> bb4; } bb3: { + _0 = const true; + goto -> bb4; + } + + bb4: { return; } } -fn user.is_int_or_bool(v: int | string | bool) -> bool { +fn user.classify(v: int | string) -> string { // Locals: - let _0: bool // _0 // return - let _1: int | string | bool // v // param + let _0: string // _0 // return + let _1: int | string // v // param let _2: bool let _3: bool bb0: { - _2 = is_type(copy _1, int); - branch copy _2 -> [bb3, bb1]; + _3 = is_type(copy _1, int); + branch copy _3 -> [bb2, bb1]; } bb1: { - _3 = is_type(copy _1, bool); - branch copy _3 -> [bb3, bb2]; + _2 = const false; + goto -> bb3; } bb2: { - _0 = const false; - goto -> bb4; + _2 = const true; + goto -> bb3; } bb3: { - _0 = const true; - goto -> bb4; + branch copy _2 -> [bb5, bb4]; } bb4: { + _0 = const "text"; + goto -> bb6; + } + + bb5: { + _0 = const "number"; + goto -> bb6; + } + + bb6: { return; } } -fn user.is_not_string(v: int | string) -> bool { +fn user.both_ints(a: int | string, b: int | string) -> bool { // Locals: let _0: bool // _0 // return - let _1: int | string // v // param - let _2: bool + let _1: int | string // a // param + let _2: int | string // b // param let _3: bool + let _4: bool + let _5: bool bb0: { - _3 = is_type(copy _1, string); - branch copy _3 -> [bb2, bb1]; + _4 = is_type(copy _1, int); + branch copy _4 -> [bb2, bb1]; } bb1: { - _2 = const false; + _3 = const false; goto -> bb3; } bb2: { - _2 = const true; + _3 = const true; goto -> bb3; } bb3: { - _0 = !copy _2; - goto -> bb4; + _0 = short_circuit(&&) copy _3 -> [eval: bb4, join: bb7]; } bb4: { + _5 = is_type(copy _2, int); + branch copy _5 -> [bb6, bb5]; + } + + bb5: { + _0 = const false; + goto -> bb7; + } + + bb6: { + _0 = const true; + goto -> bb7; + } + + bb7: { return; } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/json_alias_basic/baml_tests__compiles__json_alias_basic__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/json_alias_basic/baml_tests__compiles__json_alias_basic__04_5_mir.snap index 8b7ff4f91d6..de28b0729fb 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/json_alias_basic/baml_tests__compiles__json_alias_basic__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/json_alias_basic/baml_tests__compiles__json_alias_basic__04_5_mir.snap @@ -1,6 +1,5 @@ --- source: crates/baml_tests/src/generated_tests.rs -assertion_line: 13513 --- === MIR2 === fn user.MakeWrapper() -> Wrapper { @@ -17,67 +16,26 @@ fn user.MakeWrapper() -> Wrapper { } } -fn user.MatchJson(j: int | float | string | bool | null | baml.json.json[] | map) -> string { +fn user.ReturnNull() -> int | float | string | bool | null | baml.json.json[] | map { // Locals: - let _0: string // _0 // return - let _1: int | float | string | bool | null | baml.json.json[] | map // j // param - let _2: int + let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return bb0: { - _2 = type_tag(_1); - switch copy _2 [null: bb8, bool: bb7, int: bb6, float: bb5, string: bb4, list: bb3, map: bb2, otherwise: bb1] (exhaustive); + _0 = const null; + goto -> bb1; } bb1: { - unreachable; - } - - bb2: { - _0 = const "map"; - goto -> bb9; - } - - bb3: { - _0 = const "array"; - goto -> bb9; - } - - bb4: { - _0 = const "string"; - goto -> bb9; - } - - bb5: { - _0 = const "float"; - goto -> bb9; - } - - bb6: { - _0 = const "int"; - goto -> bb9; - } - - bb7: { - _0 = const "bool"; - goto -> bb9; - } - - bb8: { - _0 = const "null"; - goto -> bb9; - } - - bb9: { return; } } -fn user.ReturnArray() -> int | float | string | bool | null | baml.json.json[] | map { +fn user.ReturnBool() -> int | float | string | bool | null | baml.json.json[] | map { // Locals: let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return bb0: { - _0 = [const 1_i64, const 2_i64, const 3_i64]: baml.json.json[]; + _0 = const true; goto -> bb1; } @@ -86,12 +44,12 @@ fn user.ReturnArray() -> int | float | string | bool | null | baml.json.json[] | } } -fn user.ReturnBool() -> int | float | string | bool | null | baml.json.json[] | map { +fn user.ReturnInt() -> int | float | string | bool | null | baml.json.json[] | map { // Locals: let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return bb0: { - _0 = const true; + _0 = const 42_i64; goto -> bb1; } @@ -114,12 +72,12 @@ fn user.ReturnFloat() -> int | float | string | bool | null | baml.json.json[] | } } -fn user.ReturnInt() -> int | float | string | bool | null | baml.json.json[] | map { +fn user.ReturnString() -> int | float | string | bool | null | baml.json.json[] | map { // Locals: let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return bb0: { - _0 = const 42_i64; + _0 = const "hello"; goto -> bb1; } @@ -128,12 +86,12 @@ fn user.ReturnInt() -> int | float | string | bool | null | baml.json.json[] | m } } -fn user.ReturnMap() -> int | float | string | bool | null | baml.json.json[] | map { +fn user.ReturnArray() -> int | float | string | bool | null | baml.json.json[] | map { // Locals: let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return bb0: { - _0 = { const "key": const "value" }: map; + _0 = [const 1_i64, const 2_i64, const 3_i64]: baml.json.json[]; goto -> bb1; } @@ -142,12 +100,12 @@ fn user.ReturnMap() -> int | float | string | bool | null | baml.json.json[] | m } } -fn user.ReturnNull() -> int | float | string | bool | null | baml.json.json[] | map { +fn user.ReturnMap() -> int | float | string | bool | null | baml.json.json[] | map { // Locals: let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return bb0: { - _0 = const null; + _0 = { const "key": const "value" }: map; goto -> bb1; } @@ -156,16 +114,57 @@ fn user.ReturnNull() -> int | float | string | bool | null | baml.json.json[] | } } -fn user.ReturnString() -> int | float | string | bool | null | baml.json.json[] | map { +fn user.MatchJson(j: int | float | string | bool | null | baml.json.json[] | map) -> string { // Locals: - let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return + let _0: string // _0 // return + let _1: int | float | string | bool | null | baml.json.json[] | map // j // param + let _2: int bb0: { - _0 = const "hello"; - goto -> bb1; + _2 = type_tag(_1); + switch copy _2 [null: bb8, bool: bb7, int: bb6, float: bb5, string: bb4, list: bb3, map: bb2, otherwise: bb1] (exhaustive); } bb1: { + unreachable; + } + + bb2: { + _0 = const "map"; + goto -> bb9; + } + + bb3: { + _0 = const "array"; + goto -> bb9; + } + + bb4: { + _0 = const "string"; + goto -> bb9; + } + + bb5: { + _0 = const "float"; + goto -> bb9; + } + + bb6: { + _0 = const "int"; + goto -> bb9; + } + + bb7: { + _0 = const "bool"; + goto -> bb9; + } + + bb8: { + _0 = const "null"; + goto -> bb9; + } + + bb9: { return; } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/json_cross_namespace_static_call/baml_tests__compiles__json_cross_namespace_static_call__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/json_cross_namespace_static_call/baml_tests__compiles__json_cross_namespace_static_call__04_5_mir.snap index 0db353c174a..a5557c1ed9d 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/json_cross_namespace_static_call/baml_tests__compiles__json_cross_namespace_static_call__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/json_cross_namespace_static_call/baml_tests__compiles__json_cross_namespace_static_call__04_5_mir.snap @@ -1,16 +1,15 @@ --- source: crates/baml_tests/src/generated_tests.rs -assertion_line: 13949 --- === MIR2 === -fn user.decode_auto(j: int | float | string | bool | null | baml.json.json[] | map) -> pkg.inner.AutoBox { +fn user.decode_root(j: int | float | string | bool | null | baml.json.json[] | map) -> pkg.inner.Box { // Locals: - let _0: pkg.inner.AutoBox // _0 // return + let _0: pkg.inner.Box // _0 // return let _1: int | float | string | bool | null | baml.json.json[] | map // j // param let _2: type bb0: { - _2 = load_type(pkg.inner.AutoBox); + _2 = load_type(pkg.inner.Box); _0 = call const fn baml.json.to(copy _1) -> [bb1]; } @@ -19,14 +18,14 @@ fn user.decode_auto(j: int | float | string | bool | null | baml.json.json[] | m } } -fn user.decode_plain(j: int | float | string | bool | null | baml.json.json[] | map) -> pkg.inner.Plain { +fn user.decode_auto(j: int | float | string | bool | null | baml.json.json[] | map) -> pkg.inner.AutoBox { // Locals: - let _0: pkg.inner.Plain // _0 // return + let _0: pkg.inner.AutoBox // _0 // return let _1: int | float | string | bool | null | baml.json.json[] | map // j // param let _2: type bb0: { - _2 = load_type(pkg.inner.Plain); + _2 = load_type(pkg.inner.AutoBox); _0 = call const fn baml.json.to(copy _1) -> [bb1]; } @@ -35,14 +34,14 @@ fn user.decode_plain(j: int | float | string | bool | null | baml.json.json[] | } } -fn user.decode_root(j: int | float | string | bool | null | baml.json.json[] | map) -> pkg.inner.Box { +fn user.decode_plain(j: int | float | string | bool | null | baml.json.json[] | map) -> pkg.inner.Plain { // Locals: - let _0: pkg.inner.Box // _0 // return + let _0: pkg.inner.Plain // _0 // return let _1: int | float | string | bool | null | baml.json.json[] | map // j // param let _2: type bb0: { - _2 = load_type(pkg.inner.Box); + _2 = load_type(pkg.inner.Plain); _0 = call const fn baml.json.to(copy _1) -> [bb1]; } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/json_llm_return_type/baml_tests__compiles__json_llm_return_type__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/json_llm_return_type/baml_tests__compiles__json_llm_return_type__04_5_mir.snap index 097b7bae0f6..6f0803860d4 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/json_llm_return_type/baml_tests__compiles__json_llm_return_type__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/json_llm_return_type/baml_tests__compiles__json_llm_return_type__04_5_mir.snap @@ -2,6 +2,29 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === +fn user.TestClient$new(lenient: bool) -> null { + // Locals: + let _0: null // _0 // return + let _1: bool // lenient // param + let _2: baml.llm.PrimitiveClientOptions + let _3: map + let _4: map + let _5: map + + bb0: { + _3 = { }: map; + _4 = { }: map; + _5 = { }: map; + _2 = baml.llm.PrimitiveClientOptions { const "gpt-4o-mini", const null, const null, const null, const null, const null, const null, const null, const null, const "test-key", const null, const null, copy _3, copy _4, copy _5 }; + _0 = baml.llm.PrimitiveClient { const "TestClient", const "openai", copy _2 }; + goto -> bb1; + } + + bb1: { + return; + } +} + fn user.ExtractAny(client: baml.llm.Client) -> int | float | string | bool | null | baml.json.json[] | map { // Locals: let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return @@ -85,6 +108,66 @@ fn user.ExtractAny$build_request_stream(client: baml.llm.Client) -> baml.http.Re } } +fn user.ExtractAny$parse(json: string, client: baml.llm.Client) -> int | float | string | bool | null | baml.json.json[] | map { + // Locals: + let _0: int | float | string | bool | null | baml.json.json[] | map // _0 // return + let _1: string // json // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.TestClient; + goto -> bb2; + } + + bb2: { + _4 = load_type(baml.json.json$stream | null); + _5 = load_type(baml.json.json); + _0 = call const fn baml.llm.parse(copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.ExtractAny$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client) -> baml.llm.Stream, int | float | string | bool | null | baml.json.json[] | map> { + // Locals: + let _0: baml.llm.Stream, int | float | string | bool | null | baml.json.json[] | map> // _0 // return + let _1: baml.http.SseStream // sse // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.TestClient; + goto -> bb2; + } + + bb2: { + _4 = load_type(baml.json.json$stream | null); + _5 = load_type(baml.json.json); + _0 = call const fn baml.llm.Client.__make_stream(copy _2, copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + fn user.ExtractAny$render_prompt(client: baml.llm.Client) -> baml.llm.PromptAst { // Locals: let _0: baml.llm.PromptAst // _0 // return @@ -112,25 +195,33 @@ fn user.ExtractAny$render_prompt(client: baml.llm.Client) -> baml.llm.PromptAst } } -fn user.TestClient$new(lenient: bool) -> null { +fn user.ExtractAny$stream(client: baml.llm.Client) -> baml.llm.Stream, int | float | string | bool | null | baml.json.json[] | map> { // Locals: - let _0: null // _0 // return - let _1: bool // lenient // param - let _2: baml.llm.PrimitiveClientOptions - let _3: map - let _4: map - let _5: map + let _0: baml.llm.Stream, int | float | string | bool | null | baml.json.json[] | map> // _0 // return + let _1: baml.llm.Client // client // param + let _2: bool + let _3: map + let _4: type + let _5: type bb0: { - _3 = { }: map; - _4 = { }: map; - _5 = { }: map; - _2 = baml.llm.PrimitiveClientOptions { const "gpt-4o-mini", const null, const null, const null, const null, const null, const null, const null, const null, const "test-key", const null, const null, copy _3, copy _4, copy _5 }; - _0 = baml.llm.PrimitiveClient { const "TestClient", const "openai", copy _2 }; - goto -> bb1; + _2 = copy _1 == const ; + branch copy _2 -> [bb1, bb2]; } bb1: { + _1 = const item user.TestClient; + goto -> bb2; + } + + bb2: { + _3 = { }: map; + _4 = load_type(baml.json.json$stream | null); + _5 = load_type(baml.json.json); + _0 = call const fn baml.llm.stream_llm_function(copy _1, const "ExtractAny", copy _3, const ) -> [bb3]; + } + + bb3: { return; } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/json_parse_stringify_intrinsics/baml_tests__compiles__json_parse_stringify_intrinsics__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/json_parse_stringify_intrinsics/baml_tests__compiles__json_parse_stringify_intrinsics__04_5_mir.snap index 6fce0bc2ab3..0c112ac6df6 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/json_parse_stringify_intrinsics/baml_tests__compiles__json_parse_stringify_intrinsics__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/json_parse_stringify_intrinsics/baml_tests__compiles__json_parse_stringify_intrinsics__04_5_mir.snap @@ -2,6 +2,48 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === +fn user.parse_and_roundtrip(s: string) -> string { + // Locals: + let _0: string // _0 // return + let _1: string // s // param + let _2: int | float | string | bool | null | (int | float | string | bool | null | baml.json.json[] | map)[] | map> // j + let _3: int | float | string | bool | null | (int | float | string | bool | null | baml.json.json[] | map)[] | map> + + bb0: { + _2 = call const fn baml.json.parse(copy _1) -> [bb1]; + } + + bb1: { + _3 = copy _2; + _0 = call const fn baml.json.stringify(copy _3) -> [bb2]; + } + + bb2: { + return; + } +} + +fn user.parse_and_roundtrip_pretty(s: string) -> string { + // Locals: + let _0: string // _0 // return + let _1: string // s // param + let _2: int | float | string | bool | null | (int | float | string | bool | null | baml.json.json[] | map)[] | map> // j + let _3: int | float | string | bool | null | (int | float | string | bool | null | baml.json.json[] | map)[] | map> + + bb0: { + _2 = call const fn baml.json.parse(copy _1) -> [bb1]; + } + + bb1: { + _3 = copy _2; + _0 = call const fn baml.json.stringify_pretty(copy _3) -> [bb2]; + } + + bb2: { + return; + } +} + fn user.match_parsed(s: string) -> string { // Locals: let _0: string // _0 // return @@ -105,45 +147,3 @@ fn user.match_parsed(s: string) -> string { return; } } - -fn user.parse_and_roundtrip(s: string) -> string { - // Locals: - let _0: string // _0 // return - let _1: string // s // param - let _2: int | float | string | bool | null | (int | float | string | bool | null | baml.json.json[] | map)[] | map> // j - let _3: int | float | string | bool | null | (int | float | string | bool | null | baml.json.json[] | map)[] | map> - - bb0: { - _2 = call const fn baml.json.parse(copy _1) -> [bb1]; - } - - bb1: { - _3 = copy _2; - _0 = call const fn baml.json.stringify(copy _3) -> [bb2]; - } - - bb2: { - return; - } -} - -fn user.parse_and_roundtrip_pretty(s: string) -> string { - // Locals: - let _0: string // _0 // return - let _1: string // s // param - let _2: int | float | string | bool | null | (int | float | string | bool | null | baml.json.json[] | map)[] | map> // j - let _3: int | float | string | bool | null | (int | float | string | bool | null | baml.json.json[] | map)[] | map> - - bb0: { - _2 = call const fn baml.json.parse(copy _1) -> [bb1]; - } - - bb1: { - _3 = copy _2; - _0 = call const fn baml.json.stringify_pretty(copy _3) -> [bb2]; - } - - bb2: { - return; - } -} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_concrete/baml_tests__compiles__json_to_from_string_concrete__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_concrete/baml_tests__compiles__json_to_from_string_concrete__04_5_mir.snap index b05b65db3cb..f9582b84771 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_concrete/baml_tests__compiles__json_to_from_string_concrete__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_concrete/baml_tests__compiles__json_to_from_string_concrete__04_5_mir.snap @@ -2,15 +2,15 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === -fn user.deserialize_user(s: string) -> User { +fn user.serialize_user(u: User) -> string { // Locals: - let _0: User // _0 // return - let _1: string // s // param + let _0: string // _0 // return + let _1: User // u // param let _2: type bb0: { _2 = load_type(User); - _0 = call const fn baml.json.from_string(copy _1) -> [bb1]; + _0 = call const fn baml.json.to_string(copy _1) -> [bb1]; } bb1: { @@ -18,15 +18,15 @@ fn user.deserialize_user(s: string) -> User { } } -fn user.serialize_user(u: User) -> string { +fn user.deserialize_user(s: string) -> User { // Locals: - let _0: string // _0 // return - let _1: User // u // param + let _0: User // _0 // return + let _1: string // s // param let _2: type bb0: { _2 = load_type(User); - _0 = call const fn baml.json.to_string(copy _1) -> [bb1]; + _0 = call const fn baml.json.from_string(copy _1) -> [bb1]; } bb1: { diff --git a/baml_language/crates/baml_tests/snapshots/compiles/lambda_advanced/baml_tests__compiles__lambda_advanced__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/lambda_advanced/baml_tests__compiles__lambda_advanced__04_5_mir.snap index 74d7456ecdc..4e650fab53b 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/lambda_advanced/baml_tests__compiles__lambda_advanced__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/lambda_advanced/baml_tests__compiles__lambda_advanced__04_5_mir.snap @@ -1,101 +1,51 @@ --- source: crates/baml_tests/src/generated_tests.rs -assertion_line: 16890 --- === MIR2 === -fn user.test_apply_twice_inferred() -> int { - // Locals: - let _0: int // _0 // return - let _1: (int) -> int throws never // double - let _2: ((int) -> int throws never, int) -> int throws never // apply_twice - let _3: ((int) -> int throws never, int) -> int throws never - let _4: (int) -> int throws never - - bb0: { - _1 = make_closure lambda[0](); - _2 = make_closure lambda[1](); - _3 = copy _2; - _4 = copy _1; - _0 = call copy _3(copy _4, const 3_i64) -> [bb1]; - } - - bb1: { - return; - } -} - -// lambda[0] -fn .(x: int) -> null { - // Locals: - let _0: null // _0 // return - let _1: int // x // param - - bb0: { - _0 = copy _1 * const 2_i64; - goto -> bb1; - } - - bb1: { - return; - } -} - -// lambda[1] -fn .(f: (int) -> int throws never, x: int) -> null { - // Locals: - let _0: null // _0 // return - let _1: (int) -> int throws never // f // param - let _2: int // x // param - let _3: int - - bb0: { - _3 = call copy _1(copy _2) -> [bb1]; - } - - bb1: { - _0 = call copy _1(copy _3) -> [bb2]; - } - - bb2: { - return; - } -} - -fn user.test_capture_in_map_inferred() -> int[] { +fn user.test_chained_map() -> int[] { // Locals: let _0: int[] // _0 // return let _1: int[] // items - let _2: int // factor [captured] + let _2: int[] // step1 let _3: (int) -> int throws E let _4: type let _5: type let _6: type + let _7: (int) -> int throws E + let _8: type + let _9: type + let _10: type bb0: { _1 = [const 1_i64, const 2_i64, const 3_i64]: int[]; - _2 = const 10_i64; - _3 = make_closure lambda[0](copy _2); + _3 = make_closure lambda[0](); _4 = load_type(int); _5 = load_type(never); _6 = load_type(int); - _0 = call const fn baml.Array.map(copy _1, copy _3) -> [bb1]; + _2 = call const fn baml.Array.map(copy _1, copy _3) -> [bb1]; } bb1: { + _7 = make_closure lambda[1](); + _8 = load_type(int); + _9 = load_type(never); + _10 = load_type(int); + _0 = call const fn baml.Array.map(copy _2, copy _7) -> [bb2]; + } + + bb2: { return; } } // lambda[0] -fn .(x: null) -> null { +fn .(x: null) -> null { // Locals: let _0: null // _0 // return let _1: null // x // param - let _2: int bb0: { - _2 = copy capture[0]; - _0 = copy _1 * copy _2; + _0 = copy _1 * const 10_i64; goto -> bb1; } @@ -104,18 +54,15 @@ fn .(x: null) -> null { } } -fn user.test_capture_lambda_inferred() -> int { +// lambda[1] +fn .(x: null) -> null { // Locals: - let _0: int // _0 // return - let _1: (int, int) -> int throws never // multiply [captured] - let _2: (int) -> int throws never // double - let _3: (int) -> int throws never + let _0: null // _0 // return + let _1: null // x // param bb0: { - _1 = make_closure lambda[0](); - _2 = make_closure lambda[1](copy _1); - _3 = copy _2; - _0 = call copy _3(const 21_i64) -> [bb1]; + _0 = copy _1 + const 1_i64; + goto -> bb1; } bb1: { @@ -123,16 +70,22 @@ fn user.test_capture_lambda_inferred() -> int { } } -// lambda[0] -fn .(a: int, b: int) -> null { +fn user.test_map_string_to_int() -> int[] { // Locals: - let _0: null // _0 // return - let _1: int // a // param - let _2: int // b // param + let _0: int[] // _0 // return + let _1: string[] // words + let _2: (string) -> int throws E + let _3: type + let _4: type + let _5: type bb0: { - _0 = copy _1 * copy _2; - goto -> bb1; + _1 = [const "hello", const "world"]: string[]; + _2 = make_closure lambda[0](); + _3 = load_type(int); + _4 = load_type(never); + _5 = load_type(string); + _0 = call const fn baml.Array.map(copy _1, copy _2) -> [bb1]; } bb1: { @@ -140,16 +93,14 @@ fn .(a: int, b: int) -> null { } } -// lambda[1] -fn .(x: int) -> null { +// lambda[0] +fn .(w: string) -> null { // Locals: let _0: null // _0 // return - let _1: int // x // param - let _2: (int, int) -> int throws never + let _1: string // w // param bb0: { - _2 = copy capture[0]; - _0 = call copy _2(copy _1, const 2_i64) -> [bb1]; + _0 = call const fn baml.String.length(copy _1) -> [bb1]; } bb1: { @@ -157,35 +108,23 @@ fn .(x: int) -> null { } } -fn user.test_chained_map() -> int[] { +fn user.test_higher_order_return() -> int { // Locals: - let _0: int[] // _0 // return - let _1: int[] // items - let _2: int[] // step1 - let _3: (int) -> int throws E - let _4: type - let _5: type - let _6: type - let _7: (int) -> int throws E - let _8: type - let _9: type - let _10: type + let _0: int // _0 // return + let _1: (int) -> ((int) -> int throws never) throws never // make_adder + let _2: (int) -> int throws never // add5 + let _3: (int) -> ((int) -> int throws never) throws never + let _4: (int) -> int throws never bb0: { - _1 = [const 1_i64, const 2_i64, const 3_i64]: int[]; - _3 = make_closure lambda[0](); - _4 = load_type(int); - _5 = load_type(never); - _6 = load_type(int); - _2 = call const fn baml.Array.map(copy _1, copy _3) -> [bb1]; + _1 = make_closure lambda[0](); + _3 = copy _1; + _2 = call copy _3(const 5_i64) -> [bb1]; } bb1: { - _7 = make_closure lambda[1](); - _8 = load_type(int); - _9 = load_type(never); - _10 = load_type(int); - _0 = call const fn baml.Array.map(copy _2, copy _7) -> [bb2]; + _4 = copy _2; + _0 = call copy _4(const 37_i64) -> [bb2]; } bb2: { @@ -194,13 +133,15 @@ fn user.test_chained_map() -> int[] { } // lambda[0] -fn .(x: null) -> null { +fn .(n: int) -> null { // Locals: let _0: null // _0 // return - let _1: null // x // param + let _1: int // n // param [captured] + let _2: (int) -> int throws never // adder bb0: { - _0 = copy _1 * const 10_i64; + _2 = make_closure lambda[0](copy _1); + _0 = copy _2; goto -> bb1; } @@ -209,14 +150,16 @@ fn .(x: null) -> null { } } -// lambda[1] -fn .(x: null) -> null { +// lambda[0] +fn ., 1)>(x: int) -> null { // Locals: let _0: null // _0 // return - let _1: null // x // param + let _1: int // x // param + let _2: int bb0: { - _0 = copy _1 + const 1_i64; + _2 = copy capture[0]; + _0 = copy _1 + copy _2; goto -> bb1; } @@ -225,47 +168,32 @@ fn .(x: null) -> null { } } -fn user.test_compose_inferred() -> int[] { +fn user.test_lambda_calling_lambda() -> int { // Locals: - let _0: int[] // _0 // return - let _1: int[] // items - let _2: int[] // step1 - let _3: (int) -> int throws E - let _4: type - let _5: type - let _6: type - let _7: (int) -> int throws E - let _8: type - let _9: type - let _10: type + let _0: int // _0 // return + let _1: (int) -> int throws never // double + let _2: ((int) -> int throws never, int) -> int throws never // apply_twice + let _3: ((int) -> int throws never, int) -> int throws never + let _4: (int) -> int throws never bb0: { - _1 = [const 1_i64, const 2_i64, const 3_i64]: int[]; - _3 = make_closure lambda[0](); - _4 = load_type(int); - _5 = load_type(never); - _6 = load_type(int); - _2 = call const fn baml.Array.map(copy _1, copy _3) -> [bb1]; + _1 = make_closure lambda[0](); + _2 = make_closure lambda[1](); + _3 = copy _2; + _4 = copy _1; + _0 = call copy _3(copy _4, const 3_i64) -> [bb1]; } bb1: { - _7 = make_closure lambda[1](); - _8 = load_type(int); - _9 = load_type(never); - _10 = load_type(int); - _0 = call const fn baml.Array.map(copy _2, copy _7) -> [bb2]; - } - - bb2: { return; } } // lambda[0] -fn .(x: null) -> null { +fn .(x: int) -> null { // Locals: let _0: null // _0 // return - let _1: null // x // param + let _1: int // x // param bb0: { _0 = copy _1 * const 2_i64; @@ -278,17 +206,22 @@ fn .(x: null) -> null { } // lambda[1] -fn .(x: null) -> null { +fn .(f: (int) -> int throws never, x: int) -> null { // Locals: let _0: null // _0 // return - let _1: null // x // param + let _1: (int) -> int throws never // f // param + let _2: int // x // param + let _3: int bb0: { - _0 = copy _1 + const 1_i64; - goto -> bb1; + _3 = call copy _1(copy _2) -> [bb1]; } bb1: { + _0 = call copy _1(copy _3) -> [bb2]; + } + + bb2: { return; } } @@ -353,18 +286,16 @@ fn ., 1)>(c: int) -> null { } } -fn user.test_deep_capture_inferred() -> int { +fn user.test_lambda_with_match() -> string { // Locals: - let _0: int // _0 // return - let _1: int // a [captured] - let _2: (int) -> int throws never // f - let _3: (int) -> int throws never + let _0: string // _0 // return + let _1: (int) -> string throws never // describe + let _2: (int) -> string throws never bb0: { - _1 = const 1_i64; - _2 = make_closure lambda[0](copy _1); - _3 = copy _2; - _0 = call copy _3(const 10_i64) -> [bb1]; + _1 = make_closure lambda[0](); + _2 = copy _1; + _0 = call copy _2(const 1_i64) -> [bb1]; } bb1: { @@ -373,62 +304,45 @@ fn user.test_deep_capture_inferred() -> int { } // lambda[0] -fn .(b: int) -> null { +fn .(n: int) -> null { // Locals: let _0: null // _0 // return - let _1: int // b // param [captured] - let _2: (int) -> int throws never // g - let _3: (int) -> int throws never + let _1: int // n // param bb0: { - _2 = make_closure lambda[0](copy capture[0], copy _1); - _3 = copy _2; - _0 = call copy _3(const 100_i64) -> [bb1]; + switch copy _1 [0: bb3, 1: bb2, otherwise: bb1]; } bb1: { - return; + _0 = const "many"; + goto -> bb4; } -} -// lambda[0] -fn ., 1)>(c: int) -> null { - // Locals: - let _0: null // _0 // return - let _1: int // c // param - let _2: int - let _3: int - let _4: int + bb2: { + _0 = const "one"; + goto -> bb4; + } - bb0: { - _3 = copy capture[0]; - _4 = copy capture[1]; - _2 = copy _3 + copy _4; - _0 = copy _2 + copy _1; - goto -> bb1; + bb3: { + _0 = const "zero"; + goto -> bb4; } - bb1: { + bb4: { return; } } -fn user.test_fully_inferred_map() -> int[] { +fn user.test_lambda_with_if() -> string { // Locals: - let _0: int[] // _0 // return - let _1: int[] // items - let _2: (int) -> int throws E - let _3: type - let _4: type - let _5: type + let _0: string // _0 // return + let _1: (int) -> string throws never // classify + let _2: (int) -> string throws never bb0: { - _1 = [const 1_i64, const 2_i64, const 3_i64]: int[]; - _2 = make_closure lambda[0](); - _3 = load_type(int); - _4 = load_type(never); - _5 = load_type(int); - _0 = call const fn baml.Array.map(copy _1, copy _2) -> [bb1]; + _1 = make_closure lambda[0](); + _2 = copy _1; + _0 = call copy _2(const -5_i64) -> [bb1]; } bb1: { @@ -437,56 +351,61 @@ fn user.test_fully_inferred_map() -> int[] { } // lambda[0] -fn .(x: null) -> null { +fn .(n: int) -> null { // Locals: let _0: null // _0 // return - let _1: null // x // param + let _1: int // n // param + let _2: bool + let _3: bool bb0: { - _0 = copy _1 * const 2_i64; - goto -> bb1; + _2 = copy _1 < const 0_i64; + branch copy _2 -> [bb4, bb1]; } bb1: { - return; + _3 = copy _1 == const 0_i64; + branch copy _3 -> [bb3, bb2]; } -} -fn user.test_higher_order_inferred() -> int { - // Locals: - let _0: int // _0 // return - let _1: (int) -> ((int) -> int throws never) throws never // make_adder - let _2: (int) -> int throws never // add5 - let _3: (int) -> ((int) -> int throws never) throws never - let _4: (int) -> int throws never + bb2: { + _0 = const "positive"; + goto -> bb5; + } - bb0: { - _1 = make_closure lambda[0](); - _3 = copy _1; - _2 = call copy _3(const 5_i64) -> [bb1]; + bb3: { + _0 = const "zero"; + goto -> bb5; } - bb1: { - _4 = copy _2; - _0 = call copy _4(const 37_i64) -> [bb2]; + bb4: { + _0 = const "negative"; + goto -> bb5; } - bb2: { + bb5: { return; } } -// lambda[0] -fn .(n: int) -> null { +fn user.test_map_with_capture() -> int[] { // Locals: - let _0: null // _0 // return - let _1: int // n // param [captured] - let _2: (int) -> int throws never // adder + let _0: int[] // _0 // return + let _1: int[] // items + let _2: int // factor [captured] + let _3: (int) -> int throws E + let _4: type + let _5: type + let _6: type bb0: { - _2 = make_closure lambda[0](copy _1); - _0 = copy _2; - goto -> bb1; + _1 = [const 1_i64, const 2_i64, const 3_i64]: int[]; + _2 = const 10_i64; + _3 = make_closure lambda[0](copy _2); + _4 = load_type(int); + _5 = load_type(never); + _6 = load_type(int); + _0 = call const fn baml.Array.map(copy _1, copy _3) -> [bb1]; } bb1: { @@ -495,15 +414,15 @@ fn .(n: int) -> null { } // lambda[0] -fn ., 1)>(x: int) -> null { +fn .(x: null) -> null { // Locals: let _0: null // _0 // return - let _1: int // x // param + let _1: null // x // param let _2: int bb0: { _2 = copy capture[0]; - _0 = copy _1 + copy _2; + _0 = copy _1 * copy _2; goto -> bb1; } @@ -512,41 +431,49 @@ fn ., 1)>(x: int) -> null { } } -fn user.test_higher_order_return() -> int { +fn user.test_nested_map() -> int[][] { // Locals: - let _0: int // _0 // return - let _1: (int) -> ((int) -> int throws never) throws never // make_adder - let _2: (int) -> int throws never // add5 - let _3: (int) -> ((int) -> int throws never) throws never - let _4: (int) -> int throws never + let _0: int[][] // _0 // return + let _1: int[][] // matrix + let _2: int[] + let _3: int[] + let _4: (int[]) -> int[] throws E + let _5: type + let _6: type + let _7: type bb0: { - _1 = make_closure lambda[0](); - _3 = copy _1; - _2 = call copy _3(const 5_i64) -> [bb1]; + _2 = [const 1_i64, const 2_i64]: int[]; + _3 = [const 3_i64, const 4_i64]: int[]; + _1 = [copy _2, copy _3]: int[][]; + _4 = make_closure lambda[0](); + _5 = load_type(int[]); + _6 = load_type(never); + _7 = load_type(int[]); + _0 = call const fn baml.Array.map(copy _1, copy _4) -> [bb1]; } bb1: { - _4 = copy _2; - _0 = call copy _4(const 37_i64) -> [bb2]; - } - - bb2: { return; } } // lambda[0] -fn .(n: int) -> null { +fn .(row: int[]) -> null { // Locals: let _0: null // _0 // return - let _1: int // n // param [captured] - let _2: (int) -> int throws never // adder + let _1: int[] // row // param + let _2: (int) -> int throws E + let _3: type + let _4: type + let _5: type bb0: { - _2 = make_closure lambda[0](copy _1); - _0 = copy _2; - goto -> bb1; + _2 = make_closure lambda[0](); + _3 = load_type(int); + _4 = load_type(never); + _5 = load_type(int); + _0 = call const fn baml.Array.map(copy _1, copy _2) -> [bb1]; } bb1: { @@ -555,15 +482,13 @@ fn .(n: int) -> null { } // lambda[0] -fn ., 1)>(x: int) -> null { +fn ., 1)>(x: null) -> null { // Locals: let _0: null // _0 // return - let _1: int // x // param - let _2: int + let _1: null // x // param bb0: { - _2 = copy capture[0]; - _0 = copy _1 + copy _2; + _0 = copy _1 * copy _1; goto -> bb1; } @@ -572,35 +497,45 @@ fn ., 1)>(x: int) -> null { } } -fn user.test_iife() -> int { +fn user.test_map_multi_statement() -> int[] { // Locals: - let _0: int // _0 // return - let _1: int // result - let _2: (int) -> int throws never + let _0: int[] // _0 // return + let _1: int[] // items + let _2: (int) -> int throws E + let _3: type + let _4: type + let _5: type bb0: { + _1 = [const 1_i64, const 2_i64, const 3_i64]: int[]; _2 = make_closure lambda[0](); - _1 = call copy _2(const 7_i64) -> [bb1]; + _3 = load_type(int); + _4 = load_type(never); + _5 = load_type(int); + _0 = call const fn baml.Array.map(copy _1, copy _2) -> [bb1]; } bb1: { - _0 = copy _1; - goto -> bb2; - } - - bb2: { return; } } // lambda[0] -fn .(x: int) -> null { +fn .(x: null) -> null { // Locals: let _0: null // _0 // return - let _1: int // x // param + let _1: null // x // param + let _2: int // doubled + let _3: int // offset + let _4: int + let _5: int bb0: { - _0 = copy _1 * copy _1; + _2 = copy _1 * const 2_i64; + _3 = const 100_i64; + _4 = copy _2; + _5 = copy _3; + _0 = copy _4 + copy _5; goto -> bb1; } @@ -609,14 +544,24 @@ fn .(x: int) -> null { } } -fn user.test_iife_inferred() -> int { +fn user.test_lambda_variable_then_pass() -> int[] { // Locals: - let _0: int // _0 // return - let _1: (int) -> int throws never + let _0: int[] // _0 // return + let _1: int[] // items + let _2: (int) -> int throws never // halve + let _3: (int) -> int throws never + let _4: type + let _5: type + let _6: type bb0: { - _1 = make_closure lambda[0](); - _0 = call copy _1(const 7_i64) -> [bb1]; + _1 = [const 10_i64, const 20_i64, const 30_i64]: int[]; + _2 = make_closure lambda[0](); + _3 = copy _2; + _4 = load_type(int); + _5 = load_type(never); + _6 = load_type(int); + _0 = call const fn baml.Array.map(copy _1, copy _3) -> [bb1]; } bb1: { @@ -625,13 +570,13 @@ fn user.test_iife_inferred() -> int { } // lambda[0] -fn .(x: int) -> null { +fn .(x: int) -> null { // Locals: let _0: null // _0 // return let _1: int // x // param bb0: { - _0 = copy _1 * copy _1; + _0 = copy _1 / const 2_i64; goto -> bb1; } @@ -640,117 +585,127 @@ fn .(x: int) -> null { } } -fn user.test_lambda_calling_lambda() -> int { +fn user.test_shadowing() -> string { // Locals: - let _0: int // _0 // return - let _1: (int) -> int throws never // double - let _2: ((int) -> int throws never, int) -> int throws never // apply_twice - let _3: ((int) -> int throws never, int) -> int throws never - let _4: (int) -> int throws never - - bb0: { - _1 = make_closure lambda[0](); - _2 = make_closure lambda[1](); - _3 = copy _2; - _4 = copy _1; - _0 = call copy _3(copy _4, const 3_i64) -> [bb1]; - } - - bb1: { - return; - } -} - -// lambda[0] -fn .(x: int) -> null { - // Locals: - let _0: null // _0 // return - let _1: int // x // param + let _0: string // _0 // return + let _1: string // x + let _2: int[] // items + let _3: int[] // mapped + let _4: (int) -> int throws E + let _5: type + let _6: type + let _7: type + let _8: int[] + let _9: baml.iter.Iterator + let _10: unknown + let _11: bool + let _12: int + let _13: int // y + let _14: int // i + let _15: bool + let _16: int + let _17: int bb0: { - _0 = copy _1 * const 2_i64; - goto -> bb1; + _1 = const "999"; + _2 = [const 1_i64, const 2_i64, const 3_i64]: int[]; + _4 = make_closure lambda[0](); + _5 = load_type(int); + _6 = load_type(never); + _7 = load_type(int); + _3 = call const fn baml.Array.map(copy _2, copy _4) -> [bb1]; } bb1: { - return; + _8 = copy _3; + _9 = virtual_call iter as baml.iter.Iterable(copy _8) -> [bb2]; } -} -// lambda[1] -fn .(f: (int) -> int throws never, x: int) -> null { - // Locals: - let _0: null // _0 // return - let _1: (int) -> int throws never // f // param - let _2: int // x // param - let _3: int + bb2: { + _10 = virtual_call next as baml.iter.Iterator(copy _9) -> [bb3]; + } - bb0: { - _3 = call copy _1(copy _2) -> [bb1]; + bb3: { + _11 = is_type(copy _10, baml.iter.Done); + branch copy _11 -> [bb7, bb4]; } - bb1: { - _0 = call copy _1(copy _3) -> [bb2]; + bb4: { + _12 = copy _10; + fresh_cell(_13); + _13 = copy _12; + _14 = const 0_i64; + goto -> bb5; } - bb2: { + bb5: { + _16 = copy _14; + _17 = copy _13; + _15 = copy _16 < copy _17; + branch copy _15 -> [bb6, bb2]; + } + + bb6: { + _1 = copy _1 + const "1"; + _14 = copy _14 + const 1_i64; + goto -> bb5; + } + + bb7: { + _0 = copy _1; + goto -> bb8; + } + + bb8: { return; } } -fn user.test_lambda_in_match_inferred() -> int { +// lambda[0] +fn .(x: null) -> null { // Locals: - let _0: int // _0 // return - let _1: string // op - let _2: (int) -> int throws never // f - let _3: bool - let _4: bool - let _5: (int) -> int throws never + let _0: null // _0 // return + let _1: null // x // param bb0: { - _1 = const "double"; - _3 = copy _1 == const "double"; - branch copy _3 -> [bb4, bb1]; + _0 = copy _1 + const 1_i64; + goto -> bb1; } bb1: { - _4 = copy _1 == const "negate"; - branch copy _4 -> [bb3, bb2]; - } - - bb2: { - _2 = make_closure lambda[2](); - goto -> bb5; + return; } +} - bb3: { - _2 = make_closure lambda[1](); - goto -> bb5; - } +fn user.test_iife() -> int { + // Locals: + let _0: int // _0 // return + let _1: int // result + let _2: (int) -> int throws never - bb4: { + bb0: { _2 = make_closure lambda[0](); - goto -> bb5; + _1 = call copy _2(const 7_i64) -> [bb1]; } - bb5: { - _5 = copy _2; - _0 = call copy _5(const 21_i64) -> [bb6]; + bb1: { + _0 = copy _1; + goto -> bb2; } - bb6: { + bb2: { return; } } // lambda[0] -fn .(x: int) -> null { +fn .(x: int) -> null { // Locals: let _0: null // _0 // return let _1: int // x // param bb0: { - _0 = copy _1 * const 2_i64; + _0 = copy _1 * copy _1; goto -> bb1; } @@ -759,15 +714,16 @@ fn .(x: int) -> null { } } -// lambda[1] -fn .(x: int) -> null { +fn user.test_optional_return() -> int | null { // Locals: - let _0: null // _0 // return - let _1: int // x // param + let _0: int | null // _0 // return + let _1: (int) -> int | null throws never // maybe + let _2: (int) -> int | null throws never bb0: { - _0 = const 0_i64 - copy _1; - goto -> bb1; + _1 = make_closure lambda[0](); + _2 = copy _1; + _0 = call copy _2(const -1_i64) -> [bb1]; } bb1: { @@ -775,40 +731,49 @@ fn .(x: int) -> null { } } -// lambda[2] -fn .(x: int) -> null { +// lambda[0] +fn .(x: int) -> null { // Locals: let _0: null // _0 // return let _1: int // x // param + let _2: bool bb0: { - _0 = copy _1; - goto -> bb1; + _2 = copy _1 > const 0_i64; + branch copy _2 -> [bb2, bb1]; } bb1: { + _0 = const null; + goto -> bb3; + } + + bb2: { + _0 = copy _1; + goto -> bb3; + } + + bb3: { return; } } -fn user.test_lambda_variable_then_pass() -> int[] { +fn user.test_fully_inferred_map() -> int[] { // Locals: let _0: int[] // _0 // return let _1: int[] // items - let _2: (int) -> int throws never // halve - let _3: (int) -> int throws never + let _2: (int) -> int throws E + let _3: type let _4: type let _5: type - let _6: type bb0: { - _1 = [const 10_i64, const 20_i64, const 30_i64]: int[]; + _1 = [const 1_i64, const 2_i64, const 3_i64]: int[]; _2 = make_closure lambda[0](); - _3 = copy _2; - _4 = load_type(int); - _5 = load_type(never); - _6 = load_type(int); - _0 = call const fn baml.Array.map(copy _1, copy _3) -> [bb1]; + _3 = load_type(int); + _4 = load_type(never); + _5 = load_type(int); + _0 = call const fn baml.Array.map(copy _1, copy _2) -> [bb1]; } bb1: { @@ -817,13 +782,13 @@ fn user.test_lambda_variable_then_pass() -> int[] { } // lambda[0] -fn .(x: int) -> null { +fn .(x: null) -> null { // Locals: let _0: null // _0 // return - let _1: int // x // param + let _1: null // x // param bb0: { - _0 = copy _1 / const 2_i64; + _0 = copy _1 * const 2_i64; goto -> bb1; } @@ -832,16 +797,22 @@ fn .(x: int) -> null { } } -fn user.test_lambda_with_if() -> string { +fn user.test_map_type_change_inferred() -> string[] { // Locals: - let _0: string // _0 // return - let _1: (int) -> string throws never // classify - let _2: (int) -> string throws never + let _0: string[] // _0 // return + let _1: int[] // nums + let _2: (int) -> string throws E + let _3: type + let _4: type + let _5: type bb0: { - _1 = make_closure lambda[0](); - _2 = copy _1; - _0 = call copy _2(const -5_i64) -> [bb1]; + _1 = [const 1_i64, const 2_i64, const 3_i64]: int[]; + _2 = make_closure lambda[0](); + _3 = load_type(string); + _4 = load_type(never); + _5 = load_type(int); + _0 = call const fn baml.Array.map(copy _1, copy _2) -> [bb1]; } bb1: { @@ -850,53 +821,51 @@ fn user.test_lambda_with_if() -> string { } // lambda[0] -fn .(n: int) -> null { +fn .(n: null) -> null { // Locals: let _0: null // _0 // return - let _1: int // n // param - let _2: bool - let _3: bool + let _1: null // n // param bb0: { - _2 = copy _1 < const 0_i64; - branch copy _2 -> [bb4, bb1]; + switch copy _1 [1: bb3, 2: bb2, otherwise: bb1]; } bb1: { - _3 = copy _1 == const 0_i64; - branch copy _3 -> [bb3, bb2]; + _0 = const "other"; + goto -> bb4; } bb2: { - _0 = const "positive"; - goto -> bb5; + _0 = const "two"; + goto -> bb4; } bb3: { - _0 = const "zero"; - goto -> bb5; + _0 = const "one"; + goto -> bb4; } bb4: { - _0 = const "negative"; - goto -> bb5; - } - - bb5: { return; } } -fn user.test_lambda_with_match() -> string { +fn user.test_literal_return_inference() -> int[] { // Locals: - let _0: string // _0 // return - let _1: (int) -> string throws never // describe - let _2: (int) -> string throws never + let _0: int[] // _0 // return + let _1: int[] // items + let _2: (int) -> int throws E + let _3: type + let _4: type + let _5: type bb0: { - _1 = make_closure lambda[0](); - _2 = copy _1; - _0 = call copy _2(const 1_i64) -> [bb1]; + _1 = [const 1_i64, const 2_i64, const 3_i64]: int[]; + _2 = make_closure lambda[0](); + _3 = load_type(int); + _4 = load_type(never); + _5 = load_type(int); + _0 = call const fn baml.Array.map(copy _1, copy _2) -> [bb1]; } bb1: { @@ -905,66 +874,65 @@ fn user.test_lambda_with_match() -> string { } // lambda[0] -fn .(n: int) -> null { +fn .(x: null) -> null { // Locals: let _0: null // _0 // return - let _1: int // n // param + let _1: null // x // param bb0: { - switch copy _1 [0: bb3, 1: bb2, otherwise: bb1]; + _0 = const 0_i64; + goto -> bb1; } bb1: { - _0 = const "many"; - goto -> bb4; - } - - bb2: { - _0 = const "one"; - goto -> bb4; - } - - bb3: { - _0 = const "zero"; - goto -> bb4; - } - - bb4: { return; } } -fn user.test_literal_return_inference() -> int[] { +fn user.test_compose_inferred() -> int[] { // Locals: let _0: int[] // _0 // return let _1: int[] // items - let _2: (int) -> int throws E - let _3: type + let _2: int[] // step1 + let _3: (int) -> int throws E let _4: type let _5: type + let _6: type + let _7: (int) -> int throws E + let _8: type + let _9: type + let _10: type bb0: { _1 = [const 1_i64, const 2_i64, const 3_i64]: int[]; - _2 = make_closure lambda[0](); - _3 = load_type(int); - _4 = load_type(never); - _5 = load_type(int); - _0 = call const fn baml.Array.map(copy _1, copy _2) -> [bb1]; + _3 = make_closure lambda[0](); + _4 = load_type(int); + _5 = load_type(never); + _6 = load_type(int); + _2 = call const fn baml.Array.map(copy _1, copy _3) -> [bb1]; } bb1: { + _7 = make_closure lambda[1](); + _8 = load_type(int); + _9 = load_type(never); + _10 = load_type(int); + _0 = call const fn baml.Array.map(copy _2, copy _7) -> [bb2]; + } + + bb2: { return; } } // lambda[0] -fn .(x: null) -> null { +fn .(x: null) -> null { // Locals: let _0: null // _0 // return let _1: null // x // param bb0: { - _0 = const 0_i64; + _0 = copy _1 * const 2_i64; goto -> bb1; } @@ -973,45 +941,14 @@ fn .(x: null) -> null { } } -fn user.test_map_multi_statement() -> int[] { - // Locals: - let _0: int[] // _0 // return - let _1: int[] // items - let _2: (int) -> int throws E - let _3: type - let _4: type - let _5: type - - bb0: { - _1 = [const 1_i64, const 2_i64, const 3_i64]: int[]; - _2 = make_closure lambda[0](); - _3 = load_type(int); - _4 = load_type(never); - _5 = load_type(int); - _0 = call const fn baml.Array.map(copy _1, copy _2) -> [bb1]; - } - - bb1: { - return; - } -} - -// lambda[0] -fn .(x: null) -> null { +// lambda[1] +fn .(x: null) -> null { // Locals: let _0: null // _0 // return let _1: null // x // param - let _2: int // doubled - let _3: int // offset - let _4: int - let _5: int bb0: { - _2 = copy _1 * const 2_i64; - _3 = const 100_i64; - _4 = copy _2; - _5 = copy _3; - _0 = copy _4 + copy _5; + _0 = copy _1 + const 1_i64; goto -> bb1; } @@ -1020,72 +957,59 @@ fn .(x: null) -> null { } } -fn user.test_map_optional_inferred() -> int[] { +fn user.test_higher_order_inferred() -> int { // Locals: - let _0: int[] // _0 // return - let _1: (int | null)[] // items - let _2: (int | null) -> int throws E - let _3: type - let _4: type - let _5: type + let _0: int // _0 // return + let _1: (int) -> ((int) -> int throws never) throws never // make_adder + let _2: (int) -> int throws never // add5 + let _3: (int) -> ((int) -> int throws never) throws never + let _4: (int) -> int throws never bb0: { - _1 = [const 1_i64, const null, const 3_i64]: int | null[]; - _2 = make_closure lambda[0](); - _3 = load_type(int); - _4 = load_type(never); - _5 = load_type(int | null); - _0 = call const fn baml.Array.map(copy _1, copy _2) -> [bb1]; + _1 = make_closure lambda[0](); + _3 = copy _1; + _2 = call copy _3(const 5_i64) -> [bb1]; } bb1: { + _4 = copy _2; + _0 = call copy _4(const 37_i64) -> [bb2]; + } + + bb2: { return; } } // lambda[0] -fn .(x: null) -> null { +fn .(n: int) -> null { // Locals: let _0: null // _0 // return - let _1: null // x // param - let _2: bool + let _1: int // n // param [captured] + let _2: (int) -> int throws never // adder bb0: { - _2 = copy _1 == const null; - branch copy _2 -> [bb2, bb1]; + _2 = make_closure lambda[0](copy _1); + _0 = copy _2; + goto -> bb1; } bb1: { - _0 = const 1_i64; - goto -> bb3; - } - - bb2: { - _0 = const 0_i64; - goto -> bb3; - } - - bb3: { return; } } -fn user.test_map_string_to_int() -> int[] { +// lambda[0] +fn ., 1)>(x: int) -> null { // Locals: - let _0: int[] // _0 // return - let _1: string[] // words - let _2: (string) -> int throws E - let _3: type - let _4: type - let _5: type + let _0: null // _0 // return + let _1: int // x // param + let _2: int bb0: { - _1 = [const "hello", const "world"]: string[]; - _2 = make_closure lambda[0](); - _3 = load_type(int); - _4 = load_type(never); - _5 = load_type(string); - _0 = call const fn baml.Array.map(copy _1, copy _2) -> [bb1]; + _2 = copy capture[0]; + _0 = copy _1 + copy _2; + goto -> bb1; } bb1: { @@ -1093,14 +1017,20 @@ fn user.test_map_string_to_int() -> int[] { } } -// lambda[0] -fn .(w: string) -> null { +fn user.test_apply_twice_inferred() -> int { // Locals: - let _0: null // _0 // return - let _1: string // w // param + let _0: int // _0 // return + let _1: (int) -> int throws never // double + let _2: ((int) -> int throws never, int) -> int throws never // apply_twice + let _3: ((int) -> int throws never, int) -> int throws never + let _4: (int) -> int throws never bb0: { - _0 = call const fn baml.String.length(copy _1) -> [bb1]; + _1 = make_closure lambda[0](); + _2 = make_closure lambda[1](); + _3 = copy _2; + _4 = copy _1; + _0 = call copy _3(copy _4, const 3_i64) -> [bb1]; } bb1: { @@ -1108,22 +1038,15 @@ fn .(w: string) -> null { } } -fn user.test_map_type_change_inferred() -> string[] { +// lambda[0] +fn .(x: int) -> null { // Locals: - let _0: string[] // _0 // return - let _1: int[] // nums - let _2: (int) -> string throws E - let _3: type - let _4: type - let _5: type + let _0: null // _0 // return + let _1: int // x // param bb0: { - _1 = [const 1_i64, const 2_i64, const 3_i64]: int[]; - _2 = make_closure lambda[0](); - _3 = load_type(string); - _4 = load_type(never); - _5 = load_type(int); - _0 = call const fn baml.Array.map(copy _1, copy _2) -> [bb1]; + _0 = copy _1 * const 2_i64; + goto -> bb1; } bb1: { @@ -1131,54 +1054,39 @@ fn user.test_map_type_change_inferred() -> string[] { } } -// lambda[0] -fn .(n: null) -> null { +// lambda[1] +fn .(f: (int) -> int throws never, x: int) -> null { // Locals: let _0: null // _0 // return - let _1: null // n // param + let _1: (int) -> int throws never // f // param + let _2: int // x // param + let _3: int bb0: { - switch copy _1 [1: bb3, 2: bb2, otherwise: bb1]; + _3 = call copy _1(copy _2) -> [bb1]; } bb1: { - _0 = const "other"; - goto -> bb4; + _0 = call copy _1(copy _3) -> [bb2]; } bb2: { - _0 = const "two"; - goto -> bb4; - } - - bb3: { - _0 = const "one"; - goto -> bb4; - } - - bb4: { return; } } -fn user.test_map_with_capture() -> int[] { +fn user.test_deep_capture_inferred() -> int { // Locals: - let _0: int[] // _0 // return - let _1: int[] // items - let _2: int // factor [captured] - let _3: (int) -> int throws E - let _4: type - let _5: type - let _6: type + let _0: int // _0 // return + let _1: int // a [captured] + let _2: (int) -> int throws never // f + let _3: (int) -> int throws never bb0: { - _1 = [const 1_i64, const 2_i64, const 3_i64]: int[]; - _2 = const 10_i64; - _3 = make_closure lambda[0](copy _2); - _4 = load_type(int); - _5 = load_type(never); - _6 = load_type(int); - _0 = call const fn baml.Array.map(copy _1, copy _3) -> [bb1]; + _1 = const 1_i64; + _2 = make_closure lambda[0](copy _1); + _3 = copy _2; + _0 = call copy _3(const 10_i64) -> [bb1]; } bb1: { @@ -1187,16 +1095,17 @@ fn user.test_map_with_capture() -> int[] { } // lambda[0] -fn .(x: null) -> null { +fn .(b: int) -> null { // Locals: let _0: null // _0 // return - let _1: null // x // param - let _2: int + let _1: int // b // param [captured] + let _2: (int) -> int throws never // g + let _3: (int) -> int throws never bb0: { - _2 = copy capture[0]; - _0 = copy _1 * copy _2; - goto -> bb1; + _2 = make_closure lambda[0](copy capture[0], copy _1); + _3 = copy _2; + _0 = call copy _3(const 100_i64) -> [bb1]; } bb1: { @@ -1204,26 +1113,21 @@ fn .(x: null) -> null { } } -fn user.test_nested_map() -> int[][] { +// lambda[0] +fn ., 1)>(c: int) -> null { // Locals: - let _0: int[][] // _0 // return - let _1: int[][] // matrix - let _2: int[] - let _3: int[] - let _4: (int[]) -> int[] throws E - let _5: type - let _6: type - let _7: type + let _0: null // _0 // return + let _1: int // c // param + let _2: int + let _3: int + let _4: int bb0: { - _2 = [const 1_i64, const 2_i64]: int[]; - _3 = [const 3_i64, const 4_i64]: int[]; - _1 = [copy _2, copy _3]: int[][]; - _4 = make_closure lambda[0](); - _5 = load_type(int[]); - _6 = load_type(never); - _7 = load_type(int[]); - _0 = call const fn baml.Array.map(copy _1, copy _4) -> [bb1]; + _3 = copy capture[0]; + _4 = copy capture[1]; + _2 = copy _3 + copy _4; + _0 = copy _2 + copy _1; + goto -> bb1; } bb1: { @@ -1231,22 +1135,20 @@ fn user.test_nested_map() -> int[][] { } } -// lambda[0] -fn .(row: int[]) -> null { +fn user.test_two_transforms_inferred() -> int { // Locals: - let _0: null // _0 // return - let _1: int[] // row // param - let _2: (int) -> int throws E - let _3: type - let _4: type - let _5: type + let _0: int // _0 // return + let _1: ((int) -> int throws never, (int) -> int throws never, int) -> int throws never // apply_both + let _2: ((int) -> int throws never, (int) -> int throws never, int) -> int throws never + let _3: (int) -> int throws never + let _4: (int) -> int throws never bb0: { - _2 = make_closure lambda[0](); - _3 = load_type(int); - _4 = load_type(never); - _5 = load_type(int); - _0 = call const fn baml.Array.map(copy _1, copy _2) -> [bb1]; + _1 = make_closure lambda[0](); + _2 = copy _1; + _3 = make_closure lambda[1](); + _4 = make_closure lambda[2](); + _0 = call copy _2(copy _3, copy _4, const 5_i64) -> [bb1]; } bb1: { @@ -1255,31 +1157,36 @@ fn .(row: int[]) -> null { } // lambda[0] -fn ., 1)>(x: null) -> null { +fn .(f: (int) -> int throws never, g: (int) -> int throws never, x: int) -> null { // Locals: let _0: null // _0 // return - let _1: null // x // param + let _1: (int) -> int throws never // f // param + let _2: (int) -> int throws never // g // param + let _3: int // x // param + let _4: int bb0: { - _0 = copy _1 * copy _1; - goto -> bb1; + _4 = call copy _1(copy _3) -> [bb1]; } bb1: { + _0 = call copy _2(copy _4) -> [bb2]; + } + + bb2: { return; } } -fn user.test_optional_return() -> int | null { +// lambda[1] +fn .(x: int) -> null { // Locals: - let _0: int | null // _0 // return - let _1: (int) -> int | null throws never // maybe - let _2: (int) -> int | null throws never + let _0: null // _0 // return + let _1: int // x // param bb0: { - _1 = make_closure lambda[0](); - _2 = copy _1; - _0 = call copy _2(const -1_i64) -> [bb1]; + _0 = copy _1 * const 2_i64; + goto -> bb1; } bb1: { @@ -1287,156 +1194,75 @@ fn user.test_optional_return() -> int | null { } } -// lambda[0] -fn .(x: int) -> null { +// lambda[2] +fn .(x: int) -> null { // Locals: let _0: null // _0 // return let _1: int // x // param - let _2: bool bb0: { - _2 = copy _1 > const 0_i64; - branch copy _2 -> [bb2, bb1]; + _0 = copy _1 + const 10_i64; + goto -> bb1; } bb1: { - _0 = const null; - goto -> bb3; - } - - bb2: { - _0 = copy _1; - goto -> bb3; - } - - bb3: { return; } } -fn user.test_shadowing() -> string { +fn user.test_lambda_in_match_inferred() -> int { // Locals: - let _0: string // _0 // return - let _1: string // x - let _2: int[] // items - let _3: int[] // mapped - let _4: (int) -> int throws E - let _5: type - let _6: type - let _7: type - let _8: int[] - let _9: baml.iter.Iterator - let _10: unknown - let _11: bool - let _12: int - let _13: int // y - let _14: int // i - let _15: bool - let _16: int - let _17: int + let _0: int // _0 // return + let _1: string // op + let _2: (int) -> int throws never // f + let _3: bool + let _4: bool + let _5: (int) -> int throws never bb0: { - _1 = const "999"; - _2 = [const 1_i64, const 2_i64, const 3_i64]: int[]; - _4 = make_closure lambda[0](); - _5 = load_type(int); - _6 = load_type(never); - _7 = load_type(int); - _3 = call const fn baml.Array.map(copy _2, copy _4) -> [bb1]; + _1 = const "double"; + _3 = copy _1 == const "double"; + branch copy _3 -> [bb4, bb1]; } bb1: { - _8 = copy _3; - _9 = virtual_call iter as baml.iter.Iterable(copy _8) -> [bb2]; + _4 = copy _1 == const "negate"; + branch copy _4 -> [bb3, bb2]; } bb2: { - _10 = virtual_call next as baml.iter.Iterator(copy _9) -> [bb3]; - } - - bb3: { - _11 = is_type(copy _10, baml.iter.Done); - branch copy _11 -> [bb7, bb4]; - } - - bb4: { - _12 = copy _10; - fresh_cell(_13); - _13 = copy _12; - _14 = const 0_i64; + _2 = make_closure lambda[2](); goto -> bb5; } - bb5: { - _16 = copy _14; - _17 = copy _13; - _15 = copy _16 < copy _17; - branch copy _15 -> [bb6, bb2]; - } - - bb6: { - _1 = copy _1 + const "1"; - _14 = copy _14 + const 1_i64; + bb3: { + _2 = make_closure lambda[1](); goto -> bb5; } - bb7: { - _0 = copy _1; - goto -> bb8; - } - - bb8: { - return; - } -} - -// lambda[0] -fn .(x: null) -> null { - // Locals: - let _0: null // _0 // return - let _1: null // x // param - - bb0: { - _0 = copy _1 + const 1_i64; - goto -> bb1; - } - - bb1: { - return; - } -} - -fn user.test_shadowing_inferred() -> int[] { - // Locals: - let _0: int[] // _0 // return - let _1: int[] // items - let _2: (int) -> int throws E - let _3: type - let _4: type - let _5: type - - bb0: { - _1 = [const 1_i64, const 2_i64, const 3_i64]: int[]; + bb4: { _2 = make_closure lambda[0](); - _3 = load_type(int); - _4 = load_type(never); - _5 = load_type(int); - _0 = call const fn baml.Array.map(copy _1, copy _2) -> [bb1]; + goto -> bb5; } - bb1: { + bb5: { + _5 = copy _2; + _0 = call copy _5(const 21_i64) -> [bb6]; + } + + bb6: { return; } } // lambda[0] -fn .(x: null) -> null { +fn .(x: int) -> null { // Locals: let _0: null // _0 // return - let _1: null // x // param + let _1: int // x // param bb0: { - _0 = copy _1 + const 1_i64; + _0 = copy _1 * const 2_i64; goto -> bb1; } @@ -1445,20 +1271,15 @@ fn .(x: null) -> null { } } -fn user.test_two_transforms_inferred() -> int { +// lambda[1] +fn .(x: int) -> null { // Locals: - let _0: int // _0 // return - let _1: ((int) -> int throws never, (int) -> int throws never, int) -> int throws never // apply_both - let _2: ((int) -> int throws never, (int) -> int throws never, int) -> int throws never - let _3: (int) -> int throws never - let _4: (int) -> int throws never + let _0: null // _0 // return + let _1: int // x // param bb0: { - _1 = make_closure lambda[0](); - _2 = copy _1; - _3 = make_closure lambda[1](); - _4 = make_closure lambda[2](); - _0 = call copy _2(copy _3, copy _4, const 5_i64) -> [bb1]; + _0 = const 0_i64 - copy _1; + goto -> bb1; } bb1: { @@ -1466,37 +1287,40 @@ fn user.test_two_transforms_inferred() -> int { } } -// lambda[0] -fn .(f: (int) -> int throws never, g: (int) -> int throws never, x: int) -> null { +// lambda[2] +fn .(x: int) -> null { // Locals: let _0: null // _0 // return - let _1: (int) -> int throws never // f // param - let _2: (int) -> int throws never // g // param - let _3: int // x // param - let _4: int + let _1: int // x // param bb0: { - _4 = call copy _1(copy _3) -> [bb1]; + _0 = copy _1; + goto -> bb1; } bb1: { - _0 = call copy _2(copy _4) -> [bb2]; - } - - bb2: { return; } } -// lambda[1] -fn .(x: int) -> null { +fn user.test_capture_in_map_inferred() -> int[] { // Locals: - let _0: null // _0 // return - let _1: int // x // param + let _0: int[] // _0 // return + let _1: int[] // items + let _2: int // factor [captured] + let _3: (int) -> int throws E + let _4: type + let _5: type + let _6: type bb0: { - _0 = copy _1 * const 2_i64; - goto -> bb1; + _1 = [const 1_i64, const 2_i64, const 3_i64]: int[]; + _2 = const 10_i64; + _3 = make_closure lambda[0](copy _2); + _4 = load_type(int); + _5 = load_type(never); + _6 = load_type(int); + _0 = call const fn baml.Array.map(copy _1, copy _3) -> [bb1]; } bb1: { @@ -1504,14 +1328,16 @@ fn .(x: int) -> null { } } -// lambda[2] -fn .(x: int) -> null { +// lambda[0] +fn .(x: null) -> null { // Locals: let _0: null // _0 // return - let _1: int // x // param + let _1: null // x // param + let _2: int bb0: { - _0 = copy _1 + const 10_i64; + _2 = copy capture[0]; + _0 = copy _1 * copy _2; goto -> bb1; } @@ -1638,3 +1464,176 @@ fn ., 1)>() -> null { return; } } + +fn user.test_capture_lambda_inferred() -> int { + // Locals: + let _0: int // _0 // return + let _1: (int, int) -> int throws never // multiply [captured] + let _2: (int) -> int throws never // double + let _3: (int) -> int throws never + + bb0: { + _1 = make_closure lambda[0](); + _2 = make_closure lambda[1](copy _1); + _3 = copy _2; + _0 = call copy _3(const 21_i64) -> [bb1]; + } + + bb1: { + return; + } +} + +// lambda[0] +fn .(a: int, b: int) -> null { + // Locals: + let _0: null // _0 // return + let _1: int // a // param + let _2: int // b // param + + bb0: { + _0 = copy _1 * copy _2; + goto -> bb1; + } + + bb1: { + return; + } +} + +// lambda[1] +fn .(x: int) -> null { + // Locals: + let _0: null // _0 // return + let _1: int // x // param + let _2: (int, int) -> int throws never + + bb0: { + _2 = copy capture[0]; + _0 = call copy _2(copy _1, const 2_i64) -> [bb1]; + } + + bb1: { + return; + } +} + +fn user.test_map_optional_inferred() -> int[] { + // Locals: + let _0: int[] // _0 // return + let _1: (int | null)[] // items + let _2: (int | null) -> int throws E + let _3: type + let _4: type + let _5: type + + bb0: { + _1 = [const 1_i64, const null, const 3_i64]: int | null[]; + _2 = make_closure lambda[0](); + _3 = load_type(int); + _4 = load_type(never); + _5 = load_type(int | null); + _0 = call const fn baml.Array.map(copy _1, copy _2) -> [bb1]; + } + + bb1: { + return; + } +} + +// lambda[0] +fn .(x: null) -> null { + // Locals: + let _0: null // _0 // return + let _1: null // x // param + let _2: bool + + bb0: { + _2 = copy _1 == const null; + branch copy _2 -> [bb2, bb1]; + } + + bb1: { + _0 = const 1_i64; + goto -> bb3; + } + + bb2: { + _0 = const 0_i64; + goto -> bb3; + } + + bb3: { + return; + } +} + +fn user.test_shadowing_inferred() -> int[] { + // Locals: + let _0: int[] // _0 // return + let _1: int[] // items + let _2: (int) -> int throws E + let _3: type + let _4: type + let _5: type + + bb0: { + _1 = [const 1_i64, const 2_i64, const 3_i64]: int[]; + _2 = make_closure lambda[0](); + _3 = load_type(int); + _4 = load_type(never); + _5 = load_type(int); + _0 = call const fn baml.Array.map(copy _1, copy _2) -> [bb1]; + } + + bb1: { + return; + } +} + +// lambda[0] +fn .(x: null) -> null { + // Locals: + let _0: null // _0 // return + let _1: null // x // param + + bb0: { + _0 = copy _1 + const 1_i64; + goto -> bb1; + } + + bb1: { + return; + } +} + +fn user.test_iife_inferred() -> int { + // Locals: + let _0: int // _0 // return + let _1: (int) -> int throws never + + bb0: { + _1 = make_closure lambda[0](); + _0 = call copy _1(const 7_i64) -> [bb1]; + } + + bb1: { + return; + } +} + +// lambda[0] +fn .(x: int) -> null { + // Locals: + let _0: null // _0 // return + let _1: int // x // param + + bb0: { + _0 = copy _1 * copy _1; + goto -> bb1; + } + + bb1: { + return; + } +} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/lambda_basic/baml_tests__compiles__lambda_basic__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/lambda_basic/baml_tests__compiles__lambda_basic__04_5_mir.snap index 0febfc22df9..6c777d51f0f 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/lambda_basic/baml_tests__compiles__lambda_basic__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/lambda_basic/baml_tests__compiles__lambda_basic__04_5_mir.snap @@ -35,18 +35,16 @@ fn .(x: int) -> null { } } -fn user.test_capture() -> int { +fn user.test_inferred_return() -> int { // Locals: let _0: int // _0 // return - let _1: int // offset [captured] - let _2: (int) -> int throws never // add_offset - let _3: (int) -> int throws never + let _1: (int) -> int throws never // double + let _2: (int) -> int throws never bb0: { - _1 = const 10_i64; - _2 = make_closure lambda[0](copy _1); - _3 = copy _2; - _0 = call copy _3(const 32_i64) -> [bb1]; + _1 = make_closure lambda[0](); + _2 = copy _1; + _0 = call copy _2(const 21_i64) -> [bb1]; } bb1: { @@ -55,15 +53,13 @@ fn user.test_capture() -> int { } // lambda[0] -fn .(x: int) -> null { +fn .(x: int) -> null { // Locals: let _0: null // _0 // return let _1: int // x // param - let _2: int bb0: { - _2 = copy capture[0]; - _0 = copy _1 + copy _2; + _0 = copy _1 * const 2_i64; goto -> bb1; } @@ -72,16 +68,16 @@ fn .(x: int) -> null { } } -fn user.test_inferred_return() -> int { +fn user.test_zero_param() -> int { // Locals: let _0: int // _0 // return - let _1: (int) -> int throws never // double - let _2: (int) -> int throws never + let _1: () -> int throws never // constant + let _2: () -> int throws never bb0: { _1 = make_closure lambda[0](); _2 = copy _1; - _0 = call copy _2(const 21_i64) -> [bb1]; + _0 = call copy _2() -> [bb1]; } bb1: { @@ -90,13 +86,12 @@ fn user.test_inferred_return() -> int { } // lambda[0] -fn .(x: int) -> null { +fn .() -> null { // Locals: let _0: null // _0 // return - let _1: int // x // param bb0: { - _0 = copy _1 * const 2_i64; + _0 = const 42_i64; goto -> bb1; } @@ -144,16 +139,16 @@ fn .(x: null) -> null { } } -fn user.test_multi_param() -> int { +fn user.test_throws() -> int { // Locals: let _0: int // _0 // return - let _1: (int, int) -> int throws never // add - let _2: (int, int) -> int throws never + let _1: (int) -> int throws string // risky + let _2: (int) -> int throws string bb0: { _1 = make_closure lambda[0](); _2 = copy _1; - _0 = call copy _2(const 20_i64, const 22_i64) -> [bb1]; + _0 = call copy _2(const 42_i64) -> [bb1]; } bb1: { @@ -162,51 +157,43 @@ fn user.test_multi_param() -> int { } // lambda[0] -fn .(a: int, b: int) -> null { +fn .(x: int) -> null { // Locals: let _0: null // _0 // return - let _1: int // a // param - let _2: int // b // param + let _1: int // x // param + let _2: bool bb0: { - _0 = copy _1 + copy _2; - goto -> bb1; + _2 = copy _1 < const 0_i64; + branch copy _2 -> [bb3, bb1]; } bb1: { - return; + _0 = copy _1; + goto -> bb2; } -} -fn user.test_nested() -> int { - // Locals: - let _0: int // _0 // return - let _1: (int) -> int throws never // outer - let _2: (int) -> int throws never - - bb0: { - _1 = make_closure lambda[0](); - _2 = copy _1; - _0 = call copy _2(const 41_i64) -> [bb1]; + bb2: { + return; } - bb1: { - return; + bb3: { + throw const "negative"; } } -// lambda[0] -fn .(x: int) -> null { +fn user.test_capture() -> int { // Locals: - let _0: null // _0 // return - let _1: int // x // param [captured] - let _2: (int) -> int throws never // inner + let _0: int // _0 // return + let _1: int // offset [captured] + let _2: (int) -> int throws never // add_offset let _3: (int) -> int throws never bb0: { + _1 = const 10_i64; _2 = make_closure lambda[0](copy _1); _3 = copy _2; - _0 = call copy _3(const 1_i64) -> [bb1]; + _0 = call copy _3(const 32_i64) -> [bb1]; } bb1: { @@ -215,15 +202,15 @@ fn .(x: int) -> null { } // lambda[0] -fn ., 1)>(y: int) -> null { +fn .(x: int) -> null { // Locals: let _0: null // _0 // return - let _1: int // y // param + let _1: int // x // param let _2: int bb0: { _2 = copy capture[0]; - _0 = copy _2 + copy _1; + _0 = copy _1 + copy _2; goto -> bb1; } @@ -232,16 +219,16 @@ fn ., 1)>(y: int) -> null { } } -fn user.test_throws() -> int { +fn user.test_nested() -> int { // Locals: let _0: int // _0 // return - let _1: (int) -> int throws string // risky - let _2: (int) -> int throws string + let _1: (int) -> int throws never // outer + let _2: (int) -> int throws never bb0: { _1 = make_closure lambda[0](); _2 = copy _1; - _0 = call copy _2(const 42_i64) -> [bb1]; + _0 = call copy _2(const 41_i64) -> [bb1]; } bb1: { @@ -250,41 +237,52 @@ fn user.test_throws() -> int { } // lambda[0] -fn .(x: int) -> null { +fn .(x: int) -> null { // Locals: let _0: null // _0 // return - let _1: int // x // param - let _2: bool + let _1: int // x // param [captured] + let _2: (int) -> int throws never // inner + let _3: (int) -> int throws never bb0: { - _2 = copy _1 < const 0_i64; - branch copy _2 -> [bb3, bb1]; + _2 = make_closure lambda[0](copy _1); + _3 = copy _2; + _0 = call copy _3(const 1_i64) -> [bb1]; } bb1: { - _0 = copy _1; - goto -> bb2; + return; } +} - bb2: { - return; +// lambda[0] +fn ., 1)>(y: int) -> null { + // Locals: + let _0: null // _0 // return + let _1: int // y // param + let _2: int + + bb0: { + _2 = copy capture[0]; + _0 = copy _2 + copy _1; + goto -> bb1; } - bb3: { - throw const "negative"; + bb1: { + return; } } -fn user.test_zero_param() -> int { +fn user.test_multi_param() -> int { // Locals: let _0: int // _0 // return - let _1: () -> int throws never // constant - let _2: () -> int throws never + let _1: (int, int) -> int throws never // add + let _2: (int, int) -> int throws never bb0: { _1 = make_closure lambda[0](); _2 = copy _1; - _0 = call copy _2() -> [bb1]; + _0 = call copy _2(const 20_i64, const 22_i64) -> [bb1]; } bb1: { @@ -293,12 +291,14 @@ fn user.test_zero_param() -> int { } // lambda[0] -fn .() -> null { +fn .(a: int, b: int) -> null { // Locals: let _0: null // _0 // return + let _1: int // a // param + let _2: int // b // param bb0: { - _0 = const 42_i64; + _0 = copy _1 + copy _2; goto -> bb1; } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/lambda_fat_arrow/baml_tests__compiles__lambda_fat_arrow__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/lambda_fat_arrow/baml_tests__compiles__lambda_fat_arrow__04_5_mir.snap index 93e08e29b7f..4fda306451f 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/lambda_fat_arrow/baml_tests__compiles__lambda_fat_arrow__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/lambda_fat_arrow/baml_tests__compiles__lambda_fat_arrow__04_5_mir.snap @@ -35,41 +35,30 @@ fn .(x: int) -> null { } } -fn user.test_in_match(x: int) -> int { +fn user.test_zero_param() -> int { // Locals: let _0: int // _0 // return - let _1: int // x // param - let _2: (int) -> int throws never // inc - let _3: (int) -> int throws never + let _1: () -> int throws never // constant + let _2: () -> int throws never bb0: { - switch copy _1 [0: bb2, otherwise: bb1]; + _1 = make_closure lambda[0](); + _2 = copy _1; + _0 = call copy _2() -> [bb1]; } bb1: { - _0 = const 0_i64; - goto -> bb3; - } - - bb2: { - _2 = make_closure lambda[0](); - _3 = copy _2; - _0 = call copy _3(const 10_i64) -> [bb3]; - } - - bb3: { return; } } // lambda[0] -fn .(y: int) -> null { +fn .() -> null { // Locals: let _0: null // _0 // return - let _1: int // y // param bb0: { - _0 = copy _1 + const 1_i64; + _0 = const 42_i64; goto -> bb1; } @@ -111,46 +100,32 @@ fn .(x: int) -> null { } } -fn user.test_mixed() -> int { +fn user.test_multi_param() -> int { // Locals: let _0: int // _0 // return - let _1: (int) -> int throws never // a - let _2: (int) -> int throws never // b - let _3: int - let _4: (int) -> int throws never - let _5: int - let _6: (int) -> int throws never + let _1: (int, int) -> int throws never // add + let _2: (int, int) -> int throws never bb0: { _1 = make_closure lambda[0](); - _2 = make_closure lambda[1](); - _4 = copy _1; - _3 = call copy _4(const 0_i64) -> [bb1]; + _2 = copy _1; + _0 = call copy _2(const 20_i64, const 22_i64) -> [bb1]; } bb1: { - _6 = copy _2; - _5 = call copy _6(const 0_i64) -> [bb2]; - } - - bb2: { - _0 = copy _3 + copy _5; - goto -> bb3; - } - - bb3: { return; } } // lambda[0] -fn .(x: int) -> null { +fn .(a: int, b: int) -> null { // Locals: let _0: null // _0 // return - let _1: int // x // param + let _1: int // a // param + let _2: int // b // param bb0: { - _0 = copy _1 + const 1_i64; + _0 = copy _1 + copy _2; goto -> bb1; } @@ -159,48 +134,41 @@ fn .(x: int) -> null { } } -// lambda[1] -fn .(x: int) -> null { +fn user.test_in_match(x: int) -> int { // Locals: - let _0: null // _0 // return + let _0: int // _0 // return let _1: int // x // param + let _2: (int) -> int throws never // inc + let _3: (int) -> int throws never bb0: { - _0 = copy _1 + const 2_i64; - goto -> bb1; + switch copy _1 [0: bb2, otherwise: bb1]; } bb1: { - return; + _0 = const 0_i64; + goto -> bb3; } -} -fn user.test_multi_param() -> int { - // Locals: - let _0: int // _0 // return - let _1: (int, int) -> int throws never // add - let _2: (int, int) -> int throws never - - bb0: { - _1 = make_closure lambda[0](); - _2 = copy _1; - _0 = call copy _2(const 20_i64, const 22_i64) -> [bb1]; + bb2: { + _2 = make_closure lambda[0](); + _3 = copy _2; + _0 = call copy _3(const 10_i64) -> [bb3]; } - bb1: { + bb3: { return; } } // lambda[0] -fn .(a: int, b: int) -> null { +fn .(y: int) -> null { // Locals: let _0: null // _0 // return - let _1: int // a // param - let _2: int // b // param + let _1: int // y // param bb0: { - _0 = copy _1 + copy _2; + _0 = copy _1 + const 1_i64; goto -> bb1; } @@ -209,30 +177,62 @@ fn .(a: int, b: int) -> null { } } -fn user.test_zero_param() -> int { +fn user.test_mixed() -> int { // Locals: let _0: int // _0 // return - let _1: () -> int throws never // constant - let _2: () -> int throws never + let _1: (int) -> int throws never // a + let _2: (int) -> int throws never // b + let _3: int + let _4: (int) -> int throws never + let _5: int + let _6: (int) -> int throws never bb0: { _1 = make_closure lambda[0](); - _2 = copy _1; - _0 = call copy _2() -> [bb1]; + _2 = make_closure lambda[1](); + _4 = copy _1; + _3 = call copy _4(const 0_i64) -> [bb1]; } bb1: { + _6 = copy _2; + _5 = call copy _6(const 0_i64) -> [bb2]; + } + + bb2: { + _0 = copy _3 + copy _5; + goto -> bb3; + } + + bb3: { return; } } // lambda[0] -fn .() -> null { +fn .(x: int) -> null { // Locals: let _0: null // _0 // return + let _1: int // x // param bb0: { - _0 = const 42_i64; + _0 = copy _1 + const 1_i64; + goto -> bb1; + } + + bb1: { + return; + } +} + +// lambda[1] +fn .(x: int) -> null { + // Locals: + let _0: null // _0 // return + let _1: int // x // param + + bb0: { + _0 = copy _1 + const 2_i64; goto -> bb1; } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/lambda_field_access/baml_tests__compiles__lambda_field_access__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/lambda_field_access/baml_tests__compiles__lambda_field_access__04_5_mir.snap index 78c94d5e9a3..77df68ef905 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/lambda_field_access/baml_tests__compiles__lambda_field_access__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/lambda_field_access/baml_tests__compiles__lambda_field_access__04_5_mir.snap @@ -68,34 +68,39 @@ fn .() -> null { } } -fn user.test_lambda_param_and_capture(obj: Outer) -> int { +fn user.test_no_leak_after_lambda(obj: Outer) -> string { // Locals: - let _0: int // _0 // return + let _0: string // _0 // return let _1: Outer // obj // param [captured] - let _2: (int) -> int throws never // add_to_value - let _3: (int) -> int throws never + let _2: () -> int throws never // get_value + let _3: int // v + let _4: () -> int throws never + let _5: Outer // result bb0: { _2 = make_closure lambda[0](copy _1); - _3 = copy _2; - _0 = call copy _3(const 10_i64) -> [bb1]; + _4 = copy _2; + _3 = call copy _4() -> [bb1]; } bb1: { + _5 = copy _1; + _0 = copy _5.1; + goto -> bb2; + } + + bb2: { return; } } // lambda[0] -fn .(x: int) -> null { +fn .() -> null { // Locals: let _0: null // _0 // return - let _1: int // x // param - let _2: int bb0: { - _2 = copy capture[0].0.0; - _0 = copy _1 + copy _2; + _0 = copy capture[0].0.0; goto -> bb1; } @@ -155,25 +160,26 @@ fn ., 1)>() -> null { } } -fn user.test_no_leak_after_lambda(obj: Outer) -> string { +fn user.test_sequential_lambdas(obj: Outer) -> int { // Locals: - let _0: string // _0 // return + let _0: int // _0 // return let _1: Outer // obj // param [captured] - let _2: () -> int throws never // get_value - let _3: int // v - let _4: () -> int throws never - let _5: Outer // result + let _2: () -> string throws never // get_name + let _3: () -> int throws never // get_value + let _4: string // n + let _5: () -> string throws never + let _6: () -> int throws never bb0: { _2 = make_closure lambda[0](copy _1); - _4 = copy _2; - _3 = call copy _4() -> [bb1]; + _3 = make_closure lambda[1](copy _1); + _5 = copy _2; + _4 = call copy _5() -> [bb1]; } bb1: { - _5 = copy _1; - _0 = copy _5.1; - goto -> bb2; + _6 = copy _3; + _0 = call copy _6() -> [bb2]; } bb2: { @@ -182,12 +188,12 @@ fn user.test_no_leak_after_lambda(obj: Outer) -> string { } // lambda[0] -fn .() -> null { +fn .() -> null { // Locals: let _0: null // _0 // return bb0: { - _0 = copy capture[0].0.0; + _0 = copy capture[0].1; goto -> bb1; } @@ -196,41 +202,32 @@ fn .() -> null { } } -fn user.test_sequential_lambdas(obj: Outer) -> int { +// lambda[1] +fn .() -> null { // Locals: - let _0: int // _0 // return - let _1: Outer // obj // param [captured] - let _2: () -> string throws never // get_name - let _3: () -> int throws never // get_value - let _4: string // n - let _5: () -> string throws never - let _6: () -> int throws never + let _0: null // _0 // return bb0: { - _2 = make_closure lambda[0](copy _1); - _3 = make_closure lambda[1](copy _1); - _5 = copy _2; - _4 = call copy _5() -> [bb1]; + _0 = copy capture[0].0.0; + goto -> bb1; } bb1: { - _6 = copy _3; - _0 = call copy _6() -> [bb2]; - } - - bb2: { return; } } -// lambda[0] -fn .() -> null { +fn user.test_lambda_param_and_capture(obj: Outer) -> int { // Locals: - let _0: null // _0 // return + let _0: int // _0 // return + let _1: Outer // obj // param [captured] + let _2: (int) -> int throws never // add_to_value + let _3: (int) -> int throws never bb0: { - _0 = copy capture[0].1; - goto -> bb1; + _2 = make_closure lambda[0](copy _1); + _3 = copy _2; + _0 = call copy _3(const 10_i64) -> [bb1]; } bb1: { @@ -238,13 +235,16 @@ fn .() -> null { } } -// lambda[1] -fn .() -> null { +// lambda[0] +fn .(x: int) -> null { // Locals: let _0: null // _0 // return + let _1: int // x // param + let _2: int bb0: { - _0 = copy capture[0].0.0; + _2 = copy capture[0].0.0; + _0 = copy _1 + copy _2; goto -> bb1; } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/lexical_scoping/baml_tests__compiles__lexical_scoping__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/lexical_scoping/baml_tests__compiles__lexical_scoping__04_5_mir.snap index d7c2a5dbf76..a9482b801c5 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/lexical_scoping/baml_tests__compiles__lexical_scoping__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/lexical_scoping/baml_tests__compiles__lexical_scoping__04_5_mir.snap @@ -30,51 +30,51 @@ fn user.branch_locals(b: bool) -> int { } } -fn user.capture_before_after_shadow() -> int { +fn user.same_scope_shadow() -> int { // Locals: let _0: int // _0 // return - let _1: int // x [captured] - let _2: () -> int throws never // g - let _3: int // x [captured] - let _4: () -> int throws never // f - let _5: int - let _6: int - let _7: () -> int throws never - let _8: int - let _9: () -> int throws never + let _1: int // x bb0: { - _1 = const 1_i64; - _2 = make_closure lambda[0](copy _1); - _3 = const 2_i64; - _4 = make_closure lambda[1](copy _3); - _7 = copy _2; - _6 = call copy _7() -> [bb1]; + _1 = const 2_i64; + _0 = copy _1; + goto -> bb1; } bb1: { - _5 = copy _6 * const 10_i64; - _9 = copy _4; - _8 = call copy _9() -> [bb2]; + return; } +} - bb2: { - _0 = copy _5 + copy _8; - goto -> bb3; +fn user.initializer_uses_previous() -> int { + // Locals: + let _0: int // _0 // return + let _1: int // x + let _2: int // x + let _3: int + + bb0: { + _1 = const 1_i64; + _3 = copy _1; + _2 = copy _3 + const 1_i64; + _0 = copy _2; + goto -> bb1; } - bb3: { + bb1: { return; } } -// lambda[0] -fn .() -> null { +fn user.shadow_param(x: int) -> int { // Locals: - let _0: null // _0 // return + let _0: int // _0 // return + let _1: int // x // param + let _2: int // x bb0: { - _0 = copy capture[0]; + _2 = copy _1 + const 1_i64; + _0 = copy _2; goto -> bb1; } @@ -83,13 +83,14 @@ fn .() -> null { } } -// lambda[1] -fn .() -> null { +fn user.outer_restored() -> int { // Locals: - let _0: null // _0 // return + let _0: int // _0 // return + let _1: int // x bb0: { - _0 = copy capture[0]; + _1 = const 1_i64; + _0 = copy _1; goto -> bb1; } @@ -157,18 +158,18 @@ fn user.for_loop_restores_outer() -> int { } } -fn user.initializer_uses_previous() -> int { +fn user.nested_outer_restored() -> int { // Locals: let _0: int // _0 // return let _1: int // x let _2: int // x - let _3: int + let _3: int // x bb0: { _1 = const 1_i64; - _3 = copy _1; - _2 = copy _3 + const 1_i64; - _0 = copy _2; + _2 = const 2_i64; + _3 = const 3_i64; + _0 = copy _1; goto -> bb1; } @@ -177,45 +178,46 @@ fn user.initializer_uses_previous() -> int { } } -fn user.nested_lambda_capture() -> int { +fn user.capture_before_after_shadow() -> int { // Locals: let _0: int // _0 // return let _1: int // x [captured] - let _2: () -> int throws never // outer - let _3: () -> int throws never + let _2: () -> int throws never // g + let _3: int // x [captured] + let _4: () -> int throws never // f + let _5: int + let _6: int + let _7: () -> int throws never + let _8: int + let _9: () -> int throws never bb0: { - _1 = const 7_i64; + _1 = const 1_i64; _2 = make_closure lambda[0](copy _1); - _3 = copy _2; - _0 = call copy _3() -> [bb1]; + _3 = const 2_i64; + _4 = make_closure lambda[1](copy _3); + _7 = copy _2; + _6 = call copy _7() -> [bb1]; } bb1: { - return; + _5 = copy _6 * const 10_i64; + _9 = copy _4; + _8 = call copy _9() -> [bb2]; } -} - -// lambda[0] -fn .() -> null { - // Locals: - let _0: null // _0 // return - let _1: () -> int throws never // inner - let _2: () -> int throws never - bb0: { - _1 = make_closure lambda[0](copy capture[0]); - _2 = copy _1; - _0 = call copy _2() -> [bb1]; + bb2: { + _0 = copy _5 + copy _8; + goto -> bb3; } - bb1: { + bb3: { return; } } // lambda[0] -fn ., 1)>() -> null { +fn .() -> null { // Locals: let _0: null // _0 // return @@ -229,18 +231,13 @@ fn ., 1)>() -> null { } } -fn user.nested_outer_restored() -> int { +// lambda[1] +fn .() -> null { // Locals: - let _0: int // _0 // return - let _1: int // x - let _2: int // x - let _3: int // x + let _0: null // _0 // return bb0: { - _1 = const 1_i64; - _2 = const 2_i64; - _3 = const 3_i64; - _0 = copy _1; + _0 = copy capture[0]; goto -> bb1; } @@ -249,15 +246,18 @@ fn user.nested_outer_restored() -> int { } } -fn user.outer_restored() -> int { +fn user.nested_lambda_capture() -> int { // Locals: let _0: int // _0 // return - let _1: int // x + let _1: int // x [captured] + let _2: () -> int throws never // outer + let _3: () -> int throws never bb0: { - _1 = const 1_i64; - _0 = copy _1; - goto -> bb1; + _1 = const 7_i64; + _2 = make_closure lambda[0](copy _1); + _3 = copy _2; + _0 = call copy _3() -> [bb1]; } bb1: { @@ -265,15 +265,17 @@ fn user.outer_restored() -> int { } } -fn user.same_scope_shadow() -> int { +// lambda[0] +fn .() -> null { // Locals: - let _0: int // _0 // return - let _1: int // x + let _0: null // _0 // return + let _1: () -> int throws never // inner + let _2: () -> int throws never bb0: { - _1 = const 2_i64; - _0 = copy _1; - goto -> bb1; + _1 = make_closure lambda[0](copy capture[0]); + _2 = copy _1; + _0 = call copy _2() -> [bb1]; } bb1: { @@ -281,15 +283,13 @@ fn user.same_scope_shadow() -> int { } } -fn user.shadow_param(x: int) -> int { +// lambda[0] +fn ., 1)>() -> null { // Locals: - let _0: int // _0 // return - let _1: int // x // param - let _2: int // x + let _0: null // _0 // return bb0: { - _2 = copy _1 + const 1_i64; - _0 = copy _2; + _0 = copy capture[0]; goto -> bb1; } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/literal_union_arithmetic/baml_tests__compiles__literal_union_arithmetic__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/literal_union_arithmetic/baml_tests__compiles__literal_union_arithmetic__04_5_mir.snap index 9bb1ac5da13..609bf5371fb 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/literal_union_arithmetic/baml_tests__compiles__literal_union_arithmetic__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/literal_union_arithmetic/baml_tests__compiles__literal_union_arithmetic__04_5_mir.snap @@ -1,8 +1,71 @@ --- source: crates/baml_tests/src/generated_tests.rs -assertion_line: 18643 --- === MIR2 === +fn user.ifElseAdd() -> int { + // Locals: + let _0: int // _0 // return + let _1: 2 | 3 + + bb0: { + branch const true -> [bb2, bb1]; + } + + bb1: { + _1 = const 3_i64; + goto -> bb3; + } + + bb2: { + _1 = const 2_i64; + goto -> bb3; + } + + bb3: { + _0 = const 1_i64 + copy _1; + goto -> bb4; + } + + bb4: { + return; + } +} + +fn user.matchAdd(x: int) -> int { + // Locals: + let _0: int // _0 // return + let _1: int // x // param + let _2: 0 | 10 | 20 + + bb0: { + switch copy _1 [1: bb3, 2: bb2, otherwise: bb1]; + } + + bb1: { + _2 = const 0_i64; + goto -> bb4; + } + + bb2: { + _2 = const 20_i64; + goto -> bb4; + } + + bb3: { + _2 = const 10_i64; + goto -> bb4; + } + + bb4: { + _0 = copy _2 + const 1_i64; + goto -> bb5; + } + + bb5: { + return; + } +} + fn user.bothSidesUnion() -> int { // Locals: let _0: int // _0 // return @@ -47,10 +110,10 @@ fn user.bothSidesUnion() -> int { } } -fn user.ifElseAdd() -> int { +fn user.subtractUnion() -> int { // Locals: let _0: int // _0 // return - let _1: 2 | 3 + let _1: 3 | 7 bb0: { branch const true -> [bb2, bb1]; @@ -62,12 +125,12 @@ fn user.ifElseAdd() -> int { } bb2: { - _1 = const 2_i64; + _1 = const 7_i64; goto -> bb3; } bb3: { - _0 = const 1_i64 + copy _1; + _0 = const 100_i64 - copy _1; goto -> bb4; } @@ -135,67 +198,3 @@ fn user.loopMatchAccum() -> int { goto -> bb1; } } - -fn user.matchAdd(x: int) -> int { - // Locals: - let _0: int // _0 // return - let _1: int // x // param - let _2: 0 | 10 | 20 - - bb0: { - switch copy _1 [1: bb3, 2: bb2, otherwise: bb1]; - } - - bb1: { - _2 = const 0_i64; - goto -> bb4; - } - - bb2: { - _2 = const 20_i64; - goto -> bb4; - } - - bb3: { - _2 = const 10_i64; - goto -> bb4; - } - - bb4: { - _0 = copy _2 + const 1_i64; - goto -> bb5; - } - - bb5: { - return; - } -} - -fn user.subtractUnion() -> int { - // Locals: - let _0: int // _0 // return - let _1: 3 | 7 - - bb0: { - branch const true -> [bb2, bb1]; - } - - bb1: { - _1 = const 3_i64; - goto -> bb3; - } - - bb2: { - _1 = const 7_i64; - goto -> bb3; - } - - bb3: { - _0 = const 100_i64 - copy _1; - goto -> bb4; - } - - bb4: { - return; - } -} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/literal_union_widening/baml_tests__compiles__literal_union_widening__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/literal_union_widening/baml_tests__compiles__literal_union_widening__04_5_mir.snap index 3bfd51d2841..109196c6548 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/literal_union_widening/baml_tests__compiles__literal_union_widening__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/literal_union_widening/baml_tests__compiles__literal_union_widening__04_5_mir.snap @@ -2,22 +2,6 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === -fn user.annotatedLiteralUnion() -> int { - // Locals: - let _0: int // _0 // return - let _1: 1 | 2 // x - - bb0: { - _1 = const 1_i64; - _0 = copy _1; - goto -> bb1; - } - - bb1: { - return; - } -} - fn user.arrayOfInts() -> int[] { // Locals: let _0: int[] // _0 // return @@ -69,3 +53,19 @@ fn user.nestedArray() -> int[][] { return; } } + +fn user.annotatedLiteralUnion() -> int { + // Locals: + let _0: int // _0 // return + let _1: 1 | 2 // x + + bb0: { + _1 = const 1_i64; + _0 = copy _1; + goto -> bb1; + } + + bb1: { + return; + } +} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/llm_image_outputs/baml_tests__compiles__llm_image_outputs__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/llm_image_outputs/baml_tests__compiles__llm_image_outputs__04_5_mir.snap index b5d738f2c90..dac18d2821c 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/llm_image_outputs/baml_tests__compiles__llm_image_outputs__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/llm_image_outputs/baml_tests__compiles__llm_image_outputs__04_5_mir.snap @@ -2,6 +2,38 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === +fn user.OpenAIImageResponses$new(lenient: bool) -> null { + // Locals: + let _0: null // _0 // return + let _1: bool // lenient // param + let _2: baml.llm.PrimitiveClientOptions + let _3: string + let _4: map + let _5: map + let _6: map + let _7: map[] + let _8: map + + bb0: { + _3 = call const fn baml.env.get_or_panic_lenient(const "OPENAI_API_KEY", copy _1) -> [bb1]; + } + + bb1: { + _4 = { }: map; + _5 = { }: map; + _8 = { const "type": const "image_generation", const "size": const "1024x1024", const "quality": const "low" }: map; + _7 = [copy _8]: map[]; + _6 = { const "tools": copy _7 }: map; + _2 = baml.llm.PrimitiveClientOptions { const "gpt-4.1", const null, const null, const null, const null, const null, const null, const null, const null, copy _3, const null, const null, copy _4, copy _5, copy _6 }; + _0 = baml.llm.PrimitiveClient { const "OpenAIImageResponses", const "openai-responses", copy _2 }; + goto -> bb2; + } + + bb2: { + return; + } +} + fn user.GenerateImage(prompt: string, client: baml.llm.Client) -> image { // Locals: let _0: image // _0 // return @@ -88,6 +120,66 @@ fn user.GenerateImage$build_request_stream(prompt: string, client: baml.llm.Clie } } +fn user.GenerateImage$parse(json: string, client: baml.llm.Client) -> image { + // Locals: + let _0: image // _0 // return + let _1: string // json // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.OpenAIImageResponses; + goto -> bb2; + } + + bb2: { + _4 = load_type(image); + _5 = load_type(image); + _0 = call const fn baml.llm.parse(copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.GenerateImage$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client) -> baml.llm.Stream { + // Locals: + let _0: baml.llm.Stream // _0 // return + let _1: baml.http.SseStream // sse // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.OpenAIImageResponses; + goto -> bb2; + } + + bb2: { + _4 = load_type(image); + _5 = load_type(image); + _0 = call const fn baml.llm.Client.__make_stream(copy _2, copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + fn user.GenerateImage$render_prompt(prompt: string, client: baml.llm.Client) -> baml.llm.PromptAst { // Locals: let _0: baml.llm.PromptAst // _0 // return @@ -116,6 +208,38 @@ fn user.GenerateImage$render_prompt(prompt: string, client: baml.llm.Client) -> } } +fn user.GenerateImage$stream(prompt: string, client: baml.llm.Client) -> baml.llm.Stream { + // Locals: + let _0: baml.llm.Stream // _0 // return + let _1: string // prompt // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: map + let _5: type + let _6: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.OpenAIImageResponses; + goto -> bb2; + } + + bb2: { + _4 = { const "prompt": copy _1 }: map; + _5 = load_type(image); + _6 = load_type(image); + _0 = call const fn baml.llm.stream_llm_function(copy _2, const "GenerateImage", copy _4, const ) -> [bb3]; + } + + bb3: { + return; + } +} + fn user.GenerateImageSet(prompt: string, client: baml.llm.Client) -> image[] { // Locals: let _0: image[] // _0 // return @@ -202,6 +326,66 @@ fn user.GenerateImageSet$build_request_stream(prompt: string, client: baml.llm.C } } +fn user.GenerateImageSet$parse(json: string, client: baml.llm.Client) -> image[] { + // Locals: + let _0: image[] // _0 // return + let _1: string // json // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.OpenAIImageResponses; + goto -> bb2; + } + + bb2: { + _4 = load_type(image[]); + _5 = load_type(image[]); + _0 = call const fn baml.llm.parse(copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.GenerateImageSet$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client) -> baml.llm.Stream { + // Locals: + let _0: baml.llm.Stream // _0 // return + let _1: baml.http.SseStream // sse // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.OpenAIImageResponses; + goto -> bb2; + } + + bb2: { + _4 = load_type(image[]); + _5 = load_type(image[]); + _0 = call const fn baml.llm.Client.__make_stream(copy _2, copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + fn user.GenerateImageSet$render_prompt(prompt: string, client: baml.llm.Client) -> baml.llm.PromptAst { // Locals: let _0: baml.llm.PromptAst // _0 // return @@ -230,6 +414,38 @@ fn user.GenerateImageSet$render_prompt(prompt: string, client: baml.llm.Client) } } +fn user.GenerateImageSet$stream(prompt: string, client: baml.llm.Client) -> baml.llm.Stream { + // Locals: + let _0: baml.llm.Stream // _0 // return + let _1: string // prompt // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: map + let _5: type + let _6: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.OpenAIImageResponses; + goto -> bb2; + } + + bb2: { + _4 = { const "prompt": copy _1 }: map; + _5 = load_type(image[]); + _6 = load_type(image[]); + _0 = call const fn baml.llm.stream_llm_function(copy _2, const "GenerateImageSet", copy _4, const ) -> [bb3]; + } + + bb3: { + return; + } +} + fn user.GenerateMixedImageNarrative(prompt: string, client: baml.llm.Client) -> (string | image)[] { // Locals: let _0: (string | image)[] // _0 // return @@ -316,6 +532,66 @@ fn user.GenerateMixedImageNarrative$build_request_stream(prompt: string, client: } } +fn user.GenerateMixedImageNarrative$parse(json: string, client: baml.llm.Client) -> (string | image)[] { + // Locals: + let _0: (string | image)[] // _0 // return + let _1: string // json // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.OpenAIImageResponses; + goto -> bb2; + } + + bb2: { + _4 = load_type((image | string)[]); + _5 = load_type((image | string)[]); + _0 = call const fn baml.llm.parse(copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.GenerateMixedImageNarrative$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client) -> baml.llm.Stream<(string | image)[], (string | image)[]> { + // Locals: + let _0: baml.llm.Stream<(string | image)[], (string | image)[]> // _0 // return + let _1: baml.http.SseStream // sse // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.OpenAIImageResponses; + goto -> bb2; + } + + bb2: { + _4 = load_type((image | string)[]); + _5 = load_type((image | string)[]); + _0 = call const fn baml.llm.Client.__make_stream(copy _2, copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + fn user.GenerateMixedImageNarrative$render_prompt(prompt: string, client: baml.llm.Client) -> baml.llm.PromptAst { // Locals: let _0: baml.llm.PromptAst // _0 // return @@ -344,34 +620,34 @@ fn user.GenerateMixedImageNarrative$render_prompt(prompt: string, client: baml.l } } -fn user.OpenAIImageResponses$new(lenient: bool) -> null { +fn user.GenerateMixedImageNarrative$stream(prompt: string, client: baml.llm.Client) -> baml.llm.Stream<(string | image)[], (string | image)[]> { // Locals: - let _0: null // _0 // return - let _1: bool // lenient // param - let _2: baml.llm.PrimitiveClientOptions - let _3: string - let _4: map - let _5: map - let _6: map - let _7: map[] - let _8: map + let _0: baml.llm.Stream<(string | image)[], (string | image)[]> // _0 // return + let _1: string // prompt // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: map + let _5: type + let _6: type bb0: { - _3 = call const fn baml.env.get_or_panic_lenient(const "OPENAI_API_KEY", copy _1) -> [bb1]; + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } bb1: { - _4 = { }: map; - _5 = { }: map; - _8 = { const "type": const "image_generation", const "size": const "1024x1024", const "quality": const "low" }: map; - _7 = [copy _8]: map[]; - _6 = { const "tools": copy _7 }: map; - _2 = baml.llm.PrimitiveClientOptions { const "gpt-4.1", const null, const null, const null, const null, const null, const null, const null, const null, copy _3, const null, const null, copy _4, copy _5, copy _6 }; - _0 = baml.llm.PrimitiveClient { const "OpenAIImageResponses", const "openai-responses", copy _2 }; + _2 = const item user.OpenAIImageResponses; goto -> bb2; } bb2: { + _4 = { const "prompt": copy _1 }: map; + _5 = load_type((image | string)[]); + _6 = load_type((image | string)[]); + _0 = call const fn baml.llm.stream_llm_function(copy _2, const "GenerateMixedImageNarrative", copy _4, const ) -> [bb3]; + } + + bb3: { return; } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/llm_parse_catchable_parse_error/baml_tests__compiles__llm_parse_catchable_parse_error__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/llm_parse_catchable_parse_error/baml_tests__compiles__llm_parse_catchable_parse_error__04_5_mir.snap index 598c8a14a9d..6e7f1fa7c5c 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/llm_parse_catchable_parse_error/baml_tests__compiles__llm_parse_catchable_parse_error__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/llm_parse_catchable_parse_error/baml_tests__compiles__llm_parse_catchable_parse_error__04_5_mir.snap @@ -2,6 +2,34 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === +fn user.GPT4o$new(lenient: bool) -> null { + // Locals: + let _0: null // _0 // return + let _1: bool // lenient // param + let _2: baml.llm.PrimitiveClientOptions + let _3: string + let _4: map + let _5: map + let _6: map + + bb0: { + _3 = call const fn baml.env.get_or_panic_lenient(const "OPENAI_API_KEY", copy _1) -> [bb1]; + } + + bb1: { + _4 = { }: map; + _5 = { }: map; + _6 = { }: map; + _2 = baml.llm.PrimitiveClientOptions { const "gpt-4o", const null, const null, const null, const null, const null, const null, const null, const null, copy _3, const null, const null, copy _4, copy _5, copy _6 }; + _0 = baml.llm.PrimitiveClient { const "GPT4o", const "openai", copy _2 }; + goto -> bb2; + } + + bb2: { + return; + } +} + fn user.ExtractInvoice(text: string, client: baml.llm.Client) -> Invoice { // Locals: let _0: Invoice // _0 // return @@ -88,6 +116,66 @@ fn user.ExtractInvoice$build_request_stream(text: string, client: baml.llm.Clien } } +fn user.ExtractInvoice$parse(json: string, client: baml.llm.Client) -> Invoice { + // Locals: + let _0: Invoice // _0 // return + let _1: string // json // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.GPT4o; + goto -> bb2; + } + + bb2: { + _4 = load_type(Invoice$stream | null); + _5 = load_type(Invoice); + _0 = call const fn baml.llm.parse(copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.ExtractInvoice$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client) -> baml.llm.Stream { + // Locals: + let _0: baml.llm.Stream // _0 // return + let _1: baml.http.SseStream // sse // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.GPT4o; + goto -> bb2; + } + + bb2: { + _4 = load_type(Invoice$stream | null); + _5 = load_type(Invoice); + _0 = call const fn baml.llm.Client.__make_stream(copy _2, copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + fn user.ExtractInvoice$render_prompt(text: string, client: baml.llm.Client) -> baml.llm.PromptAst { // Locals: let _0: baml.llm.PromptAst // _0 // return @@ -116,30 +204,34 @@ fn user.ExtractInvoice$render_prompt(text: string, client: baml.llm.Client) -> b } } -fn user.GPT4o$new(lenient: bool) -> null { +fn user.ExtractInvoice$stream(text: string, client: baml.llm.Client) -> baml.llm.Stream { // Locals: - let _0: null // _0 // return - let _1: bool // lenient // param - let _2: baml.llm.PrimitiveClientOptions - let _3: string - let _4: map - let _5: map - let _6: map + let _0: baml.llm.Stream // _0 // return + let _1: string // text // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: map + let _5: type + let _6: type bb0: { - _3 = call const fn baml.env.get_or_panic_lenient(const "OPENAI_API_KEY", copy _1) -> [bb1]; + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } bb1: { - _4 = { }: map; - _5 = { }: map; - _6 = { }: map; - _2 = baml.llm.PrimitiveClientOptions { const "gpt-4o", const null, const null, const null, const null, const null, const null, const null, const null, copy _3, const null, const null, copy _4, copy _5, copy _6 }; - _0 = baml.llm.PrimitiveClient { const "GPT4o", const "openai", copy _2 }; + _2 = const item user.GPT4o; goto -> bb2; } bb2: { + _4 = { const "text": copy _1 }: map; + _5 = load_type(Invoice$stream | null); + _6 = load_type(Invoice); + _0 = call const fn baml.llm.stream_llm_function(copy _2, const "ExtractInvoice", copy _4, const ) -> [bb3]; + } + + bb3: { return; } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/method_explicit_type_args/baml_tests__compiles__method_explicit_type_args__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/method_explicit_type_args/baml_tests__compiles__method_explicit_type_args__04_5_mir.snap index 859f86a5967..f70ad5004b3 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/method_explicit_type_args/baml_tests__compiles__method_explicit_type_args__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/method_explicit_type_args/baml_tests__compiles__method_explicit_type_args__04_5_mir.snap @@ -1,8 +1,22 @@ --- source: crates/baml_tests/src/generated_tests.rs -assertion_line: 19690 --- === MIR2 === +fn user.Foo.zero(self: Foo) -> null | T { + // Locals: + let _0: null | T // _0 // return + let _1: Foo // self // param + + bb0: { + _0 = const null; + goto -> bb1; + } + + bb1: { + return; + } +} + fn user.use_method_type_args() -> int { // Locals: let _0: int // _0 // return @@ -38,18 +52,3 @@ fn user.use_method_type_args() -> int { return; } } - -fn user.Foo.zero(self: Foo) -> null | T { - // Locals: - let _0: null | T // _0 // return - let _1: Foo // self // param - - bb0: { - _0 = const null; - goto -> bb1; - } - - bb1: { - return; - } -} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/namespaces_type_resolution/baml_tests__compiles__namespaces_type_resolution__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/namespaces_type_resolution/baml_tests__compiles__namespaces_type_resolution__04_5_mir.snap index bb1f4e246df..e330a7c0f38 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/namespaces_type_resolution/baml_tests__compiles__namespaces_type_resolution__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/namespaces_type_resolution/baml_tests__compiles__namespaces_type_resolution__04_5_mir.snap @@ -2,13 +2,13 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === -fn user.RootAliasParam(cfg: Config) -> string { +fn user.RootIdentity(cfg: Config) -> Config { // Locals: - let _0: string // _0 // return + let _0: Config // _0 // return let _1: Config // cfg // param bb0: { - _0 = copy _1.0; + _0 = copy _1; goto -> bb1; } @@ -32,6 +32,20 @@ fn user.RootConstruct(key: string) -> Config { } } +fn user.RootEnumReturn() -> Status { + // Locals: + let _0: Status // _0 // return + + bb0: { + _0 = const user.Status.Ok; + goto -> bb1; + } + + bb1: { + return; + } +} + fn user.RootEnumMatch(s: Status) -> string { // Locals: let _0: string // _0 // return @@ -67,40 +81,10 @@ fn user.RootEnumMatch(s: Status) -> string { } } -fn user.RootEnumReturn() -> Status { - // Locals: - let _0: Status // _0 // return - - bb0: { - _0 = const user.Status.Ok; - goto -> bb1; - } - - bb1: { - return; - } -} - -fn user.RootIdentity(cfg: Config) -> Config { - // Locals: - let _0: Config // _0 // return - let _1: Config // cfg // param - - bb0: { - _0 = copy _1; - goto -> bb1; - } - - bb1: { - return; - } -} - -fn user.RootMixedConfigs(root_cfg: Config, llm_cfg: llm.Config) -> string { +fn user.RootAliasParam(cfg: Config) -> string { // Locals: let _0: string // _0 // return - let _1: Config // root_cfg // param - let _2: llm.Config // llm_cfg // param + let _1: Config // cfg // param bb0: { _0 = copy _1.0; @@ -160,10 +144,10 @@ fn user.RootThrowEnum(x: int) -> string { } } -fn user.RootUsesAuthConfig(cfg: auth.Config) -> string { +fn user.RootUsesLlmConfig(cfg: llm.Config) -> string { // Locals: let _0: string // _0 // return - let _1: auth.Config // cfg // param + let _1: llm.Config // cfg // param bb0: { _0 = copy _1.0; @@ -175,10 +159,10 @@ fn user.RootUsesAuthConfig(cfg: auth.Config) -> string { } } -fn user.RootUsesAuthError(e: auth.Error) -> string { +fn user.RootUsesLlmError(e: llm.Error) -> string { // Locals: let _0: string // _0 // return - let _1: auth.Error // e // param + let _1: llm.Error // e // param bb0: { _0 = copy _1.0; @@ -190,13 +174,12 @@ fn user.RootUsesAuthError(e: auth.Error) -> string { } } -fn user.RootUsesLlmConfig(cfg: llm.Config) -> string { +fn user.RootUsesLlmStatus() -> llm.Status { // Locals: - let _0: string // _0 // return - let _1: llm.Config // cfg // param + let _0: llm.Status // _0 // return bb0: { - _0 = copy _1.0; + _0 = const user.llm.Status.Ready; goto -> bb1; } @@ -205,10 +188,10 @@ fn user.RootUsesLlmConfig(cfg: llm.Config) -> string { } } -fn user.RootUsesLlmError(e: llm.Error) -> string { +fn user.RootUsesAuthConfig(cfg: auth.Config) -> string { // Locals: let _0: string // _0 // return - let _1: llm.Error // e // param + let _1: auth.Config // cfg // param bb0: { _0 = copy _1.0; @@ -220,12 +203,13 @@ fn user.RootUsesLlmError(e: llm.Error) -> string { } } -fn user.RootUsesLlmStatus() -> llm.Status { +fn user.RootUsesAuthError(e: auth.Error) -> string { // Locals: - let _0: llm.Status // _0 // return + let _0: string // _0 // return + let _1: auth.Error // e // param bb0: { - _0 = const user.llm.Status.Ready; + _0 = copy _1.0; goto -> bb1; } @@ -249,10 +233,11 @@ fn user.RootUsesNestedClient(c: llm.openai.Client) -> string { } } -fn user.auth.AuthAliasParam(t: auth.Token) -> string { +fn user.RootMixedConfigs(root_cfg: Config, llm_cfg: llm.Config) -> string { // Locals: let _0: string // _0 // return - let _1: auth.Token // t // param + let _1: Config // root_cfg // param + let _2: llm.Config // llm_cfg // param bb0: { _0 = copy _1.0; @@ -264,6 +249,21 @@ fn user.auth.AuthAliasParam(t: auth.Token) -> string { } } +fn user.auth.AuthIdentity(cfg: auth.Config) -> auth.Config { + // Locals: + let _0: auth.Config // _0 // return + let _1: auth.Config // cfg // param + + bb0: { + _0 = copy _1; + goto -> bb1; + } + + bb1: { + return; + } +} + fn user.auth.AuthConstruct(provider: string) -> auth.Config { // Locals: let _0: auth.Config // _0 // return @@ -279,6 +279,20 @@ fn user.auth.AuthConstruct(provider: string) -> auth.Config { } } +fn user.auth.AuthEnumReturn() -> auth.Role { + // Locals: + let _0: auth.Role // _0 // return + + bb0: { + _0 = const user.auth.Role.Admin; + goto -> bb1; + } + + bb1: { + return; + } +} + fn user.auth.AuthEnumMatch(r: auth.Role) -> string { // Locals: let _0: string // _0 // return @@ -314,12 +328,13 @@ fn user.auth.AuthEnumMatch(r: auth.Role) -> string { } } -fn user.auth.AuthEnumReturn() -> auth.Role { +fn user.auth.AuthAliasParam(t: auth.Token) -> string { // Locals: - let _0: auth.Role // _0 // return + let _0: string // _0 // return + let _1: auth.Token // t // param bb0: { - _0 = const user.auth.Role.Admin; + _0 = copy _1.0; goto -> bb1; } @@ -328,19 +343,52 @@ fn user.auth.AuthEnumReturn() -> auth.Role { } } -fn user.auth.AuthIdentity(cfg: auth.Config) -> auth.Config { +fn user.auth.AuthThrowClass(x: int) -> string { // Locals: - let _0: auth.Config // _0 // return - let _1: auth.Config // cfg // param + let _0: string // _0 // return + let _1: int // x // param + let _2: auth.Error bb0: { - _0 = copy _1; - goto -> bb1; + switch copy _1 [0: bb3, otherwise: bb1]; + } + + bb1: { + _0 = const "ok"; + goto -> bb2; + } + + bb2: { + return; + } + + bb3: { + _2 = user.auth.Error { const "auth failed", const true }; + throw copy _2; + } +} + +fn user.auth.AuthThrowEnum(x: int) -> string { + // Locals: + let _0: string // _0 // return + let _1: int // x // param + + bb0: { + switch copy _1 [0: bb3, otherwise: bb1]; } bb1: { + _0 = const "ok"; + goto -> bb2; + } + + bb2: { return; } + + bb3: { + throw const user.auth.Role.Guest; + } } fn user.auth.AuthMakeToken(v: string) -> auth.Token { @@ -358,37 +406,31 @@ fn user.auth.AuthMakeToken(v: string) -> auth.Token { } } -fn user.auth.AuthMatchesLlmStatus(s: llm.Status) -> string { +fn user.auth.AuthUsesRootConfig(cfg: Config) -> string { // Locals: let _0: string // _0 // return - let _1: llm.Status // s // param - let _2: int + let _1: Config // cfg // param bb0: { - _2 = discriminant(_1); - switch copy _2 [Status.Ready: bb4, Status.Generating: bb3, Status.Done: bb2, otherwise: bb1] (exhaustive); + _0 = copy _1.0; + goto -> bb1; } bb1: { - unreachable; - } - - bb2: { - _0 = const "done"; - goto -> bb5; + return; } +} - bb3: { - _0 = const "generating"; - goto -> bb5; - } +fn user.auth.AuthUsesRootStatus() -> Status { + // Locals: + let _0: Status // _0 // return - bb4: { - _0 = const "ready"; - goto -> bb5; + bb0: { + _0 = const user.Status.Pending; + goto -> bb1; } - bb5: { + bb1: { return; } } @@ -428,29 +470,35 @@ fn user.auth.AuthMatchesRootStatus(s: Status) -> string { } } -fn user.auth.AuthMixedConfigs(auth_cfg: auth.Config, root_cfg: Config, llm_cfg: llm.Config) -> string { +fn user.auth.AuthThrowsRootError(x: int) -> string { // Locals: let _0: string // _0 // return - let _1: auth.Config // auth_cfg // param - let _2: Config // root_cfg // param - let _3: llm.Config // llm_cfg // param + let _1: int // x // param + let _2: Error bb0: { - _0 = copy _1.0; - goto -> bb1; + switch copy _1 [0: bb3, otherwise: bb1]; } bb1: { + _0 = const "ok"; + goto -> bb2; + } + + bb2: { return; } + + bb3: { + _2 = user.Error { const 403_i64, const "forbidden" }; + throw copy _2; + } } -fn user.auth.AuthMixedErrors(auth_err: auth.Error, root_err: Error, llm_err: llm.Error) -> string { +fn user.auth.AuthUsesLlmConfig(cfg: llm.Config) -> string { // Locals: let _0: string // _0 // return - let _1: auth.Error // auth_err // param - let _2: Error // root_err // param - let _3: llm.Error // llm_err // param + let _1: llm.Config // cfg // param bb0: { _0 = copy _1.0; @@ -462,98 +510,74 @@ fn user.auth.AuthMixedErrors(auth_err: auth.Error, root_err: Error, llm_err: llm } } -fn user.auth.AuthThrowClass(x: int) -> string { +fn user.auth.AuthUsesLlmResponse(r: llm.Response) -> string { // Locals: let _0: string // _0 // return - let _1: int // x // param - let _2: auth.Error + let _1: llm.Response // r // param bb0: { - switch copy _1 [0: bb3, otherwise: bb1]; + _0 = copy _1.0; + goto -> bb1; } bb1: { - _0 = const "ok"; - goto -> bb2; + return; } +} - bb2: { - return; +fn user.auth.AuthUsesLlmStatus() -> llm.Status { + // Locals: + let _0: llm.Status // _0 // return + + bb0: { + _0 = const user.llm.Status.Ready; + goto -> bb1; } - bb3: { - _2 = user.auth.Error { const "auth failed", const true }; - throw copy _2; + bb1: { + return; } } -fn user.auth.AuthThrowEnum(x: int) -> string { +fn user.auth.AuthMatchesLlmStatus(s: llm.Status) -> string { // Locals: let _0: string // _0 // return - let _1: int // x // param + let _1: llm.Status // s // param + let _2: int bb0: { - switch copy _1 [0: bb3, otherwise: bb1]; + _2 = discriminant(_1); + switch copy _2 [Status.Ready: bb4, Status.Generating: bb3, Status.Done: bb2, otherwise: bb1] (exhaustive); } bb1: { - _0 = const "ok"; - goto -> bb2; - } - - bb2: { - return; - } - - bb3: { - throw const user.auth.Role.Guest; - } -} - -fn user.auth.AuthThrowsRootError(x: int) -> string { - // Locals: - let _0: string // _0 // return - let _1: int // x // param - let _2: Error - - bb0: { - switch copy _1 [0: bb3, otherwise: bb1]; - } - - bb1: { - _0 = const "ok"; - goto -> bb2; + unreachable; } bb2: { - return; + _0 = const "done"; + goto -> bb5; } bb3: { - _2 = user.Error { const 403_i64, const "forbidden" }; - throw copy _2; + _0 = const "generating"; + goto -> bb5; } -} - -fn user.auth.AuthUsesLlmConfig(cfg: llm.Config) -> string { - // Locals: - let _0: string // _0 // return - let _1: llm.Config // cfg // param - bb0: { - _0 = copy _1.0; - goto -> bb1; + bb4: { + _0 = const "ready"; + goto -> bb5; } - bb1: { + bb5: { return; } } -fn user.auth.AuthUsesLlmResponse(r: llm.Response) -> string { +fn user.auth.AuthUsesNestedClient(c: llm.openai.Client) -> string { // Locals: let _0: string // _0 // return - let _1: llm.Response // r // param + let _1: llm.openai.Client // c // param bb0: { _0 = copy _1.0; @@ -565,24 +589,12 @@ fn user.auth.AuthUsesLlmResponse(r: llm.Response) -> string { } } -fn user.auth.AuthUsesLlmStatus() -> llm.Status { - // Locals: - let _0: llm.Status // _0 // return - - bb0: { - _0 = const user.llm.Status.Ready; - goto -> bb1; - } - - bb1: { - return; - } -} - -fn user.auth.AuthUsesNestedClient(c: llm.openai.Client) -> string { +fn user.auth.AuthMixedConfigs(auth_cfg: auth.Config, root_cfg: Config, llm_cfg: llm.Config) -> string { // Locals: let _0: string // _0 // return - let _1: llm.openai.Client // c // param + let _1: auth.Config // auth_cfg // param + let _2: Config // root_cfg // param + let _3: llm.Config // llm_cfg // param bb0: { _0 = copy _1.0; @@ -594,10 +606,12 @@ fn user.auth.AuthUsesNestedClient(c: llm.openai.Client) -> string { } } -fn user.auth.AuthUsesRootConfig(cfg: Config) -> string { +fn user.auth.AuthMixedErrors(auth_err: auth.Error, root_err: Error, llm_err: llm.Error) -> string { // Locals: let _0: string // _0 // return - let _1: Config // cfg // param + let _1: auth.Error // auth_err // param + let _2: Error // root_err // param + let _3: llm.Error // llm_err // param bb0: { _0 = copy _1.0; @@ -609,12 +623,13 @@ fn user.auth.AuthUsesRootConfig(cfg: Config) -> string { } } -fn user.auth.AuthUsesRootStatus() -> Status { +fn user.llm.LlmIdentity(cfg: llm.Config) -> llm.Config { // Locals: - let _0: Status // _0 // return + let _0: llm.Config // _0 // return + let _1: llm.Config // cfg // param bb0: { - _0 = const user.Status.Pending; + _0 = copy _1; goto -> bb1; } @@ -623,13 +638,13 @@ fn user.auth.AuthUsesRootStatus() -> Status { } } -fn user.llm.LlmAliasParam(cfg: llm.Config) -> string { +fn user.llm.LlmConstruct(model: string) -> llm.Config { // Locals: - let _0: string // _0 // return - let _1: llm.Config // cfg // param + let _0: llm.Config // _0 // return + let _1: string // model // param bb0: { - _0 = copy _1.0; + _0 = user.llm.Config { copy _1, const 0.7_f64 }; goto -> bb1; } @@ -638,13 +653,12 @@ fn user.llm.LlmAliasParam(cfg: llm.Config) -> string { } } -fn user.llm.LlmConstruct(model: string) -> llm.Config { +fn user.llm.LlmEnumReturn() -> llm.Status { // Locals: - let _0: llm.Config // _0 // return - let _1: string // model // param + let _0: llm.Status // _0 // return bb0: { - _0 = user.llm.Config { copy _1, const 0.7_f64 }; + _0 = const user.llm.Status.Ready; goto -> bb1; } @@ -688,12 +702,13 @@ fn user.llm.LlmEnumMatch(s: llm.Status) -> string { } } -fn user.llm.LlmEnumReturn() -> llm.Status { +fn user.llm.LlmAliasParam(cfg: llm.Config) -> string { // Locals: - let _0: llm.Status // _0 // return + let _0: string // _0 // return + let _1: llm.Config // cfg // param bb0: { - _0 = const user.llm.Status.Ready; + _0 = copy _1.0; goto -> bb1; } @@ -702,62 +717,73 @@ fn user.llm.LlmEnumReturn() -> llm.Status { } } -fn user.llm.LlmIdentity(cfg: llm.Config) -> llm.Config { +fn user.llm.LlmThrowClass(x: int) -> string { // Locals: - let _0: llm.Config // _0 // return - let _1: llm.Config // cfg // param + let _0: string // _0 // return + let _1: int // x // param + let _2: llm.Error bb0: { - _0 = copy _1; - goto -> bb1; + switch copy _1 [0: bb3, otherwise: bb1]; } bb1: { + _0 = const "ok"; + goto -> bb2; + } + + bb2: { return; } + + bb3: { + _2 = user.llm.Error { const "llm failed", const true }; + throw copy _2; + } } -fn user.llm.LlmMatchesRootStatus(s: Status) -> string { +fn user.llm.LlmThrowEnum(x: int) -> string { // Locals: let _0: string // _0 // return - let _1: Status // s // param - let _2: int + let _1: int // x // param bb0: { - _2 = discriminant(_1); - switch copy _2 [Status.Ok: bb4, Status.Failed: bb3, Status.Pending: bb2, otherwise: bb1] (exhaustive); + switch copy _1 [0: bb3, otherwise: bb1]; } bb1: { - unreachable; + _0 = const "ok"; + goto -> bb2; } bb2: { - _0 = const "pending"; - goto -> bb5; + return; } bb3: { - _0 = const "failed"; - goto -> bb5; + throw const user.llm.Status.Done; } +} - bb4: { - _0 = const "ok"; - goto -> bb5; +fn user.llm.LlmResponseConstruct(text: string) -> llm.Response { + // Locals: + let _0: llm.Response // _0 // return + let _1: string // text // param + + bb0: { + _0 = user.llm.Response { copy _1, const 42_i64 }; + goto -> bb1; } - bb5: { + bb1: { return; } } -fn user.llm.LlmMixedConfigs(llm_cfg: llm.Config, root_cfg: Config, auth_cfg: auth.Config) -> string { +fn user.llm.LlmUsesRootConfig(cfg: Config) -> string { // Locals: let _0: string // _0 // return - let _1: llm.Config // llm_cfg // param - let _2: Config // root_cfg // param - let _3: auth.Config // auth_cfg // param + let _1: Config // cfg // param bb0: { _0 = copy _1.0; @@ -769,13 +795,13 @@ fn user.llm.LlmMixedConfigs(llm_cfg: llm.Config, root_cfg: Config, auth_cfg: aut } } -fn user.llm.LlmResponseConstruct(text: string) -> llm.Response { +fn user.llm.LlmUsesRootError(e: Error) -> string { // Locals: - let _0: llm.Response // _0 // return - let _1: string // text // param + let _0: string // _0 // return + let _1: Error // e // param bb0: { - _0 = user.llm.Response { copy _1, const 42_i64 }; + _0 = copy _1.1; goto -> bb1; } @@ -784,58 +810,75 @@ fn user.llm.LlmResponseConstruct(text: string) -> llm.Response { } } -fn user.llm.LlmThrowClass(x: int) -> string { +fn user.llm.LlmUsesRootStatus() -> Status { + // Locals: + let _0: Status // _0 // return + + bb0: { + _0 = const user.Status.Ok; + goto -> bb1; + } + + bb1: { + return; + } +} + +fn user.llm.LlmMatchesRootStatus(s: Status) -> string { // Locals: let _0: string // _0 // return - let _1: int // x // param - let _2: llm.Error + let _1: Status // s // param + let _2: int bb0: { - switch copy _1 [0: bb3, otherwise: bb1]; + _2 = discriminant(_1); + switch copy _2 [Status.Ok: bb4, Status.Failed: bb3, Status.Pending: bb2, otherwise: bb1] (exhaustive); } bb1: { - _0 = const "ok"; - goto -> bb2; + unreachable; } bb2: { - return; + _0 = const "pending"; + goto -> bb5; } bb3: { - _2 = user.llm.Error { const "llm failed", const true }; - throw copy _2; + _0 = const "failed"; + goto -> bb5; + } + + bb4: { + _0 = const "ok"; + goto -> bb5; + } + + bb5: { + return; } } -fn user.llm.LlmThrowEnum(x: int) -> string { +fn user.llm.LlmUsesRootAlias(cfg: Config) -> string { // Locals: let _0: string // _0 // return - let _1: int // x // param + let _1: Config // cfg // param bb0: { - switch copy _1 [0: bb3, otherwise: bb1]; + _0 = copy _1.0; + goto -> bb1; } bb1: { - _0 = const "ok"; - goto -> bb2; - } - - bb2: { return; } - - bb3: { - throw const user.llm.Status.Done; - } } -fn user.llm.LlmThrowsRootEnum(x: int) -> string { +fn user.llm.LlmThrowsRootError(x: int) -> string { // Locals: let _0: string // _0 // return let _1: int // x // param + let _2: Error bb0: { switch copy _1 [0: bb3, otherwise: bb1]; @@ -851,15 +894,15 @@ fn user.llm.LlmThrowsRootEnum(x: int) -> string { } bb3: { - throw const user.Status.Failed; + _2 = user.Error { const 404_i64, const "not found" }; + throw copy _2; } } -fn user.llm.LlmThrowsRootError(x: int) -> string { +fn user.llm.LlmThrowsRootEnum(x: int) -> string { // Locals: let _0: string // _0 // return let _1: int // x // param - let _2: Error bb0: { switch copy _1 [0: bb3, otherwise: bb1]; @@ -875,8 +918,7 @@ fn user.llm.LlmThrowsRootError(x: int) -> string { } bb3: { - _2 = user.Error { const 404_i64, const "not found" }; - throw copy _2; + throw const user.Status.Failed; } } @@ -939,10 +981,12 @@ fn user.llm.LlmUsesNestedClient(c: llm.openai.Client) -> string { } } -fn user.llm.LlmUsesRootAlias(cfg: Config) -> string { +fn user.llm.LlmMixedConfigs(llm_cfg: llm.Config, root_cfg: Config, auth_cfg: auth.Config) -> string { // Locals: let _0: string // _0 // return - let _1: Config // cfg // param + let _1: llm.Config // llm_cfg // param + let _2: Config // root_cfg // param + let _3: auth.Config // auth_cfg // param bb0: { _0 = copy _1.0; @@ -954,13 +998,13 @@ fn user.llm.LlmUsesRootAlias(cfg: Config) -> string { } } -fn user.llm.LlmUsesRootConfig(cfg: Config) -> string { +fn user.llm.openai.OpenAIIdentity(c: llm.openai.Client) -> llm.openai.Client { // Locals: - let _0: string // _0 // return - let _1: Config // cfg // param + let _0: llm.openai.Client // _0 // return + let _1: llm.openai.Client // c // param bb0: { - _0 = copy _1.0; + _0 = copy _1; goto -> bb1; } @@ -969,27 +1013,13 @@ fn user.llm.LlmUsesRootConfig(cfg: Config) -> string { } } -fn user.llm.LlmUsesRootError(e: Error) -> string { - // Locals: - let _0: string // _0 // return - let _1: Error // e // param - - bb0: { - _0 = copy _1.1; - goto -> bb1; - } - - bb1: { - return; - } -} - -fn user.llm.LlmUsesRootStatus() -> Status { +fn user.llm.openai.OpenAIConstruct(key: string) -> llm.openai.Client { // Locals: - let _0: Status // _0 // return + let _0: llm.openai.Client // _0 // return + let _1: string // key // param bb0: { - _0 = const user.Status.Ok; + _0 = user.llm.openai.Client { copy _1, const "org-123" }; goto -> bb1; } @@ -998,13 +1028,12 @@ fn user.llm.LlmUsesRootStatus() -> Status { } } -fn user.llm.openai.OpenAIConstruct(key: string) -> llm.openai.Client { +fn user.llm.openai.OpenAIEnumReturn() -> llm.openai.Model { // Locals: - let _0: llm.openai.Client // _0 // return - let _1: string // key // param + let _0: llm.openai.Model // _0 // return bb0: { - _0 = user.llm.openai.Client { copy _1, const "org-123" }; + _0 = const user.llm.openai.Model.GPT4o; goto -> bb1; } @@ -1048,101 +1077,79 @@ fn user.llm.openai.OpenAIEnumMatch(m: llm.openai.Model) -> string { } } -fn user.llm.openai.OpenAIEnumReturn() -> llm.openai.Model { +fn user.llm.openai.OpenAIThrowClass(x: int) -> string { // Locals: - let _0: llm.openai.Model // _0 // return + let _0: string // _0 // return + let _1: int // x // param + let _2: llm.openai.Error bb0: { - _0 = const user.llm.openai.Model.GPT4o; - goto -> bb1; + switch copy _1 [0: bb3, otherwise: bb1]; } bb1: { - return; + _0 = const "ok"; + goto -> bb2; } -} -fn user.llm.openai.OpenAIIdentity(c: llm.openai.Client) -> llm.openai.Client { - // Locals: - let _0: llm.openai.Client // _0 // return - let _1: llm.openai.Client // c // param - - bb0: { - _0 = copy _1; - goto -> bb1; + bb2: { + return; } - bb1: { - return; + bb3: { + _2 = user.llm.openai.Error { const 429_i64, const "rate limited" }; + throw copy _2; } } -fn user.llm.openai.OpenAIMatchesAuthRole(r: auth.Role) -> string { +fn user.llm.openai.OpenAIThrowEnum(x: int) -> string { // Locals: let _0: string // _0 // return - let _1: auth.Role // r // param - let _2: int + let _1: int // x // param bb0: { - _2 = discriminant(_1); - switch copy _2 [Role.Admin: bb4, Role.User: bb3, Role.Guest: bb2, otherwise: bb1] (exhaustive); + switch copy _1 [0: bb3, otherwise: bb1]; } bb1: { - unreachable; + _0 = const "ok"; + goto -> bb2; } bb2: { - _0 = const "guest"; - goto -> bb5; + return; } bb3: { - _0 = const "user"; - goto -> bb5; - } - - bb4: { - _0 = const "admin"; - goto -> bb5; - } - - bb5: { - return; + throw const user.llm.openai.Model.O3; } } -fn user.llm.openai.OpenAIMatchesLlmStatus(s: llm.Status) -> string { +fn user.llm.openai.OpenAIUsesRootConfig(cfg: Config) -> string { // Locals: let _0: string // _0 // return - let _1: llm.Status // s // param - let _2: int + let _1: Config // cfg // param bb0: { - _2 = discriminant(_1); - switch copy _2 [Status.Ready: bb4, Status.Generating: bb3, Status.Done: bb2, otherwise: bb1] (exhaustive); + _0 = copy _1.0; + goto -> bb1; } bb1: { - unreachable; - } - - bb2: { - _0 = const "done"; - goto -> bb5; + return; } +} - bb3: { - _0 = const "generating"; - goto -> bb5; - } +fn user.llm.openai.OpenAIUsesRootStatus() -> Status { + // Locals: + let _0: Status // _0 // return - bb4: { - _0 = const "ready"; - goto -> bb5; + bb0: { + _0 = const user.Status.Ok; + goto -> bb1; } - bb5: { + bb1: { return; } } @@ -1182,16 +1189,13 @@ fn user.llm.openai.OpenAIMatchesRootStatus(s: Status) -> string { } } -fn user.llm.openai.OpenAIMixedErrors(openai_err: llm.openai.Error, root_err: Error, llm_err: llm.Error, auth_err: auth.Error) -> string { +fn user.llm.openai.OpenAIUsesLlmConfig(cfg: llm.Config) -> string { // Locals: let _0: string // _0 // return - let _1: llm.openai.Error // openai_err // param - let _2: Error // root_err // param - let _3: llm.Error // llm_err // param - let _4: auth.Error // auth_err // param + let _1: llm.Config // cfg // param bb0: { - _0 = copy _1.1; + _0 = copy _1.0; goto -> bb1; } @@ -1200,87 +1204,67 @@ fn user.llm.openai.OpenAIMixedErrors(openai_err: llm.openai.Error, root_err: Err } } -fn user.llm.openai.OpenAIMixedModels(openai_model: llm.openai.Model, llm_model: llm.Model) -> string { +fn user.llm.openai.OpenAIUsesLlmResponse(r: llm.Response) -> string { // Locals: let _0: string // _0 // return - let _1: llm.openai.Model // openai_model // param - let _2: llm.Model // llm_model // param - let _3: int + let _1: llm.Response // r // param bb0: { - _3 = discriminant(_1); - switch copy _3 [Model.GPT4o: bb4, Model.GPT4oMini: bb3, Model.O3: bb2, otherwise: bb1] (exhaustive); + _0 = copy _1.0; + goto -> bb1; } bb1: { - unreachable; - } - - bb2: { - _0 = const "o3"; - goto -> bb5; - } - - bb3: { - _0 = const "mini"; - goto -> bb5; - } - - bb4: { - _0 = const "gpt4o"; - goto -> bb5; - } - - bb5: { return; } } -fn user.llm.openai.OpenAIThrowClass(x: int) -> string { +fn user.llm.openai.OpenAIUsesLlmStatus() -> llm.Status { // Locals: - let _0: string // _0 // return - let _1: int // x // param - let _2: llm.openai.Error + let _0: llm.Status // _0 // return bb0: { - switch copy _1 [0: bb3, otherwise: bb1]; + _0 = const user.llm.Status.Generating; + goto -> bb1; } bb1: { - _0 = const "ok"; - goto -> bb2; - } - - bb2: { return; } - - bb3: { - _2 = user.llm.openai.Error { const 429_i64, const "rate limited" }; - throw copy _2; - } } -fn user.llm.openai.OpenAIThrowEnum(x: int) -> string { +fn user.llm.openai.OpenAIMatchesLlmStatus(s: llm.Status) -> string { // Locals: let _0: string // _0 // return - let _1: int // x // param + let _1: llm.Status // s // param + let _2: int bb0: { - switch copy _1 [0: bb3, otherwise: bb1]; + _2 = discriminant(_1); + switch copy _2 [Status.Ready: bb4, Status.Generating: bb3, Status.Done: bb2, otherwise: bb1] (exhaustive); } bb1: { - _0 = const "ok"; - goto -> bb2; + unreachable; } bb2: { - return; + _0 = const "done"; + goto -> bb5; } bb3: { - throw const user.llm.openai.Model.O3; + _0 = const "generating"; + goto -> bb5; + } + + bb4: { + _0 = const "ready"; + goto -> bb5; + } + + bb5: { + return; } } @@ -1313,42 +1297,51 @@ fn user.llm.openai.OpenAIUsesAuthRole() -> auth.Role { } } -fn user.llm.openai.OpenAIUsesLlmConfig(cfg: llm.Config) -> string { +fn user.llm.openai.OpenAIMatchesAuthRole(r: auth.Role) -> string { // Locals: let _0: string // _0 // return - let _1: llm.Config // cfg // param + let _1: auth.Role // r // param + let _2: int bb0: { - _0 = copy _1.0; - goto -> bb1; + _2 = discriminant(_1); + switch copy _2 [Role.Admin: bb4, Role.User: bb3, Role.Guest: bb2, otherwise: bb1] (exhaustive); } bb1: { - return; + unreachable; } -} -fn user.llm.openai.OpenAIUsesLlmResponse(r: llm.Response) -> string { - // Locals: - let _0: string // _0 // return - let _1: llm.Response // r // param + bb2: { + _0 = const "guest"; + goto -> bb5; + } - bb0: { - _0 = copy _1.0; - goto -> bb1; + bb3: { + _0 = const "user"; + goto -> bb5; } - bb1: { + bb4: { + _0 = const "admin"; + goto -> bb5; + } + + bb5: { return; } } -fn user.llm.openai.OpenAIUsesLlmStatus() -> llm.Status { +fn user.llm.openai.OpenAIMixedErrors(openai_err: llm.openai.Error, root_err: Error, llm_err: llm.Error, auth_err: auth.Error) -> string { // Locals: - let _0: llm.Status // _0 // return + let _0: string // _0 // return + let _1: llm.openai.Error // openai_err // param + let _2: Error // root_err // param + let _3: llm.Error // llm_err // param + let _4: auth.Error // auth_err // param bb0: { - _0 = const user.llm.Status.Generating; + _0 = copy _1.1; goto -> bb1; } @@ -1357,31 +1350,38 @@ fn user.llm.openai.OpenAIUsesLlmStatus() -> llm.Status { } } -fn user.llm.openai.OpenAIUsesRootConfig(cfg: Config) -> string { +fn user.llm.openai.OpenAIMixedModels(openai_model: llm.openai.Model, llm_model: llm.Model) -> string { // Locals: let _0: string // _0 // return - let _1: Config // cfg // param + let _1: llm.openai.Model // openai_model // param + let _2: llm.Model // llm_model // param + let _3: int bb0: { - _0 = copy _1.0; - goto -> bb1; + _3 = discriminant(_1); + switch copy _3 [Model.GPT4o: bb4, Model.GPT4oMini: bb3, Model.O3: bb2, otherwise: bb1] (exhaustive); } bb1: { - return; + unreachable; } -} -fn user.llm.openai.OpenAIUsesRootStatus() -> Status { - // Locals: - let _0: Status // _0 // return + bb2: { + _0 = const "o3"; + goto -> bb5; + } - bb0: { - _0 = const user.Status.Ok; - goto -> bb1; + bb3: { + _0 = const "mini"; + goto -> bb5; } - bb1: { + bb4: { + _0 = const "gpt4o"; + goto -> bb5; + } + + bb5: { return; } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/numeric_invariance_ok/baml_tests__compiles__numeric_invariance_ok__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/numeric_invariance_ok/baml_tests__compiles__numeric_invariance_ok__04_5_mir.snap index a8d0fd3e3b5..9df0696148d 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/numeric_invariance_ok/baml_tests__compiles__numeric_invariance_ok__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/numeric_invariance_ok/baml_tests__compiles__numeric_invariance_ok__04_5_mir.snap @@ -2,12 +2,12 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === -fn user.BigintFieldOk() -> BigintCounter { +fn user.BigintLiteralArray() -> bigint[] { // Locals: - let _0: BigintCounter // _0 // return + let _0: bigint[] // _0 // return bb0: { - _0 = user.BigintCounter { const 1n }; + _0 = [const 1n, const 2n]: bigint[]; goto -> bb1; } @@ -16,12 +16,12 @@ fn user.BigintFieldOk() -> BigintCounter { } } -fn user.BigintLiteralArray() -> bigint[] { +fn user.EmptyBigintArray() -> bigint[] { // Locals: let _0: bigint[] // _0 // return bb0: { - _0 = [const 1n, const 2n]: bigint[]; + _0 = []: bigint[]; goto -> bb1; } @@ -30,12 +30,14 @@ fn user.BigintLiteralArray() -> bigint[] { } } -fn user.BigintMapLiteral() -> map { +fn user.EvolvingRetype() -> bigint[] { // Locals: - let _0: map // _0 // return + let _0: bigint[] // _0 // return + let _1: bigint[] // a bb0: { - _0 = { const "a": const 1n }: map; + _1 = []: never[]; + _0 = copy _1; goto -> bb1; } @@ -44,12 +46,14 @@ fn user.BigintMapLiteral() -> map { } } -fn user.EmptyBigintArray() -> bigint[] { +fn user.IntArrayIdentity() -> int[] { // Locals: - let _0: bigint[] // _0 // return + let _0: int[] // _0 // return + let _1: int[] // a bb0: { - _0 = []: bigint[]; + _1 = [const 1_i64, const 2_i64]: int[]; + _0 = copy _1; goto -> bb1; } @@ -58,14 +62,12 @@ fn user.EmptyBigintArray() -> bigint[] { } } -fn user.EvolvingRetype() -> bigint[] { +fn user.BigintMapLiteral() -> map { // Locals: - let _0: bigint[] // _0 // return - let _1: bigint[] // a + let _0: map // _0 // return bb0: { - _1 = []: never[]; - _0 = copy _1; + _0 = { const "a": const 1n }: map; goto -> bb1; } @@ -74,14 +76,12 @@ fn user.EvolvingRetype() -> bigint[] { } } -fn user.IntArrayIdentity() -> int[] { +fn user.BigintFieldOk() -> BigintCounter { // Locals: - let _0: int[] // _0 // return - let _1: int[] // a + let _0: BigintCounter // _0 // return bb0: { - _1 = [const 1_i64, const 2_i64]: int[]; - _0 = copy _1; + _0 = user.BigintCounter { const 1n }; goto -> bb1; } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/numeric_literal_method_call/baml_tests__compiles__numeric_literal_method_call__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/numeric_literal_method_call/baml_tests__compiles__numeric_literal_method_call__04_5_mir.snap index 36957a30952..b28f851e0ee 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/numeric_literal_method_call/baml_tests__compiles__numeric_literal_method_call__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/numeric_literal_method_call/baml_tests__compiles__numeric_literal_method_call__04_5_mir.snap @@ -2,14 +2,14 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === -fn user.BigintToStringBareLiteral() -> string { +fn user.IntToStringBareLiteral() -> string { // Locals: let _0: string // _0 // return let _1: type bb0: { - _1 = load_type(42n); - _0 = call const fn baml.String.from(const 42n) -> [bb1]; + _1 = load_type(7); + _0 = call const fn baml.String.from(const 7_i64) -> [bb1]; } bb1: { @@ -17,12 +17,12 @@ fn user.BigintToStringBareLiteral() -> string { } } -fn user.FloatFloorBareLiteral() -> float { +fn user.IntAbsBareLiteral() -> int { // Locals: - let _0: float // _0 // return + let _0: int // _0 // return bb0: { - _0 = call const fn baml.Float.floor(const 2.5_f64) -> [bb1]; + _0 = call const fn baml.Int.abs(const 3_i64) -> [bb1]; } bb1: { @@ -30,12 +30,12 @@ fn user.FloatFloorBareLiteral() -> float { } } -fn user.IntAbsBareLiteral() -> int { +fn user.IntPowBareLiteral() -> int { // Locals: let _0: int // _0 // return bb0: { - _0 = call const fn baml.Int.abs(const 3_i64) -> [bb1]; + _0 = call const fn baml.Int.pow(const 2_i64, const 3_i64) -> [bb1]; } bb1: { @@ -43,12 +43,12 @@ fn user.IntAbsBareLiteral() -> int { } } -fn user.IntPowBareLiteral() -> int { +fn user.FloatFloorBareLiteral() -> float { // Locals: - let _0: int // _0 // return + let _0: float // _0 // return bb0: { - _0 = call const fn baml.Int.pow(const 2_i64, const 3_i64) -> [bb1]; + _0 = call const fn baml.Float.floor(const 2.5_f64) -> [bb1]; } bb1: { @@ -56,14 +56,14 @@ fn user.IntPowBareLiteral() -> int { } } -fn user.IntToStringBareLiteral() -> string { +fn user.BigintToStringBareLiteral() -> string { // Locals: let _0: string // _0 // return let _1: type bb0: { - _1 = load_type(7); - _0 = call const fn baml.String.from(const 7_i64) -> [bb1]; + _1 = load_type(42n); + _0 = call const fn baml.String.from(const 42n) -> [bb1]; } bb1: { diff --git a/baml_language/crates/baml_tests/snapshots/compiles/o1_allowed_roles/baml_tests__compiles__o1_allowed_roles__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/o1_allowed_roles/baml_tests__compiles__o1_allowed_roles__04_5_mir.snap index 7675fdb7044..6f46dfdce0e 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/o1_allowed_roles/baml_tests__compiles__o1_allowed_roles__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/o1_allowed_roles/baml_tests__compiles__o1_allowed_roles__04_5_mir.snap @@ -2,7 +2,7 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === -fn user.Gpt4oClient$new(lenient: bool) -> null { +fn user.O1Client$new(lenient: bool) -> null { // Locals: let _0: null // _0 // return let _1: bool // lenient // param @@ -15,8 +15,8 @@ fn user.Gpt4oClient$new(lenient: bool) -> null { _3 = { }: map; _4 = { }: map; _5 = { }: map; - _2 = baml.llm.PrimitiveClientOptions { const "gpt-4o", const null, const null, const null, const null, const null, const null, const null, const null, const "sk-test", const null, const null, copy _3, copy _4, copy _5 }; - _0 = baml.llm.PrimitiveClient { const "Gpt4oClient", const "openai", copy _2 }; + _2 = baml.llm.PrimitiveClientOptions { const "o1", const null, const null, const null, const null, const null, const null, const null, const null, const "sk-test", const null, const null, copy _3, copy _4, copy _5 }; + _0 = baml.llm.PrimitiveClient { const "O1Client", const "openai", copy _2 }; goto -> bb1; } @@ -25,7 +25,7 @@ fn user.Gpt4oClient$new(lenient: bool) -> null { } } -fn user.O1Client$new(lenient: bool) -> null { +fn user.O1MiniClient$new(lenient: bool) -> null { // Locals: let _0: null // _0 // return let _1: bool // lenient // param @@ -38,8 +38,8 @@ fn user.O1Client$new(lenient: bool) -> null { _3 = { }: map; _4 = { }: map; _5 = { }: map; - _2 = baml.llm.PrimitiveClientOptions { const "o1", const null, const null, const null, const null, const null, const null, const null, const null, const "sk-test", const null, const null, copy _3, copy _4, copy _5 }; - _0 = baml.llm.PrimitiveClient { const "O1Client", const "openai", copy _2 }; + _2 = baml.llm.PrimitiveClientOptions { const "o1-mini", const null, const null, const null, const null, const null, const null, const null, const null, const "sk-test", const null, const null, copy _3, copy _4, copy _5 }; + _0 = baml.llm.PrimitiveClient { const "O1MiniClient", const "openai", copy _2 }; goto -> bb1; } @@ -48,7 +48,7 @@ fn user.O1Client$new(lenient: bool) -> null { } } -fn user.O1MiniClient$new(lenient: bool) -> null { +fn user.Gpt4oClient$new(lenient: bool) -> null { // Locals: let _0: null // _0 // return let _1: bool // lenient // param @@ -61,8 +61,8 @@ fn user.O1MiniClient$new(lenient: bool) -> null { _3 = { }: map; _4 = { }: map; _5 = { }: map; - _2 = baml.llm.PrimitiveClientOptions { const "o1-mini", const null, const null, const null, const null, const null, const null, const null, const null, const "sk-test", const null, const null, copy _3, copy _4, copy _5 }; - _0 = baml.llm.PrimitiveClient { const "O1MiniClient", const "openai", copy _2 }; + _2 = baml.llm.PrimitiveClientOptions { const "gpt-4o", const null, const null, const null, const null, const null, const null, const null, const null, const "sk-test", const null, const null, copy _3, copy _4, copy _5 }; + _0 = baml.llm.PrimitiveClient { const "Gpt4oClient", const "openai", copy _2 }; goto -> bb1; } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/optional_function_parameters/baml_tests__compiles__optional_function_parameters__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/optional_function_parameters/baml_tests__compiles__optional_function_parameters__04_5_mir.snap index 5ddff5453e8..f4cf0b73644 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/optional_function_parameters/baml_tests__compiles__optional_function_parameters__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/optional_function_parameters/baml_tests__compiles__optional_function_parameters__04_5_mir.snap @@ -2,18 +2,92 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === -fn user.AskDocs(query: string, max_results: int, filter: string, client: baml.llm.Client) -> string { +fn user.TestClient$new(lenient: bool) -> null { + // Locals: + let _0: null // _0 // return + let _1: bool // lenient // param + let _2: baml.llm.PrimitiveClientOptions + let _3: map + let _4: map + let _5: map + + bb0: { + _3 = { }: map; + _4 = { }: map; + _5 = { }: map; + _2 = baml.llm.PrimitiveClientOptions { const null, const null, const null, const null, const null, const null, const null, const null, const null, const null, const null, const null, copy _3, copy _4, copy _5 }; + _0 = baml.llm.PrimitiveClient { const "TestClient", const "openai", copy _2 }; + goto -> bb1; + } + + bb1: { + return; + } +} + +fn user.DefaultFilter() -> string { // Locals: let _0: string // _0 // return + + bb0: { + _0 = const "none"; + goto -> bb1; + } + + bb1: { + return; + } +} + +fn user.Search(query: string, max_results: int, filter: string) -> int { + // Locals: + let _0: int // _0 // return let _1: string // query // param let _2: int // max_results // param let _3: string // filter // param - let _4: baml.llm.Client // client // param + let _4: bool + let _5: bool + + bb0: { + _4 = copy _2 == const ; + branch copy _4 -> [bb1, bb2]; + } + + bb1: { + _2 = const 10_i64; + goto -> bb2; + } + + bb2: { + _5 = copy _3 == const ; + branch copy _5 -> [bb3, bb4]; + } + + bb3: { + _3 = const "none"; + goto -> bb4; + } + + bb4: { + _0 = copy _2; + goto -> bb5; + } + + bb5: { + return; + } +} + +fn user.SearchDocs(query: string, max_results: int, filter: string | null, chunk_size: int) -> string[] { + // Locals: + let _0: string[] // _0 // return + let _1: string // query // param + let _2: int // max_results // param + let _3: string | null // filter // param + let _4: int // chunk_size // param let _5: bool let _6: bool let _7: bool - let _8: map - let _9: type bb0: { _5 = copy _2 == const ; @@ -31,7 +105,8 @@ fn user.AskDocs(query: string, max_results: int, filter: string, client: baml.ll } bb3: { - _3 = call const fn user.DefaultFilter() -> [bb4]; + _3 = const null; + goto -> bb4; } bb4: { @@ -40,14 +115,12 @@ fn user.AskDocs(query: string, max_results: int, filter: string, client: baml.ll } bb5: { - _4 = const item user.TestClient; - goto -> bb6; + _4 = call const fn baml.String.length(copy _1) -> [bb6]; } bb6: { - _8 = { const "query": copy _1, const "max_results": copy _2, const "filter": copy _3 }: map; - _9 = load_type(string); - _0 = call const fn baml.llm.call_llm_function(copy _4, const "AskDocs", copy _8, const ) -> [bb7]; + _0 = [copy _1]: string[]; + goto -> bb7; } bb7: { @@ -55,21 +128,93 @@ fn user.AskDocs(query: string, max_results: int, filter: string, client: baml.ll } } -fn user.AskDocs$build_request(query: string, max_results: int, filter: string, client: baml.llm.Client) -> baml.http.Request { +fn user.UseNamedDefaults() -> int { // Locals: - let _0: baml.http.Request // _0 // return + let _0: int // _0 // return + + bb0: { + _0 = call const fn user.Search(const "cats", const 5_i64, const "recent") -> [bb1]; + } + + bb1: { + return; + } +} + +fn user.UseMixedArgs() -> int { + // Locals: + let _0: int // _0 // return + + bb0: { + _0 = call const fn user.Search(const "dogs", const 3_i64, const "all") -> [bb1]; + } + + bb1: { + return; + } +} + +fn user.UseRequiredByName() -> string[] { + // Locals: + let _0: string[] // _0 // return + + bb0: { + _0 = call const fn user.SearchDocs(const "birds", const , const , const ) -> [bb1]; + } + + bb1: { + return; + } +} + +fn user.UseOptionalDropping() -> string[] { + // Locals: + let _0: string[] // _0 // return + let _1: (string, string | null) -> string[] throws never // narrowed + let _2: (string, int, string | null, int) -> string[] throws never [captured] + let _3: (string, string | null) -> string[] throws never + + bb0: { + _2 = const fn user.SearchDocs; + _1 = make_closure lambda[0](copy _2); + _3 = copy _1; + _0 = call copy _3(const "cats", const "recent") -> [bb1]; + } + + bb1: { + return; + } +} + +// lambda[0] +fn .(query: string, filter: string | null) -> string[] { + // Locals: + let _0: string[] // _0 // return + let _1: string // query // param + let _2: string | null // filter // param + + bb0: { + _0 = call copy capture[0](copy _1, const , copy _2, const ) -> [bb1]; + } + + bb1: { + return; + } +} + +fn user.HostEntry(query: string, max_results: int, filter: string | null) -> int { + // Locals: + let _0: int // _0 // return let _1: string // query // param let _2: int // max_results // param - let _3: string // filter // param - let _4: baml.llm.Client // client // param + let _3: string | null // filter // param + let _4: bool let _5: bool let _6: bool - let _7: bool - let _8: map bb0: { - _5 = copy _2 == const ; - branch copy _5 -> [bb1, bb2]; + _4 = copy _2 == const ; + branch copy _4 -> [bb1, bb2]; } bb1: { @@ -78,37 +223,41 @@ fn user.AskDocs$build_request(query: string, max_results: int, filter: string, c } bb2: { - _6 = copy _3 == const ; - branch copy _6 -> [bb3, bb4]; + _5 = copy _3 == const ; + branch copy _5 -> [bb3, bb4]; } bb3: { - _3 = call const fn user.DefaultFilter() -> [bb4]; + _3 = const null; + goto -> bb4; } bb4: { - _7 = copy _4 == const ; - branch copy _7 -> [bb5, bb6]; + _6 = call const fn baml.ops.equals_equals(copy _3, const null) -> [bb5]; } bb5: { - _4 = const item user.TestClient; - goto -> bb6; + branch copy _6 -> [bb7, bb6]; } bb6: { - _8 = { const "query": copy _1, const "max_results": copy _2, const "filter": copy _3 }: map; - _0 = call const fn baml.llm.build_request(copy _4, const "AskDocs", copy _8, const ) -> [bb7]; + _0 = copy _2 + const 100_i64; + goto -> bb8; } bb7: { + _0 = copy _2; + goto -> bb8; + } + + bb8: { return; } } -fn user.AskDocs$build_request_stream(query: string, max_results: int, filter: string, client: baml.llm.Client) -> baml.http.Request { +fn user.AskDocs(query: string, max_results: int, filter: string, client: baml.llm.Client) -> string { // Locals: - let _0: baml.http.Request // _0 // return + let _0: string // _0 // return let _1: string // query // param let _2: int // max_results // param let _3: string // filter // param @@ -117,6 +266,7 @@ fn user.AskDocs$build_request_stream(query: string, max_results: int, filter: st let _6: bool let _7: bool let _8: map + let _9: type bb0: { _5 = copy _2 == const ; @@ -149,7 +299,8 @@ fn user.AskDocs$build_request_stream(query: string, max_results: int, filter: st bb6: { _8 = { const "query": copy _1, const "max_results": copy _2, const "filter": copy _3 }: map; - _0 = call const fn baml.llm.build_request_stream(copy _4, const "AskDocs", copy _8, const ) -> [bb7]; + _9 = load_type(string); + _0 = call const fn baml.llm.call_llm_function(copy _4, const "AskDocs", copy _8, const ) -> [bb7]; } bb7: { @@ -157,9 +308,9 @@ fn user.AskDocs$build_request_stream(query: string, max_results: int, filter: st } } -fn user.AskDocs$render_prompt(query: string, max_results: int, filter: string, client: baml.llm.Client) -> baml.llm.PromptAst { +fn user.AskDocs$build_request(query: string, max_results: int, filter: string, client: baml.llm.Client) -> baml.http.Request { // Locals: - let _0: baml.llm.PromptAst // _0 // return + let _0: baml.http.Request // _0 // return let _1: string // query // param let _2: int // max_results // param let _3: string // filter // param @@ -200,7 +351,7 @@ fn user.AskDocs$render_prompt(query: string, max_results: int, filter: string, c bb6: { _8 = { const "query": copy _1, const "max_results": copy _2, const "filter": copy _3 }: map; - _0 = call const fn baml.llm.render_prompt(copy _4, const "AskDocs", copy _8, const ) -> [bb7]; + _0 = call const fn baml.llm.build_request(copy _4, const "AskDocs", copy _8, const ) -> [bb7]; } bb7: { @@ -208,60 +359,21 @@ fn user.AskDocs$render_prompt(query: string, max_results: int, filter: string, c } } -fn user.DefaultFilter() -> string { - // Locals: - let _0: string // _0 // return - - bb0: { - _0 = const "none"; - goto -> bb1; - } - - bb1: { - return; - } -} - -fn user.SearchService.Docs(self: SearchService, query: string, filter: string | null) -> string[] { - // Locals: - let _0: string[] // _0 // return - let _1: SearchService // self // param - let _2: string // query // param - let _3: string | null // filter // param - let _4: bool - - bb0: { - _4 = copy _3 == const ; - branch copy _4 -> [bb1, bb2]; - } - - bb1: { - _3 = const null; - goto -> bb2; - } - - bb2: { - _0 = call const fn user.SearchDocs(copy _2, const , copy _3, const ) -> [bb3]; - } - - bb3: { - return; - } -} - -fn user.HostEntry(query: string, max_results: int, filter: string | null) -> int { +fn user.AskDocs$build_request_stream(query: string, max_results: int, filter: string, client: baml.llm.Client) -> baml.http.Request { // Locals: - let _0: int // _0 // return + let _0: baml.http.Request // _0 // return let _1: string // query // param let _2: int // max_results // param - let _3: string | null // filter // param - let _4: bool + let _3: string // filter // param + let _4: baml.llm.Client // client // param let _5: bool let _6: bool + let _7: bool + let _8: map bb0: { - _4 = copy _2 == const ; - branch copy _4 -> [bb1, bb2]; + _5 = copy _2 == const ; + branch copy _5 -> [bb1, bb2]; } bb1: { @@ -270,60 +382,57 @@ fn user.HostEntry(query: string, max_results: int, filter: string | null) -> int } bb2: { - _5 = copy _3 == const ; - branch copy _5 -> [bb3, bb4]; + _6 = copy _3 == const ; + branch copy _6 -> [bb3, bb4]; } bb3: { - _3 = const null; - goto -> bb4; + _3 = call const fn user.DefaultFilter() -> [bb4]; } bb4: { - _6 = call const fn baml.ops.equals_equals(copy _3, const null) -> [bb5]; + _7 = copy _4 == const ; + branch copy _7 -> [bb5, bb6]; } bb5: { - branch copy _6 -> [bb7, bb6]; + _4 = const item user.TestClient; + goto -> bb6; } bb6: { - _0 = copy _2 + const 100_i64; - goto -> bb8; + _8 = { const "query": copy _1, const "max_results": copy _2, const "filter": copy _3 }: map; + _0 = call const fn baml.llm.build_request_stream(copy _4, const "AskDocs", copy _8, const ) -> [bb7]; } bb7: { - _0 = copy _2; - goto -> bb8; - } - - bb8: { return; } } -fn user.SearchService.Run(self: SearchService, query: string, limit: int) -> int { +fn user.AskDocs$parse(json: string, client: baml.llm.Client) -> string { // Locals: - let _0: int // _0 // return - let _1: SearchService // self // param - let _2: string // query // param - let _3: int // limit // param - let _4: bool - let _5: string + let _0: string // _0 // return + let _1: string // json // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type bb0: { - _4 = copy _3 == const ; - branch copy _4 -> [bb1, bb2]; + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } bb1: { - _3 = const 20_i64; + _2 = const item user.TestClient; goto -> bb2; } bb2: { - _5 = copy _1.0; - _0 = call const fn user.Search(copy _2, copy _3, copy _5) -> [bb3]; + _4 = load_type(string | null); + _5 = load_type(string); + _0 = call const fn baml.llm.parse(copy _1) -> [bb3]; } bb3: { @@ -331,55 +440,47 @@ fn user.SearchService.Run(self: SearchService, query: string, limit: int) -> int } } -fn user.Search(query: string, max_results: int, filter: string) -> int { +fn user.AskDocs$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client) -> baml.llm.Stream { // Locals: - let _0: int // _0 // return - let _1: string // query // param - let _2: int // max_results // param - let _3: string // filter // param - let _4: bool - let _5: bool + let _0: baml.llm.Stream // _0 // return + let _1: baml.http.SseStream // sse // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type bb0: { - _4 = copy _2 == const ; - branch copy _4 -> [bb1, bb2]; + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } bb1: { - _2 = const 10_i64; + _2 = const item user.TestClient; goto -> bb2; } bb2: { - _5 = copy _3 == const ; - branch copy _5 -> [bb3, bb4]; + _4 = load_type(string | null); + _5 = load_type(string); + _0 = call const fn baml.llm.Client.__make_stream(copy _2, copy _1) -> [bb3]; } bb3: { - _3 = const "none"; - goto -> bb4; - } - - bb4: { - _0 = copy _2; - goto -> bb5; - } - - bb5: { return; } } -fn user.SearchDocs(query: string, max_results: int, filter: string | null, chunk_size: int) -> string[] { +fn user.AskDocs$render_prompt(query: string, max_results: int, filter: string, client: baml.llm.Client) -> baml.llm.PromptAst { // Locals: - let _0: string[] // _0 // return + let _0: baml.llm.PromptAst // _0 // return let _1: string // query // param let _2: int // max_results // param - let _3: string | null // filter // param - let _4: int // chunk_size // param + let _3: string // filter // param + let _4: baml.llm.Client // client // param let _5: bool let _6: bool let _7: bool + let _8: map bb0: { _5 = copy _2 == const ; @@ -397,8 +498,7 @@ fn user.SearchDocs(query: string, max_results: int, filter: string | null, chunk } bb3: { - _3 = const null; - goto -> bb4; + _3 = call const fn user.DefaultFilter() -> [bb4]; } bb4: { @@ -407,12 +507,13 @@ fn user.SearchDocs(query: string, max_results: int, filter: string | null, chunk } bb5: { - _4 = call const fn baml.String.length(copy _1) -> [bb6]; + _4 = const item user.TestClient; + goto -> bb6; } bb6: { - _0 = [copy _1]: string[]; - goto -> bb7; + _8 = { const "query": copy _1, const "max_results": copy _2, const "filter": copy _3 }: map; + _0 = call const fn baml.llm.render_prompt(copy _4, const "AskDocs", copy _8, const ) -> [bb7]; } bb7: { @@ -420,99 +521,113 @@ fn user.SearchDocs(query: string, max_results: int, filter: string | null, chunk } } -fn user.TestClient$new(lenient: bool) -> null { +fn user.AskDocs$stream(query: string, max_results: int, filter: string, client: baml.llm.Client) -> baml.llm.Stream { // Locals: - let _0: null // _0 // return - let _1: bool // lenient // param - let _2: baml.llm.PrimitiveClientOptions - let _3: map - let _4: map - let _5: map + let _0: baml.llm.Stream // _0 // return + let _1: string // query // param + let _2: int // max_results // param + let _3: string // filter // param + let _4: baml.llm.Client // client // param + let _5: bool + let _6: bool + let _7: bool + let _8: map + let _9: type + let _10: type bb0: { - _3 = { }: map; - _4 = { }: map; - _5 = { }: map; - _2 = baml.llm.PrimitiveClientOptions { const null, const null, const null, const null, const null, const null, const null, const null, const null, const null, const null, const null, copy _3, copy _4, copy _5 }; - _0 = baml.llm.PrimitiveClient { const "TestClient", const "openai", copy _2 }; - goto -> bb1; + _5 = copy _2 == const ; + branch copy _5 -> [bb1, bb2]; } bb1: { - return; + _2 = const 10_i64; + goto -> bb2; } -} -fn user.UseMixedArgs() -> int { - // Locals: - let _0: int // _0 // return + bb2: { + _6 = copy _3 == const ; + branch copy _6 -> [bb3, bb4]; + } - bb0: { - _0 = call const fn user.Search(const "dogs", const 3_i64, const "all") -> [bb1]; + bb3: { + _3 = call const fn user.DefaultFilter() -> [bb4]; } - bb1: { - return; + bb4: { + _7 = copy _4 == const ; + branch copy _7 -> [bb5, bb6]; } -} -fn user.UseNamedDefaults() -> int { - // Locals: - let _0: int // _0 // return + bb5: { + _4 = const item user.TestClient; + goto -> bb6; + } - bb0: { - _0 = call const fn user.Search(const "cats", const 5_i64, const "recent") -> [bb1]; + bb6: { + _8 = { const "query": copy _1, const "max_results": copy _2, const "filter": copy _3 }: map; + _9 = load_type(string | null); + _10 = load_type(string); + _0 = call const fn baml.llm.stream_llm_function(copy _4, const "AskDocs", copy _8, const ) -> [bb7]; } - bb1: { + bb7: { return; } } -fn user.UseOptionalDropping() -> string[] { +fn user.SearchService.Run(self: SearchService, query: string, limit: int) -> int { // Locals: - let _0: string[] // _0 // return - let _1: (string, string | null) -> string[] throws never // narrowed - let _2: (string, int, string | null, int) -> string[] throws never [captured] - let _3: (string, string | null) -> string[] throws never + let _0: int // _0 // return + let _1: SearchService // self // param + let _2: string // query // param + let _3: int // limit // param + let _4: bool + let _5: string bb0: { - _2 = const fn user.SearchDocs; - _1 = make_closure lambda[0](copy _2); - _3 = copy _1; - _0 = call copy _3(const "cats", const "recent") -> [bb1]; + _4 = copy _3 == const ; + branch copy _4 -> [bb1, bb2]; } bb1: { - return; + _3 = const 20_i64; + goto -> bb2; } -} -// lambda[0] -fn .(query: string, filter: string | null) -> string[] { - // Locals: - let _0: string[] // _0 // return - let _1: string // query // param - let _2: string | null // filter // param - - bb0: { - _0 = call copy capture[0](copy _1, const , copy _2, const ) -> [bb1]; + bb2: { + _5 = copy _1.0; + _0 = call const fn user.Search(copy _2, copy _3, copy _5) -> [bb3]; } - bb1: { + bb3: { return; } } -fn user.UseRequiredByName() -> string[] { +fn user.SearchService.Docs(self: SearchService, query: string, filter: string | null) -> string[] { // Locals: let _0: string[] // _0 // return + let _1: SearchService // self // param + let _2: string // query // param + let _3: string | null // filter // param + let _4: bool bb0: { - _0 = call const fn user.SearchDocs(const "birds", const , const , const ) -> [bb1]; + _4 = copy _3 == const ; + branch copy _4 -> [bb1, bb2]; } bb1: { + _3 = const null; + goto -> bb2; + } + + bb2: { + _0 = call const fn user.SearchDocs(copy _2, const , copy _3, const ) -> [bb3]; + } + + bb3: { return; } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/parser_statements/baml_tests__compiles__parser_statements__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/parser_statements/baml_tests__compiles__parser_statements__04_5_mir.snap index c6c8618ef02..4a83b734815 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/parser_statements/baml_tests__compiles__parser_statements__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/parser_statements/baml_tests__compiles__parser_statements__04_5_mir.snap @@ -2,14 +2,14 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === -fn user.add_assign() -> int { +fn user.simple_assign() -> int { // Locals: let _0: int // _0 // return let _1: int // x bb0: { - _1 = const 10_i64; - _1 = copy _1 + const 5_i64; + _1 = const 1_i64; + _1 = const 5_i64; _0 = copy _1; goto -> bb1; } @@ -19,59 +19,31 @@ fn user.add_assign() -> int { } } -fn user.assign_in_loop() -> int { +fn user.add_assign() -> int { // Locals: let _0: int // _0 // return - let _1: int // sum - let _2: int // i - let _3: bool - let _4: int - let _5: int + let _1: int // x bb0: { - _1 = const 0_i64; - _2 = const 0_i64; + _1 = const 10_i64; + _1 = copy _1 + const 5_i64; + _0 = copy _1; goto -> bb1; } bb1: { - _4 = copy _2; - _3 = copy _4 < const 5_i64; - branch copy _3 -> [bb4, bb2]; - } - - bb2: { - _0 = copy _1; - goto -> bb3; - } - - bb3: { return; } - - bb4: { - _5 = copy _2; - _1 = copy _1 + copy _5; - _2 = copy _2 + const 1_i64; - goto -> bb1; - } } -fn user.block_with_tail() -> int { +fn user.sub_assign() -> int { // Locals: let _0: int // _0 // return let _1: int // x - let _2: int // y - let _3: int // z - let _4: int - let _5: int bb0: { - _2 = const 1_i64; - _3 = const 2_i64; - _4 = copy _2; - _5 = copy _3; - _1 = copy _4 + copy _5; + _1 = const 10_i64; + _1 = copy _1 - const 3_i64; _0 = copy _1; goto -> bb1; } @@ -81,105 +53,123 @@ fn user.block_with_tail() -> int { } } -fn user.edge_call_then_index(foo: () -> int[] throws never) -> int { +fn user.mul_assign() -> int { // Locals: let _0: int // _0 // return - let _1: () -> int[] throws never // foo // param - let _2: int[] - let _3: 0 + let _1: int // x bb0: { - _2 = call copy _1() -> [bb1]; + _1 = const 3_i64; + _1 = copy _1 * const 4_i64; + _0 = copy _1; + goto -> bb1; } bb1: { - _3 = const 0_i64; - _0 = const 1_i64; - goto -> bb2; - } - - bb2: { return; } } -fn user.edge_call_then_parens(foo: () -> ((int) -> int throws never) throws never) -> int { +fn user.multi_assign() -> int { // Locals: let _0: int // _0 // return - let _1: () -> ((int) -> int throws never) throws never // foo // param - let _2: int - let _3: (int) -> int throws never + let _1: int // a + let _2: int // b + let _3: int + let _4: int bb0: { - _3 = call copy _1() -> [bb1]; + _1 = const 1_i64; + _2 = const 2_i64; + _1 = const 10_i64; + _2 = const 20_i64; + _3 = copy _1; + _4 = copy _2; + _0 = copy _3 + copy _4; + goto -> bb1; } bb1: { - _2 = call copy _3(const 1_i64) -> [bb2]; - } - - bb2: { - _0 = const 2_i64; - goto -> bb3; - } - - bb3: { return; } } -fn user.edge_let_call_then_index(bar: () -> int[] throws never) -> int { +fn user.assign_in_loop() -> int { // Locals: let _0: int // _0 // return - let _1: () -> int[] throws never // bar // param - let _2: int // x - let _3: int[] - let _4: 0 + let _1: int // sum + let _2: int // i + let _3: bool + let _4: int + let _5: int bb0: { - _3 = call copy _1() -> [bb1]; + _1 = const 0_i64; + _2 = const 0_i64; + goto -> bb1; } bb1: { - _4 = const 0_i64; - _2 = copy _3[_4]; - _0 = copy _2; - goto -> bb2; + _4 = copy _2; + _3 = copy _4 < const 5_i64; + branch copy _3 -> [bb4, bb2]; } bb2: { + _0 = copy _1; + goto -> bb3; + } + + bb3: { return; } + + bb4: { + _5 = copy _2; + _1 = copy _1 + copy _5; + _2 = copy _2 + const 1_i64; + goto -> bb1; + } } -fn user.edge_semicolon_forces_boundary(bar: () -> int[] throws never) -> int { +fn user.block_with_tail() -> int { // Locals: let _0: int // _0 // return - let _1: () -> int[] throws never // bar // param - let _2: int[] + let _1: int // x + let _2: int // y + let _3: int // z + let _4: int + let _5: int bb0: { - _2 = call copy _1() -> [bb1]; + _2 = const 1_i64; + _3 = const 2_i64; + _4 = copy _2; + _5 = copy _3; + _1 = copy _4 + copy _5; + _0 = copy _1; + goto -> bb1; } bb1: { - _0 = const 1_i64; - goto -> bb2; - } - - bb2: { return; } } -fn user.edge_type_then_object() -> int { +fn user.let_no_semicolons() -> int { // Locals: let _0: int // _0 // return - let _1: EdgeFoo + let _1: int // x + let _2: int // y + let _3: int + let _4: int bb0: { - _1 = user.EdgeFoo { const 1_i64 }; - _0 = copy _1.0; + _1 = const 1_i64; + _2 = const 2_i64; + _3 = copy _1; + _4 = copy _2; + _0 = copy _3 + copy _4; goto -> bb1; } @@ -222,61 +212,61 @@ fn user.let_mixed_semicolons() -> int { } } -fn user.let_no_semicolons() -> int { +fn user.edge_call_then_parens(foo: () -> ((int) -> int throws never) throws never) -> int { // Locals: let _0: int // _0 // return - let _1: int // x - let _2: int // y - let _3: int - let _4: int + let _1: () -> ((int) -> int throws never) throws never // foo // param + let _2: int + let _3: (int) -> int throws never bb0: { - _1 = const 1_i64; - _2 = const 2_i64; - _3 = copy _1; - _4 = copy _2; - _0 = copy _3 + copy _4; - goto -> bb1; + _3 = call copy _1() -> [bb1]; } bb1: { + _2 = call copy _3(const 1_i64) -> [bb2]; + } + + bb2: { + _0 = const 2_i64; + goto -> bb3; + } + + bb3: { return; } } -fn user.mul_assign() -> int { +fn user.edge_call_then_index(foo: () -> int[] throws never) -> int { // Locals: let _0: int // _0 // return - let _1: int // x + let _1: () -> int[] throws never // foo // param + let _2: int[] + let _3: 0 bb0: { - _1 = const 3_i64; - _1 = copy _1 * const 4_i64; - _0 = copy _1; - goto -> bb1; + _2 = call copy _1() -> [bb1]; } bb1: { + _3 = const 0_i64; + _0 = const 1_i64; + goto -> bb2; + } + + bb2: { return; } } -fn user.multi_assign() -> int { +fn user.edge_type_then_object() -> int { // Locals: let _0: int // _0 // return - let _1: int // a - let _2: int // b - let _3: int - let _4: int + let _1: EdgeFoo bb0: { - _1 = const 1_i64; - _2 = const 2_i64; - _1 = const 10_i64; - _2 = const 20_i64; - _3 = copy _1; - _4 = copy _2; - _0 = copy _3 + copy _4; + _1 = user.EdgeFoo { const 1_i64 }; + _0 = copy _1.0; goto -> bb1; } @@ -285,60 +275,64 @@ fn user.multi_assign() -> int { } } -fn user.simple_assign() -> int { +fn user.edge_let_call_then_index(bar: () -> int[] throws never) -> int { // Locals: let _0: int // _0 // return - let _1: int // x + let _1: () -> int[] throws never // bar // param + let _2: int // x + let _3: int[] + let _4: 0 bb0: { - _1 = const 1_i64; - _1 = const 5_i64; - _0 = copy _1; - goto -> bb1; + _3 = call copy _1() -> [bb1]; } bb1: { + _4 = const 0_i64; + _2 = copy _3[_4]; + _0 = copy _2; + goto -> bb2; + } + + bb2: { return; } } -fn user.sub_assign() -> int { +fn user.edge_semicolon_forces_boundary(bar: () -> int[] throws never) -> int { // Locals: let _0: int // _0 // return - let _1: int // x + let _1: () -> int[] throws never // bar // param + let _2: int[] bb0: { - _1 = const 10_i64; - _1 = copy _1 - const 3_i64; - _0 = copy _1; - goto -> bb1; + _2 = call copy _1() -> [bb1]; } bb1: { + _0 = const 1_i64; + goto -> bb2; + } + + bb2: { return; } } -fn user.break_in_for() -> int { +fn user.simple_break() -> int { // Locals: let _0: int // _0 // return - let _1: int // i - let _2: bool - let _3: int bb0: { - _1 = const 0_i64; goto -> bb1; } bb1: { - _3 = copy _1; - _2 = copy _3 < const 10_i64; - branch copy _2 -> [bb2, bb2]; + branch const true -> [bb2, bb2]; } bb2: { - _0 = const 1_i64; + _0 = const 42_i64; goto -> bb3; } @@ -347,7 +341,7 @@ fn user.break_in_for() -> int { } } -fn user.break_with_locals() -> int { +fn user.simple_continue() -> int { // Locals: let _0: int // _0 // return @@ -356,30 +350,25 @@ fn user.break_with_locals() -> int { } bb1: { - branch const true -> [bb2, bb3]; + branch const true -> [bb1, bb2]; } bb2: { - branch const true -> [bb3, bb1]; + _0 = const 0_i64; + goto -> bb3; } bb3: { - _0 = const 4_i64; - goto -> bb4; - } - - bb4: { return; } } -fn user.continue_in_for() -> int { +fn user.break_in_for() -> int { // Locals: let _0: int // _0 // return let _1: int // i let _2: bool let _3: int - let _4: int bb0: { _1 = const 0_i64; @@ -389,39 +378,40 @@ fn user.continue_in_for() -> int { bb1: { _3 = copy _1; _2 = copy _3 < const 10_i64; - branch copy _2 -> [bb4, bb2]; + branch copy _2 -> [bb2, bb2]; } bb2: { - _0 = const 2_i64; + _0 = const 1_i64; goto -> bb3; } bb3: { return; } - - bb4: { - _4 = copy _1; - _1 = copy _4 + const 1_i64; - goto -> bb1; - } } -fn user.continue_with_locals() -> int { +fn user.continue_in_for() -> int { // Locals: let _0: int // _0 // return + let _1: int // i + let _2: bool + let _3: int + let _4: int bb0: { + _1 = const 0_i64; goto -> bb1; } bb1: { - branch const true -> [bb4, bb2]; + _3 = copy _1; + _2 = copy _3 < const 10_i64; + branch copy _2 -> [bb4, bb2]; } bb2: { - _0 = const 5_i64; + _0 = const 2_i64; goto -> bb3; } @@ -430,7 +420,9 @@ fn user.continue_with_locals() -> int { } bb4: { - branch const true -> [bb1, bb1]; + _4 = copy _1; + _1 = copy _4 + const 1_i64; + goto -> bb1; } } @@ -460,7 +452,7 @@ fn user.nested_break() -> int { } } -fn user.simple_break() -> int { +fn user.break_with_locals() -> int { // Locals: let _0: int // _0 // return @@ -469,20 +461,24 @@ fn user.simple_break() -> int { } bb1: { - branch const true -> [bb2, bb2]; + branch const true -> [bb2, bb3]; } bb2: { - _0 = const 42_i64; - goto -> bb3; + branch const true -> [bb3, bb1]; } bb3: { + _0 = const 4_i64; + goto -> bb4; + } + + bb4: { return; } } -fn user.simple_continue() -> int { +fn user.continue_with_locals() -> int { // Locals: let _0: int // _0 // return @@ -491,17 +487,21 @@ fn user.simple_continue() -> int { } bb1: { - branch const true -> [bb1, bb2]; + branch const true -> [bb4, bb2]; } bb2: { - _0 = const 0_i64; + _0 = const 5_i64; goto -> bb3; } bb3: { return; } + + bb4: { + branch const true -> [bb1, bb1]; + } } fn user.c_style_for_loop() -> int { @@ -722,16 +722,13 @@ fn user.let_statements() -> int { } } -fn user.nested_while_loop() -> int { +fn user.simple_while_loop() -> int { // Locals: let _0: int // _0 // return let _1: int // i let _2: bool let _3: int - let _4: int // j - let _5: bool - let _6: int - let _7: int + let _4: int bb0: { _1 = const 0_i64; @@ -754,30 +751,22 @@ fn user.nested_while_loop() -> int { } bb4: { - _4 = const 0_i64; - goto -> bb5; - } - - bb5: { - _6 = copy _4; - _5 = copy _6 < const 10_i64; - branch copy _5 -> [bb6, bb1]; - } - - bb6: { - _7 = copy _4; - _4 = copy _7 + const 1_i64; - goto -> bb5; + _4 = copy _1; + _1 = copy _4 + const 1_i64; + goto -> bb1; } } -fn user.simple_while_loop() -> int { +fn user.nested_while_loop() -> int { // Locals: let _0: int // _0 // return let _1: int // i let _2: bool let _3: int - let _4: int + let _4: int // j + let _5: bool + let _6: int + let _7: int bb0: { _1 = const 0_i64; @@ -800,8 +789,19 @@ fn user.simple_while_loop() -> int { } bb4: { - _4 = copy _1; - _1 = copy _4 + const 1_i64; - goto -> bb1; + _4 = const 0_i64; + goto -> bb5; + } + + bb5: { + _6 = copy _4; + _5 = copy _6 < const 10_i64; + branch copy _5 -> [bb6, bb1]; + } + + bb6: { + _7 = copy _4; + _4 = copy _7 + const 1_i64; + goto -> bb5; } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/patterns_class_destructure_namespaces/baml_tests__compiles__patterns_class_destructure_namespaces__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/patterns_class_destructure_namespaces/baml_tests__compiles__patterns_class_destructure_namespaces__04_5_mir.snap index 1bf387d2d06..6f5a4aec726 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/patterns_class_destructure_namespaces/baml_tests__compiles__patterns_class_destructure_namespaces__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/patterns_class_destructure_namespaces/baml_tests__compiles__patterns_class_destructure_namespaces__04_5_mir.snap @@ -2,24 +2,21 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === -fn user.DeepGenericDestructureNamespaceQualifiedLet() -> int { +fn user.DestructureQualifiedLet() -> int { // Locals: let _0: int // _0 // return - let _1: llm.openai.Outer // outer - let _2: llm.openai.Box - let _3: llm.openai.Outer - let _4: llm.openai.Box - let _5: string - let _6: string // value + let _1: llm.openai.Response // response + let _2: llm.openai.Response + let _3: int + let _4: int // score bb0: { - _2 = user.llm.openai.Box { const "done" }; - _1 = user.llm.openai.Outer { copy _2 }; - _3 = copy _1; - _4 = copy _3.0; - _5 = copy _4.0; - _6 = copy _5; - _0 = call const fn baml.String.length(copy _6) -> [bb1]; + _1 = user.llm.openai.Response { const "ok", const 41_i64 }; + _2 = copy _1; + _3 = copy _2.1; + _4 = copy _3; + _0 = copy _4; + goto -> bb1; } bb1: { @@ -27,28 +24,41 @@ fn user.DeepGenericDestructureNamespaceQualifiedLet() -> int { } } -fn user.DeepGenericDestructureQualifiedLet() -> int { +fn user.DestructureQualifiedMatch() -> int { // Locals: let _0: int // _0 // return - let _1: llm.openai.Outer // outer - let _2: llm.openai.Box - let _3: llm.openai.Outer - let _4: llm.openai.Box + let _1: llm.openai.Response // response + let _2: bool + let _3: int + let _4: bool let _5: int - let _6: int // value + let _6: int // matched bb0: { - _2 = user.llm.openai.Box { const 52_i64 }; - _1 = user.llm.openai.Outer { copy _2 }; - _3 = copy _1; - _4 = copy _3.0; - _5 = copy _4.0; + _1 = user.llm.openai.Response { const "ok", const 42_i64 }; + _2 = is_type(copy _1, llm.openai.Response); + branch copy _2 -> [bb1, bb2]; + } + + bb1: { + _3 = copy _1.1; + _4 = copy _3 == const 0_i64; + branch copy _4 -> [bb3, bb2]; + } + + bb2: { + _5 = copy _1.1; _6 = copy _5; _0 = copy _6; - goto -> bb1; + goto -> bb4; } - bb1: { + bb3: { + _0 = const 0_i64; + goto -> bb4; + } + + bb4: { return; } } @@ -114,20 +124,14 @@ fn user.DestructureNamespaceQualifiedMatch() -> int { } } -fn user.DestructureQualifiedLet() -> int { +fn user.TypePatternQualifiedLet() -> int { // Locals: let _0: int // _0 // return let _1: llm.openai.Response // response - let _2: llm.openai.Response - let _3: int - let _4: int // score bb0: { - _1 = user.llm.openai.Response { const "ok", const 41_i64 }; - _2 = copy _1; - _3 = copy _2.1; - _4 = copy _3; - _0 = copy _4; + _1 = user.llm.openai.Response { const "ok", const 43_i64 }; + _0 = copy _1.1; goto -> bb1; } @@ -136,59 +140,47 @@ fn user.DestructureQualifiedLet() -> int { } } -fn user.DestructureQualifiedMatch() -> int { +fn user.TypePatternQualifiedMatch() -> int { // Locals: let _0: int // _0 // return let _1: llm.openai.Response // response - let _2: bool - let _3: int - let _4: bool - let _5: int - let _6: int // matched bb0: { - _1 = user.llm.openai.Response { const "ok", const 42_i64 }; - _2 = is_type(copy _1, llm.openai.Response); - branch copy _2 -> [bb1, bb2]; + _1 = user.llm.openai.Response { const "ok", const 44_i64 }; + _0 = copy _1.1; + goto -> bb1; } bb1: { - _3 = copy _1.1; - _4 = copy _3 == const 0_i64; - branch copy _4 -> [bb3, bb2]; + return; } +} - bb2: { - _5 = copy _1.1; - _6 = copy _5; - _0 = copy _6; - goto -> bb4; - } +fn user.TypePatternNamespaceQualifiedLet() -> int { + // Locals: + let _0: int // _0 // return + let _1: llm.openai.Response // response - bb3: { - _0 = const 0_i64; - goto -> bb4; + bb0: { + _1 = user.llm.openai.Response { const "ok", const 47_i64 }; + _0 = copy _1.1; + goto -> bb1; } - bb4: { + bb1: { return; } } -fn user.GenericDestructureNamespaceQualifiedLet() -> int { +fn user.TypePatternNamespaceQualifiedMatch() -> int { // Locals: let _0: int // _0 // return - let _1: llm.openai.Box // boxed - let _2: llm.openai.Box - let _3: string - let _4: string // value + let _1: llm.openai.Response // response bb0: { - _1 = user.llm.openai.Box { const "ok" }; - _2 = copy _1; - _3 = copy _2.0; - _4 = copy _3; - _0 = call const fn baml.String.length(copy _4) -> [bb1]; + _1 = user.llm.openai.Response { const "ok", const 48_i64 }; + _0 = copy _1.1; + goto -> bb1; } bb1: { @@ -218,29 +210,23 @@ fn user.GenericDestructureQualifiedLet() -> int { } } -fn user.GenericTypePatternNamespaceQualifiedMatch() -> int { +fn user.GenericDestructureNamespaceQualifiedLet() -> int { // Locals: let _0: int // _0 // return - let _1: llm.openai.Box | llm.openai.Box // boxed - let _2: bool + let _1: llm.openai.Box // boxed + let _2: llm.openai.Box + let _3: string + let _4: string // value bb0: { - _1 = user.llm.openai.Box { const "ready" }; - _2 = is_type(copy _1, llm.openai.Box); - branch copy _2 -> [bb2, bb1]; + _1 = user.llm.openai.Box { const "ok" }; + _2 = copy _1; + _3 = copy _2.0; + _4 = copy _3; + _0 = call const fn baml.String.length(copy _4) -> [bb1]; } bb1: { - _0 = const 51_i64; - goto -> bb3; - } - - bb2: { - _0 = const 0_i64; - goto -> bb3; - } - - bb3: { return; } } @@ -272,46 +258,51 @@ fn user.GenericTypePatternQualifiedMatch() -> int { } } -fn user.TypePatternNamespaceQualifiedLet() -> int { +fn user.GenericTypePatternNamespaceQualifiedMatch() -> int { // Locals: let _0: int // _0 // return - let _1: llm.openai.Response // response + let _1: llm.openai.Box | llm.openai.Box // boxed + let _2: bool bb0: { - _1 = user.llm.openai.Response { const "ok", const 47_i64 }; - _0 = copy _1.1; - goto -> bb1; + _1 = user.llm.openai.Box { const "ready" }; + _2 = is_type(copy _1, llm.openai.Box); + branch copy _2 -> [bb2, bb1]; } bb1: { - return; + _0 = const 51_i64; + goto -> bb3; } -} - -fn user.TypePatternNamespaceQualifiedMatch() -> int { - // Locals: - let _0: int // _0 // return - let _1: llm.openai.Response // response - bb0: { - _1 = user.llm.openai.Response { const "ok", const 48_i64 }; - _0 = copy _1.1; - goto -> bb1; + bb2: { + _0 = const 0_i64; + goto -> bb3; } - bb1: { + bb3: { return; } } -fn user.TypePatternQualifiedLet() -> int { +fn user.DeepGenericDestructureQualifiedLet() -> int { // Locals: let _0: int // _0 // return - let _1: llm.openai.Response // response + let _1: llm.openai.Outer // outer + let _2: llm.openai.Box + let _3: llm.openai.Outer + let _4: llm.openai.Box + let _5: int + let _6: int // value bb0: { - _1 = user.llm.openai.Response { const "ok", const 43_i64 }; - _0 = copy _1.1; + _2 = user.llm.openai.Box { const 52_i64 }; + _1 = user.llm.openai.Outer { copy _2 }; + _3 = copy _1; + _4 = copy _3.0; + _5 = copy _4.0; + _6 = copy _5; + _0 = copy _6; goto -> bb1; } @@ -320,15 +311,24 @@ fn user.TypePatternQualifiedLet() -> int { } } -fn user.TypePatternQualifiedMatch() -> int { +fn user.DeepGenericDestructureNamespaceQualifiedLet() -> int { // Locals: let _0: int // _0 // return - let _1: llm.openai.Response // response + let _1: llm.openai.Outer // outer + let _2: llm.openai.Box + let _3: llm.openai.Outer + let _4: llm.openai.Box + let _5: string + let _6: string // value bb0: { - _1 = user.llm.openai.Response { const "ok", const 44_i64 }; - _0 = copy _1.1; - goto -> bb1; + _2 = user.llm.openai.Box { const "done" }; + _1 = user.llm.openai.Outer { copy _2 }; + _3 = copy _1; + _4 = copy _3.0; + _5 = copy _4.0; + _6 = copy _5; + _0 = call const fn baml.String.length(copy _6) -> [bb1]; } bb1: { diff --git a/baml_language/crates/baml_tests/snapshots/compiles/patterns_new/baml_tests__compiles__patterns_new__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/patterns_new/baml_tests__compiles__patterns_new__04_5_mir.snap index aa76cc6ba33..ce81cc88ef9 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/patterns_new/baml_tests__compiles__patterns_new__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/patterns_new/baml_tests__compiles__patterns_new__04_5_mir.snap @@ -2,11 +2,74 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === -fn user.bare_type_arm(v: int | string) -> int { +fn user.or_with_repeated_typed_binding(v: int | string) -> int { // Locals: let _0: int // _0 // return let _1: int | string // v // param let _2: bool + let _3: int // x + let _4: bool + let _5: int // x + + bb0: { + _2 = is_type(copy _1, int); + branch copy _2 -> [bb4, bb1]; + } + + bb1: { + _4 = is_type(copy _1, int); + branch copy _4 -> [bb3, bb2]; + } + + bb2: { + _0 = const 0_i64; + goto -> bb5; + } + + bb3: { + _5 = copy _1; + _0 = copy _5; + goto -> bb5; + } + + bb4: { + _3 = copy _1; + _0 = copy _3; + goto -> bb5; + } + + bb5: { + return; + } +} + +fn user.or_with_repeated_bare_binding(v: int) -> int { + // Locals: + let _0: int // _0 // return + let _1: int // v // param + let _2: int // x + + bb0: { + goto -> bb1; + } + + bb1: { + _2 = copy _1; + _0 = copy _2; + goto -> bb2; + } + + bb2: { + return; + } +} + +fn user.chain_narrow_then_wildcard(v: int | string | bool) -> int { + // Locals: + let _0: int // _0 // return + let _1: int | string | bool // v // param + let _2: bool + let _3: int // n bb0: { _2 = is_type(copy _1, int); @@ -14,12 +77,13 @@ fn user.bare_type_arm(v: int | string) -> int { } bb1: { - _0 = const 2_i64; + _0 = const 0_i64; goto -> bb3; } bb2: { - _0 = const 1_i64; + _3 = copy _1; + _0 = copy _3; goto -> bb3; } @@ -28,14 +92,14 @@ fn user.bare_type_arm(v: int | string) -> int { } } -fn user.call_either_int_caller(cb: ((int) -> int throws never) | ((bool) -> int throws never)) -> int { +fn user.bare_type_arm(v: int | string) -> int { // Locals: let _0: int // _0 // return - let _1: ((int) -> int throws never) | ((bool) -> int throws never) // cb // param + let _1: int | string // v // param let _2: bool bb0: { - _2 = is_type(copy _1, (int) -> int throws never); + _2 = is_type(copy _1, int); branch copy _2 -> [bb2, bb1]; } @@ -72,35 +136,28 @@ fn user.call_int_callback(cb: (int) -> int throws never) -> int { } } -fn user.call_with_callback(runner: (((int) -> int throws never) -> int throws never) | (((string) -> int throws never) -> int throws never)) -> int { +fn user.dispatch_callback(cb: ((int) -> int throws never) | ((string) -> string throws never)) -> int { // Locals: let _0: int // _0 // return - let _1: (((int) -> int throws never) -> int throws never) | (((string) -> int throws never) -> int throws never) // runner // param + let _1: ((int) -> int throws never) | ((string) -> string throws never) // cb // param let _2: bool - let _3: ((int) -> int throws never) -> int throws never // r - let _4: ((int) -> int throws never) -> int throws never - let _5: (int) -> int throws never - let _6: ((string) -> int throws never) -> int throws never // r - let _7: ((string) -> int throws never) -> int throws never - let _8: (string) -> int throws never + let _3: (int) -> int throws never // f + let _4: (int) -> int throws never bb0: { - _2 = is_type(copy _1, ((int) -> int throws never) -> int throws never); + _2 = is_type(copy _1, (int) -> int throws never); branch copy _2 -> [bb2, bb1]; } bb1: { - _6 = copy _1; - _7 = copy _6; - _8 = make_closure lambda[1](); - _0 = call copy _7(copy _8) -> [bb3]; + _0 = const 0_i64; + goto -> bb3; } bb2: { _3 = copy _1; _4 = copy _3; - _5 = make_closure lambda[0](); - _0 = call copy _4(copy _5) -> [bb3]; + _0 = call copy _4(const 0_i64) -> [bb3]; } bb3: { @@ -108,103 +165,93 @@ fn user.call_with_callback(runner: (((int) -> int throws never) -> int throws ne } } -// lambda[0] -fn .(x: int) -> null { +fn user.call_either_int_caller(cb: ((int) -> int throws never) | ((bool) -> int throws never)) -> int { // Locals: - let _0: null // _0 // return - let _1: int // x // param + let _0: int // _0 // return + let _1: ((int) -> int throws never) | ((bool) -> int throws never) // cb // param + let _2: bool bb0: { - _0 = copy _1 + const 1_i64; - goto -> bb1; + _2 = is_type(copy _1, (int) -> int throws never); + branch copy _2 -> [bb2, bb1]; } bb1: { - return; + _0 = const 2_i64; + goto -> bb3; } -} - -// lambda[1] -fn .(s: string) -> null { - // Locals: - let _0: null // _0 // return - let _1: string // s // param - bb0: { - _0 = const 0_i64; - goto -> bb1; + bb2: { + _0 = const 1_i64; + goto -> bb3; } - bb1: { + bb3: { return; } } -fn user.catch_chain_union(mode: int) -> int { +fn user.dispatch_with_wildcard(cb: ((int) -> int throws never) | ((string) -> int throws never)) -> int { // Locals: let _0: int // _0 // return - let _1: int // mode // param - let _2: unknown // e - let _3: bool - let _4: bool + let _1: ((int) -> int throws never) | ((string) -> int throws never) // cb // param + let _2: bool bb0: { - _0 = call const fn user.risky_error(copy _1) -> [bb5, unwind: bb1]; + _2 = is_type(copy _1, (int) -> int throws never); + branch copy _2 -> [bb2, bb1]; } bb1: { - _3 = is_type(copy _2, AppError); - branch copy _3 -> [bb4, bb2]; + _0 = const 0_i64; + goto -> bb3; } bb2: { - _4 = is_type(copy _2, string); - branch copy _4 -> [bb4, bb3]; - } - - bb3: { - rethrow copy _2; - } - - bb4: { _0 = const 1_i64; - goto -> bb5; + goto -> bb3; } - bb5: { + bb3: { return; } } -fn user.catch_paren_or_chain(mode: int) -> int { +fn user.unwrap_typed(cb: ((int) -> T throws never) | ((string) -> T throws never)) -> T { // Locals: - let _0: int // _0 // return - let _1: int // mode // param - let _2: unknown // e - let _3: bool - let _4: bool + let _0: T // _0 // return + let _1: ((int) -> T throws never) | ((string) -> T throws never) // cb // param + let _2: bool + let _3: (int) -> T throws never // f + let _4: (int) -> T throws never + let _5: bool + let _6: (string) -> T throws never // f + let _7: (string) -> T throws never bb0: { - _0 = call const fn user.risky_error(copy _1) -> [bb5, unwind: bb1]; + _2 = is_type(copy _1, (int) -> #0 throws never); + branch copy _2 -> [bb4, bb1]; } bb1: { - _3 = is_type(copy _2, AppError); - branch copy _3 -> [bb4, bb2]; + _5 = is_type(copy _1, (string) -> #0 throws never); + branch copy _5 -> [bb3, bb2]; } bb2: { - _4 = is_type(copy _2, string); - branch copy _4 -> [bb4, bb3]; + unreachable; } bb3: { - rethrow copy _2; + _6 = copy _1; + _7 = copy _6; + _0 = call copy _7(const "") -> [bb5]; } bb4: { - _0 = const 1_i64; - goto -> bb5; + _3 = copy _1; + _4 = copy _3; + _0 = call copy _4(const 0_i64) -> [bb5]; } bb5: { @@ -212,68 +259,74 @@ fn user.catch_paren_or_chain(mode: int) -> int { } } -fn user.catch_widening_chain(mode: int) -> int { +fn user.unwrap_curried(f: ((int) -> ((int) -> ((int) -> int throws never) throws never) throws never) | ((string) -> ((string) -> string throws never) throws never)) -> int { // Locals: let _0: int // _0 // return - let _1: int // mode // param - let _2: unknown // e - let _3: bool - let _4: bool + let _1: ((int) -> ((int) -> ((int) -> int throws never) throws never) throws never) | ((string) -> ((string) -> string throws never) throws never) // f // param + let _2: bool + let _3: (int) -> ((int) -> ((int) -> int throws never) throws never) throws never // triple + let _4: (int) -> int throws never + let _5: (int) -> ((int) -> int throws never) throws never + let _6: (int) -> ((int) -> ((int) -> int throws never) throws never) throws never bb0: { - _0 = call const fn user.risky_error(copy _1) -> [bb6, unwind: bb1]; + _2 = is_type(copy _1, (int) -> ((int) -> ((int) -> int throws never) throws never) throws never); + branch copy _2 -> [bb2, bb1]; } bb1: { - _3 = is_type(copy _2, string); - branch copy _3 -> [bb5, bb2]; + _0 = const 0_i64; + goto -> bb5; } bb2: { - _4 = is_type(copy _2, AppError); - branch copy _4 -> [bb4, bb3]; + _3 = copy _1; + _6 = copy _3; + _5 = call copy _6(const 1_i64) -> [bb3]; } bb3: { - rethrow copy _2; + _4 = call copy _5(const 2_i64) -> [bb4]; } bb4: { - _0 = const 2_i64; - goto -> bb6; + _0 = call copy _4(const 3_i64) -> [bb5]; } bb5: { - _0 = const 1_i64; - goto -> bb6; - } - - bb6: { return; } } -fn user.chain_narrow_then_wildcard(v: int | string | bool) -> int { +fn user.call_with_callback(runner: (((int) -> int throws never) -> int throws never) | (((string) -> int throws never) -> int throws never)) -> int { // Locals: let _0: int // _0 // return - let _1: int | string | bool // v // param + let _1: (((int) -> int throws never) -> int throws never) | (((string) -> int throws never) -> int throws never) // runner // param let _2: bool - let _3: int // n + let _3: ((int) -> int throws never) -> int throws never // r + let _4: ((int) -> int throws never) -> int throws never + let _5: (int) -> int throws never + let _6: ((string) -> int throws never) -> int throws never // r + let _7: ((string) -> int throws never) -> int throws never + let _8: (string) -> int throws never bb0: { - _2 = is_type(copy _1, int); + _2 = is_type(copy _1, ((int) -> int throws never) -> int throws never); branch copy _2 -> [bb2, bb1]; } bb1: { - _0 = const 0_i64; - goto -> bb3; + _6 = copy _1; + _7 = copy _6; + _8 = make_closure lambda[1](); + _0 = call copy _7(copy _8) -> [bb3]; } bb2: { _3 = copy _1; - _0 = copy _3; - goto -> bb3; + _4 = copy _3; + _5 = make_closure lambda[0](); + _0 = call copy _4(copy _5) -> [bb3]; } bb3: { @@ -281,72 +334,63 @@ fn user.chain_narrow_then_wildcard(v: int | string | bool) -> int { } } -fn user.dispatch_callback(cb: ((int) -> int throws never) | ((string) -> string throws never)) -> int { +// lambda[0] +fn .(x: int) -> null { // Locals: - let _0: int // _0 // return - let _1: ((int) -> int throws never) | ((string) -> string throws never) // cb // param - let _2: bool - let _3: (int) -> int throws never // f - let _4: (int) -> int throws never + let _0: null // _0 // return + let _1: int // x // param bb0: { - _2 = is_type(copy _1, (int) -> int throws never); - branch copy _2 -> [bb2, bb1]; + _0 = copy _1 + const 1_i64; + goto -> bb1; } bb1: { - _0 = const 0_i64; - goto -> bb3; + return; } +} - bb2: { - _3 = copy _1; - _4 = copy _3; - _0 = call copy _4(const 0_i64) -> [bb3]; +// lambda[1] +fn .(s: string) -> null { + // Locals: + let _0: null // _0 // return + let _1: string // s // param + + bb0: { + _0 = const 0_i64; + goto -> bb1; } - bb3: { + bb1: { return; } } -fn user.dispatch_with_wildcard(cb: ((int) -> int throws never) | ((string) -> int throws never)) -> int { +fn user.literal_widens_to_int(v: int) -> int { // Locals: let _0: int // _0 // return - let _1: ((int) -> int throws never) | ((string) -> int throws never) // cb // param - let _2: bool + let _1: int // v // param + let _2: int // n bb0: { - _2 = is_type(copy _1, (int) -> int throws never); - branch copy _2 -> [bb2, bb1]; + _2 = copy _1; + _0 = copy _2; + goto -> bb1; } bb1: { - _0 = const 0_i64; - goto -> bb3; - } - - bb2: { - _0 = const 1_i64; - goto -> bb3; - } - - bb3: { return; } } -fn user.fn_pattern(cb: (int) -> int throws never) -> int { +fn user.fn_return_widens(cb: (int) -> int | string throws never) -> int { // Locals: let _0: int // _0 // return - let _1: (int) -> int throws never // cb // param - let _2: (int) -> int throws never // f - let _3: (int) -> int throws never + let _1: (int) -> int | string throws never // cb // param bb0: { - _2 = copy _1; - _3 = copy _2; - _0 = call copy _3(const 0_i64) -> [bb1]; + _0 = const 1_i64; + goto -> bb1; } bb1: { @@ -354,10 +398,10 @@ fn user.fn_pattern(cb: (int) -> int throws never) -> int { } } -fn user.fn_return_widens(cb: (int) -> int | string throws never) -> int { +fn user.int_widens_to_alias(v: int | float) -> int { // Locals: let _0: int // _0 // return - let _1: (int) -> int | string throws never // cb // param + let _1: int | float // v // param bb0: { _0 = const 1_i64; @@ -369,100 +413,102 @@ fn user.fn_return_widens(cb: (int) -> int | string throws never) -> int { } } -fn user.for_let_ascription(items: int[]) -> int { +fn user.paren_chains_in_or(v: int) -> int { // Locals: let _0: int // _0 // return - let _1: int[] // items // param - let _2: int // sum - let _3: baml.iter.Iterator - let _4: unknown - let _5: bool - let _6: int - let _7: int | string // n + let _1: int // v // param + let _2: bool + let _3: bool bb0: { - _2 = const 0_i64; - _3 = virtual_call iter as baml.iter.Iterable(copy _1) -> [bb1]; + _2 = is_type(copy _1, int); + branch copy _2 -> [bb3, bb1]; } bb1: { - _4 = virtual_call next as baml.iter.Iterator(copy _3) -> [bb2]; + _3 = is_type(copy _1, int); + branch copy _3 -> [bb2, bb4]; } bb2: { - _5 = is_type(copy _4, baml.iter.Done); - branch copy _5 -> [bb4, bb3]; + _0 = const 1_i64; + goto -> bb4; } bb3: { - _6 = copy _4; - fresh_cell(_7); - _7 = copy _6; - _2 = copy _2 + const 1_i64; - goto -> bb1; + _0 = const 1_i64; + goto -> bb4; } bb4: { - _0 = copy _2; - goto -> bb5; + return; } +} - bb5: { +fn user.fn_pattern(cb: (int) -> int throws never) -> int { + // Locals: + let _0: int // _0 // return + let _1: (int) -> int throws never // cb // param + let _2: (int) -> int throws never // f + let _3: (int) -> int throws never + + bb0: { + _2 = copy _1; + _3 = copy _2; + _0 = call copy _3(const 0_i64) -> [bb1]; + } + + bb1: { return; } } -fn user.for_let_fn_narrow(items: ((int) -> int throws never)[]) -> int { +fn user.for_let_with_narrow(items: int[]) -> int { // Locals: let _0: int // _0 // return - let _1: ((int) -> int throws never)[] // items // param - let _2: int // total - let _3: baml.iter.Iterator int throws never> + let _1: int[] // items // param + let _2: int // sum + let _3: baml.iter.Iterator let _4: unknown let _5: bool - let _6: (int) -> int throws never - let _7: (int) -> int throws never // f + let _6: int + let _7: int // n let _8: int - let _9: (int) -> int throws never bb0: { _2 = const 0_i64; - _3 = virtual_call iter as baml.iter.Iterable int throws never, Error = never>(copy _1) -> [bb1]; + _3 = virtual_call iter as baml.iter.Iterable(copy _1) -> [bb1]; } bb1: { - _4 = virtual_call next as baml.iter.Iterator int throws never, Error = never>(copy _3) -> [bb2]; + _4 = virtual_call next as baml.iter.Iterator(copy _3) -> [bb2]; } bb2: { _5 = is_type(copy _4, baml.iter.Done); - branch copy _5 -> [bb5, bb3]; + branch copy _5 -> [bb4, bb3]; } bb3: { _6 = copy _4; fresh_cell(_7); _7 = copy _6; - _9 = copy _7; - _8 = call copy _9(const 0_i64) -> [bb4]; - } - - bb4: { + _8 = copy _7; _2 = copy _2 + copy _8; goto -> bb1; } - bb5: { + bb4: { _0 = copy _2; - goto -> bb6; + goto -> bb5; } - bb6: { + bb5: { return; } } -fn user.for_let_with_narrow(items: int[]) -> int { +fn user.for_let_ascription(items: int[]) -> int { // Locals: let _0: int // _0 // return let _1: int[] // items // param @@ -471,8 +517,7 @@ fn user.for_let_with_narrow(items: int[]) -> int { let _4: unknown let _5: bool let _6: int - let _7: int // n - let _8: int + let _7: int | string // n bb0: { _2 = const 0_i64; @@ -492,8 +537,7 @@ fn user.for_let_with_narrow(items: int[]) -> int { _6 = copy _4; fresh_cell(_7); _7 = copy _6; - _8 = copy _7; - _2 = copy _2 + copy _8; + _2 = copy _2 + const 1_i64; goto -> bb1; } @@ -507,167 +551,142 @@ fn user.for_let_with_narrow(items: int[]) -> int { } } -fn user.int_widens_to_alias(v: int | float) -> int { +fn user.for_let_fn_narrow(items: ((int) -> int throws never)[]) -> int { // Locals: let _0: int // _0 // return - let _1: int | float // v // param + let _1: ((int) -> int throws never)[] // items // param + let _2: int // total + let _3: baml.iter.Iterator int throws never> + let _4: unknown + let _5: bool + let _6: (int) -> int throws never + let _7: (int) -> int throws never // f + let _8: int + let _9: (int) -> int throws never bb0: { - _0 = const 1_i64; - goto -> bb1; + _2 = const 0_i64; + _3 = virtual_call iter as baml.iter.Iterable int throws never, Error = never>(copy _1) -> [bb1]; } bb1: { - return; + _4 = virtual_call next as baml.iter.Iterator int throws never, Error = never>(copy _3) -> [bb2]; } -} - -fn user.literal_widens_to_int(v: int) -> int { - // Locals: - let _0: int // _0 // return - let _1: int // v // param - let _2: int // n - bb0: { - _2 = copy _1; - _0 = copy _2; - goto -> bb1; + bb2: { + _5 = is_type(copy _4, baml.iter.Done); + branch copy _5 -> [bb5, bb3]; } - bb1: { - return; + bb3: { + _6 = copy _4; + fresh_cell(_7); + _7 = copy _6; + _9 = copy _7; + _8 = call copy _9(const 0_i64) -> [bb4]; } -} -fn user.match_nested_paren_union(v: (int | string)[]) -> int { - // Locals: - let _0: int // _0 // return - let _1: (int | string)[] // v // param - - bb0: { - _0 = const 1_i64; + bb4: { + _2 = copy _2 + copy _8; goto -> bb1; } - bb1: { - return; - } -} - -fn user.nested_paren_union_array_one(items: (int | string)[]) -> int { - // Locals: - let _0: int // _0 // return - let _1: (int | string)[] // items // param - - bb0: { - _0 = len(_1); - goto -> bb1; + bb5: { + _0 = copy _2; + goto -> bb6; } - bb1: { + bb6: { return; } } -fn user.nested_paren_union_array_optional(v: null | (int | string)[]) -> int { +fn user.risky_error(mode: int) -> int { // Locals: let _0: int // _0 // return - let _1: null | (int | string)[] // v // param + let _1: int // mode // param + let _2: bool + let _3: AppError bb0: { - _0 = const 1_i64; - goto -> bb1; + _2 = copy _1 == const 0_i64; + branch copy _2 -> [bb2, bb1]; } bb1: { - return; - } -} - -fn user.nested_paren_union_array_three(v: (int | string)[][]) -> int { - // Locals: - let _0: int // _0 // return - let _1: (int | string)[][] // v // param - - bb0: { - _0 = len(_1); - goto -> bb1; + throw const "boom"; } - bb1: { - return; + bb2: { + _3 = user.AppError { const 1_i64 }; + throw copy _3; } } -fn user.nested_paren_union_array_two(items: (int | string)[]) -> int { +fn user.catch_chain_union(mode: int) -> int { // Locals: let _0: int // _0 // return - let _1: (int | string)[] // items // param + let _1: int // mode // param + let _2: unknown // e + let _3: bool + let _4: bool bb0: { - _0 = len(_1); - goto -> bb1; + _0 = call const fn user.risky_error(copy _1) -> [bb5, unwind: bb1]; } bb1: { - return; + _3 = is_type(copy _2, AppError); + branch copy _3 -> [bb4, bb2]; } -} -fn user.or_with_repeated_bare_binding(v: int) -> int { - // Locals: - let _0: int // _0 // return - let _1: int // v // param - let _2: int // x + bb2: { + _4 = is_type(copy _2, string); + branch copy _4 -> [bb4, bb3]; + } - bb0: { - goto -> bb1; + bb3: { + rethrow copy _2; } - bb1: { - _2 = copy _1; - _0 = copy _2; - goto -> bb2; + bb4: { + _0 = const 1_i64; + goto -> bb5; } - bb2: { + bb5: { return; } } -fn user.or_with_repeated_typed_binding(v: int | string) -> int { +fn user.catch_paren_or_chain(mode: int) -> int { // Locals: let _0: int // _0 // return - let _1: int | string // v // param - let _2: bool - let _3: int // x + let _1: int // mode // param + let _2: unknown // e + let _3: bool let _4: bool - let _5: int // x bb0: { - _2 = is_type(copy _1, int); - branch copy _2 -> [bb4, bb1]; + _0 = call const fn user.risky_error(copy _1) -> [bb5, unwind: bb1]; } bb1: { - _4 = is_type(copy _1, int); - branch copy _4 -> [bb3, bb2]; + _3 = is_type(copy _2, AppError); + branch copy _3 -> [bb4, bb2]; } bb2: { - _0 = const 0_i64; - goto -> bb5; + _4 = is_type(copy _2, string); + branch copy _4 -> [bb4, bb3]; } bb3: { - _5 = copy _1; - _0 = copy _5; - goto -> bb5; + rethrow copy _2; } bb4: { - _3 = copy _1; - _0 = copy _3; + _0 = const 1_i64; goto -> bb5; } @@ -676,137 +695,118 @@ fn user.or_with_repeated_typed_binding(v: int | string) -> int { } } -fn user.paren_chains_in_or(v: int) -> int { +fn user.catch_widening_chain(mode: int) -> int { // Locals: let _0: int // _0 // return - let _1: int // v // param - let _2: bool + let _1: int // mode // param + let _2: unknown // e let _3: bool + let _4: bool bb0: { - _2 = is_type(copy _1, int); - branch copy _2 -> [bb3, bb1]; + _0 = call const fn user.risky_error(copy _1) -> [bb6, unwind: bb1]; } bb1: { - _3 = is_type(copy _1, int); - branch copy _3 -> [bb2, bb4]; + _3 = is_type(copy _2, string); + branch copy _3 -> [bb5, bb2]; } bb2: { - _0 = const 1_i64; - goto -> bb4; + _4 = is_type(copy _2, AppError); + branch copy _4 -> [bb4, bb3]; } bb3: { - _0 = const 1_i64; - goto -> bb4; + rethrow copy _2; } bb4: { + _0 = const 2_i64; + goto -> bb6; + } + + bb5: { + _0 = const 1_i64; + goto -> bb6; + } + + bb6: { return; } } -fn user.risky_error(mode: int) -> int { +fn user.nested_paren_union_array_one(items: (int | string)[]) -> int { // Locals: let _0: int // _0 // return - let _1: int // mode // param - let _2: bool - let _3: AppError + let _1: (int | string)[] // items // param bb0: { - _2 = copy _1 == const 0_i64; - branch copy _2 -> [bb2, bb1]; + _0 = len(_1); + goto -> bb1; } bb1: { - throw const "boom"; - } - - bb2: { - _3 = user.AppError { const 1_i64 }; - throw copy _3; + return; } } -fn user.unwrap_curried(f: ((int) -> ((int) -> ((int) -> int throws never) throws never) throws never) | ((string) -> ((string) -> string throws never) throws never)) -> int { +fn user.nested_paren_union_array_two(items: (int | string)[]) -> int { // Locals: let _0: int // _0 // return - let _1: ((int) -> ((int) -> ((int) -> int throws never) throws never) throws never) | ((string) -> ((string) -> string throws never) throws never) // f // param - let _2: bool - let _3: (int) -> ((int) -> ((int) -> int throws never) throws never) throws never // triple - let _4: (int) -> int throws never - let _5: (int) -> ((int) -> int throws never) throws never - let _6: (int) -> ((int) -> ((int) -> int throws never) throws never) throws never + let _1: (int | string)[] // items // param bb0: { - _2 = is_type(copy _1, (int) -> ((int) -> ((int) -> int throws never) throws never) throws never); - branch copy _2 -> [bb2, bb1]; + _0 = len(_1); + goto -> bb1; } bb1: { - _0 = const 0_i64; - goto -> bb5; - } - - bb2: { - _3 = copy _1; - _6 = copy _3; - _5 = call copy _6(const 1_i64) -> [bb3]; + return; } +} - bb3: { - _4 = call copy _5(const 2_i64) -> [bb4]; - } +fn user.nested_paren_union_array_three(v: (int | string)[][]) -> int { + // Locals: + let _0: int // _0 // return + let _1: (int | string)[][] // v // param - bb4: { - _0 = call copy _4(const 3_i64) -> [bb5]; + bb0: { + _0 = len(_1); + goto -> bb1; } - bb5: { + bb1: { return; } } -fn user.unwrap_typed(cb: ((int) -> T throws never) | ((string) -> T throws never)) -> T { +fn user.nested_paren_union_array_optional(v: null | (int | string)[]) -> int { // Locals: - let _0: T // _0 // return - let _1: ((int) -> T throws never) | ((string) -> T throws never) // cb // param - let _2: bool - let _3: (int) -> T throws never // f - let _4: (int) -> T throws never - let _5: bool - let _6: (string) -> T throws never // f - let _7: (string) -> T throws never + let _0: int // _0 // return + let _1: null | (int | string)[] // v // param bb0: { - _2 = is_type(copy _1, (int) -> #0 throws never); - branch copy _2 -> [bb4, bb1]; + _0 = const 1_i64; + goto -> bb1; } bb1: { - _5 = is_type(copy _1, (string) -> #0 throws never); - branch copy _5 -> [bb3, bb2]; - } - - bb2: { - unreachable; + return; } +} - bb3: { - _6 = copy _1; - _7 = copy _6; - _0 = call copy _7(const "") -> [bb5]; - } +fn user.match_nested_paren_union(v: (int | string)[]) -> int { + // Locals: + let _0: int // _0 // return + let _1: (int | string)[] // v // param - bb4: { - _3 = copy _1; - _4 = copy _3; - _0 = call copy _4(const 0_i64) -> [bb5]; + bb0: { + _0 = const 1_i64; + goto -> bb1; } - bb5: { + bb1: { return; } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/reflect_type_of_user_generic/baml_tests__compiles__reflect_type_of_user_generic__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/reflect_type_of_user_generic/baml_tests__compiles__reflect_type_of_user_generic__04_5_mir.snap index 16dec61ddc0..dd33dd1bc66 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/reflect_type_of_user_generic/baml_tests__compiles__reflect_type_of_user_generic__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/reflect_type_of_user_generic/baml_tests__compiles__reflect_type_of_user_generic__04_5_mir.snap @@ -2,12 +2,12 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === -fn user.reflect_array() -> type { +fn user.reflect_type() -> type { // Locals: let _0: type // _0 // return bb0: { - _0 = load_type(#0[]); + _0 = load_type(#0); goto -> bb1; } @@ -16,14 +16,13 @@ fn user.reflect_array() -> type { } } -fn user.reflect_int_array() -> type { +fn user.reflect_array() -> type { // Locals: let _0: type // _0 // return - let _1: type bb0: { - _1 = load_type(int); - _0 = call const fn user.reflect_array() -> [bb1]; + _0 = load_type(#0[]); + goto -> bb1; } bb1: { @@ -46,13 +45,14 @@ fn user.reflect_person() -> type { } } -fn user.reflect_type() -> type { +fn user.reflect_int_array() -> type { // Locals: let _0: type // _0 // return + let _1: type bb0: { - _0 = load_type(#0); - goto -> bb1; + _1 = load_type(int); + _0 = call const fn user.reflect_array() -> [bb1]; } bb1: { diff --git a/baml_language/crates/baml_tests/snapshots/compiles/scientific_notation_float/baml_tests__compiles__scientific_notation_float__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/scientific_notation_float/baml_tests__compiles__scientific_notation_float__04_5_mir.snap index e9ceb198f41..8843ceca44c 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/scientific_notation_float/baml_tests__compiles__scientific_notation_float__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/scientific_notation_float/baml_tests__compiles__scientific_notation_float__04_5_mir.snap @@ -2,12 +2,12 @@ source: crates/baml_tests/src/generated_tests.rs --- === MIR2 === -fn user.DecimalMantissa() -> float { +fn user.IntegerMantissa() -> float { // Locals: let _0: float // _0 // return bb0: { - _0 = const 1500_f64; + _0 = const 10000000000_f64; goto -> bb1; } @@ -16,12 +16,12 @@ fn user.DecimalMantissa() -> float { } } -fn user.DecimalMantissaNegativeExponent() -> float { +fn user.UppercaseExponent() -> float { // Locals: let _0: float // _0 // return bb0: { - _0 = const 0.0015_f64; + _0 = const 1000_f64; goto -> bb1; } @@ -30,12 +30,12 @@ fn user.DecimalMantissaNegativeExponent() -> float { } } -fn user.IntegerMantissa() -> float { +fn user.NegativeExponent() -> float { // Locals: let _0: float // _0 // return bb0: { - _0 = const 10000000000_f64; + _0 = const 0.001_f64; goto -> bb1; } @@ -44,12 +44,12 @@ fn user.IntegerMantissa() -> float { } } -fn user.NegativeExponent() -> float { +fn user.PositiveExponent() -> float { // Locals: let _0: float // _0 // return bb0: { - _0 = const 0.001_f64; + _0 = const 200000_f64; goto -> bb1; } @@ -58,12 +58,12 @@ fn user.NegativeExponent() -> float { } } -fn user.PositiveExponent() -> float { +fn user.DecimalMantissa() -> float { // Locals: let _0: float // _0 // return bb0: { - _0 = const 200000_f64; + _0 = const 1500_f64; goto -> bb1; } @@ -72,12 +72,12 @@ fn user.PositiveExponent() -> float { } } -fn user.UppercaseExponent() -> float { +fn user.DecimalMantissaNegativeExponent() -> float { // Locals: let _0: float // _0 // return bb0: { - _0 = const 1000_f64; + _0 = const 0.0015_f64; goto -> bb1; } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/stream_llm_inferred_typeargs/baml_tests__compiles__stream_llm_inferred_typeargs__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/stream_llm_inferred_typeargs/baml_tests__compiles__stream_llm_inferred_typeargs__04_5_mir.snap index 02068f64e23..d3229079a90 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/stream_llm_inferred_typeargs/baml_tests__compiles__stream_llm_inferred_typeargs__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/stream_llm_inferred_typeargs/baml_tests__compiles__stream_llm_inferred_typeargs__04_5_mir.snap @@ -111,6 +111,66 @@ fn user.TestFunc$build_request_stream(input: string, client: baml.llm.Client) -> } } +fn user.TestFunc$parse(json: string, client: baml.llm.Client) -> string { + // Locals: + let _0: string // _0 // return + let _1: string // json // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.TestClient; + goto -> bb2; + } + + bb2: { + _4 = load_type(string | null); + _5 = load_type(string); + _0 = call const fn baml.llm.parse(copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.TestFunc$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client) -> baml.llm.Stream { + // Locals: + let _0: baml.llm.Stream // _0 // return + let _1: baml.http.SseStream // sse // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.TestClient; + goto -> bb2; + } + + bb2: { + _4 = load_type(string | null); + _5 = load_type(string); + _0 = call const fn baml.llm.Client.__make_stream(copy _2, copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + fn user.TestFunc$render_prompt(input: string, client: baml.llm.Client) -> baml.llm.PromptAst { // Locals: let _0: baml.llm.PromptAst // _0 // return @@ -139,6 +199,38 @@ fn user.TestFunc$render_prompt(input: string, client: baml.llm.Client) -> baml.l } } +fn user.TestFunc$stream(input: string, client: baml.llm.Client) -> baml.llm.Stream { + // Locals: + let _0: baml.llm.Stream // _0 // return + let _1: string // input // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: map + let _5: type + let _6: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.TestClient; + goto -> bb2; + } + + bb2: { + _4 = { const "input": copy _1 }: map; + _5 = load_type(string | null); + _6 = load_type(string); + _0 = call const fn baml.llm.stream_llm_function(copy _2, const "TestFunc", copy _4, const ) -> [bb3]; + } + + bb3: { + return; + } +} + fn user.call_stream_inferred() -> baml.llm.Stream { // Locals: let _0: baml.llm.Stream // _0 // return diff --git a/baml_language/crates/baml_tests/snapshots/compiles/testset_vibes_nested/baml_tests__compiles__testset_vibes_nested__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/testset_vibes_nested/baml_tests__compiles__testset_vibes_nested__04_5_mir.snap index d2ba0601038..2a7ce12ace7 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/testset_vibes_nested/baml_tests__compiles__testset_vibes_nested__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/testset_vibes_nested/baml_tests__compiles__testset_vibes_nested__04_5_mir.snap @@ -309,6 +309,34 @@ fn ., 3)>, 4)>, 5)>() -> nul } } +fn user.GPT4o$new(lenient: bool) -> null { + // Locals: + let _0: null // _0 // return + let _1: bool // lenient // param + let _2: baml.llm.PrimitiveClientOptions + let _3: string + let _4: map + let _5: map + let _6: map + + bb0: { + _3 = call const fn baml.env.get_or_panic_lenient(const "OPENAI_API_KEY", copy _1) -> [bb1]; + } + + bb1: { + _4 = { }: map; + _5 = { }: map; + _6 = { }: map; + _2 = baml.llm.PrimitiveClientOptions { const "gpt-4o", const null, const null, const null, const null, const null, const null, const null, const null, copy _3, const null, const null, copy _4, copy _5, copy _6 }; + _0 = baml.llm.PrimitiveClient { const "GPT4o", const "openai", copy _2 }; + goto -> bb2; + } + + bb2: { + return; + } +} + fn user.ClassifySentiment(text: string, client: baml.llm.Client) -> Sentiment { // Locals: let _0: Sentiment // _0 // return @@ -395,13 +423,14 @@ fn user.ClassifySentiment$build_request_stream(text: string, client: baml.llm.Cl } } -fn user.ClassifySentiment$render_prompt(text: string, client: baml.llm.Client) -> baml.llm.PromptAst { +fn user.ClassifySentiment$parse(json: string, client: baml.llm.Client) -> Sentiment { // Locals: - let _0: baml.llm.PromptAst // _0 // return - let _1: string // text // param + let _0: Sentiment // _0 // return + let _1: string // json // param let _2: baml.llm.Client // client // param let _3: bool - let _4: map + let _4: type + let _5: type bb0: { _3 = copy _2 == const ; @@ -414,8 +443,9 @@ fn user.ClassifySentiment$render_prompt(text: string, client: baml.llm.Client) - } bb2: { - _4 = { const "text": copy _1 }: map; - _0 = call const fn baml.llm.render_prompt(copy _2, const "ClassifySentiment", copy _4, const ) -> [bb3]; + _4 = load_type(Sentiment$stream | null); + _5 = load_type(Sentiment); + _0 = call const fn baml.llm.parse(copy _1) -> [bb3]; } bb3: { @@ -423,13 +453,13 @@ fn user.ClassifySentiment$render_prompt(text: string, client: baml.llm.Client) - } } -fn user.ClassifySentiment2(text: string, client: baml.llm.Client) -> string { +fn user.ClassifySentiment$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client) -> baml.llm.Stream { // Locals: - let _0: string // _0 // return - let _1: string // text // param + let _0: baml.llm.Stream // _0 // return + let _1: baml.http.SseStream // sse // param let _2: baml.llm.Client // client // param let _3: bool - let _4: map + let _4: type let _5: type bb0: { @@ -443,9 +473,9 @@ fn user.ClassifySentiment2(text: string, client: baml.llm.Client) -> string { } bb2: { - _4 = { const "text": copy _1 }: map; - _5 = load_type(string); - _0 = call const fn baml.llm.call_llm_function(copy _2, const "ClassifySentiment2", copy _4, const ) -> [bb3]; + _4 = load_type(Sentiment$stream | null); + _5 = load_type(Sentiment); + _0 = call const fn baml.llm.Client.__make_stream(copy _2, copy _1) -> [bb3]; } bb3: { @@ -453,9 +483,9 @@ fn user.ClassifySentiment2(text: string, client: baml.llm.Client) -> string { } } -fn user.ClassifySentiment2$build_request(text: string, client: baml.llm.Client) -> baml.http.Request { +fn user.ClassifySentiment$render_prompt(text: string, client: baml.llm.Client) -> baml.llm.PromptAst { // Locals: - let _0: baml.http.Request // _0 // return + let _0: baml.llm.PromptAst // _0 // return let _1: string // text // param let _2: baml.llm.Client // client // param let _3: bool @@ -473,7 +503,7 @@ fn user.ClassifySentiment2$build_request(text: string, client: baml.llm.Client) bb2: { _4 = { const "text": copy _1 }: map; - _0 = call const fn baml.llm.build_request(copy _2, const "ClassifySentiment2", copy _4, const ) -> [bb3]; + _0 = call const fn baml.llm.render_prompt(copy _2, const "ClassifySentiment", copy _4, const ) -> [bb3]; } bb3: { @@ -481,13 +511,15 @@ fn user.ClassifySentiment2$build_request(text: string, client: baml.llm.Client) } } -fn user.ClassifySentiment2$build_request_stream(text: string, client: baml.llm.Client) -> baml.http.Request { +fn user.ClassifySentiment$stream(text: string, client: baml.llm.Client) -> baml.llm.Stream { // Locals: - let _0: baml.http.Request // _0 // return + let _0: baml.llm.Stream // _0 // return let _1: string // text // param let _2: baml.llm.Client // client // param let _3: bool let _4: map + let _5: type + let _6: type bb0: { _3 = copy _2 == const ; @@ -501,7 +533,9 @@ fn user.ClassifySentiment2$build_request_stream(text: string, client: baml.llm.C bb2: { _4 = { const "text": copy _1 }: map; - _0 = call const fn baml.llm.build_request_stream(copy _2, const "ClassifySentiment2", copy _4, const ) -> [bb3]; + _5 = load_type(Sentiment$stream | null); + _6 = load_type(Sentiment); + _0 = call const fn baml.llm.stream_llm_function(copy _2, const "ClassifySentiment", copy _4, const ) -> [bb3]; } bb3: { @@ -509,13 +543,103 @@ fn user.ClassifySentiment2$build_request_stream(text: string, client: baml.llm.C } } -fn user.ClassifySentiment2$render_prompt(text: string, client: baml.llm.Client) -> baml.llm.PromptAst { +fn user.GenerateTests(count: int, topic: string, client: baml.llm.Client) -> string[] { // Locals: - let _0: baml.llm.PromptAst // _0 // return - let _1: string // text // param + let _0: string[] // _0 // return + let _1: int // count // param + let _2: string // topic // param + let _3: baml.llm.Client // client // param + let _4: bool + let _5: map + let _6: type + + bb0: { + _4 = copy _3 == const ; + branch copy _4 -> [bb1, bb2]; + } + + bb1: { + _3 = const item user.GPT4o; + goto -> bb2; + } + + bb2: { + _5 = { const "count": copy _1, const "topic": copy _2 }: map; + _6 = load_type(string[]); + _0 = call const fn baml.llm.call_llm_function(copy _3, const "GenerateTests", copy _5, const ) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.GenerateTests$build_request(count: int, topic: string, client: baml.llm.Client) -> baml.http.Request { + // Locals: + let _0: baml.http.Request // _0 // return + let _1: int // count // param + let _2: string // topic // param + let _3: baml.llm.Client // client // param + let _4: bool + let _5: map + + bb0: { + _4 = copy _3 == const ; + branch copy _4 -> [bb1, bb2]; + } + + bb1: { + _3 = const item user.GPT4o; + goto -> bb2; + } + + bb2: { + _5 = { const "count": copy _1, const "topic": copy _2 }: map; + _0 = call const fn baml.llm.build_request(copy _3, const "GenerateTests", copy _5, const ) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.GenerateTests$build_request_stream(count: int, topic: string, client: baml.llm.Client) -> baml.http.Request { + // Locals: + let _0: baml.http.Request // _0 // return + let _1: int // count // param + let _2: string // topic // param + let _3: baml.llm.Client // client // param + let _4: bool + let _5: map + + bb0: { + _4 = copy _3 == const ; + branch copy _4 -> [bb1, bb2]; + } + + bb1: { + _3 = const item user.GPT4o; + goto -> bb2; + } + + bb2: { + _5 = { const "count": copy _1, const "topic": copy _2 }: map; + _0 = call const fn baml.llm.build_request_stream(copy _3, const "GenerateTests", copy _5, const ) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.GenerateTests$parse(json: string, client: baml.llm.Client) -> string[] { + // Locals: + let _0: string[] // _0 // return + let _1: string // json // param let _2: baml.llm.Client // client // param let _3: bool - let _4: map + let _4: type + let _5: type bb0: { _3 = copy _2 == const ; @@ -528,8 +652,101 @@ fn user.ClassifySentiment2$render_prompt(text: string, client: baml.llm.Client) } bb2: { - _4 = { const "text": copy _1 }: map; - _0 = call const fn baml.llm.render_prompt(copy _2, const "ClassifySentiment2", copy _4, const ) -> [bb3]; + _4 = load_type(string[]); + _5 = load_type(string[]); + _0 = call const fn baml.llm.parse(copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.GenerateTests$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client) -> baml.llm.Stream { + // Locals: + let _0: baml.llm.Stream // _0 // return + let _1: baml.http.SseStream // sse // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.GPT4o; + goto -> bb2; + } + + bb2: { + _4 = load_type(string[]); + _5 = load_type(string[]); + _0 = call const fn baml.llm.Client.__make_stream(copy _2, copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.GenerateTests$render_prompt(count: int, topic: string, client: baml.llm.Client) -> baml.llm.PromptAst { + // Locals: + let _0: baml.llm.PromptAst // _0 // return + let _1: int // count // param + let _2: string // topic // param + let _3: baml.llm.Client // client // param + let _4: bool + let _5: map + + bb0: { + _4 = copy _3 == const ; + branch copy _4 -> [bb1, bb2]; + } + + bb1: { + _3 = const item user.GPT4o; + goto -> bb2; + } + + bb2: { + _5 = { const "count": copy _1, const "topic": copy _2 }: map; + _0 = call const fn baml.llm.render_prompt(copy _3, const "GenerateTests", copy _5, const ) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.GenerateTests$stream(count: int, topic: string, client: baml.llm.Client) -> baml.llm.Stream { + // Locals: + let _0: baml.llm.Stream // _0 // return + let _1: int // count // param + let _2: string // topic // param + let _3: baml.llm.Client // client // param + let _4: bool + let _5: map + let _6: type + let _7: type + + bb0: { + _4 = copy _3 == const ; + branch copy _4 -> [bb1, bb2]; + } + + bb1: { + _3 = const item user.GPT4o; + goto -> bb2; + } + + bb2: { + _5 = { const "count": copy _1, const "topic": copy _2 }: map; + _6 = load_type(string[]); + _7 = load_type(string[]); + _0 = call const fn baml.llm.stream_llm_function(copy _3, const "GenerateTests", copy _5, const ) -> [bb3]; } bb3: { @@ -583,58 +800,57 @@ fn user.Foo() -> string | image { } } -fn user.GPT4o$new(lenient: bool) -> null { +fn user.ClassifySentiment2(text: string, client: baml.llm.Client) -> string { // Locals: - let _0: null // _0 // return - let _1: bool // lenient // param - let _2: baml.llm.PrimitiveClientOptions - let _3: string - let _4: map - let _5: map - let _6: map + let _0: string // _0 // return + let _1: string // text // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: map + let _5: type bb0: { - _3 = call const fn baml.env.get_or_panic_lenient(const "OPENAI_API_KEY", copy _1) -> [bb1]; + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } bb1: { - _4 = { }: map; - _5 = { }: map; - _6 = { }: map; - _2 = baml.llm.PrimitiveClientOptions { const "gpt-4o", const null, const null, const null, const null, const null, const null, const null, const null, copy _3, const null, const null, copy _4, copy _5, copy _6 }; - _0 = baml.llm.PrimitiveClient { const "GPT4o", const "openai", copy _2 }; + _2 = const item user.GPT4o; goto -> bb2; } bb2: { + _4 = { const "text": copy _1 }: map; + _5 = load_type(string); + _0 = call const fn baml.llm.call_llm_function(copy _2, const "ClassifySentiment2", copy _4, const ) -> [bb3]; + } + + bb3: { return; } } -fn user.GenerateTests(count: int, topic: string, client: baml.llm.Client) -> string[] { +fn user.ClassifySentiment2$build_request(text: string, client: baml.llm.Client) -> baml.http.Request { // Locals: - let _0: string[] // _0 // return - let _1: int // count // param - let _2: string // topic // param - let _3: baml.llm.Client // client // param - let _4: bool - let _5: map - let _6: type + let _0: baml.http.Request // _0 // return + let _1: string // text // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: map bb0: { - _4 = copy _3 == const ; - branch copy _4 -> [bb1, bb2]; + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } bb1: { - _3 = const item user.GPT4o; + _2 = const item user.GPT4o; goto -> bb2; } bb2: { - _5 = { const "count": copy _1, const "topic": copy _2 }: map; - _6 = load_type(string[]); - _0 = call const fn baml.llm.call_llm_function(copy _3, const "GenerateTests", copy _5, const ) -> [bb3]; + _4 = { const "text": copy _1 }: map; + _0 = call const fn baml.llm.build_request(copy _2, const "ClassifySentiment2", copy _4, const ) -> [bb3]; } bb3: { @@ -642,28 +858,27 @@ fn user.GenerateTests(count: int, topic: string, client: baml.llm.Client) -> str } } -fn user.GenerateTests$build_request(count: int, topic: string, client: baml.llm.Client) -> baml.http.Request { +fn user.ClassifySentiment2$build_request_stream(text: string, client: baml.llm.Client) -> baml.http.Request { // Locals: let _0: baml.http.Request // _0 // return - let _1: int // count // param - let _2: string // topic // param - let _3: baml.llm.Client // client // param - let _4: bool - let _5: map + let _1: string // text // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: map bb0: { - _4 = copy _3 == const ; - branch copy _4 -> [bb1, bb2]; + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } bb1: { - _3 = const item user.GPT4o; + _2 = const item user.GPT4o; goto -> bb2; } bb2: { - _5 = { const "count": copy _1, const "topic": copy _2 }: map; - _0 = call const fn baml.llm.build_request(copy _3, const "GenerateTests", copy _5, const ) -> [bb3]; + _4 = { const "text": copy _1 }: map; + _0 = call const fn baml.llm.build_request_stream(copy _2, const "ClassifySentiment2", copy _4, const ) -> [bb3]; } bb3: { @@ -671,28 +886,29 @@ fn user.GenerateTests$build_request(count: int, topic: string, client: baml.llm. } } -fn user.GenerateTests$build_request_stream(count: int, topic: string, client: baml.llm.Client) -> baml.http.Request { +fn user.ClassifySentiment2$parse(json: string, client: baml.llm.Client) -> string { // Locals: - let _0: baml.http.Request // _0 // return - let _1: int // count // param - let _2: string // topic // param - let _3: baml.llm.Client // client // param - let _4: bool - let _5: map + let _0: string // _0 // return + let _1: string // json // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type bb0: { - _4 = copy _3 == const ; - branch copy _4 -> [bb1, bb2]; + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } bb1: { - _3 = const item user.GPT4o; + _2 = const item user.GPT4o; goto -> bb2; } bb2: { - _5 = { const "count": copy _1, const "topic": copy _2 }: map; - _0 = call const fn baml.llm.build_request_stream(copy _3, const "GenerateTests", copy _5, const ) -> [bb3]; + _4 = load_type(string | null); + _5 = load_type(string); + _0 = call const fn baml.llm.parse(copy _1) -> [bb3]; } bb3: { @@ -700,28 +916,89 @@ fn user.GenerateTests$build_request_stream(count: int, topic: string, client: ba } } -fn user.GenerateTests$render_prompt(count: int, topic: string, client: baml.llm.Client) -> baml.llm.PromptAst { +fn user.ClassifySentiment2$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client) -> baml.llm.Stream { + // Locals: + let _0: baml.llm.Stream // _0 // return + let _1: baml.http.SseStream // sse // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: type + let _5: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.GPT4o; + goto -> bb2; + } + + bb2: { + _4 = load_type(string | null); + _5 = load_type(string); + _0 = call const fn baml.llm.Client.__make_stream(copy _2, copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.ClassifySentiment2$render_prompt(text: string, client: baml.llm.Client) -> baml.llm.PromptAst { // Locals: let _0: baml.llm.PromptAst // _0 // return - let _1: int // count // param - let _2: string // topic // param - let _3: baml.llm.Client // client // param - let _4: bool - let _5: map + let _1: string // text // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: map bb0: { - _4 = copy _3 == const ; - branch copy _4 -> [bb1, bb2]; + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; } bb1: { - _3 = const item user.GPT4o; + _2 = const item user.GPT4o; goto -> bb2; } bb2: { - _5 = { const "count": copy _1, const "topic": copy _2 }: map; - _0 = call const fn baml.llm.render_prompt(copy _3, const "GenerateTests", copy _5, const ) -> [bb3]; + _4 = { const "text": copy _1 }: map; + _0 = call const fn baml.llm.render_prompt(copy _2, const "ClassifySentiment2", copy _4, const ) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.ClassifySentiment2$stream(text: string, client: baml.llm.Client) -> baml.llm.Stream { + // Locals: + let _0: baml.llm.Stream // _0 // return + let _1: string // text // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: map + let _5: type + let _6: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _2 = const item user.GPT4o; + goto -> bb2; + } + + bb2: { + _4 = { const "text": copy _1 }: map; + _5 = load_type(string | null); + _6 = load_type(string); + _0 = call const fn baml.llm.stream_llm_function(copy _2, const "ClassifySentiment2", copy _4, const ) -> [bb3]; } bb3: { diff --git a/baml_language/crates/baml_tests/snapshots/compiles/type_annotation/baml_tests__compiles__type_annotation__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/type_annotation/baml_tests__compiles__type_annotation__04_5_mir.snap index c64503383f9..ccf593fc131 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/type_annotation/baml_tests__compiles__type_annotation__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/type_annotation/baml_tests__compiles__type_annotation__04_5_mir.snap @@ -42,10 +42,10 @@ fn user.test_let_binding(function_name: string) -> string { } } -fn user.test_list(function_name: string) -> string { +fn user.test_param(t: type) -> string { // Locals: let _0: string // _0 // return - let _1: string // function_name // param + let _1: type // t // param bb0: { _0 = const "ok"; @@ -57,14 +57,13 @@ fn user.test_list(function_name: string) -> string { } } -fn user.test_map(function_name: string) -> string { +fn user.test_return_type(function_name: string) -> type { // Locals: - let _0: string // _0 // return + let _0: type // _0 // return let _1: string // function_name // param bb0: { - _0 = const "ok"; - goto -> bb1; + _0 = sys_op const fn baml.llm.get_return_type(copy _1) -> bb1; } bb1: { @@ -87,10 +86,10 @@ fn user.test_optional(function_name: string) -> string { } } -fn user.test_param(t: type) -> string { +fn user.test_list(function_name: string) -> string { // Locals: let _0: string // _0 // return - let _1: type // t // param + let _1: string // function_name // param bb0: { _0 = const "ok"; @@ -102,13 +101,14 @@ fn user.test_param(t: type) -> string { } } -fn user.test_return_type(function_name: string) -> type { +fn user.test_union(function_name: string) -> string { // Locals: - let _0: type // _0 // return + let _0: string // _0 // return let _1: string // function_name // param bb0: { - _0 = sys_op const fn baml.llm.get_return_type(copy _1) -> bb1; + _0 = const "ok"; + goto -> bb1; } bb1: { @@ -116,7 +116,7 @@ fn user.test_return_type(function_name: string) -> type { } } -fn user.test_union(function_name: string) -> string { +fn user.test_map(function_name: string) -> string { // Locals: let _0: string // _0 // return let _1: string // function_name // param diff --git a/baml_language/crates/baml_tests/snapshots/compiles/type_builder_errors/baml_tests__compiles__type_builder_errors__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/type_builder_errors/baml_tests__compiles__type_builder_errors__04_5_mir.snap index a4e289704ad..ddd369e0e5c 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/type_builder_errors/baml_tests__compiles__type_builder_errors__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/type_builder_errors/baml_tests__compiles__type_builder_errors__04_5_mir.snap @@ -94,6 +94,70 @@ fn user.TypeBuilderFn$build_request_stream(from_text: string, client: baml.llm.C } } +fn user.TypeBuilderFn$parse(json: string, client: baml.llm.Client) -> Resume { + // Locals: + let _0: Resume // _0 // return + let _1: string // json // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: baml.llm.Client[] + let _5: type + let _6: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _4 = []: baml.llm.Client[]; + _2 = baml.llm.Client { const "openai/gpt-4o-mini", const baml.llm.ClientType.Primitive, copy _4, const null, const 0_i64 }; + goto -> bb2; + } + + bb2: { + _5 = load_type(Resume$stream | null); + _6 = load_type(Resume); + _0 = call const fn baml.llm.parse(copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.TypeBuilderFn$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client) -> baml.llm.Stream { + // Locals: + let _0: baml.llm.Stream // _0 // return + let _1: baml.http.SseStream // sse // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: baml.llm.Client[] + let _5: type + let _6: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _4 = []: baml.llm.Client[]; + _2 = baml.llm.Client { const "openai/gpt-4o-mini", const baml.llm.ClientType.Primitive, copy _4, const null, const 0_i64 }; + goto -> bb2; + } + + bb2: { + _5 = load_type(Resume$stream | null); + _6 = load_type(Resume); + _0 = call const fn baml.llm.Client.__make_stream(copy _2, copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + fn user.TypeBuilderFn$render_prompt(from_text: string, client: baml.llm.Client) -> baml.llm.PromptAst { // Locals: let _0: baml.llm.PromptAst // _0 // return @@ -123,3 +187,37 @@ fn user.TypeBuilderFn$render_prompt(from_text: string, client: baml.llm.Client) return; } } + +fn user.TypeBuilderFn$stream(from_text: string, client: baml.llm.Client) -> baml.llm.Stream { + // Locals: + let _0: baml.llm.Stream // _0 // return + let _1: string // from_text // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: baml.llm.Client[] + let _5: map + let _6: type + let _7: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _4 = []: baml.llm.Client[]; + _2 = baml.llm.Client { const "openai/gpt-4o-mini", const baml.llm.ClientType.Primitive, copy _4, const null, const 0_i64 }; + goto -> bb2; + } + + bb2: { + _5 = { const "from_text": copy _1 }: map; + _6 = load_type(Resume$stream | null); + _7 = load_type(Resume); + _0 = call const fn baml.llm.stream_llm_function(copy _2, const "TypeBuilderFn", copy _5, const ) -> [bb3]; + } + + bb3: { + return; + } +} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/type_builder_test/baml_tests__compiles__type_builder_test__04_5_mir.snap b/baml_language/crates/baml_tests/snapshots/compiles/type_builder_test/baml_tests__compiles__type_builder_test__04_5_mir.snap index 9abfb55f66c..03ed182d5d6 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/type_builder_test/baml_tests__compiles__type_builder_test__04_5_mir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/type_builder_test/baml_tests__compiles__type_builder_test__04_5_mir.snap @@ -91,6 +91,70 @@ fn user.Fn$build_request_stream(client: baml.llm.Client) -> baml.http.Request { } } +fn user.Fn$parse(json: string, client: baml.llm.Client) -> string { + // Locals: + let _0: string // _0 // return + let _1: string // json // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: baml.llm.Client[] + let _5: type + let _6: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _4 = []: baml.llm.Client[]; + _2 = baml.llm.Client { const "openai/gpt-4o", const baml.llm.ClientType.Primitive, copy _4, const null, const 0_i64 }; + goto -> bb2; + } + + bb2: { + _5 = load_type(string | null); + _6 = load_type(string); + _0 = call const fn baml.llm.parse(copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + +fn user.Fn$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client) -> baml.llm.Stream { + // Locals: + let _0: baml.llm.Stream // _0 // return + let _1: baml.http.SseStream // sse // param + let _2: baml.llm.Client // client // param + let _3: bool + let _4: baml.llm.Client[] + let _5: type + let _6: type + + bb0: { + _3 = copy _2 == const ; + branch copy _3 -> [bb1, bb2]; + } + + bb1: { + _4 = []: baml.llm.Client[]; + _2 = baml.llm.Client { const "openai/gpt-4o", const baml.llm.ClientType.Primitive, copy _4, const null, const 0_i64 }; + goto -> bb2; + } + + bb2: { + _5 = load_type(string | null); + _6 = load_type(string); + _0 = call const fn baml.llm.Client.__make_stream(copy _2, copy _1) -> [bb3]; + } + + bb3: { + return; + } +} + fn user.Fn$render_prompt(client: baml.llm.Client) -> baml.llm.PromptAst { // Locals: let _0: baml.llm.PromptAst // _0 // return @@ -119,3 +183,36 @@ fn user.Fn$render_prompt(client: baml.llm.Client) -> baml.llm.PromptAst { return; } } + +fn user.Fn$stream(client: baml.llm.Client) -> baml.llm.Stream { + // Locals: + let _0: baml.llm.Stream // _0 // return + let _1: baml.llm.Client // client // param + let _2: bool + let _3: baml.llm.Client[] + let _4: map + let _5: type + let _6: type + + bb0: { + _2 = copy _1 == const ; + branch copy _2 -> [bb1, bb2]; + } + + bb1: { + _3 = []: baml.llm.Client[]; + _1 = baml.llm.Client { const "openai/gpt-4o", const baml.llm.ClientType.Primitive, copy _3, const null, const 0_i64 }; + goto -> bb2; + } + + bb2: { + _4 = { }: map; + _5 = load_type(string | null); + _6 = load_type(string); + _0 = call const fn baml.llm.stream_llm_function(copy _1, const "Fn", copy _4, const ) -> [bb3]; + } + + bb3: { + return; + } +} From 920568a9007bd47bbc637012b3c44c7b821ff7ca Mon Sep 17 00:00:00 2001 From: 2kai2kai2 Date: Tue, 21 Jul 2026 10:40:43 -0700 Subject: [PATCH 05/10] CLI should use ItemTree firewall queries --- .../crates/baml_cli/src/bytecode_cache.rs | 201 ++++++++++-------- 1 file changed, 107 insertions(+), 94 deletions(-) diff --git a/baml_language/crates/baml_cli/src/bytecode_cache.rs b/baml_language/crates/baml_cli/src/bytecode_cache.rs index caa0ddb7fb6..ec4b9d1c4cd 100644 --- a/baml_language/crates/baml_cli/src/bytecode_cache.rs +++ b/baml_language/crates/baml_cli/src/bytecode_cache.rs @@ -45,7 +45,7 @@ use baml_db::{ generate_project_bytecode_with_reuse_artifacts, generate_project_bytecode_with_stdlib, generate_stdlib_program, reuse_throws_mismatches, }, - baml_compiler2_hir, + baml_compiler2_hir, baml_compiler2_ppir, }; use baml_project::ProjectDatabase; use bex_cache::{ @@ -744,50 +744,38 @@ fn last_segment(name: &str) -> &str { /// Last-segment names of every item `file` defines, from the HIR item tree. fn defined_names(db: &ProjectDatabase, file: SourceFile) -> Vec { - use baml_compiler2_hir::{ - contributions::Definition, - loc::{ClassLoc, EnumLoc, FunctionLoc, InterfaceLoc, LetLoc, TypeAliasLoc}, + use baml_compiler2_hir::contributions::Definition; + use baml_compiler2_ppir::item_data::{ + file_classes, file_enums, file_functions, file_interfaces, file_lets, file_type_aliases, }; use baml_db::baml_compiler2_mir::def_to_item_ref; - let item_tree = baml_compiler2_hir::file_item_tree(db, file); + let mut names: Vec = Vec::new(); - for local_id in item_tree.functions.keys() { - let fq = def_to_item_ref( - db, - Definition::Function(FunctionLoc::new(db, file, *local_id)), - ); - names.push(last_segment(&fq.to_string()).to_string()); + let push = |def, names: &mut Vec| { + names.push(last_segment(&def_to_item_ref(db, def).to_string()).to_string()); + }; + for &loc in file_functions(db, file) { + push(Definition::Function(loc), &mut names); } - for local_id in item_tree.lets.keys() { - let fq = def_to_item_ref(db, Definition::Let(LetLoc::new(db, file, *local_id))); - names.push(last_segment(&fq.to_string()).to_string()); + for &loc in file_lets(db, file) { + push(Definition::Let(loc), &mut names); } - for local_id in item_tree.classes.keys() { - let fq = def_to_item_ref(db, Definition::Class(ClassLoc::new(db, file, *local_id))); - names.push(last_segment(&fq.to_string()).to_string()); + for &loc in file_classes(db, file) { + push(Definition::Class(loc), &mut names); } - for local_id in item_tree.enums.keys() { - let fq = def_to_item_ref(db, Definition::Enum(EnumLoc::new(db, file, *local_id))); - names.push(last_segment(&fq.to_string()).to_string()); + for &loc in file_enums(db, file) { + push(Definition::Enum(loc), &mut names); } - for local_id in item_tree.interfaces.keys() { - let fq = def_to_item_ref( - db, - Definition::Interface(InterfaceLoc::new(db, file, *local_id)), - ); - names.push(last_segment(&fq.to_string()).to_string()); + for &loc in file_interfaces(db, file) { + push(Definition::Interface(loc), &mut names); } // Type aliases are erased into their consumers (a non-recursive alias is // expanded inline at every use), so an alias whose RHS changes must reach // the change-propagation set by *name*: a consumer that named the alias // would otherwise splice the stale expansion. `def_to_item_ref` handles // `TypeAlias` like any other named item. - for local_id in item_tree.type_aliases.keys() { - let fq = def_to_item_ref( - db, - Definition::TypeAlias(TypeAliasLoc::new(db, file, *local_id)), - ); - names.push(last_segment(&fq.to_string()).to_string()); + for &loc in file_type_aliases(db, file) { + push(Definition::TypeAlias(loc), &mut names); } names.sort_unstable(); names.dedup(); @@ -864,86 +852,106 @@ fn is_builtin_type_word(word: &str) -> bool { /// file to the dirty set, never removes one — while every real type name is /// always present as an identifier run. The floor this guarantees: any file /// naming a changed type in a signature is dirtied. +/// The firewall-`TypeRef` twin of [`add_type_display`]: render one type +/// reference from an item's `type_refs` arena and tokenize its name into `out`. +fn add_type_ref_display( + store: &baml_compiler2_hir::type_ref::TypeRefStore, + id: baml_compiler2_hir::type_ref::TypeRefId, + out: &mut HashSet, +) { + add_type_display(&store.display(id), out); +} + fn syntactic_type_names(db: &ProjectDatabase, file: SourceFile) -> HashSet { - let item_tree = baml_compiler2_hir::file_item_tree(db, file); + use baml_compiler2_ppir::item_data::{ + ImplSubjectData, class_data, file_classes, file_functions, file_impls, file_interfaces, + file_template_strings, file_type_aliases, function_data, impl_block_data, interface_data, + template_string_data, type_alias_data, + }; let mut names: HashSet = HashSet::new(); - for func in item_tree.functions.values() { - for te in func.params.iter().filter_map(|p| p.type_expr.as_ref()) { - add_type_display(te, &mut names); + for &loc in file_functions(db, file) { + let func = function_data(db, loc); + for id in func.params.iter().filter_map(|p| p.type_ref) { + add_type_ref_display(&func.type_refs, id, &mut names); } - if let Some(te) = &func.return_type { - add_type_display(te, &mut names); + if let Some(id) = func.return_type { + add_type_ref_display(&func.type_refs, id, &mut names); } - if let Some(te) = &func.throws { - add_type_display(te, &mut names); + if let Some(id) = func.throws { + add_type_ref_display(&func.type_refs, id, &mut names); } - for te in func.generic_param_bounds.iter().flatten() { - add_type_display(te, &mut names); + for id in func.generic_param_bounds.iter().flatten() { + add_type_ref_display(&func.type_refs, *id, &mut names); } } - for ts in item_tree.template_strings.values() { - for te in ts.params.iter().filter_map(|p| p.type_expr.as_ref()) { - add_type_display(te, &mut names); + for &loc in file_template_strings(db, file) { + let ts = template_string_data(db, loc); + for id in ts.params.iter().filter_map(|p| p.type_ref) { + add_type_ref_display(&ts.type_refs, id, &mut names); } } - for class in item_tree.classes.values() { - for te in class.fields.iter().filter_map(|f| f.type_expr.as_ref()) { - add_type_display(te, &mut names); + for &loc in file_classes(db, file) { + let class = class_data(db, loc); + for id in class.fields.iter().filter_map(|f| f.type_ref) { + add_type_ref_display(&class.type_refs, id, &mut names); } - for te in class.generic_param_bounds.iter().flatten() { - add_type_display(te, &mut names); + for id in class.generic_param_bounds.iter().flatten() { + add_type_ref_display(&class.type_refs, *id, &mut names); } for block in &class.implements { - add_type_display(&block.target, &mut names); + add_type_ref_display(&class.type_refs, block.target, &mut names); } } - for iface in item_tree.interfaces.values() { - for te in iface.fields.iter().filter_map(|f| f.type_expr.as_ref()) { - add_type_display(te, &mut names); + for &loc in file_interfaces(db, file) { + let iface = interface_data(db, loc); + for id in iface.fields.iter().filter_map(|f| f.type_ref) { + add_type_ref_display(&iface.type_refs, id, &mut names); } - for te in &iface.requires { - add_type_display(te, &mut names); + for id in &iface.requires { + add_type_ref_display(&iface.type_refs, *id, &mut names); } - for te in iface.generic_param_bounds.iter().flatten() { - add_type_display(te, &mut names); + for id in iface.generic_param_bounds.iter().flatten() { + add_type_ref_display(&iface.type_refs, *id, &mut names); } for method in &iface.required_methods { - for te in method.params.iter().filter_map(|p| p.type_expr.as_ref()) { - add_type_display(te, &mut names); + for id in method.params.iter().filter_map(|p| p.type_ref) { + add_type_ref_display(&iface.type_refs, id, &mut names); } - if let Some(te) = &method.return_type { - add_type_display(te, &mut names); + if let Some(id) = method.return_type { + add_type_ref_display(&iface.type_refs, id, &mut names); } - if let Some(te) = &method.throws { - add_type_display(te, &mut names); + if let Some(id) = method.throws { + add_type_ref_display(&iface.type_refs, id, &mut names); } - for te in method.generic_param_bounds.iter().flatten() { - add_type_display(te, &mut names); + for id in method.generic_param_bounds.iter().flatten() { + add_type_ref_display(&iface.type_refs, *id, &mut names); } } for assoc in &iface.associated_types { - if let Some(te) = &assoc.bound { - add_type_display(te, &mut names); + if let Some(id) = assoc.bound { + add_type_ref_display(&iface.type_refs, id, &mut names); } - if let Some(te) = &assoc.default { - add_type_display(te, &mut names); + if let Some(id) = assoc.default { + add_type_ref_display(&iface.type_refs, id, &mut names); } } } - for alias in item_tree.type_aliases.values() { - if let Some(te) = &alias.type_expr { - add_type_display(te, &mut names); + for &loc in file_type_aliases(db, file) { + let alias = type_alias_data(db, loc); + if let Some(id) = alias.value { + add_type_ref_display(&alias.type_refs, id, &mut names); } } - for imp in item_tree.impls.values() { - add_type_display(&imp.interface_target, &mut names); - // Out-of-body (`Free`) impls carry an explicit for-target `TypeExpr`; an - // in-class impl's for-target is the class itself (no `TypeExpr` to - // display). `names` is a set, so the interface_target added above is not + for &loc in file_impls(db, file) { + let block = impl_block_data(db, loc); + add_type_ref_display(&block.type_refs, block.interface_target, &mut names); + // Out-of-body (`Free`) impls carry an explicit for-target; an in-class + // impl's for-target is the class itself (no header type to display). + // `names` is a set, so the interface_target added above is not // double-counted for free impls. - if let baml_compiler2_hir::item_tree::ImplSubject::Free { for_target, .. } = &imp.subject { - add_type_display(for_target, &mut names); + if let ImplSubjectData::Free { for_target, .. } = &block.subject { + add_type_ref_display(&block.type_refs, *for_target, &mut names); } } names @@ -956,11 +964,13 @@ fn syntactic_type_names(db: &ProjectDatabase, file: SourceFile) -> HashSet bool { - let item_tree = baml_compiler2_hir::file_item_tree(db, file); - !item_tree.classes.is_empty() - || !item_tree.enums.is_empty() - || !item_tree.interfaces.is_empty() - || !item_tree.type_aliases.is_empty() + use baml_compiler2_ppir::item_data::{ + file_classes, file_enums, file_interfaces, file_type_aliases, + }; + !file_classes(db, file).is_empty() + || !file_enums(db, file).is_empty() + || !file_interfaces(db, file).is_empty() + || !file_type_aliases(db, file).is_empty() } /// Whether `file` declares any interface-`impl` construct — an `impl` block, an @@ -968,10 +978,13 @@ fn file_defines_type(db: &ProjectDatabase, file: SourceFile) -> bool { /// `IMPL_SENTINEL`: only a change to such a file can move the package's impl set /// (and thus a coherence verdict), so an impl-free edit never trips the fallback. fn file_has_impl_construct(db: &ProjectDatabase, file: SourceFile) -> bool { - let item_tree = baml_compiler2_hir::file_item_tree(db, file); - // The unified `impls` map holds both in-class and out-of-body impl blocks; a - // class `implements` block is a distinct construct, so it needs its own check. - !item_tree.impls.is_empty() || item_tree.classes.values().any(|c| !c.implements.is_empty()) + use baml_compiler2_ppir::item_data::{class_data, file_classes, file_impls}; + // `file_impls` holds both in-class and out-of-body impl blocks; a class + // `implements` block is a distinct construct, so it needs its own check. + !file_impls(db, file).is_empty() + || file_classes(db, file) + .iter() + .any(|&loc| !class_data(db, loc).implements.is_empty()) } /// Last-segment names referenced by each user file's compiled bytecode, @@ -3168,13 +3181,13 @@ mod tests { )]); let file = file_named(&db, "a.baml"); let (f_id, g_id) = { - let item_tree = baml_compiler2_hir::file_item_tree(&db, file); + use baml_compiler2_ppir::item_data::{file_functions, function_data}; let mut f_id = None; let mut g_id = None; - for (lid, func) in &item_tree.functions { - match func.name.as_str() { - "f" => f_id = Some(*lid), - "g" => g_id = Some(*lid), + for &loc in file_functions(&db, file) { + match function_data(&db, loc).name.as_str() { + "f" => f_id = Some(loc.id(&db)), + "g" => g_id = Some(loc.id(&db)), _ => {} } } From 1b9b9804d20209f8e6d9b931ee908ad352d05e79 Mon Sep 17 00:00:00 2001 From: 2kai2kai2 Date: Tue, 21 Jul 2026 12:05:11 -0700 Subject: [PATCH 06/10] Per-phase `baml_tests` should use ItemTree firewall queries --- ..._default_prologue_and_source_omission.snap | 26 +- ...piler2_mir__optional_dropping_adapter.snap | 70 ++-- ..._optional_named_gap_and_explicit_null.snap | 52 +-- .../crates/baml_tests/src/compiler2_hir.rs | 120 ++++--- .../baml_tests/src/compiler2_mir/mod.rs | 28 +- .../baml_tests/src/compiler2_tir/inference.rs | 15 +- .../baml_tests/src/compiler2_tir/mod.rs | 326 +++++++++--------- .../baml_tests/src/compiler2_tir/phase3a.rs | 19 +- .../baml_tests/src/compiler2_tir/phase5.rs | 40 ++- .../baml_tests/src/incremental/scenarios.rs | 135 ++++---- 10 files changed, 421 insertions(+), 410 deletions(-) diff --git a/baml_language/crates/baml_tests/snapshots/compiler2_mir/baml_tests__compiler2_mir__optional_default_prologue_and_source_omission.snap b/baml_language/crates/baml_tests/snapshots/compiler2_mir/baml_tests__compiler2_mir__optional_default_prologue_and_source_omission.snap index c0f745b4b92..112f0bd3eef 100644 --- a/baml_language/crates/baml_tests/snapshots/compiler2_mir/baml_tests__compiler2_mir__optional_default_prologue_and_source_omission.snap +++ b/baml_language/crates/baml_tests/snapshots/compiler2_mir/baml_tests__compiler2_mir__optional_default_prologue_and_source_omission.snap @@ -1,19 +1,6 @@ --- source: crates/baml_tests/src/compiler2_mir/mod.rs --- -fn user.main() -> int { - // Locals: - let _0: int // _0 // return - - bb0: { - _0 = call const fn user.add(const 5_i64, const ) -> [bb1]; - } - - bb1: { - return; - } -} - fn user.add(base: int, amount: int) -> int { // Locals: let _0: int // _0 // return @@ -40,3 +27,16 @@ fn user.add(base: int, amount: int) -> int { return; } } + +fn user.main() -> int { + // Locals: + let _0: int // _0 // return + + bb0: { + _0 = call const fn user.add(const 5_i64, const ) -> [bb1]; + } + + bb1: { + return; + } +} diff --git a/baml_language/crates/baml_tests/snapshots/compiler2_mir/baml_tests__compiler2_mir__optional_dropping_adapter.snap b/baml_language/crates/baml_tests/snapshots/compiler2_mir/baml_tests__compiler2_mir__optional_dropping_adapter.snap index 1526f2a79a7..748de14a79e 100644 --- a/baml_language/crates/baml_tests/snapshots/compiler2_mir/baml_tests__compiler2_mir__optional_dropping_adapter.snap +++ b/baml_language/crates/baml_tests/snapshots/compiler2_mir/baml_tests__compiler2_mir__optional_dropping_adapter.snap @@ -1,41 +1,6 @@ --- source: crates/baml_tests/src/compiler2_mir/mod.rs --- -fn user.main() -> int { - // Locals: - let _0: int // _0 // return - let _1: (int, int) -> int throws never // f - let _2: (int, int, int) -> int throws never [captured] - let _3: (int, int) -> int throws never - - bb0: { - _2 = const fn user.combine; - _1 = make_closure lambda[0](copy _2); - _3 = copy _1; - _0 = call copy _3(const 1_i64, const 5_i64) -> [bb1]; - } - - bb1: { - return; - } -} - -// lambda[0] -fn .(x: int, b: int) -> int { - // Locals: - let _0: int // _0 // return - let _1: int // x // param - let _2: int // b // param - - bb0: { - _0 = call copy capture[0](copy _1, const , copy _2) -> [bb1]; - } - - bb1: { - return; - } -} - fn user.combine(x: int, a: int, b: int) -> int { // Locals: let _0: int // _0 // return @@ -76,3 +41,38 @@ fn user.combine(x: int, a: int, b: int) -> int { return; } } + +fn user.main() -> int { + // Locals: + let _0: int // _0 // return + let _1: (int, int) -> int throws never // f + let _2: (int, int, int) -> int throws never [captured] + let _3: (int, int) -> int throws never + + bb0: { + _2 = const fn user.combine; + _1 = make_closure lambda[0](copy _2); + _3 = copy _1; + _0 = call copy _3(const 1_i64, const 5_i64) -> [bb1]; + } + + bb1: { + return; + } +} + +// lambda[0] +fn .(x: int, b: int) -> int { + // Locals: + let _0: int // _0 // return + let _1: int // x // param + let _2: int // b // param + + bb0: { + _0 = call copy capture[0](copy _1, const , copy _2) -> [bb1]; + } + + bb1: { + return; + } +} diff --git a/baml_language/crates/baml_tests/snapshots/compiler2_mir/baml_tests__compiler2_mir__optional_named_gap_and_explicit_null.snap b/baml_language/crates/baml_tests/snapshots/compiler2_mir/baml_tests__compiler2_mir__optional_named_gap_and_explicit_null.snap index f41526c8757..ea2ff52c882 100644 --- a/baml_language/crates/baml_tests/snapshots/compiler2_mir/baml_tests__compiler2_mir__optional_named_gap_and_explicit_null.snap +++ b/baml_language/crates/baml_tests/snapshots/compiler2_mir/baml_tests__compiler2_mir__optional_named_gap_and_explicit_null.snap @@ -1,32 +1,6 @@ --- source: crates/baml_tests/src/compiler2_mir/mod.rs --- -fn user.explicit_null() -> bool { - // Locals: - let _0: bool // _0 // return - - bb0: { - _0 = call const fn user.is_null(const null) -> [bb1]; - } - - bb1: { - return; - } -} - -fn user.omitted_middle() -> int { - // Locals: - let _0: int // _0 // return - - bb0: { - _0 = call const fn user.score(const "cats", const , const "recent") -> [bb1]; - } - - bb1: { - return; - } -} - fn user.score(query: string, max_results: int, filter: string | null) -> int { // Locals: let _0: int // _0 // return @@ -104,3 +78,29 @@ fn user.is_null(value: int | null) -> bool { return; } } + +fn user.omitted_middle() -> int { + // Locals: + let _0: int // _0 // return + + bb0: { + _0 = call const fn user.score(const "cats", const , const "recent") -> [bb1]; + } + + bb1: { + return; + } +} + +fn user.explicit_null() -> bool { + // Locals: + let _0: bool // _0 // return + + bb0: { + _0 = call const fn user.is_null(const null) -> [bb1]; + } + + bb1: { + return; + } +} diff --git a/baml_language/crates/baml_tests/src/compiler2_hir.rs b/baml_language/crates/baml_tests/src/compiler2_hir.rs index ff227aeada1..5f9760d36c3 100644 --- a/baml_language/crates/baml_tests/src/compiler2_hir.rs +++ b/baml_language/crates/baml_tests/src/compiler2_hir.rs @@ -34,14 +34,15 @@ mod tests { file: baml_base::SourceFile, name: &str, ) -> FunctionLoc<'db> { - let item_tree = baml_compiler2_hir::file_item_tree(db, file); - let local_id = item_tree - .functions + *baml_compiler2_ppir::item_data::file_functions(db, file) .iter() - .find(|(_, func)| func.name.as_str() == name) - .map(|(local_id, _)| *local_id) - .unwrap_or_else(|| panic!("missing function {name}")); - FunctionLoc::new(db, file, local_id) + .find(|&&loc| { + baml_compiler2_ppir::item_data::function_data(db, loc) + .name + .as_str() + == name + }) + .unwrap_or_else(|| panic!("missing function {name}")) } fn find_method_loc<'db>( @@ -50,19 +51,25 @@ mod tests { class_name: &str, method_name: &str, ) -> FunctionLoc<'db> { - let item_tree = baml_compiler2_hir::file_item_tree(db, file); - let class = item_tree - .classes - .values() - .find(|class| class.name.as_str() == class_name) + let class_loc = *baml_compiler2_ppir::item_data::file_classes(db, file) + .iter() + .find(|&&loc| { + baml_compiler2_ppir::item_data::class_data(db, loc) + .name + .as_str() + == class_name + }) .unwrap_or_else(|| panic!("missing class {class_name}")); - let method_id = class + *baml_compiler2_ppir::item_data::class_data(db, class_loc) .methods .iter() - .find(|method_id| item_tree[**method_id].name.as_str() == method_name) - .copied() - .unwrap_or_else(|| panic!("missing method {class_name}.{method_name}")); - FunctionLoc::new(db, file, method_id) + .find(|&&method_loc| { + baml_compiler2_ppir::item_data::function_data(db, method_loc) + .name + .as_str() + == method_name + }) + .unwrap_or_else(|| panic!("missing method {class_name}.{method_name}")) } // ── 1. Targeted unit test: multi-file package_items ────────────────────── @@ -222,7 +229,7 @@ mod tests { assert!(ns.types.contains_key(&Name::new("Widget"))); } - // ── 3. file_item_tree Index access ──────────────────────────────────────── + // ── 3. item-data firewall: function data + impl representation ───────────── /// The enriched ItemTree stores function params and return types. #[test] @@ -233,14 +240,14 @@ mod tests { "function greet(name: string) -> string { client C\nprompt #\"hi\"# }", ); - let item_tree = baml_compiler2_hir::file_item_tree(&db, file); - - // Find the function in the item tree - let func = item_tree - .functions - .values() - .find(|f| f.name == Name::new("greet")); - let func = func.expect("function 'greet' should be in item tree"); + // Find the function via the firewall. + let greet = *baml_compiler2_ppir::item_data::file_functions(&db, file) + .iter() + .find(|&&loc| { + baml_compiler2_ppir::item_data::function_data(&db, loc).name == Name::new("greet") + }) + .expect("function 'greet' should be in item tree"); + let func = baml_compiler2_ppir::item_data::function_data(&db, greet); assert_eq!( func.params.len(), @@ -269,8 +276,6 @@ mod tests { /// `class_to_impls` indexes every `InClass` impl. #[test] fn impls_map_is_consistent_with_legacy_representation() { - use baml_compiler2_hir::item_tree::ImplSubject; - let mut db = make_db(); let file = db.add_file( "impls.baml", @@ -299,39 +304,52 @@ mod tests { "#, ); - let item_tree = baml_compiler2_hir::file_item_tree(&db, file); + use baml_compiler2_ppir::item_data::{ + ImplSubjectData, class_data, class_impls, file_classes, file_free_impls, file_impls, + impl_block_data, + }; - let legacy_in_class: usize = item_tree.classes.values().map(|c| c.implements.len()).sum(); - let legacy_out_of_body = item_tree.free_impls.len(); + let legacy_in_class: usize = file_classes(&db, file) + .iter() + .map(|&c| class_data(&db, c).implements.len()) + .sum(); + let legacy_out_of_body = file_free_impls(&db, file).len(); // One ImplBlock per legacy entry. assert_eq!( - item_tree.impls.len(), + file_impls(&db, file).len(), legacy_in_class + legacy_out_of_body, "expected one ImplBlock per legacy impl entry" ); // Subject partition matches the legacy split. - let in_class = item_tree - .impls - .values() - .filter(|b| matches!(b.subject, ImplSubject::InClass { .. })) + let in_class = file_impls(&db, file) + .iter() + .filter(|&&b| { + matches!( + impl_block_data(&db, b).subject, + ImplSubjectData::InClass { .. } + ) + }) .count(); assert_eq!(in_class, legacy_in_class, "InClass count mismatch"); assert_eq!( - item_tree.impls.len() - in_class, + file_impls(&db, file).len() - in_class, legacy_out_of_body, "Free count mismatch" ); - // `class_to_impls` indexes exactly the InClass impls. - let indexed: usize = item_tree.class_to_impls.values().map(|v| v.len()).sum(); + // `class_impls` indexes exactly the InClass impls. + let indexed: usize = file_classes(&db, file) + .iter() + .map(|&c| class_impls(&db, c).len()) + .sum(); assert_eq!(indexed, legacy_in_class, "class_to_impls coverage mismatch"); // Every impl carries its lowered method ids (here, `show`). - for block in item_tree.impls.values() { + for &block in file_impls(&db, file) { assert!( - !block.methods.is_empty(), + !impl_block_data(&db, block).methods.is_empty(), "impl block should carry its method ids" ); } @@ -367,16 +385,17 @@ mod tests { ); let pkg_id = PackageId::new(&db, Name::new("user")); - let tree = baml_compiler2_hir::file_item_tree(&db, file); let aliases = std::collections::HashMap::new(); let class_ty = |class_name: &str| { - let (id, data) = tree - .classes + let loc = *baml_compiler2_ppir::item_data::file_classes(&db, file) .iter() - .find(|(_, c)| c.name == Name::new(class_name)) + .find(|&&loc| { + baml_compiler2_ppir::item_data::class_data(&db, loc).name + == Name::new(class_name) + }) .expect("class in item tree"); - let loc = baml_compiler2_hir::loc::ClassLoc::new(&db, file, *id); + let data = baml_compiler2_ppir::item_data::class_data(&db, loc); let qtn = baml_compiler2_tir::lower_type_expr::qualify_def( &db, Definition::Class(loc), @@ -385,12 +404,13 @@ mod tests { Ty::Class(qtn, vec![], TyAttr::default()) }; let iface = |iface_name: &str| { - let (id, _) = tree - .interfaces + let loc = *baml_compiler2_ppir::item_data::file_interfaces(&db, file) .iter() - .find(|(_, i)| i.name == Name::new(iface_name)) + .find(|&&loc| { + baml_compiler2_ppir::item_data::interface_data(&db, loc).name + == Name::new(iface_name) + }) .expect("interface in item tree"); - let loc = baml_compiler2_hir::loc::InterfaceLoc::new(&db, file, *id); let qtn = baml_compiler2_tir::interfaces::interface_loc_qtn(&db, loc) .expect("interface loc resolves to a qtn"); baml_type::Interface { diff --git a/baml_language/crates/baml_tests/src/compiler2_mir/mod.rs b/baml_language/crates/baml_tests/src/compiler2_mir/mod.rs index da16ca5d056..1c6329f0f62 100644 --- a/baml_language/crates/baml_tests/src/compiler2_mir/mod.rs +++ b/baml_language/crates/baml_tests/src/compiler2_mir/mod.rs @@ -5,10 +5,10 @@ use std::fmt::Write; -use baml_compiler2_hir::{file_item_tree, loc::FunctionLoc}; use baml_compiler2_mir::{ MirFunctionKind, OptLevel, Terminator, lower_function, pretty::display_function, }; +use baml_compiler2_ppir::item_data::{file_functions, function_data, function_source_map}; use baml_project::ProjectDatabase; const SNAPSHOT_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/snapshots/compiler2_mir"); @@ -21,11 +21,13 @@ fn make_db() -> ProjectDatabase { /// Lower all functions in a file to MIR and pretty-print them. fn render_mir(db: &ProjectDatabase, file: baml_base::SourceFile) -> String { - let item_tree = file_item_tree(db, file); + // Dump in source order (by declaration span) — intrinsic and + // salsa-enumeration-independent, matching the generated `test_04_5_mir`. + let mut functions = file_functions(db, file).to_vec(); + functions.sort_by_key(|loc| function_source_map(db, *loc).span.start()); let mut output = String::new(); - for local_id in item_tree.functions.keys() { - let func_loc = FunctionLoc::new(db, file, *local_id); + for func_loc in functions { let mir = lower_function(db, func_loc, OptLevel::Two); writeln!(output, "{}", display_function(&mir)).unwrap(); } @@ -48,14 +50,11 @@ function main(call_id: boundary.LocalId, sysop_id: boundary.LocalId) -> int thro } "#, ); - let item_tree = file_item_tree(&db, file); - let main_id = item_tree - .functions + let main_loc = *file_functions(&db, file) .iter() - .find(|(_, function)| function.name.as_str() == "main") - .map(|(id, _)| *id) + .find(|&&loc| function_data(&db, loc).name.as_str() == "main") .expect("main function"); - let mir = lower_function(&db, FunctionLoc::new(&db, file, main_id), OptLevel::Two); + let mir = lower_function(&db, main_loc, OptLevel::Two); let MirFunctionKind::Bytecode(body) = &mir.kind else { panic!("main must lower to bytecode") }; @@ -114,15 +113,12 @@ function union_dispatch(speaker: Dog | Cat, id: boundary.LocalId) -> int { } "#, ); - let item_tree = file_item_tree(&db, file); let lower_named = |name: &str| { - let id = item_tree - .functions + let loc = *file_functions(&db, file) .iter() - .find(|(_, function)| function.name.as_str() == name) - .map(|(id, _)| *id) + .find(|&&loc| function_data(&db, loc).name.as_str() == name) .unwrap_or_else(|| panic!("{name} function")); - lower_function(&db, FunctionLoc::new(&db, file, id), OptLevel::Two) + lower_function(&db, loc, OptLevel::Two) }; for name in ["indirect", "optional"] { diff --git a/baml_language/crates/baml_tests/src/compiler2_tir/inference.rs b/baml_language/crates/baml_tests/src/compiler2_tir/inference.rs index 7fc9144cae0..44e3b89e766 100644 --- a/baml_language/crates/baml_tests/src/compiler2_tir/inference.rs +++ b/baml_language/crates/baml_tests/src/compiler2_tir/inference.rs @@ -524,9 +524,8 @@ implements ToJson for Dog { "#, ); - let item_tree = baml_compiler2_hir::file_item_tree(&db, impl_file); assert_eq!( - item_tree.free_impls.len(), + baml_compiler2_ppir::item_data::file_free_impls(&db, impl_file).len(), 1, "cross-file class target must remain a first-class out-of-body impl record" ); @@ -698,13 +697,15 @@ fn lambda_scope_retypes_capture_from_function_parameter() { .expect("lambda scope"); let lambda_inference = infer_scope_types(&db, lambda_scope_id); - let item_tree = baml_compiler2_ppir::file_item_tree(&db, file); - let (main_id, _) = item_tree - .functions + let main_loc = *baml_compiler2_ppir::item_data::file_functions(&db, file) .iter() - .find(|(_, func)| func.name.as_str() == "main") + .find(|&&loc| { + baml_compiler2_ppir::item_data::function_data(&db, loc) + .name + .as_str() + == "main" + }) .expect("main function"); - let main_loc = baml_compiler2_hir::loc::FunctionLoc::new(&db, file, main_id); let main_body = baml_compiler2_ppir::function_body(&db, main_loc); let baml_compiler2_hir::body::FunctionBody::Expr(main_expr_body) = main_body.as_ref() else { panic!("main expression body"); diff --git a/baml_language/crates/baml_tests/src/compiler2_tir/mod.rs b/baml_language/crates/baml_tests/src/compiler2_tir/mod.rs index 22bdc561078..02218a84e01 100644 --- a/baml_language/crates/baml_tests/src/compiler2_tir/mod.rs +++ b/baml_language/crates/baml_tests/src/compiler2_tir/mod.rs @@ -33,8 +33,7 @@ pub(crate) mod support { Stmt, StmtId, }; use baml_compiler2_hir::{ - body::FunctionBody, contributions::Definition, item_tree::DefaultExprRef, loc::FunctionLoc, - scope::ScopeKind, + body::FunctionBody, contributions::Definition, item_tree::DefaultExprRef, scope::ScopeKind, }; use baml_compiler2_tir::{ inference::{ @@ -1120,165 +1119,161 @@ pub(crate) mod support { let mut func_body_opt: Option> = None; let mut sig_display = String::new(); if matches!(scope.kind, ScopeKind::Function) { - let item_tree = &index.item_tree; - for (local_id, func_data) in &item_tree.functions { - let name_matches = scope.name.as_ref().is_none_or(|n| *n == func_data.name); - if func_data.span == scope.range && name_matches { - let func_loc = FunctionLoc::new(db, file, *local_id); - func_body_opt = Some(baml_compiler2_ppir::function_body(db, func_loc)); - let sig = baml_compiler2_ppir::function_signature(db, func_loc); - let ns = &pkg_info.namespace_path; - - // The enclosing class/interface and its declared generic - // params, if this function is a method. A method signature - // can reference an enclosing generic (e.g. a synthesized - // `from_json` returning `Box` on `class Box`), so - // those params must be in scope when lowering the signature - // — otherwise `T` erases to `unknown`. (Interfaces share the - // `Class` scope kind; both must be handled, or an interface - // method's unannotated `self` would erase to `unknown`.) - let enclosing: Option<(baml_compiler2_tir::ty::Ty, Vec)> = - scope.parent.and_then(|parent_idx| { - let parent = &index.scopes[parent_idx.index() as usize]; - if !matches!(parent.kind, ScopeKind::Class) { - return None; + // The authoritative scope→item link (replaces the fragile + // `func.span == scope.range` join, which collided on companion spans). + if let Some(baml_compiler2_ppir::item_data::ScopeOwner::Function(func_loc)) = + baml_compiler2_ppir::item_data::scope_owner(db, scope_id) + { + let func_data = baml_compiler2_ppir::item_data::function_data(db, func_loc); + func_body_opt = Some(baml_compiler2_ppir::function_body(db, func_loc)); + let sig = baml_compiler2_ppir::function_signature(db, func_loc); + let ns = &pkg_info.namespace_path; + + // The enclosing class/interface and its declared generic + // params, if this function is a method. A method signature + // can reference an enclosing generic (e.g. a synthesized + // `from_json` returning `Box` on `class Box`), so + // those params must be in scope when lowering the signature + // — otherwise `T` erases to `unknown`. (Interfaces share the + // `Class` scope kind; both must be handled, or an interface + // method's unannotated `self` would erase to `unknown`.) + let enclosing: Option<(baml_compiler2_tir::ty::Ty, Vec)> = + scope.parent.and_then(|parent_idx| { + let parent = &index.scopes[parent_idx.index() as usize]; + if !matches!(parent.kind, ScopeKind::Class) { + return None; + } + let cn = parent.name.as_ref()?; + let def = pkg_items.lookup_type(ns, cn)?; + let generics = match def { + Definition::Class(class_loc) => { + baml_compiler2_ppir::item_data::class_data(db, class_loc) + .generic_params + .clone() } - let cn = parent.name.as_ref()?; - let def = pkg_items.lookup_type(ns, cn)?; - let generics = match def { - Definition::Class(class_loc) => { - baml_compiler2_ppir::file_item_tree(db, class_loc.file(db)) - [class_loc.id(db)] + Definition::Interface(iface_loc) => { + baml_compiler2_ppir::item_data::interface_data(db, iface_loc) .generic_params .clone() - } - Definition::Interface(iface_loc) => { - baml_compiler2_ppir::file_item_tree(db, iface_loc.file(db)) - .interfaces - .get(&iface_loc.id(db))? - .generic_params - .clone() - } - _ => return None, - }; - let class_ty = baml_compiler2_tir::ty::Ty::Class( - baml_compiler2_tir::lower_type_expr::qualify_def(db, def, cn), - generics - .iter() - .map(|n| { - baml_compiler2_tir::ty::Ty::TypeVar( - n.clone(), - Default::default(), - ) - }) - .collect(), - Default::default(), - ); - Some((class_ty, generics)) - }); - let (enclosing_class_ty, enclosing_class_generics) = match enclosing { - Some((ty, generics)) => (Some(ty), generics), - None => (None, Vec::new()), - }; + } + _ => return None, + }; + let class_ty = baml_compiler2_tir::ty::Ty::Class( + baml_compiler2_tir::lower_type_expr::qualify_def(db, def, cn), + generics + .iter() + .map(|n| { + baml_compiler2_tir::ty::Ty::TypeVar( + n.clone(), + Default::default(), + ) + }) + .collect(), + Default::default(), + ); + Some((class_ty, generics)) + }); + let (enclosing_class_ty, enclosing_class_generics) = match enclosing { + Some((ty, generics)) => (Some(ty), generics), + None => (None, Vec::new()), + }; - let gp = &func_data.generic_params; - // Type-lowering scope for the signature: the enclosing - // class's generics plus the function's own. (The displayed - // `<...>` below still shows only the function's own.) - let mut sig_generics: Vec = enclosing_class_generics; - sig_generics.extend(gp.iter().cloned()); - // One lowering scope shared by the param/return/throws sites - // below (a display helper — no type-var bounds threaded). - let sig_bounds = TypeVarBoundsMap::default(); - let sig_scope = ScopeCtx { - db, - package_items: pkg_items, - ns_context: ns, - generic_params: &sig_generics, - bounds: &sig_bounds, - self_ty: None, - }; - let generics_display = if gp.is_empty() { - String::new() - } else { - let names: Vec = gp.iter().map(|n| n.to_string()).collect(); - format!("<{}>", names.join(", ")) - }; + let gp = &func_data.generic_params; + // Type-lowering scope for the signature: the enclosing + // class's generics plus the function's own. (The displayed + // `<...>` below still shows only the function's own.) + let mut sig_generics: Vec = enclosing_class_generics; + sig_generics.extend(gp.iter().cloned()); + // One lowering scope shared by the param/return/throws sites + // below (a display helper — no type-var bounds threaded). + let sig_bounds = TypeVarBoundsMap::default(); + let sig_scope = ScopeCtx { + db, + package_items: pkg_items, + ns_context: ns, + generic_params: &sig_generics, + bounds: &sig_bounds, + self_ty: None, + }; + let generics_display = if gp.is_empty() { + String::new() + } else { + let names: Vec = gp.iter().map(|n| n.to_string()).collect(); + format!("<{}>", names.join(", ")) + }; - let parameter_defaults = - baml_compiler2_ppir::function_parameter_defaults(db, func_loc); - let params: Vec = sig - .params - .iter() - .enumerate() - .map(|(index, param)| { - let ty = if param.name.as_str() == "self" - && matches!( - param.ty.kind, - baml_compiler2_ast::TypeExprKind::Unknown { .. } - ) { - enclosing_class_ty.clone().unwrap_or( - baml_compiler2_tir::ty::Ty::Unknown { - attr: Default::default(), - }, - ) - } else { - let mut diags = Vec::new(); - lower_type_expr(¶m.ty, &sig_scope, &mut diags) - }; - let default_suffix = default_ref_suffix( - parameter_defaults.param_default(index), - ¶meter_defaults.defaults, - ); - format!( - "{}: {}{}", - param.name, - ty.render_canonical(), - default_suffix + let parameter_defaults = + baml_compiler2_ppir::function_parameter_defaults(db, func_loc); + let params: Vec = sig + .params + .iter() + .enumerate() + .map(|(index, param)| { + let ty = if param.name.as_str() == "self" + && matches!( + param.ty.kind, + baml_compiler2_ast::TypeExprKind::Unknown { .. } + ) { + enclosing_class_ty.clone().unwrap_or( + baml_compiler2_tir::ty::Ty::Unknown { + attr: Default::default(), + }, ) - }) - .collect(); - let ret = sig - .return_type - .as_ref() - .map(|t| { + } else { let mut diags = Vec::new(); - lower_type_expr(t, &sig_scope, &mut diags).render_canonical() + lower_type_expr(¶m.ty, &sig_scope, &mut diags) + }; + let default_suffix = default_ref_suffix( + parameter_defaults.param_default(index), + ¶meter_defaults.defaults, + ); + format!( + "{}: {}{}", + param.name, + ty.render_canonical(), + default_suffix + ) + }) + .collect(); + let ret = sig + .return_type + .as_ref() + .map(|t| { + let mut diags = Vec::new(); + lower_type_expr(t, &sig_scope, &mut diags).render_canonical() + }) + .unwrap_or_else(|| "?".into()); + // Compute inferred throws from transitive throw set + let inferred_throws: Option = { + let key = baml_base::Name::new(&*fqn); + throw_sets + .transitive_for(&key) + .filter(|facts| !facts.is_empty()) + .map(|facts| { + let types: Vec = + facts.iter().map(|f| f.render_canonical()).collect(); + types.join(" | ") }) - .unwrap_or_else(|| "?".into()); - // Compute inferred throws from transitive throw set - let inferred_throws: Option = { - let key = baml_base::Name::new(&*fqn); - throw_sets - .transitive_for(&key) - .filter(|facts| !facts.is_empty()) - .map(|facts| { - let types: Vec = - facts.iter().map(|f| f.render_canonical()).collect(); - types.join(" | ") - }) - }; + }; - let throws = if let Some(t) = &sig.throws { - let mut diags = Vec::new(); - let declared = - lower_type_expr(t, &sig_scope, &mut diags).render_canonical(); - match &inferred_throws { - Some(inferred) => { - format!(" throws {declared} infers {inferred}") - } - None => format!(" throws {declared}"), - } - } else { - match &inferred_throws { - Some(inferred) => format!(" throws {inferred}"), - None => " throws never".to_string(), + let throws = if let Some(t) = &sig.throws { + let mut diags = Vec::new(); + let declared = + lower_type_expr(t, &sig_scope, &mut diags).render_canonical(); + match &inferred_throws { + Some(inferred) => { + format!(" throws {declared} infers {inferred}") } - }; - sig_display = - format!("{generics_display}({}) -> {ret}{throws}", params.join(", ")); - break; - } + None => format!(" throws {declared}"), + } + } else { + match &inferred_throws { + Some(inferred) => format!(" throws {inferred}"), + None => " throws never".to_string(), + } + }; + sig_display = + format!("{generics_display}({}) -> {ret}{throws}", params.join(", ")); } } @@ -2144,13 +2139,13 @@ pub(crate) mod support { function_name: &str, expr_text: &str, ) -> String { - let item_tree = baml_compiler2_hir::file_item_tree(db, file); - let (func_loc, func_span) = item_tree - .functions + let func_loc = *baml_compiler2_ppir::item_data::file_functions(db, file) .iter() - .find_map(|(local_id, func_data)| { - (func_data.name.as_str() == function_name) - .then_some((FunctionLoc::new(db, file, *local_id), func_data.span)) + .find(|&&loc| { + baml_compiler2_ppir::item_data::function_data(db, loc) + .name + .as_str() + == function_name }) .unwrap_or_else(|| panic!("function `{function_name}` not found")); let func_body = baml_compiler2_ppir::function_body(db, func_loc); @@ -2159,20 +2154,9 @@ pub(crate) mod support { _ => panic!("function `{function_name}` has no expression body"), }; - let index = baml_compiler2_ppir::file_semantic_index(db, file); - let scope_id = index - .scopes - .iter() - .enumerate() - .find_map(|(i, scope)| { - (matches!(scope.kind, ScopeKind::Function) - && scope.range == func_span - && scope - .name - .as_ref() - .is_some_and(|name| name.as_str() == function_name)) - .then_some(index.scope_ids[i]) - }) + // The authoritative function→scope link, replacing a `scope.range == + // func.span` join. + let scope_id = baml_compiler2_ppir::item_data::function_scope(db, func_loc) .unwrap_or_else(|| panic!("scope for function `{function_name}` not found")); let inference = infer_scope_types(db, scope_id); diff --git a/baml_language/crates/baml_tests/src/compiler2_tir/phase3a.rs b/baml_language/crates/baml_tests/src/compiler2_tir/phase3a.rs index 1577d33583a..c06d449190c 100644 --- a/baml_language/crates/baml_tests/src/compiler2_tir/phase3a.rs +++ b/baml_language/crates/baml_tests/src/compiler2_tir/phase3a.rs @@ -8,7 +8,7 @@ use super::support::{make_db, render_tir}; #[test] fn explicit_local_id_is_structural_call_metadata() { - use baml_compiler2_hir::scope::ScopeKind; + use baml_compiler2_ppir::item_data::{file_functions, function_data, function_scope}; use baml_compiler2_tir::inference::{ParamBinding, infer_scope_types}; let mut db = make_db(); @@ -31,20 +31,11 @@ function main(id: boundary.LocalId) -> int { "a trailing LocalId side channel must compile cleanly:\n{rendered}" ); - let index = baml_compiler2_ppir::file_semantic_index(&db, file); - let main_scope = index - .scopes + let main_loc = *file_functions(&db, file) .iter() - .enumerate() - .find(|(_, scope)| { - scope.kind == ScopeKind::Function - && scope - .name - .as_ref() - .is_some_and(|name| name.as_str() == "main") - }) - .map(|(scope_index, _)| index.scope_ids[scope_index]) - .expect("main function scope"); + .find(|&&loc| function_data(&db, loc).name.as_str() == "main") + .expect("main function"); + let main_scope = function_scope(&db, main_loc).expect("main function scope"); let inference = infer_scope_types(&db, main_scope); let plans = inference.iter_call_plans().collect::>(); assert_eq!(plans.len(), 1, "main contains exactly one call: {rendered}"); diff --git a/baml_language/crates/baml_tests/src/compiler2_tir/phase5.rs b/baml_language/crates/baml_tests/src/compiler2_tir/phase5.rs index 19f87d30cb6..f237b966638 100644 --- a/baml_language/crates/baml_tests/src/compiler2_tir/phase5.rs +++ b/baml_language/crates/baml_tests/src/compiler2_tir/phase5.rs @@ -10,7 +10,6 @@ use std::fmt::Write; use baml_base::Name; use baml_compiler2_hir::{ contributions::Definition, - file_item_tree, package::{PackageId, package_items}, }; use baml_project::ProjectDatabase; @@ -59,8 +58,7 @@ fn render_baml_package_items(db: &ProjectDatabase) -> String { let def = &ns_items.types[name]; match def { Definition::Class(class_loc) => { - let item_tree = file_item_tree(db, class_loc.file(db)); - let class_data = &item_tree[class_loc.id(db)]; + let class_data = baml_compiler2_ppir::item_data::class_data(db, *class_loc); let gp_str = if class_data.generic_params.is_empty() { String::new() } else { @@ -77,7 +75,11 @@ fn render_baml_package_items(db: &ProjectDatabase) -> String { let method_names: Vec = class_data .methods .iter() - .map(|mid| item_tree.functions[mid].name.to_string()) + .map(|mid| { + baml_compiler2_ppir::item_data::function_data(db, *mid) + .name + .to_string() + }) .collect(); writeln!( output, @@ -102,8 +104,7 @@ fn render_baml_package_items(db: &ProjectDatabase) -> String { let def = &ns_items.values[name]; match def { Definition::Function(func_loc) => { - let item_tree = file_item_tree(db, func_loc.file(db)); - let func_data = &item_tree[func_loc.id(db)]; + let func_data = baml_compiler2_ppir::item_data::function_data(db, *func_loc); let gp_str = if func_data.generic_params.is_empty() { String::new() } else { @@ -260,8 +261,7 @@ fn array_has_generic_param_t() { panic!("Array should be a class"); }; - let item_tree = file_item_tree(&db, class_loc.file(&db)); - let class_data = &item_tree[class_loc.id(&db)]; + let class_data = baml_compiler2_ppir::item_data::class_data(&db, *class_loc); assert_eq!( class_data.generic_params, @@ -282,8 +282,7 @@ fn map_has_generic_params_k_v() { panic!("Map should be a class"); }; - let item_tree = file_item_tree(&db, class_loc.file(&db)); - let class_data = &item_tree[class_loc.id(&db)]; + let class_data = baml_compiler2_ppir::item_data::class_data(&db, *class_loc); assert_eq!( class_data.generic_params, @@ -304,8 +303,7 @@ fn string_class_has_no_generic_params() { panic!("String should be a class"); }; - let item_tree = file_item_tree(&db, class_loc.file(&db)); - let class_data = &item_tree[class_loc.id(&db)]; + let class_data = baml_compiler2_ppir::item_data::class_data(&db, *class_loc); assert!( class_data.generic_params.is_empty(), @@ -327,13 +325,16 @@ fn array_has_expected_methods() { panic!("Array should be a class"); }; - let item_tree = file_item_tree(&db, class_loc.file(&db)); - let class_data = &item_tree[class_loc.id(&db)]; + let class_data = baml_compiler2_ppir::item_data::class_data(&db, *class_loc); let method_names: Vec = class_data .methods .iter() - .map(|mid| item_tree.functions[mid].name.to_string()) + .map(|mid| { + baml_compiler2_ppir::item_data::function_data(&db, *mid) + .name + .to_string() + }) .collect(); let expected = [ @@ -359,13 +360,16 @@ fn map_has_expected_methods() { panic!("Map should be a class"); }; - let item_tree = file_item_tree(&db, class_loc.file(&db)); - let class_data = &item_tree[class_loc.id(&db)]; + let class_data = baml_compiler2_ppir::item_data::class_data(&db, *class_loc); let method_names: Vec = class_data .methods .iter() - .map(|mid| item_tree.functions[mid].name.to_string()) + .map(|mid| { + baml_compiler2_ppir::item_data::function_data(&db, *mid) + .name + .to_string() + }) .collect(); let expected = ["length", "has", "keys", "values", "set", "get"]; diff --git a/baml_language/crates/baml_tests/src/incremental/scenarios.rs b/baml_language/crates/baml_tests/src/incremental/scenarios.rs index 3b007f324dd..c3bc6e250a3 100644 --- a/baml_language/crates/baml_tests/src/incremental/scenarios.rs +++ b/baml_language/crates/baml_tests/src/incremental/scenarios.rs @@ -363,13 +363,15 @@ fn type_alias_loc<'db>( file: SourceFile, name: &str, ) -> baml_compiler2_hir::loc::TypeAliasLoc<'db> { - let item_tree = baml_compiler2_ppir::file_item_tree(db, file); - let (id, _) = item_tree - .type_aliases + *baml_compiler2_ppir::item_data::file_type_aliases(db, file) .iter() - .find(|(_, alias)| alias.name.as_str() == name) - .unwrap_or_else(|| unreachable!("type alias `{name}` should exist")); - baml_compiler2_hir::loc::TypeAliasLoc::new(db, file, *id) + .find(|&&loc| { + baml_compiler2_ppir::item_data::type_alias_data(db, loc) + .name + .as_str() + == name + }) + .unwrap_or_else(|| unreachable!("type alias `{name}` should exist")) } /// A whitespace-only edit must leave the semantic data byte-for-byte equal (so @@ -443,13 +445,15 @@ fn class_loc<'db>( file: SourceFile, name: &str, ) -> baml_compiler2_hir::loc::ClassLoc<'db> { - let item_tree = baml_compiler2_ppir::file_item_tree(db, file); - let (id, _) = item_tree - .classes + *baml_compiler2_ppir::item_data::file_classes(db, file) .iter() - .find(|(_, class)| class.name.as_str() == name) - .unwrap_or_else(|| unreachable!("class `{name}` should exist")); - baml_compiler2_hir::loc::ClassLoc::new(db, file, *id) + .find(|&&loc| { + baml_compiler2_ppir::item_data::class_data(db, loc) + .name + .as_str() + == name + }) + .unwrap_or_else(|| unreachable!("class `{name}` should exist")) } fn function_loc<'db>( @@ -457,13 +461,15 @@ fn function_loc<'db>( file: SourceFile, name: &str, ) -> baml_compiler2_hir::loc::FunctionLoc<'db> { - let item_tree = baml_compiler2_ppir::file_item_tree(db, file); - let (id, _) = item_tree - .functions + *baml_compiler2_ppir::item_data::file_functions(db, file) .iter() - .find(|(_, function)| function.name.as_str() == name) - .unwrap_or_else(|| unreachable!("function `{name}` should exist")); - baml_compiler2_hir::loc::FunctionLoc::new(db, file, *id) + .find(|&&loc| { + baml_compiler2_ppir::item_data::function_data(db, loc) + .name + .as_str() + == name + }) + .unwrap_or_else(|| unreachable!("function `{name}` should exist")) } /// Everything span-bearing in a `ClassData`, as an owned value. @@ -613,23 +619,27 @@ fn function_scope_index_agrees_with_the_span_join_it_replaces() { let db = test_db.db(); let index = baml_compiler2_ppir::file_semantic_index(db, file); - let item_tree = baml_compiler2_ppir::file_item_tree(db, file); - // Guard against a vacuous test: the declarative `Greet` must actually have // synthesized companions, or the ambiguous case is not being exercised. - let companions = item_tree - .functions - .values() - .filter(|f| !matches!(f.origin, baml_compiler2_ast::FunctionOrigin::UserDefined)) + let functions = baml_compiler2_ppir::item_data::file_functions(db, file); + let companions = functions + .iter() + .filter(|&&loc| { + !matches!( + baml_compiler2_ppir::item_data::function_data(db, loc).origin, + baml_compiler2_ast::FunctionOrigin::UserDefined + ) + }) .count(); assert!( companions > 0, "fixture should synthesize companions; got {} functions, none synthetic", - item_tree.functions.len() + functions.len() ); - for (id, func) in item_tree.functions.iter() { - let loc = baml_compiler2_hir::loc::FunctionLoc::new(db, file, *id); + for &loc in functions { + let func = baml_compiler2_ppir::item_data::function_data(db, loc); + let func_span = baml_compiler2_ppir::item_data::function_source_map(db, loc).span; // The scan being retired. let legacy = index @@ -639,7 +649,7 @@ fn function_scope_index_agrees_with_the_span_join_it_replaces() { .find(|scope_id| { let scope = &index.scopes[scope_id.file_scope_id(db).index() as usize]; matches!(scope.kind, baml_compiler2_hir::scope::ScopeKind::Function) - && scope.range == func.span + && scope.range == func_span && scope.name.as_ref() == Some(&func.name) }) .map(|scope| scope.file_scope_id(db)); @@ -777,69 +787,74 @@ function free_standing(x: int) -> int throws never { ); let db = test_db.db(); - let item_tree = baml_compiler2_ppir::file_item_tree(db, file); - assert!(!item_tree.functions.is_empty()); + assert!(!baml_compiler2_ppir::item_data::file_functions(db, file).is_empty()); let mut cases = (0usize, 0usize, 0usize, 0usize); - for id in item_tree.functions.keys() { - let loc = baml_compiler2_hir::loc::FunctionLoc::new(db, file, *id); + for &loc in baml_compiler2_ppir::item_data::file_functions(db, file) { + let func_name = baml_compiler2_ppir::item_data::function_data(db, loc) + .name + .clone(); // The scans being retired. - let by_class = item_tree - .classes + let by_class = baml_compiler2_ppir::item_data::file_classes(db, file) .iter() - .find(|(_, class)| class.methods.contains(id)) - .map(|(class_id, _)| *class_id); - let by_interface = item_tree - .interfaces + .copied() + .find(|&class_loc| { + baml_compiler2_ppir::item_data::class_data(db, class_loc) + .methods + .contains(&loc) + }); + let by_interface = baml_compiler2_ppir::item_data::file_interfaces(db, file) .iter() - .find(|(_, iface)| iface.default_methods.contains(id)) - .map(|(iface_id, _)| *iface_id); - let by_free_impl = item_tree - .free_impls + .copied() + .find(|&iface_loc| { + baml_compiler2_ppir::item_data::interface_data(db, iface_loc) + .default_methods + .contains(&loc) + }); + let by_free_impl = baml_compiler2_ppir::item_data::file_free_impls(db, file) .iter() - .find(|impl_id| item_tree.impls[impl_id].methods.contains(id)) - .copied(); + .copied() + .find(|&impl_loc| { + baml_compiler2_ppir::item_data::impl_block_data(db, impl_loc) + .methods + .contains(&loc) + }); let indexed = baml_compiler2_ppir::item_data::method_owner(db, loc); use baml_compiler2_ppir::item_data::MethodOwner; match (by_class, by_interface, by_free_impl) { - (Some(class_id), None, None) => { + (Some(class_loc), None, None) => { cases.0 += 1; assert!( - matches!(indexed, Some(MethodOwner::Class(c)) if c.id(db) == class_id), - "class scan and index disagree for {:?}", - item_tree[*id].name + matches!(indexed, Some(MethodOwner::Class(c)) if c == class_loc), + "class scan and index disagree for {func_name:?}" ); } - (None, Some(iface_id), None) => { + (None, Some(iface_loc), None) => { cases.1 += 1; assert!( - matches!(indexed, Some(MethodOwner::Interface(i)) if i.id(db) == iface_id), - "interface scan and index disagree for {:?}", - item_tree[*id].name + matches!(indexed, Some(MethodOwner::Interface(i)) if i == iface_loc), + "interface scan and index disagree for {func_name:?}" ); } - (None, None, Some(impl_id)) => { + (None, None, Some(impl_loc)) => { cases.2 += 1; assert!( - matches!(indexed, Some(MethodOwner::FreeImpl(b)) if b.id(db) == impl_id), - "free-impl scan and index disagree for {:?}", - item_tree[*id].name + matches!(indexed, Some(MethodOwner::FreeImpl(b)) if b == impl_loc), + "free-impl scan and index disagree for {func_name:?}" ); } (None, None, None) => { cases.3 += 1; assert_eq!( indexed, None, - "top-level function {:?} should have no owner", - item_tree[*id].name + "top-level function {func_name:?} should have no owner" ); } other => unreachable!( - "a method can only have one owner; scans returned {other:?} for {:?}", - item_tree[*id].name + "a method can only have one owner; scans returned {other:?} for {func_name:?}" ), } } From 235137d0daf8f353f5af76fc837178b6b88bc067 Mon Sep 17 00:00:00 2001 From: 2kai2kai2 Date: Tue, 21 Jul 2026 13:56:57 -0700 Subject: [PATCH 07/10] PPIR snapshots instead of HIR --- baml_language/crates/baml_tests/build.rs | 14 +- ...s__compiles____assert_std____03_ppir.snap} | 5 +- ...sts__compiles____baml_std____03_ppir.snap} | 731 +++++++++++++++--- ...__compiles____testing_std____03_ppir.snap} | 104 ++- ...mpiles__anyfunction_reflect__03_ppir.snap} | 8 +- ...mpiles__backtick_decl_slots__03_ppir.snap} | 11 +- ...__compiles__backtick_dedent__03_ppir.snap} | 3 +- ..._compiles__backtick_strings__03_ppir.snap} | 3 +- ...sts__compiles__bigint_arith__03_ppir.snap} | 3 +- ...tests__compiles__bigint_cmp__03_ppir.snap} | 3 +- ...s__compiles__bigint_literal__03_ppir.snap} | 3 +- ...piles__byte_string_literals__03_ppir.snap} | 3 +- ...compiles__catch_all_keyword__03_ppir.snap} | 3 +- ..._compiles__catch_all_panics__03_ppir.snap} | 3 +- ..._compiles__catch_arm_return__03_ppir.snap} | 3 +- ...ests__compiles__catch_throw__03_ppir.snap} | 3 +- ...iles__closure_loop_variable__03_ppir.snap} | 3 +- ...l_tests__compiles__closures__03_ppir.snap} | 29 +- ...ment_after_string_in_config__03_ppir.snap} | 3 +- ...__compiles__comment_in_type__03_ppir.snap} | 21 +- ...compiles__config_dictionary__03_ppir.snap} | 3 +- ...mpiles__config_model_string__03_ppir.snap} | 3 +- ..._compiles__deep_method_call__03_ppir.snap} | 9 +- ...ts__compiles__function_call__03_ppir.snap} | 6 +- ...mpiles__generic_field_chain__03_ppir.snap} | 10 +- ...__generic_match_typevar_arm__03_ppir.snap} | 8 +- ...ompiles__host_callable_call__03_ppir.snap} | 3 +- ...ests__compiles__is_operator__03_ppir.snap} | 3 +- ..._compiles__json_alias_basic__03_ppir.snap} | 6 +- ...cross_namespace_static_call__03_ppir.snap} | 12 +- ...piles__json_llm_return_type__03_ppir.snap} | 12 +- ..._compiles__json_map_literal__03_ppir.snap} | 3 +- ..._parse_stringify_intrinsics__03_ppir.snap} | 3 +- ...om_string_composite_generic__03_ppir.snap} | 9 +- ...son_to_from_string_concrete__03_ppir.snap} | 7 +- ...m_string_generic_forwarding__03_ppir.snap} | 3 +- ..._to_from_string_three_level__03_ppir.snap} | 3 +- ...__compiles__lambda_advanced__03_ppir.snap} | 3 +- ...sts__compiles__lambda_basic__03_ppir.snap} | 3 +- ..._compiles__lambda_fat_arrow__03_ppir.snap} | 3 +- ...mpiles__lambda_field_access__03_ppir.snap} | 10 +- ...__compiles__lexical_scoping__03_ppir.snap} | 3 +- ...s__literal_union_arithmetic__03_ppir.snap} | 3 +- ...les__literal_union_widening__03_ppir.snap} | 4 +- ...compiles__llm_image_outputs__03_ppir.snap} | 30 +- ...parse_catchable_parse_error__03_ppir.snap} | 16 +- ...__method_explicit_type_args__03_ppir.snap} | 6 +- ..._compiles__namespaces_basic__03_ppir.snap} | 11 +- ...compiles__namespaces_nested__03_ppir.snap} | 10 +- ...s__namespaces_root_fallback__03_ppir.snap} | 9 +- ...__compiles__namespaces_shadow__03_hir.snap | 10 - ..._compiles__namespaces_shadow__03_ppir.snap | 17 + ..._namespaces_type_resolution__03_ppir.snap} | 75 +- ...iles__numeric_invariance_ok__03_ppir.snap} | 6 +- ...numeric_literal_method_call__03_ppir.snap} | 3 +- ..._compiles__o1_allowed_roles__03_ppir.snap} | 3 +- ...ptional_function_parameters__03_ppir.snap} | 17 +- ..._compiles__paren_union_test__03_ppir.snap} | 27 +- ...ompiles__parser_expressions__03_ppir.snap} | 20 +- ...compiles__parser_statements__03_ppir.snap} | 10 +- ...lass_destructure_namespaces__03_ppir.snap} | 13 +- ...sts__compiles__patterns_new__03_ppir.snap} | 13 +- ...eflect_type_of_user_generic__03_ppir.snap} | 6 +- ...sts__compiles__retry_policy__03_ppir.snap} | 3 +- ...__scientific_notation_float__03_ppir.snap} | 3 +- ...s__compiles__stream_crossfile__03_hir.snap | 17 - ...__compiles__stream_crossfile__03_ppir.snap | 30 + ...tream_llm_inferred_typeargs__03_ppir.snap} | 12 +- ...s__compiles__string_methods__03_ppir.snap} | 3 +- ...__compiles__test_expr_basic__03_ppir.snap} | 3 +- ...iles__test_expr_name_concat__03_ppir.snap} | 3 +- ...es__test_expr_throwing_body__03_ppir.snap} | 3 +- ...iles__test_expr_with_runner__03_ppir.snap} | 3 +- ..._compiles__test_old_and_new__03_ppir.snap} | 3 +- ...piles__test_raw_string_name__03_ppir.snap} | 3 +- ...iles__test_with_not_keyword__03_ppir.snap} | 9 +- ...ts__compiles__testset_basic__03_ppir.snap} | 3 +- ...__compiles__testset_dynamic__03_ppir.snap} | 3 +- ...s__compiles__testset_nested__03_ppir.snap} | 3 +- ...piles__testset_vibes_nested__03_ppir.snap} | 35 +- ...ompiles__testset_with_setup__03_ppir.snap} | 3 +- ...s__top_level_header_comment__03_ppir.snap} | 3 +- ...ts__compiles__top_level_let__03_ppir.snap} | 3 +- ...__compiles__type_annotation__03_ppir.snap} | 13 +- ...mpiles__type_builder_errors__03_ppir.snap} | 15 +- ...compiles__type_builder_test__03_ppir.snap} | 15 +- ...gnostic_errors__anyfunction__03_ppir.snap} | 14 +- ...s__assignment_expr_position__03_ppir.snap} | 3 +- ...c_errors__attr_disambiguation__03_hir.snap | 145 ---- ..._errors__attr_disambiguation__03_ppir.snap | 269 +++++++ ...rrors__attribute_validation__03_ppir.snap} | 14 +- ...backtick_interp_type_errors__03_ppir.snap} | 3 +- ...rors__backtick_strict_types__03_ppir.snap} | 3 +- ...gnostic_errors__basic_types__03_ppir.snap} | 66 +- ...agnostic_errors__builtin_io__03_ppir.snap} | 3 +- ...rrors__captured_field_chain__03_ppir.snap} | 10 +- ..._catch_arm_braceless_return__03_ppir.snap} | 3 +- ..._catch_return_type_mismatch__03_ppir.snap} | 4 +- ...rs__catch_throw_regressions__03_ppir.snap} | 6 +- ...errors__client_option_types__03_ppir.snap} | 3 +- ...stic_errors__closure_errors__03_ppir.snap} | 13 +- ...nostic_errors__control_flow__03_ppir.snap} | 12 +- ...errors__duplicate_attribute__03_ppir.snap} | 15 +- ...rrors__duplicate_class_span__03_ppir.snap} | 7 +- ...errors__duplicate_field_alias__03_hir.snap | 34 - ...rrors__duplicate_field_alias__03_ppir.snap | 65 ++ ...rs__duplicate_variant_alias__03_ppir.snap} | 3 +- ...ostic_errors__format_checks__03_ppir.snap} | 355 ++++++++- ...unction_type_missing_throws__03_ppir.snap} | 14 +- ...rrors__function_type_throws__03_ppir.snap} | 10 +- ...stic_errors__function_types__03_ppir.snap} | 12 +- ...ors__generic_call_ambiguity__03_ppir.snap} | 3 +- ...ss_destructure_no_type_args__03_ppir.snap} | 6 +- ...eneric_error_arg_no_cascade__03_ppir.snap} | 3 +- ...diagnostic_errors__generics__03_ppir.snap} | 50 +- ..._errors__headers_edge_cases__03_ppir.snap} | 3 +- ..._errors__instanceof_removed__03_ppir.snap} | 9 +- ...s__invalid_numeric_literals__03_ppir.snap} | 7 +- ...errors__is_pattern_negative__03_ppir.snap} | 9 +- ...agnostic_errors__json_alias__03_ppir.snap} | 3 +- ...s__json_static_method_arity__03_ppir.snap} | 6 +- ...ostic_errors__lambda_errors__03_ppir.snap} | 4 +- ...ors__lexical_scoping_errors__03_ppir.snap} | 3 +- ...rrors__match_exhaustiveness__03_ppir.snap} | 40 +- ...mespaces_bare_name_rejected__03_ppir.snap} | 9 +- ...c_errors__namespaces_conflict__03_hir.snap | 11 - ..._errors__namespaces_conflict__03_ppir.snap | 19 + ...amespaces_stream_direct_ref__03_ppir.snap} | 23 +- ...ostic_errors__null_handling__03_ppir.snap} | 23 +- ..._errors__numeric_invariance__03_ppir.snap} | 6 +- ...optional_parameter_defaults__03_ppir.snap} | 8 +- ...errors__parser_constructors__03_ppir.snap} | 15 +- ...patterns_array_rest_binding__03_ppir.snap} | 7 +- ..._patterns_class_destructure__03_ppir.snap} | 27 +- ...lass_destructure_namespaces__03_ppir.snap} | 9 +- ...nostic_errors__patterns_new__03_ppir.snap} | 28 +- ...c_errors__runtime_id_misuse__03_ppir.snap} | 7 +- ...nostic_errors__self_in_body__03_ppir.snap} | 6 +- ...tic_errors__simple_function__03_ppir.snap} | 16 +- ...c_errors__simple_type_error__03_ppir.snap} | 3 +- ...agnostic_errors__stream_types__03_hir.snap | 205 ----- ...gnostic_errors__stream_types__03_ppir.snap | 404 ++++++++++ ...__test_expr_name_type_error__03_ppir.snap} | 3 +- ...ors__test_expr_wrong_runner__03_ppir.snap} | 3 +- ..._test_with_runner_ambiguity__03_ppir.snap} | 6 +- ...nostic_errors__type_aliases__03_ppir.snap} | 10 +- ...ors__type_reflection_strict__03_ppir.snap} | 6 +- ..._errors__unknown_type_error__03_ppir.snap} | 6 +- ...ic_errors__void_return_type__03_ppir.snap} | 7 +- .../baml_tests/src/compiler2_tir/mod.rs | 255 ++++-- 150 files changed, 3225 insertions(+), 713 deletions(-) rename baml_language/crates/baml_tests/snapshots/compiles/__assert_std__/{baml_tests__compiles____assert_std____03_hir.snap => baml_tests__compiles____assert_std____03_ppir.snap} (95%) rename baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/{baml_tests__compiles____baml_std____03_hir.snap => baml_tests__compiles____baml_std____03_ppir.snap} (87%) rename baml_language/crates/baml_tests/snapshots/compiles/__testing_std__/{baml_tests__compiles____testing_std____03_hir.snap => baml_tests__compiles____testing_std____03_ppir.snap} (89%) rename baml_language/crates/baml_tests/snapshots/compiles/anyfunction_reflect/{baml_tests__compiles__anyfunction_reflect__03_hir.snap => baml_tests__compiles__anyfunction_reflect__03_ppir.snap} (93%) rename baml_language/crates/baml_tests/snapshots/compiles/backtick_decl_slots/{baml_tests__compiles__backtick_decl_slots__03_hir.snap => baml_tests__compiles__backtick_decl_slots__03_ppir.snap} (75%) rename baml_language/crates/baml_tests/snapshots/compiles/backtick_dedent/{baml_tests__compiles__backtick_dedent__03_hir.snap => baml_tests__compiles__backtick_dedent__03_ppir.snap} (94%) rename baml_language/crates/baml_tests/snapshots/compiles/backtick_strings/{baml_tests__compiles__backtick_strings__03_hir.snap => baml_tests__compiles__backtick_strings__03_ppir.snap} (98%) rename baml_language/crates/baml_tests/snapshots/compiles/bigint_arith/{baml_tests__compiles__bigint_arith__03_hir.snap => baml_tests__compiles__bigint_arith__03_ppir.snap} (95%) rename baml_language/crates/baml_tests/snapshots/compiles/bigint_cmp/{baml_tests__compiles__bigint_cmp__03_hir.snap => baml_tests__compiles__bigint_cmp__03_ppir.snap} (91%) rename baml_language/crates/baml_tests/snapshots/compiles/bigint_literal/{baml_tests__compiles__bigint_literal__03_hir.snap => baml_tests__compiles__bigint_literal__03_ppir.snap} (89%) rename baml_language/crates/baml_tests/snapshots/compiles/byte_string_literals/{baml_tests__compiles__byte_string_literals__03_hir.snap => baml_tests__compiles__byte_string_literals__03_ppir.snap} (97%) rename baml_language/crates/baml_tests/snapshots/compiles/catch_all_keyword/{baml_tests__compiles__catch_all_keyword__03_hir.snap => baml_tests__compiles__catch_all_keyword__03_ppir.snap} (95%) rename baml_language/crates/baml_tests/snapshots/compiles/catch_all_panics/{baml_tests__compiles__catch_all_panics__03_hir.snap => baml_tests__compiles__catch_all_panics__03_ppir.snap} (95%) rename baml_language/crates/baml_tests/snapshots/compiles/catch_arm_return/{baml_tests__compiles__catch_arm_return__03_hir.snap => baml_tests__compiles__catch_arm_return__03_ppir.snap} (91%) rename baml_language/crates/baml_tests/snapshots/compiles/catch_throw/{baml_tests__compiles__catch_throw__03_hir.snap => baml_tests__compiles__catch_throw__03_ppir.snap} (97%) rename baml_language/crates/baml_tests/snapshots/compiles/closure_loop_variable/{baml_tests__compiles__closure_loop_variable__03_hir.snap => baml_tests__compiles__closure_loop_variable__03_ppir.snap} (89%) rename baml_language/crates/baml_tests/snapshots/compiles/closures/{baml_tests__compiles__closures__03_hir.snap => baml_tests__compiles__closures__03_ppir.snap} (86%) rename baml_language/crates/baml_tests/snapshots/compiles/comment_after_string_in_config/{baml_tests__compiles__comment_after_string_in_config__03_hir.snap => baml_tests__compiles__comment_after_string_in_config__03_ppir.snap} (95%) rename baml_language/crates/baml_tests/snapshots/compiles/comment_in_type/{baml_tests__compiles__comment_in_type__03_hir.snap => baml_tests__compiles__comment_in_type__03_ppir.snap} (65%) rename baml_language/crates/baml_tests/snapshots/compiles/config_dictionary/{baml_tests__compiles__config_dictionary__03_hir.snap => baml_tests__compiles__config_dictionary__03_ppir.snap} (97%) rename baml_language/crates/baml_tests/snapshots/compiles/config_model_string/{baml_tests__compiles__config_model_string__03_hir.snap => baml_tests__compiles__config_model_string__03_ppir.snap} (95%) rename baml_language/crates/baml_tests/snapshots/compiles/deep_method_call/{baml_tests__compiles__deep_method_call__03_hir.snap => baml_tests__compiles__deep_method_call__03_ppir.snap} (76%) rename baml_language/crates/baml_tests/snapshots/compiles/function_call/{baml_tests__compiles__function_call__03_hir.snap => baml_tests__compiles__function_call__03_ppir.snap} (88%) rename baml_language/crates/baml_tests/snapshots/compiles/generic_field_chain/{baml_tests__compiles__generic_field_chain__03_hir.snap => baml_tests__compiles__generic_field_chain__03_ppir.snap} (79%) rename baml_language/crates/baml_tests/snapshots/compiles/generic_match_typevar_arm/{baml_tests__compiles__generic_match_typevar_arm__03_hir.snap => baml_tests__compiles__generic_match_typevar_arm__03_ppir.snap} (70%) rename baml_language/crates/baml_tests/snapshots/compiles/host_callable_call/{baml_tests__compiles__host_callable_call__03_hir.snap => baml_tests__compiles__host_callable_call__03_ppir.snap} (82%) rename baml_language/crates/baml_tests/snapshots/compiles/is_operator/{baml_tests__compiles__is_operator__03_hir.snap => baml_tests__compiles__is_operator__03_ppir.snap} (94%) rename baml_language/crates/baml_tests/snapshots/compiles/json_alias_basic/{baml_tests__compiles__json_alias_basic__03_hir.snap => baml_tests__compiles__json_alias_basic__03_ppir.snap} (90%) rename baml_language/crates/baml_tests/snapshots/compiles/json_cross_namespace_static_call/{baml_tests__compiles__json_cross_namespace_static_call__03_hir.snap => baml_tests__compiles__json_cross_namespace_static_call__03_ppir.snap} (73%) rename baml_language/crates/baml_tests/snapshots/compiles/json_llm_return_type/{baml_tests__compiles__json_llm_return_type__03_hir.snap => baml_tests__compiles__json_llm_return_type__03_ppir.snap} (68%) rename baml_language/crates/baml_tests/snapshots/compiles/json_map_literal/{baml_tests__compiles__json_map_literal__03_hir.snap => baml_tests__compiles__json_map_literal__03_ppir.snap} (84%) rename baml_language/crates/baml_tests/snapshots/compiles/json_parse_stringify_intrinsics/{baml_tests__compiles__json_parse_stringify_intrinsics__03_hir.snap => baml_tests__compiles__json_parse_stringify_intrinsics__03_ppir.snap} (95%) rename baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_composite_generic/{baml_tests__compiles__json_to_from_string_composite_generic__03_hir.snap => baml_tests__compiles__json_to_from_string_composite_generic__03_ppir.snap} (64%) rename baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_concrete/{baml_tests__compiles__json_to_from_string_concrete__03_hir.snap => baml_tests__compiles__json_to_from_string_concrete__03_ppir.snap} (74%) rename baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_generic_forwarding/{baml_tests__compiles__json_to_from_string_generic_forwarding__03_hir.snap => baml_tests__compiles__json_to_from_string_generic_forwarding__03_ppir.snap} (80%) rename baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_three_level/{baml_tests__compiles__json_to_from_string_three_level__03_hir.snap => baml_tests__compiles__json_to_from_string_three_level__03_ppir.snap} (88%) rename baml_language/crates/baml_tests/snapshots/compiles/lambda_advanced/{baml_tests__compiles__lambda_advanced__03_hir.snap => baml_tests__compiles__lambda_advanced__03_ppir.snap} (99%) rename baml_language/crates/baml_tests/snapshots/compiles/lambda_basic/{baml_tests__compiles__lambda_basic__03_hir.snap => baml_tests__compiles__lambda_basic__03_ppir.snap} (97%) rename baml_language/crates/baml_tests/snapshots/compiles/lambda_fat_arrow/{baml_tests__compiles__lambda_fat_arrow__03_hir.snap => baml_tests__compiles__lambda_fat_arrow__03_ppir.snap} (95%) rename baml_language/crates/baml_tests/snapshots/compiles/lambda_field_access/{baml_tests__compiles__lambda_field_access__03_hir.snap => baml_tests__compiles__lambda_field_access__03_ppir.snap} (90%) rename baml_language/crates/baml_tests/snapshots/compiles/lexical_scoping/{baml_tests__compiles__lexical_scoping__03_hir.snap => baml_tests__compiles__lexical_scoping__03_ppir.snap} (97%) rename baml_language/crates/baml_tests/snapshots/compiles/literal_union_arithmetic/{baml_tests__compiles__literal_union_arithmetic__03_hir.snap => baml_tests__compiles__literal_union_arithmetic__03_ppir.snap} (94%) rename baml_language/crates/baml_tests/snapshots/compiles/literal_union_widening/{baml_tests__compiles__literal_union_widening__03_hir.snap => baml_tests__compiles__literal_union_widening__03_ppir.snap} (92%) rename baml_language/crates/baml_tests/snapshots/compiles/llm_image_outputs/{baml_tests__compiles__llm_image_outputs__03_hir.snap => baml_tests__compiles__llm_image_outputs__03_ppir.snap} (65%) rename baml_language/crates/baml_tests/snapshots/compiles/llm_parse_catchable_parse_error/{baml_tests__compiles__llm_parse_catchable_parse_error__03_hir.snap => baml_tests__compiles__llm_parse_catchable_parse_error__03_ppir.snap} (70%) rename baml_language/crates/baml_tests/snapshots/compiles/method_explicit_type_args/{baml_tests__compiles__method_explicit_type_args__03_hir.snap => baml_tests__compiles__method_explicit_type_args__03_ppir.snap} (77%) rename baml_language/crates/baml_tests/snapshots/compiles/namespaces_basic/{baml_tests__compiles__namespaces_basic__03_hir.snap => baml_tests__compiles__namespaces_basic__03_ppir.snap} (70%) rename baml_language/crates/baml_tests/snapshots/compiles/namespaces_nested/{baml_tests__compiles__namespaces_nested__03_hir.snap => baml_tests__compiles__namespaces_nested__03_ppir.snap} (64%) rename baml_language/crates/baml_tests/snapshots/compiles/namespaces_root_fallback/{baml_tests__compiles__namespaces_root_fallback__03_hir.snap => baml_tests__compiles__namespaces_root_fallback__03_ppir.snap} (64%) delete mode 100644 baml_language/crates/baml_tests/snapshots/compiles/namespaces_shadow/baml_tests__compiles__namespaces_shadow__03_hir.snap create mode 100644 baml_language/crates/baml_tests/snapshots/compiles/namespaces_shadow/baml_tests__compiles__namespaces_shadow__03_ppir.snap rename baml_language/crates/baml_tests/snapshots/compiles/namespaces_type_resolution/{baml_tests__compiles__namespaces_type_resolution__03_hir.snap => baml_tests__compiles__namespaces_type_resolution__03_ppir.snap} (83%) rename baml_language/crates/baml_tests/snapshots/compiles/numeric_invariance_ok/{baml_tests__compiles__numeric_invariance_ok__03_hir.snap => baml_tests__compiles__numeric_invariance_ok__03_ppir.snap} (86%) rename baml_language/crates/baml_tests/snapshots/compiles/numeric_literal_method_call/{baml_tests__compiles__numeric_literal_method_call__03_hir.snap => baml_tests__compiles__numeric_literal_method_call__03_ppir.snap} (92%) rename baml_language/crates/baml_tests/snapshots/compiles/o1_allowed_roles/{baml_tests__compiles__o1_allowed_roles__03_hir.snap => baml_tests__compiles__o1_allowed_roles__03_ppir.snap} (98%) rename baml_language/crates/baml_tests/snapshots/compiles/optional_function_parameters/{baml_tests__compiles__optional_function_parameters__03_hir.snap => baml_tests__compiles__optional_function_parameters__03_ppir.snap} (80%) rename baml_language/crates/baml_tests/snapshots/compiles/paren_union_test/{baml_tests__compiles__paren_union_test__03_hir.snap => baml_tests__compiles__paren_union_test__03_ppir.snap} (53%) rename baml_language/crates/baml_tests/snapshots/compiles/parser_expressions/{baml_tests__compiles__parser_expressions__03_hir.snap => baml_tests__compiles__parser_expressions__03_ppir.snap} (73%) rename baml_language/crates/baml_tests/snapshots/compiles/parser_statements/{baml_tests__compiles__parser_statements__03_hir.snap => baml_tests__compiles__parser_statements__03_ppir.snap} (95%) rename baml_language/crates/baml_tests/snapshots/compiles/patterns_class_destructure_namespaces/{baml_tests__compiles__patterns_class_destructure_namespaces__03_hir.snap => baml_tests__compiles__patterns_class_destructure_namespaces__03_ppir.snap} (93%) rename baml_language/crates/baml_tests/snapshots/compiles/patterns_new/{baml_tests__compiles__patterns_new__03_hir.snap => baml_tests__compiles__patterns_new__03_ppir.snap} (95%) rename baml_language/crates/baml_tests/snapshots/compiles/reflect_type_of_user_generic/{baml_tests__compiles__reflect_type_of_user_generic__03_hir.snap => baml_tests__compiles__reflect_type_of_user_generic__03_ppir.snap} (82%) rename baml_language/crates/baml_tests/snapshots/compiles/retry_policy/{baml_tests__compiles__retry_policy__03_hir.snap => baml_tests__compiles__retry_policy__03_ppir.snap} (94%) rename baml_language/crates/baml_tests/snapshots/compiles/scientific_notation_float/{baml_tests__compiles__scientific_notation_float__03_hir.snap => baml_tests__compiles__scientific_notation_float__03_ppir.snap} (93%) delete mode 100644 baml_language/crates/baml_tests/snapshots/compiles/stream_crossfile/baml_tests__compiles__stream_crossfile__03_hir.snap create mode 100644 baml_language/crates/baml_tests/snapshots/compiles/stream_crossfile/baml_tests__compiles__stream_crossfile__03_ppir.snap rename baml_language/crates/baml_tests/snapshots/compiles/stream_llm_inferred_typeargs/{baml_tests__compiles__stream_llm_inferred_typeargs__03_hir.snap => baml_tests__compiles__stream_llm_inferred_typeargs__03_ppir.snap} (73%) rename baml_language/crates/baml_tests/snapshots/compiles/{top_level_let/baml_tests__compiles__top_level_let__03_hir.snap => string_methods/baml_tests__compiles__string_methods__03_ppir.snap} (61%) rename baml_language/crates/baml_tests/snapshots/compiles/test_expr_basic/{baml_tests__compiles__test_expr_basic__03_hir.snap => baml_tests__compiles__test_expr_basic__03_ppir.snap} (91%) rename baml_language/crates/baml_tests/snapshots/compiles/test_expr_name_concat/{baml_tests__compiles__test_expr_name_concat__03_hir.snap => baml_tests__compiles__test_expr_name_concat__03_ppir.snap} (93%) rename baml_language/crates/baml_tests/snapshots/compiles/test_expr_throwing_body/{baml_tests__compiles__test_expr_throwing_body__03_hir.snap => baml_tests__compiles__test_expr_throwing_body__03_ppir.snap} (89%) rename baml_language/crates/baml_tests/snapshots/compiles/test_expr_with_runner/{baml_tests__compiles__test_expr_with_runner__03_hir.snap => baml_tests__compiles__test_expr_with_runner__03_ppir.snap} (88%) rename baml_language/crates/baml_tests/snapshots/compiles/test_old_and_new/{baml_tests__compiles__test_old_and_new__03_hir.snap => baml_tests__compiles__test_old_and_new__03_ppir.snap} (90%) rename baml_language/crates/baml_tests/snapshots/compiles/test_raw_string_name/{baml_tests__compiles__test_raw_string_name__03_hir.snap => baml_tests__compiles__test_raw_string_name__03_ppir.snap} (93%) rename baml_language/crates/baml_tests/snapshots/compiles/test_with_not_keyword/{baml_tests__compiles__test_with_not_keyword__03_hir.snap => baml_tests__compiles__test_with_not_keyword__03_ppir.snap} (79%) rename baml_language/crates/baml_tests/snapshots/compiles/testset_basic/{baml_tests__compiles__testset_basic__03_hir.snap => baml_tests__compiles__testset_basic__03_ppir.snap} (91%) rename baml_language/crates/baml_tests/snapshots/compiles/testset_dynamic/{baml_tests__compiles__testset_dynamic__03_hir.snap => baml_tests__compiles__testset_dynamic__03_ppir.snap} (95%) rename baml_language/crates/baml_tests/snapshots/compiles/testset_nested/{baml_tests__compiles__testset_nested__03_hir.snap => baml_tests__compiles__testset_nested__03_ppir.snap} (94%) rename baml_language/crates/baml_tests/snapshots/compiles/testset_vibes_nested/{baml_tests__compiles__testset_vibes_nested__03_hir.snap => baml_tests__compiles__testset_vibes_nested__03_ppir.snap} (71%) rename baml_language/crates/baml_tests/snapshots/compiles/testset_with_setup/{baml_tests__compiles__testset_with_setup__03_hir.snap => baml_tests__compiles__testset_with_setup__03_ppir.snap} (94%) rename baml_language/crates/baml_tests/snapshots/compiles/top_level_header_comment/{baml_tests__compiles__top_level_header_comment__03_hir.snap => baml_tests__compiles__top_level_header_comment__03_ppir.snap} (75%) rename baml_language/crates/baml_tests/snapshots/compiles/{string_methods/baml_tests__compiles__string_methods__03_hir.snap => top_level_let/baml_tests__compiles__top_level_let__03_ppir.snap} (61%) rename baml_language/crates/baml_tests/snapshots/compiles/type_annotation/{baml_tests__compiles__type_annotation__03_hir.snap => baml_tests__compiles__type_annotation__03_ppir.snap} (81%) rename baml_language/crates/baml_tests/snapshots/compiles/type_builder_errors/{baml_tests__compiles__type_builder_errors__03_hir.snap => baml_tests__compiles__type_builder_errors__03_ppir.snap} (58%) rename baml_language/crates/baml_tests/snapshots/compiles/type_builder_test/{baml_tests__compiles__type_builder_test__03_hir.snap => baml_tests__compiles__type_builder_test__03_ppir.snap} (56%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/anyfunction/{baml_tests__diagnostic_errors__anyfunction__03_hir.snap => baml_tests__diagnostic_errors__anyfunction__03_ppir.snap} (78%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/assignment_expr_position/{baml_tests__diagnostic_errors__assignment_expr_position__03_hir.snap => baml_tests__diagnostic_errors__assignment_expr_position__03_ppir.snap} (82%) delete mode 100644 baml_language/crates/baml_tests/snapshots/diagnostic_errors/attr_disambiguation/baml_tests__diagnostic_errors__attr_disambiguation__03_hir.snap create mode 100644 baml_language/crates/baml_tests/snapshots/diagnostic_errors/attr_disambiguation/baml_tests__diagnostic_errors__attr_disambiguation__03_ppir.snap rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/attribute_validation/{baml_tests__diagnostic_errors__attribute_validation__03_hir.snap => baml_tests__diagnostic_errors__attribute_validation__03_ppir.snap} (58%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/backtick_interp_type_errors/{baml_tests__diagnostic_errors__backtick_interp_type_errors__03_hir.snap => baml_tests__diagnostic_errors__backtick_interp_type_errors__03_ppir.snap} (94%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/backtick_strict_types/{baml_tests__diagnostic_errors__backtick_strict_types__03_hir.snap => baml_tests__diagnostic_errors__backtick_strict_types__03_ppir.snap} (89%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/basic_types/{baml_tests__diagnostic_errors__basic_types__03_hir.snap => baml_tests__diagnostic_errors__basic_types__03_ppir.snap} (53%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/builtin_io/{baml_tests__diagnostic_errors__builtin_io__03_hir.snap => baml_tests__diagnostic_errors__builtin_io__03_ppir.snap} (99%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/captured_field_chain/{baml_tests__diagnostic_errors__captured_field_chain__03_hir.snap => baml_tests__diagnostic_errors__captured_field_chain__03_ppir.snap} (82%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_arm_braceless_return/{baml_tests__diagnostic_errors__catch_arm_braceless_return__03_hir.snap => baml_tests__diagnostic_errors__catch_arm_braceless_return__03_ppir.snap} (87%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_return_type_mismatch/{baml_tests__diagnostic_errors__catch_return_type_mismatch__03_hir.snap => baml_tests__diagnostic_errors__catch_return_type_mismatch__03_ppir.snap} (90%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_throw_regressions/{baml_tests__diagnostic_errors__catch_throw_regressions__03_hir.snap => baml_tests__diagnostic_errors__catch_throw_regressions__03_ppir.snap} (95%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/client_option_types/{baml_tests__diagnostic_errors__client_option_types__03_hir.snap => baml_tests__diagnostic_errors__client_option_types__03_ppir.snap} (99%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/closure_errors/{baml_tests__diagnostic_errors__closure_errors__03_hir.snap => baml_tests__diagnostic_errors__closure_errors__03_ppir.snap} (85%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/control_flow/{baml_tests__diagnostic_errors__control_flow__03_hir.snap => baml_tests__diagnostic_errors__control_flow__03_ppir.snap} (81%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_attribute/{baml_tests__diagnostic_errors__duplicate_attribute__03_hir.snap => baml_tests__diagnostic_errors__duplicate_attribute__03_ppir.snap} (54%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_class_span/{baml_tests__diagnostic_errors__duplicate_class_span__03_hir.snap => baml_tests__diagnostic_errors__duplicate_class_span__03_ppir.snap} (56%) delete mode 100644 baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_field_alias/baml_tests__diagnostic_errors__duplicate_field_alias__03_hir.snap create mode 100644 baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_field_alias/baml_tests__diagnostic_errors__duplicate_field_alias__03_ppir.snap rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_variant_alias/{baml_tests__diagnostic_errors__duplicate_variant_alias__03_hir.snap => baml_tests__diagnostic_errors__duplicate_variant_alias__03_ppir.snap} (91%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/format_checks/{baml_tests__diagnostic_errors__format_checks__03_hir.snap => baml_tests__diagnostic_errors__format_checks__03_ppir.snap} (80%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_missing_throws/{baml_tests__diagnostic_errors__function_type_missing_throws__03_hir.snap => baml_tests__diagnostic_errors__function_type_missing_throws__03_ppir.snap} (85%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_throws/{baml_tests__diagnostic_errors__function_type_throws__03_hir.snap => baml_tests__diagnostic_errors__function_type_throws__03_ppir.snap} (89%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_types/{baml_tests__diagnostic_errors__function_types__03_hir.snap => baml_tests__diagnostic_errors__function_types__03_ppir.snap} (66%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_call_ambiguity/{baml_tests__diagnostic_errors__generic_call_ambiguity__03_hir.snap => baml_tests__diagnostic_errors__generic_call_ambiguity__03_ppir.snap} (95%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_class_destructure_no_type_args/{baml_tests__diagnostic_errors__generic_class_destructure_no_type_args__03_hir.snap => baml_tests__diagnostic_errors__generic_class_destructure_no_type_args__03_ppir.snap} (73%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_error_arg_no_cascade/{baml_tests__diagnostic_errors__generic_error_arg_no_cascade__03_hir.snap => baml_tests__diagnostic_errors__generic_error_arg_no_cascade__03_ppir.snap} (92%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/generics/{baml_tests__diagnostic_errors__generics__03_hir.snap => baml_tests__diagnostic_errors__generics__03_ppir.snap} (82%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/headers_edge_cases/{baml_tests__diagnostic_errors__headers_edge_cases__03_hir.snap => baml_tests__diagnostic_errors__headers_edge_cases__03_ppir.snap} (98%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/instanceof_removed/{baml_tests__diagnostic_errors__instanceof_removed__03_hir.snap => baml_tests__diagnostic_errors__instanceof_removed__03_ppir.snap} (72%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/invalid_numeric_literals/{baml_tests__diagnostic_errors__invalid_numeric_literals__03_hir.snap => baml_tests__diagnostic_errors__invalid_numeric_literals__03_ppir.snap} (87%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/is_pattern_negative/{baml_tests__diagnostic_errors__is_pattern_negative__03_hir.snap => baml_tests__diagnostic_errors__is_pattern_negative__03_ppir.snap} (85%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/json_alias/{baml_tests__diagnostic_errors__json_alias__03_hir.snap => baml_tests__diagnostic_errors__json_alias__03_ppir.snap} (78%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/json_static_method_arity/{baml_tests__diagnostic_errors__json_static_method_arity__03_hir.snap => baml_tests__diagnostic_errors__json_static_method_arity__03_ppir.snap} (84%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/lambda_errors/{baml_tests__diagnostic_errors__lambda_errors__03_hir.snap => baml_tests__diagnostic_errors__lambda_errors__03_ppir.snap} (95%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/lexical_scoping_errors/{baml_tests__diagnostic_errors__lexical_scoping_errors__03_hir.snap => baml_tests__diagnostic_errors__lexical_scoping_errors__03_ppir.snap} (90%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/match_exhaustiveness/{baml_tests__diagnostic_errors__match_exhaustiveness__03_hir.snap => baml_tests__diagnostic_errors__match_exhaustiveness__03_ppir.snap} (92%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_bare_name_rejected/{baml_tests__diagnostic_errors__namespaces_bare_name_rejected__03_hir.snap => baml_tests__diagnostic_errors__namespaces_bare_name_rejected__03_ppir.snap} (64%) delete mode 100644 baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_conflict/baml_tests__diagnostic_errors__namespaces_conflict__03_hir.snap create mode 100644 baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_conflict/baml_tests__diagnostic_errors__namespaces_conflict__03_ppir.snap rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_stream_direct_ref/{baml_tests__diagnostic_errors__namespaces_stream_direct_ref__03_hir.snap => baml_tests__diagnostic_errors__namespaces_stream_direct_ref__03_ppir.snap} (61%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/null_handling/{baml_tests__diagnostic_errors__null_handling__03_hir.snap => baml_tests__diagnostic_errors__null_handling__03_ppir.snap} (87%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/numeric_invariance/{baml_tests__diagnostic_errors__numeric_invariance__03_hir.snap => baml_tests__diagnostic_errors__numeric_invariance__03_ppir.snap} (94%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/optional_parameter_defaults/{baml_tests__diagnostic_errors__optional_parameter_defaults__03_hir.snap => baml_tests__diagnostic_errors__optional_parameter_defaults__03_ppir.snap} (91%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/parser_constructors/{baml_tests__diagnostic_errors__parser_constructors__03_hir.snap => baml_tests__diagnostic_errors__parser_constructors__03_ppir.snap} (84%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_array_rest_binding/{baml_tests__diagnostic_errors__patterns_array_rest_binding__03_hir.snap => baml_tests__diagnostic_errors__patterns_array_rest_binding__03_ppir.snap} (93%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_class_destructure/{baml_tests__diagnostic_errors__patterns_class_destructure__03_hir.snap => baml_tests__diagnostic_errors__patterns_class_destructure__03_ppir.snap} (93%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_class_destructure_namespaces/{baml_tests__diagnostic_errors__patterns_class_destructure_namespaces__03_hir.snap => baml_tests__diagnostic_errors__patterns_class_destructure_namespaces__03_ppir.snap} (87%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_new/{baml_tests__diagnostic_errors__patterns_new__03_hir.snap => baml_tests__diagnostic_errors__patterns_new__03_ppir.snap} (89%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/runtime_id_misuse/{baml_tests__diagnostic_errors__runtime_id_misuse__03_hir.snap => baml_tests__diagnostic_errors__runtime_id_misuse__03_ppir.snap} (89%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/self_in_body/{baml_tests__diagnostic_errors__self_in_body__03_hir.snap => baml_tests__diagnostic_errors__self_in_body__03_ppir.snap} (92%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/simple_function/{baml_tests__diagnostic_errors__simple_function__03_hir.snap => baml_tests__diagnostic_errors__simple_function__03_ppir.snap} (58%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/simple_type_error/{baml_tests__diagnostic_errors__simple_type_error__03_hir.snap => baml_tests__diagnostic_errors__simple_type_error__03_ppir.snap} (76%) delete mode 100644 baml_language/crates/baml_tests/snapshots/diagnostic_errors/stream_types/baml_tests__diagnostic_errors__stream_types__03_hir.snap create mode 100644 baml_language/crates/baml_tests/snapshots/diagnostic_errors/stream_types/baml_tests__diagnostic_errors__stream_types__03_ppir.snap rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_expr_name_type_error/{baml_tests__diagnostic_errors__test_expr_name_type_error__03_hir.snap => baml_tests__diagnostic_errors__test_expr_name_type_error__03_ppir.snap} (92%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_expr_wrong_runner/{baml_tests__diagnostic_errors__test_expr_wrong_runner__03_hir.snap => baml_tests__diagnostic_errors__test_expr_wrong_runner__03_ppir.snap} (93%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_with_runner_ambiguity/{baml_tests__diagnostic_errors__test_with_runner_ambiguity__03_hir.snap => baml_tests__diagnostic_errors__test_with_runner_ambiguity__03_ppir.snap} (84%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/type_aliases/{baml_tests__diagnostic_errors__type_aliases__03_hir.snap => baml_tests__diagnostic_errors__type_aliases__03_ppir.snap} (64%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/type_reflection_strict/{baml_tests__diagnostic_errors__type_reflection_strict__03_hir.snap => baml_tests__diagnostic_errors__type_reflection_strict__03_ppir.snap} (90%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/unknown_type_error/{baml_tests__diagnostic_errors__unknown_type_error__03_hir.snap => baml_tests__diagnostic_errors__unknown_type_error__03_ppir.snap} (88%) rename baml_language/crates/baml_tests/snapshots/diagnostic_errors/void_return_type/{baml_tests__diagnostic_errors__void_return_type__03_hir.snap => baml_tests__diagnostic_errors__void_return_type__03_ppir.snap} (92%) diff --git a/baml_language/crates/baml_tests/build.rs b/baml_language/crates/baml_tests/build.rs index ca13f9934ed..8439e4328e2 100644 --- a/baml_language/crates/baml_tests/build.rs +++ b/baml_language/crates/baml_tests/build.rs @@ -617,7 +617,7 @@ fn generate_hir_test(project: &TestProject, stdlib_package_filter: Option<&str>) quote! { { let pkg_filter = #pkg_lit; - writeln!(output, "\n=== HIR2 (package {}) ===", pkg_filter).unwrap(); + writeln!(output, "\n=== PPIR (package {}) ===", pkg_filter).unwrap(); use baml_compiler2_hir::{compiler2_all_files, file_package::file_package}; let mut baml_files: Vec<_> = compiler2_all_files(&db) .into_iter() @@ -626,7 +626,7 @@ fn generate_hir_test(project: &TestProject, stdlib_package_filter: Option<&str>) baml_files.sort_by_key(|f| f.path(&db).to_string_lossy().to_string()); for sf in baml_files { writeln!(output, "\n--- {} ---", sf.path(&db).display()).unwrap(); - output.push_str(&render_hir2(&db, sf)); + output.push_str(&render_ppir(&db, sf)); } } } @@ -636,8 +636,8 @@ fn generate_hir_test(project: &TestProject, stdlib_package_filter: Option<&str>) quote! { #[test] - fn test_03_hir() { - use crate::compiler2_tir::support::render_hir2; + fn test_03_ppir() { + use crate::compiler2_tir::support::render_ppir; let mut db = ProjectDatabase::new(); let _root = db.set_project_root(std::path::Path::new(".")); @@ -646,16 +646,16 @@ fn generate_hir_test(project: &TestProject, stdlib_package_filter: Option<&str>) #file_loaders let mut output = String::new(); - writeln!(output, "=== HIR2 ===").unwrap(); + writeln!(output, "=== PPIR ===").unwrap(); for source_file in &source_files { - output.push_str(&render_hir2(&db, *source_file)); + output.push_str(&render_ppir(&db, *source_file)); } #stdlib_section with_settings!({snapshot_path => SNAPSHOT_PATH, omit_expression => true}, { - assert_snapshot!("03_hir", output); + assert_snapshot!("03_ppir", output); }); } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/__assert_std__/baml_tests__compiles____assert_std____03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/__assert_std__/baml_tests__compiles____assert_std____03_ppir.snap similarity index 95% rename from baml_language/crates/baml_tests/snapshots/compiles/__assert_std__/baml_tests__compiles____assert_std____03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/__assert_std__/baml_tests__compiles____assert_std____03_ppir.snap index de65f0aac63..6819cd14636 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/__assert_std__/baml_tests__compiles____assert_std____03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/__assert_std__/baml_tests__compiles____assert_std____03_ppir.snap @@ -1,9 +1,10 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 4244 --- -=== HIR2 === +=== PPIR === -=== HIR2 (package assert) === +=== PPIR (package assert) === --- /assert/assert.baml --- function assert.approx_equal(actual: float, expected: float, eps: float) -> null [expr] { diff --git a/baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____03_ppir.snap similarity index 87% rename from baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____03_ppir.snap index beba75f3fa5..3b9dd9f4c85 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____03_ppir.snap @@ -1,13 +1,16 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 4640 --- -=== HIR2 === +=== PPIR === -=== HIR2 (package baml) === +=== PPIR (package baml) === --- /baml/bigint.baml --- class baml.Bigint { } +class baml.Bigint$stream { +} function baml.abs(self: ?) -> bigint [builtin] function baml.clamp(self: ?, min: bigint, max: bigint) -> bigint [builtin] function baml.ilog(self: ?, base: bigint) -> bigint [builtin] @@ -21,6 +24,8 @@ function baml.random(lower: bigint, upper: bigint) -> bigint [builtin] --- /baml/bool.baml --- class baml.Bool { } +class baml.Bool$stream { +} --- /baml/comparable.baml --- function baml._compare_shim(a: T, b: T) -> int [builtin] @@ -31,13 +36,13 @@ function baml.compare(self: ?, other: Self) -> int [expr] { { } if (self Lt other) { } Neg 1 else if (self Gt other) { } 1 else { } 0 } function baml.compare(self: ?, other: Self) -> int [expr] { - { } root._float_total_cmp(self, other) + { } if (self Lt other) { } Neg 1 else if (self Gt other) { } 1 else { } 0 } function baml.compare(self: ?, other: Self) -> int [expr] { { } if (self Lt other) { } Neg 1 else if (self Gt other) { } 1 else { } 0 } function baml.compare(self: ?, other: Self) -> int [expr] { - { } if (self Lt other) { } Neg 1 else if (self Gt other) { } 1 else { } 0 + { } root._float_total_cmp(self, other) } function baml.sort(self: ?) -> Self [expr] { { } if (root._is_primitive_array(self)) { } root._rust_sort(self) else { } self.sort_by((a: T, b: T) -> int throws T.CompareError { { } root._compare_shim(a, b) }) @@ -46,8 +51,12 @@ function baml.sort(self: ?) -> Self [expr] { --- /baml/containers.baml --- class baml.Array { } +class baml.Array$stream { +} class baml.Map { } +class baml.Map$stream { +} function baml._mean_float(values: float[]) -> float [builtin] function baml._median_float(values: float[]) -> float [builtin] function baml._sum_float(values: float[]) -> float [builtin] @@ -106,12 +115,12 @@ function baml.sort_by_key(self: ?, key: (T) -> U throws E) -> T[] [expr] { { let n = self.length(); if (n Le 1) { return self }; let items = self.slice(0, n); let keys: U[] = []; for x in items { keys.push(key(x)) }; let order: int[] = []; let p = 0; while p Lt n { order.push(p); p Add= 1 }; order.sort_by((i: int, j: int) -> int throws U.CompareError { { } match (keys.at(i)) { null => 0, ki: U => match (keys.at(j)) { null => 0, kj: U => ki.compare(kj) } } }); let sorted: T[] = []; for i in order { } match (items.at(i)) { null => { }, item: T => { sorted.push(item) } }; self.clear(); for s in sorted { self.push(s) }; return self } } function baml.splice(self: ?, start: int, count: int, replace: T[]) -> null [builtin] -function baml.sum(self: ?) -> float [expr] { - { } root._sum_float(self) -} function baml.sum(self: ?) -> int [expr] { { } root._sum_int(self) } +function baml.sum(self: ?) -> float [expr] { + { } root._sum_float(self) +} function baml.unshift(self: ?, item: T) -> int [builtin] function baml.values(self: ?) -> V[] [builtin] @@ -137,12 +146,18 @@ class baml.TaggedString { parts: string[] values: unknown[] } +class baml.TaggedString$stream { + parts: string[] + values: unknown[] +} function baml.deep_copy(value: T) -> T [builtin] function baml.deep_equals(a: T, b: T) -> bool [builtin] --- /baml/float.baml --- class baml.Float { } +class baml.Float$stream { +} function baml._trunc_to_int(value: float) -> int [builtin] function baml.abs(self: ?) -> float [builtin] function baml.acos(self: ?) -> float [builtin] @@ -196,6 +211,8 @@ function baml.trunc(self: ?) -> float [builtin] --- /baml/int.baml --- class baml.Int { } +class baml.Int$stream { +} function baml.abs(self: ?) -> int [builtin] function baml.clamp(self: ?, min: int, max: int) -> int [builtin] function baml.count_ones(self: ?) -> int [builtin] @@ -229,36 +246,76 @@ class baml.csv.CsvError { expected: int? found: int? } +class baml.csv.CsvError$stream { + kind: baml.csv.CsvErrorKind | null + message: string | null + line: int | null + record: int | null + field: int | null + column: string | null + expected: int | null + found: int | null +} class baml.csv.CsvHeaders { names: string[]? } +class baml.csv.CsvHeaders$stream { + names: string[] | null +} class baml.csv.CsvNeedData { } +class baml.csv.CsvNeedData$stream { +} class baml.csv.CsvPosition { byte: int line: int record: int } +class baml.csv.CsvPosition$stream { + byte: int | null + line: int | null + record: int | null +} class baml.csv.CsvReader { _handle: $rust_type _file: root.fs.File? _on_skip: (baml.csv.CsvError) -> null throws never? _owns_file: bool } +class baml.csv.CsvReader$stream { + _handle: $rust_type + _file: root.fs.File$stream | null + _on_skip: unknown | null + _owns_file: bool | null +} class baml.csv.CsvRecord { _handle: $rust_type } +class baml.csv.CsvRecord$stream { + _handle: $rust_type +} class baml.csv.CsvRows { reader: baml.csv.CsvReader } +class baml.csv.CsvRows$stream { + reader: baml.csv.CsvReader$stream | null +} class baml.csv.CsvSkip { error: baml.csv.CsvError } +class baml.csv.CsvSkip$stream { + error: baml.csv.CsvError$stream | null +} class baml.csv.CsvWriter { _handle: $rust_type _file: root.fs.File? _owns_file: bool } +class baml.csv.CsvWriter$stream { + _handle: $rust_type + _file: root.fs.File$stream | null + _owns_file: bool | null +} class baml.csv.ReaderOptions { delimiter: string? quote: string? @@ -279,6 +336,26 @@ class baml.csv.ReaderOptions { max_skipped: int? limit: int? } +class baml.csv.ReaderOptions$stream { + delimiter: string | null + quote: string | null + quoting: bool | null + escape: string | null + has_header: bool | null + headers: string[] | null + comment: string | null + trim: "none" | "headers" | "fields" | "all" | null + skip_lines: int | null + skip_blank_records: bool | null + ragged: "strict" | "pad" | "truncate" | null + null_values: string[] | null + encoding: "utf8" | "utf8-lossy" | null + bom: "strip" | "keep" | null + on_error: "throw" | "skip" | null + on_skip: unknown | null + max_skipped: int | null + limit: int | null +} class baml.csv.WriterOptions { delimiter: string? quote: string? @@ -291,8 +368,21 @@ class baml.csv.WriterOptions { bom: bool? sanitize_formulas: bool? } +class baml.csv.WriterOptions$stream { + delimiter: string | null + quote: string | null + quote_style: "minimal" | "all" | "never" | null + escape: string | null + terminator: "lf" | "crlf" | null + write_header: bool | null + headers: string[] | null + null_value: string | null + bom: bool | null + sanitize_formulas: bool | null +} enum baml.csv.CsvErrorKind {Options, Quote, FieldCount, Encoding, Header, Decode, Encode, NotFound, TooManyRows, Closed} type baml.csv.CsvValue = null | bool | int | bigint | float | string +type baml.csv.CsvValue$stream = null | bool | int | bigint | float | string function baml.csv._buffer(options: baml.csv.WriterOptions?) -> baml.csv.CsvWriter [builtin] function baml.csv._bytes_written(self: ?) -> int [builtin] function baml.csv._cell_by_index(rec: baml.csv.CsvRecord, index: int) -> T? [builtin] @@ -336,12 +426,12 @@ function baml.csv.close(self: ?) -> null [expr] { function baml.csv.create(path: string, options: baml.csv.WriterOptions? = null) -> baml.csv.CsvWriter [expr] { { let f = baml.fs.open(path, "w") catch (_) { root.errors.InvalidArgument { message: message } => throw root.errors.Io { message: message } } } _writer(f, options, true) } -function baml.csv.decode(source: string | uint8array, options: baml.csv.ReaderOptions? = null) -> T[] [expr] { - { } { } reader(source, options = options).rows().collect() catch (_) { root.errors.Io { message: message } => root.sys.panic("unreachable: in-m..." Add message) } -} function baml.csv.decode(self: ?) -> T [expr] { { } _decode_record(self) } +function baml.csv.decode(source: string | uint8array, options: baml.csv.ReaderOptions? = null) -> T[] [expr] { + { } { } reader(source, options = options).rows().collect() catch (_) { root.errors.Io { message: message } => root.sys.panic("unreachable: in-m..." Add message) } +} function baml.csv.decode_one(source: string | uint8array, options: baml.csv.ReaderOptions? = null) -> T [expr] { { let all = decode(source, options = options); if (all.length() Eq 0) { throw _error(CsvErrorKind.NotFound, "expected exactly ...") }; if (all.length() Gt 1) { throw _error(CsvErrorKind.TooManyRows, "expected exactly ..." Add root.json.stringify(all.length())) } } match (all.at(0)) { null => root.sys.panic("unreachable: deco..."), v: T => v } } @@ -368,12 +458,12 @@ function baml.csv.iter(self: ?) -> root.iter.Iterator int [builtin] -function baml.csv.next(self: ?) -> T | root.iter.Done [expr] { - { while true { } match (self.reader.next()) { d: root.iter.Done => { return d }, rec: baml.csv.CsvRecord => { } match (_try_decode(rec, self.reader)) { s: baml.csv.CsvSkip => { match (self.reader._on_skip) { null => null, cb: (baml.csv.CsvError) -> null throws never => cb(s.error) } }, v: T => { return v } } } } root.sys.panic("unreachable: CsvR...") -} function baml.csv.next(self: ?) -> baml.csv.CsvRecord | root.iter.Done [expr] { { while true { } match (self._poll()) { rec: baml.csv.CsvRecord => { return rec }, d: root.iter.Done => { return d }, s: baml.csv.CsvSkip => { match (self._on_skip) { null => null, cb: (baml.csv.CsvError) -> null throws never => cb(s.error) } }, baml.csv.CsvNeedData => { self._read_chunk() } } } root.sys.panic("unreachable: CsvR...") } +function baml.csv.next(self: ?) -> T | root.iter.Done [expr] { + { while true { } match (self.reader.next()) { d: root.iter.Done => { return d }, rec: baml.csv.CsvRecord => { } match (_try_decode(rec, self.reader)) { s: baml.csv.CsvSkip => { match (self.reader._on_skip) { null => null, cb: (baml.csv.CsvError) -> null throws never => cb(s.error) } }, v: T => { return v } } } } root.sys.panic("unreachable: CsvR...") +} function baml.csv.open(path: string, options: baml.csv.ReaderOptions? = null) -> baml.csv.CsvReader [expr] { { let f = baml.fs.open(path, "r") catch (_) { root.errors.InvalidArgument { message: message } => throw root.errors.Io { message: message } } } _reader(f, options, true) } @@ -442,6 +532,11 @@ class baml.errors.ErrorContext { stack_trace: StackTrace cause: baml.errors.ErrorContext? } +class baml.errors.ErrorContext$stream { + error: unknown + stack_trace: StackTrace$stream | null + cause: baml.errors.ErrorContext$stream | null +} function baml.errors._to_string_impl(self: ?) -> string [builtin] function baml.errors.root_cause(self: ?) -> baml.errors.ErrorContext [expr] { { } match (self.cause) { null => self, c: baml.errors.ErrorContext => c.root_cause() } @@ -454,15 +549,27 @@ function baml.errors.to_string(self: ?) -> string [expr] { class baml.errors.AccessError { message: string } +class baml.errors.AccessError$stream { + message: string | null +} class baml.errors.CompilationError { message: string } +class baml.errors.CompilationError$stream { + message: string | null +} class baml.errors.DevOther { message: string } +class baml.errors.DevOther$stream { + message: string | null +} class baml.errors.GenericSdkError { message: string } +class baml.errors.GenericSdkError$stream { + message: string | null +} class baml.errors.HostCallable { message: string class_name: string @@ -470,34 +577,69 @@ class baml.errors.HostCallable { traceback: string? _handle: $rust_type } +class baml.errors.HostCallable$stream { + message: string | null + class_name: string | null + language: string | null + traceback: string | null + _handle: $rust_type +} class baml.errors.InvalidArgument { message: string } +class baml.errors.InvalidArgument$stream { + message: string | null +} class baml.errors.Io { message: string } +class baml.errors.Io$stream { + message: string | null +} class baml.errors.LlmClient { message: string } +class baml.errors.LlmClient$stream { + message: string | null +} class baml.errors.NotImplemented { message: string } +class baml.errors.NotImplemented$stream { + message: string | null +} class baml.errors.ParseError { message: string } +class baml.errors.ParseError$stream { + message: string | null +} class baml.errors.RenderPrompt { message: string } +class baml.errors.RenderPrompt$stream { + message: string | null +} class baml.errors.Timeout { message: string duration_ms: int? } +class baml.errors.Timeout$stream { + message: string | null + duration_ms: int | null +} class baml.errors.TypeMismatch { message: string } +class baml.errors.TypeMismatch$stream { + message: string | null +} class baml.errors.Unsupported { message: string } +class baml.errors.Unsupported$stream { + message: string | null +} --- /baml/ns_errors/stack_trace.baml --- class baml.errors.StackFrame { @@ -505,9 +647,17 @@ class baml.errors.StackFrame { line: int function_name: string } +class baml.errors.StackFrame$stream { + file: string | null + line: int | null + function_name: string | null +} class baml.errors.StackTrace { frames: baml.errors.StackFrame[] } +class baml.errors.StackTrace$stream { + frames: baml.errors.StackFrame$stream[] +} function baml.errors._to_string_impl(self: ?) -> string [builtin] function baml.errors.to_string(self: ?) -> string [expr] { { } self._to_string_impl() @@ -522,19 +672,31 @@ class baml.fs.DirEntry { is_file: bool is_symlink: bool } +class baml.fs.DirEntry$stream { + name: string | null + is_dir: bool | null + is_file: bool | null + is_symlink: bool | null +} class baml.fs.File { _handle: $rust_type } +class baml.fs.File$stream { + _handle: $rust_type +} class baml.fs.MkdirOptions { recursive: bool } +class baml.fs.MkdirOptions$stream { + recursive: bool | null +} function baml.fs.bytes(self: ?) -> uint8array [builtin] function baml.fs.close(self: ?) -> null [builtin] function baml.fs.exists(path: string) -> bool [builtin] function baml.fs.mkdir(path: string, options: baml.fs.MkdirOptions) -> null [builtin] function baml.fs.open(path: string, mode: "r" | "r+" | "w" | "w+" | "a" | "a+") -> baml.fs.File [builtin] -function baml.fs.read(path: string) -> string [builtin] function baml.fs.read(self: ?, n: int) -> string [builtin] +function baml.fs.read(path: string) -> string [builtin] function baml.fs.read_bytes(self: ?, n: int) -> uint8array [builtin] function baml.fs.read_dir(path: string) -> baml.fs.DirEntry[] [builtin] function baml.fs.remove(path: string) -> null [builtin] @@ -552,8 +714,13 @@ function baml.fs.write_bytes(path: string, content: uint8array) -> int [builtin class baml.future.AllFailed { errors: E[] } +class baml.future.AllFailed$stream { + errors: E[] +} class baml.future.Future { } +class baml.future.Future$stream { +} enum baml.future.FutureState {Pending, Ready, Error, Cancelled} function baml.future.__await_any(futures: baml.future.Future[]) -> int [builtin] function baml.future.all(futures: baml.future.Future[]) -> baml.future.Future [expr] { @@ -586,6 +753,9 @@ lambda () in any: captures [futures] class baml.glob.Glob { _handle: $rust_type } +class baml.glob.Glob$stream { + _handle: $rust_type +} class baml.glob.ScanOptions { cwd: string? dot: bool? @@ -594,6 +764,14 @@ class baml.glob.ScanOptions { throw_error_on_broken_symlink: bool? only_files: bool? } +class baml.glob.ScanOptions$stream { + cwd: string | null + dot: bool | null + absolute: bool | null + follow_symlinks: bool | null + throw_error_on_broken_symlink: bool | null + only_files: bool | null +} function baml.glob.matches(self: ?, path: string) -> bool [builtin] function baml.glob.new(pattern: string) -> baml.glob.Glob [builtin] function baml.glob.scan(self: ?, root: string | baml.glob.ScanOptions) -> string[] [builtin] @@ -601,6 +779,8 @@ function baml.glob.scan(self: ?, root: string | baml.glob.ScanOptions) -> string --- /baml/ns_host/host.baml --- class baml.host.HostValue { } +class baml.host.HostValue$stream { +} function baml.host.call_host_value(handle: baml.host.HostValue, args: unknown[]) -> T [builtin] --- /baml/ns_http/http.baml --- @@ -610,16 +790,32 @@ class baml.http.Request { headers: map body: string } +class baml.http.Request$stream { + method: string | null + url: string | null + headers: map + body: string | null +} class baml.http.Response { status_code: int headers: map url: string _body: $rust_type } +class baml.http.Response$stream { + status_code: int | null + headers: map + url: string | null + _body: $rust_type +} class baml.http.SseStream { url: string _handle: $rust_type } +class baml.http.SseStream$stream { + url: string | null + _handle: $rust_type +} function baml.http._fetch(url: string, timeout_nanos: bigint) -> baml.http.Response [builtin] function baml.http._send(request: baml.http.Request, timeout_nanos: bigint) -> baml.http.Response [builtin] function baml.http._timeout_nanos(timeout: root.time.Duration?) -> bigint [expr] { @@ -649,12 +845,22 @@ class baml.http.Server { addr: string _state: $rust_type } +class baml.http.Server$stream { + addr: string | null + _state: $rust_type +} class baml.http.TlsConfig { allow_tls1_2: bool _certificate: $rust_type _private_key: $rust_type _handshake_timeout_nanos: bigint } +class baml.http.TlsConfig$stream { + allow_tls1_2: bool | null + _certificate: $rust_type + _private_key: $rust_type + _handshake_timeout_nanos: bigint | null +} function baml.http._new(cert_pem: uint8array, key_pem: uint8array, allow_tls1_2: bool, handshake_timeout_nanos: bigint) -> baml.http.TlsConfig [builtin] function baml.http._serve(self: ?, handler: (req: Request) -> Response throws never, tls_config: baml.http.TlsConfig?, allow_http1: bool, allow_http2: bool, max_body_size: int, max_connections: int, header_read_timeout_nanos: bigint) -> never [builtin] function baml.http.bind(addr: string) -> baml.http.Server [builtin] @@ -682,53 +888,104 @@ class baml.iter.ArrayIterator { arr: T[] idx: int } +class baml.iter.ArrayIterator$stream { + arr: T[] + idx: int | null +} class baml.iter.Chain { first: Iterator other: Iterator first_done: bool } +class baml.iter.Chain$stream { + first: Iterator | null + other: Iterator | null + first_done: bool | null +} class baml.iter.Done { } +class baml.iter.Done$stream { +} class baml.iter.Filter { source: Iterator predicate: (T) -> bool throws E2 } +class baml.iter.Filter$stream { + source: Iterator | null + predicate: unknown +} class baml.iter.FilterMap { source: Iterator func: (T) -> R? throws E2 } +class baml.iter.FilterMap$stream { + source: Iterator | null + func: unknown +} class baml.iter.FlatMap { source: Iterator func: (T) -> Iterable throws E2 inner: Iterator | baml.iter.Done } +class baml.iter.FlatMap$stream { + source: Iterator | null + func: unknown + inner: Iterator | baml.iter.Done$stream | null +} class baml.iter.Flatten { source: Iterator inner: Iterator | baml.iter.Done } +class baml.iter.Flatten$stream { + source: Iterator | null + inner: Iterator | baml.iter.Done$stream | null +} class baml.iter.Map { source: Iterator func: (T) -> R throws E2 } +class baml.iter.Map$stream { + source: Iterator | null + func: unknown +} class baml.iter.Peekable { source: Iterator buffer: T | baml.iter.Done has_buffer: bool } +class baml.iter.Peekable$stream { + source: Iterator | null + buffer: T | baml.iter.Done$stream | null + has_buffer: bool | null +} class baml.iter.Range { i: int max: int step: int } +class baml.iter.Range$stream { + i: int | null + max: int | null + step: int | null +} class baml.iter.Repeat { value: T count: int } +class baml.iter.Repeat$stream { + value: T | null + count: int | null +} class baml.iter.StepBy { source: Iterator n: int first: bool } +class baml.iter.StepBy$stream { + source: Iterator | null + n: int | null + first: bool | null +} function baml.iter.chain(self: ?, other: Iterable) -> Iterator [expr] { { } baml.iter.Chain { first: self, other: other.iter(), first_done: false } } @@ -759,7 +1016,10 @@ function baml.iter.flatten(src: Iterator) -> Iterator void throws E2) -> void [expr] { { while true { } match (self.next()) { baml.iter.Done => { break }, x: Self.Item => { fn(x) } } } } -function baml.iter.iter(self: ?) -> Iterator [expr] { +function baml.iter.iter(self: ?) -> Iterator [expr] { + { } self +} +function baml.iter.iter(self: ?) -> Iterator [expr] { { } self } function baml.iter.iter(self: ?) -> Iterator [expr] { @@ -768,80 +1028,77 @@ function baml.iter.iter(self: ?) -> Iterator [expr] { function baml.iter.iter(self: ?) -> Iterator [expr] { { } self } -function baml.iter.iter(self: ?) -> Iterator [expr] { +function baml.iter.iter(self: ?) -> Iterator [expr] { { } self } -function baml.iter.iter(self: ?) -> Iterator [expr] { +function baml.iter.iter(self: ?) -> Iterator [expr] { { } self } -function baml.iter.iter(self: ?) -> Iterator [expr] { - { } self.chars().iter() -} -function baml.iter.iter(self: ?) -> Iterator [expr] { +function baml.iter.iter(self: ?) -> Iterator [expr] { { } self } -function baml.iter.iter(self: ?) -> Iterator [expr] { +function baml.iter.iter(self: ?) -> Iterator [expr] { { } self } function baml.iter.iter(self: ?) -> Iterator [expr] { { } self } -function baml.iter.iter(self: ?) -> Iterator [expr] { - { } ArrayIterator.new(self) -} -function baml.iter.iter(self: ?) -> Iterator [expr] { +function baml.iter.iter(self: ?) -> Iterator [expr] { { } self } function baml.iter.iter(self: ?) -> Iterator [expr] { { } self } -function baml.iter.iter(self: ?) -> Iterator [expr] { - { } self +function baml.iter.iter(self: ?) -> Iterator [expr] { + { } ArrayIterator.new(self) +} +function baml.iter.iter(self: ?) -> Iterator [expr] { + { } self.chars().iter() } function baml.iter.map(self: ?, fn: (Self.Item) -> R throws E2) -> Iterator [expr] { { } baml.iter.Map { source: self, func: fn } } -function baml.iter.new(min: int, max: int, step: int = 1) -> baml.iter.Range [expr] { - { } baml.iter.Range { i: min, max: max, step: step } -} function baml.iter.new(arr: T[]) -> baml.iter.ArrayIterator [expr] { { } baml.iter.ArrayIterator { arr: arr, idx: 0 } } +function baml.iter.new(min: int, max: int, step: int = 1) -> baml.iter.Range [expr] { + { } baml.iter.Range { i: min, max: max, step: step } +} function baml.iter.new(value: T, count: int = ...) -> baml.iter.Repeat [expr] { { } baml.iter.Repeat { value: value, count: count } } +function baml.iter.next(self: ?) -> T | baml.iter.Done [expr] { + { if (self.idx Ge self.arr.length()) { return baml.iter.Done { } }; let item = self.arr.at(self.idx); self.idx Add= 1 } match (item) { value: T => value } +} function baml.iter.next(self: ?) -> int | baml.iter.Done [expr] { { } if (self.i Lt self.max) { let cur = self.i; self.i Add= self.step } cur else { } baml.iter.Done { } } function baml.iter.next(self: ?) -> T | baml.iter.Done [expr] { - { while true { } match (self.source.next()) { baml.iter.Done => { return baml.iter.Done { } }, x: T => { } if (self.predicate(x)) { return x } } } baml.iter.Done { } + { } if (self.count Lt 0) { } self.value else if (self.count Gt 0) { self.count Sub= 1 } self.value else { } baml.iter.Done { } } function baml.iter.next(self: ?) -> R | baml.iter.Done [expr] { - { while true { } match (self.inner) { cur: Iterator => { } match (cur.next()) { baml.iter.Done => { self.inner = baml.iter.Done { } }, y: R => { return y } }, baml.iter.Done => { } match (self.source.next()) { baml.iter.Done => { return baml.iter.Done { } }, x: I => { let it = x.iter(); self.inner = it } } } } baml.iter.Done { } -} -function baml.iter.next(self: ?) -> T | baml.iter.Done [expr] { - { if (Not self.first_done) { } match (self.first.next()) { baml.iter.Done => { self.first_done = true }, x: T => { return x } } } self.other.next() + { } match (self.source.next()) { baml.iter.Done => baml.iter.Done { }, x: T => self.func(x) } } function baml.iter.next(self: ?) -> T | baml.iter.Done [expr] { - { if (self.idx Ge self.arr.length()) { return baml.iter.Done { } }; let item = self.arr.at(self.idx); self.idx Add= 1 } match (item) { value: T => value } + { while true { } match (self.source.next()) { baml.iter.Done => { return baml.iter.Done { } }, x: T => { } if (self.predicate(x)) { return x } } } baml.iter.Done { } } function baml.iter.next(self: ?) -> R | baml.iter.Done [expr] { - { } match (self.source.next()) { baml.iter.Done => baml.iter.Done { }, x: T => self.func(x) } + { while true { } match (self.source.next()) { baml.iter.Done => { return baml.iter.Done { } }, x: T => { } match (self.func(x)) { null => { }, y: R => { return y } } } } baml.iter.Done { } } function baml.iter.next(self: ?) -> R | baml.iter.Done [expr] { { while true { } match (self.inner) { cur: Iterator => { } match (cur.next()) { baml.iter.Done => { self.inner = baml.iter.Done { } }, y: R => { return y } }, baml.iter.Done => { } match (self.source.next()) { baml.iter.Done => { return baml.iter.Done { } }, x: T => { let it = self.func(x).iter(); self.inner = it } } } } baml.iter.Done { } } -function baml.iter.next(self: ?) -> T | baml.iter.Done [expr] { - { if (self.first) { self.first = false; return self.source.next() }; { let i = 0; while i Lt self.n Sub 1 { } match (self.source.next()) { baml.iter.Done => { return baml.iter.Done { } }, x: T => { } } } } self.source.next() +function baml.iter.next(self: ?) -> R | baml.iter.Done [expr] { + { while true { } match (self.inner) { cur: Iterator => { } match (cur.next()) { baml.iter.Done => { self.inner = baml.iter.Done { } }, y: R => { return y } }, baml.iter.Done => { } match (self.source.next()) { baml.iter.Done => { return baml.iter.Done { } }, x: I => { let it = x.iter(); self.inner = it } } } } baml.iter.Done { } } function baml.iter.next(self: ?) -> T | baml.iter.Done [expr] { - { } if (self.count Lt 0) { } self.value else if (self.count Gt 0) { self.count Sub= 1 } self.value else { } baml.iter.Done { } + { if (self.has_buffer) { let v = self.buffer; self.buffer = baml.iter.Done { }; self.has_buffer = false; return v } } self.source.next() } -function baml.iter.next(self: ?) -> R | baml.iter.Done [expr] { - { while true { } match (self.source.next()) { baml.iter.Done => { return baml.iter.Done { } }, x: T => { } match (self.func(x)) { null => { }, y: R => { return y } } } } baml.iter.Done { } +function baml.iter.next(self: ?) -> T | baml.iter.Done [expr] { + { if (self.first) { self.first = false; return self.source.next() }; { let i = 0; while i Lt self.n Sub 1 { } match (self.source.next()) { baml.iter.Done => { return baml.iter.Done { } }, x: T => { } } } } self.source.next() } function baml.iter.next(self: ?) -> T | baml.iter.Done [expr] { - { if (self.has_buffer) { let v = self.buffer; self.buffer = baml.iter.Done { }; self.has_buffer = false; return v } } self.source.next() + { if (Not self.first_done) { } match (self.first.next()) { baml.iter.Done => { self.first_done = true }, x: T => { return x } } } self.other.next() } function baml.iter.peek(self: ?) -> T | baml.iter.Done [expr] { { if (self.has_buffer) { return self.buffer }; let v = self.source.next(); self.buffer = v; self.has_buffer = true } v @@ -864,15 +1121,28 @@ class baml.json.JsonDecodeError { message: string path: string } +class baml.json.JsonDecodeError$stream { + message: string | null + path: string | null +} class baml.json.JsonParseError { message: string } +class baml.json.JsonParseError$stream { + message: string | null +} class baml.json.JsonSerializationError { message: string path: string reason: string } +class baml.json.JsonSerializationError$stream { + message: string | null + path: string | null + reason: string | null +} type baml.json.json = null | bool | int | float | string | baml.json.json[] | map +type baml.json.json$stream = null | bool | int | float | string | baml.json.json$stream[] | map function baml.json.deserialize(s: string) -> T [expr] { { } from_json(parse(s)) } @@ -901,13 +1171,26 @@ class baml.llm.ExecutionContext { function_name: string prompt_closure: (Context) -> PromptAst throws never? } +class baml.llm.ExecutionContext$stream { + jinja_string: string | null + args: map + function_name: string | null + prompt_closure: unknown | null +} class baml.llm.OrchestrationStep { primitive_client: PrimitiveClient delay_ms: int } +class baml.llm.OrchestrationStep$stream { + primitive_client: PrimitiveClient$stream | null + delay_ms: int | null +} class baml.llm.PlannerState { rr_client_names: string[] } +class baml.llm.PlannerState$stream { + rr_client_names: string[] +} function baml.llm.build_request(client: Client, function_name: string, args: map, prompt_closure: (Context) -> PromptAst throws never? = null) -> root.http.Request [expr] { { let return_type = get_return_type(function_name); let primitive_client = client.to_primitive_client(); let template = prompt_template_for(function_name, prompt_closure); let specialized_prompt = primitive_client.render_specialized_prompt(template, args, return_type, prompt_closure) } primitive_client.build_request(specialized_prompt, return_type) } @@ -940,12 +1223,21 @@ function baml.llm.stream_llm_function(client: Client, function_name: string, arg class baml.llm.AnthropicOptions { max_tokens: int | null } +class baml.llm.AnthropicOptions$stream { + max_tokens: int | null +} class baml.llm.AzureOpenAiOptions { resource_name: string | null deployment_id: string | null api_version: string max_tokens: int | null } +class baml.llm.AzureOpenAiOptions$stream { + resource_name: string | null + deployment_id: string | null + api_version: string | null + max_tokens: int | null +} class baml.llm.BedrockOptions { region: string | null endpoint_url: string | null @@ -958,6 +1250,18 @@ class baml.llm.BedrockOptions { temperature: float | null top_p: float | null } +class baml.llm.BedrockOptions$stream { + region: string | null + endpoint_url: string | null + access_key_id: string | null + secret_access_key: string | null + session_token: string | null + profile: string | null + stop_sequences: string[] | null + max_tokens: int | null + temperature: float | null + top_p: float | null +} class baml.llm.Client { name: string client_type: baml.llm.ClientType @@ -965,18 +1269,37 @@ class baml.llm.Client { retry: baml.llm.RetryPolicy? counter: int } +class baml.llm.Client$stream { + name: string | null + client_type: baml.llm.ClientType | null + sub_clients: baml.llm.Client$stream[] + retry: baml.llm.RetryPolicy$stream | null + counter: int | null +} class baml.llm.Context { client: baml.llm.ContextClient tags: map output_format: string _output_format: baml.llm.OutputFormat } +class baml.llm.Context$stream { + client: baml.llm.ContextClient$stream | null + tags: map + output_format: string | null + _output_format: baml.llm.OutputFormat$stream | null +} class baml.llm.ContextClient { name: string provider: string default_role: string allowed_roles: string[] } +class baml.llm.ContextClient$stream { + name: string | null + provider: string | null + default_role: string | null + allowed_roles: string[] +} class baml.llm.GoogleAiOptions { enterprise: bool | null credentials: string | null @@ -984,20 +1307,41 @@ class baml.llm.GoogleAiOptions { location: string | null project_id: string | null } +class baml.llm.GoogleAiOptions$stream { + enterprise: bool | null + credentials: string | null + credentials_content: string | null + location: string | null + project_id: string | null +} class baml.llm.MediaUrlHandler { image: string | null audio: string | null video: string | null pdf: string | null } +class baml.llm.MediaUrlHandler$stream { + image: string | null + audio: string | null + video: string | null + pdf: string | null +} class baml.llm.OutputFormat { _data: $rust_type } +class baml.llm.OutputFormat$stream { + _data: $rust_type +} class baml.llm.PrimitiveClient { name: string provider: string options: baml.llm.PrimitiveClientOptions } +class baml.llm.PrimitiveClient$stream { + name: string | null + provider: string | null + options: baml.llm.PrimitiveClientOptions$stream | null +} class baml.llm.PrimitiveClientOptions { model: string | null base_url: string | null @@ -1015,41 +1359,93 @@ class baml.llm.PrimitiveClientOptions { query_params: map request_body: map } +class baml.llm.PrimitiveClientOptions$stream { + model: string | null + base_url: string | null + allowed_role_metadata: unknown | null + finish_reason_allow_list: string[] | null + finish_reason_deny_list: string[] | null + supports_streaming: bool | null + default_role: string | null + allowed_roles: string[] | null + remap_roles: map | null + api_key: string | null + provider_options: baml.llm.AnthropicOptions$stream | baml.llm.AzureOpenAiOptions$stream | baml.llm.BedrockOptions$stream | baml.llm.GoogleAiOptions$stream | baml.llm.VertexAiOptions$stream | null + media_url_handler: baml.llm.MediaUrlHandler$stream | null + headers: map + query_params: map + request_body: map +} class baml.llm.PromptAst { _data: $rust_type } +class baml.llm.PromptAst$stream { + _data: $rust_type +} class baml.llm.PromptMessage { role: string content: string } +class baml.llm.PromptMessage$stream { + role: string | null + content: string | null +} class baml.llm.RetryPolicy { max_retries: int initial_delay_ms: int? multiplier: float? max_delay_ms: int? } +class baml.llm.RetryPolicy$stream { + max_retries: int | null + initial_delay_ms: int | null + multiplier: float | null + max_delay_ms: int | null +} class baml.llm.Role { name: string metadata: map } +class baml.llm.Role$stream { + name: string | null + metadata: map +} class baml.llm.Stream { _client: baml.llm.PrimitiveClient _acc: baml.llm.StreamAccumulator _sse: root.http.SseStream _cache: baml.llm.StreamCache } +class baml.llm.Stream$stream { + _client: baml.llm.PrimitiveClient$stream | null + _acc: baml.llm.StreamAccumulator$stream | null + _sse: root.http.SseStream$stream | null + _cache: baml.llm.StreamCache$stream | null +} class baml.llm.StreamAccumulator { _handle: $rust_type } +class baml.llm.StreamAccumulator$stream { + _handle: $rust_type +} class baml.llm.StreamCache { _data: $rust_type } +class baml.llm.StreamCache$stream { + _data: $rust_type +} class baml.llm.VertexAiOptions { credentials: string | null credentials_content: string | null location: string | null project_id: string | null } +class baml.llm.VertexAiOptions$stream { + credentials: string | null + credentials_content: string | null + location: string | null + project_id: string | null +} enum baml.llm.ClientType {Primitive, Fallback, RoundRobin} function baml.llm.__make_stream(self: ?, sse: root.http.SseStream) -> baml.llm.Stream [expr] { { let primitive = self.to_primitive_client(); let acc = primitive.new_stream_accumulator(); let cache: baml.llm.StreamCache = StreamCache.new(reflect.type_of(), reflect.type_of()) } baml.llm.Stream { _client: primitive, _acc: acc, _sse: sse, _cache: cache } @@ -1149,15 +1545,27 @@ lambda (ctx) in prompt: captures [body] class baml.media.Audio { _data: $rust_type } +class baml.media.Audio$stream { + _data: $rust_type +} class baml.media.Image { _data: $rust_type } +class baml.media.Image$stream { + _data: $rust_type +} class baml.media.Pdf { _data: $rust_type } +class baml.media.Pdf$stream { + _data: $rust_type +} class baml.media.Video { _data: $rust_type } +class baml.media.Video$stream { + _data: $rust_type +} function baml.media.base64(self: ?) -> string [builtin] function baml.media.base64(self: ?) -> string [builtin] function baml.media.base64(self: ?) -> string [builtin] @@ -1166,18 +1574,18 @@ function baml.media.file(self: ?) -> string? [builtin] function baml.media.file(self: ?) -> string? [builtin] function baml.media.file(self: ?) -> string? [builtin] function baml.media.file(self: ?) -> string? [builtin] -function baml.media.from_base64(base64: string, mime_type: string?) -> video [builtin] function baml.media.from_base64(base64: string, mime_type: string?) -> pdf [builtin] -function baml.media.from_base64(base64: string, mime_type: string?) -> image [builtin] function baml.media.from_base64(base64: string, mime_type: string?) -> audio [builtin] -function baml.media.from_file(file: string, mime_type: string?) -> video [builtin] +function baml.media.from_base64(base64: string, mime_type: string?) -> video [builtin] +function baml.media.from_base64(base64: string, mime_type: string?) -> image [builtin] function baml.media.from_file(file: string, mime_type: string?) -> pdf [builtin] -function baml.media.from_file(file: string, mime_type: string?) -> image [builtin] function baml.media.from_file(file: string, mime_type: string?) -> audio [builtin] -function baml.media.from_url(url: string, mime_type: string?) -> video [builtin] +function baml.media.from_file(file: string, mime_type: string?) -> video [builtin] +function baml.media.from_file(file: string, mime_type: string?) -> image [builtin] function baml.media.from_url(url: string, mime_type: string?) -> pdf [builtin] -function baml.media.from_url(url: string, mime_type: string?) -> image [builtin] function baml.media.from_url(url: string, mime_type: string?) -> audio [builtin] +function baml.media.from_url(url: string, mime_type: string?) -> video [builtin] +function baml.media.from_url(url: string, mime_type: string?) -> image [builtin] function baml.media.mime_type(self: ?) -> string? [builtin] function baml.media.mime_type(self: ?) -> string? [builtin] function baml.media.mime_type(self: ?) -> string? [builtin] @@ -1192,15 +1600,28 @@ class baml.net.Datagram { data: uint8array addr: string } +class baml.net.Datagram$stream { + data: uint8array + addr: string | null +} class baml.net.TcpListener { _handle: $rust_type } +class baml.net.TcpListener$stream { + _handle: $rust_type +} class baml.net.TcpStream { _handle: $rust_type } +class baml.net.TcpStream$stream { + _handle: $rust_type +} class baml.net.UdpSocket { _handle: $rust_type } +class baml.net.UdpSocket$stream { + _handle: $rust_type +} function baml.net._connect(addr: string, timeout_nanos: bigint) -> baml.net.TcpStream [builtin] function baml.net._read(self: ?, timeout_nanos: bigint) -> uint8array [builtin] function baml.net._recv_from(self: ?, timeout_nanos: bigint) -> baml.net.Datagram [builtin] @@ -1233,46 +1654,46 @@ function baml.net.write(self: ?, data: uint8array, timeout: root.time.Duration? --- /baml/ns_ops/comparison.baml --- function baml.ops.eq(self: ?, other: Self) -> bool [builtin] +function baml.ops.eq(self: ?, other: Self) -> bool [builtin] +function baml.ops.eq(self: ?, other: Self) -> bool [builtin] +function baml.ops.eq(self: ?, other: Self) -> bool [builtin] function baml.ops.eq(self: ?, other: Self) -> bool [expr] { { } true } +function baml.ops.eq(self: ?, other: Self) -> bool [builtin] +function baml.ops.eq(self: ?, other: Self) -> bool [builtin] function baml.ops.eq(self: ?, other: Self) -> bool [expr] { { } baml.ops.equals_equals(self, other) } -function baml.ops.eq(self: ?, other: Self) -> bool [builtin] -function baml.ops.eq(self: ?, other: Self) -> bool [builtin] function baml.ops.eq(self: ?, other: Self) -> bool [expr] { { } baml.ops.equals_equals(self, other) } -function baml.ops.eq(self: ?, other: Self) -> bool [builtin] -function baml.ops.eq(self: ?, other: Self) -> bool [builtin] -function baml.ops.eq(self: ?, other: Self) -> bool [builtin] function baml.ops.equals_equals(a: unknown, b: unknown) -> bool [builtin] function baml.ops.ge(self: ?, other: Self) -> bool [expr] { { } Not self.lt(other) } function baml.ops.ge(self: ?, other: Self) -> bool [builtin] function baml.ops.ge(self: ?, other: Self) -> bool [builtin] -function baml.ops.gt(self: ?, other: Self) -> bool [builtin] function baml.ops.gt(self: ?, other: Self) -> bool [expr] { - { } self And Not other + { } Not self.le(other) } +function baml.ops.gt(self: ?, other: Self) -> bool [builtin] function baml.ops.gt(self: ?, other: Self) -> bool [expr] { - { } Not self.le(other) + { } self And Not other } function baml.ops.gt(self: ?, other: Self) -> bool [builtin] -function baml.ops.le(self: ?, other: Self) -> bool [builtin] -function baml.ops.le(self: ?, other: Self) -> bool [builtin] function baml.ops.le(self: ?, other: Self) -> bool [expr] { { } self.lt(other) Or self.eq(other) } +function baml.ops.le(self: ?, other: Self) -> bool [builtin] +function baml.ops.le(self: ?, other: Self) -> bool [builtin] +function baml.ops.lt(self: ?, other: Self) -> bool [builtin] +function baml.ops.lt(self: ?, other: Self) -> bool [builtin] function baml.ops.lt(self: ?, other: Self) -> bool [builtin] function baml.ops.lt(self: ?, other: Self) -> bool [expr] { { } Not self And other } function baml.ops.lt(self: ?, other: Self) -> bool [builtin] -function baml.ops.lt(self: ?, other: Self) -> bool [builtin] -function baml.ops.lt(self: ?, other: Self) -> bool [builtin] function baml.ops.neq(self: ?, other: Self) -> bool [expr] { { } Not self.eq(other) } @@ -1287,135 +1708,200 @@ function baml.ops.__union_mul(a: unknown, b: unknown) -> unknown [builtin] function baml.ops.__union_neg(a: unknown) -> unknown [builtin] function baml.ops.__union_rem(a: unknown, b: unknown) -> unknown [builtin] function baml.ops.__union_sub(a: unknown, b: unknown) -> unknown [builtin] -function baml.ops.add(self: ?, rhs: float) -> float [builtin] -function baml.ops.add(self: ?, rhs: bigint) -> bigint [builtin] function baml.ops.add(self: ?, rhs: int) -> int [builtin] function baml.ops.add(self: ?, rhs: float) -> float [builtin] -function baml.ops.add(self: ?, rhs: bigint) -> bigint [builtin] function baml.ops.add(self: ?, rhs: int) -> float [builtin] +function baml.ops.add(self: ?, rhs: float) -> float [builtin] +function baml.ops.add(self: ?, rhs: bigint) -> bigint [builtin] function baml.ops.add(self: ?, rhs: int) -> bigint [builtin] +function baml.ops.add(self: ?, rhs: bigint) -> bigint [builtin] function baml.ops.div(self: ?, rhs: int) -> int [builtin] function baml.ops.div(self: ?, rhs: float) -> float [builtin] -function baml.ops.div(self: ?, rhs: bigint) -> bigint [builtin] function baml.ops.div(self: ?, rhs: int) -> float [builtin] -function baml.ops.div(self: ?, rhs: int) -> bigint [builtin] function baml.ops.div(self: ?, rhs: float) -> float [builtin] function baml.ops.div(self: ?, rhs: bigint) -> bigint [builtin] -function baml.ops.mul(self: ?, rhs: bigint) -> bigint [builtin] +function baml.ops.div(self: ?, rhs: int) -> bigint [builtin] +function baml.ops.div(self: ?, rhs: bigint) -> bigint [builtin] +function baml.ops.mul(self: ?, rhs: int) -> int [builtin] +function baml.ops.mul(self: ?, rhs: float) -> float [builtin] function baml.ops.mul(self: ?, rhs: int) -> float [builtin] -function baml.ops.mul(self: ?, rhs: int) -> bigint [builtin] function baml.ops.mul(self: ?, rhs: float) -> float [builtin] function baml.ops.mul(self: ?, rhs: bigint) -> bigint [builtin] -function baml.ops.mul(self: ?, rhs: int) -> int [builtin] -function baml.ops.mul(self: ?, rhs: float) -> float [builtin] -function baml.ops.neg(self: ?) -> bigint [builtin] -function baml.ops.neg(self: ?) -> float [builtin] +function baml.ops.mul(self: ?, rhs: int) -> bigint [builtin] +function baml.ops.mul(self: ?, rhs: bigint) -> bigint [builtin] function baml.ops.neg(self: ?) -> int [builtin] +function baml.ops.neg(self: ?) -> float [builtin] +function baml.ops.neg(self: ?) -> bigint [builtin] +function baml.ops.rem(self: ?, rhs: int) -> int [builtin] +function baml.ops.rem(self: ?, rhs: float) -> float [builtin] function baml.ops.rem(self: ?, rhs: int) -> float [builtin] -function baml.ops.rem(self: ?, rhs: int) -> bigint [builtin] function baml.ops.rem(self: ?, rhs: float) -> float [builtin] function baml.ops.rem(self: ?, rhs: bigint) -> bigint [builtin] -function baml.ops.rem(self: ?, rhs: int) -> int [builtin] -function baml.ops.rem(self: ?, rhs: float) -> float [builtin] +function baml.ops.rem(self: ?, rhs: int) -> bigint [builtin] function baml.ops.rem(self: ?, rhs: bigint) -> bigint [builtin] +function baml.ops.sub(self: ?, rhs: int) -> int [builtin] +function baml.ops.sub(self: ?, rhs: float) -> float [builtin] function baml.ops.sub(self: ?, rhs: int) -> float [builtin] -function baml.ops.sub(self: ?, rhs: int) -> bigint [builtin] function baml.ops.sub(self: ?, rhs: float) -> float [builtin] function baml.ops.sub(self: ?, rhs: bigint) -> bigint [builtin] -function baml.ops.sub(self: ?, rhs: int) -> int [builtin] -function baml.ops.sub(self: ?, rhs: float) -> float [builtin] +function baml.ops.sub(self: ?, rhs: int) -> bigint [builtin] function baml.ops.sub(self: ?, rhs: bigint) -> bigint [builtin] --- /baml/ns_panics/panics.baml --- class baml.panics.AllocFailure { message: string } +class baml.panics.AllocFailure$stream { + message: string | null +} class baml.panics.AssertionFailed { message: string } +class baml.panics.AssertionFailed$stream { + message: string | null +} class baml.panics.Cancelled { message: string } +class baml.panics.Cancelled$stream { + message: string | null +} class baml.panics.DivisionByZero { dividend: int } +class baml.panics.DivisionByZero$stream { + dividend: int | null +} class baml.panics.Exit { code: int } +class baml.panics.Exit$stream { + code: int | null +} class baml.panics.HostContractViolation { message: string class_name: string? language: string? } +class baml.panics.HostContractViolation$stream { + message: string | null + class_name: string | null + language: string | null +} class baml.panics.HostUnavailable { resource: string message: string } +class baml.panics.HostUnavailable$stream { + resource: string | null + message: string | null +} class baml.panics.IndexOutOfBounds { index: int length: int } +class baml.panics.IndexOutOfBounds$stream { + index: int | null + length: int | null +} class baml.panics.IntegerOverflow { message: string } +class baml.panics.IntegerOverflow$stream { + message: string | null +} class baml.panics.InvalidFieldAccess { field_index: int field_count: int } +class baml.panics.InvalidFieldAccess$stream { + field_index: int | null + field_count: int | null +} class baml.panics.MapKeyNotFound { key: string } +class baml.panics.MapKeyNotFound$stream { + key: string | null +} class baml.panics.NegativeBitShift { message: string } +class baml.panics.NegativeBitShift$stream { + message: string | null +} class baml.panics.SdkPanic { message: string } +class baml.panics.SdkPanic$stream { + message: string | null +} class baml.panics.StackOverflow { message: string } +class baml.panics.StackOverflow$stream { + message: string | null +} class baml.panics.Unreachable { message: string } +class baml.panics.Unreachable$stream { + message: string | null +} class baml.panics.UserPanic { message: string } +class baml.panics.UserPanic$stream { + message: string | null +} type baml.panics.Panic = baml.panics.DivisionByZero | baml.panics.IndexOutOfBounds | baml.panics.InvalidFieldAccess | baml.panics.MapKeyNotFound | baml.panics.StackOverflow | baml.panics.AssertionFailed | baml.panics.Unreachable | baml.panics.Cancelled | baml.panics.UserPanic | baml.panics.Exit | baml.panics.AllocFailure | baml.panics.HostUnavailable | baml.panics.NegativeBitShift | baml.panics.SdkPanic | baml.panics.HostContractViolation | baml.panics.IntegerOverflow +type baml.panics.Panic$stream = baml.panics.DivisionByZero$stream | baml.panics.IndexOutOfBounds$stream | baml.panics.InvalidFieldAccess$stream | baml.panics.MapKeyNotFound$stream | baml.panics.StackOverflow$stream | baml.panics.AssertionFailed$stream | baml.panics.Unreachable$stream | baml.panics.Cancelled$stream | baml.panics.UserPanic$stream | baml.panics.Exit$stream | baml.panics.AllocFailure$stream | baml.panics.HostUnavailable$stream | baml.panics.NegativeBitShift$stream | baml.panics.SdkPanic$stream | baml.panics.HostContractViolation$stream | baml.panics.IntegerOverflow$stream --- /baml/ns_random/random.baml --- class baml.random.ChaCha20 { _state: $rust_type } +class baml.random.ChaCha20$stream { + _state: $rust_type +} class baml.random.SystemRandom { } +class baml.random.SystemRandom$stream { +} class baml.random.Xoshiro256PlusPlus { _state: $rust_type } -function baml.random._new(seed: uint8array) -> baml.random.ChaCha20 [builtin] +class baml.random.Xoshiro256PlusPlus$stream { + _state: $rust_type +} function baml.random._new(seed: uint8array) -> baml.random.Xoshiro256PlusPlus [builtin] +function baml.random._new(seed: uint8array) -> baml.random.ChaCha20 [builtin] function baml.random.get() -> baml.random.SystemRandom [expr] { { } baml.random.SystemRandom { } } -function baml.random.new(seed: uint8array = SystemRandom.get().random(32)) -> baml.random.ChaCha20 [expr] { - { } ChaCha20._new(seed) -} function baml.random.new(seed: uint8array = SystemRandom.get().random(32)) -> baml.random.Xoshiro256PlusPlus [expr] { { } Xoshiro256PlusPlus._new(seed) } +function baml.random.new(seed: uint8array = SystemRandom.get().random(32)) -> baml.random.ChaCha20 [expr] { + { } ChaCha20._new(seed) +} function baml.random.random(self: ?, bytes: int) -> uint8array [builtin] function baml.random.random(self: ?, bytes: int) -> uint8array [builtin] function baml.random.random(self: ?, bytes: int) -> uint8array [builtin] -function baml.random.random_int(self: ?) -> int [builtin] function baml.random.random_int(self: ?) -> int [expr] { { let bytes = self.random(8); let magnitude = bytes[0] BitAnd 63 Shl 56 BitOr bytes[1] Shl 48 BitOr bytes[2] Shl 40 BitOr bytes[3] Shl 32 BitOr bytes[4] Shl 24 BitOr bytes[5] Shl 16 BitOr bytes[6] Shl 8 BitOr bytes[7] } if (bytes[0] BitAnd 64 Eq 0) { } magnitude else { } 0 Sub magnitude Sub 1 } function baml.random.random_int(self: ?) -> int [builtin] function baml.random.random_int(self: ?) -> int [builtin] +function baml.random.random_int(self: ?) -> int [builtin] --- /baml/ns_spawn/spawn.baml --- class baml.spawn.CancelToken { _handle: $rust_type } +class baml.spawn.CancelToken$stream { + _handle: $rust_type +} class baml.spawn.SpawnParams { body: () -> T throws E name: string? @@ -1423,18 +1909,28 @@ class baml.spawn.SpawnParams { cancel: baml.spawn.CancelToken? detach: bool } +class baml.spawn.SpawnParams$stream { + body: unknown + name: string | null + group: baml.spawn.TaskGroup$stream | null + cancel: baml.spawn.CancelToken$stream | null + detach: bool | null +} class baml.spawn.TaskGroup { _handle: $rust_type } +class baml.spawn.TaskGroup$stream { + _handle: $rust_type +} function baml.spawn.active_count(self: ?) -> int [builtin] function baml.spawn.any(tokens: baml.spawn.CancelToken[]) -> baml.spawn.CancelToken [builtin] -function baml.spawn.cancel(self: ?) -> int [builtin] function baml.spawn.cancel(self: ?, pending: bool? = true, active: bool? = true) -> int [builtin] +function baml.spawn.cancel(self: ?) -> int [builtin] function baml.spawn.is_cancelled(self: ?) -> bool [builtin] function baml.spawn.limit(self: ?) -> int [builtin] function baml.spawn.name(self: ?) -> string? [builtin] -function baml.spawn.new() -> baml.spawn.CancelToken [builtin] function baml.spawn.new(limit: int, name: string? = null) -> baml.spawn.TaskGroup [builtin] +function baml.spawn.new() -> baml.spawn.CancelToken [builtin] function baml.spawn.options(group: baml.spawn.TaskGroup? = null, cancel: baml.spawn.CancelToken? = null, detach: bool? = null) -> (baml.spawn.SpawnParams) -> baml.spawn.SpawnParams throws never [expr] { { } (params: SpawnParams) -> SpawnParams { { } baml.spawn.SpawnParams { body: params.body, name: params.name, group: group NullCoalesce params.group, cancel: cancel NullCoalesce params.cancel, detach: detach NullCoalesce params.detach } } } @@ -1447,8 +1943,12 @@ lambda (params) in options: captures [group, cancel, detach] --- /baml/ns_stream/stream.baml --- class baml.stream.StreamFinished { } +class baml.stream.StreamFinished$stream { +} class baml.stream.StreamNoYield { } +class baml.stream.StreamNoYield$stream { +} --- /baml/ns_sys/sys.baml --- class baml.sys.ProcessOptions { @@ -1457,11 +1957,22 @@ class baml.sys.ProcessOptions { timeout_ms: int? stdin: string? } +class baml.sys.ProcessOptions$stream { + cwd: string | null + env: map | null + timeout_ms: int | null + stdin: string | null +} class baml.sys.ShellOutput { stdout: uint8array stderr: uint8array exit_code: int } +class baml.sys.ShellOutput$stream { + stdout: uint8array + stderr: uint8array + exit_code: int | null +} function baml.sys.argv() -> string[] [builtin] function baml.sys.exec(program: string, args: string[]?, options: baml.sys.ProcessOptions?) -> baml.sys.ShellOutput [builtin] function baml.sys.exit(code: int) -> never [builtin] @@ -1477,6 +1988,9 @@ function baml.sys.sleep(delay: root.time.Duration) -> null [builtin] class baml.time.Duration { _nanoseconds: bigint } +class baml.time.Duration$stream { + _nanoseconds: bigint | null +} function baml.time.abs(self: ?) -> baml.time.Duration [expr] { { } baml.time.Duration { _nanoseconds: self._nanoseconds.abs() } } @@ -1521,6 +2035,9 @@ function baml.time.to_seconds(self: ?) -> bigint [expr] { class baml.time.Instant { _nanoseconds: bigint } +class baml.time.Instant$stream { + _nanoseconds: bigint | null +} function baml.time._to_string_impl(self: ?) -> string [builtin] function baml.time.abs_diff(self: ?, other: baml.time.Instant) -> Duration [expr] { { } Duration { _nanoseconds: self._nanoseconds Sub other._nanoseconds.abs() } @@ -1577,6 +2094,9 @@ function baml.time.to_timestamp_seconds(self: ?) -> bigint [expr] { class baml.time.PlainDate { _days: int } +class baml.time.PlainDate$stream { + _days: int | null +} function baml.time._to_plain_datetime(self: ?, time: PlainTime?) -> PlainDateTime [builtin] function baml.time._to_string_impl(self: ?) -> string [builtin] function baml.time.day(self: ?) -> int [builtin] @@ -1601,6 +2121,9 @@ function baml.time.year(self: ?) -> int [builtin] class baml.time.PlainDateTime { _nanoseconds: bigint } +class baml.time.PlainDateTime$stream { + _nanoseconds: bigint | null +} function baml.time._from_components(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int, microsecond: int, nanosecond: int) -> baml.time.PlainDateTime [builtin] function baml.time._to_string_impl(self: ?) -> string [builtin] function baml.time.day(self: ?) -> int [builtin] @@ -1639,6 +2162,9 @@ function baml.time.year(self: ?) -> int [builtin] class baml.time.PlainTime { _nanoseconds: int } +class baml.time.PlainTime$stream { + _nanoseconds: int | null +} function baml.time._from_components(hour: int, minute: int, second: int, millisecond: int, microsecond: int, nanosecond: int) -> baml.time.PlainTime [builtin] function baml.time._to_string_impl(self: ?) -> string [builtin] function baml.time.from_components(hour: int, minute: int = 0, second: int = 0, millisecond: int = 0, microsecond: int = 0, nanosecond: int = 0) -> baml.time.PlainTime [expr] { @@ -1674,13 +2200,23 @@ function baml.time.to_string(self: ?) -> string [expr] { class baml.time.AmbiguousTimeError { message: string } +class baml.time.AmbiguousTimeError$stream { + message: string | null +} class baml.time.TimeZoneOffset { _nanoseconds: int } +class baml.time.TimeZoneOffset$stream { + _nanoseconds: int | null +} class baml.time.UnknownTimezoneError { timezone: string } +class baml.time.UnknownTimezoneError$stream { + timezone: string | null +} type baml.time.Disambiguation = "compatible" | "earlier" | "later" | "reject" +type baml.time.Disambiguation$stream = "compatible" | "earlier" | "later" | "reject" function baml.time._tz_offset_at(timezone: string, at_ns: bigint) -> int? [builtin] function baml.time._tz_to_instant(timezone: string, civil_ns: bigint, disambiguation: string) -> bigint? [builtin] function baml.time.from_duration(duration: Duration) -> baml.time.TimeZoneOffset [builtin] @@ -1713,6 +2249,11 @@ class baml.time.ZonedDateTime { _offset_ns: int? _iana: string? } +class baml.time.ZonedDateTime$stream { + _nanoseconds: bigint | null + _offset_ns: int | null + _iana: string | null +} function baml.time._format_zoned(epoch_ns: bigint, offset_ns: int, iana: string?) -> string [builtin] function baml.time._to_string_impl(self: ?) -> string [expr] { { } _format_zoned(self._nanoseconds, self.timezone_offset()._nanoseconds, self._iana) @@ -1786,10 +2327,17 @@ function baml.time.year(self: ?) -> int [expr] { class baml.toml.Table { items: map } +class baml.toml.Table$stream { + items: map +} class baml.toml.TomlParseError { message: string } +class baml.toml.TomlParseError$stream { + message: string | null +} type baml.toml.Item = baml.toml.Table | baml.toml.Item[] | bool | int | float | string | baml.time.ZonedDateTime | baml.time.PlainDateTime | baml.time.PlainDate | baml.time.PlainTime +type baml.toml.Item$stream = baml.toml.Table$stream | baml.toml.Item$stream[] | bool | int | float | string | baml.time.ZonedDateTime$stream | baml.time.PlainDateTime$stream | baml.time.PlainDate$stream | baml.time.PlainTime$stream function baml.toml.from_json(j: baml.json.json) -> Self [expr] { { } table_from_json(j) } @@ -1811,6 +2359,9 @@ function baml.toml.to_json(self: ?) -> baml.json.json [expr] { class baml.yaml.YamlParseError { message: string } +class baml.yaml.YamlParseError$stream { + message: string | null +} function baml.yaml.deserialize(s: string) -> T [expr] { { } baml.json.from_json(parse(s)) } @@ -1819,10 +2370,14 @@ function baml.yaml.parse(s: string) -> baml.json.json [builtin] --- /baml/null.baml --- class baml.Null { } +class baml.Null$stream { +} --- /baml/string.baml --- class baml.String { } +class baml.String$stream { +} function baml.byte_length(self: ?) -> int [builtin] function baml.char_at(self: ?, index: int) -> string [builtin] function baml.char_count(self: ?) -> int [builtin] @@ -1874,6 +2429,8 @@ function baml.trim_start(self: ?) -> string [builtin] --- /baml/type_class.baml --- class baml.TypeValue { } +class baml.TypeValue$stream { +} function baml._to_string_impl(self: ?) -> string [builtin] function baml.implemented_by(self: ?, other: type) -> bool [builtin] function baml.implementors(self: ?) -> type[] [builtin] @@ -1885,6 +2442,8 @@ function baml.to_string(self: ?) -> string [expr] { --- /baml/uint8array.baml --- class baml.Uint8Array { } +class baml.Uint8Array$stream { +} function baml._to_string_impl(self: ?) -> string [builtin] function baml.at(self: ?, index: int) -> int? [builtin] function baml.concat(self: ?, other: uint8array) -> uint8array [builtin] diff --git a/baml_language/crates/baml_tests/snapshots/compiles/__testing_std__/baml_tests__compiles____testing_std____03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/__testing_std__/baml_tests__compiles____testing_std____03_ppir.snap similarity index 89% rename from baml_language/crates/baml_tests/snapshots/compiles/__testing_std__/baml_tests__compiles____testing_std____03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/__testing_std__/baml_tests__compiles____testing_std____03_ppir.snap index 61f4ffead66..8e54166fc99 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/__testing_std__/baml_tests__compiles____testing_std____03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/__testing_std__/baml_tests__compiles____testing_std____03_ppir.snap @@ -1,55 +1,100 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 5036 --- -=== HIR2 === +=== PPIR === -=== HIR2 (package testing) === +=== PPIR (package testing) === --- /testing/registry.baml --- class testing.FilterPat { func_pat: string test_pat: string } +class testing.FilterPat$stream { + func_pat: string | null + test_pat: string | null +} class testing.LeafCounts { passed: int failed: int tolerated: int total: int } +class testing.LeafCounts$stream { + passed: int | null + failed: int | null + tolerated: int | null + total: int | null +} class testing.NameSplit { head: string tail: string } +class testing.NameSplit$stream { + head: string | null + tail: string | null +} class testing.SerializedTest { type: string name: string } +class testing.SerializedTest$stream { + type: string | null + name: string | null +} class testing.SerializedTestSet { name: string items: testing.SerializedTestDef[] loadingTimeMs: int } +class testing.SerializedTestSet$stream { + name: string | null + items: testing.SerializedTestDef$stream[] + loadingTimeMs: int | null +} class testing.TestCollector { prefix: string tests: testing.TestRegistration[] testsets: testing.TestSetRegistration[] } +class testing.TestCollector$stream { + prefix: string | null + tests: testing.TestRegistration$stream[] + testsets: testing.TestSetRegistration$stream[] +} class testing.TestRegistration { name: string body: TestBody runner: TestRunner? } +class testing.TestRegistration$stream { + name: string | null + body: TestBody$stream | null + runner: TestRunner$stream | null +} class testing.TestRegistry { collector: testing.TestCollector expansions: map loading_time_ms: int } +class testing.TestRegistry$stream { + collector: testing.TestCollector$stream | null + expansions: map + loading_time_ms: int | null +} class testing.TestSetRegistration { name: string collector: TestSetBody runner: TestSetRunner? } +class testing.TestSetRegistration$stream { + name: string | null + collector: TestSetBody$stream | null + runner: TestSetRunner$stream | null +} type testing.SerializedTestDef = testing.SerializedTest | testing.SerializedTestSet +type testing.SerializedTestDef$stream = testing.SerializedTest$stream | testing.SerializedTestSet$stream function testing.$invoke_collector(collector: TestSetBody, c: testing.TestCollector) -> void [expr] { { } collector(c) } @@ -107,12 +152,12 @@ function testing.leaf_selected(name: string, include: testing.FilterPat[], exclu function testing.list_filtered(self: ?, include: string[], exclude: string[]) -> string[] [expr] { { } root.select_names(self, include, exclude) } -function testing.new(collector: testing.TestCollector) -> testing.TestRegistry [expr] { - { } testing.TestRegistry { collector: collector, expansions: map { }, loading_time_ms: 0 } -} function testing.new(prefix: string) -> testing.TestCollector [expr] { { } testing.TestCollector { prefix: prefix, tests: [], testsets: [] } } +function testing.new(collector: testing.TestCollector) -> testing.TestRegistry [expr] { + { } testing.TestRegistry { collector: collector, expansions: map { }, loading_time_ms: 0 } +} function testing.parse_filter_patterns(raw: string[]) -> testing.FilterPat[] [expr] { { let out: testing.FilterPat[] = []; for s in raw { } if let idx: int = s.index_of("::") { } out.push(testing.FilterPat { func_pat: s.substring(0, idx), test_pat: s.substring(idx Add 2, s.length()) }) else { out.push(testing.FilterPat { func_pat: s, test_pat: "" }) } out.push(testing.FilterPat { func_pat: "", test_pat: s }) } out } @@ -140,12 +185,12 @@ function testing.run_test(self: ?, name: string) -> TestReport [expr] { function testing.run_test(body: TestBody, runner: TestRunner?) -> TestReport [expr] { { let base_run: TestReportThunk = () -> TestReport { { let start = baml.sys.now_ms(); let result = { body() } RunReport { outcome: "pass", duration_ms: 0, message: null } catch_all (e) { p: baml.panics.UserPanic => { } RunReport { outcome: "fail", duration_ms: 0, message: p.message }, p: baml.panics.AssertionFailed => { } RunReport { outcome: "fail", duration_ms: 0, message: p.message }, baml.panics.Panic => { } RunReport { outcome: "fail", duration_ms: 0, message: null }, _ => { } RunReport { outcome: "fail", duration_ms: 0, message: null } } } TestReport { outcome: result.outcome, runs: [RunReport { outcome: result.outcome, duration_ms: baml.sys.now_ms() Sub start, message: result.message }] } } } match (runner) { null => base_run(), r: TestRunner => { let wrapped: TestReportThunk = r(base_run) } wrapped() } } -function testing.run_testset(children: TestSetChild[], runner: TestSetRunner?) -> TestSetReport [expr] { - { } match (runner) { null => root.run_children_parallel(children), r: TestSetRunner => r(children) } -} function testing.run_testset(self: ?, name: string) -> TestSetReport [expr] { { for ts in self.collector.testsets { } if (ts.name Eq name) { return root.run_testset(root.testset_children(self.expand_testset_registry(ts)), ts.runner) }; for k in self.expansions.keys() { let sub = self.expansions[k] } if (name.starts_with(k Add "/")) { return sub.run_testset(name) }; throw "TestSet not found: " Add name } } +function testing.run_testset(children: TestSetChild[], runner: TestSetRunner?) -> TestSetReport [expr] { + { } match (runner) { null => root.run_children_parallel(children), r: TestSetRunner => r(children) } +} function testing.select_names(registry: testing.TestRegistry, include: string[], exclude: string[]) -> string[] [expr] { { let inc = root.parse_filter_patterns(include); let exc = root.parse_filter_patterns(exclude); let out: string[] = []; for name in root.collect_leaf_names(registry) { } if (root.leaf_selected(name, inc, exc)) { out.push(name) } } out } @@ -216,23 +261,49 @@ class testing.FlatTestReport { failed_names: string[] messages: string[] } +class testing.FlatTestReport$stream { + outcome: testing.Outcome$stream | null + passed: int | null + failed: int | null + tolerated: int | null + total: int | null + failed_names: string[] + messages: string[] +} class testing.NamedChildReport { name: string report: testing.ChildReport } +class testing.NamedChildReport$stream { + name: string | null + report: testing.ChildReport$stream | null +} class testing.RunReport { outcome: testing.Outcome duration_ms: int message: string? } +class testing.RunReport$stream { + outcome: testing.Outcome$stream | null + duration_ms: int | null + message: string | null +} class testing.TestReport { outcome: testing.Outcome runs: testing.RunReport[] } +class testing.TestReport$stream { + outcome: testing.Outcome$stream | null + runs: testing.RunReport$stream[] +} class testing.TestSetChild { name: string run: testing.ChildReportThunk } +class testing.TestSetChild$stream { + name: string | null + run: testing.ChildReportThunk$stream | null +} class testing.TestSetReport { outcome: testing.Outcome passed: int @@ -241,12 +312,29 @@ class testing.TestSetReport { failed_names: string[] results: testing.ChildReport[] } +class testing.TestSetReport$stream { + outcome: testing.Outcome$stream | null + passed: int | null + failed: int | null + total: int | null + failed_names: string[] + results: testing.ChildReport$stream[] +} type testing.ChildReport = testing.TestReport | testing.TestSetReport +type testing.ChildReport$stream = testing.TestReport$stream | testing.TestSetReport$stream type testing.ChildReportThunk = () -> testing.ChildReport throws never +type testing.ChildReportThunk$stream = unknown type testing.Outcome = "pass" | "fail" | "error" +type testing.Outcome$stream = "pass" | "fail" | "error" type testing.TestBody = () -> void throws unknown +type testing.TestBody$stream = unknown type testing.TestReportThunk = () -> testing.TestReport throws never +type testing.TestReportThunk$stream = unknown type testing.TestRunner = (testing.TestReportThunk) -> testing.TestReportThunk throws never +type testing.TestRunner$stream = unknown type testing.TestSetBody = (TestCollector) -> void throws unknown +type testing.TestSetBody$stream = unknown type testing.TestSetReportThunk = () -> testing.TestSetReport throws never +type testing.TestSetReportThunk$stream = unknown type testing.TestSetRunner = (testing.TestSetChild[]) -> testing.TestSetReport throws never +type testing.TestSetRunner$stream = unknown diff --git a/baml_language/crates/baml_tests/snapshots/compiles/anyfunction_reflect/baml_tests__compiles__anyfunction_reflect__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/anyfunction_reflect/baml_tests__compiles__anyfunction_reflect__03_ppir.snap similarity index 93% rename from baml_language/crates/baml_tests/snapshots/compiles/anyfunction_reflect/baml_tests__compiles__anyfunction_reflect__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/anyfunction_reflect/baml_tests__compiles__anyfunction_reflect__03_ppir.snap index cc789ea74c7..f0988bd4a29 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/anyfunction_reflect/baml_tests__compiles__anyfunction_reflect__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/anyfunction_reflect/baml_tests__compiles__anyfunction_reflect__03_ppir.snap @@ -1,13 +1,19 @@ --- source: crates/baml_tests/src/generated_tests.rs --- -=== HIR2 === +=== PPIR === class user.Doc { title: string } +class user.Doc$stream { + title: string | null +} class user.ToolError { message: string } +class user.ToolError$stream { + message: string | null +} function user.bare_and_pinned() -> int [expr] { { let f: baml.AnyFunction = web_search; let g: baml.AnyFunction = web_search; let widened: baml.AnyFunction = g; let bare: baml.AnyFunction = g; return 0 } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/backtick_decl_slots/baml_tests__compiles__backtick_decl_slots__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/backtick_decl_slots/baml_tests__compiles__backtick_decl_slots__03_ppir.snap similarity index 75% rename from baml_language/crates/baml_tests/snapshots/compiles/backtick_decl_slots/baml_tests__compiles__backtick_decl_slots__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/backtick_decl_slots/baml_tests__compiles__backtick_decl_slots__03_ppir.snap index 2a56520bc19..7ebe38beeaa 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/backtick_decl_slots/baml_tests__compiles__backtick_decl_slots__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/backtick_decl_slots/baml_tests__compiles__backtick_decl_slots__03_ppir.snap @@ -1,7 +1,7 @@ --- source: crates/baml_tests/src/generated_tests.rs --- -=== HIR2 === +=== PPIR === function user.Fast$new(lenient: bool) -> ? [expr] { baml.llm.PrimitiveClient { name: "Fast", provider: "openai", options: baml.llm.PrimitiveClientOptions { model: "gpt-4o-mini", base_url: null, allowed_role_metadata: null, finish_reason_allow_list: null, finish_reason_deny_list: null, supports_streaming: null, default_role: null, allowed_roles: null, remap_roles: null, api_key: baml.env.get_or_panic_lenient("OPENAI_API_KEY", lenient), provider_options: null, media_url_handler: null, headers: map { }, query_params: map { }, request_body: map { } } } } @@ -14,9 +14,18 @@ function user.Greet$build_request(name: string, client: baml.llm.Client = Fast) function user.Greet$build_request_stream(name: string, client: baml.llm.Client = Fast) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "Greet", map { "name": name }, prompt_closure = baml.llm.prompt`...`) } +function user.Greet$parse(json: string, client: baml.llm.Client = Fast) -> string [expr] { + baml.llm.parse(json) +} +function user.Greet$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = Fast) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.Greet$render_prompt(name: string, client: baml.llm.Client = Fast) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "Greet", map { "name": name }, prompt_closure = baml.llm.prompt`...`) } +function user.Greet$stream(name: string, client: baml.llm.Client = Fast) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "Greet", map { "name": name }, prompt_closure = baml.llm.prompt`...`) +} --- captures --- lambda () in Greet: captures [name] diff --git a/baml_language/crates/baml_tests/snapshots/compiles/backtick_dedent/baml_tests__compiles__backtick_dedent__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/backtick_dedent/baml_tests__compiles__backtick_dedent__03_ppir.snap similarity index 94% rename from baml_language/crates/baml_tests/snapshots/compiles/backtick_dedent/baml_tests__compiles__backtick_dedent__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/backtick_dedent/baml_tests__compiles__backtick_dedent__03_ppir.snap index 6721b180109..2fefc59a6ab 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/backtick_dedent/baml_tests__compiles__backtick_dedent__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/backtick_dedent/baml_tests__compiles__backtick_dedent__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 5763 --- -=== HIR2 === +=== PPIR === function user.FarIndented() -> string [expr] { { } `...` } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/backtick_strings/baml_tests__compiles__backtick_strings__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/backtick_strings/baml_tests__compiles__backtick_strings__03_ppir.snap similarity index 98% rename from baml_language/crates/baml_tests/snapshots/compiles/backtick_strings/baml_tests__compiles__backtick_strings__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/backtick_strings/baml_tests__compiles__backtick_strings__03_ppir.snap index 930393e3453..81e2427e3cf 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/backtick_strings/baml_tests__compiles__backtick_strings__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/backtick_strings/baml_tests__compiles__backtick_strings__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 6110 --- -=== HIR2 === +=== PPIR === function user.BacktickEquality() -> bool [expr] { { } `...` Eq `...` } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/bigint_arith/baml_tests__compiles__bigint_arith__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/bigint_arith/baml_tests__compiles__bigint_arith__03_ppir.snap similarity index 95% rename from baml_language/crates/baml_tests/snapshots/compiles/bigint_arith/baml_tests__compiles__bigint_arith__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/bigint_arith/baml_tests__compiles__bigint_arith__03_ppir.snap index 9b104fff8ce..3c22e6cfc12 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/bigint_arith/baml_tests__compiles__bigint_arith__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/bigint_arith/baml_tests__compiles__bigint_arith__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 6457 --- -=== HIR2 === +=== PPIR === function user.AddBigints() -> bigint [expr] { { } 2n Add 3n } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/bigint_cmp/baml_tests__compiles__bigint_cmp__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/bigint_cmp/baml_tests__compiles__bigint_cmp__03_ppir.snap similarity index 91% rename from baml_language/crates/baml_tests/snapshots/compiles/bigint_cmp/baml_tests__compiles__bigint_cmp__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/bigint_cmp/baml_tests__compiles__bigint_cmp__03_ppir.snap index c1ce5cf1dda..d73c0aaf174 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/bigint_cmp/baml_tests__compiles__bigint_cmp__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/bigint_cmp/baml_tests__compiles__bigint_cmp__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 6805 --- -=== HIR2 === +=== PPIR === function user.EqDistinctAllocs() -> bool [expr] { { let a: bigint = 42n; let b: bigint = bigint.parse("42") } a Eq b } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/bigint_literal/baml_tests__compiles__bigint_literal__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/bigint_literal/baml_tests__compiles__bigint_literal__03_ppir.snap similarity index 89% rename from baml_language/crates/baml_tests/snapshots/compiles/bigint_literal/baml_tests__compiles__bigint_literal__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/bigint_literal/baml_tests__compiles__bigint_literal__03_ppir.snap index 04146702a47..9a9c14bba28 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/bigint_literal/baml_tests__compiles__bigint_literal__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/bigint_literal/baml_tests__compiles__bigint_literal__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 7149 --- -=== HIR2 === +=== PPIR === function user.GetBigint() -> bigint [expr] { { let x: bigint = 42n } x } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/byte_string_literals/baml_tests__compiles__byte_string_literals__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/byte_string_literals/baml_tests__compiles__byte_string_literals__03_ppir.snap similarity index 97% rename from baml_language/crates/baml_tests/snapshots/compiles/byte_string_literals/baml_tests__compiles__byte_string_literals__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/byte_string_literals/baml_tests__compiles__byte_string_literals__03_ppir.snap index cd9f646967e..6a693504d80 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/byte_string_literals/baml_tests__compiles__byte_string_literals__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/byte_string_literals/baml_tests__compiles__byte_string_literals__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 7497 --- -=== HIR2 === +=== PPIR === function user.ByteStringBasic() -> int [expr] { { let data = b"<5 bytes>" } data.length() } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/catch_all_keyword/baml_tests__compiles__catch_all_keyword__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/catch_all_keyword/baml_tests__compiles__catch_all_keyword__03_ppir.snap similarity index 95% rename from baml_language/crates/baml_tests/snapshots/compiles/catch_all_keyword/baml_tests__compiles__catch_all_keyword__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/catch_all_keyword/baml_tests__compiles__catch_all_keyword__03_ppir.snap index 1d53db56a69..3d940d5e282 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/catch_all_keyword/baml_tests__compiles__catch_all_keyword__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/catch_all_keyword/baml_tests__compiles__catch_all_keyword__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 7844 --- -=== HIR2 === +=== PPIR === function user.CatchAllTyped(x: int) -> string [expr] { { } MayFailIntOrString(x) catch_all (e) { string => "caught string", int => "caught int" } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/catch_all_panics/baml_tests__compiles__catch_all_panics__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/catch_all_panics/baml_tests__compiles__catch_all_panics__03_ppir.snap similarity index 95% rename from baml_language/crates/baml_tests/snapshots/compiles/catch_all_panics/baml_tests__compiles__catch_all_panics__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/catch_all_panics/baml_tests__compiles__catch_all_panics__03_ppir.snap index 5d1942a39ea..299560fab77 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/catch_all_panics/baml_tests__compiles__catch_all_panics__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/catch_all_panics/baml_tests__compiles__catch_all_panics__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 8195 --- -=== HIR2 === +=== PPIR === function user.CatchAllPanicsTyped(x: int) -> string [expr] { { } MayFailIntOrString(x) catch_all_panics (e) { string => "caught string", int => "caught int" } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/catch_arm_return/baml_tests__compiles__catch_arm_return__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/catch_arm_return/baml_tests__compiles__catch_arm_return__03_ppir.snap similarity index 91% rename from baml_language/crates/baml_tests/snapshots/compiles/catch_arm_return/baml_tests__compiles__catch_arm_return__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/catch_arm_return/baml_tests__compiles__catch_arm_return__03_ppir.snap index 26fcc00b9c5..62d451e09f9 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/catch_arm_return/baml_tests__compiles__catch_arm_return__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/catch_arm_return/baml_tests__compiles__catch_arm_return__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 8543 --- -=== HIR2 === +=== PPIR === function user.may_throw(x: int) -> int [expr] { { if (x Eq 0) { throw "boom" } } x } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/catch_throw/baml_tests__compiles__catch_throw__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/catch_throw/baml_tests__compiles__catch_throw__03_ppir.snap similarity index 97% rename from baml_language/crates/baml_tests/snapshots/compiles/catch_throw/baml_tests__compiles__catch_throw__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/catch_throw/baml_tests__compiles__catch_throw__03_ppir.snap index 0f85418334f..85ee60220c0 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/catch_throw/baml_tests__compiles__catch_throw__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/catch_throw/baml_tests__compiles__catch_throw__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 8891 --- -=== HIR2 === +=== PPIR === function user.AlsoMayFail(x: int) -> string [expr] { { } match (x) { 0 => throw "secondary error", _ => "also ok" } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/closure_loop_variable/baml_tests__compiles__closure_loop_variable__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/closure_loop_variable/baml_tests__compiles__closure_loop_variable__03_ppir.snap similarity index 89% rename from baml_language/crates/baml_tests/snapshots/compiles/closure_loop_variable/baml_tests__compiles__closure_loop_variable__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/closure_loop_variable/baml_tests__compiles__closure_loop_variable__03_ppir.snap index d6ae8ae0bab..59d2bb4e204 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/closure_loop_variable/baml_tests__compiles__closure_loop_variable__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/closure_loop_variable/baml_tests__compiles__closure_loop_variable__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 9239 --- -=== HIR2 === +=== PPIR === function user.sum_array(arr: int[]) -> int [expr] { { let sum = 0; let total = []; for i in arr { } total.push(() -> { { sum Add= i } }); for cb in total { cb() } } sum } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/closures/baml_tests__compiles__closures__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/closures/baml_tests__compiles__closures__03_ppir.snap similarity index 86% rename from baml_language/crates/baml_tests/snapshots/compiles/closures/baml_tests__compiles__closures__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/closures/baml_tests__compiles__closures__03_ppir.snap index e2525b73b89..f78b4f39092 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/closures/baml_tests__compiles__closures__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/closures/baml_tests__compiles__closures__03_ppir.snap @@ -1,33 +1,60 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 9586 --- -=== HIR2 === +=== PPIR === class user.Box { value: T } +class user.Box$stream { + value: T | null +} class user.Calculator { op: string } +class user.Calculator$stream { + op: string | null +} class user.Config { encoder: user.Encoder } +class user.Config$stream { + encoder: user.Encoder$stream | null +} class user.Counter { value: int } +class user.Counter$stream { + value: int | null +} class user.Employee { first: string last: string } +class user.Employee$stream { + first: string | null + last: string | null +} class user.Encoder { charset: string } +class user.Encoder$stream { + charset: string | null +} class user.Formatter { prefix: string } +class user.Formatter$stream { + prefix: string | null +} class user.RangeCheck { min: int max: int } +class user.RangeCheck$stream { + min: int | null + max: int | null +} function user.apply(f: (int, int) -> int, a: int, b: int) -> int [expr] { { } f(a, b) } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/comment_after_string_in_config/baml_tests__compiles__comment_after_string_in_config__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/comment_after_string_in_config/baml_tests__compiles__comment_after_string_in_config__03_ppir.snap similarity index 95% rename from baml_language/crates/baml_tests/snapshots/compiles/comment_after_string_in_config/baml_tests__compiles__comment_after_string_in_config__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/comment_after_string_in_config/baml_tests__compiles__comment_after_string_in_config__03_ppir.snap index 0e5568f6444..e748f9ed7f5 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/comment_after_string_in_config/baml_tests__compiles__comment_after_string_in_config__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/comment_after_string_in_config/baml_tests__compiles__comment_after_string_in_config__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 9929 --- -=== HIR2 === +=== PPIR === function user.OpenRouterMistralSmall3_1_24b$new(lenient: bool) -> ? [expr] { baml.llm.PrimitiveClient { name: "OpenRouterMistral...", provider: "openai-generic", options: baml.llm.PrimitiveClientOptions { model: "mistralai/mistral...", base_url: "https://openroute...", allowed_role_metadata: null, finish_reason_allow_list: null, finish_reason_deny_list: null, supports_streaming: null, default_role: null, allowed_roles: null, remap_roles: null, api_key: baml.env.get_or_panic_lenient("OPENROUTER_API_KEY", lenient), provider_options: null, media_url_handler: null, headers: map { }, query_params: map { }, request_body: map { "temperature": 0.1 } } } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/comment_in_type/baml_tests__compiles__comment_in_type__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/comment_in_type/baml_tests__compiles__comment_in_type__03_ppir.snap similarity index 65% rename from baml_language/crates/baml_tests/snapshots/compiles/comment_in_type/baml_tests__compiles__comment_in_type__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/comment_in_type/baml_tests__compiles__comment_in_type__03_ppir.snap index a46822bcbc6..87fe598ef14 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/comment_in_type/baml_tests__compiles__comment_in_type__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/comment_in_type/baml_tests__compiles__comment_in_type__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 10276 --- -=== HIR2 === +=== PPIR === function user.CommentAfterArrow(client: baml.llm.Client = TestClient) -> string [llm] { baml.llm.call_llm_function(client, "CommentAfterArrow", map { }) } @@ -11,9 +12,18 @@ function user.CommentAfterArrow$build_request(client: baml.llm.Client = TestClie function user.CommentAfterArrow$build_request_stream(client: baml.llm.Client = TestClient) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "CommentAfterArrow", map { }) } +function user.CommentAfterArrow$parse(json: string, client: baml.llm.Client = TestClient) -> string [expr] { + baml.llm.parse(json) +} +function user.CommentAfterArrow$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = TestClient) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.CommentAfterArrow$render_prompt(client: baml.llm.Client = TestClient) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "CommentAfterArrow", map { }) } +function user.CommentAfterArrow$stream(client: baml.llm.Client = TestClient) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "CommentAfterArrow", map { }) +} function user.FunctionWithComments(a: string, b: int, client: baml.llm.Client = TestClient) -> string [llm] { baml.llm.call_llm_function(client, "FunctionWithComments", map { "a": a, "b": b }) } @@ -23,9 +33,18 @@ function user.FunctionWithComments$build_request(a: string, b: int, client: baml function user.FunctionWithComments$build_request_stream(a: string, b: int, client: baml.llm.Client = TestClient) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "FunctionWithComments", map { "a": a, "b": b }) } +function user.FunctionWithComments$parse(json: string, client: baml.llm.Client = TestClient) -> string [expr] { + baml.llm.parse(json) +} +function user.FunctionWithComments$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = TestClient) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.FunctionWithComments$render_prompt(a: string, b: int, client: baml.llm.Client = TestClient) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "FunctionWithComments", map { "a": a, "b": b }) } +function user.FunctionWithComments$stream(a: string, b: int, client: baml.llm.Client = TestClient) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "FunctionWithComments", map { "a": a, "b": b }) +} function user.TestClient$new(lenient: bool) -> ? [expr] { baml.llm.PrimitiveClient { name: "TestClient", provider: "openai", options: baml.llm.PrimitiveClientOptions { model: null, base_url: null, allowed_role_metadata: null, finish_reason_allow_list: null, finish_reason_deny_list: null, supports_streaming: null, default_role: null, allowed_roles: null, remap_roles: null, api_key: null, provider_options: null, media_url_handler: null, headers: map { }, query_params: map { }, request_body: map { } } } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/config_dictionary/baml_tests__compiles__config_dictionary__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/config_dictionary/baml_tests__compiles__config_dictionary__03_ppir.snap similarity index 97% rename from baml_language/crates/baml_tests/snapshots/compiles/config_dictionary/baml_tests__compiles__config_dictionary__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/config_dictionary/baml_tests__compiles__config_dictionary__03_ppir.snap index 9c0e140e5fb..160831a0e17 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/config_dictionary/baml_tests__compiles__config_dictionary__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/config_dictionary/baml_tests__compiles__config_dictionary__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 10624 --- -=== HIR2 === +=== PPIR === function user.MyClient$new(lenient: bool) -> ? [expr] { baml.llm.PrimitiveClient { name: "MyClient", provider: "openai", options: baml.llm.PrimitiveClientOptions { model: null, base_url: null, allowed_role_metadata: null, finish_reason_allow_list: null, finish_reason_deny_list: null, supports_streaming: null, default_role: null, allowed_roles: null, remap_roles: null, api_key: null, provider_options: null, media_url_handler: null, headers: map { }, query_params: map { }, request_body: map { "max_tokens": 100, "array_key_with_qu...": ["abc", "abc", "ccc"], "key2": "somerandomvalue", "hello": "world", "thing": "hello", "block_string": "#hellotheremyfriend#", "inline_raw_string": "#inlinerawstring,,#", "booleanValue": true, "stringKey": true, "array1": ["one", "two"], "array2": ["one", "two"], "array3Numbers": [1, 2, 3], "nestedKey": map { "key": "value", "key2": "value2", "nestedArray": ["yes", "queen"], "number": 10 }, "oneMoreValueToTes...": "value", "myInteger": 100, "tools": [map { "server_label": "parallel_web_search", "server_url": "https://example.com", "headers": map { "authorization": "Bearertoken" }, "type": "mcp" }, map { "another_tool": "value" }], "block_string": "#hellotheremyfrie..." } } } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/config_model_string/baml_tests__compiles__config_model_string__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/config_model_string/baml_tests__compiles__config_model_string__03_ppir.snap similarity index 95% rename from baml_language/crates/baml_tests/snapshots/compiles/config_model_string/baml_tests__compiles__config_model_string__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/config_model_string/baml_tests__compiles__config_model_string__03_ppir.snap index c051a277359..1722bdc2df0 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/config_model_string/baml_tests__compiles__config_model_string__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/config_model_string/baml_tests__compiles__config_model_string__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 10972 --- -=== HIR2 === +=== PPIR === function user.MyAwsClient$new(lenient: bool) -> ? [expr] { baml.llm.PrimitiveClient { name: "MyAwsClient", provider: "aws-bedrock", options: baml.llm.PrimitiveClientOptions { model: "anthropic.claude-...", base_url: null, allowed_role_metadata: null, finish_reason_allow_list: null, finish_reason_deny_list: null, supports_streaming: null, default_role: null, allowed_roles: null, remap_roles: null, api_key: "sk-1234", provider_options: baml.llm.BedrockOptions { region: null, endpoint_url: null, access_key_id: null, secret_access_key: null, session_token: null, profile: null, stop_sequences: null, max_tokens: 100, temperature: 0.7, top_p: null }, media_url_handler: null, headers: map { }, query_params: map { }, request_body: map { } } } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/deep_method_call/baml_tests__compiles__deep_method_call__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/deep_method_call/baml_tests__compiles__deep_method_call__03_ppir.snap similarity index 76% rename from baml_language/crates/baml_tests/snapshots/compiles/deep_method_call/baml_tests__compiles__deep_method_call__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/deep_method_call/baml_tests__compiles__deep_method_call__03_ppir.snap index 84ed58a923a..f6ec52d2573 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/deep_method_call/baml_tests__compiles__deep_method_call__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/deep_method_call/baml_tests__compiles__deep_method_call__03_ppir.snap @@ -1,13 +1,20 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 11320 --- -=== HIR2 === +=== PPIR === class user.A { b: user.B } +class user.A$stream { + b: user.B$stream | null +} class user.B { label: string } +class user.B$stream { + label: string | null +} function user.greet(self: ?) -> string [expr] { { } self.label } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/function_call/baml_tests__compiles__function_call__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/function_call/baml_tests__compiles__function_call__03_ppir.snap similarity index 88% rename from baml_language/crates/baml_tests/snapshots/compiles/function_call/baml_tests__compiles__function_call__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/function_call/baml_tests__compiles__function_call__03_ppir.snap index ae99e106aa5..848544f80c8 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/function_call/baml_tests__compiles__function_call__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/function_call/baml_tests__compiles__function_call__03_ppir.snap @@ -1,13 +1,17 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 11738 --- -=== HIR2 === +=== PPIR === function user.array_length() -> int [expr] { { let array = [1, 2, 3]; return baml.Array.length(array) } } class user.Baz { name: string } +class user.Baz$stream { + name: string | null +} function user.Bar() -> int [expr] { { let x = Foo(1) } x } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/generic_field_chain/baml_tests__compiles__generic_field_chain__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/generic_field_chain/baml_tests__compiles__generic_field_chain__03_ppir.snap similarity index 79% rename from baml_language/crates/baml_tests/snapshots/compiles/generic_field_chain/baml_tests__compiles__generic_field_chain__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/generic_field_chain/baml_tests__compiles__generic_field_chain__03_ppir.snap index d2934a0023a..08593ace519 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/generic_field_chain/baml_tests__compiles__generic_field_chain__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/generic_field_chain/baml_tests__compiles__generic_field_chain__03_ppir.snap @@ -1,14 +1,22 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 12170 --- -=== HIR2 === +=== PPIR === class user.Box { value: T } +class user.Box$stream { + value: T | null +} class user.User { name: string age: int } +class user.User$stream { + name: string | null + age: int | null +} function user.test_generic_capture(box: user.Box) -> string [expr] { { let get_name = () -> string { { } box.value.name } } get_name() } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/generic_match_typevar_arm/baml_tests__compiles__generic_match_typevar_arm__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/generic_match_typevar_arm/baml_tests__compiles__generic_match_typevar_arm__03_ppir.snap similarity index 70% rename from baml_language/crates/baml_tests/snapshots/compiles/generic_match_typevar_arm/baml_tests__compiles__generic_match_typevar_arm__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/generic_match_typevar_arm/baml_tests__compiles__generic_match_typevar_arm__03_ppir.snap index 0ff8b846f65..8d4fd283b07 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/generic_match_typevar_arm/baml_tests__compiles__generic_match_typevar_arm__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/generic_match_typevar_arm/baml_tests__compiles__generic_match_typevar_arm__03_ppir.snap @@ -1,12 +1,18 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 12521 --- -=== HIR2 === +=== PPIR === class user.Non { } +class user.Non$stream { +} class user.Opt { value: T } +class user.Opt$stream { + value: T | null +} function user.unwrap_or(o: user.Opt | user.Non, default: T) -> T [expr] { { } match (o) { s: user.Opt => s.value, _ => default } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/host_callable_call/baml_tests__compiles__host_callable_call__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/host_callable_call/baml_tests__compiles__host_callable_call__03_ppir.snap similarity index 82% rename from baml_language/crates/baml_tests/snapshots/compiles/host_callable_call/baml_tests__compiles__host_callable_call__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/host_callable_call/baml_tests__compiles__host_callable_call__03_ppir.snap index f6196653c0e..4ffad87668a 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/host_callable_call/baml_tests__compiles__host_callable_call__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/host_callable_call/baml_tests__compiles__host_callable_call__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 12877 --- -=== HIR2 === +=== PPIR === function user.call_with_callback(callback: (int) -> string, x: int) -> string [expr] { { } callback(x) } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/is_operator/baml_tests__compiles__is_operator__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/is_operator/baml_tests__compiles__is_operator__03_ppir.snap similarity index 94% rename from baml_language/crates/baml_tests/snapshots/compiles/is_operator/baml_tests__compiles__is_operator__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/is_operator/baml_tests__compiles__is_operator__03_ppir.snap index 688f6d6bc85..3a26845dff8 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/is_operator/baml_tests__compiles__is_operator__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/is_operator/baml_tests__compiles__is_operator__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 13224 --- -=== HIR2 === +=== PPIR === function user.both_ints(a: int | string, b: int | string) -> bool [expr] { { } a is int And b is int } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/json_alias_basic/baml_tests__compiles__json_alias_basic__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/json_alias_basic/baml_tests__compiles__json_alias_basic__03_ppir.snap similarity index 90% rename from baml_language/crates/baml_tests/snapshots/compiles/json_alias_basic/baml_tests__compiles__json_alias_basic__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/json_alias_basic/baml_tests__compiles__json_alias_basic__03_ppir.snap index 65786977e97..dbd30be968e 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/json_alias_basic/baml_tests__compiles__json_alias_basic__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/json_alias_basic/baml_tests__compiles__json_alias_basic__03_ppir.snap @@ -1,10 +1,14 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 13572 --- -=== HIR2 === +=== PPIR === class user.Wrapper { data: baml.json.json } +class user.Wrapper$stream { + data: baml.json.json$stream | null +} function user.MakeWrapper() -> user.Wrapper [expr] { { } user.Wrapper { data: null } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/json_cross_namespace_static_call/baml_tests__compiles__json_cross_namespace_static_call__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/json_cross_namespace_static_call/baml_tests__compiles__json_cross_namespace_static_call__03_ppir.snap similarity index 73% rename from baml_language/crates/baml_tests/snapshots/compiles/json_cross_namespace_static_call/baml_tests__compiles__json_cross_namespace_static_call__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/json_cross_namespace_static_call/baml_tests__compiles__json_cross_namespace_static_call__03_ppir.snap index 9f885326b17..cb183a1b7b4 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/json_cross_namespace_static_call/baml_tests__compiles__json_cross_namespace_static_call__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/json_cross_namespace_static_call/baml_tests__compiles__json_cross_namespace_static_call__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 13990 --- -=== HIR2 === +=== PPIR === function user.decode_auto(j: baml.json.json) -> root.pkg.inner.AutoBox [expr] { { } root.pkg.inner.AutoBox.from_json(j) } @@ -14,9 +15,18 @@ function user.decode_root(j: baml.json.json) -> root.pkg.inner.Box [expr] class user.pkg.inner.AutoBox { value: T } +class user.pkg.inner.AutoBox$stream { + value: T | null +} class user.pkg.inner.Box { value: T } +class user.pkg.inner.Box$stream { + value: T | null +} class user.pkg.inner.Plain { n: int } +class user.pkg.inner.Plain$stream { + n: int | null +} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/json_llm_return_type/baml_tests__compiles__json_llm_return_type__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/json_llm_return_type/baml_tests__compiles__json_llm_return_type__03_ppir.snap similarity index 68% rename from baml_language/crates/baml_tests/snapshots/compiles/json_llm_return_type/baml_tests__compiles__json_llm_return_type__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/json_llm_return_type/baml_tests__compiles__json_llm_return_type__03_ppir.snap index d649b9fe45a..574747606e9 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/json_llm_return_type/baml_tests__compiles__json_llm_return_type__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/json_llm_return_type/baml_tests__compiles__json_llm_return_type__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 14424 --- -=== HIR2 === +=== PPIR === function user.ExtractAny(client: baml.llm.Client = TestClient) -> baml.json.json [llm] { baml.llm.call_llm_function(client, "ExtractAny", map { }) } @@ -11,9 +12,18 @@ function user.ExtractAny$build_request(client: baml.llm.Client = TestClient) -> function user.ExtractAny$build_request_stream(client: baml.llm.Client = TestClient) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "ExtractAny", map { }) } +function user.ExtractAny$parse(json: string, client: baml.llm.Client = TestClient) -> baml.json.json [expr] { + baml.llm.parse(json) +} +function user.ExtractAny$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = TestClient) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.ExtractAny$render_prompt(client: baml.llm.Client = TestClient) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "ExtractAny", map { }) } +function user.ExtractAny$stream(client: baml.llm.Client = TestClient) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "ExtractAny", map { }) +} function user.TestClient$new(lenient: bool) -> ? [expr] { baml.llm.PrimitiveClient { name: "TestClient", provider: "openai", options: baml.llm.PrimitiveClientOptions { model: "gpt-4o-mini", base_url: null, allowed_role_metadata: null, finish_reason_allow_list: null, finish_reason_deny_list: null, supports_streaming: null, default_role: null, allowed_roles: null, remap_roles: null, api_key: "test-key", provider_options: null, media_url_handler: null, headers: map { }, query_params: map { }, request_body: map { } } } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/json_map_literal/baml_tests__compiles__json_map_literal__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/json_map_literal/baml_tests__compiles__json_map_literal__03_ppir.snap similarity index 84% rename from baml_language/crates/baml_tests/snapshots/compiles/json_map_literal/baml_tests__compiles__json_map_literal__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/json_map_literal/baml_tests__compiles__json_map_literal__03_ppir.snap index d0410a6fac6..3399b07fe73 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/json_map_literal/baml_tests__compiles__json_map_literal__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/json_map_literal/baml_tests__compiles__json_map_literal__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 14776 --- -=== HIR2 === +=== PPIR === function user.NestedMapLiteral() -> baml.json.json [expr] { { } map { "a": 1, "b": [2, 3], "c": map { "nested": null } } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/json_parse_stringify_intrinsics/baml_tests__compiles__json_parse_stringify_intrinsics__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/json_parse_stringify_intrinsics/baml_tests__compiles__json_parse_stringify_intrinsics__03_ppir.snap similarity index 95% rename from baml_language/crates/baml_tests/snapshots/compiles/json_parse_stringify_intrinsics/baml_tests__compiles__json_parse_stringify_intrinsics__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/json_parse_stringify_intrinsics/baml_tests__compiles__json_parse_stringify_intrinsics__03_ppir.snap index 4618c0bbf59..8d1e36a4af6 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/json_parse_stringify_intrinsics/baml_tests__compiles__json_parse_stringify_intrinsics__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/json_parse_stringify_intrinsics/baml_tests__compiles__json_parse_stringify_intrinsics__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 15126 --- -=== HIR2 === +=== PPIR === function user.match_parsed(s: string) -> string [expr] { { let j: baml.json.json = baml.json.parse(s) } match (j) { arr: baml.json.json[] => baml.json.stringify(arr), m: map => baml.json.stringify(m), n: int => "int", f: float => "float", b: bool => "bool", st: string => st, null => "null" } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_composite_generic/baml_tests__compiles__json_to_from_string_composite_generic__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_composite_generic/baml_tests__compiles__json_to_from_string_composite_generic__03_ppir.snap similarity index 64% rename from baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_composite_generic/baml_tests__compiles__json_to_from_string_composite_generic__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_composite_generic/baml_tests__compiles__json_to_from_string_composite_generic__03_ppir.snap index b3ea00b6fbf..84ecab9ae6a 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_composite_generic/baml_tests__compiles__json_to_from_string_composite_generic__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_composite_generic/baml_tests__compiles__json_to_from_string_composite_generic__03_ppir.snap @@ -1,13 +1,20 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 15489 --- -=== HIR2 === +=== PPIR === class user.Container { item: T } +class user.Container$stream { + item: T | null +} class user.User { name: string } +class user.User$stream { + name: string | null +} function user.decode_container(s: string) -> user.Container [expr] { { } baml.json.from_string(s) } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_concrete/baml_tests__compiles__json_to_from_string_concrete__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_concrete/baml_tests__compiles__json_to_from_string_concrete__03_ppir.snap similarity index 74% rename from baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_concrete/baml_tests__compiles__json_to_from_string_concrete__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_concrete/baml_tests__compiles__json_to_from_string_concrete__03_ppir.snap index 70a0650de52..0076c248563 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_concrete/baml_tests__compiles__json_to_from_string_concrete__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_concrete/baml_tests__compiles__json_to_from_string_concrete__03_ppir.snap @@ -1,11 +1,16 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 15849 --- -=== HIR2 === +=== PPIR === class user.User { name: string age: int } +class user.User$stream { + name: string | null + age: int | null +} function user.deserialize_user(s: string) -> user.User [expr] { { } baml.json.from_string(s) } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_generic_forwarding/baml_tests__compiles__json_to_from_string_generic_forwarding__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_generic_forwarding/baml_tests__compiles__json_to_from_string_generic_forwarding__03_ppir.snap similarity index 80% rename from baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_generic_forwarding/baml_tests__compiles__json_to_from_string_generic_forwarding__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_generic_forwarding/baml_tests__compiles__json_to_from_string_generic_forwarding__03_ppir.snap index e74111ccc31..a5005bc6938 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_generic_forwarding/baml_tests__compiles__json_to_from_string_generic_forwarding__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_generic_forwarding/baml_tests__compiles__json_to_from_string_generic_forwarding__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 16211 --- -=== HIR2 === +=== PPIR === function user.fetch_as(s: string) -> T [expr] { { } baml.json.from_string(s) } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_three_level/baml_tests__compiles__json_to_from_string_three_level__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_three_level/baml_tests__compiles__json_to_from_string_three_level__03_ppir.snap similarity index 88% rename from baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_three_level/baml_tests__compiles__json_to_from_string_three_level__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_three_level/baml_tests__compiles__json_to_from_string_three_level__03_ppir.snap index 5b6d81774e5..b1255de0a30 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_three_level/baml_tests__compiles__json_to_from_string_three_level__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/json_to_from_string_three_level/baml_tests__compiles__json_to_from_string_three_level__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 16573 --- -=== HIR2 === +=== PPIR === function user.level1(s: string) -> T [expr] { { } baml.json.from_string(s) } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/lambda_advanced/baml_tests__compiles__lambda_advanced__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/lambda_advanced/baml_tests__compiles__lambda_advanced__03_ppir.snap similarity index 99% rename from baml_language/crates/baml_tests/snapshots/compiles/lambda_advanced/baml_tests__compiles__lambda_advanced__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/lambda_advanced/baml_tests__compiles__lambda_advanced__03_ppir.snap index aa62da292a2..9b8e224d330 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/lambda_advanced/baml_tests__compiles__lambda_advanced__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/lambda_advanced/baml_tests__compiles__lambda_advanced__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 16931 --- -=== HIR2 === +=== PPIR === function user.test_apply_twice_inferred() -> int [expr] { { let double = (x: int) -> { { } x Mul 2 }; let apply_twice = (f: (int) -> int throws never, x: int) -> { { } f(f(x)) } } apply_twice(double, 3) } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/lambda_basic/baml_tests__compiles__lambda_basic__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/lambda_basic/baml_tests__compiles__lambda_basic__03_ppir.snap similarity index 97% rename from baml_language/crates/baml_tests/snapshots/compiles/lambda_basic/baml_tests__compiles__lambda_basic__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/lambda_basic/baml_tests__compiles__lambda_basic__03_ppir.snap index 500971c3036..18e1dbc5046 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/lambda_basic/baml_tests__compiles__lambda_basic__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/lambda_basic/baml_tests__compiles__lambda_basic__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 17279 --- -=== HIR2 === +=== PPIR === function user.test_annotated() -> int [expr] { { let double = (x: int) -> int { { } x Mul 2 } } double(21) } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/lambda_fat_arrow/baml_tests__compiles__lambda_fat_arrow__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/lambda_fat_arrow/baml_tests__compiles__lambda_fat_arrow__03_ppir.snap similarity index 95% rename from baml_language/crates/baml_tests/snapshots/compiles/lambda_fat_arrow/baml_tests__compiles__lambda_fat_arrow__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/lambda_fat_arrow/baml_tests__compiles__lambda_fat_arrow__03_ppir.snap index 3275b93fd7e..67b9bd118a3 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/lambda_fat_arrow/baml_tests__compiles__lambda_fat_arrow__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/lambda_fat_arrow/baml_tests__compiles__lambda_fat_arrow__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 17627 --- -=== HIR2 === +=== PPIR === function user.test_annotated() -> int [expr] { { let double = (x: int) -> int { { } x Mul 2 } } double(21) } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/lambda_field_access/baml_tests__compiles__lambda_field_access__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/lambda_field_access/baml_tests__compiles__lambda_field_access__03_ppir.snap similarity index 90% rename from baml_language/crates/baml_tests/snapshots/compiles/lambda_field_access/baml_tests__compiles__lambda_field_access__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/lambda_field_access/baml_tests__compiles__lambda_field_access__03_ppir.snap index 0bbd1ba75c4..9bfdcda2ff7 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/lambda_field_access/baml_tests__compiles__lambda_field_access__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/lambda_field_access/baml_tests__compiles__lambda_field_access__03_ppir.snap @@ -1,14 +1,22 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 17975 --- -=== HIR2 === +=== PPIR === class user.Inner { value: int } +class user.Inner$stream { + value: int | null +} class user.Outer { inner: user.Inner name: string } +class user.Outer$stream { + inner: user.Inner$stream | null + name: string | null +} function user.test_captured_field_access(obj: user.Outer) -> string [expr] { { let get_name = () -> string { { } obj.name } } get_name() } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/lexical_scoping/baml_tests__compiles__lexical_scoping__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/lexical_scoping/baml_tests__compiles__lexical_scoping__03_ppir.snap similarity index 97% rename from baml_language/crates/baml_tests/snapshots/compiles/lexical_scoping/baml_tests__compiles__lexical_scoping__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/lexical_scoping/baml_tests__compiles__lexical_scoping__03_ppir.snap index f0d1f53a770..0ed165d78f1 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/lexical_scoping/baml_tests__compiles__lexical_scoping__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/lexical_scoping/baml_tests__compiles__lexical_scoping__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 18326 --- -=== HIR2 === +=== PPIR === function user.branch_locals(b: bool) -> int [expr] { { } if (b) { let a = 1 } a else { let a = 2 } a } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/literal_union_arithmetic/baml_tests__compiles__literal_union_arithmetic__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/literal_union_arithmetic/baml_tests__compiles__literal_union_arithmetic__03_ppir.snap similarity index 94% rename from baml_language/crates/baml_tests/snapshots/compiles/literal_union_arithmetic/baml_tests__compiles__literal_union_arithmetic__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/literal_union_arithmetic/baml_tests__compiles__literal_union_arithmetic__03_ppir.snap index 8808fc43979..3af0702c825 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/literal_union_arithmetic/baml_tests__compiles__literal_union_arithmetic__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/literal_union_arithmetic/baml_tests__compiles__literal_union_arithmetic__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 18674 --- -=== HIR2 === +=== PPIR === function user.bothSidesUnion() -> int [expr] { { } if (true) { } 1 else { } 2 Add if (false) { } 3 else { } 4 } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/literal_union_widening/baml_tests__compiles__literal_union_widening__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/literal_union_widening/baml_tests__compiles__literal_union_widening__03_ppir.snap similarity index 92% rename from baml_language/crates/baml_tests/snapshots/compiles/literal_union_widening/baml_tests__compiles__literal_union_widening__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/literal_union_widening/baml_tests__compiles__literal_union_widening__03_ppir.snap index e9cc0a2b90c..eddb90ecdfb 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/literal_union_widening/baml_tests__compiles__literal_union_widening__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/literal_union_widening/baml_tests__compiles__literal_union_widening__03_ppir.snap @@ -1,8 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs -assertion_line: 11323 +assertion_line: 19021 --- -=== HIR2 === +=== PPIR === function user.annotatedLiteralUnion() -> int [expr] { { let x: 1 | 2 = 1; return x } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/llm_image_outputs/baml_tests__compiles__llm_image_outputs__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/llm_image_outputs/baml_tests__compiles__llm_image_outputs__03_ppir.snap similarity index 65% rename from baml_language/crates/baml_tests/snapshots/compiles/llm_image_outputs/baml_tests__compiles__llm_image_outputs__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/llm_image_outputs/baml_tests__compiles__llm_image_outputs__03_ppir.snap index c91b66bc926..24a984f6972 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/llm_image_outputs/baml_tests__compiles__llm_image_outputs__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/llm_image_outputs/baml_tests__compiles__llm_image_outputs__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 19368 --- -=== HIR2 === +=== PPIR === function user.GenerateImage(prompt: string, client: baml.llm.Client = OpenAIImageResponses) -> image [llm] { baml.llm.call_llm_function(client, "GenerateImage", map { "prompt": prompt }) } @@ -11,9 +12,18 @@ function user.GenerateImage$build_request(prompt: string, client: baml.llm.Clien function user.GenerateImage$build_request_stream(prompt: string, client: baml.llm.Client = OpenAIImageResponses) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "GenerateImage", map { "prompt": prompt }) } +function user.GenerateImage$parse(json: string, client: baml.llm.Client = OpenAIImageResponses) -> image [expr] { + baml.llm.parse(json) +} +function user.GenerateImage$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = OpenAIImageResponses) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.GenerateImage$render_prompt(prompt: string, client: baml.llm.Client = OpenAIImageResponses) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "GenerateImage", map { "prompt": prompt }) } +function user.GenerateImage$stream(prompt: string, client: baml.llm.Client = OpenAIImageResponses) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "GenerateImage", map { "prompt": prompt }) +} function user.GenerateImageSet(prompt: string, client: baml.llm.Client = OpenAIImageResponses) -> image[] [llm] { baml.llm.call_llm_function(client, "GenerateImageSet", map { "prompt": prompt }) } @@ -23,9 +33,18 @@ function user.GenerateImageSet$build_request(prompt: string, client: baml.llm.Cl function user.GenerateImageSet$build_request_stream(prompt: string, client: baml.llm.Client = OpenAIImageResponses) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "GenerateImageSet", map { "prompt": prompt }) } +function user.GenerateImageSet$parse(json: string, client: baml.llm.Client = OpenAIImageResponses) -> image[] [expr] { + baml.llm.parse(json) +} +function user.GenerateImageSet$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = OpenAIImageResponses) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.GenerateImageSet$render_prompt(prompt: string, client: baml.llm.Client = OpenAIImageResponses) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "GenerateImageSet", map { "prompt": prompt }) } +function user.GenerateImageSet$stream(prompt: string, client: baml.llm.Client = OpenAIImageResponses) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "GenerateImageSet", map { "prompt": prompt }) +} function user.GenerateMixedImageNarrative(prompt: string, client: baml.llm.Client = OpenAIImageResponses) -> image | string[] [llm] { baml.llm.call_llm_function(client, "GenerateMixedImag...", map { "prompt": prompt }) } @@ -35,9 +54,18 @@ function user.GenerateMixedImageNarrative$build_request(prompt: string, client: function user.GenerateMixedImageNarrative$build_request_stream(prompt: string, client: baml.llm.Client = OpenAIImageResponses) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "GenerateMixedImag...", map { "prompt": prompt }) } +function user.GenerateMixedImageNarrative$parse(json: string, client: baml.llm.Client = OpenAIImageResponses) -> image | string[] [expr] { + baml.llm.parse(json) +} +function user.GenerateMixedImageNarrative$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = OpenAIImageResponses) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.GenerateMixedImageNarrative$render_prompt(prompt: string, client: baml.llm.Client = OpenAIImageResponses) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "GenerateMixedImag...", map { "prompt": prompt }) } +function user.GenerateMixedImageNarrative$stream(prompt: string, client: baml.llm.Client = OpenAIImageResponses) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "GenerateMixedImag...", map { "prompt": prompt }) +} function user.OpenAIImageResponses$new(lenient: bool) -> ? [expr] { baml.llm.PrimitiveClient { name: "OpenAIImageResponses", provider: "openai-responses", options: baml.llm.PrimitiveClientOptions { model: "gpt-4.1", base_url: null, allowed_role_metadata: null, finish_reason_allow_list: null, finish_reason_deny_list: null, supports_streaming: null, default_role: null, allowed_roles: null, remap_roles: null, api_key: baml.env.get_or_panic_lenient("OPENAI_API_KEY", lenient), provider_options: null, media_url_handler: null, headers: map { }, query_params: map { }, request_body: map { "tools": [map { "type": "image_generation", "size": "1024x1024", "quality": "low" }] } } } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/llm_parse_catchable_parse_error/baml_tests__compiles__llm_parse_catchable_parse_error__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/llm_parse_catchable_parse_error/baml_tests__compiles__llm_parse_catchable_parse_error__03_ppir.snap similarity index 70% rename from baml_language/crates/baml_tests/snapshots/compiles/llm_parse_catchable_parse_error/baml_tests__compiles__llm_parse_catchable_parse_error__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/llm_parse_catchable_parse_error/baml_tests__compiles__llm_parse_catchable_parse_error__03_ppir.snap index e4f63acbee0..7db0bafdb2b 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/llm_parse_catchable_parse_error/baml_tests__compiles__llm_parse_catchable_parse_error__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/llm_parse_catchable_parse_error/baml_tests__compiles__llm_parse_catchable_parse_error__03_ppir.snap @@ -1,11 +1,16 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 19715 --- -=== HIR2 === +=== PPIR === class user.Invoice { currency: user.Currency amount: float } +class user.Invoice$stream { + currency: user.Currency | null + amount: float | null +} enum user.Currency {USD, EUR} function user.ExtractInvoice(text: string, client: baml.llm.Client = GPT4o) -> user.Invoice [llm] { baml.llm.call_llm_function(client, "ExtractInvoice", map { "text": text }) @@ -16,9 +21,18 @@ function user.ExtractInvoice$build_request(text: string, client: baml.llm.Client function user.ExtractInvoice$build_request_stream(text: string, client: baml.llm.Client = GPT4o) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "ExtractInvoice", map { "text": text }) } +function user.ExtractInvoice$parse(json: string, client: baml.llm.Client = GPT4o) -> user.Invoice [expr] { + baml.llm.parse(json) +} +function user.ExtractInvoice$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = GPT4o) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.ExtractInvoice$render_prompt(text: string, client: baml.llm.Client = GPT4o) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "ExtractInvoice", map { "text": text }) } +function user.ExtractInvoice$stream(text: string, client: baml.llm.Client = GPT4o) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "ExtractInvoice", map { "text": text }) +} function user.GPT4o$new(lenient: bool) -> ? [expr] { baml.llm.PrimitiveClient { name: "GPT4o", provider: "openai", options: baml.llm.PrimitiveClientOptions { model: "gpt-4o", base_url: null, allowed_role_metadata: null, finish_reason_allow_list: null, finish_reason_deny_list: null, supports_streaming: null, default_role: null, allowed_roles: null, remap_roles: null, api_key: baml.env.get_or_panic_lenient("OPENAI_API_KEY", lenient), provider_options: null, media_url_handler: null, headers: map { }, query_params: map { }, request_body: map { } } } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/method_explicit_type_args/baml_tests__compiles__method_explicit_type_args__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/method_explicit_type_args/baml_tests__compiles__method_explicit_type_args__03_ppir.snap similarity index 77% rename from baml_language/crates/baml_tests/snapshots/compiles/method_explicit_type_args/baml_tests__compiles__method_explicit_type_args__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/method_explicit_type_args/baml_tests__compiles__method_explicit_type_args__03_ppir.snap index 30b3f168696..d91ad0b81c0 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/method_explicit_type_args/baml_tests__compiles__method_explicit_type_args__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/method_explicit_type_args/baml_tests__compiles__method_explicit_type_args__03_ppir.snap @@ -1,10 +1,14 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 20062 --- -=== HIR2 === +=== PPIR === class user.Foo { tag: string } +class user.Foo$stream { + tag: string | null +} function user.use_method_type_args() -> int [expr] { { let f = user.Foo { tag: "x" }; let v: int = f.zero() NullCoalesce 5 } v } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/namespaces_basic/baml_tests__compiles__namespaces_basic__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/namespaces_basic/baml_tests__compiles__namespaces_basic__03_ppir.snap similarity index 70% rename from baml_language/crates/baml_tests/snapshots/compiles/namespaces_basic/baml_tests__compiles__namespaces_basic__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/namespaces_basic/baml_tests__compiles__namespaces_basic__03_ppir.snap index 6fe3c80bf50..af6736b6f99 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/namespaces_basic/baml_tests__compiles__namespaces_basic__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/namespaces_basic/baml_tests__compiles__namespaces_basic__03_ppir.snap @@ -1,11 +1,16 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 20488 --- -=== HIR2 === +=== PPIR === class user.Config { key: string model: string } +class user.Config$stream { + key: string | null + model: string | null +} function user.GetResponse(cfg: user.Config) -> root.llm.Response [expr] { { } root.llm.Response { text: "hello", model: cfg.model } } @@ -13,6 +18,10 @@ class user.llm.Response { text: string model: string } +class user.llm.Response$stream { + text: string | null + model: string | null +} function user.llm.MakeResponse(cfg: root.Config) -> user.llm.Response [expr] { { } user.llm.Response { text: "ok", model: cfg.model } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/namespaces_nested/baml_tests__compiles__namespaces_nested__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/namespaces_nested/baml_tests__compiles__namespaces_nested__03_ppir.snap similarity index 64% rename from baml_language/crates/baml_tests/snapshots/compiles/namespaces_nested/baml_tests__compiles__namespaces_nested__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/namespaces_nested/baml_tests__compiles__namespaces_nested__03_ppir.snap index 6f228a350b6..a97eee014e7 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/namespaces_nested/baml_tests__compiles__namespaces_nested__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/namespaces_nested/baml_tests__compiles__namespaces_nested__03_ppir.snap @@ -1,10 +1,14 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 20989 --- -=== HIR2 === +=== PPIR === class user.AppConfig { api_key: string } +class user.AppConfig$stream { + api_key: string | null +} function user.CallOpenAI(cfg: user.AppConfig) -> root.llm.openai.OpenAIResponse [expr] { { } root.llm.openai.OpenAIResponse { text: "response", model: "gpt-4" } } @@ -12,3 +16,7 @@ class user.llm.openai.OpenAIResponse { text: string model: string } +class user.llm.openai.OpenAIResponse$stream { + text: string | null + model: string | null +} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/namespaces_root_fallback/baml_tests__compiles__namespaces_root_fallback__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/namespaces_root_fallback/baml_tests__compiles__namespaces_root_fallback__03_ppir.snap similarity index 64% rename from baml_language/crates/baml_tests/snapshots/compiles/namespaces_root_fallback/baml_tests__compiles__namespaces_root_fallback__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/namespaces_root_fallback/baml_tests__compiles__namespaces_root_fallback__03_ppir.snap index 2aea93c68e5..280b6065205 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/namespaces_root_fallback/baml_tests__compiles__namespaces_root_fallback__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/namespaces_root_fallback/baml_tests__compiles__namespaces_root_fallback__03_ppir.snap @@ -1,13 +1,20 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 21497 --- -=== HIR2 === +=== PPIR === class user.Config { key: string } +class user.Config$stream { + key: string | null +} class user.llm.Response { text: string } +class user.llm.Response$stream { + text: string | null +} function user.llm.UseConfig(cfg: root.Config) -> user.llm.Response [expr] { { } user.llm.Response { text: cfg.key } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/namespaces_shadow/baml_tests__compiles__namespaces_shadow__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/namespaces_shadow/baml_tests__compiles__namespaces_shadow__03_hir.snap deleted file mode 100644 index 2e31e689941..00000000000 --- a/baml_language/crates/baml_tests/snapshots/compiles/namespaces_shadow/baml_tests__compiles__namespaces_shadow__03_hir.snap +++ /dev/null @@ -1,10 +0,0 @@ ---- -source: crates/baml_tests/src/generated_tests.rs ---- -=== HIR2 === -class user.foo { - x: int -} -class user.foo.Bar { - y: string -} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/namespaces_shadow/baml_tests__compiles__namespaces_shadow__03_ppir.snap b/baml_language/crates/baml_tests/snapshots/compiles/namespaces_shadow/baml_tests__compiles__namespaces_shadow__03_ppir.snap new file mode 100644 index 00000000000..3ca939a3312 --- /dev/null +++ b/baml_language/crates/baml_tests/snapshots/compiles/namespaces_shadow/baml_tests__compiles__namespaces_shadow__03_ppir.snap @@ -0,0 +1,17 @@ +--- +source: crates/baml_tests/src/generated_tests.rs +assertion_line: 21998 +--- +=== PPIR === +class user.foo { + x: int +} +class user.foo$stream { + x: int | null +} +class user.foo.Bar { + y: string +} +class user.foo.Bar$stream { + y: string | null +} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/namespaces_type_resolution/baml_tests__compiles__namespaces_type_resolution__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/namespaces_type_resolution/baml_tests__compiles__namespaces_type_resolution__03_ppir.snap similarity index 83% rename from baml_language/crates/baml_tests/snapshots/compiles/namespaces_type_resolution/baml_tests__compiles__namespaces_type_resolution__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/namespaces_type_resolution/baml_tests__compiles__namespaces_type_resolution__03_ppir.snap index e52d358d63e..2edcca87dfd 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/namespaces_type_resolution/baml_tests__compiles__namespaces_type_resolution__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/namespaces_type_resolution/baml_tests__compiles__namespaces_type_resolution__03_ppir.snap @@ -1,19 +1,32 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 22639 --- -=== HIR2 === +=== PPIR === class user.Config { key: string env: string } +class user.Config$stream { + key: string | null + env: string | null +} class user.Error { code: int message: string } +class user.Error$stream { + code: int | null + message: string | null +} class user.RootWithCrossNsAlias { llm_alias: root.llm.ResponseAlias own_alias: user.ConfigAlias } +class user.RootWithCrossNsAlias$stream { + llm_alias: root.llm.Response$stream | null + own_alias: user.Config$stream | null +} class user.RootWithCrossNsFields { own_config: user.Config llm_config: root.llm.Config @@ -23,8 +36,18 @@ class user.RootWithCrossNsFields { own_status: user.Status own_alias: user.ConfigAlias } +class user.RootWithCrossNsFields$stream { + own_config: user.Config$stream | null + llm_config: root.llm.Config$stream | null + auth_config: root.auth.Config$stream | null + llm_response: root.llm.Response$stream | null + nested_client: root.llm.openai.Client$stream | null + own_status: user.Status | null + own_alias: user.Config$stream | null +} enum user.Status {Ok, Failed, Pending} type user.ConfigAlias = user.Config +type user.ConfigAlias$stream = user.Config$stream function user.RootAliasParam(cfg: user.ConfigAlias) -> string [expr] { { } cfg.key } @@ -71,16 +94,29 @@ class user.auth.Config { provider: string secret: string } +class user.auth.Config$stream { + provider: string | null + secret: string | null +} class user.auth.Error { realm: string expired: bool } +class user.auth.Error$stream { + realm: string | null + expired: bool | null +} class user.auth.Token { value: string role: user.auth.Role } +class user.auth.Token$stream { + value: string | null + role: user.auth.Role | null +} enum user.auth.Role {Admin, User, Guest} type user.auth.TokenAlias = user.auth.Token +type user.auth.TokenAlias$stream = user.auth.Token$stream function user.auth.AuthAliasParam(t: user.auth.TokenAlias) -> string [expr] { { } t.value } @@ -142,10 +178,18 @@ class user.llm.Config { model: string temperature: float } +class user.llm.Config$stream { + model: string | null + temperature: float | null +} class user.llm.Error { reason: string retryable: bool } +class user.llm.Error$stream { + reason: string | null + retryable: bool | null +} class user.llm.LlmWithCrossNsFields { own_config: user.llm.Config own_response: user.llm.Response @@ -157,18 +201,39 @@ class user.llm.LlmWithCrossNsFields { own_alias: user.llm.ConfigAlias root_alias: root.ConfigAlias } +class user.llm.LlmWithCrossNsFields$stream { + own_config: user.llm.Config$stream | null + own_response: user.llm.Response$stream | null + root_config: root.Config$stream | null + root_error: root.Error$stream | null + auth_config: root.auth.Config$stream | null + nested_client: root.llm.openai.Client$stream | null + own_status: user.llm.Status | null + own_alias: root.Config$stream | null + root_alias: root.Config$stream | null +} class user.llm.LlmWithRootAlias { root_alias: root.ConfigAlias own_alias: user.llm.ResponseAlias } +class user.llm.LlmWithRootAlias$stream { + root_alias: root.Config$stream | null + own_alias: user.llm.Response$stream | null +} class user.llm.Response { text: string tokens: int } +class user.llm.Response$stream { + text: string | null + tokens: int | null +} enum user.llm.Model {GPT4, Claude} enum user.llm.Status {Ready, Generating, Done} type user.llm.ConfigAlias = user.llm.Config +type user.llm.ConfigAlias$stream = user.llm.Config$stream type user.llm.ResponseAlias = user.llm.Response +type user.llm.ResponseAlias$stream = user.llm.Response$stream function user.llm.LlmAliasParam(cfg: user.llm.ConfigAlias) -> string [expr] { { } cfg.model } @@ -233,10 +298,18 @@ class user.llm.openai.Client { api_key: string org_id: string } +class user.llm.openai.Client$stream { + api_key: string | null + org_id: string | null +} class user.llm.openai.Error { status_code: int body: string } +class user.llm.openai.Error$stream { + status_code: int | null + body: string | null +} enum user.llm.openai.Model {GPT4o, GPT4oMini, O3} function user.llm.openai.OpenAIConstruct(key: string) -> user.llm.openai.Client [expr] { { } user.llm.openai.Client { api_key: key, org_id: "org-123" } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/numeric_invariance_ok/baml_tests__compiles__numeric_invariance_ok__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/numeric_invariance_ok/baml_tests__compiles__numeric_invariance_ok__03_ppir.snap similarity index 86% rename from baml_language/crates/baml_tests/snapshots/compiles/numeric_invariance_ok/baml_tests__compiles__numeric_invariance_ok__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/numeric_invariance_ok/baml_tests__compiles__numeric_invariance_ok__03_ppir.snap index 650b104fe07..52b49a5b83b 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/numeric_invariance_ok/baml_tests__compiles__numeric_invariance_ok__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/numeric_invariance_ok/baml_tests__compiles__numeric_invariance_ok__03_ppir.snap @@ -1,10 +1,14 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 23245 --- -=== HIR2 === +=== PPIR === class user.BigintCounter { count: bigint } +class user.BigintCounter$stream { + count: bigint | null +} function user.BigintFieldOk() -> user.BigintCounter [expr] { { } user.BigintCounter { count: 1n } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/numeric_literal_method_call/baml_tests__compiles__numeric_literal_method_call__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/numeric_literal_method_call/baml_tests__compiles__numeric_literal_method_call__03_ppir.snap similarity index 92% rename from baml_language/crates/baml_tests/snapshots/compiles/numeric_literal_method_call/baml_tests__compiles__numeric_literal_method_call__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/numeric_literal_method_call/baml_tests__compiles__numeric_literal_method_call__03_ppir.snap index bb6e9c1d57c..973ed39511f 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/numeric_literal_method_call/baml_tests__compiles__numeric_literal_method_call__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/numeric_literal_method_call/baml_tests__compiles__numeric_literal_method_call__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 23600 --- -=== HIR2 === +=== PPIR === function user.BigintToStringBareLiteral() -> string [expr] { { } 42n.to_string() } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/o1_allowed_roles/baml_tests__compiles__o1_allowed_roles__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/o1_allowed_roles/baml_tests__compiles__o1_allowed_roles__03_ppir.snap similarity index 98% rename from baml_language/crates/baml_tests/snapshots/compiles/o1_allowed_roles/baml_tests__compiles__o1_allowed_roles__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/o1_allowed_roles/baml_tests__compiles__o1_allowed_roles__03_ppir.snap index 75f939b7792..5e13d376ba5 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/o1_allowed_roles/baml_tests__compiles__o1_allowed_roles__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/o1_allowed_roles/baml_tests__compiles__o1_allowed_roles__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 23957 --- -=== HIR2 === +=== PPIR === function user.Gpt4oClient$new(lenient: bool) -> ? [expr] { baml.llm.PrimitiveClient { name: "Gpt4oClient", provider: "openai", options: baml.llm.PrimitiveClientOptions { model: "gpt-4o", base_url: null, allowed_role_metadata: null, finish_reason_allow_list: null, finish_reason_deny_list: null, supports_streaming: null, default_role: null, allowed_roles: null, remap_roles: null, api_key: "sk-test", provider_options: null, media_url_handler: null, headers: map { }, query_params: map { }, request_body: map { } } } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/optional_function_parameters/baml_tests__compiles__optional_function_parameters__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/optional_function_parameters/baml_tests__compiles__optional_function_parameters__03_ppir.snap similarity index 80% rename from baml_language/crates/baml_tests/snapshots/compiles/optional_function_parameters/baml_tests__compiles__optional_function_parameters__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/optional_function_parameters/baml_tests__compiles__optional_function_parameters__03_ppir.snap index 88025e6a313..53b045d4af9 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/optional_function_parameters/baml_tests__compiles__optional_function_parameters__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/optional_function_parameters/baml_tests__compiles__optional_function_parameters__03_ppir.snap @@ -1,12 +1,18 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 24305 --- -=== HIR2 === +=== PPIR === class user.SearchService { base: string } +class user.SearchService$stream { + base: string | null +} type user.NarrowSearcher = (query: string, filter?: string?) -> string[] throws never +type user.NarrowSearcher$stream = unknown type user.Searcher = (query: string, max_results?: int) -> int throws never +type user.Searcher$stream = unknown function user.AskDocs(query: string, max_results: int = 10, filter: string = DefaultFilter(), client: baml.llm.Client = TestClient) -> string [llm] { baml.llm.call_llm_function(client, "AskDocs", map { "query": query, "max_results": max_results, "filter": filter }) } @@ -16,9 +22,18 @@ function user.AskDocs$build_request(query: string, max_results: int = 10, filter function user.AskDocs$build_request_stream(query: string, max_results: int = 10, filter: string = DefaultFilter(), client: baml.llm.Client = TestClient) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "AskDocs", map { "query": query, "max_results": max_results, "filter": filter }) } +function user.AskDocs$parse(json: string, client: baml.llm.Client = TestClient) -> string [expr] { + baml.llm.parse(json) +} +function user.AskDocs$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = TestClient) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.AskDocs$render_prompt(query: string, max_results: int = 10, filter: string = DefaultFilter(), client: baml.llm.Client = TestClient) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "AskDocs", map { "query": query, "max_results": max_results, "filter": filter }) } +function user.AskDocs$stream(query: string, max_results: int = 10, filter: string = DefaultFilter(), client: baml.llm.Client = TestClient) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "AskDocs", map { "query": query, "max_results": max_results, "filter": filter }) +} function user.DefaultFilter() -> string [expr] { { } "none" } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/paren_union_test/baml_tests__compiles__paren_union_test__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/paren_union_test/baml_tests__compiles__paren_union_test__03_ppir.snap similarity index 53% rename from baml_language/crates/baml_tests/snapshots/compiles/paren_union_test/baml_tests__compiles__paren_union_test__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/paren_union_test/baml_tests__compiles__paren_union_test__03_ppir.snap index 998806a9d8c..3b342338381 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/paren_union_test/baml_tests__compiles__paren_union_test__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/paren_union_test/baml_tests__compiles__paren_union_test__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 24652 --- -=== HIR2 === +=== PPIR === class user.Union { u: user.Union | user.Union | user.Union | user.Union u_arr: user.Union | user.Union | user.Union | user.Union[] @@ -26,3 +27,27 @@ class user.Union { arr_opt_arr_fun_opt_opt_opt_arr_arr_opt_arr: (user.Union | user.Union[]?[] | user.Union | user.Union) -> user.Union | user.Union[]?[] | user.Union | user.Union throws never???[][]?[] opt_arr_opt_fun_opt_opt_opt_arr_arr_opt_arr: (user.Union | user.Union?[]? | user.Union | user.Union) -> user.Union | user.Union?[]? | user.Union | user.Union throws never???[][]?[] } +class user.Union$stream { + u: user.Union$stream | user.Union$stream | user.Union$stream | user.Union$stream | null + u_arr: user.Union$stream | user.Union$stream | user.Union$stream | user.Union$stream[] + u_arr_arr: user.Union$stream | user.Union$stream[][] + u_arr_arr_arr: user.Union$stream | user.Union$stream[][][] + u_opt_arr: user.Union$stream | user.Union$stream | user.Union$stream | user.Union$stream | null[] + u_arr_opt: user.Union$stream | user.Union$stream | user.Union$stream | user.Union$stream[] | null + u_arr_opt_arr: user.Union$stream | user.Union$stream | user.Union$stream | user.Union$stream[] | null[] + u_opt_arr_opt: user.Union$stream | user.Union$stream | user.Union$stream | user.Union$stream | null[] | null + u_opt_arr_arr_opt_arr_arr: user.Union$stream | user.Union$stream | user.Union$stream | user.Union$stream | null[][] | null[][] + u_arr_opt_opt_arr_opt_opt: user.Union$stream | user.Union$stream | user.Union$stream | user.Union$stream[] | null | null[] | null | null + u_arr_arr_arr_opt_arr_arr_opt_opt_opt: user.Union$stream | user.Union$stream | user.Union$stream | user.Union$stream[][][] | null[][] | null | null | null + u_opt_opt_opt_arr_opt_opt_arr_arr_arr: user.Union$stream | user.Union$stream | user.Union$stream | user.Union$stream | null | null | null[] | null | null[][][] + arr_opt_arr_u_arr_arr_arr_opt_opt_arr: user.Union$stream | user.Union$stream[] | null[] | user.Union$stream | user.Union$stream[][][] | null | null[] + opt_arr_opt_u_arr_arr_arr_opt_opt_arr: user.Union$stream | user.Union$stream | null[] | null | user.Union$stream | user.Union$stream[][][] | null | null[] + fun: unknown + fun_arr: unknown[] + fun_arr_opt: unknown[] | null + fun_opt: unknown | null + fun_opt_arr: unknown | null[] + fun_opt_opt_opt_arr_arr_opt_arr: unknown | null | null | null[][] | null[] + arr_opt_arr_fun_opt_opt_opt_arr_arr_opt_arr: unknown | null | null | null[][] | null[] + opt_arr_opt_fun_opt_opt_opt_arr_arr_opt_arr: unknown | null | null | null[][] | null[] +} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/parser_expressions/baml_tests__compiles__parser_expressions__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/parser_expressions/baml_tests__compiles__parser_expressions__03_ppir.snap similarity index 73% rename from baml_language/crates/baml_tests/snapshots/compiles/parser_expressions/baml_tests__compiles__parser_expressions__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/parser_expressions/baml_tests__compiles__parser_expressions__03_ppir.snap index 81a47e628e6..ac51bccc429 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/parser_expressions/baml_tests__compiles__parser_expressions__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/parser_expressions/baml_tests__compiles__parser_expressions__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 25209 --- -=== HIR2 === +=== PPIR === function user.Calculate() -> int [expr] { { let a = 1 Add 2; let b = a Mul 3; let c = b Div 2 Sub 1; let d = a Add b Mul c; return d } } @@ -9,14 +10,26 @@ class user.Profile { bio: string settings: user.Settings } +class user.Profile$stream { + bio: string | null + settings: user.Settings$stream | null +} class user.Settings { theme: string } +class user.Settings$stream { + theme: string | null +} class user.User { name: string profile: user.Profile tags: string[] } +class user.User$stream { + name: string | null + profile: user.Profile$stream | null + tags: string[] +} function user.FieldAccess(user: user.User) -> string [expr] { { let name = user.name; let bio = user.profile.bio; let theme = user.profile.settings.theme; let firstTag = user.tags[0]; return theme } } @@ -25,6 +38,11 @@ class user.IndexUser { age: int tags: string[] } +class user.IndexUser$stream { + name: string | null + age: int | null + tags: string[] +} function user.IndexAccess(users: user.IndexUser[]) -> string [expr] { { let first = users[0]; let idx = 1; let second = users[idx]; let firstName = users[0].name; let tag = users[0].tags[0]; return firstName } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/parser_statements/baml_tests__compiles__parser_statements__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/parser_statements/baml_tests__compiles__parser_statements__03_ppir.snap similarity index 95% rename from baml_language/crates/baml_tests/snapshots/compiles/parser_statements/baml_tests__compiles__parser_statements__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/parser_statements/baml_tests__compiles__parser_statements__03_ppir.snap index 67c26b41e79..2db2feec5ad 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/parser_statements/baml_tests__compiles__parser_statements__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/parser_statements/baml_tests__compiles__parser_statements__03_ppir.snap @@ -1,10 +1,14 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 26322 --- -=== HIR2 === +=== PPIR === class user.EdgeFoo { x: int } +class user.EdgeFoo$stream { + x: int | null +} function user.add_assign() -> int [expr] { { let x = 10; x Add= 5; return x } } @@ -84,6 +88,10 @@ class user.Point { x: int y: int } +class user.Point$stream { + x: int | null + y: int | null +} function user.let_statements() -> int [expr] { { let x = 1; let y: int = 2; let z: int[] = [1, 2, 3]; let point: user.Point = user.Point { x: 1, y: 2 }; return point.x Add point.y } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/patterns_class_destructure_namespaces/baml_tests__compiles__patterns_class_destructure_namespaces__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/patterns_class_destructure_namespaces/baml_tests__compiles__patterns_class_destructure_namespaces__03_ppir.snap similarity index 93% rename from baml_language/crates/baml_tests/snapshots/compiles/patterns_class_destructure_namespaces/baml_tests__compiles__patterns_class_destructure_namespaces__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/patterns_class_destructure_namespaces/baml_tests__compiles__patterns_class_destructure_namespaces__03_ppir.snap index c5481096732..265b2e05757 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/patterns_class_destructure_namespaces/baml_tests__compiles__patterns_class_destructure_namespaces__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/patterns_class_destructure_namespaces/baml_tests__compiles__patterns_class_destructure_namespaces__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 27402 --- -=== HIR2 === +=== PPIR === function user.DeepGenericDestructureNamespaceQualifiedLet() -> int [expr] { { let outer: llm.openai.Outer = llm.openai.Outer { inner: llm.openai.Box { value: "done" } }; let llm.openai.Outer { inner: llm.openai.Box { value: value } } = outer } value.length() } @@ -47,13 +48,23 @@ function user.TypePatternQualifiedMatch() -> int [expr] { class user.llm.openai.Box { value: T } +class user.llm.openai.Box$stream { + value: T | null +} class user.llm.openai.Outer { inner: user.llm.openai.Box } +class user.llm.openai.Outer$stream { + inner: user.llm.openai.Box$stream | null +} class user.llm.openai.Response { text: string score: int } +class user.llm.openai.Response$stream { + text: string | null + score: int | null +} function user.llm.openai.DestructureBareInNamespace(response: user.llm.openai.Response) -> int [expr] { { let Response { score: score } = response } score } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/patterns_new/baml_tests__compiles__patterns_new__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/patterns_new/baml_tests__compiles__patterns_new__03_ppir.snap similarity index 95% rename from baml_language/crates/baml_tests/snapshots/compiles/patterns_new/baml_tests__compiles__patterns_new__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/patterns_new/baml_tests__compiles__patterns_new__03_ppir.snap index f7931d63d5a..a2f61bdceaf 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/patterns_new/baml_tests__compiles__patterns_new__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/patterns_new/baml_tests__compiles__patterns_new__03_ppir.snap @@ -1,17 +1,28 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 27840 --- -=== HIR2 === +=== PPIR === class user.AppError { code: int } +class user.AppError$stream { + code: int | null +} class user.PatternBucket { values: int[] } +class user.PatternBucket$stream { + values: int[] +} class user.PatternMatrix { rows: int[][] } +class user.PatternMatrix$stream { + rows: int[][] +} type user.Number = int | float +type user.Number$stream = int | float function user.bare_type_arm(v: int | string) -> int [expr] { { } match (v) { int => 1, string => 2 } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/reflect_type_of_user_generic/baml_tests__compiles__reflect_type_of_user_generic__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/reflect_type_of_user_generic/baml_tests__compiles__reflect_type_of_user_generic__03_ppir.snap similarity index 82% rename from baml_language/crates/baml_tests/snapshots/compiles/reflect_type_of_user_generic/baml_tests__compiles__reflect_type_of_user_generic__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/reflect_type_of_user_generic/baml_tests__compiles__reflect_type_of_user_generic__03_ppir.snap index 4a00e48d58a..f4c3a1df8a6 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/reflect_type_of_user_generic/baml_tests__compiles__reflect_type_of_user_generic__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/reflect_type_of_user_generic/baml_tests__compiles__reflect_type_of_user_generic__03_ppir.snap @@ -1,10 +1,14 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 28188 --- -=== HIR2 === +=== PPIR === class user.Person { name: string } +class user.Person$stream { + name: string | null +} function user.reflect_array() -> type [expr] { { } reflect.type_of() } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/retry_policy/baml_tests__compiles__retry_policy__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/retry_policy/baml_tests__compiles__retry_policy__03_ppir.snap similarity index 94% rename from baml_language/crates/baml_tests/snapshots/compiles/retry_policy/baml_tests__compiles__retry_policy__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/retry_policy/baml_tests__compiles__retry_policy__03_ppir.snap index 9c444ab5311..ba098be4eae 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/retry_policy/baml_tests__compiles__retry_policy__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/retry_policy/baml_tests__compiles__retry_policy__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 28535 --- -=== HIR2 === +=== PPIR === function user.MyClient$new(lenient: bool) -> ? [expr] { baml.llm.PrimitiveClient { name: "MyClient", provider: "openai", options: baml.llm.PrimitiveClientOptions { model: "gpt-4", base_url: null, allowed_role_metadata: null, finish_reason_allow_list: null, finish_reason_deny_list: null, supports_streaming: null, default_role: null, allowed_roles: null, remap_roles: null, api_key: null, provider_options: null, media_url_handler: null, headers: map { }, query_params: map { }, request_body: map { } } } } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/scientific_notation_float/baml_tests__compiles__scientific_notation_float__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/scientific_notation_float/baml_tests__compiles__scientific_notation_float__03_ppir.snap similarity index 93% rename from baml_language/crates/baml_tests/snapshots/compiles/scientific_notation_float/baml_tests__compiles__scientific_notation_float__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/scientific_notation_float/baml_tests__compiles__scientific_notation_float__03_ppir.snap index 7804764cd8d..85d27fa3a62 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/scientific_notation_float/baml_tests__compiles__scientific_notation_float__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/scientific_notation_float/baml_tests__compiles__scientific_notation_float__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 28883 --- -=== HIR2 === +=== PPIR === function user.DecimalMantissa() -> float [expr] { { } 1.5e3 } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/stream_crossfile/baml_tests__compiles__stream_crossfile__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/stream_crossfile/baml_tests__compiles__stream_crossfile__03_hir.snap deleted file mode 100644 index 7eece91de5a..00000000000 --- a/baml_language/crates/baml_tests/snapshots/compiles/stream_crossfile/baml_tests__compiles__stream_crossfile__03_hir.snap +++ /dev/null @@ -1,17 +0,0 @@ ---- -source: crates/baml_tests/src/generated_tests.rs ---- -=== HIR2 === -class user.Education { - school: string - degree: user.Degree - year: int -} -enum user.Degree {Bachelors, Masters, PhD} -type user.EducationList = user.Education[] -class user.Resume { - name: string - education: Education[] - highest_degree: Degree - aliases: EducationList -} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/stream_crossfile/baml_tests__compiles__stream_crossfile__03_ppir.snap b/baml_language/crates/baml_tests/snapshots/compiles/stream_crossfile/baml_tests__compiles__stream_crossfile__03_ppir.snap new file mode 100644 index 00000000000..9d847cdd2f1 --- /dev/null +++ b/baml_language/crates/baml_tests/snapshots/compiles/stream_crossfile/baml_tests__compiles__stream_crossfile__03_ppir.snap @@ -0,0 +1,30 @@ +--- +source: crates/baml_tests/src/generated_tests.rs +assertion_line: 29309 +--- +=== PPIR === +class user.Education { + school: string + degree: user.Degree + year: int +} +class user.Education$stream { + school: string | null + degree: user.Degree | null + year: int | null +} +enum user.Degree {Bachelors, Masters, PhD} +type user.EducationList = user.Education[] +type user.EducationList$stream = user.Education$stream[] +class user.Resume { + name: string + education: Education[] + highest_degree: Degree + aliases: EducationList +} +class user.Resume$stream { + name: string | null + education: Education$stream[] + highest_degree: Degree | null + aliases: Education$stream[] +} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/stream_llm_inferred_typeargs/baml_tests__compiles__stream_llm_inferred_typeargs__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/stream_llm_inferred_typeargs/baml_tests__compiles__stream_llm_inferred_typeargs__03_ppir.snap similarity index 73% rename from baml_language/crates/baml_tests/snapshots/compiles/stream_llm_inferred_typeargs/baml_tests__compiles__stream_llm_inferred_typeargs__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/stream_llm_inferred_typeargs/baml_tests__compiles__stream_llm_inferred_typeargs__03_ppir.snap index e93e4d6244a..8bd5a72b0f1 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/stream_llm_inferred_typeargs/baml_tests__compiles__stream_llm_inferred_typeargs__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/stream_llm_inferred_typeargs/baml_tests__compiles__stream_llm_inferred_typeargs__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 29739 --- -=== HIR2 === +=== PPIR === function user.TestClient$new(lenient: bool) -> ? [expr] { baml.llm.PrimitiveClient { name: "TestClient", provider: "openai", options: baml.llm.PrimitiveClientOptions { model: "gpt-4o-mini", base_url: "http://localhost:...", allowed_role_metadata: null, finish_reason_allow_list: null, finish_reason_deny_list: null, supports_streaming: null, default_role: null, allowed_roles: null, remap_roles: null, api_key: "test-key", provider_options: null, media_url_handler: null, headers: map { }, query_params: map { }, request_body: map { } } } } @@ -14,9 +15,18 @@ function user.TestFunc$build_request(input: string, client: baml.llm.Client = Te function user.TestFunc$build_request_stream(input: string, client: baml.llm.Client = TestClient) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "TestFunc", map { "input": input }) } +function user.TestFunc$parse(json: string, client: baml.llm.Client = TestClient) -> string [expr] { + baml.llm.parse(json) +} +function user.TestFunc$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = TestClient) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.TestFunc$render_prompt(input: string, client: baml.llm.Client = TestClient) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "TestFunc", map { "input": input }) } +function user.TestFunc$stream(input: string, client: baml.llm.Client = TestClient) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "TestFunc", map { "input": input }) +} function user.call_stream_inferred() -> baml.llm.Stream [expr] { { } baml.llm.stream_llm_function(TestClient, "TestFunc", map { "input": "world" }) } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/top_level_let/baml_tests__compiles__top_level_let__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/string_methods/baml_tests__compiles__string_methods__03_ppir.snap similarity index 61% rename from baml_language/crates/baml_tests/snapshots/compiles/top_level_let/baml_tests__compiles__top_level_let__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/string_methods/baml_tests__compiles__string_methods__03_ppir.snap index b31d48dad7b..1e012669a07 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/top_level_let/baml_tests__compiles__top_level_let__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/string_methods/baml_tests__compiles__string_methods__03_ppir.snap @@ -1,4 +1,5 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 30086 --- -=== HIR2 === +=== PPIR === diff --git a/baml_language/crates/baml_tests/snapshots/compiles/test_expr_basic/baml_tests__compiles__test_expr_basic__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/test_expr_basic/baml_tests__compiles__test_expr_basic__03_ppir.snap similarity index 91% rename from baml_language/crates/baml_tests/snapshots/compiles/test_expr_basic/baml_tests__compiles__test_expr_basic__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/test_expr_basic/baml_tests__compiles__test_expr_basic__03_ppir.snap index 855a0daa7b8..7eea040267e 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/test_expr_basic/baml_tests__compiles__test_expr_basic__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/test_expr_basic/baml_tests__compiles__test_expr_basic__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 30434 --- -=== HIR2 === +=== PPIR === function user.$init_test_main(registry: testing.TestCollector) -> ? [expr] { { registry.register_test("simple test", () -> void { { let x = 1 Add 2 } assert.equal(x, 3) }, null); registry.register_test("with not_null", () -> void { { let result = "hello" } assert.not_null(result) }, null) } null } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/test_expr_name_concat/baml_tests__compiles__test_expr_name_concat__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/test_expr_name_concat/baml_tests__compiles__test_expr_name_concat__03_ppir.snap similarity index 93% rename from baml_language/crates/baml_tests/snapshots/compiles/test_expr_name_concat/baml_tests__compiles__test_expr_name_concat__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/test_expr_name_concat/baml_tests__compiles__test_expr_name_concat__03_ppir.snap index a6ee3a108bb..1f0b30d2ad4 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/test_expr_name_concat/baml_tests__compiles__test_expr_name_concat__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/test_expr_name_concat/baml_tests__compiles__test_expr_name_concat__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 30781 --- -=== HIR2 === +=== PPIR === function user.$init_test_main(registry: testing.TestCollector) -> ? [expr] { { registry.register_test_set("concat names", (testset: testing.TestCollector) -> void { { testset.register_test("prefix_" Add "suffix", () -> { { } null }, null); testset.register_test_set("nested_" Add "group", (testset: testing.TestCollector) -> { { testset.register_test("inner", () -> { { } null }, null) } null }, null) } null }, null) } null } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/test_expr_throwing_body/baml_tests__compiles__test_expr_throwing_body__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/test_expr_throwing_body/baml_tests__compiles__test_expr_throwing_body__03_ppir.snap similarity index 89% rename from baml_language/crates/baml_tests/snapshots/compiles/test_expr_throwing_body/baml_tests__compiles__test_expr_throwing_body__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/test_expr_throwing_body/baml_tests__compiles__test_expr_throwing_body__03_ppir.snap index 4a98d2cf7f5..808d5da5993 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/test_expr_throwing_body/baml_tests__compiles__test_expr_throwing_body__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/test_expr_throwing_body/baml_tests__compiles__test_expr_throwing_body__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 31128 --- -=== HIR2 === +=== PPIR === function user.$init_test_main(registry: testing.TestCollector) -> ? [expr] { { registry.register_test("throwing body bec...", () -> void { { } risky() }, null) } null } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/test_expr_with_runner/baml_tests__compiles__test_expr_with_runner__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/test_expr_with_runner/baml_tests__compiles__test_expr_with_runner__03_ppir.snap similarity index 88% rename from baml_language/crates/baml_tests/snapshots/compiles/test_expr_with_runner/baml_tests__compiles__test_expr_with_runner__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/test_expr_with_runner/baml_tests__compiles__test_expr_with_runner__03_ppir.snap index eda436d03af..ba4388735c4 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/test_expr_with_runner/baml_tests__compiles__test_expr_with_runner__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/test_expr_with_runner/baml_tests__compiles__test_expr_with_runner__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 31475 --- -=== HIR2 === +=== PPIR === function user.$init_test_main(registry: testing.TestCollector) -> ? [expr] { { registry.register_test("with quorum", () -> void { { let result = "hello" } assert.not_null(result) }, testing.Quorum(5, 3)) } null } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/test_old_and_new/baml_tests__compiles__test_old_and_new__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/test_old_and_new/baml_tests__compiles__test_old_and_new__03_ppir.snap similarity index 90% rename from baml_language/crates/baml_tests/snapshots/compiles/test_old_and_new/baml_tests__compiles__test_old_and_new__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/test_old_and_new/baml_tests__compiles__test_old_and_new__03_ppir.snap index 8b279a2a01a..160d996090e 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/test_old_and_new/baml_tests__compiles__test_old_and_new__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/test_old_and_new/baml_tests__compiles__test_old_and_new__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 31822 --- -=== HIR2 === +=== PPIR === function user.$init_test_main(registry: testing.TestCollector) -> ? [expr] { { registry.register_test("new style", () -> void { { let result = "hello" } assert.not_null(result) }, null) } null } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/test_raw_string_name/baml_tests__compiles__test_raw_string_name__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/test_raw_string_name/baml_tests__compiles__test_raw_string_name__03_ppir.snap similarity index 93% rename from baml_language/crates/baml_tests/snapshots/compiles/test_raw_string_name/baml_tests__compiles__test_raw_string_name__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/test_raw_string_name/baml_tests__compiles__test_raw_string_name__03_ppir.snap index 968c3c76f8c..be3d5baf3ac 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/test_raw_string_name/baml_tests__compiles__test_raw_string_name__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/test_raw_string_name/baml_tests__compiles__test_raw_string_name__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 32169 --- -=== HIR2 === +=== PPIR === function user.$init_test_main(registry: testing.TestCollector) -> ? [expr] { { registry.register_test("raw string name", () -> void { { } assert.is_true(true) }, null); registry.register_test("has \"quotes\" inside", () -> void { { } assert.is_true(true) }, null); registry.register_test_set("raw testset name", (testset: testing.TestCollector) -> void { { testset.register_test("nested raw name", () -> { { } assert.is_true(true) }, null) } null }, null) } null } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/test_with_not_keyword/baml_tests__compiles__test_with_not_keyword__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/test_with_not_keyword/baml_tests__compiles__test_with_not_keyword__03_ppir.snap similarity index 79% rename from baml_language/crates/baml_tests/snapshots/compiles/test_with_not_keyword/baml_tests__compiles__test_with_not_keyword__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/test_with_not_keyword/baml_tests__compiles__test_with_not_keyword__03_ppir.snap index 2a275d7361d..7e4f5176080 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/test_with_not_keyword/baml_tests__compiles__test_with_not_keyword__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/test_with_not_keyword/baml_tests__compiles__test_with_not_keyword__03_ppir.snap @@ -1,13 +1,20 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 32516 --- -=== HIR2 === +=== PPIR === class user.Foo { x: int } +class user.Foo$stream { + x: int | null +} class user.HasWith { with: int } +class user.HasWith$stream { + with: int | null +} function user.$init_test_main(registry: testing.TestCollector) -> ? [expr] { { registry.register_test("with as field", () -> void { { let h = user.HasWith { with: 1 } } assert.equal(h.with, 1) }, null) } null } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/testset_basic/baml_tests__compiles__testset_basic__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/testset_basic/baml_tests__compiles__testset_basic__03_ppir.snap similarity index 91% rename from baml_language/crates/baml_tests/snapshots/compiles/testset_basic/baml_tests__compiles__testset_basic__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/testset_basic/baml_tests__compiles__testset_basic__03_ppir.snap index c3940f42208..94cfd2421ea 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/testset_basic/baml_tests__compiles__testset_basic__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/testset_basic/baml_tests__compiles__testset_basic__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 32863 --- -=== HIR2 === +=== PPIR === function user.$init_test_main(registry: testing.TestCollector) -> ? [expr] { { registry.register_test_set("basic group", (testset: testing.TestCollector) -> void { { testset.register_test("first", () -> { { } assert.is_true(true) }, null); testset.register_test("second", () -> { { } assert.is_true(true) }, null) } null }, null) } null } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/testset_dynamic/baml_tests__compiles__testset_dynamic__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/testset_dynamic/baml_tests__compiles__testset_dynamic__03_ppir.snap similarity index 95% rename from baml_language/crates/baml_tests/snapshots/compiles/testset_dynamic/baml_tests__compiles__testset_dynamic__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/testset_dynamic/baml_tests__compiles__testset_dynamic__03_ppir.snap index 3ecee451e4c..49ea8c0cbbf 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/testset_dynamic/baml_tests__compiles__testset_dynamic__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/testset_dynamic/baml_tests__compiles__testset_dynamic__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 33210 --- -=== HIR2 === +=== PPIR === function user.$init_test_main(registry: testing.TestCollector) -> ? [expr] { { registry.register_test_set("dynamic tests", (testset: testing.TestCollector) -> void { { let cases = ["hello", "world", "foo"]; for case in cases { testset.register_test("check case", () -> { { } assert.not_null(case) }, null) } } null }, null); registry.register_test_set("conditional tests", (testset: testing.TestCollector) -> void { { { let run_slow = false; testset.register_test("always runs", () -> { { } assert.is_true(true) }, null) } if (run_slow) { testset.register_test("only when slow", () -> { { } assert.is_true(true) }, null) } } null }, null) } null } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/testset_nested/baml_tests__compiles__testset_nested__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/testset_nested/baml_tests__compiles__testset_nested__03_ppir.snap similarity index 94% rename from baml_language/crates/baml_tests/snapshots/compiles/testset_nested/baml_tests__compiles__testset_nested__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/testset_nested/baml_tests__compiles__testset_nested__03_ppir.snap index 159ed8a84fe..d1fa039c775 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/testset_nested/baml_tests__compiles__testset_nested__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/testset_nested/baml_tests__compiles__testset_nested__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 33557 --- -=== HIR2 === +=== PPIR === function user.$init_test_main(registry: testing.TestCollector) -> ? [expr] { { registry.register_test_set("all evals", (testset: testing.TestCollector) -> void { { testset.register_test_set("normal cases", (testset: testing.TestCollector) -> { { testset.register_test("case one", () -> { { } assert.is_true(true) }, null) } null }, null); testset.register_test_set("hard cases", (testset: testing.TestCollector) -> { { testset.register_test("case two", () -> { { } assert.is_true(true) }, null) } null }, null) } null }, null) } null } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/testset_vibes_nested/baml_tests__compiles__testset_vibes_nested__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/testset_vibes_nested/baml_tests__compiles__testset_vibes_nested__03_ppir.snap similarity index 71% rename from baml_language/crates/baml_tests/snapshots/compiles/testset_vibes_nested/baml_tests__compiles__testset_vibes_nested__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/testset_vibes_nested/baml_tests__compiles__testset_vibes_nested__03_ppir.snap index 01c4712629d..d0722011293 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/testset_vibes_nested/baml_tests__compiles__testset_vibes_nested__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/testset_vibes_nested/baml_tests__compiles__testset_vibes_nested__03_ppir.snap @@ -1,12 +1,18 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 33904 --- -=== HIR2 === +=== PPIR === class user.Sentiment { feeling: string confidence: float reasoning: string } +class user.Sentiment$stream { + feeling: string | null + confidence: float | null + reasoning: string | null +} function user.$init_test_main(registry: testing.TestCollector) -> ? [expr] { { registry.register_test_set("test", (testset: testing.TestCollector) -> void { { let topics = ["happy", "sad"]; for sentiments in topics { testset.register_test_set(sentiments, (testset: testing.TestCollector) -> { { let req = baml.http.fetch("http://localhost:..." Add sentiments); let data = req.text(); let tests = GenerateTests$parse(data); for ex in tests { testset.register_test(ex, () -> { { let result = ClassifySentiment("hi"); assert.equal(result.feeling, "positive") } }, null) } } null }, null) }; testset.register_test_set("vibes", (testset: testing.TestCollector) -> { { let topics = ["happy", "sad"]; for sentiments in topics { testset.register_test_set(sentiments, (testset: testing.TestCollector) -> { { let tests = GenerateTests(5, sentiments); for ex in tests { testset.register_test(ex, () -> { { let result = ClassifySentiment("hi"); assert.equal(result.feeling, "positive") } }, null) } } null }, null) } } null }, null) } null }, null) } null } @@ -19,9 +25,18 @@ function user.ClassifySentiment$build_request(text: string, client: baml.llm.Cli function user.ClassifySentiment$build_request_stream(text: string, client: baml.llm.Client = GPT4o) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "ClassifySentiment", map { "text": text }) } +function user.ClassifySentiment$parse(json: string, client: baml.llm.Client = GPT4o) -> user.Sentiment [expr] { + baml.llm.parse(json) +} +function user.ClassifySentiment$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = GPT4o) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.ClassifySentiment$render_prompt(text: string, client: baml.llm.Client = GPT4o) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "ClassifySentiment", map { "text": text }) } +function user.ClassifySentiment$stream(text: string, client: baml.llm.Client = GPT4o) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "ClassifySentiment", map { "text": text }) +} function user.ClassifySentiment2(text: string, client: baml.llm.Client = GPT4o) -> string [llm] { baml.llm.call_llm_function(client, "ClassifySentiment2", map { "text": text }) } @@ -31,9 +46,18 @@ function user.ClassifySentiment2$build_request(text: string, client: baml.llm.Cl function user.ClassifySentiment2$build_request_stream(text: string, client: baml.llm.Client = GPT4o) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "ClassifySentiment2", map { "text": text }) } +function user.ClassifySentiment2$parse(json: string, client: baml.llm.Client = GPT4o) -> string [expr] { + baml.llm.parse(json) +} +function user.ClassifySentiment2$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = GPT4o) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.ClassifySentiment2$render_prompt(text: string, client: baml.llm.Client = GPT4o) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "ClassifySentiment2", map { "text": text }) } +function user.ClassifySentiment2$stream(text: string, client: baml.llm.Client = GPT4o) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "ClassifySentiment2", map { "text": text }) +} function user.Foo() -> string | image [expr] { { let x = "foo"; let y = 2; { let i = 0; while i Lt y { x = "hi: " Add x } } } x } @@ -49,9 +73,18 @@ function user.GenerateTests$build_request(count: int, topic: string, client: bam function user.GenerateTests$build_request_stream(count: int, topic: string, client: baml.llm.Client = GPT4o) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "GenerateTests", map { "count": count, "topic": topic }) } +function user.GenerateTests$parse(json: string, client: baml.llm.Client = GPT4o) -> string[] [expr] { + baml.llm.parse(json) +} +function user.GenerateTests$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = GPT4o) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.GenerateTests$render_prompt(count: int, topic: string, client: baml.llm.Client = GPT4o) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "GenerateTests", map { "count": count, "topic": topic }) } +function user.GenerateTests$stream(count: int, topic: string, client: baml.llm.Client = GPT4o) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "GenerateTests", map { "count": count, "topic": topic }) +} --- captures --- lambda (testset) in ?: captures [sentiments] diff --git a/baml_language/crates/baml_tests/snapshots/compiles/testset_with_setup/baml_tests__compiles__testset_with_setup__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/testset_with_setup/baml_tests__compiles__testset_with_setup__03_ppir.snap similarity index 94% rename from baml_language/crates/baml_tests/snapshots/compiles/testset_with_setup/baml_tests__compiles__testset_with_setup__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/testset_with_setup/baml_tests__compiles__testset_with_setup__03_ppir.snap index 2be384b35a6..b444afa1d63 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/testset_with_setup/baml_tests__compiles__testset_with_setup__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/testset_with_setup/baml_tests__compiles__testset_with_setup__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 34251 --- -=== HIR2 === +=== PPIR === function user.$init_test_main(registry: testing.TestCollector) -> ? [expr] { { registry.register_test_set("with shared setup", (testset: testing.TestCollector) -> void { { let base_url = "https://api.examp..."; let timeout = 5000; testset.register_test("uses setup vars", () -> { { assert.not_null(base_url) } assert.equal(timeout, 5000) }, null); testset.register_test("also uses setup", () -> { { } assert.contains(base_url, "example") }, null) } null }, null) } null } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/top_level_header_comment/baml_tests__compiles__top_level_header_comment__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/top_level_header_comment/baml_tests__compiles__top_level_header_comment__03_ppir.snap similarity index 75% rename from baml_language/crates/baml_tests/snapshots/compiles/top_level_header_comment/baml_tests__compiles__top_level_header_comment__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/top_level_header_comment/baml_tests__compiles__top_level_header_comment__03_ppir.snap index eaaea722f38..c8b3230d0fc 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/top_level_header_comment/baml_tests__compiles__top_level_header_comment__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/top_level_header_comment/baml_tests__compiles__top_level_header_comment__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 34598 --- -=== HIR2 === +=== PPIR === function user.Foo() -> int [expr] { { } 1 } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/string_methods/baml_tests__compiles__string_methods__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/top_level_let/baml_tests__compiles__top_level_let__03_ppir.snap similarity index 61% rename from baml_language/crates/baml_tests/snapshots/compiles/string_methods/baml_tests__compiles__string_methods__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/top_level_let/baml_tests__compiles__top_level_let__03_ppir.snap index b31d48dad7b..82f4fa7e305 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/string_methods/baml_tests__compiles__string_methods__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/top_level_let/baml_tests__compiles__top_level_let__03_ppir.snap @@ -1,4 +1,5 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 34945 --- -=== HIR2 === +=== PPIR === diff --git a/baml_language/crates/baml_tests/snapshots/compiles/type_annotation/baml_tests__compiles__type_annotation__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/type_annotation/baml_tests__compiles__type_annotation__03_ppir.snap similarity index 81% rename from baml_language/crates/baml_tests/snapshots/compiles/type_annotation/baml_tests__compiles__type_annotation__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/type_annotation/baml_tests__compiles__type_annotation__03_ppir.snap index 892a75ec7ba..1db717ff152 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/type_annotation/baml_tests__compiles__type_annotation__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/type_annotation/baml_tests__compiles__type_annotation__03_ppir.snap @@ -1,20 +1,31 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 35502 --- -=== HIR2 === +=== PPIR === type user.MetaAlias = type +type user.MetaAlias$stream = unknown type user.MetaList = type[] +type user.MetaList$stream = unknown[] type user.MetaUnion = type | string +type user.MetaUnion$stream = unknown | string function user.test_type_annotation(function_name: string) -> string [expr] { { let t: type = baml.llm.get_return_type(function_name); return "ok" } } class user.MetaField { type: type } +class user.MetaField$stream { + type: unknown +} class user.RiskFactor { type: string severity: float } +class user.RiskFactor$stream { + type: string | null + severity: float | null +} enum user.Kind {type, other} function user.test_let_binding(function_name: string) -> string [expr] { { let t: type = baml.llm.get_return_type(function_name); return "ok" } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/type_builder_errors/baml_tests__compiles__type_builder_errors__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/type_builder_errors/baml_tests__compiles__type_builder_errors__03_ppir.snap similarity index 58% rename from baml_language/crates/baml_tests/snapshots/compiles/type_builder_errors/baml_tests__compiles__type_builder_errors__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/type_builder_errors/baml_tests__compiles__type_builder_errors__03_ppir.snap index 7b193a1803a..e328e99c96f 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/type_builder_errors/baml_tests__compiles__type_builder_errors__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/type_builder_errors/baml_tests__compiles__type_builder_errors__03_ppir.snap @@ -1,10 +1,14 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 36112 --- -=== HIR2 === +=== PPIR === class user.Resume { name: string } +class user.Resume$stream { + name: string | null +} function user.TypeBuilderFn(from_text: string, client: baml.llm.Client = ...) -> user.Resume [llm] { baml.llm.call_llm_function(client, "TypeBuilderFn", map { "from_text": from_text }) } @@ -14,6 +18,15 @@ function user.TypeBuilderFn$build_request(from_text: string, client: baml.llm.Cl function user.TypeBuilderFn$build_request_stream(from_text: string, client: baml.llm.Client = ...) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "TypeBuilderFn", map { "from_text": from_text }) } +function user.TypeBuilderFn$parse(json: string, client: baml.llm.Client = ...) -> user.Resume [expr] { + baml.llm.parse(json) +} +function user.TypeBuilderFn$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = ...) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.TypeBuilderFn$render_prompt(from_text: string, client: baml.llm.Client = ...) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "TypeBuilderFn", map { "from_text": from_text }) } +function user.TypeBuilderFn$stream(from_text: string, client: baml.llm.Client = ...) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "TypeBuilderFn", map { "from_text": from_text }) +} diff --git a/baml_language/crates/baml_tests/snapshots/compiles/type_builder_test/baml_tests__compiles__type_builder_test__03_hir.snap b/baml_language/crates/baml_tests/snapshots/compiles/type_builder_test/baml_tests__compiles__type_builder_test__03_ppir.snap similarity index 56% rename from baml_language/crates/baml_tests/snapshots/compiles/type_builder_test/baml_tests__compiles__type_builder_test__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/compiles/type_builder_test/baml_tests__compiles__type_builder_test__03_ppir.snap index 71b3d3ee74d..e35d7ffcf78 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/type_builder_test/baml_tests__compiles__type_builder_test__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/type_builder_test/baml_tests__compiles__type_builder_test__03_ppir.snap @@ -1,10 +1,14 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 36459 --- -=== HIR2 === +=== PPIR === class user.TopLevelClass { a: string } +class user.TopLevelClass$stream { + a: string | null +} enum user.TopLevelEnum {A, B} function user.Fn(client: baml.llm.Client = ...) -> string [llm] { baml.llm.call_llm_function(client, "Fn", map { }) @@ -15,6 +19,15 @@ function user.Fn$build_request(client: baml.llm.Client = ...) -> baml.http.Reque function user.Fn$build_request_stream(client: baml.llm.Client = ...) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "Fn", map { }) } +function user.Fn$parse(json: string, client: baml.llm.Client = ...) -> string [expr] { + baml.llm.parse(json) +} +function user.Fn$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = ...) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.Fn$render_prompt(client: baml.llm.Client = ...) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "Fn", map { }) } +function user.Fn$stream(client: baml.llm.Client = ...) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "Fn", map { }) +} diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/anyfunction/baml_tests__diagnostic_errors__anyfunction__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/anyfunction/baml_tests__diagnostic_errors__anyfunction__03_ppir.snap similarity index 78% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/anyfunction/baml_tests__diagnostic_errors__anyfunction__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/anyfunction/baml_tests__diagnostic_errors__anyfunction__03_ppir.snap index 6859f18c641..33819d96b2e 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/anyfunction/baml_tests__diagnostic_errors__anyfunction__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/anyfunction/baml_tests__diagnostic_errors__anyfunction__03_ppir.snap @@ -1,19 +1,31 @@ --- source: crates/baml_tests/src/generated_tests.rs --- -=== HIR2 === +=== PPIR === class user.Doc { title: string } +class user.Doc$stream { + title: string | null +} class user.Holder { f: T } +class user.Holder$stream { + f: T | null +} class user.MyTool { name: string } +class user.MyTool$stream { + name: string | null +} class user.ToolError { message: string } +class user.ToolError$stream { + message: string | null +} function user.main() -> int [expr] { { let bad_ret: baml.AnyFunction = web_search; let bad_throws: baml.AnyFunction = web_search; let not_a_fn: baml.AnyFunction = 42; let narrow: baml.AnyFunction = web_search; let bad_widen: baml.AnyFunction = narrow; return 0 } } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/assignment_expr_position/baml_tests__diagnostic_errors__assignment_expr_position__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/assignment_expr_position/baml_tests__diagnostic_errors__assignment_expr_position__03_ppir.snap similarity index 82% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/assignment_expr_position/baml_tests__diagnostic_errors__assignment_expr_position__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/assignment_expr_position/baml_tests__diagnostic_errors__assignment_expr_position__03_ppir.snap index bcc2c925f9d..c73e3d02487 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/assignment_expr_position/baml_tests__diagnostic_errors__assignment_expr_position__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/assignment_expr_position/baml_tests__diagnostic_errors__assignment_expr_position__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 36809 --- -=== HIR2 === +=== PPIR === function user.assignment_in_expression_position() -> int [expr] { { let x = 10; let y = } y } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/attr_disambiguation/baml_tests__diagnostic_errors__attr_disambiguation__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/attr_disambiguation/baml_tests__diagnostic_errors__attr_disambiguation__03_hir.snap deleted file mode 100644 index 27e8c3848d9..00000000000 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/attr_disambiguation/baml_tests__diagnostic_errors__attr_disambiguation__03_hir.snap +++ /dev/null @@ -1,145 +0,0 @@ ---- -source: crates/baml_tests/src/generated_tests.rs ---- -=== HIR2 === -class user.GAliased { - status: user.GStatus - role: user.GRole - point: user.GPoint - coord: user.GCoord -} -class user.GComplex { - statuses: user.GStatus[] - maybe_status: user.GStatus? - role_or_status: user.GRole | user.GStatus - points: user.GPoint[] - maybe_point: user.GPoint? - config_map: map -} -class user.GConfig { - key: string - value: string -} -class user.GCoord { - lat: float - lng: float -} -class user.GIncident { - severity: user.GSeverity - priority: user.GPriority - title: string - config: user.GConfig -} -class user.GPoint { - x: float - y: float -} -class user.GProfile { - status: user.GStatus - role: user.GRole - name: string - location: user.GPoint - fallback: user.GCoord -} -enum user.GPriority {P0, P1, P2, P3} -enum user.GRole {Admin, User, Guest} -enum user.GSeverity {Low, Medium, High} -enum user.GSize {Small, Medium, Large} -enum user.GStatus {Active, Inactive, Pending} -enum user.GroupF {F1, F2, F3, F4, F5, F6} -class user.MFoo { - x: int -} -class user.OrderingModifiers { - c1: user.MFoo? - c2: user.MFoo? - c3: user.MFoo[] - c4: user.MFoo[] - c5: user.MFoo[]? - c6: map -} -class user.AliasInNestedTypes { - d1: user.NFoo[] - d2: user.NFoo[] - d3: user.NFoo[] - d4: map - d5: map - d6: user.NFoo | user.NBar[] - d7: user.NFoo | user.NBar[] - d8: user.NFoo[] - d9: user.NFoo - d10: map> -} -class user.NBar { - x: int -} -class user.NFoo { - x: int -} -class user.EA { - x: int -} -class user.EB { - x: int -} -class user.EC { - x: int -} -class user.EFoo { - x: int -} -type user.E1 = user.EFoo -type user.E2 = user.EFoo -type user.E3 = user.EFoo -type user.E4 = user.EA | user.EB | user.EC -function user.E5(x: user.EFoo) -> string [expr] { - { } "hello" -} -function user.E6(x: user.EFoo) -> string [expr] { - { } "hello" -} -function user.E7() -> user.EFoo [expr] { - { } user.EFoo { x: 1 } -} -function user.E8() -> user.EFoo [expr] { - { } user.EFoo { x: 1 } -} -class user.Fizz { - x: int -} -class user.OrderingSimple { - a1: user.Fizz - a2: user.Fizz - a3: user.Fizz - a4: user.Fizz - a5: user.Fizz - a6: user.Fizz - a7: user.Fizz - a8: user.Fizz - a9: user.Fizz -} -class user.OrderingUnions { - b1: user.UA | user.UB | user.UC - b2: user.UA | user.UB | user.UC - b3: user.UA | user.UB | user.UC - b4: user.UA | user.UB | user.UC - b5: user.UA | user.UB | user.UC - b6: user.UA | user.UB | user.UC - b7: user.UA | user.UB | user.UC - b8: user.UA | user.UB | user.UC - b9: user.UA | user.UB - b10: user.UA | user.UB - b11: user.UA | user.UB - b12: user.UA | user.UB - b13: user.UA | user.UB - b14: user.UA | user.UB -} -class user.UA { - x: int -} -class user.UB { - x: int -} -class user.UC { - x: int -} diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/attr_disambiguation/baml_tests__diagnostic_errors__attr_disambiguation__03_ppir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/attr_disambiguation/baml_tests__diagnostic_errors__attr_disambiguation__03_ppir.snap new file mode 100644 index 00000000000..8893479d2a3 --- /dev/null +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/attr_disambiguation/baml_tests__diagnostic_errors__attr_disambiguation__03_ppir.snap @@ -0,0 +1,269 @@ +--- +source: crates/baml_tests/src/generated_tests.rs +assertion_line: 37509 +--- +=== PPIR === +class user.GAliased { + status: user.GStatus + role: user.GRole + point: user.GPoint + coord: user.GCoord +} +class user.GAliased$stream { + status: user.GStatus | null + role: user.GRole | null + point: user.GPoint$stream | null + coord: user.GCoord$stream | null +} +class user.GComplex { + statuses: user.GStatus[] + maybe_status: user.GStatus? + role_or_status: user.GRole | user.GStatus + points: user.GPoint[] + maybe_point: user.GPoint? + config_map: map +} +class user.GComplex$stream { + statuses: user.GStatus[] + maybe_status: user.GStatus | null + role_or_status: user.GRole | user.GStatus | null + points: user.GPoint$stream[] + maybe_point: user.GPoint$stream | null + config_map: map +} +class user.GConfig { + key: string + value: string +} +class user.GConfig$stream { + key: string | null + value: string | null +} +class user.GCoord { + lat: float + lng: float +} +class user.GCoord$stream { + lat: float | null + lng: float | null +} +class user.GIncident { + severity: user.GSeverity + priority: user.GPriority + title: string + config: user.GConfig +} +class user.GIncident$stream { + severity: user.GSeverity | null + priority: user.GPriority | null + title: string | null + config: user.GConfig$stream | null +} +class user.GPoint { + x: float + y: float +} +class user.GPoint$stream { + x: float | null + y: float | null +} +class user.GProfile { + status: user.GStatus + role: user.GRole + name: string + location: user.GPoint + fallback: user.GCoord +} +class user.GProfile$stream { + status: user.GStatus | null + role: user.GRole | null + name: string | null + location: user.GPoint$stream | null + fallback: user.GCoord$stream | null +} +enum user.GPriority {P0, P1, P2, P3} +enum user.GRole {Admin, User, Guest} +enum user.GSeverity {Low, Medium, High} +enum user.GSize {Small, Medium, Large} +enum user.GStatus {Active, Inactive, Pending} +enum user.GroupF {F1, F2, F3, F4, F5, F6} +class user.MFoo { + x: int +} +class user.MFoo$stream { + x: int | null +} +class user.OrderingModifiers { + c1: user.MFoo? + c2: user.MFoo? + c3: user.MFoo[] + c4: user.MFoo[] + c5: user.MFoo[]? + c6: map +} +class user.OrderingModifiers$stream { + c1: user.MFoo? + c2: user.MFoo? + c3: user.MFoo[] + c4: user.MFoo[] + c5: user.MFoo[]? + c6: map +} +class user.AliasInNestedTypes { + d1: user.NFoo[] + d2: user.NFoo[] + d3: user.NFoo[] + d4: map + d5: map + d6: user.NFoo | user.NBar[] + d7: user.NFoo | user.NBar[] + d8: user.NFoo[] + d9: user.NFoo + d10: map> +} +class user.AliasInNestedTypes$stream { + d1: user.NFoo$stream[] + d2: user.NFoo$stream[] + d3: user.NFoo$stream[] + d4: map + d5: map + d6: user.NFoo$stream | user.NBar$stream[] + d7: user.NFoo$stream | user.NBar$stream[] + d8: user.NFoo[] + d9: user.NFoo$stream | null + d10: map> +} +class user.NBar { + x: int +} +class user.NBar$stream { + x: int | null +} +class user.NFoo { + x: int +} +class user.NFoo$stream { + x: int | null +} +class user.EA { + x: int +} +class user.EA$stream { + x: int | null +} +class user.EB { + x: int +} +class user.EB$stream { + x: int | null +} +class user.EC { + x: int +} +class user.EC$stream { + x: int | null +} +class user.EFoo { + x: int +} +class user.EFoo$stream { + x: int | null +} +type user.E1 = user.EFoo +type user.E1$stream = user.EFoo$stream +type user.E2 = user.EFoo +type user.E2$stream = user.EFoo$stream +type user.E3 = user.EFoo +type user.E3$stream = user.EFoo$stream +type user.E4 = user.EA | user.EB | user.EC +type user.E4$stream = user.EA$stream | user.EB$stream | user.EC$stream +function user.E5(x: user.EFoo) -> string [expr] { + { } "hello" +} +function user.E6(x: user.EFoo) -> string [expr] { + { } "hello" +} +function user.E7() -> user.EFoo [expr] { + { } user.EFoo { x: 1 } +} +function user.E8() -> user.EFoo [expr] { + { } user.EFoo { x: 1 } +} +class user.Fizz { + x: int +} +class user.Fizz$stream { + x: int | null +} +class user.OrderingSimple { + a1: user.Fizz + a2: user.Fizz + a3: user.Fizz + a4: user.Fizz + a5: user.Fizz + a6: user.Fizz + a7: user.Fizz + a8: user.Fizz + a9: user.Fizz +} +class user.OrderingSimple$stream { + a1: user.Fizz + a2: user.Fizz$stream | null + a3: user.Fizz + a4: user.Fizz + a5: user.Fizz + a6: user.Fizz + a7: user.Fizz + a8: user.Fizz$stream | null + a9: user.Fizz +} +class user.OrderingUnions { + b1: user.UA | user.UB | user.UC + b2: user.UA | user.UB | user.UC + b3: user.UA | user.UB | user.UC + b4: user.UA | user.UB | user.UC + b5: user.UA | user.UB | user.UC + b6: user.UA | user.UB | user.UC + b7: user.UA | user.UB | user.UC + b8: user.UA | user.UB | user.UC + b9: user.UA | user.UB + b10: user.UA | user.UB + b11: user.UA | user.UB + b12: user.UA | user.UB + b13: user.UA | user.UB + b14: user.UA | user.UB +} +class user.OrderingUnions$stream { + b1: user.UA | user.UB | user.UC + b2: user.UA$stream | user.UB$stream | user.UC$stream | null + b3: user.UA$stream | user.UB$stream | user.UC$stream | null + b4: user.UA$stream | user.UB$stream | user.UC$stream | null + b5: user.UA$stream | user.UB$stream | user.UC$stream | null + b6: user.UA$stream | user.UB$stream | user.UC$stream | null + b7: user.UA | user.UB | user.UC + b8: user.UA$stream | user.UB$stream | user.UC$stream | null + b9: user.UA | user.UB + b10: user.UA | user.UB + b11: user.UA$stream | user.UB$stream | null + b12: user.UA | user.UB + b13: user.UA$stream | user.UB$stream | null + b14: user.UA$stream | user.UB$stream | null +} +class user.UA { + x: int +} +class user.UA$stream { + x: int | null +} +class user.UB { + x: int +} +class user.UB$stream { + x: int | null +} +class user.UC { + x: int +} +class user.UC$stream { + x: int | null +} diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/attribute_validation/baml_tests__diagnostic_errors__attribute_validation__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/attribute_validation/baml_tests__diagnostic_errors__attribute_validation__03_ppir.snap similarity index 58% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/attribute_validation/baml_tests__diagnostic_errors__attribute_validation__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/attribute_validation/baml_tests__diagnostic_errors__attribute_validation__03_ppir.snap index fad57e345c0..5474e6e4328 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/attribute_validation/baml_tests__diagnostic_errors__attribute_validation__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/attribute_validation/baml_tests__diagnostic_errors__attribute_validation__03_ppir.snap @@ -1,18 +1,30 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 38200 --- -=== HIR2 === +=== PPIR === class user.HasDuplicateDescription { name: string } +class user.HasDuplicateDescription$stream { + name: string | null +} class user.HasDuplicateField { name: string age: int name: int } +class user.HasDuplicateField$stream { + name: string | null + age: int | null + name: int | null +} class user.HasDuplicateFieldAttr { name: string } +class user.HasDuplicateFieldAttr$stream { + name: string | null +} enum user.HasDuplicateEnumAttr {ONE, TWO} enum user.HasDuplicateVariant {RED, BLUE, RED} enum user.HasDuplicateVariantAttr {ACTIVE, INACTIVE} diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/backtick_interp_type_errors/baml_tests__diagnostic_errors__backtick_interp_type_errors__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/backtick_interp_type_errors/baml_tests__diagnostic_errors__backtick_interp_type_errors__03_ppir.snap similarity index 94% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/backtick_interp_type_errors/baml_tests__diagnostic_errors__backtick_interp_type_errors__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/backtick_interp_type_errors/baml_tests__diagnostic_errors__backtick_interp_type_errors__03_ppir.snap index 69473af3fde..8f70a8afb0e 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/backtick_interp_type_errors/baml_tests__diagnostic_errors__backtick_interp_type_errors__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/backtick_interp_type_errors/baml_tests__diagnostic_errors__backtick_interp_type_errors__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 38480 --- -=== HIR2 === +=== PPIR === function user.bad_member_chain_interp() -> string [expr] { { } `...` } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/backtick_strict_types/baml_tests__diagnostic_errors__backtick_strict_types__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/backtick_strict_types/baml_tests__diagnostic_errors__backtick_strict_types__03_ppir.snap similarity index 89% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/backtick_strict_types/baml_tests__diagnostic_errors__backtick_strict_types__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/backtick_strict_types/baml_tests__diagnostic_errors__backtick_strict_types__03_ppir.snap index e53fcaf98de..28106b34080 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/backtick_strict_types/baml_tests__diagnostic_errors__backtick_strict_types__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/backtick_strict_types/baml_tests__diagnostic_errors__backtick_strict_types__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 38760 --- -=== HIR2 === +=== PPIR === function user.case_a_null_interp() -> string [expr] { { let x: int? = null } `...` } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/basic_types/baml_tests__diagnostic_errors__basic_types__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/basic_types/baml_tests__diagnostic_errors__basic_types__03_ppir.snap similarity index 53% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/basic_types/baml_tests__diagnostic_errors__basic_types__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/basic_types/baml_tests__diagnostic_errors__basic_types__03_ppir.snap index a7b34c5c751..e0d3b88ccf5 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/basic_types/baml_tests__diagnostic_errors__basic_types__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/basic_types/baml_tests__diagnostic_errors__basic_types__03_ppir.snap @@ -1,10 +1,14 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 39180 --- -=== HIR2 === +=== PPIR === class user.ClassAttributes { name: string } +class user.ClassAttributes$stream { + name: string | null +} class user.FieldAttributes { money: int currency: string @@ -14,6 +18,15 @@ class user.FieldAttributes { state: string multiple: string? } +class user.FieldAttributes$stream { + money: int | null + currency: string | null + name: string | null + summary: string + details: string | null + state: string | null + multiple: string? +} function user.GetMixedList(client: baml.llm.Client = GPT4) -> int | string[] [llm] { baml.llm.call_llm_function(client, "GetMixedList", map { }) } @@ -23,9 +36,18 @@ function user.GetMixedList$build_request(client: baml.llm.Client = GPT4) -> baml function user.GetMixedList$build_request_stream(client: baml.llm.Client = GPT4) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "GetMixedList", map { }) } +function user.GetMixedList$parse(json: string, client: baml.llm.Client = GPT4) -> int | string[] [expr] { + baml.llm.parse(json) +} +function user.GetMixedList$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = GPT4) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.GetMixedList$render_prompt(client: baml.llm.Client = GPT4) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "GetMixedList", map { }) } +function user.GetMixedList$stream(client: baml.llm.Client = GPT4) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "GetMixedList", map { }) +} function user.GetMixedMap(client: baml.llm.Client = GPT4) -> map [llm] { baml.llm.call_llm_function(client, "GetMixedMap", map { }) } @@ -35,9 +57,18 @@ function user.GetMixedMap$build_request(client: baml.llm.Client = GPT4) -> baml. function user.GetMixedMap$build_request_stream(client: baml.llm.Client = GPT4) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "GetMixedMap", map { }) } +function user.GetMixedMap$parse(json: string, client: baml.llm.Client = GPT4) -> map [expr] { + baml.llm.parse(json) +} +function user.GetMixedMap$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = GPT4) -> baml.llm.Stream, map> [expr] { + client.__make_stream(sse) +} function user.GetMixedMap$render_prompt(client: baml.llm.Client = GPT4) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "GetMixedMap", map { }) } +function user.GetMixedMap$stream(client: baml.llm.Client = GPT4) -> baml.llm.Stream, map> [expr] { + baml.llm.stream_llm_function(client, "GetMixedMap", map { }) +} function user.GetStatus(client: baml.llm.Client = GPT4) -> Status [llm] { baml.llm.call_llm_function(client, "GetStatus", map { }) } @@ -47,9 +78,18 @@ function user.GetStatus$build_request(client: baml.llm.Client = GPT4) -> baml.ht function user.GetStatus$build_request_stream(client: baml.llm.Client = GPT4) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "GetStatus", map { }) } +function user.GetStatus$parse(json: string, client: baml.llm.Client = GPT4) -> Status [expr] { + baml.llm.parse(json) +} +function user.GetStatus$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = GPT4) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.GetStatus$render_prompt(client: baml.llm.Client = GPT4) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "GetStatus", map { }) } +function user.GetStatus$stream(client: baml.llm.Client = GPT4) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "GetStatus", map { }) +} function user.GetUser(id: int, client: baml.llm.Client = ...) -> User [llm] { baml.llm.call_llm_function(client, "GetUser", map { "id": id }) } @@ -59,22 +99,46 @@ function user.GetUser$build_request(id: int, client: baml.llm.Client = ...) -> b function user.GetUser$build_request_stream(id: int, client: baml.llm.Client = ...) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "GetUser", map { "id": id }) } +function user.GetUser$parse(json: string, client: baml.llm.Client = ...) -> User [expr] { + baml.llm.parse(json) +} +function user.GetUser$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = ...) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.GetUser$render_prompt(id: int, client: baml.llm.Client = ...) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "GetUser", map { "id": id }) } +function user.GetUser$stream(id: int, client: baml.llm.Client = ...) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "GetUser", map { "id": id }) +} class user.User { id: int name: string email: string } +class user.User$stream { + id: int | null + name: string | null + email: string | null +} enum user.Status {Active, Inactive} type user.MixedList = int | string[] +type user.MixedList$stream = int | string[] type user.MixedMap = map +type user.MixedMap$stream = map type user.OptionalCode = 200? +type user.OptionalCode$stream = 200 | null type user.OptionalFlag = true? +type user.OptionalFlag$stream = true | null type user.OptionalRole = "admin"? +type user.OptionalRole$stream = "admin" | null type user.OptionalRoleList = "writer"[]? +type user.OptionalRoleList$stream = "writer"[] | null type user.ReallyLongMapType = map | map> | map>> | map>>>> +type user.ReallyLongMapType$stream = map | map> | map>> | map>>>> type user.Role = "user" | "assistant" | "system" +type user.Role$stream = "user" | "assistant" | "system" type user.RoleList = "reader"[] +type user.RoleList$stream = "reader"[] type user.UnionOfArrays = int[] | string[] +type user.UnionOfArrays$stream = int[] | string[] diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/builtin_io/baml_tests__diagnostic_errors__builtin_io__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/builtin_io/baml_tests__diagnostic_errors__builtin_io__03_ppir.snap similarity index 99% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/builtin_io/baml_tests__diagnostic_errors__builtin_io__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/builtin_io/baml_tests__diagnostic_errors__builtin_io__03_ppir.snap index 4407a83dea4..3b0fdd668e4 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/builtin_io/baml_tests__diagnostic_errors__builtin_io__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/builtin_io/baml_tests__diagnostic_errors__builtin_io__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 39807 --- -=== HIR2 === +=== PPIR === function user.Append() -> int [expr] { { let f = baml.fs.open("log.txt", "a") } f.write("line\n") } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/captured_field_chain/baml_tests__diagnostic_errors__captured_field_chain__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/captured_field_chain/baml_tests__diagnostic_errors__captured_field_chain__03_ppir.snap similarity index 82% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/captured_field_chain/baml_tests__diagnostic_errors__captured_field_chain__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/captured_field_chain/baml_tests__diagnostic_errors__captured_field_chain__03_ppir.snap index 3872d86d6a4..05f58902fb5 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/captured_field_chain/baml_tests__diagnostic_errors__captured_field_chain__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/captured_field_chain/baml_tests__diagnostic_errors__captured_field_chain__03_ppir.snap @@ -1,14 +1,22 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 40288 --- -=== HIR2 === +=== PPIR === class user.Inner { value: int } +class user.Inner$stream { + value: int | null +} class user.Outer { inner: user.Inner name: string } +class user.Outer$stream { + inner: user.Inner$stream | null + name: string | null +} function user.test_captured_chain(outer: user.Outer) -> int [expr] { { let result = [1].map((x) -> { { } outer.inner.value }) } result[0] } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_arm_braceless_return/baml_tests__diagnostic_errors__catch_arm_braceless_return__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_arm_braceless_return/baml_tests__diagnostic_errors__catch_arm_braceless_return__03_ppir.snap similarity index 87% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_arm_braceless_return/baml_tests__diagnostic_errors__catch_arm_braceless_return__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_arm_braceless_return/baml_tests__diagnostic_errors__catch_arm_braceless_return__03_ppir.snap index 92aa36590e2..1dbf3fecad4 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_arm_braceless_return/baml_tests__diagnostic_errors__catch_arm_braceless_return__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_arm_braceless_return/baml_tests__diagnostic_errors__catch_arm_braceless_return__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 40573 --- -=== HIR2 === +=== PPIR === function user.callee(x: int) -> bool [expr] { { if (x Eq 0) { throw "boom" } } true } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_return_type_mismatch/baml_tests__diagnostic_errors__catch_return_type_mismatch__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_return_type_mismatch/baml_tests__diagnostic_errors__catch_return_type_mismatch__03_ppir.snap similarity index 90% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_return_type_mismatch/baml_tests__diagnostic_errors__catch_return_type_mismatch__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_return_type_mismatch/baml_tests__diagnostic_errors__catch_return_type_mismatch__03_ppir.snap index 21261297f09..fb8a2b787ad 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_return_type_mismatch/baml_tests__diagnostic_errors__catch_return_type_mismatch__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_return_type_mismatch/baml_tests__diagnostic_errors__catch_return_type_mismatch__03_ppir.snap @@ -1,8 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs -assertion_line: 27565 +assertion_line: 40853 --- -=== HIR2 === +=== PPIR === enum user.Errors {AuthenticationError, AuthorizationError, NotFoundError, InternalServerError} function user.callee() -> bool [expr] { { return true } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_throw_regressions/baml_tests__diagnostic_errors__catch_throw_regressions__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_throw_regressions/baml_tests__diagnostic_errors__catch_throw_regressions__03_ppir.snap similarity index 95% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_throw_regressions/baml_tests__diagnostic_errors__catch_throw_regressions__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_throw_regressions/baml_tests__diagnostic_errors__catch_throw_regressions__03_ppir.snap index 2c76635a18c..03b286c4479 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_throw_regressions/baml_tests__diagnostic_errors__catch_throw_regressions__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/catch_throw_regressions/baml_tests__diagnostic_errors__catch_throw_regressions__03_ppir.snap @@ -1,10 +1,14 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 41142 --- -=== HIR2 === +=== PPIR === class user.BuildError { reason: string } +class user.BuildError$stream { + reason: string | null +} enum user.Status {HttpError, IndexError, AuthError, SomeOtherError} function user.AlwaysThrowsStatus(n: int) -> user.Status [expr] { { } match (n) { 0 => throw "http_error", _ => throw 404 } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/client_option_types/baml_tests__diagnostic_errors__client_option_types__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/client_option_types/baml_tests__diagnostic_errors__client_option_types__03_ppir.snap similarity index 99% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/client_option_types/baml_tests__diagnostic_errors__client_option_types__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/client_option_types/baml_tests__diagnostic_errors__client_option_types__03_ppir.snap index 92a979c08dd..6c7211099af 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/client_option_types/baml_tests__diagnostic_errors__client_option_types__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/client_option_types/baml_tests__diagnostic_errors__client_option_types__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 41423 --- -=== HIR2 === +=== PPIR === function user.BadAzureMissingUrl$new(lenient: bool) -> ? [expr] { baml.llm.PrimitiveClient { name: "BadAzureMissingUrl", provider: "azure-openai", options: baml.llm.PrimitiveClientOptions { model: "gpt-4o", base_url: null, allowed_role_metadata: null, finish_reason_allow_list: null, finish_reason_deny_list: null, supports_streaming: null, default_role: null, allowed_roles: null, remap_roles: null, api_key: null, provider_options: baml.llm.AzureOpenAiOptions { resource_name: null, deployment_id: null, api_version: "2024-02-15-preview", max_tokens: null }, media_url_handler: null, headers: map { }, query_params: map { }, request_body: map { } } } } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/closure_errors/baml_tests__diagnostic_errors__closure_errors__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/closure_errors/baml_tests__diagnostic_errors__closure_errors__03_ppir.snap similarity index 85% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/closure_errors/baml_tests__diagnostic_errors__closure_errors__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/closure_errors/baml_tests__diagnostic_errors__closure_errors__03_ppir.snap index 925a003bb9e..107d47c9d07 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/closure_errors/baml_tests__diagnostic_errors__closure_errors__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/closure_errors/baml_tests__diagnostic_errors__closure_errors__03_ppir.snap @@ -1,17 +1,28 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 41707 --- -=== HIR2 === +=== PPIR === class user.Counter { value: int } +class user.Counter$stream { + value: int | null +} class user.Employee { first: string last: string } +class user.Employee$stream { + first: string | null + last: string | null +} class user.Formatter { prefix: string } +class user.Formatter$stream { + prefix: string | null +} function user.format(self: ?, text: string) -> string [expr] { { } self.prefix Add text } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/control_flow/baml_tests__diagnostic_errors__control_flow__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/control_flow/baml_tests__diagnostic_errors__control_flow__03_ppir.snap similarity index 81% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/control_flow/baml_tests__diagnostic_errors__control_flow__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/control_flow/baml_tests__diagnostic_errors__control_flow__03_ppir.snap index 3f292d445a1..46a8658eb6f 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/control_flow/baml_tests__diagnostic_errors__control_flow__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/control_flow/baml_tests__diagnostic_errors__control_flow__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 41988 --- -=== HIR2 === +=== PPIR === function user.ElseIfChain(x: int) -> string [expr] { { } if (x Eq 1) { // [1] Case one } "one" else if (x Eq 2) { // [1] Case two } "two" else if (x Eq 3) { // [1] Case three } "three" else { // [1] Default case } "other" } @@ -20,9 +21,18 @@ function user.LlmFunction$build_request(input: string, client: baml.llm.Client = function user.LlmFunction$build_request_stream(input: string, client: baml.llm.Client = TestClient) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "LlmFunction", map { "input": input }) } +function user.LlmFunction$parse(json: string, client: baml.llm.Client = TestClient) -> string [expr] { + baml.llm.parse(json) +} +function user.LlmFunction$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = TestClient) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.LlmFunction$render_prompt(input: string, client: baml.llm.Client = TestClient) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "LlmFunction", map { "input": input }) } +function user.LlmFunction$stream(input: string, client: baml.llm.Client = TestClient) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "LlmFunction", map { "input": input }) +} function user.MatchExpression(x: int) -> string [expr] { { } match (x) { 1 => { // [1] One } "one", 2 => { // [1] Two } "two", _ => { // [1] Default } "other" } } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_attribute/baml_tests__diagnostic_errors__duplicate_attribute__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_attribute/baml_tests__diagnostic_errors__duplicate_attribute__03_ppir.snap similarity index 54% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_attribute/baml_tests__diagnostic_errors__duplicate_attribute__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_attribute/baml_tests__diagnostic_errors__duplicate_attribute__03_ppir.snap index 7ff26004a32..73131f8b773 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_attribute/baml_tests__diagnostic_errors__duplicate_attribute__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_attribute/baml_tests__diagnostic_errors__duplicate_attribute__03_ppir.snap @@ -1,18 +1,31 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 42268 --- -=== HIR2 === +=== PPIR === class user.AliasAndDescription { a: string } +class user.AliasAndDescription$stream { + a: string | null +} class user.SingleAlias { a: string } +class user.SingleAlias$stream { + a: string | null +} class user.TwoFieldAlias { a: string } +class user.TwoFieldAlias$stream { + a: string | null +} class user.TwoFieldDescription { a: string } +class user.TwoFieldDescription$stream { + a: string | null +} enum user.SingleVariantAlias {RED, BLUE} enum user.TwoVariantAlias {ACTIVE, INACTIVE} diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_class_span/baml_tests__diagnostic_errors__duplicate_class_span__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_class_span/baml_tests__diagnostic_errors__duplicate_class_span__03_ppir.snap similarity index 56% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_class_span/baml_tests__diagnostic_errors__duplicate_class_span__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_class_span/baml_tests__diagnostic_errors__duplicate_class_span__03_ppir.snap index 95c6cdec9be..bd5e2615248 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_class_span/baml_tests__diagnostic_errors__duplicate_class_span__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_class_span/baml_tests__diagnostic_errors__duplicate_class_span__03_ppir.snap @@ -1,11 +1,16 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 42552 --- -=== HIR2 === +=== PPIR === class user.A { field: string } class user.A { field: string } +class user.A$stream { + field: string | null +} type user.A = int +type user.A$stream = int diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_field_alias/baml_tests__diagnostic_errors__duplicate_field_alias__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_field_alias/baml_tests__diagnostic_errors__duplicate_field_alias__03_hir.snap deleted file mode 100644 index 81f7dfa98e1..00000000000 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_field_alias/baml_tests__diagnostic_errors__duplicate_field_alias__03_hir.snap +++ /dev/null @@ -1,34 +0,0 @@ ---- -source: crates/baml_tests/src/generated_tests.rs ---- -=== HIR2 === -class user.AliasEqualsOwnName { - a: string - b: string -} -class user.AliasVsAlias { - a: string - b: string -} -class user.AllDistinct { - a: string - b: string - c: string -} -class user.NameVsAlias { - x: string - b: string -} -class user.NormalizedCollision { - a: string - b: string -} -class user.SkippedDoesNotCollide { - a: string - b: string -} -class user.TripleCollision { - first: string - second: string - shared: string -} diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_field_alias/baml_tests__diagnostic_errors__duplicate_field_alias__03_ppir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_field_alias/baml_tests__diagnostic_errors__duplicate_field_alias__03_ppir.snap new file mode 100644 index 00000000000..625d7e4e062 --- /dev/null +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_field_alias/baml_tests__diagnostic_errors__duplicate_field_alias__03_ppir.snap @@ -0,0 +1,65 @@ +--- +source: crates/baml_tests/src/generated_tests.rs +assertion_line: 42832 +--- +=== PPIR === +class user.AliasEqualsOwnName { + a: string + b: string +} +class user.AliasEqualsOwnName$stream { + a: string | null + b: string | null +} +class user.AliasVsAlias { + a: string + b: string +} +class user.AliasVsAlias$stream { + a: string | null + b: string | null +} +class user.AllDistinct { + a: string + b: string + c: string +} +class user.AllDistinct$stream { + a: string | null + b: string | null + c: string | null +} +class user.NameVsAlias { + x: string + b: string +} +class user.NameVsAlias$stream { + x: string | null + b: string | null +} +class user.NormalizedCollision { + a: string + b: string +} +class user.NormalizedCollision$stream { + a: string | null + b: string | null +} +class user.SkippedDoesNotCollide { + a: string + b: string +} +class user.SkippedDoesNotCollide$stream { + a: string | null + b: string | null +} +class user.TripleCollision { + first: string + second: string + shared: string +} +class user.TripleCollision$stream { + first: string | null + second: string | null + shared: string | null +} diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_variant_alias/baml_tests__diagnostic_errors__duplicate_variant_alias__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_variant_alias/baml_tests__diagnostic_errors__duplicate_variant_alias__03_ppir.snap similarity index 91% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_variant_alias/baml_tests__diagnostic_errors__duplicate_variant_alias__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_variant_alias/baml_tests__diagnostic_errors__duplicate_variant_alias__03_ppir.snap index 1ff8ec264b6..9001913e5ba 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_variant_alias/baml_tests__diagnostic_errors__duplicate_variant_alias__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/duplicate_variant_alias/baml_tests__diagnostic_errors__duplicate_variant_alias__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 43120 --- -=== HIR2 === +=== PPIR === enum user.AliasEqualsOwnName {A, B} enum user.AliasVsAlias {A, B} enum user.AllDistinct {A, B, C} diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/format_checks/baml_tests__diagnostic_errors__format_checks__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/format_checks/baml_tests__diagnostic_errors__format_checks__03_ppir.snap similarity index 80% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/format_checks/baml_tests__diagnostic_errors__format_checks__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/format_checks/baml_tests__diagnostic_errors__format_checks__03_ppir.snap index ce1656a6d60..4a97ebfefdf 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/format_checks/baml_tests__diagnostic_errors__format_checks__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/format_checks/baml_tests__diagnostic_errors__format_checks__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 44178 --- -=== HIR2 === +=== PPIR === function user.BinaryExprs(a: int, b: int, c: int, d: int, s: string, flag: bool) -> int [expr] { { a Add b; a Sub b; a Mul b; a Div b; a Mod b; a Eq b; a Ne b; a Lt b; a Gt b; a Le b; a Ge b; flag And true; flag Or false; a BitAnd b; a BitOr b; a BitXor b; a Shl b; a Shr b; let mut_a = a; mut_a Add= b; mut_a Sub= b; mut_a Mul= b; mut_a Div= b; mut_a Mod= b; mut_a BitAnd= b; mut_a BitOr= b; mut_a BitXor= b; mut_a Shl= b; mut_a Shr= b; a Add b Add c; a Add b Add c Add d; a Sub b Add c Sub d; a Mul b Mul c; a Mul b Div c Mod d; a Gt 0 And b Gt 0; a Gt 0 Or b Gt 0; a Gt 0 And b Gt 0 And c Gt 0; a Gt 0 Or b Gt 0 Or c Gt 0; a Gt 0 And b Gt 0 Or c Gt 0; a Add b Mul c; a Add b Mul c; a Mul b Add c Mul d; a Add b Mul c Add d; a Add b Mul c Add d; a Add b Mul c Add d; a Add b Mul c Add d; a Add b Mul c Add d Mul a Sub b Add c Sub d Add a Mul b Add c Mul d; a Add b Mul c Add d Add a Sub b Mul c Sub d Mul a Mul c Mul d Add b Mul c Mul d Sub a Mul d Add b Mul c Mul d; a Add b; a Add b; a Add b Add c; a Add b Add c Add d Add a Add b Add c Add d Add a Add b Add c Add d Add a Add b Add c Add d Add a Add b Add c Add d Add a Add b Add c Add d Add a Add b; a Gt 0 And b Gt 0 And c Gt 0 And d Gt 0 And a Ne b And b Ne c And c Ne d And a Lt 1000 Mul 8 Add 1 Mul 2 And b Lt 1000 And c Lt 1000 And d Lt 1000 Add 2 Add 3; a Mul b Add c Mul d Sub a Mul b Add c Mul d Sub a Mul b Add c Mul d Sub a Mul b Add c Mul d Sub a Mul b Add c Mul d Sub a Mul b Add c Mul d Sub a Mul b Add c Mul d Sub a Mul b Add c Mul d Sub a Mul b Add c Mul d Sub a Mul b Add c Mul d; a Add b Add c Add d Gt 0 And a Mul b Mul c Mul d Lt 10000 And a Sub b Sub c Sub d Ne 0 And a Add b Mul c Add d Ge 100 Or a Mul 1 Lt 2 And "aowiefjowiaj" Eq "jfeiowajpwoeifj"; "a very long strin..." Add " concatenated with " Add "another very long..."; mut_a Add= a Mul b Add c Mul d Add a Mul b Add c Mul d Add a Mul b Add c Mul d Add a Mul b Add c Mul d Add a Mul b Add c Mul d Add a; a Add b Add c Add d Add a Add b Add c Add d Add a Add b Add c Add d; a Add b Add c Add d Add a Add b Add c Add d Add a Add b Add c Add d; a Gt 0 And b Gt 0 And c Gt 0 And d Gt 0 And a Ne b And b Ne c And c Ne d; a Add b; 1 Add 2; a Gt b; a Add b; a Mul b Add c; a Eq b; a Eq 2 And b Ne 3 } a Add b } @@ -10,37 +11,70 @@ class user.ChainItem { value: int metadata: user.ChainMetadata } +class user.ChainItem$stream { + label: string | null + value: int | null + metadata: user.ChainMetadata$stream | null +} class user.ChainMetadata { created_at: string tags: string[] } +class user.ChainMetadata$stream { + created_at: string | null + tags: string[] +} class user.ChainPreferences { color: string font: string size: int } +class user.ChainPreferences$stream { + color: string | null + font: string | null + size: int | null +} class user.ChainProfile { bio: string settings: user.ChainSettings items: user.ChainItem[] } +class user.ChainProfile$stream { + bio: string | null + settings: user.ChainSettings$stream | null + items: user.ChainItem$stream[] +} class user.ChainSettings { theme: string notifications: bool preferences: user.ChainPreferences } +class user.ChainSettings$stream { + theme: string | null + notifications: bool | null + preferences: user.ChainPreferences$stream | null +} class user.ChainUser { name: string profile: user.ChainProfile tags: string[] scores: int[][] } +class user.ChainUser$stream { + name: string | null + profile: user.ChainProfile$stream | null + tags: string[] + scores: int[][] +} function user.ChainExprs(user: user.ChainUser, items: user.ChainItem[], m: map) -> string [expr] { { user; user.name; user.profile.bio; user.profile.settings.theme; user.profile.settings.preferences.color; user.profile.items[0].metadata.tags[0]; user.profile.settings.preferences.font; user.name; user.name; user.profile.settings.theme; user.name.len(); items.len(); user.profile.items.get(0); items.get(0); items.get(0); items[0]; items[0].label; user.tags[0]; user.scores[0][1]; items[0]; items[0]; user.name.len().to_string(); user.profile.settings.preferences.color.len().to_string().len().to_string().len().to_string().len().to_string(); user.profile.items[0].metadata.tags[0].len().to_string().len().to_string().len().to_string(); user.profile.items.get(user.profile.items.len() Sub 1 Add user.profile.items.len() Sub 2 Add user.profile.items.len() Sub 3).label; user.profile.items.slice(0, user.profile.items.len() Sub 1, user.profile.settings.preferences.size); user.profile.settings.preferences.color.len().to_string().len(); user.profile.settings.preferences.color.len().to_string().len(); user.profile.items.get(user.profile.items.len() Sub 1 Add user.profile.items.len() Sub 2).label; user.scores[0][0]; user.scores[0][1]; user.scores[user.scores.len() Sub 1][user.scores[0].len() Sub 1]; user.name; items[0]; items.get(0); user.tags[0].len(); user.scores[0][0]; items[0].label.len(); baml.env.get_or_panic("API_KEY"); baml.env.get_or_panic("DATABASE_URL") } user.name } class user.A { x: int } +class user.A$stream { + x: int | null +} class user.AttributeVariety { a: string b: string @@ -49,59 +83,120 @@ class user.AttributeVariety { e: string f: string } +class user.AttributeVariety$stream { + a: string | null + b: string | null + c: string | null + d: string + e: string | null + f: string | null +} class user.AttrsWithDelimiters { name: string age: int active: bool } +class user.AttrsWithDelimiters$stream { + name: string | null + age: int | null + active: bool +} class user.ColonFields { name: string age: int } +class user.ColonFields$stream { + name: string | null + age: int | null +} class user.DeepLevel1 { level2: user.DeepLevel2 items: user.DeepLevel2[] mapping: map } +class user.DeepLevel1$stream { + level2: user.DeepLevel2$stream | null + items: user.DeepLevel2$stream[] + mapping: map +} class user.DeepLevel2 { level3: user.DeepLevel3 value: int | string | bool | float | null } +class user.DeepLevel2$stream { + level3: user.DeepLevel3$stream | null + value: int | string | bool | float | null +} class user.DeepLevel3 { data: string nested: map> } +class user.DeepLevel3$stream { + data: string | null + nested: map> +} class user.DeepOuter { level1: user.DeepLevel1 } +class user.DeepOuter$stream { + level1: user.DeepLevel1$stream | null +} class user.DynamicClass { name: string } +class user.DynamicClass$stream { + name: string | null +} class user.EmptyClass { } +class user.EmptyClass$stream { +} class user.ExtraWhitespace { name: string age: int } +class user.ExtraWhitespace$stream { + name: string | null + age: int | null +} class user.FieldsAndMethods { name: string age: int active: bool } +class user.FieldsAndMethods$stream { + name: string | null + age: int | null + active: bool | null +} class user.InnerNested { value: int } +class user.InnerNested$stream { + value: int | null +} class user.LongAttrField { name: string data: map config: map> } +class user.LongAttrField$stream { + name: string | null + data: map + config: map> +} class user.LongFieldTypes { very_long_field_name_that_takes_up_space: int | string | bool | float | null | int[] | string[] another_long_field: map>> callback_field: (first_param: int, second_param: string, third_param: bool) -> map throws never deeply_nested: int | string | bool | float | null[]? } +class user.LongFieldTypes$stream { + very_long_field_name_that_takes_up_space: int | string | bool | float | null | int[] | string[] + another_long_field: map>> + callback_field: unknown + deeply_nested: int | string | bool | float | null[] | null +} class user.ManyFields { field1: int field2: int @@ -114,88 +209,182 @@ class user.ManyFields { field9: int field10: int } +class user.ManyFields$stream { + field1: int | null + field2: int | null + field3: int | null + field4: int | null + field5: int | null + field6: int | null + field7: int | null + field8: int | null + field9: int | null + field10: int | null +} class user.MixedDelimiters { a: string b: int c: bool d: float } +class user.MixedDelimiters$stream { + a: string | null + b: int | null + c: bool | null + d: float | null +} class user.MultiAttrField { name: string summary: string? } +class user.MultiAttrField$stream { + name: string | null + summary: string? +} class user.MultiBlockAttr { name: string } +class user.MultiBlockAttr$stream { + name: string | null +} class user.MultiField { name: string age: int active: bool } +class user.MultiField$stream { + name: string | null + age: int | null + active: bool | null +} class user.NoColonDelimiters { name: string age: int active: bool } +class user.NoColonDelimiters$stream { + name: string | null + age: int | null + active: bool | null +} class user.Outer { inner: user.InnerNested list: user.InnerNested[] optional: user.InnerNested? mapping: map } +class user.Outer$stream { + inner: user.InnerNested$stream | null + list: user.InnerNested$stream[] + optional: user.InnerNested$stream | null + mapping: map +} class user.SemicolonTrivia { name: string age: int } +class user.SemicolonTrivia$stream { + name: string | null + age: int | null +} class user.SingleAttrField { name: string } +class user.SingleAttrField$stream { + name: string | null +} class user.SingleField { name: string } +class user.SingleField$stream { + name: string | null +} class user.SingleFieldComma { name: string } +class user.SingleFieldComma$stream { + name: string | null +} class user.SingleFieldSemicolon { name: string } +class user.SingleFieldSemicolon$stream { + name: string | null +} class user.ThisIsAnExtremelyLongClassNameThatDefinitelyExceedsTheOneHundredCharacterLineLimitAllByItself { x: int } +class user.ThisIsAnExtremelyLongClassNameThatDefinitelyExceedsTheOneHundredCharacterLineLimitAllByItself$stream { + x: int | null +} class user.TrailingCommas { name: string age: int active: bool } +class user.TrailingCommas$stream { + name: string | null + age: int | null + active: bool | null +} class user.TrailingSemicolons { name: string age: int active: bool } +class user.TrailingSemicolons$stream { + name: string | null + age: int | null + active: bool | null +} class user.TriviaClass { name: string } +class user.TriviaClass$stream { + name: string | null +} class user.TriviaClassBlock { name: string } +class user.TriviaClassBlock$stream { + name: string | null +} class user.TriviaFieldAttrs { name: string } +class user.TriviaFieldAttrs$stream { + name: string | null +} class user.TriviaFieldAttrsBlock { name: string } +class user.TriviaFieldAttrsBlock$stream { + name: string | null +} class user.TriviaLongFieldType { data: map } +class user.TriviaLongFieldType$stream { + data: map +} class user.TriviaLongFieldTypeBlock { data: map } +class user.TriviaLongFieldTypeBlock$stream { + data: map +} class user.TriviaMultiAttr { name: string } +class user.TriviaMultiAttr$stream { + name: string +} class user.TriviaMultiAttrBlock { name: string } +class user.TriviaMultiAttrBlock$stream { + name: string +} class user.TypeVariety { simple: string optional: string? @@ -211,12 +400,33 @@ class user.TypeVariety { paren_union_array: int | string | bool[] triple_nested: map>> } +class user.TypeVariety$stream { + simple: string | null + optional: string | null + array: int[] + nested_array: int[][] + union_type: int | string | null + optional_union: int | string | null + union_array: int | string[] + generic: map + complex_generic: map + deep_generic: map> + fn_type: unknown + paren_union_array: int | string | bool[] + triple_nested: map>> +} class user.WithLongMethod { name: string } +class user.WithLongMethod$stream { + name: string | null +} class user.WithMethod { name: string } +class user.WithMethod$stream { + name: string | null +} function user.greet() -> string [expr] { { } "hello" } @@ -292,9 +502,18 @@ function user.TestTarget$build_request(client: baml.llm.Client = BasicClient) -> function user.TestTarget$build_request_stream(client: baml.llm.Client = BasicClient) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "TestTarget", map { }) } +function user.TestTarget$parse(json: string, client: baml.llm.Client = BasicClient) -> string [expr] { + baml.llm.parse(json) +} +function user.TestTarget$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = BasicClient) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.TestTarget$render_prompt(client: baml.llm.Client = BasicClient) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "TestTarget", map { }) } +function user.TestTarget$stream(client: baml.llm.Client = BasicClient) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "TestTarget", map { }) +} function user.ThisIsAnExtremelyLongClientNameThatDefinitelyExceedsTheDefaultLineLimitOfOneHundredColumns$new(lenient: bool) -> ? [expr] { baml.llm.PrimitiveClient { name: "ThisIsAnExtremely...", provider: "openai", options: baml.llm.PrimitiveClientOptions { model: "gpt-4", base_url: null, allowed_role_metadata: null, finish_reason_allow_list: null, finish_reason_deny_list: null, supports_streaming: null, default_role: null, allowed_roles: null, remap_roles: null, api_key: null, provider_options: null, media_url_handler: null, headers: map { }, query_params: map { }, request_body: map { } } } } @@ -377,9 +596,18 @@ function user.LlmBasic$build_request(name: string, client: baml.llm.Client = GPT function user.LlmBasic$build_request_stream(name: string, client: baml.llm.Client = GPT4) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "LlmBasic", map { "name": name }) } +function user.LlmBasic$parse(json: string, client: baml.llm.Client = GPT4) -> string [expr] { + baml.llm.parse(json) +} +function user.LlmBasic$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = GPT4) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.LlmBasic$render_prompt(name: string, client: baml.llm.Client = GPT4) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "LlmBasic", map { "name": name }) } +function user.LlmBasic$stream(name: string, client: baml.llm.Client = GPT4) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "LlmBasic", map { "name": name }) +} function user.LlmMultiLine(text: string, client: baml.llm.Client = GPT4) -> string [llm] { baml.llm.call_llm_function(client, "LlmMultiLine", map { "text": text }) } @@ -389,9 +617,18 @@ function user.LlmMultiLine$build_request(text: string, client: baml.llm.Client = function user.LlmMultiLine$build_request_stream(text: string, client: baml.llm.Client = GPT4) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "LlmMultiLine", map { "text": text }) } +function user.LlmMultiLine$parse(json: string, client: baml.llm.Client = GPT4) -> string [expr] { + baml.llm.parse(json) +} +function user.LlmMultiLine$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = GPT4) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.LlmMultiLine$render_prompt(text: string, client: baml.llm.Client = GPT4) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "LlmMultiLine", map { "text": text }) } +function user.LlmMultiLine$stream(text: string, client: baml.llm.Client = GPT4) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "LlmMultiLine", map { "text": text }) +} function user.LlmReversedOrder(text: string, client: baml.llm.Client = GPT4) -> string [llm] { baml.llm.call_llm_function(client, "LlmReversedOrder", map { "text": text }) } @@ -401,9 +638,18 @@ function user.LlmReversedOrder$build_request(text: string, client: baml.llm.Clie function user.LlmReversedOrder$build_request_stream(text: string, client: baml.llm.Client = GPT4) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "LlmReversedOrder", map { "text": text }) } +function user.LlmReversedOrder$parse(json: string, client: baml.llm.Client = GPT4) -> string [expr] { + baml.llm.parse(json) +} +function user.LlmReversedOrder$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = GPT4) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.LlmReversedOrder$render_prompt(text: string, client: baml.llm.Client = GPT4) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "LlmReversedOrder", map { "text": text }) } +function user.LlmReversedOrder$stream(text: string, client: baml.llm.Client = GPT4) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "LlmReversedOrder", map { "text": text }) +} function user.LlmStringClient(text: string, client: baml.llm.Client = ...) -> string [llm] { baml.llm.call_llm_function(client, "LlmStringClient", map { "text": text }) } @@ -413,9 +659,18 @@ function user.LlmStringClient$build_request(text: string, client: baml.llm.Clien function user.LlmStringClient$build_request_stream(text: string, client: baml.llm.Client = ...) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "LlmStringClient", map { "text": text }) } +function user.LlmStringClient$parse(json: string, client: baml.llm.Client = ...) -> string [expr] { + baml.llm.parse(json) +} +function user.LlmStringClient$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = ...) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.LlmStringClient$render_prompt(text: string, client: baml.llm.Client = ...) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "LlmStringClient", map { "text": text }) } +function user.LlmStringClient$stream(text: string, client: baml.llm.Client = ...) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "LlmStringClient", map { "text": text }) +} function user.LlmWithLongSignature(first_context: string, second_context: string, third_context: string, user_query: string, client: baml.llm.Client = GPT4) -> string [llm] { baml.llm.call_llm_function(client, "LlmWithLongSignature", map { "first_context": first_context, "second_context": second_context, "third_context": third_context, "user_query": user_query }) } @@ -425,9 +680,18 @@ function user.LlmWithLongSignature$build_request(first_context: string, second_c function user.LlmWithLongSignature$build_request_stream(first_context: string, second_context: string, third_context: string, user_query: string, client: baml.llm.Client = GPT4) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "LlmWithLongSignature", map { "first_context": first_context, "second_context": second_context, "third_context": third_context, "user_query": user_query }) } +function user.LlmWithLongSignature$parse(json: string, client: baml.llm.Client = GPT4) -> string [expr] { + baml.llm.parse(json) +} +function user.LlmWithLongSignature$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = GPT4) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.LlmWithLongSignature$render_prompt(first_context: string, second_context: string, third_context: string, user_query: string, client: baml.llm.Client = GPT4) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "LlmWithLongSignature", map { "first_context": first_context, "second_context": second_context, "third_context": third_context, "user_query": user_query }) } +function user.LlmWithLongSignature$stream(first_context: string, second_context: string, third_context: string, user_query: string, client: baml.llm.Client = GPT4) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "LlmWithLongSignature", map { "first_context": first_context, "second_context": second_context, "third_context": third_context, "user_query": user_query }) +} function user.LongNameWithLongReturnType_ExceedsTheLineLimit(x: int) -> map> [expr] { { } map { "a": map { "b": 1 } } } @@ -521,14 +785,24 @@ function user.LoopStmts(items: int[], flag: bool) -> int [expr] { class user.ArrayPatternTriviaBox { values: int[] } +class user.ArrayPatternTriviaBox$stream { + values: int[] +} class user.MatchFailure { reason: string } +class user.MatchFailure$stream { + reason: string | null +} class user.MatchSuccess { data: string } +class user.MatchSuccess$stream { + data: string | null +} enum user.MatchStatus {Active, Inactive, Pending} type user.MatchResult = user.MatchSuccess | user.MatchFailure +type user.MatchResult$stream = user.MatchSuccess$stream | user.MatchFailure$stream function user.MatchExprs(x: int, s: user.MatchStatus, r: user.MatchResult, b: bool) -> string [expr] { { match (x) { 0 => "zero", _ => "other" }; match (x) { 0 => "zero", 1 => "one", 2 => "two", 3 => "three", 4 => "four", _ => "other" }; match (x) { 0 => { "zero" }, _ => { let y = x Add 1; "other" } }; match (x) { 0 => "zero", _ => "other" }; match (x) { 0 => "zero", _ => "other" }; match (x) { n: int => "positive", _ => "other" }; match (x) { n: int => "positive", _ => "other" }; match (x) { 0 => "zero", 1 => "one", 42 => "the answer", _ => "unknown" }; match ("hello") { "hello" => "greeting", "bye" => "farewell", _ => "other" }; match (b) { true => "yes", false => "no" }; match (x) { 0 => "zero", n => "nonzero" }; match (x) { n: int => "an integer" }; match (s) { user.MatchStatus.Active => "active", user.MatchStatus.Inactive => "inactive", user.MatchStatus.Pending => "pending" }; match (x) { 0 | 1 => "binary", 2 | 3 | 4 => "small", _ => "big" }; match (x) { 0 => "zero", 1 | 2 => "small", _ => "other" }; match (s) { user.MatchStatus.Active | user.MatchStatus.Pending => "actionable", user.MatchStatus.Inactive => "done" }; match (r) { s: user.MatchSuccess => s.data, f: user.MatchFailure => f.reason }; match (r) { x: user.MatchSuccess | user.MatchFailure => "something" }; match (x) { 0 | 1 | 2 | 3 | 4 | 5 => "small", _ => "big" }; match (x) { n: int => "positive", n: int => "negative", _ => "zero" }; match (x) { n: int => "acceptable small ...", _ => "other" }; match (x) { 0 => "this is a very lo...", 1 => "another long stri...", _ => "short" }; match (x) { 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 => "lots of literals", _ => "other" }; match (s) { user.MatchStatus.Active | user.MatchStatus.Inactive | user.MatchStatus.Pending => "this arm has many..." }; match (x) { 0 => { let result = if (b) { } "this is the true ..." else { } "this is the false..." } result, _ => "short" }; match (x) { n: int => "acceptable small ...", _ => "other" }; match (x) { n: int => "acceptable small ...", _ => "other" }; match (x Add 1) { 0 => "was minus one", _ => "other" }; match (x Mul x Add b Mul b Add x Mul b Add x Add b Add x Mul x Mul x Add b Mul b Mul b Add x Mul b Mul x Add b Mul x Mul b) { 0 => "zero polynomial", _ => "nonzero" }; match (x Add 1) { 0 => "whitespace", _ => "other" }; match (x) { 0 => "zero", _ => "other" }; match (x) { 0 => match (b) { true => "zero-true", false => "zero-false" }, _ => "nonzero" }; match (x) { 0 => match (b) { true => match (s) { user.MatchStatus.Active => "zero-true-active", user.MatchStatus.Inactive => "zero-true-inactive", user.MatchStatus.Pending => "zero-true-pending" }, false => "zero-false" }, 1 => match (r) { s: user.MatchSuccess => match (b) { true => s.data, false => "one-success-false" }, f: user.MatchFailure => f.reason }, _ => "other" }; match (x) { 0 => if (b) { } match (s) { user.MatchStatus.Active => "active", user.MatchStatus.Inactive => "inactive", user.MatchStatus.Pending => "pending" } else { } "not bool", _ => "other" }; match (x) { 0 => "zero", _ => "other" }; match (x) { x: int | x: int => x }; match (s) { user.MatchStatus.Active | user.MatchStatus.Inactive | user.MatchStatus.Pending => "any" }; match (x) { 1 | 2 => 0 }; match (x) { 1 | 2 => 0 }; match (x) { 1 | 2 => 0 }; match (x) { 1 | 2 | 3 => 0 }; match (s) { user.MatchStatus.Active | user.MatchStatus.Inactive | user.MatchStatus.Pending => "x" }; match (s) { user.MatchStatus.Active | user.MatchStatus.Inactive | user.MatchStatus.Pending => "y" } } match (x) { 1 | 2 | 3 => 0 } } @@ -536,81 +810,160 @@ class user.OtherPoint { x: int y: int } +class user.OtherPoint$stream { + x: int | null + y: int | null +} class user.OtherTriple { a: user.OtherVec b: user.OtherVec c: user.OtherVec } +class user.OtherTriple$stream { + a: user.OtherVec$stream | null + b: user.OtherVec$stream | null + c: user.OtherVec$stream | null +} class user.OtherVec { p: user.OtherPoint q: user.OtherPoint } +class user.OtherVec$stream { + p: user.OtherPoint$stream | null + q: user.OtherPoint$stream | null +} function user.OtherExprs(a: int, b: int) -> int [expr] { { 0; 1; 42; 999999; 0.0; 3.14; 99.999; "hello"; "a short string"; "a much longer str..."; true; false; null; "raw string"; "raw string with \"..."; "\n multi-li..."; a; a Add b; a; a Add b Mul a Sub b; a Add b Mul a Sub b Add a Mul a Add b Mul b Mul a Add b Mul a Add b Sub a Sub b Mul a Sub b; a; a; Neg a; Not true; Neg Neg a; Not a Gt b; Neg a; Neg a; []; [1]; [1, 2, 3]; [1, 2, 3, 4, 5]; ["short", "array"]; ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q"]; ["this is a long st...", "another long stri...", "yet another one t...", "and one more stri..."]; ["alpha", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel", "india", "juliet", "kilo", "lima", "mike", "november", "oscar", "papa"]; [[1, 2], [3, 4]]; [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; [[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]], [[13, 14], [15, 16]]]; [1, 2]; [1, 2]; ["this is a long st...", "another long stri...", "yet another that ...", "and one more stri..."]; ["this is a long st...", "another long stri...", "yet another that ...", "and one more stri..."]; map { "key": 1 }; map { "a": 1, "b": 2 }; map { "a": 1, "b": 2, "c": 3, "d": 4, "e": 5 }; map { "first_key": "first value", "second_key": "second value", "third_key": "third value", "fourth_key": "fourth value", "fifth_key": "fifth" }; map { "outer": map { "inner_a": 1, "inner_b": 2, "inner_c": 3 }, "other": map { "inner_d": 4, "inner_e": 5, "inner_f": 6 } }; map { "k": 1 }; map { "k": 1 }; user.OtherPoint { x: 1, y: 2 }; user.OtherVec { p: user.OtherPoint { x: 1, y: 2 }, q: user.OtherPoint { x: 3, y: 4 } }; user.OtherVec { p: user.OtherPoint { x: 100000, y: 200000 }, q: user.OtherPoint { x: 300000, y: 400000 } }; user.OtherTriple { a: user.OtherVec { p: user.OtherPoint { x: 1, y: 2 }, q: user.OtherPoint { x: 3, y: 4 } }, b: user.OtherVec { p: user.OtherPoint { x: 5, y: 6 }, q: user.OtherPoint { x: 7, y: 8 } }, c: user.OtherVec { p: user.OtherPoint { x: 9, y: 10 }, q: user.OtherPoint { x: 11, y: 12 } } }; user.OtherPoint { x: 1, y: 2 }; user.OtherPoint { x: 1, y: 2 }; user.OtherVec { p: user.OtherPoint { x: 100000, y: 200000 }, q: user.OtherPoint { x: 300000, y: 400000 } }; { let x = 1 } x Add 1; { let x = a Add b; let y = x Mul 2 } y; { let x = { let y = { let z = a Add b } z Mul z } y Add y } x Mul x; { let x = if (a Gt b) { } match (a) { 0 => { let inner = b Mul 2 } inner Add 1, _ => a } else { } b } x; [1, 2, 3]; map { "k": 1 }; user.OtherPoint { x: 1, y: 2 } } a Add b } class user.TypeAliasFailure { reason: string } +class user.TypeAliasFailure$stream { + reason: string | null +} class user.TypeAliasSuccess { data: string } +class user.TypeAliasSuccess$stream { + data: string | null +} type user.AliasChain = user.SimpleAlias +type user.AliasChain$stream = user.SimpleAlias$stream type user.AlwaysTrue = true +type user.AlwaysTrue$stream = true type user.ArrayOptional = int[]? +type user.ArrayOptional$stream = int[] | null type user.BinaryOp = (a: int, b: int) -> int throws never +type user.BinaryOp$stream = unknown type user.ComplexFn = (items: int[], lookup: map) -> string? throws never +type user.ComplexFn$stream = unknown type user.ComplexMap = map +type user.ComplexMap$stream = map type user.ComplexPostfix = int | string?[][] +type user.ComplexPostfix$stream = int | string | null[][] type user.Curried = (x: int) -> (y: int) -> int throws never throws never +type user.Curried$stream = unknown type user.DeepFnType = (x: int) -> (y: int) -> (z: int) -> (w: int) -> map throws never throws never throws never throws never +type user.DeepFnType$stream = unknown type user.DeepGeneric = map>>> +type user.DeepGeneric$stream = map>>> type user.DeepParenUnion = int | string | bool | float | null | int[][]? +type user.DeepParenUnion$stream = int | string | bool | float | null | int[][] | null type user.DeepPostfix = int | string | bool | float?[][]? +type user.DeepPostfix$stream = int | string | bool | float | null[][] | null type user.DoubleArray = int[][] +type user.DoubleArray$stream = int[][] type user.DoubleOptional = int?? +type user.DoubleOptional$stream = int | null | null type user.ExtraWhitespace = int | string | bool | float | null +type user.ExtraWhitespace$stream = int | string | bool | float | null type user.FnFactory = (config: string) -> (int) -> int throws never throws never +type user.FnFactory$stream = unknown type user.HttpOk = 200 +type user.HttpOk$stream = 200 type user.IntList = int[] +type user.IntList$stream = int[] type user.IntToInt = (x: int) -> int throws never +type user.IntToInt$stream = unknown type user.Json = int | float | string | bool | null | user.Json[] | map +type user.Json$stream = int | float | string | bool | null | user.Json$stream[] | map type user.LongParamFn = (first_parameter: map, second_parameter: int | string[], third_parameter: map) -> string throws never +type user.LongParamFn$stream = unknown type user.LongUnion = "alpha" | "bravo" | "charlie" | "delta" | "echo" | "foxtrot" | "golf" | "hotel" | "india" | "juliet" | "kilo" | "lima" +type user.LongUnion$stream = "alpha" | "bravo" | "charlie" | "delta" | "echo" | "foxtrot" | "golf" | "hotel" | "india" | "juliet" | "kilo" | "lima" type user.Matrix = int[][] +type user.Matrix$stream = int[][] type user.MaybeInt = int? +type user.MaybeInt$stream = int | null type user.MaybeResult = user.Result? +type user.MaybeResult$stream = user.Result$stream | null type user.MixedLiterals = 200 | "success" | true +type user.MixedLiterals$stream = 200 | "success" | true type user.Name = string +type user.Name$stream = string type user.NestedMap = map> +type user.NestedMap$stream = map> type user.NestedParenUnion = int | string | bool | float[] +type user.NestedParenUnion$stream = int | string | bool | float[] type user.OptionalArray = int?[] +type user.OptionalArray$stream = int | null[] type user.OptionalUnion = int | string? +type user.OptionalUnion$stream = int | string | null type user.ParenUnion = int | string[] +type user.ParenUnion$stream = int | string[] type user.Producer = () -> string throws never +type user.Producer$stream = unknown type user.Result = user.TypeAliasSuccess | user.TypeAliasFailure +type user.Result$stream = user.TypeAliasSuccess$stream | user.TypeAliasFailure$stream type user.Role = "user" | "assistant" | "system" +type user.Role$stream = "user" | "assistant" | "system" type user.SimpleAlias = int +type user.SimpleAlias$stream = int type user.StringMap = map +type user.StringMap$stream = map type user.SuccessCode = 200 | 201 | 204 +type user.SuccessCode$stream = 200 | 201 | 204 type user.T = int +type user.T$stream = int type user.ThisIsAnExtremelyLongTypeAliasNameThatDefinitelyExceedsLimit = int | string | bool | float | null +type user.ThisIsAnExtremelyLongTypeAliasNameThatDefinitelyExceedsLimit$stream = int | string | bool | float | null type user.Tree = string | map | user.Tree[] | map> +type user.Tree$stream = string | map | user.Tree$stream[] | map> type user.TriviaAlias = int +type user.TriviaAlias$stream = int type user.TriviaAliasBlock = int +type user.TriviaAliasBlock$stream = int type user.TriviaArray = int[] +type user.TriviaArray$stream = int[] type user.TriviaDeepGeneric = map>> +type user.TriviaDeepGeneric$stream = map>> type user.TriviaFnType = (x: int) -> string throws never +type user.TriviaFnType$stream = unknown type user.TriviaFnTypeBlock = (x: int) -> string throws never +type user.TriviaFnTypeBlock$stream = unknown type user.TriviaGeneric = map +type user.TriviaGeneric$stream = map type user.TriviaGenericBlock = map +type user.TriviaGenericBlock$stream = map type user.TriviaLongFnType = (first_parameter: map, second_parameter: int | string[], third_parameter: map) -> string throws never +type user.TriviaLongFnType$stream = unknown type user.TriviaLongUnion = "alpha" | "bravo" | "charlie" | "delta" | "echo" | "foxtrot" | "golf" | "hotel" +type user.TriviaLongUnion$stream = "alpha" | "bravo" | "charlie" | "delta" | "echo" | "foxtrot" | "golf" | "hotel" type user.TriviaLongUnionBlock = "alpha" | "bravo" | "charlie" | "delta" | "echo" | "foxtrot" | "golf" | "hotel" +type user.TriviaLongUnionBlock$stream = "alpha" | "bravo" | "charlie" | "delta" | "echo" | "foxtrot" | "golf" | "hotel" type user.TriviaOptional = int? +type user.TriviaOptional$stream = int | null type user.TriviaParen = int | string[] +type user.TriviaParen$stream = int | string[] type user.TriviaUnion = int | string | bool +type user.TriviaUnion$stream = int | string | bool type user.TriviaUnionBlock = int | string | bool +type user.TriviaUnionBlock$stream = int | string | bool type user.UnionParamFn = (value: int | string) -> bool throws never +type user.UnionParamFn$stream = unknown type user.UnnamedParams = (int, int) -> int throws never +type user.UnnamedParams$stream = unknown type user.VeryLongNamePlusLongUnion = "alpha" | "bravo" | "charlie" | "delta" | "echo" | "foxtrot" | "golf" | "hotel" | "india" +type user.VeryLongNamePlusLongUnion$stream = "alpha" | "bravo" | "charlie" | "delta" | "echo" | "foxtrot" | "golf" | "hotel" | "india" type user.WideUnion = int | string | bool | float | null | int[] | string[] | bool[] | map | map +type user.WideUnion$stream = int | string | bool | float | null | int[] | string[] | bool[] | map | map diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_missing_throws/baml_tests__diagnostic_errors__function_type_missing_throws__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_missing_throws/baml_tests__diagnostic_errors__function_type_missing_throws__03_ppir.snap similarity index 85% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_missing_throws/baml_tests__diagnostic_errors__function_type_missing_throws__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_missing_throws/baml_tests__diagnostic_errors__function_type_missing_throws__03_ppir.snap index f9cefb817bd..8e244f85528 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_missing_throws/baml_tests__diagnostic_errors__function_type_missing_throws__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_missing_throws/baml_tests__diagnostic_errors__function_type_missing_throws__03_ppir.snap @@ -1,12 +1,18 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 45294 --- -=== HIR2 === +=== PPIR === class user.Holder { cb: (value: int) -> int opt_cb: (value: int) -> int? } +class user.Holder$stream { + cb: unknown + opt_cb: unknown | null +} type user.Alias = (x: int) -> int +type user.Alias$stream = unknown function user.lambda_param() -> int [expr] { { let apply = (f: (value: int) -> int, x: int) -> int { { } f(x) } } apply((value: int) -> int { { } value }, 1) } @@ -29,8 +35,14 @@ class user.Callbacks { on_done: (value: int) -> int throws never on_skip: (value: int) -> int throws never? } +class user.Callbacks$stream { + on_done: unknown + on_skip: unknown | null +} type user.ExplicitAlias = (x: int) -> int throws never +type user.ExplicitAlias$stream = unknown type user.OpenAlias = (x: int) -> int throws unknown +type user.OpenAlias$stream = unknown function user.explicit_let() -> int [expr] { { let f: (x: int) -> int throws never = (x: int) -> int { { } x } } f(1) } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_throws/baml_tests__diagnostic_errors__function_type_throws__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_throws/baml_tests__diagnostic_errors__function_type_throws__03_ppir.snap similarity index 89% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_throws/baml_tests__diagnostic_errors__function_type_throws__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_throws/baml_tests__diagnostic_errors__function_type_throws__03_ppir.snap index 960e2a03b18..e2a4cef3eaf 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_throws/baml_tests__diagnostic_errors__function_type_throws__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_type_throws/baml_tests__diagnostic_errors__function_type_throws__03_ppir.snap @@ -1,11 +1,16 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 45712 --- -=== HIR2 === +=== PPIR === class user.Holder { cb: (value: int) -> int throws never } +class user.Holder$stream { + cb: unknown +} type user.HiddenHandler = (value: int) -> int throws never +type user.HiddenHandler$stream = unknown function user.accept_hidden(cb: user.HiddenHandler) -> int [expr] { { } cb(1) } @@ -27,6 +32,9 @@ function user.risky(value: int) -> int [expr] { class user.Worker { factor: int } +class user.Worker$stream { + factor: int | null +} function user.builtin_map(cb: (value: int) -> int, values: int[]) -> int[] [expr] { { } values.map(cb) } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_types/baml_tests__diagnostic_errors__function_types__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_types/baml_tests__diagnostic_errors__function_types__03_ppir.snap similarity index 66% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_types/baml_tests__diagnostic_errors__function_types__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_types/baml_tests__diagnostic_errors__function_types__03_ppir.snap index bb2a03c032b..ed4c68032f2 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_types/baml_tests__diagnostic_errors__function_types__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/function_types/baml_tests__diagnostic_errors__function_types__03_ppir.snap @@ -1,16 +1,26 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 46060 --- -=== HIR2 === +=== PPIR === type user.BinaryOp = (a: int, b: int) -> int throws never +type user.BinaryOp$stream = unknown type user.Complex = (items: int[], lookup: map) -> string? throws never +type user.Complex$stream = unknown type user.Curried = (x: int) -> (y: int) -> int throws never throws never +type user.Curried$stream = unknown type user.FunctionFactory = (config: string) -> (int) -> int throws never throws never +type user.FunctionFactory$stream = unknown type user.IntToInt = (x: int) -> int throws never +type user.IntToInt$stream = unknown type user.MixedParams = (x: int, int, z: string) -> bool throws never +type user.MixedParams$stream = unknown type user.Producer = () -> string throws never +type user.Producer$stream = unknown type user.UnionParam = (value: int | string) -> bool throws never +type user.UnionParam$stream = unknown type user.UnnamedParams = (int, int) -> int throws never +type user.UnnamedParams$stream = unknown function user.GetTransform() -> (x: int) -> int throws never [expr] { { } 1 } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_call_ambiguity/baml_tests__diagnostic_errors__generic_call_ambiguity__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_call_ambiguity/baml_tests__diagnostic_errors__generic_call_ambiguity__03_ppir.snap similarity index 95% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_call_ambiguity/baml_tests__diagnostic_errors__generic_call_ambiguity__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_call_ambiguity/baml_tests__diagnostic_errors__generic_call_ambiguity__03_ppir.snap index 322ba456f42..51d871a3a7c 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_call_ambiguity/baml_tests__diagnostic_errors__generic_call_ambiguity__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_call_ambiguity/baml_tests__diagnostic_errors__generic_call_ambiguity__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 46411 --- -=== HIR2 === +=== PPIR === function user.ArrayCompareThenCall(f: int, x: int) -> int[] [expr] { { } [f Lt x, y()] } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_class_destructure_no_type_args/baml_tests__diagnostic_errors__generic_class_destructure_no_type_args__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_class_destructure_no_type_args/baml_tests__diagnostic_errors__generic_class_destructure_no_type_args__03_ppir.snap similarity index 73% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_class_destructure_no_type_args/baml_tests__diagnostic_errors__generic_class_destructure_no_type_args__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_class_destructure_no_type_args/baml_tests__diagnostic_errors__generic_class_destructure_no_type_args__03_ppir.snap index 7800346020e..26f4004c7be 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_class_destructure_no_type_args/baml_tests__diagnostic_errors__generic_class_destructure_no_type_args__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_class_destructure_no_type_args/baml_tests__diagnostic_errors__generic_class_destructure_no_type_args__03_ppir.snap @@ -1,10 +1,14 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 46761 --- -=== HIR2 === +=== PPIR === class user.Box { value: T } +class user.Box$stream { + value: T | null +} function user.main() -> int [expr] { { let boxed: user.Box = user.Box { value: 42 }; let Box { value: value } = boxed } value } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_error_arg_no_cascade/baml_tests__diagnostic_errors__generic_error_arg_no_cascade__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_error_arg_no_cascade/baml_tests__diagnostic_errors__generic_error_arg_no_cascade__03_ppir.snap similarity index 92% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_error_arg_no_cascade/baml_tests__diagnostic_errors__generic_error_arg_no_cascade__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_error_arg_no_cascade/baml_tests__diagnostic_errors__generic_error_arg_no_cascade__03_ppir.snap index 771d8ba15a9..8778a4a8392 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_error_arg_no_cascade/baml_tests__diagnostic_errors__generic_error_arg_no_cascade__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/generic_error_arg_no_cascade/baml_tests__diagnostic_errors__generic_error_arg_no_cascade__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 47042 --- -=== HIR2 === +=== PPIR === function user.broken_arg() -> int [expr] { { } consume([1, 2, 3].len()) } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/generics/baml_tests__diagnostic_errors__generics__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/generics/baml_tests__diagnostic_errors__generics__03_ppir.snap similarity index 82% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/generics/baml_tests__diagnostic_errors__generics__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/generics/baml_tests__diagnostic_errors__generics__03_ppir.snap index fb0d938659b..a397f75fd8b 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/generics/baml_tests__diagnostic_errors__generics__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/generics/baml_tests__diagnostic_errors__generics__03_ppir.snap @@ -1,44 +1,82 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 47392 --- -=== HIR2 === +=== PPIR === class user.Box { value: T } +class user.Box$stream { + value: T | null +} class user.Container { inner: user.Box } +class user.Container$stream { + inner: user.Box$stream | null +} class user.Factory { data: T } +class user.Factory$stream { + data: T | null +} class user.Foo { value: T } +class user.Foo$stream { + value: T | null +} class user.Holder { data: string } +class user.Holder$stream { + data: string | null +} class user.Maker { data: T } +class user.Maker$stream { + data: T | null +} class user.MaybeBox { value: T? } +class user.MaybeBox$stream { + value: T | null +} class user.Pair { first: A second: B } +class user.Pair$stream { + first: A | null + second: B | null +} class user.Plain { name: string } +class user.Plain$stream { + name: string | null +} class user.Shadow { value: T } +class user.Shadow$stream { + value: T | null +} class user.Stack { items: T[] } +class user.Stack$stream { + items: T[] +} class user.Wrapper { data: T } +class user.Wrapper$stream { + data: T | null +} function user.bad(x: T) -> T [expr] { { } x } @@ -55,10 +93,10 @@ function user.from_value(params: T) -> user.Maker [expr] { { } user.Maker { data: params } } function user.get(self: ?) -> T [expr] { - { } self.data + { } self.value } function user.get(self: ?) -> T [expr] { - { } self.value + { } self.data } function user.get_data(self: ?) -> T [expr] { { } self.data @@ -132,6 +170,12 @@ class user.Todo { completed: bool userId: int } +class user.Todo$stream { + id: int | null + title: string | null + completed: bool | null + userId: int | null +} function user.GetTodo() -> user.Todo [expr] { { } baml.fetch_as(baml.HttpRequest { method: baml.HttpMethod.Get, url: "dummyjson.com/tod..." }) } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/headers_edge_cases/baml_tests__diagnostic_errors__headers_edge_cases__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/headers_edge_cases/baml_tests__diagnostic_errors__headers_edge_cases__03_ppir.snap similarity index 98% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/headers_edge_cases/baml_tests__diagnostic_errors__headers_edge_cases__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/headers_edge_cases/baml_tests__diagnostic_errors__headers_edge_cases__03_ppir.snap index 101dcca782b..c5af16f862d 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/headers_edge_cases/baml_tests__diagnostic_errors__headers_edge_cases__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/headers_edge_cases/baml_tests__diagnostic_errors__headers_edge_cases__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 47736 --- -=== HIR2 === +=== PPIR === function user.ConsecutiveHeaders() -> string [expr] { { // [1] First Header; // [1] Second Header; // [1] Third Header; // [2] Subsection A; // [2] Subsection B; // [2] Subsection C } "multiple consecut..." } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/instanceof_removed/baml_tests__diagnostic_errors__instanceof_removed__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/instanceof_removed/baml_tests__diagnostic_errors__instanceof_removed__03_ppir.snap similarity index 72% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/instanceof_removed/baml_tests__diagnostic_errors__instanceof_removed__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/instanceof_removed/baml_tests__diagnostic_errors__instanceof_removed__03_ppir.snap index e453a26fe01..d485bd47420 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/instanceof_removed/baml_tests__diagnostic_errors__instanceof_removed__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/instanceof_removed/baml_tests__diagnostic_errors__instanceof_removed__03_ppir.snap @@ -1,13 +1,20 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 48017 --- -=== HIR2 === +=== PPIR === class user.Cat { name: string } +class user.Cat$stream { + name: string | null +} class user.Dog { breed: string } +class user.Dog$stream { + breed: string | null +} function user.check_instanceof(x: user.Cat | user.Dog) -> bool [expr] { { } } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/invalid_numeric_literals/baml_tests__diagnostic_errors__invalid_numeric_literals__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/invalid_numeric_literals/baml_tests__diagnostic_errors__invalid_numeric_literals__03_ppir.snap similarity index 87% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/invalid_numeric_literals/baml_tests__diagnostic_errors__invalid_numeric_literals__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/invalid_numeric_literals/baml_tests__diagnostic_errors__invalid_numeric_literals__03_ppir.snap index 8dd18883aa0..d8335929ec4 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/invalid_numeric_literals/baml_tests__diagnostic_errors__invalid_numeric_literals__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/invalid_numeric_literals/baml_tests__diagnostic_errors__invalid_numeric_literals__03_ppir.snap @@ -1,14 +1,19 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 48371 --- -=== HIR2 === +=== PPIR === type user.BadHexFlag = 0 | 0 +type user.BadHexFlag$stream = 0 | 0 function user.bad_literals() -> int [expr] { { let no_digits_hex = 0; let no_digits_octal = 0; let no_digits_binary = 0; let no_digits_underscores = 0; let bad_binary = 0; let bad_binary_underscores = 0; let bad_octal = 0; let bad_octal_underscores = 0; let upper_hex = 0; let upper_binary = 0; let upper_octal = 0; let too_large_decimal = 0; let too_large_decimal_wide = 0; let too_large_hex = 0; let too_large_binary = 0; let too_large_octal = 0; let beyond_int_range = 4611686018427387904; let bigint_no_digits = 0n; let bigint_bad_digit = 0n } 0 } type user.Mask = 15 | 0 +type user.Mask$stream = 15 | 0 type user.Permissions = 420 | 493 +type user.Permissions$stream = 420 | 493 type user.ReadFlag = 1 +type user.ReadFlag$stream = 1 function user.good_literals() -> int [expr] { { let hex = 255; let hex_lower = 51966; let octal = 493; let binary = 10; let plain_zero_prefixed = 0; let underscores = 1000000; let trailing_underscore = 1; let hex_underscores = 65535; let underscore_after_prefix = 15; let int_max = 4611686018427387903; let negative = Neg 255; let big_hex = 1208925819614629174706175n; let big_underscores = 1000n; let float_mantissa = 1000.5; let float_exponent = 1e10 } hex Add octal Add binary } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/is_pattern_negative/baml_tests__diagnostic_errors__is_pattern_negative__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/is_pattern_negative/baml_tests__diagnostic_errors__is_pattern_negative__03_ppir.snap similarity index 85% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/is_pattern_negative/baml_tests__diagnostic_errors__is_pattern_negative__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/is_pattern_negative/baml_tests__diagnostic_errors__is_pattern_negative__03_ppir.snap index dc472f3fe87..34e4c609934 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/is_pattern_negative/baml_tests__diagnostic_errors__is_pattern_negative__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/is_pattern_negative/baml_tests__diagnostic_errors__is_pattern_negative__03_ppir.snap @@ -1,13 +1,20 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 48719 --- -=== HIR2 === +=== PPIR === class user.WrapGeneric { val: T } +class user.WrapGeneric$stream { + val: T | null +} class user.WrapNonGeneric { x: int } +class user.WrapNonGeneric$stream { + x: int | null +} function user.binding_leak_if() -> int [expr] { { let v: int | string = 7 } if (v is x: int) { } x else { } 0 } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/json_alias/baml_tests__diagnostic_errors__json_alias__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/json_alias/baml_tests__diagnostic_errors__json_alias__03_ppir.snap similarity index 78% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/json_alias/baml_tests__diagnostic_errors__json_alias__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/json_alias/baml_tests__diagnostic_errors__json_alias__03_ppir.snap index 77469a23adb..2856c38669a 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/json_alias/baml_tests__diagnostic_errors__json_alias__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/json_alias/baml_tests__diagnostic_errors__json_alias__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 48999 --- -=== HIR2 === +=== PPIR === function user.BadAssign(j: baml.json.json) -> int [expr] { { } j } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/json_static_method_arity/baml_tests__diagnostic_errors__json_static_method_arity__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/json_static_method_arity/baml_tests__diagnostic_errors__json_static_method_arity__03_ppir.snap similarity index 84% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/json_static_method_arity/baml_tests__diagnostic_errors__json_static_method_arity__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/json_static_method_arity/baml_tests__diagnostic_errors__json_static_method_arity__03_ppir.snap index eceb3274559..4866f2702aa 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/json_static_method_arity/baml_tests__diagnostic_errors__json_static_method_arity__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/json_static_method_arity/baml_tests__diagnostic_errors__json_static_method_arity__03_ppir.snap @@ -1,10 +1,14 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 49276 --- -=== HIR2 === +=== PPIR === class user.Box { value: T } +class user.Box$stream { + value: T | null +} function user.bad_extra(j: baml.json.json) -> user.Box [expr] { { } Box.from_json(j) } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/lambda_errors/baml_tests__diagnostic_errors__lambda_errors__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/lambda_errors/baml_tests__diagnostic_errors__lambda_errors__03_ppir.snap similarity index 95% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/lambda_errors/baml_tests__diagnostic_errors__lambda_errors__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/lambda_errors/baml_tests__diagnostic_errors__lambda_errors__03_ppir.snap index d5e8792efef..a0730f5e3ea 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/lambda_errors/baml_tests__diagnostic_errors__lambda_errors__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/lambda_errors/baml_tests__diagnostic_errors__lambda_errors__03_ppir.snap @@ -1,8 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs -assertion_line: 33113 +assertion_line: 49564 --- -=== HIR2 === +=== PPIR === function user.test_arity_mismatch() -> int[] [expr] { { let items: int[] = [1, 2, 3] } items.map((x, y) -> { { } x }) } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/lexical_scoping_errors/baml_tests__diagnostic_errors__lexical_scoping_errors__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/lexical_scoping_errors/baml_tests__diagnostic_errors__lexical_scoping_errors__03_ppir.snap similarity index 90% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/lexical_scoping_errors/baml_tests__diagnostic_errors__lexical_scoping_errors__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/lexical_scoping_errors/baml_tests__diagnostic_errors__lexical_scoping_errors__03_ppir.snap index e40908fe10b..9456b825db7 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/lexical_scoping_errors/baml_tests__diagnostic_errors__lexical_scoping_errors__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/lexical_scoping_errors/baml_tests__diagnostic_errors__lexical_scoping_errors__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 49845 --- -=== HIR2 === +=== PPIR === function user.block_does_not_leak(b: bool) -> int [expr] { { if (b) { let a = 1 } } a } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/match_exhaustiveness/baml_tests__diagnostic_errors__match_exhaustiveness__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/match_exhaustiveness/baml_tests__diagnostic_errors__match_exhaustiveness__03_ppir.snap similarity index 92% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/match_exhaustiveness/baml_tests__diagnostic_errors__match_exhaustiveness__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/match_exhaustiveness/baml_tests__diagnostic_errors__match_exhaustiveness__03_ppir.snap index d143108cdfa..284339f622d 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/match_exhaustiveness/baml_tests__diagnostic_errors__match_exhaustiveness__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/match_exhaustiveness/baml_tests__diagnostic_errors__match_exhaustiveness__03_ppir.snap @@ -1,46 +1,84 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 50133 --- -=== HIR2 === +=== PPIR === class user.Bird { name: string } +class user.Bird$stream { + name: string | null +} class user.Cat { name: string } +class user.Cat$stream { + name: string | null +} class user.Dog { name: string } +class user.Dog$stream { + name: string | null +} class user.Failure { reason: string } +class user.Failure$stream { + reason: string | null +} class user.Fish { name: string } +class user.Fish$stream { + name: string | null +} class user.Pending { eta: int } +class user.Pending$stream { + eta: int | null +} class user.Success { data: string } +class user.Success$stream { + data: string | null +} enum user.DispatchState {Alpha, Beta, Gamma, Delta} enum user.Status {Active, Inactive, Pending} type user.AlwaysFalse = false +type user.AlwaysFalse$stream = false type user.AlwaysTrue = true +type user.AlwaysTrue$stream = true type user.CustomBool = true | false +type user.CustomBool$stream = true | false type user.DoubleMaybe = user.MaybeResult? +type user.DoubleMaybe$stream = user.MaybeResult$stream | null type user.FullResult = user.Success | user.Failure | user.Pending +type user.FullResult$stream = user.Success$stream | user.Failure$stream | user.Pending$stream type user.HttpCreated = 201 +type user.HttpCreated$stream = 201 type user.HttpOk = 200 +type user.HttpOk$stream = 200 type user.MaybeOk = 200? +type user.MaybeOk$stream = 200 | null type user.MaybeResult = user.Result? +type user.MaybeResult$stream = user.Result$stream | null type user.MixedLiterals = 200 | "success" | true +type user.MixedLiterals$stream = 200 | "success" | true type user.OkCode = 200 +type user.OkCode$stream = 200 type user.OkOrCreated = user.OkCode | 201 +type user.OkOrCreated$stream = user.OkCode$stream | 201 type user.Result = user.Success | user.Failure +type user.Result$stream = user.Success$stream | user.Failure$stream type user.Role = "user" | "assistant" | "system" +type user.Role$stream = "user" | "assistant" | "system" type user.SuccessCode = 200 | 201 | 204 +type user.SuccessCode$stream = 200 | 201 | 204 type user.SuccessOr200 = user.Success | 200 +type user.SuccessOr200$stream = user.Success$stream | 200 function user.BoolLiteralAfterTypedBool(b: bool) -> string [expr] { { } match (b) { x: bool => "any bool", true => "unreachable" } } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_bare_name_rejected/baml_tests__diagnostic_errors__namespaces_bare_name_rejected__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_bare_name_rejected/baml_tests__diagnostic_errors__namespaces_bare_name_rejected__03_ppir.snap similarity index 64% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_bare_name_rejected/baml_tests__diagnostic_errors__namespaces_bare_name_rejected__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_bare_name_rejected/baml_tests__diagnostic_errors__namespaces_bare_name_rejected__03_ppir.snap index f57f537b892..53fbc881f87 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_bare_name_rejected/baml_tests__diagnostic_errors__namespaces_bare_name_rejected__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_bare_name_rejected/baml_tests__diagnostic_errors__namespaces_bare_name_rejected__03_ppir.snap @@ -1,13 +1,20 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 50488 --- -=== HIR2 === +=== PPIR === class user.Config { key: string } +class user.Config$stream { + key: string | null +} class user.llm.Response { text: string } +class user.llm.Response$stream { + text: string | null +} function user.llm.UseConfig(cfg: Config) -> user.llm.Response [expr] { { } user.llm.Response { text: cfg.key } } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_conflict/baml_tests__diagnostic_errors__namespaces_conflict__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_conflict/baml_tests__diagnostic_errors__namespaces_conflict__03_hir.snap deleted file mode 100644 index 1b638023836..00000000000 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_conflict/baml_tests__diagnostic_errors__namespaces_conflict__03_hir.snap +++ /dev/null @@ -1,11 +0,0 @@ ---- -source: crates/baml_tests/src/generated_tests.rs ---- -=== HIR2 === -class user.llm.Response { - text: string -} -class user.llm.Response { - body: string - status: int -} diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_conflict/baml_tests__diagnostic_errors__namespaces_conflict__03_ppir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_conflict/baml_tests__diagnostic_errors__namespaces_conflict__03_ppir.snap new file mode 100644 index 00000000000..c587352f8bf --- /dev/null +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_conflict/baml_tests__diagnostic_errors__namespaces_conflict__03_ppir.snap @@ -0,0 +1,19 @@ +--- +source: crates/baml_tests/src/generated_tests.rs +assertion_line: 50907 +--- +=== PPIR === +class user.llm.Response { + text: string +} +class user.llm.Response$stream { + text: string | null +} +class user.llm.Response { + body: string + status: int +} +class user.llm.Response$stream { + body: string | null + status: int | null +} diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_stream_direct_ref/baml_tests__diagnostic_errors__namespaces_stream_direct_ref__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_stream_direct_ref/baml_tests__diagnostic_errors__namespaces_stream_direct_ref__03_ppir.snap similarity index 61% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_stream_direct_ref/baml_tests__diagnostic_errors__namespaces_stream_direct_ref__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_stream_direct_ref/baml_tests__diagnostic_errors__namespaces_stream_direct_ref__03_ppir.snap index bce134b04ab..f7bfad32e40 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_stream_direct_ref/baml_tests__diagnostic_errors__namespaces_stream_direct_ref__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/namespaces_stream_direct_ref/baml_tests__diagnostic_errors__namespaces_stream_direct_ref__03_ppir.snap @@ -1,17 +1,28 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 51325 --- -=== HIR2 === +=== PPIR === class user.Config { key: string } +class user.Config$stream { + key: string | null +} class user.Response { text: string } +class user.Response$stream { + text: string | null +} class user.RootWithStreamFields { own_stream: user.Config$stream llm_stream: root.llm.Config$stream } +class user.RootWithStreamFields$stream { + own_stream: user.Config$stream | null + llm_stream: root.llm.Config$stream | null +} function user.RootUsesLlmStream(r: root.llm.Response$stream) -> string [expr] { { } r.text } @@ -21,13 +32,23 @@ function user.RootUsesOwnStream(c: user.Config$stream) -> string [expr] { class user.llm.Config { model: string } +class user.llm.Config$stream { + model: string | null +} class user.llm.LlmWithStreamFields { own_stream: user.llm.Response$stream root_stream: root.Config$stream } +class user.llm.LlmWithStreamFields$stream { + own_stream: user.llm.Response$stream | null + root_stream: root.Config$stream | null +} class user.llm.Response { text: string } +class user.llm.Response$stream { + text: string | null +} function user.llm.LlmUsesOwnStream(r: user.llm.Response$stream) -> string [expr] { { } r.text } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/null_handling/baml_tests__diagnostic_errors__null_handling__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/null_handling/baml_tests__diagnostic_errors__null_handling__03_ppir.snap similarity index 87% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/null_handling/baml_tests__diagnostic_errors__null_handling__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/null_handling/baml_tests__diagnostic_errors__null_handling__03_ppir.snap index d51b7e79b2c..c2a68bc190b 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/null_handling/baml_tests__diagnostic_errors__null_handling__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/null_handling/baml_tests__diagnostic_errors__null_handling__03_ppir.snap @@ -1,27 +1,48 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 51674 --- -=== HIR2 === +=== PPIR === class user.Address { street: string zip: string? } +class user.Address$stream { + street: string | null + zip: string | null +} class user.Node { value: int next: user.Node? children: user.Node[]? labels: map? } +class user.Node$stream { + value: int | null + next: user.Node$stream | null + children: user.Node$stream[] | null + labels: map | null +} class user.Profile { name: string address: user.Address? scores: int[]? settings: map? } +class user.Profile$stream { + name: string | null + address: user.Address$stream | null + scores: int[] | null + settings: map | null +} class user.User { id: int profile: user.Profile? } +class user.User$stream { + id: int | null + profile: user.Profile$stream | null +} function user.Combined(user: user.User?, node: user.Node?, items: int[]?) -> string [expr] { { let e1 = user?.profile?.address?.street NullCoalesce "unknown"; let e2 = node?.children?.[node?.value NullCoalesce 0]; let e3 = user?.profile?.name NullCoalesce node?.labels?.["name"]?.value.to_string() NullCoalesce "fallback"; node?.children?.[0].next?.value = user?.id NullCoalesce 0; node?.value Add= items?.[0] NullCoalesce 1; let e4 = ; let e5 = node?.children?.[user?.profile?.scores?.[0] NullCoalesce 0].value; let e6 = node?.labels?.["first"]?.children?.[0].value; node?.labels?.["counter"].value = items?.[0] NullCoalesce 0 Add 1; node?.labels?.["counter"].value Add= items?.[0] NullCoalesce 0; node?.children?.[node?.value NullCoalesce 0]?.next?.value = node?.value NullCoalesce 0; return e3 } } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/numeric_invariance/baml_tests__diagnostic_errors__numeric_invariance__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/numeric_invariance/baml_tests__diagnostic_errors__numeric_invariance__03_ppir.snap similarity index 94% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/numeric_invariance/baml_tests__diagnostic_errors__numeric_invariance__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/numeric_invariance/baml_tests__diagnostic_errors__numeric_invariance__03_ppir.snap index 67b5f758b8a..4462c2448d4 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/numeric_invariance/baml_tests__diagnostic_errors__numeric_invariance__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/numeric_invariance/baml_tests__diagnostic_errors__numeric_invariance__03_ppir.snap @@ -1,10 +1,14 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 51955 --- -=== HIR2 === +=== PPIR === class user.BigintHolder { count: bigint } +class user.BigintHolder$stream { + count: bigint | null +} function user.BigintParamDefaultInt(x: bigint = 0) -> bigint [expr] { { } x } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/optional_parameter_defaults/baml_tests__diagnostic_errors__optional_parameter_defaults__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/optional_parameter_defaults/baml_tests__diagnostic_errors__optional_parameter_defaults__03_ppir.snap similarity index 91% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/optional_parameter_defaults/baml_tests__diagnostic_errors__optional_parameter_defaults__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/optional_parameter_defaults/baml_tests__diagnostic_errors__optional_parameter_defaults__03_ppir.snap index 50dadcb64bc..7101256d9eb 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/optional_parameter_defaults/baml_tests__diagnostic_errors__optional_parameter_defaults__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/optional_parameter_defaults/baml_tests__diagnostic_errors__optional_parameter_defaults__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 52309 --- -=== HIR2 === +=== PPIR === function user.BadDefaultPositional() -> string [expr] { { } Search("cats", 5) } @@ -38,8 +39,13 @@ function user.Search(query: string, max_results: int = 10, filter: string = "non class user.Counter { value: int } +class user.Counter$stream { + value: int | null +} type user.NamedFilter = (query: string, filter?: string?) -> int throws never +type user.NamedFilter$stream = unknown type user.NamedLimit = (query: string, limit?: string?) -> int throws never +type user.NamedLimit$stream = unknown function user.Current(self: ? = null) -> int [expr] { { } self.value } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/parser_constructors/baml_tests__diagnostic_errors__parser_constructors__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/parser_constructors/baml_tests__diagnostic_errors__parser_constructors__03_ppir.snap similarity index 84% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/parser_constructors/baml_tests__diagnostic_errors__parser_constructors__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/parser_constructors/baml_tests__diagnostic_errors__parser_constructors__03_ppir.snap index 884d06f08c2..7b7db5c2c6c 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/parser_constructors/baml_tests__diagnostic_errors__parser_constructors__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/parser_constructors/baml_tests__diagnostic_errors__parser_constructors__03_ppir.snap @@ -1,11 +1,16 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 52803 --- -=== HIR2 === +=== PPIR === class user.Point { x: int y: int } +class user.Point$stream { + x: int | null + y: int | null +} function user.boolArray() -> bool[] [expr] { { } [true, false, true] } @@ -28,10 +33,18 @@ class user.Point { x: int y: int } +class user.Point$stream { + x: int | null + y: int | null +} class user.Vec2D { p: user.Point q: user.Point } +class user.Vec2D$stream { + p: user.Point$stream | null + q: user.Point$stream | null +} function user.point() -> user.Point [expr] { { } user.Point { x: 1, y: 2 } } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_array_rest_binding/baml_tests__diagnostic_errors__patterns_array_rest_binding__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_array_rest_binding/baml_tests__diagnostic_errors__patterns_array_rest_binding__03_ppir.snap similarity index 93% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_array_rest_binding/baml_tests__diagnostic_errors__patterns_array_rest_binding__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_array_rest_binding/baml_tests__diagnostic_errors__patterns_array_rest_binding__03_ppir.snap index c6df38a37f4..5c115a7312d 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_array_rest_binding/baml_tests__diagnostic_errors__patterns_array_rest_binding__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_array_rest_binding/baml_tests__diagnostic_errors__patterns_array_rest_binding__03_ppir.snap @@ -1,11 +1,14 @@ --- source: crates/baml_tests/src/generated_tests.rs -assertion_line: 51952 +assertion_line: 53351 --- -=== HIR2 === +=== PPIR === class user.Wrapper { value: int } +class user.Wrapper$stream { + value: int | null +} function user.nested_bare_rest(xs: int[]) -> int [expr] { { } match (xs) { [..[..]] => 1, _ => 0 } } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_class_destructure/baml_tests__diagnostic_errors__patterns_class_destructure__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_class_destructure/baml_tests__diagnostic_errors__patterns_class_destructure__03_ppir.snap similarity index 93% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_class_destructure/baml_tests__diagnostic_errors__patterns_class_destructure__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_class_destructure/baml_tests__diagnostic_errors__patterns_class_destructure__03_ppir.snap index 8be40e3644d..45c380a7b8a 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_class_destructure/baml_tests__diagnostic_errors__patterns_class_destructure__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_class_destructure/baml_tests__diagnostic_errors__patterns_class_destructure__03_ppir.snap @@ -1,31 +1,56 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 53641 --- -=== HIR2 === +=== PPIR === class user.Address { zip: int } +class user.Address$stream { + zip: int | null +} class user.Admin { age: string } +class user.Admin$stream { + age: string | null +} class user.Box { value: T } +class user.Box$stream { + value: T | null +} class user.OptionalPerson { age: int? } +class user.OptionalPerson$stream { + age: int | null +} class user.Person { age: int flexible_age: int | string address: user.Address } +class user.Person$stream { + age: int | null + flexible_age: int | string | null + address: user.Address$stream | null +} class user.SameNameInner { field: int } +class user.SameNameInner$stream { + field: int | null +} class user.SameNameOuter { field: user.SameNameInner other: user.SameNameInner } +class user.SameNameOuter$stream { + field: user.SameNameInner$stream | null + other: user.SameNameInner$stream | null +} function user.class_destructure_box(boxed: user.Box) -> int [expr] { { let Box { value: value } = boxed } value } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_class_destructure_namespaces/baml_tests__diagnostic_errors__patterns_class_destructure_namespaces__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_class_destructure_namespaces/baml_tests__diagnostic_errors__patterns_class_destructure_namespaces__03_ppir.snap similarity index 87% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_class_destructure_namespaces/baml_tests__diagnostic_errors__patterns_class_destructure_namespaces__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_class_destructure_namespaces/baml_tests__diagnostic_errors__patterns_class_destructure_namespaces__03_ppir.snap index 2ef0788a3e5..f878e34cccc 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_class_destructure_namespaces/baml_tests__diagnostic_errors__patterns_class_destructure_namespaces__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_class_destructure_namespaces/baml_tests__diagnostic_errors__patterns_class_destructure_namespaces__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 54000 --- -=== HIR2 === +=== PPIR === function user.namespace_relative_generic_class_type_pattern_requires_type_args(boxed: llm.openai.Box) -> int [expr] { { } match (boxed) { llm.openai.Box => 1 } } @@ -20,6 +21,12 @@ function user.namespaced_non_generic_class_type_pattern_rejects_type_args(respon class user.llm.openai.Box { value: T } +class user.llm.openai.Box$stream { + value: T | null +} class user.llm.openai.Response { score: int } +class user.llm.openai.Response$stream { + score: int | null +} diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_new/baml_tests__diagnostic_errors__patterns_new__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_new/baml_tests__diagnostic_errors__patterns_new__03_ppir.snap similarity index 89% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_new/baml_tests__diagnostic_errors__patterns_new__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_new/baml_tests__diagnostic_errors__patterns_new__03_ppir.snap index 807a4dac154..d20f250fe1a 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_new/baml_tests__diagnostic_errors__patterns_new__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/patterns_new/baml_tests__diagnostic_errors__patterns_new__03_ppir.snap @@ -1,32 +1,58 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 54357 --- -=== HIR2 === +=== PPIR === class user.Bag { contents: int } +class user.Bag$stream { + contents: int | null +} class user.Box2 { first: bool second: int[]? } +class user.Box2$stream { + first: bool | null + second: int[] | null +} class user.Flagged { flag: bool note: string } +class user.Flagged$stream { + flag: bool | null + note: string | null +} class user.IntPair { a: int b: int } +class user.IntPair$stream { + a: int | null + b: int | null +} class user.Mixed { value: int | float | bool } +class user.Mixed$stream { + value: int | float | bool | null +} class user.Pair { kind: int | bool payload: int | string } +class user.Pair$stream { + kind: int | bool | null + payload: int | string | null +} class user.Team { scores: int[] } +class user.Team$stream { + scores: int[] +} enum user.Color3 {Red, Green, Blue} enum user.Direction4 {North, East, South, West} enum user.ExcessiveEnum {First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth, Eleventh, Twelfth} diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/runtime_id_misuse/baml_tests__diagnostic_errors__runtime_id_misuse__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/runtime_id_misuse/baml_tests__diagnostic_errors__runtime_id_misuse__03_ppir.snap similarity index 89% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/runtime_id_misuse/baml_tests__diagnostic_errors__runtime_id_misuse__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/runtime_id_misuse/baml_tests__diagnostic_errors__runtime_id_misuse__03_ppir.snap index 3ceb2fad8a2..ba48e5993cd 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/runtime_id_misuse/baml_tests__diagnostic_errors__runtime_id_misuse__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/runtime_id_misuse/baml_tests__diagnostic_errors__runtime_id_misuse__03_ppir.snap @@ -1,11 +1,16 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 54638 --- -=== HIR2 === +=== PPIR === class user.WithId { field_id: string $id: string } +class user.WithId$stream { + field_id: string | null + $id: string | null +} function user.$id() -> int [expr] { { } 1 } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/self_in_body/baml_tests__diagnostic_errors__self_in_body__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/self_in_body/baml_tests__diagnostic_errors__self_in_body__03_ppir.snap similarity index 92% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/self_in_body/baml_tests__diagnostic_errors__self_in_body__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/self_in_body/baml_tests__diagnostic_errors__self_in_body__03_ppir.snap index c03c736939e..dad73d4f26d 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/self_in_body/baml_tests__diagnostic_errors__self_in_body__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/self_in_body/baml_tests__diagnostic_errors__self_in_body__03_ppir.snap @@ -1,10 +1,14 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 54919 --- -=== HIR2 === +=== PPIR === class user.Box { v: T } +class user.Box$stream { + v: T | null +} function user.bind_self(self: ?, other: Self) -> bool [expr] { { let a: Self = other } true } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/simple_function/baml_tests__diagnostic_errors__simple_function__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/simple_function/baml_tests__diagnostic_errors__simple_function__03_ppir.snap similarity index 58% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/simple_function/baml_tests__diagnostic_errors__simple_function__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/simple_function/baml_tests__diagnostic_errors__simple_function__03_ppir.snap index f38fee9344c..ad157116ec9 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/simple_function/baml_tests__diagnostic_errors__simple_function__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/simple_function/baml_tests__diagnostic_errors__simple_function__03_ppir.snap @@ -1,11 +1,16 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 55199 --- -=== HIR2 === +=== PPIR === class user.User { name: string age: int } +class user.User$stream { + name: string | null + age: int | null +} function user.HelloWorld(name: string, client: baml.llm.Client = GPT4) -> string [llm] { baml.llm.call_llm_function(client, "HelloWorld", map { "name": name }) } @@ -15,6 +20,15 @@ function user.HelloWorld$build_request(name: string, client: baml.llm.Client = G function user.HelloWorld$build_request_stream(name: string, client: baml.llm.Client = GPT4) -> baml.http.Request [expr] { baml.llm.build_request_stream(client, "HelloWorld", map { "name": name }) } +function user.HelloWorld$parse(json: string, client: baml.llm.Client = GPT4) -> string [expr] { + baml.llm.parse(json) +} +function user.HelloWorld$parse_stream(sse: baml.http.SseStream, client: baml.llm.Client = GPT4) -> baml.llm.Stream [expr] { + client.__make_stream(sse) +} function user.HelloWorld$render_prompt(name: string, client: baml.llm.Client = GPT4) -> baml.llm.PromptAst [expr] { baml.llm.render_prompt(client, "HelloWorld", map { "name": name }) } +function user.HelloWorld$stream(name: string, client: baml.llm.Client = GPT4) -> baml.llm.Stream [expr] { + baml.llm.stream_llm_function(client, "HelloWorld", map { "name": name }) +} diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/simple_type_error/baml_tests__diagnostic_errors__simple_type_error__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/simple_type_error/baml_tests__diagnostic_errors__simple_type_error__03_ppir.snap similarity index 76% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/simple_type_error/baml_tests__diagnostic_errors__simple_type_error__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/simple_type_error/baml_tests__diagnostic_errors__simple_type_error__03_ppir.snap index e3261dbb322..9afb3fec985 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/simple_type_error/baml_tests__diagnostic_errors__simple_type_error__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/simple_type_error/baml_tests__diagnostic_errors__simple_type_error__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 55479 --- -=== HIR2 === +=== PPIR === function user.Foo() -> int [expr] { { } 1 Add "foo" } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/stream_types/baml_tests__diagnostic_errors__stream_types__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/stream_types/baml_tests__diagnostic_errors__stream_types__03_hir.snap deleted file mode 100644 index 079fc0c5782..00000000000 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/stream_types/baml_tests__diagnostic_errors__stream_types__03_hir.snap +++ /dev/null @@ -1,205 +0,0 @@ ---- -source: crates/baml_tests/src/generated_tests.rs ---- -=== HIR2 === -class user.AttrFoo { - x: int -} -class user.Config { - id: int - name: string - data: user.AttrFoo -} -class user.WithBlockAttrs { - a: int - b: string -} -class user.Bar { - ref: user.Foo - items: int[] - nested: user.Foo[] - mapping: map - opt: int? -} -class user.Foo { - a: int - b: string - c: float - d: bool -} -class user.ApiCall { - request: baml.http.Request - label: string -} -class user.MixedBuiltin { - requests: baml.http.Request[] - metadata: map - maybe_request: baml.http.Request? - union_request: baml.http.Request | string -} -class user.WithResponse { - response: baml.http.Response - status: string -} -class user.WithStreamRef { - partial: baml.http.Request$stream -} -class user.Complex { - color: user.Color - literal: 5 - str_literal: "hello" - union_field: int | string[] - alias_field: user.StringAlias - nested_list: user.Inner[][] - optional_class: user.Inner? - union_with_null: int | null | string -} -class user.Inner { - value: int -} -enum user.Color {Red, Green, Blue} -type user.AliasToClass = user.Inner -type user.StringAlias = string -class user.AllDone { - a: int - b: string - c: user.EdgeFoo -} -class user.AllMustExist { - a: int - b: string - c: float -} -class user.EdgeFoo { - x: int -} -class user.MustExistClass { - v: int -} -class user.NeverFields { - lit_int: 42 - lit_str: "fixed" - lit_bool: true -} -class user.SelfRef { - name: string - children: user.SelfRef[] -} -class user.UnionWithMustExist { - mixed: user.MustExistClass | 5 -} -class user.AllDefaults { - name: string - age: int - score: float - active: bool - type: "resume" - version: 42 - status: user.Status - edu: user.Education - scores: int[] - education: user.Education[] - nested_edu: user.Education[][] - edu_map: map - data: user.AliasedType - mixed: int | user.Education - maybe: string? - maybe_list: int[]? -} -class user.Container { - matrix: int[][] - grid: user.TreeNode[][] - groups: map -} -class user.DynamicClass { - name: string -} -class user.Education { - school: string - year: int -} -class user.Inner { - value: string -} -class user.Outer { - inner: user.Inner -} -class user.Primitives { - name: string - count: int - flag: bool - score: float -} -class user.Resume { - name: string - age: int - type: "resume" - status: user.Status - education: user.Education[] - scores: int[] - metadata: map -} -class user.TreeNode { - value: string - children: user.TreeNode[] -} -class user.WithEnum { - status: user.Status -} -class user.WithLists { - strings: string[] - ints: int[] - classes: user.Inner[] -} -class user.WithLiterals { - type: "resume" - version: 1 - enabled: true -} -class user.WithMaps { - simple: map - complex: map -} -class user.WithNested { - matrix: int[][] - class_matrix: user.Inner[][] - nested_map: map - class_nested_map: map -} -class user.WithOptionals { - name: string? - inner: user.Inner? - items: int[]? -} -class user.WithUnions { - simple: int | string - with_class: user.Inner | user.Primitives - mixed: int | user.Inner -} -enum user.Status {Active, Inactive} -type user.AliasedType = string | int -type user.Bar = user.Foo | bool -type user.ClassAlias = user.Inner -type user.Foo = int | string -type user.MixedType = int | user.Education -type user.OptionalAlias = user.Inner? -type user.SimpleAlias = string -type user.UnionAlias = int | user.Inner -class user.foo.NsClass { - value: string -} -class user.foo.NsRefToTop { - inner: root.Inner - status: root.Status - items: root.Inner[] - alias_ref: root.ClassAlias -} -enum user.foo.NsEnum {Alpha, Beta} -type user.foo.NsAlias = string | int -class user.TopRefToNs { - ns_class: root.foo.NsClass - ns_enum: root.foo.NsEnum - ns_items: root.foo.NsClass[] - ns_map: map - ns_alias: root.foo.NsAlias -} diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/stream_types/baml_tests__diagnostic_errors__stream_types__03_ppir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/stream_types/baml_tests__diagnostic_errors__stream_types__03_ppir.snap new file mode 100644 index 00000000000..d07a4af2bbc --- /dev/null +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/stream_types/baml_tests__diagnostic_errors__stream_types__03_ppir.snap @@ -0,0 +1,404 @@ +--- +source: crates/baml_tests/src/generated_tests.rs +assertion_line: 56253 +--- +=== PPIR === +class user.AttrFoo { + x: int +} +class user.AttrFoo$stream { + x: int | null +} +class user.Config { + id: int + name: string + data: user.AttrFoo +} +class user.Config$stream { + id: int + name: string + data: user.AttrFoo +} +class user.WithBlockAttrs { + a: int + b: string +} +class user.WithBlockAttrs$stream { + a: int | null + b: string | null +} +class user.Bar { + ref: user.Foo + items: int[] + nested: user.Foo[] + mapping: map + opt: int? +} +class user.Bar$stream { + ref: user.Foo$stream | null + items: int[] + nested: user.Foo$stream[] + mapping: map + opt: int | null +} +class user.Foo { + a: int + b: string + c: float + d: bool +} +class user.Foo$stream { + a: int | null + b: string | null + c: float | null + d: bool | null +} +class user.ApiCall { + request: baml.http.Request + label: string +} +class user.ApiCall$stream { + request: baml.http.Request$stream | null + label: string | null +} +class user.MixedBuiltin { + requests: baml.http.Request[] + metadata: map + maybe_request: baml.http.Request? + union_request: baml.http.Request | string +} +class user.MixedBuiltin$stream { + requests: baml.http.Request$stream[] + metadata: map + maybe_request: baml.http.Request$stream | null + union_request: baml.http.Request$stream | string | null +} +class user.WithResponse { + response: baml.http.Response + status: string +} +class user.WithResponse$stream { + response: baml.http.Response$stream | null + status: string | null +} +class user.WithStreamRef { + partial: baml.http.Request$stream +} +class user.WithStreamRef$stream { + partial: baml.http.Request$stream | null +} +class user.Complex { + color: user.Color + literal: 5 + str_literal: "hello" + union_field: int | string[] + alias_field: user.StringAlias + nested_list: user.Inner[][] + optional_class: user.Inner? + union_with_null: int | null | string +} +class user.Complex$stream { + color: user.Color | null + literal: 5 + str_literal: "hello" + union_field: int | string[] | null + alias_field: string | null + nested_list: user.Inner$stream[][] + optional_class: user.Inner$stream | null + union_with_null: int | null | string +} +class user.Inner { + value: int +} +class user.Inner$stream { + value: int | null +} +enum user.Color {Red, Green, Blue} +type user.AliasToClass = user.Inner +type user.AliasToClass$stream = user.Inner$stream +type user.StringAlias = string +type user.StringAlias$stream = string +class user.AllDone { + a: int + b: string + c: user.EdgeFoo +} +class user.AllDone$stream { + a: int + b: string + c: user.EdgeFoo +} +class user.AllMustExist { + a: int + b: string + c: float +} +class user.AllMustExist$stream { + a: int + b: string + c: float +} +class user.EdgeFoo { + x: int +} +class user.EdgeFoo$stream { + x: int | null +} +class user.MustExistClass { + v: int +} +class user.MustExistClass$stream { + v: int | null +} +class user.NeverFields { + lit_int: 42 + lit_str: "fixed" + lit_bool: true +} +class user.NeverFields$stream { + lit_int: 42 + lit_str: "fixed" + lit_bool: true +} +class user.SelfRef { + name: string + children: user.SelfRef[] +} +class user.SelfRef$stream { + name: string | null + children: user.SelfRef$stream[] +} +class user.UnionWithMustExist { + mixed: user.MustExistClass | 5 +} +class user.UnionWithMustExist$stream { + mixed: user.MustExistClass$stream | 5 +} +class user.AllDefaults { + name: string + age: int + score: float + active: bool + type: "resume" + version: 42 + status: user.Status + edu: user.Education + scores: int[] + education: user.Education[] + nested_edu: user.Education[][] + edu_map: map + data: user.AliasedType + mixed: int | user.Education + maybe: string? + maybe_list: int[]? +} +class user.AllDefaults$stream { + name: string | null + age: int | null + score: float | null + active: bool | null + type: "resume" + version: 42 + status: user.Status | null + edu: user.Education$stream | null + scores: int[] + education: user.Education$stream[] + nested_edu: user.Education$stream[][] + edu_map: map + data: string | int | null + mixed: int | user.Education$stream | null + maybe: string | null + maybe_list: int[] | null +} +class user.Container { + matrix: int[][] + grid: user.TreeNode[][] + groups: map +} +class user.Container$stream { + matrix: int[][] + grid: user.TreeNode$stream[][] + groups: map +} +class user.DynamicClass { + name: string +} +class user.DynamicClass$stream { + name: string | null +} +class user.Education { + school: string + year: int +} +class user.Education$stream { + school: string | null + year: int | null +} +class user.Inner { + value: string +} +class user.Inner$stream { + value: string | null +} +class user.Outer { + inner: user.Inner +} +class user.Outer$stream { + inner: user.Inner$stream | null +} +class user.Primitives { + name: string + count: int + flag: bool + score: float +} +class user.Primitives$stream { + name: string | null + count: int | null + flag: bool | null + score: float | null +} +class user.Resume { + name: string + age: int + type: "resume" + status: user.Status + education: user.Education[] + scores: int[] + metadata: map +} +class user.Resume$stream { + name: string | null + age: int | null + type: "resume" + status: user.Status | null + education: user.Education$stream[] + scores: int[] + metadata: map +} +class user.TreeNode { + value: string + children: user.TreeNode[] +} +class user.TreeNode$stream { + value: string | null + children: user.TreeNode$stream[] +} +class user.WithEnum { + status: user.Status +} +class user.WithEnum$stream { + status: user.Status | null +} +class user.WithLists { + strings: string[] + ints: int[] + classes: user.Inner[] +} +class user.WithLists$stream { + strings: string[] + ints: int[] + classes: user.Inner$stream[] +} +class user.WithLiterals { + type: "resume" + version: 1 + enabled: true +} +class user.WithLiterals$stream { + type: "resume" + version: 1 + enabled: true +} +class user.WithMaps { + simple: map + complex: map +} +class user.WithMaps$stream { + simple: map + complex: map +} +class user.WithNested { + matrix: int[][] + class_matrix: user.Inner[][] + nested_map: map + class_nested_map: map +} +class user.WithNested$stream { + matrix: int[][] + class_matrix: user.Inner$stream[][] + nested_map: map + class_nested_map: map +} +class user.WithOptionals { + name: string? + inner: user.Inner? + items: int[]? +} +class user.WithOptionals$stream { + name: string | null + inner: user.Inner$stream | null + items: int[] | null +} +class user.WithUnions { + simple: int | string + with_class: user.Inner | user.Primitives + mixed: int | user.Inner +} +class user.WithUnions$stream { + simple: int | string | null + with_class: user.Inner$stream | user.Primitives$stream | null + mixed: int | user.Inner$stream | null +} +enum user.Status {Active, Inactive} +type user.AliasedType = string | int +type user.AliasedType$stream = string | int +type user.Bar = user.Foo | bool +type user.Bar$stream = user.Foo$stream | bool +type user.ClassAlias = user.Inner +type user.ClassAlias$stream = user.Inner$stream +type user.Foo = int | string +type user.Foo$stream = int | string +type user.MixedType = int | user.Education +type user.MixedType$stream = int | user.Education$stream +type user.OptionalAlias = user.Inner? +type user.OptionalAlias$stream = user.Inner$stream | null +type user.SimpleAlias = string +type user.SimpleAlias$stream = string +type user.UnionAlias = int | user.Inner +type user.UnionAlias$stream = int | user.Inner$stream +class user.foo.NsClass { + value: string +} +class user.foo.NsClass$stream { + value: string | null +} +class user.foo.NsRefToTop { + inner: root.Inner + status: root.Status + items: root.Inner[] + alias_ref: root.ClassAlias +} +class user.foo.NsRefToTop$stream { + inner: root.Inner$stream | null + status: root.Status | null + items: root.Inner$stream[] + alias_ref: root.Inner$stream | null +} +enum user.foo.NsEnum {Alpha, Beta} +type user.foo.NsAlias = string | int +type user.foo.NsAlias$stream = string | int +class user.TopRefToNs { + ns_class: root.foo.NsClass + ns_enum: root.foo.NsEnum + ns_items: root.foo.NsClass[] + ns_map: map + ns_alias: root.foo.NsAlias +} +class user.TopRefToNs$stream { + ns_class: root.foo.NsClass$stream | null + ns_enum: root.foo.NsEnum | null + ns_items: root.foo.NsClass$stream[] + ns_map: map + ns_alias: string | int | null +} diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_expr_name_type_error/baml_tests__diagnostic_errors__test_expr_name_type_error__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_expr_name_type_error/baml_tests__diagnostic_errors__test_expr_name_type_error__03_ppir.snap similarity index 92% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_expr_name_type_error/baml_tests__diagnostic_errors__test_expr_name_type_error__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_expr_name_type_error/baml_tests__diagnostic_errors__test_expr_name_type_error__03_ppir.snap index f363089b1b2..fc776ec9aba 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_expr_name_type_error/baml_tests__diagnostic_errors__test_expr_name_type_error__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_expr_name_type_error/baml_tests__diagnostic_errors__test_expr_name_type_error__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 57021 --- -=== HIR2 === +=== PPIR === function user.$init_test_main(registry: testing.TestCollector) -> ? [expr] { { registry.register_test("a" Add 1, () -> void { { } null }, null); registry.register_test(42, () -> void { { } null }, null); registry.register_test_set("int_name", (testset: testing.TestCollector) -> void { { for i in [1, 2, 3] { testset.register_test(5 Add i, () -> { { } null }, null) } } null }, null) } null } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_expr_wrong_runner/baml_tests__diagnostic_errors__test_expr_wrong_runner__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_expr_wrong_runner/baml_tests__diagnostic_errors__test_expr_wrong_runner__03_ppir.snap similarity index 93% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_expr_wrong_runner/baml_tests__diagnostic_errors__test_expr_wrong_runner__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_expr_wrong_runner/baml_tests__diagnostic_errors__test_expr_wrong_runner__03_ppir.snap index 0a41fc3008c..f7d7a4dc2c6 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_expr_wrong_runner/baml_tests__diagnostic_errors__test_expr_wrong_runner__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_expr_wrong_runner/baml_tests__diagnostic_errors__test_expr_wrong_runner__03_ppir.snap @@ -1,7 +1,8 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 57301 --- -=== HIR2 === +=== PPIR === function user.$init_test_main(registry: testing.TestCollector) -> ? [expr] { { registry.register_test("wrong runner type", () -> void { { } assert.is_true(true) }, 42); registry.register_test("string as runner", () -> void { { } assert.is_true(true) }, "not a runner"); registry.register_test_set("wrong testset runner", (testset: testing.TestCollector) -> void { { testset.register_test("inner", () -> { { } assert.is_true(true) }, null) } null }, 42) } null } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_with_runner_ambiguity/baml_tests__diagnostic_errors__test_with_runner_ambiguity__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_with_runner_ambiguity/baml_tests__diagnostic_errors__test_with_runner_ambiguity__03_ppir.snap similarity index 84% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_with_runner_ambiguity/baml_tests__diagnostic_errors__test_with_runner_ambiguity__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_with_runner_ambiguity/baml_tests__diagnostic_errors__test_with_runner_ambiguity__03_ppir.snap index cac4811058b..3b53abd59f6 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_with_runner_ambiguity/baml_tests__diagnostic_errors__test_with_runner_ambiguity__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/test_with_runner_ambiguity/baml_tests__diagnostic_errors__test_with_runner_ambiguity__03_ppir.snap @@ -1,10 +1,14 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 57581 --- -=== HIR2 === +=== PPIR === class user.MyRunner { threshold: float } +class user.MyRunner$stream { + threshold: float | null +} function user.$init_test_main(registry: testing.TestCollector) -> ? [expr] { { registry.register_test("simple runner", () -> void { { } assert.is_true(true) }, my_runner); registry.register_test("call runner", () -> void { { } assert.is_true(true) }, testing.Quorum(5, 3)); registry.register_test("constructor runner", () -> void { { } assert.is_true(true) }, user.MyRunner { threshold: 0.5 }) } null } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/type_aliases/baml_tests__diagnostic_errors__type_aliases__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/type_aliases/baml_tests__diagnostic_errors__type_aliases__03_ppir.snap similarity index 64% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/type_aliases/baml_tests__diagnostic_errors__type_aliases__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/type_aliases/baml_tests__diagnostic_errors__type_aliases__03_ppir.snap index 12ee9bb605b..a70600416a3 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/type_aliases/baml_tests__diagnostic_errors__type_aliases__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/type_aliases/baml_tests__diagnostic_errors__type_aliases__03_ppir.snap @@ -1,10 +1,14 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 57931 --- -=== HIR2 === +=== PPIR === type user.Json = int | float | string | user.Json[] | map +type user.Json$stream = int | float | string | user.Json$stream[] | map type user.bar = int +type user.bar$stream = int type user.foo = user.bar +type user.foo$stream = user.bar$stream function user.Bar() -> user.foo [expr] { { } true } @@ -17,7 +21,11 @@ function user.Foo() -> user.foo [expr] { class user.NotJSON { inner: name } +class user.NotJSON$stream { + inner: name | null +} type user.JSON = int | float | string | bool | user.JSON[] | map +type user.JSON$stream = int | float | string | bool | user.JSON$stream[] | map function user.EchoJSON(i: user.JSON) -> user.JSON [expr] { { } user.NotJSON { inner: "Whoops" } } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/type_reflection_strict/baml_tests__diagnostic_errors__type_reflection_strict__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/type_reflection_strict/baml_tests__diagnostic_errors__type_reflection_strict__03_ppir.snap similarity index 90% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/type_reflection_strict/baml_tests__diagnostic_errors__type_reflection_strict__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/type_reflection_strict/baml_tests__diagnostic_errors__type_reflection_strict__03_ppir.snap index 0d161fafe2a..eaaecd9b38d 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/type_reflection_strict/baml_tests__diagnostic_errors__type_reflection_strict__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/type_reflection_strict/baml_tests__diagnostic_errors__type_reflection_strict__03_ppir.snap @@ -1,10 +1,14 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 58354 --- -=== HIR2 === +=== PPIR === class user.User { name: string } +class user.User$stream { + name: string | null +} function user.reflect_type_to_int() -> int [expr] { { let x: int = reflect.type_of(); return x } } diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/unknown_type_error/baml_tests__diagnostic_errors__unknown_type_error__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/unknown_type_error/baml_tests__diagnostic_errors__unknown_type_error__03_ppir.snap similarity index 88% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/unknown_type_error/baml_tests__diagnostic_errors__unknown_type_error__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/unknown_type_error/baml_tests__diagnostic_errors__unknown_type_error__03_ppir.snap index c251cb9f119..0027536321b 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/unknown_type_error/baml_tests__diagnostic_errors__unknown_type_error__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/unknown_type_error/baml_tests__diagnostic_errors__unknown_type_error__03_ppir.snap @@ -1,10 +1,14 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 58715 --- -=== HIR2 === +=== PPIR === class user.Envelope { payload: unknown } +class user.Envelope$stream { + payload: unknown +} enum user.Status {Active, Inactive} function user.Bar(x: unknown_param_type) -> int [expr] { { } 1 diff --git a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/void_return_type/baml_tests__diagnostic_errors__void_return_type__03_hir.snap b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/void_return_type/baml_tests__diagnostic_errors__void_return_type__03_ppir.snap similarity index 92% rename from baml_language/crates/baml_tests/snapshots/diagnostic_errors/void_return_type/baml_tests__diagnostic_errors__void_return_type__03_hir.snap rename to baml_language/crates/baml_tests/snapshots/diagnostic_errors/void_return_type/baml_tests__diagnostic_errors__void_return_type__03_ppir.snap index 77338cd25d6..2bd08bca335 100644 --- a/baml_language/crates/baml_tests/snapshots/diagnostic_errors/void_return_type/baml_tests__diagnostic_errors__void_return_type__03_hir.snap +++ b/baml_language/crates/baml_tests/snapshots/diagnostic_errors/void_return_type/baml_tests__diagnostic_errors__void_return_type__03_ppir.snap @@ -1,10 +1,14 @@ --- source: crates/baml_tests/src/generated_tests.rs +assertion_line: 59279 --- -=== HIR2 === +=== PPIR === type user.ExplicitHandler = (value: int) -> string throws never +type user.ExplicitHandler$stream = unknown type user.HiddenHandler = (value: int) -> string throws never +type user.HiddenHandler$stream = unknown type user.ImplicitHandler = (value: int) -> string throws never +type user.ImplicitHandler$stream = unknown function user.forward_direct(handler: (value: int) -> string, value: int) -> string [expr] { { } handler(value) } @@ -27,6 +31,7 @@ function user.run_implicit(handler: user.ImplicitHandler, value: int) -> string --- captures --- lambda (value) in return_closure: captures [handler] type user.Callback = (int) -> void throws never +type user.Callback$stream = unknown function user.bad_callback_use(cb: user.Callback) -> int [expr] { { let result = cb(1) } 1 } diff --git a/baml_language/crates/baml_tests/src/compiler2_tir/mod.rs b/baml_language/crates/baml_tests/src/compiler2_tir/mod.rs index 02218a84e01..c0ae343b8ed 100644 --- a/baml_language/crates/baml_tests/src/compiler2_tir/mod.rs +++ b/baml_language/crates/baml_tests/src/compiler2_tir/mod.rs @@ -1314,15 +1314,11 @@ pub(crate) mod support { output } - /// Render a file's HIR2 (compiler2 item tree) as readable text. - pub fn render_hir2(db: &ProjectDatabase, file: baml_base::SourceFile) -> String { + /// Render a file's PPIR (canonical, post-expansion item tree) as readable + /// text — includes the synthesized `*$stream` companions. + pub fn render_ppir(db: &ProjectDatabase, file: baml_base::SourceFile) -> String { use baml_compiler2_ast::{CatchClauseKind, Expr, ExprBody, Literal}; - use baml_compiler2_hir::{ - file_item_tree, - file_package::file_package, - file_semantic_index, - loc::{ClassLoc, EnumLoc, TypeAliasLoc}, - }; + use baml_compiler2_hir::{file_package::file_package, file_semantic_index}; fn qualify_type_name( path: &baml_base::TypePath, @@ -1494,6 +1490,161 @@ pub(crate) mod support { } } + /// The firewall-`TypeRef` twin of [`type_expr_to_string_hir`]: renders one + /// type reference from an item's `type_refs` arena, byte-identical to the + /// `ast::TypeExpr` renderer above. + fn type_ref_to_string( + store: &baml_compiler2_hir::type_ref::TypeRefStore, + id: baml_compiler2_hir::type_ref::TypeRefId, + pkg_prefix: &str, + local_type_names: &std::collections::HashSet<&str>, + ) -> String { + use baml_compiler2_hir::type_ref::TypeRefKind as K; + fn is_local_type_path( + first: &str, + local_type_names: &std::collections::HashSet<&str>, + ) -> bool { + local_type_names.contains(first) + || first + .strip_suffix("$stream") + .is_some_and(|base| local_type_names.contains(base)) + } + + match &store[id].kind { + K::Path { + segments, + generic_args, + associated_type_bindings, + } => { + let path = segments + .iter() + .map(|n| n.as_str()) + .collect::>() + .join("."); + let first = segments.first().map(|n| n.as_str()).unwrap_or(""); + let mut rendered = if is_local_type_path(first, local_type_names) { + format!("{pkg_prefix}{path}") + } else { + path + }; + if !generic_args.is_empty() || !associated_type_bindings.is_empty() { + let mut args = generic_args + .iter() + .map(|&arg| { + type_ref_to_string(store, arg, pkg_prefix, local_type_names) + }) + .collect::>(); + args.extend(associated_type_bindings.iter().map(|binding| { + format!( + "{} = {}", + binding.name, + type_ref_to_string(store, binding.ty, pkg_prefix, local_type_names) + ) + })); + rendered.push('<'); + rendered.push_str(&args.join(", ")); + rendered.push('>'); + } + rendered + } + K::Int => "int".into(), + K::Bigint => "bigint".into(), + K::Float => "float".into(), + K::String => "string".into(), + K::Bool => "bool".into(), + K::Null => "null".into(), + K::Never => "never".into(), + K::Void => "void".into(), + K::Uint8Array => "uint8array".into(), + K::Media { kind: k } => format!("{:?}", k).to_lowercase(), + K::Optional { inner } => { + format!( + "{}?", + type_ref_to_string(store, *inner, pkg_prefix, local_type_names) + ) + } + K::List { inner } => { + format!( + "{}[]", + type_ref_to_string(store, *inner, pkg_prefix, local_type_names) + ) + } + K::Map { key, value } => format!( + "map<{}, {}>", + type_ref_to_string(store, *key, pkg_prefix, local_type_names), + type_ref_to_string(store, *value, pkg_prefix, local_type_names) + ), + K::Union { variants: members } => members + .iter() + .map(|&m| type_ref_to_string(store, m, pkg_prefix, local_type_names)) + .collect::>() + .join(" | "), + K::Literal { value: lit } => lit.to_string(), + K::Function { + params, + ret, + throws, + } => { + let ps: Vec = params + .iter() + .map(|p| { + p.name + .as_ref() + .map(|n| { + let optional_marker = if p.optional { "?" } else { "" }; + format!( + "{}{}: {}", + n.as_str(), + optional_marker, + type_ref_to_string( + store, + p.ty, + pkg_prefix, + local_type_names + ) + ) + }) + .unwrap_or_else(|| { + type_ref_to_string(store, p.ty, pkg_prefix, local_type_names) + }) + }) + .collect(); + let throws = throws + .map(|throws| { + type_ref_to_string(store, throws, pkg_prefix, local_type_names) + }) + .map(|throws| format!(" throws {throws}")) + .unwrap_or_default(); + format!( + "({}) -> {}{}", + ps.join(", "), + type_ref_to_string(store, *ret, pkg_prefix, local_type_names), + throws + ) + } + K::BuiltinUnknown => "unknown".into(), + K::AssociatedTypeProjection { + base, + interface, + member, + } => { + let base = type_ref_to_string(store, *base, pkg_prefix, local_type_names); + if let Some(interface) = interface { + let interface = + type_ref_to_string(store, *interface, pkg_prefix, local_type_names); + format!("({base} as {interface}).{member}") + } else { + format!("{base}.{member}") + } + } + K::Type => "type".into(), + K::Rust => "$rust_type".into(), + K::Error => "error".into(), + K::Unknown => "?".into(), + K::Infer => "_".into(), + } + } + fn pat_desc_hir( pat_id: baml_compiler2_ast::PatId, body: &ExprBody, @@ -1982,39 +2133,41 @@ pub(crate) mod support { ) }; - let item_tree = file_item_tree(db, file); + use baml_compiler2_ppir::item_data::{ + class_data, enum_data, file_classes, file_enums, file_functions, file_type_aliases, + function_data, function_llm_meta, type_alias_data, + }; let mut local_type_names = std::collections::HashSet::new(); - for class in item_tree.classes.values() { - local_type_names.insert(class.name.as_str()); + for &loc in file_classes(db, file) { + local_type_names.insert(class_data(db, loc).name.as_str()); } - for enum_def in item_tree.enums.values() { - local_type_names.insert(enum_def.name.as_str()); + for &loc in file_enums(db, file) { + local_type_names.insert(enum_data(db, loc).name.as_str()); } - for ta in item_tree.type_aliases.values() { - local_type_names.insert(ta.name.as_str()); + for &loc in file_type_aliases(db, file) { + local_type_names.insert(type_alias_data(db, loc).name.as_str()); } - let mut classes: Vec<_> = item_tree.classes.iter().collect(); - classes.sort_by_key(|(_, c)| c.name.as_str().to_string()); - for (id, class) in classes { - let _loc = ClassLoc::new(db, file, *id); + let mut classes = file_classes(db, file).to_vec(); + classes.sort_by_key(|&loc| class_data(db, loc).name.as_str().to_string()); + for loc in classes { + let class = class_data(db, loc); writeln!(output, "class {prefix}{} {{", class.name).ok(); for field in &class.fields { let ty = field - .type_expr - .as_ref() - .map(|te| type_expr_to_string_hir(te, &prefix, &local_type_names)) + .type_ref + .map(|id| type_ref_to_string(&class.type_refs, id, &prefix, &local_type_names)) .unwrap_or_else(|| "?".into()); writeln!(output, " {}: {}", field.name, ty).ok(); } writeln!(output, "}}").ok(); } - let mut enums: Vec<_> = item_tree.enums.iter().collect(); - enums.sort_by_key(|(_, e)| e.name.as_str().to_string()); - for (id, enum_def) in enums { - let _loc = EnumLoc::new(db, file, *id); + let mut enums = file_enums(db, file).to_vec(); + enums.sort_by_key(|&loc| enum_data(db, loc).name.as_str().to_string()); + for loc in enums { + let enum_def = enum_data(db, loc); write!(output, "enum {prefix}{} {{", enum_def.name).ok(); for (i, v) in enum_def.variants.iter().enumerate() { if i > 0 { @@ -2025,46 +2178,50 @@ pub(crate) mod support { writeln!(output, "}}").ok(); } - let mut type_aliases: Vec<_> = item_tree.type_aliases.iter().collect(); - type_aliases.sort_by_key(|(_, ta)| ta.name.as_str().to_string()); - for (id, ta) in type_aliases { - let _loc = TypeAliasLoc::new(db, file, *id); + let mut type_aliases = file_type_aliases(db, file).to_vec(); + type_aliases.sort_by_key(|&loc| type_alias_data(db, loc).name.as_str().to_string()); + for loc in type_aliases { + let ta = type_alias_data(db, loc); let ty = ta - .type_expr - .as_ref() - .map(|te| type_expr_to_string_hir(te, &prefix, &local_type_names)) + .value + .map(|id| type_ref_to_string(&ta.type_refs, id, &prefix, &local_type_names)) .unwrap_or_else(|| "?".into()); writeln!(output, "type {prefix}{} = {}", ta.name, ty).ok(); } - let mut functions: Vec<_> = item_tree.functions.iter().collect(); - functions.sort_by_key(|(_, f)| f.name.as_str().to_string()); - for (_, func) in functions { + let mut functions = file_functions(db, file).to_vec(); + functions.sort_by_key(|&loc| function_data(db, loc).name.as_str().to_string()); + for loc in functions { + let func = function_data(db, loc); + let defaults = baml_compiler2_ppir::function_parameter_defaults(db, loc); let params: Vec = func .params .iter() - .map(|p| { - let default_suffix = default_ref_suffix(p.default.as_ref(), &func.defaults); + .enumerate() + .map(|(index, p)| { + let default_suffix = + default_ref_suffix(defaults.param_default(index), &defaults.defaults); let ty = p - .type_expr - .as_ref() - .map(|te| type_expr_to_string_hir(te, &prefix, &local_type_names)) + .type_ref + .map(|id| { + type_ref_to_string(&func.type_refs, id, &prefix, &local_type_names) + }) .unwrap_or_else(|| "?".into()); format!("{}: {}{}", p.name, ty, default_suffix) }) .collect(); let ret = func .return_type - .as_ref() - .map(|te| type_expr_to_string_hir(te, &prefix, &local_type_names)) + .map(|id| type_ref_to_string(&func.type_refs, id, &prefix, &local_type_names)) .unwrap_or_else(|| "?".into()); - let body_kind = if func.declarative_meta.is_some() { + let func_body = baml_compiler2_ppir::function_body(db, loc); + let body_kind = if function_llm_meta(db, loc).is_some() { "llm" } else { - match &func.body { - Some(baml_compiler2_ast::FunctionBodyDef::Expr(_, _)) => "expr", - Some(baml_compiler2_ast::FunctionBodyDef::Builtin(_)) => "builtin", - None => "missing", + match func_body.as_ref() { + baml_compiler2_hir::body::FunctionBody::Expr(_) => "expr", + baml_compiler2_hir::body::FunctionBody::Builtin(_) => "builtin", + baml_compiler2_hir::body::FunctionBody::Missing => "missing", } }; write!( @@ -2076,7 +2233,7 @@ pub(crate) mod support { body_kind ) .ok(); - if let Some(baml_compiler2_ast::FunctionBodyDef::Expr(body, _)) = &func.body { + if let baml_compiler2_hir::body::FunctionBody::Expr(body) = func_body.as_ref() { if let Some(root) = body.root_expr { writeln!(output, " {{").ok(); writeln!( From ae2e172d1e289425f5dd2b5ca9a2d269cf675c99 Mon Sep 17 00:00:00 2001 From: 2kai2kai2 Date: Tue, 21 Jul 2026 15:27:06 -0700 Subject: [PATCH 08/10] Emit should use ItemTree firewall queries Some minor snapshot churn from switching things to use deterministic source-order --- .../crates/baml_compiler2_emit/src/lib.rs | 1104 +++++++++-------- ...ompiles__o1_allowed_roles__06_codegen.snap | 4 +- ...ode_format__bytecode_display_expanded.snap | 288 ++--- ...bytecode_display_expanded_unoptimized.snap | 288 ++--- 4 files changed, 850 insertions(+), 834 deletions(-) diff --git a/baml_language/crates/baml_compiler2_emit/src/lib.rs b/baml_language/crates/baml_compiler2_emit/src/lib.rs index e9fc5c55f16..cf44d829998 100644 --- a/baml_language/crates/baml_compiler2_emit/src/lib.rs +++ b/baml_language/crates/baml_compiler2_emit/src/lib.rs @@ -17,16 +17,24 @@ use baml_compiler2_hir::{ compiler2_all_files, contributions::Definition, file_package::file_package, - loc::{ClassLoc, FunctionLoc, InterfaceLoc, LetLoc}, + loc::{FunctionLoc, LetLoc}, package::PackageId, }; use baml_compiler2_mir::{ BuiltinKind, Local, MirFunctionBody, MirFunctionKind, Operand, Place, ResolvedAliases, Rvalue, StatementKind, Terminator, def_to_item_ref, lower_function, lower_let_body, }; -// Use the PPIR item tree (which includes synthetic *$stream items) rather than -// the bare HIR item tree, to stay consistent with TIR's LocalItemId indices. -use baml_compiler2_ppir::file_item_tree; +// PPIR item-data firewall (canonical / post-expansion view, including synthetic +// `*$stream` items) — enumeration + lookup queries in place of the raw item tree. +use baml_compiler2_ppir::{ + function_body, + item_data::{ + class_data, enum_data, file_classes, file_enums, file_free_impls, file_functions, + file_interfaces, file_lets, file_template_strings, file_tests, function_data, + function_llm_meta, function_llm_prompt, impl_block_data, interface_data, + method_interface_target, template_string_data, test_data, + }, +}; use baml_type::{RuntimeTy, TyAttr}; use bex_vm_types::{ Bytecode, CaptureCategory, Class, ClassField, ConstValue, Enum, EnumVariant, Function, @@ -66,24 +74,26 @@ fn build_alias_caches( /// `RuntimeInterface::new`, which canonicalizes associated-binding order). fn build_interface_def( db: &dyn baml_compiler2_mir::Db, - file: baml_base::SourceFile, - iface_data: &baml_compiler2_hir::item_tree::Interface, + iface_loc: baml_compiler2_hir::loc::InterfaceLoc<'_>, iface_tn: baml_type::TypeName, resolved: &ResolvedAliases, ) -> bex_vm_types::types::InterfaceDef { + use baml_compiler2_hir::type_ref::{TypeRefId, TypeRefStore}; + use baml_compiler2_ppir::item_data::{FunctionParamData, function_data, interface_data}; use baml_compiler2_tir::{ - lower_type_expr::{ScopeCtx, TypeVarBoundsMap, lower_type_expr}, + lower_type_expr::{ScopeCtx, TypeVarBoundsMap, lower_type_ref}, ty, }; use baml_type::RuntimeInterface; use bex_vm_types::types::{InterfaceDef, InterfaceMethodDef}; - let item_tree = file_item_tree(db, file); + let file = iface_loc.file(db); + let interface = interface_data(db, iface_loc); let pkg_info = file_package(db, file); let pkg_id = PackageId::new(db, pkg_info.package.clone()); let pkg_items = baml_compiler2_ppir::package_items(db, pkg_id); let ns = &pkg_info.namespace_path; - let generics = &iface_data.generic_params; + let generics = &interface.generic_params; // Lower a type expr in `scope` (diagnostics discarded — the declaration was // validated upstream) and narrow to a runtime type. This can legitimately fail @@ -93,10 +103,11 @@ fn build_interface_def( // and are dropped. (Faithfully lowering them is future work, tracked for when a // consumer actually reads the method signatures — see the interface reflection // follow-up.) - let lower_rt = |expr: &TypeExpr, scope: &[Name]| -> Option { + let lower_rt = |store: &TypeRefStore, id: TypeRefId, scope: &[Name]| -> Option { let mut diags = Vec::new(); - let ty = lower_type_expr( - expr, + let ty = lower_type_ref( + store, + id, &ScopeCtx { db, package_items: pkg_items, @@ -112,42 +123,45 @@ fn build_interface_def( // Lower an interface bound / `requires` target to its runtime form. A // non-interface bound (rejected upstream) yields `None` and is skipped, as does // a bound that mentions an unsubstituted `Self`/associated type (see `lower_rt`). - let lower_iface = |expr: &TypeExpr, scope: &[Name]| -> Option { - let mut diags = Vec::new(); - let ty::Ty::Interface(qtn, args, assoc, _) = lower_type_expr( - expr, - &ScopeCtx { - db, - package_items: pkg_items, - ns_context: ns, - generic_params: scope, - bounds: &TypeVarBoundsMap::default(), - self_ty: None, - }, - &mut diags, - ) else { - return None; + let lower_iface = + |store: &TypeRefStore, id: TypeRefId, scope: &[Name]| -> Option { + let mut diags = Vec::new(); + let ty::Ty::Interface(qtn, args, assoc, _) = lower_type_ref( + store, + id, + &ScopeCtx { + db, + package_items: pkg_items, + ns_context: ns, + generic_params: scope, + bounds: &TypeVarBoundsMap::default(), + self_ty: None, + }, + &mut diags, + ) else { + return None; + }; + let generics = args + .iter() + .map(|a| baml_type::lower_to_runtime(a, resolved)) + .collect::, _>>() + .ok()?; + let associated_types = assoc + .iter() + .map(|(n, t)| baml_type::lower_to_runtime(t, resolved).map(|rt| (n.clone(), rt))) + .collect::, _>>() + .ok()?; + Some(RuntimeInterface::new(qtn, generics, associated_types)) }; - let generics = args - .iter() - .map(|a| baml_type::lower_to_runtime(a, resolved)) - .collect::, _>>() - .ok()?; - let associated_types = assoc - .iter() - .map(|(n, t)| baml_type::lower_to_runtime(t, resolved).map(|rt| (n.clone(), rt))) - .collect::, _>>() - .ok()?; - Some(RuntimeInterface::new(qtn, generics, associated_types)) - }; // A method's runtime signature: Required params → positional `args`, optional // (defaulted) params → `kwargs`; the `self` receiver is dropped; absent // return/throws lower to `Void`. The method's own generics extend the scope. - let build_method = |name: &Name, + let build_method = |store: &TypeRefStore, + name: &Name, method_generics: &[Name], - params: &[baml_compiler2_hir::item_tree::FunctionParam], - return_type: Option<&TypeExpr>, - throws: Option<&TypeExpr>| + params: &[FunctionParamData], + return_type: Option, + throws: Option| -> InterfaceMethodDef { let scope: Vec = generics.iter().chain(method_generics).cloned().collect(); let void = || RuntimeTy::Void { @@ -159,10 +173,10 @@ fn build_interface_def( if p.name.as_str() == "self" { continue; } - let Some(ty) = p.type_expr.as_ref().and_then(|te| lower_rt(te, &scope)) else { + let Some(ty) = p.type_ref.and_then(|id| lower_rt(store, id, &scope)) else { continue; }; - if p.default.is_some() { + if p.has_default { kwargs.push((p.name.clone(), ty)); } else { args.push(ty); @@ -173,73 +187,74 @@ fn build_interface_def( args, kwargs, returns: return_type - .and_then(|te| lower_rt(te, &scope)) + .and_then(|id| lower_rt(store, id, &scope)) .unwrap_or_else(void), errors: throws - .and_then(|te| lower_rt(te, &scope)) + .and_then(|id| lower_rt(store, id, &scope)) .unwrap_or_else(void), } }; // A generic param carries at most one bound today; lower it (or none). + let store = &interface.type_refs; let args = generics .iter() .enumerate() .map(|(i, param)| { - let bound = iface_data + let bound = interface .generic_param_bounds .get(i) - .and_then(Option::as_ref) - .and_then(|expr| lower_iface(expr, generics)); + .and_then(|o| *o) + .and_then(|id| lower_iface(store, id, generics)); (param.clone(), bound.into_iter().collect()) }) .collect(); - let requires = iface_data + let requires = interface .requires .iter() - .filter_map(|expr| lower_iface(expr, generics)) + .filter_map(|&id| lower_iface(store, id, generics)) .collect(); - let assoc = iface_data + let assoc = interface .associated_types .iter() .filter_map(|at| { at.bound - .as_ref() - .and_then(|b| lower_iface(b, generics)) + .and_then(|id| lower_iface(store, id, generics)) .map(|ri| (at.name.clone(), ri)) }) .collect(); - let fields = iface_data + let fields = interface .fields .iter() .filter_map(|f| { - f.type_expr - .as_ref() - .and_then(|te| lower_rt(te, generics)) + f.type_ref + .and_then(|id| lower_rt(store, id, generics)) .map(|rt| (f.name.clone(), rt)) }) .collect(); - let mut methods: Vec = iface_data + let mut methods: Vec = interface .required_methods .iter() .map(|m| { build_method( + store, &m.name, &m.generic_params, &m.params, - m.return_type.as_ref(), - m.throws.as_ref(), + m.return_type, + m.throws, ) }) .collect(); - methods.extend(iface_data.default_methods.iter().map(|&fid| { - let f = &item_tree[fid]; + methods.extend(interface.default_methods.iter().map(|&loc| { + let f = function_data(db, loc); build_method( + &f.type_refs, &f.name, &f.generic_params, &f.params, - f.return_type.as_ref(), - f.throws.as_ref(), + f.return_type, + f.throws, ) })); @@ -271,8 +286,10 @@ fn build_packages( interface_indices: &HashMap, program_packages: &mut indexmap::IndexMap, ) { + use baml_compiler2_hir::type_ref::{TypeRefId, TypeRefStore}; + use baml_compiler2_ppir::item_data::{AssociatedTypeBindingData, ImplSubjectData}; use baml_compiler2_tir::{ - lower_type_expr::{ScopeCtx, TypeVarBoundsMap, lower_type_expr, qualify_def}, + lower_type_expr::{ScopeCtx, TypeVarBoundsMap, lower_type_ref, qualify_def}, ty, }; use bex_vm_types::{ @@ -350,16 +367,12 @@ fn build_packages( let mut iface_assoc_order: indexmap::IndexMap> = indexmap::IndexMap::new(); for file in all_files { - let item_tree = file_item_tree(db, *file); - for (iface_id, iface_data) in &item_tree.interfaces { + for &iface_loc in file_interfaces(db, *file) { + let iface_data = interface_data(db, iface_loc); if iface_data.default_methods.is_empty() { continue; } - let iface_tn = qualify_def( - db, - Definition::Interface(InterfaceLoc::new(db, *file, *iface_id)), - &iface_data.name, - ); + let iface_tn = qualify_def(db, Definition::Interface(iface_loc), &iface_data.name); iface_assoc_order .entry(iface_tn.clone()) .or_insert_with(|| { @@ -372,9 +385,8 @@ fn build_packages( let entry = iface_defaults.entry(iface_tn).or_default(); for &m in &iface_data.default_methods { entry.insert( - item_tree[m].name.clone(), - def_to_item_ref(db, Definition::Function(FunctionLoc::new(db, *file, m))) - .to_string(), + function_data(db, m).name.clone(), + def_to_item_ref(db, Definition::Function(m)).to_string(), ); } } @@ -438,21 +450,26 @@ fn build_packages( }; for file in all_files { - let item_tree = file_item_tree(db, *file); let pkg_info = file_package(db, *file); let pkg_id = PackageId::new(db, pkg_info.package.clone()); let pkg_items = baml_compiler2_ppir::package_items(db, pkg_id); let ns = &pkg_info.namespace_path; let resolved = &alias_caches[&pkg_info.package]; - // Lower a type expr in this file's namespace, discarding diagnostics - // (these targets were already validated upstream). `bounds` carries the - // enclosing impl's/class's generic-param bounds so a bound-typevar - // projection in a binding value (`type SortError = T.CompareError`) - // determines its interface instead of erasing. - let lower = |expr: &TypeExpr, generics: &[Name], bounds: &TypeVarBoundsMap| -> ty::Ty { + // Lower a type ref (in the owner's `TypeRefStore`) in this file's + // namespace, discarding diagnostics (these targets were already validated + // upstream). `bounds` carries the enclosing impl's/class's generic-param + // bounds so a bound-typevar projection in a binding value + // (`type SortError = T.CompareError`) determines its interface instead of + // erasing. + let lower = |store: &TypeRefStore, + id: TypeRefId, + generics: &[Name], + bounds: &TypeVarBoundsMap| + -> ty::Ty { let mut diags = Vec::new(); - lower_type_expr( - expr, + lower_type_ref( + store, + id, &ScopeCtx { db, package_items: pkg_items, @@ -471,7 +488,8 @@ fn build_packages( // rejected upstream, has no interface to record, so skip the whole rule // (`None`); dropping a rule only ever loses a dispatch, never adds a wrong // one. - let bound_sets = |param_bounds: &[Option], + let bound_sets = |store: &TypeRefStore, + param_bounds: &[Option], generics: &[Name], bounds: &TypeVarBoundsMap| -> Option>> { @@ -479,14 +497,16 @@ fn build_packages( .iter() .map(|b| match b { None => Some(Vec::new()), - Some(te) => split_interface(&lower(te, generics, bounds), resolved, generics) - .map(|(interface, args, assoc)| { - vec![InterfaceBound { - interface, - args, - assoc, - }] - }), + Some(id) => { + split_interface(&lower(store, *id, generics, bounds), resolved, generics) + .map(|(interface, args, assoc)| { + vec![InterfaceBound { + interface, + args, + assoc, + }] + }) + } }) .collect() }; @@ -494,18 +514,19 @@ fn build_packages( // (`type Item = int`) live beside the target, not in it (`split_interface` // only sees the target), so lower them here to fold into the implemented // interface's bindings. - let lower_assoc = |bindings: &[baml_compiler2_ast::AssociatedTypeBindingDef], + let lower_assoc = |store: &TypeRefStore, + bindings: &[AssociatedTypeBindingData], generics: &[Name], bounds: &TypeVarBoundsMap| -> Vec<(Name, baml_type::TyTemplate)> { bindings .iter() .filter_map(|b| { - let te = b.type_expr.as_ref()?; + let id = b.type_ref?; Some(( b.name.clone(), baml_compiler2_mir::tir2_to_template( - &lower(te, generics, bounds), + &lower(store, id, generics, bounds), resolved, generics, ), @@ -517,44 +538,47 @@ fn build_packages( // (a) Out-of-body `implement I for FOR { ... }`: primitives, // containers, generic classes, and blanket `for T`. (A non-generic // concrete class's out-of-body impl folds onto the class — see (b).) - for impl_id in &item_tree.free_impls { - let Some(block) = item_tree.impls.get(impl_id) else { - continue; - }; - let baml_compiler2_hir::item_tree::ImplSubject::Free { + for &impl_loc in file_free_impls(db, *file) { + let block = impl_block_data(db, impl_loc); + let ImplSubjectData::Free { for_target, generics, } = &block.subject else { continue; }; + let store = &block.type_refs; let impl_param_names: Vec = generics.iter().map(|g| g.name.clone()).collect(); // Legacy flat single-bound form (first `&`-bound per param). - let impl_param_bounds: Vec> = - generics.iter().map(|g| g.bounds.first().cloned()).collect(); - let impl_bounds = baml_compiler2_tir::lower_type_expr::impl_generic_param_bounds( - db, - baml_compiler2_hir::loc::ImplLoc::new(db, *file, *impl_id), - ); + let impl_param_bounds: Vec> = + generics.iter().map(|g| g.bounds.first().copied()).collect(); + let impl_bounds = + baml_compiler2_tir::lower_type_expr::impl_generic_param_bounds(db, impl_loc); let Some((iface_tn, interface_args, mut interface_assoc)) = split_interface( - &lower(&block.interface_target, &impl_param_names, impl_bounds), + &lower( + store, + block.interface_target, + &impl_param_names, + impl_bounds, + ), resolved, &impl_param_names, ) else { continue; }; interface_assoc.extend(lower_assoc( + store, &block.associated_type_bindings, &impl_param_names, impl_bounds, )); let for_ty_pattern = baml_compiler2_mir::tir2_to_template( - &lower(for_target, &impl_param_names, impl_bounds), + &lower(store, *for_target, &impl_param_names, impl_bounds), resolved, &impl_param_names, ); let Some(generic_param_bounds) = - bound_sets(&impl_param_bounds, &impl_param_names, impl_bounds) + bound_sets(store, &impl_param_bounds, &impl_param_names, impl_bounds) else { continue; }; @@ -572,13 +596,12 @@ fn build_packages( }; let mut methods = indexmap::IndexMap::new(); for &m in &block.methods { - let fqn = def_to_item_ref(db, Definition::Function(FunctionLoc::new(db, *file, m))) - .to_string(); + let fqn = def_to_item_ref(db, Definition::Function(m)).to_string(); let Some(fqn) = resolve_fqn(&fqn) else { continue; }; methods.insert( - item_tree[m].name.clone(), + function_data(db, m).name.clone(), ProgramMethodImpl { fqn, frame: impl_frame.clone(), @@ -608,20 +631,16 @@ fn build_packages( // field-only (method-less) impl is still registered (membership matters // for reflection and bound checks even when there's nothing to dispatch); // attach any folded methods, grouped by their interface target. - for (class_id, class_data) in &item_tree.classes { - if class_data.implements.is_empty() { + for &class_loc in file_classes(db, *file) { + let class = class_data(db, class_loc); + if class.implements.is_empty() { continue; } - let class_tn = qualify_def( - db, - Definition::Class(ClassLoc::new(db, *file, *class_id)), - &class_data.name, - ); - let generics = &class_data.generic_params; - let class_bounds = baml_compiler2_tir::lower_type_expr::class_generic_param_bounds( - db, - ClassLoc::new(db, *file, *class_id), - ); + let store = &class.type_refs; + let class_tn = qualify_def(db, Definition::Class(class_loc), &class.name); + let generics = &class.generic_params; + let class_bounds = + baml_compiler2_tir::lower_type_expr::class_generic_param_bounds(db, class_loc); // Each folded method tagged with the full interface instantiation it // implements (name + args). A class may implement the same interface @@ -634,22 +653,21 @@ fn build_packages( Vec, Name, String, - )> = class_data + )> = class .methods .iter() .filter_map(|&m| { - let target = item_tree.method_to_iface_target.get(&m)?; + let target = method_interface_target(db, m).as_ref()?; let (m_iface_tn, m_args, _m_assoc) = split_interface( - &lower(target, generics, class_bounds), + &lower(&target.type_refs, target.target, generics, class_bounds), resolved, generics, )?; Some(( m_iface_tn, m_args, - item_tree[m].name.clone(), - def_to_item_ref(db, Definition::Function(FunctionLoc::new(db, *file, m))) - .to_string(), + function_data(db, m).name.clone(), + def_to_item_ref(db, Definition::Function(m)).to_string(), )) }) .collect(); @@ -671,7 +689,7 @@ fn build_packages( ) }; let Some(generic_param_bounds) = - bound_sets(&class_data.generic_param_bounds, generics, class_bounds) + bound_sets(store, &class.generic_param_bounds, generics, class_bounds) else { continue; }; @@ -681,15 +699,16 @@ fn build_packages( .map(baml_type::TyTemplate::TypeArgRef) .collect(); - for block in &class_data.implements { + for block in &class.implements { let Some((iface_tn, interface_args, mut interface_assoc)) = split_interface( - &lower(&block.target, generics, class_bounds), + &lower(store, block.target, generics, class_bounds), resolved, generics, ) else { continue; }; interface_assoc.extend(lower_assoc( + store, &block.associated_type_bindings, generics, class_bounds, @@ -922,10 +941,11 @@ fn extract_schema_attrs( pub use bex_vm_types::Program as ProgramAlias; -/// One entry in the emitted runtime field list for a class. +/// One entry in the emitted runtime field list for a class. The field type is a +/// `TypeRefId` into the owning class's `TypeRefStore` (carried alongside). type MergedFieldEntry = ( String, - Option, + Option, Vec, Vec, Vec, @@ -935,21 +955,21 @@ type MergedFieldEntry = ( /// class fields, so they never add qualified runtime slots. fn collect_class_fields_with_implements( pkg_ns: &[Name], - class_data: &baml_compiler2_hir::item_tree::Class, + class: &baml_compiler2_ppir::item_data::ClassData, ) -> Vec { let mut out: Vec = Vec::new(); let mut seen: std::collections::HashSet = std::collections::HashSet::new(); - for field in &class_data.fields { + for field in &class.fields { let name = field.name.to_string(); if !seen.insert(name.clone()) { continue; } out.push(( name, - field.type_expr.clone(), + field.type_ref, field.attributes.clone(), - class_data.generic_params.clone(), + class.generic_params.clone(), pkg_ns.to_vec(), )); } @@ -1284,23 +1304,24 @@ pub fn decompose_units( let mut func_name_to_file: HashMap = HashMap::new(); let mut let_name_to_file: HashMap = HashMap::new(); for (fi, file) in all_files.iter().enumerate() { - let item_tree = file_item_tree(db, *file); - for _ in item_tree.classes.values() { + // Owner vectors are consumed by walking the object pool in emission order, + // so they must be built in the SAME order the `Object::Class`/`Enum`/ + // `Interface` entries are emitted — the firewall enumeration (source order), + // matching Passes 2/3/3b. + for _ in file_classes(db, *file) { class_owner.push(fi); } - for _ in item_tree.enums.values() { + for _ in file_enums(db, *file) { enum_owner.push(fi); } - for _ in &item_tree.interfaces { + for _ in file_interfaces(db, *file) { iface_owner.push(fi); } - for local_id in item_tree.functions.keys() { - let func_loc = FunctionLoc::new(db, *file, *local_id); + for &func_loc in file_functions(db, *file) { let fq = def_to_item_ref(db, Definition::Function(func_loc)).to_string(); func_name_to_file.insert(fq, fi); } - for local_id in item_tree.lets.keys() { - let let_loc = LetLoc::new(db, *file, *local_id); + for &let_loc in file_lets(db, *file) { let fq = def_to_item_ref(db, Definition::Let(let_loc)).to_string(); let_name_to_file.insert(fq, fi); } @@ -1517,10 +1538,8 @@ pub fn decompose_units( } let mut local_let_count = vec![0u32; n_files]; for (fi, file) in all_files.iter().enumerate() { - let item_tree = file_item_tree(db, *file); let mut let_ord = 0u32; - for local_id in item_tree.lets.keys() { - let let_loc = LetLoc::new(db, *file, *local_id); + for &let_loc in file_lets(db, *file) { let fq = def_to_item_ref(db, Definition::Let(let_loc)).to_string(); if program.let_global_indices.contains_key(&fq) { name_to_local_global.insert(fq, (fi, func_next[fi] + let_ord)); @@ -1681,9 +1700,8 @@ pub fn decompose_units( // ---- Template-string macros (Pass 5 fragment, per file) ----------------- for (fi, file) in all_files.iter().enumerate() { - let item_tree = file_item_tree(db, *file); - for ts_data in item_tree.template_strings.values() { - if let Some(macro_def) = render_template_macro(ts_data) { + for &ts_loc in file_template_strings(db, *file) { + if let Some(macro_def) = render_template_macro(template_string_data(db, ts_loc)) { units[fi].template_macros.push(macro_def); } } @@ -1738,7 +1756,9 @@ fn local_ref_sort_key(r: LocalRef) -> (u8, u32) { /// Render one template-string definition as a Jinja `{% macro %}` block, or /// `None` for a body-less (declaration-only) template string. -fn render_template_macro(ts: &baml_compiler2_hir::item_tree::TemplateString) -> Option { +fn render_template_macro( + ts: &baml_compiler2_ppir::item_data::TemplateStringData, +) -> Option { let body = ts.body.as_ref()?; let args = ts .params @@ -2192,9 +2212,7 @@ fn inject_clean_slots( if !clean.contains(&rel) { continue; } - let item_tree = file_item_tree(db, *file); - for local_id in item_tree.functions.keys() { - let func_loc = FunctionLoc::new(db, *file, *local_id); + for &func_loc in file_functions(db, *file) { let fq = def_to_item_ref(db, Definition::Function(func_loc)).to_string(); // Intrinsic / await-any functions own no slot (Pass 1 skips them); // the `globals` guard drops them here too. @@ -2202,8 +2220,7 @@ fn inject_clean_slots( program.function_global_indices.insert(fq, slot); } } - for local_id in item_tree.lets.keys() { - let let_loc = LetLoc::new(db, *file, *local_id); + for &let_loc in file_lets(db, *file) { let fq = def_to_item_ref(db, Definition::Let(let_loc)).to_string(); if let Some(&slot) = globals.get(&fq) { program.let_global_indices.insert(fq, slot); @@ -2231,9 +2248,7 @@ fn inject_clean_object_placeholders( if !clean.contains(&rel) { continue; } - let item_tree = file_item_tree(db, *file); - for local_id in item_tree.functions.keys() { - let func_loc = FunctionLoc::new(db, *file, *local_id); + for &func_loc in file_functions(db, *file) { let fq = def_to_item_ref(db, Definition::Function(func_loc)).to_string(); if globals.get(&fq).is_some() { program.function_indices.entry(fq).or_insert_with(|| { @@ -2311,9 +2326,8 @@ fn generate_impl( // --- Pass 5: Template string macros --- let mut template_macros = Vec::new(); for file in &all_files { - let item_tree = file_item_tree(db, *file); - for ts_data in item_tree.template_strings.values() { - if let Some(macro_def) = render_template_macro(ts_data) { + for &ts_loc in file_template_strings(db, *file) { + if let Some(macro_def) = render_template_macro(template_string_data(db, ts_loc)) { template_macros.push(macro_def); } } @@ -2367,20 +2381,17 @@ fn generate_impl( // --- Pass 8: Test cases (only when requested) --- if options.emit_test_cases { for file in &all_files { - let item_tree = file_item_tree(db, *file); - for test_data in item_tree.tests.values() { - let function_names: Vec = test_data - .function_refs - .iter() - .map(ToString::to_string) - .collect(); - let args: indexmap::IndexMap = test_data + for &test_loc in file_tests(db, *file) { + let test = test_data(db, test_loc); + let function_names: Vec = + test.function_refs.iter().map(ToString::to_string).collect(); + let args: indexmap::IndexMap = test .args .iter() .map(|(k, v)| (k.to_string(), convert_test_arg_value(v))) .collect(); program.test_cases.push(bex_vm_types::TestCase { - name: test_data.name.to_string(), + name: test.name.to_string(), function_names, args, source_file: relative_source_path(db, *file), @@ -2511,26 +2522,22 @@ fn spliced_throws_match( previous: &HashMap<&str, &Option>, cache: &ResolvedAliases, ) -> Result<(), String> { - let item_tree = file_item_tree(db, file); - for (local_id, func_data) in &item_tree.functions { + for &func_loc in file_functions(db, file) { // Mirror Pass 4's skip set: these never become callable objects. if matches!( - func_data.body, - Some(baml_compiler2_ast::FunctionBodyDef::Builtin( + function_body(db, func_loc).as_ref(), + baml_compiler2_hir::body::FunctionBody::Builtin( BuiltinKind::Intrinsic | BuiltinKind::AwaitAny - )) + ) ) { continue; } - let fq = def_to_item_ref( - db, - Definition::Function(FunctionLoc::new(db, file, *local_id)), - ) - .to_string(); + let fq = def_to_item_ref(db, Definition::Function(func_loc)).to_string(); let Some(previous_throws) = previous.get(fq.as_str()) else { return Err(format!("previous units have no function `{fq}`")); }; - let current_throws = compute_throws_type(db, file, &func_data.name, cache); + let current_throws = + compute_throws_type(db, file, &function_data(db, func_loc).name, cache); if **previous_throws != current_throws { return Err(format!( "function `{fq}` changed from {:?} to {current_throws:?}", @@ -2584,9 +2591,7 @@ fn emit_file_group( // Including them here would create a mismatch between Pass-1 indices and the // actual program.globals array built in Pass 4 (which also skips intrinsics). for file in files { - let item_tree = file_item_tree(db, *file); - for (local_id, func_data) in &item_tree.functions { - let func_loc = FunctionLoc::new(db, *file, *local_id); + for &func_loc in file_functions(db, *file) { // Skip intrinsic and await-any functions — they are never called via // a Call instruction (intrinsics lower to StatementKind::Intrinsic; // `__await_any` lowers to a Terminator::AwaitAny). Pass 4 skips them @@ -2594,17 +2599,17 @@ fn emit_file_group( // desync from the program.globals array (off-by-one for everything // after the skipped function). // - // The kind is read straight off the item tree rather than from - // `lower_function(..).kind`: `lower_function` copies the item - // tree's `FunctionBodyDef::Builtin(kind)` into - // `MirFunctionKind::Builtin(kind)` verbatim, and fully MIR-lowering - // every function here just to inspect that one field would double - // the total lowering work (Pass 4 lowers every function again). + // The kind is read from the span-free `function_body` firewall query + // rather than from `lower_function(..).kind`: `lower_function` copies + // the body's `Builtin(kind)` into `MirFunctionKind::Builtin(kind)` + // verbatim, and fully MIR-lowering every function here just to inspect + // that one field would double the total lowering work (Pass 4 lowers + // every function again). if matches!( - func_data.body, - Some(baml_compiler2_ast::FunctionBodyDef::Builtin( + function_body(db, func_loc).as_ref(), + baml_compiler2_hir::body::FunctionBody::Builtin( BuiltinKind::Intrinsic | BuiltinKind::AwaitAny - )) + ) ) { continue; } @@ -2620,9 +2625,7 @@ fn emit_file_group( // Second sub-pass: assign slots to all let bindings across all files, // after all function slots have been reserved. for file in files { - let item_tree = file_item_tree(db, *file); - for local_id in item_tree.lets.keys() { - let let_loc = LetLoc::new(db, *file, *local_id); + for &let_loc in file_lets(db, *file) { let fq_name = def_to_item_ref(db, Definition::Let(let_loc)).to_string(); globals.entry(fq_name).or_insert_with(|| { let idx = global_idx; @@ -2652,12 +2655,13 @@ fn emit_file_group( // Also builds class_object_indices: class fq_name -> object index in program.objects. for file in files { - let item_tree = file_item_tree(db, *file); let pkg_info = file_package(db, *file); let pkg_id = PackageId::new(db, pkg_info.package.clone()); let pkg_items = baml_compiler2_ppir::package_items(db, pkg_id); let cache = &alias_caches[&pkg_info.package]; - for class_data in item_tree.classes.values() { + for &class_loc in file_classes(db, *file) { + let class = class_data(db, class_loc); + let store = &class.type_refs; // Build the fully-qualified name ("user.MyClass" / "baml.ns.MyClass") // through the SAME renderer MIR uses in `build_class_type_tags` // (`QualifiedTypeName::render_dotted(false)`). The class type-tag is @@ -2667,7 +2671,7 @@ fn emit_file_group( let fq_name = baml_type::QualifiedTypeName::new( pkg_info.package.clone(), pkg_info.namespace_path.clone(), - class_data.name.clone(), + class.name.clone(), ) .render_dotted(false); @@ -2677,17 +2681,16 @@ fn emit_file_group( // field type expressions to `TyTemplate::TypeArgRef(N)`. When // empty, `tir2_to_template` produces a `Concrete`-equivalent leaf // for every leaf and `field_template == Concrete(field_type)`. - let class_generic_params: Vec = class_data.generic_params.clone(); + let class_generic_params: Vec = class.generic_params.clone(); // BEP-044: collect only the class's actual runtime fields. // Interface fields are typed views over class storage, and the // validator enforces/link-checks them before emit. let merged_fields = - collect_class_fields_with_implements(&pkg_info.namespace_path, class_data); - for (idx, (name, type_expr, attrs, gen_params, ns)) in merged_fields.iter().enumerate() - { + collect_class_fields_with_implements(&pkg_info.namespace_path, class); + for (idx, (name, type_ref, attrs, gen_params, ns)) in merged_fields.iter().enumerate() { field_indices.insert(name.clone(), idx); - let (field_type, field_template) = match type_expr { - Some(te) => { + let (field_type, field_template) = match type_ref { + Some(id) => { let mut diags = Vec::new(); // Pass `class_generic_params` as the binding context so // `T`-references inside `class Container { item: T }` @@ -2696,8 +2699,9 @@ fn emit_file_group( // erased-`Ty` (TypeVar→BuiltinUnknown) used by codegen and to // the `TyTemplate` (TypeVar→TypeArgRef(N)) used by // typed runtime walking. - let tir_ty = baml_compiler2_tir::lower_type_expr::lower_type_expr( - te, + let tir_ty = baml_compiler2_tir::lower_type_expr::lower_type_ref( + store, + *id, &baml_compiler2_tir::lower_type_expr::ScopeCtx { db, package_items: pkg_items, @@ -2741,8 +2745,7 @@ fn emit_file_group( }); } - let (class_desc, class_alias, _class_skip) = - extract_schema_attrs(&class_data.attributes); + let (class_desc, class_alias, _class_skip) = extract_schema_attrs(&class.attributes); let type_tag = bex_vm_types::type_tags::class_type_tag(&fq_name); if let Some(previous) = class_type_tags.insert(type_tag, fq_name.clone()) @@ -2766,30 +2769,37 @@ fn emit_file_group( // HIR `Function`. The `throws` part reuses the shared helper; the rest // is mirrored (the two share field types but not the struct). // - // Only DIRECT class methods count. `class_data.methods` is flattened - // to include `implements`-block methods (recorded in - // `method_to_iface_target`), but those are interface members: the AST + // Only DIRECT class methods count. `class.methods` is flattened to + // include `implements`-block methods (which have a + // `method_interface_target`), but those are interface members: the AST // guard injector and the `{class_fqn}.cleanup` GC resolution only // cover direct methods, so an `implements`-block `cleanup` must NOT // mark the class finalizable (it would set the flag for a method the // GC can neither guard nor resolve). - let has_cleanup = class_data.methods.iter().any(|method_id| { - if item_tree.method_to_iface_target.contains_key(method_id) { + // + // The shape mirrors `cleanup_guard::has_cleanup_shape` over the + // span-free `FunctionData`: `throws` is effectively-none when absent or + // `never`, and the return must be `void` — read off the function's own + // `TypeRefStore`. + let has_cleanup = class.methods.iter().any(|&method| { + use baml_compiler2_hir::type_ref::TypeRefKind; + if method_interface_target(db, method).is_some() { return false; } - let func = &item_tree[*method_id]; + let func = function_data(db, method); + let throws_effectively_none = func + .throws + .is_none_or(|id| matches!(func.type_refs.get(id).kind, TypeRefKind::Never)); + let returns_void = func + .return_type + .is_some_and(|id| matches!(func.type_refs.get(id).kind, TypeRefKind::Void)); func.name.as_str() == baml_compiler2_ast::cleanup_guard::CLEANUP_METHOD && func.generic_params.is_empty() && func.params.len() == 1 && func.params[0].name.as_str() == "self" - && func.params[0].default.is_none() - && baml_compiler2_ast::cleanup_guard::throws_is_effectively_none( - func.throws.as_ref(), - ) - && matches!( - func.return_type.as_ref().map(|st| &st.kind), - Some(baml_compiler2_ast::ast::TypeExprKind::Void { .. }) - ) + && !func.params[0].has_default + && throws_effectively_none + && returns_void }); let class_obj_idx = program.add_object(Object::Class(Box::new(Class { @@ -2800,7 +2810,7 @@ fn emit_file_group( type_tag, ty_attr: TyAttr::default(), has_cleanup, - generic_param_count: class_data.generic_params.len(), + generic_param_count: class.generic_params.len(), }))); // Register with fully-qualified name for inter-package lookups. class_object_indices.insert(fq_name.clone(), class_obj_idx); @@ -2811,7 +2821,7 @@ fn emit_file_group( .insert( bex_vm_types::types::LocalName { namespace: pkg_info.namespace_path.clone(), - name: class_data.name.clone(), + name: class.name.clone(), }, ObjectIndex::from_raw(class_obj_idx), ); @@ -2821,14 +2831,14 @@ fn emit_file_group( // so emit-time type checks can do a direct display-name lookup. let display_name = if pkg_info.package.as_str() == "user" { if pkg_info.namespace_path.is_empty() { - class_data.name.to_string() + class.name.to_string() } else { let ns: Vec<&str> = pkg_info .namespace_path .iter() .map(baml_base::Name::as_str) .collect(); - format!("{}.{}", ns.join("."), class_data.name) + format!("{}.{}", ns.join("."), class.name) } } else { fq_name.clone() @@ -2838,7 +2848,7 @@ fn emit_file_group( .or_insert(class_obj_idx); // Also register with the short (unqualified) class name so that MIR aggregates, // which store only the local name (e.g., "Point" not "user.Point"), can find it. - let short_name = class_data.name.to_string(); + let short_name = class.name.to_string(); class_object_indices .entry(short_name.clone()) .or_insert(class_obj_idx); @@ -2846,8 +2856,7 @@ fn emit_file_group( // runtime field indices used by the Class object above. Use a // closure that rebuilds the same ordering. let rebuild_indices = || { - let merged = - collect_class_fields_with_implements(&pkg_info.namespace_path, class_data); + let merged = collect_class_fields_with_implements(&pkg_info.namespace_path, class); let mut m = HashMap::new(); for (idx, (name, _, _, _, _)) in merged.iter().enumerate() { m.insert(name.clone(), idx); @@ -2863,22 +2872,22 @@ fn emit_file_group( // Maps fully-qualified enum name -> (variant name -> variant index). for file in files { - let item_tree = file_item_tree(db, *file); let pkg_info = file_package(db, *file); - for enum_data in item_tree.enums.values() { + for &enum_loc in file_enums(db, *file) { + let enm = enum_data(db, enum_loc); // Same single renderer as the class pass / MIR (see above): keep the // fully-qualified name construction identical everywhere so the two // never drift. let fq_name = baml_type::QualifiedTypeName::new( pkg_info.package.clone(), pkg_info.namespace_path.clone(), - enum_data.name.clone(), + enm.name.clone(), ) .render_dotted(false); let mut variant_map = HashMap::new(); let mut variants = Vec::new(); - for (idx, variant) in enum_data.variants.iter().enumerate() { + for (idx, variant) in enm.variants.iter().enumerate() { let (var_desc, var_alias, var_skip) = extract_schema_attrs(&variant.attributes); variant_map.insert(variant.name.to_string(), idx); variants.push(EnumVariant { @@ -2889,7 +2898,7 @@ fn emit_file_group( }); } - let (enum_desc, enum_alias, _enum_skip) = extract_schema_attrs(&enum_data.attributes); + let (enum_desc, enum_alias, _enum_skip) = extract_schema_attrs(&enm.attributes); let enum_obj_idx = program.add_object(Object::Enum(Box::new(Enum { name: fq_to_type_name(&fq_name), @@ -2906,7 +2915,7 @@ fn emit_file_group( .insert( bex_vm_types::types::LocalName { namespace: pkg_info.namespace_path.clone(), - name: enum_data.name.clone(), + name: enm.name.clone(), }, ObjectIndex::from_raw(enum_obj_idx), ); @@ -2922,16 +2931,16 @@ fn emit_file_group( // `Object::Package` + `vm.packages` from; `build_packages` fills in each // package's impl rules below. for file in files { - let item_tree = file_item_tree(db, *file); let pkg_info = file_package(db, *file); let resolved = &alias_caches[&pkg_info.package]; - for (iface_id, iface_data) in &item_tree.interfaces { + for &iface_loc in baml_compiler2_ppir::item_data::file_interfaces(db, *file) { + let iface_data = baml_compiler2_ppir::item_data::interface_data(db, iface_loc); let iface_tn = baml_compiler2_tir::lower_type_expr::qualify_def( db, - Definition::Interface(InterfaceLoc::new(db, *file, *iface_id)), + Definition::Interface(iface_loc), &iface_data.name, ); - let iface_def = build_interface_def(db, *file, iface_data, iface_tn.clone(), resolved); + let iface_def = build_interface_def(db, iface_loc, iface_tn.clone(), resolved); let iface_obj_idx = program.add_object(Object::Interface(Box::new(iface_def))); interface_object_indices.insert(iface_tn, iface_obj_idx); program_packages @@ -3024,10 +3033,8 @@ fn emit_file_group( let mut pkg_lets: HashMap> = HashMap::new(); for file in files { - let item_tree = file_item_tree(db, *file); let pkg_info = file_package(db, *file); - for local_id in item_tree.lets.keys() { - let let_loc = LetLoc::new(db, *file, *local_id); + for &let_loc in file_lets(db, *file) { let fq_name = def_to_item_ref(db, Definition::Let(let_loc)).to_string(); // Ensure the global slot for this let binding is populated with Null. // Also register in let_global_indices for test/debug visibility. @@ -3113,10 +3120,8 @@ fn emit_file_group( let mut pkg_init_tests: HashMap> = HashMap::new(); for file in files { - let item_tree = file_item_tree(db, *file); let pkg_info = file_package(db, *file); - for local_id in item_tree.functions.keys() { - let func_loc = FunctionLoc::new(db, *file, *local_id); + for &func_loc in file_functions(db, *file) { let fq_name = def_to_item_ref(db, Definition::Function(func_loc)).to_string(); // Match per-file $init_test_ functions synthesized by // `synthesize_init_test_function`. The trailing underscore in the @@ -3312,7 +3317,7 @@ fn compute_throws_type( /// Stamp signature metadata onto a compiled `Function` — the single writer /// for both top-level declarations (metadata built by -/// `compute_function_metadata_from_item_tree`) and lambdas (metadata recorded +/// `compute_function_metadata`) and lambdas (metadata recorded /// by MIR's `lower_lambda` on `MirFunction::signature`). fn apply_signature_metadata(f: &mut Function, sig: &baml_compiler2_mir::RuntimeSignature) { f.param_names.clone_from(&sig.param_names); @@ -3341,27 +3346,38 @@ fn type_expr_for_name_with_generic_args(name: Name, generic_params: &[Name]) -> .at(baml_compiler2_ast::TextRange::default()) } -/// Extract runtime and display signature metadata from an `item_tree` Function. +/// Extract runtime and display signature metadata for a function, off the +/// span-free firewall (`function_data` + the enclosing owner's `*_data`). /// -/// Type resolution delegates to TIR's `lower_type_expr` (single source of truth) +/// Type resolution delegates to TIR's `lower_type_ref` (single source of truth) /// then converts via MIR's `convert_tir_ty_for_runtime` to produce runtime `baml_type::RuntimeTy`. /// The display fields keep generic type variables and unresolved projections /// intact for self-documenting surfaces like `baml run --list`. -fn compute_function_metadata_from_item_tree( - db: &dyn baml_compiler2_mir::Db, - file: baml_base::SourceFile, - func_id: baml_compiler2_hir::ids::LocalItemId, - func_data: &baml_compiler2_hir::item_tree::Function, +fn compute_function_metadata<'db>( + db: &'db dyn baml_compiler2_mir::Db, + func_loc: baml_compiler2_hir::loc::FunctionLoc<'db>, parameter_defaults: &baml_compiler2_hir::signature::FunctionParameterDefaults, cache: &ResolvedAliases, ) -> baml_compiler2_mir::RuntimeSignature { - use baml_compiler2_hir::item_tree::MethodOwner; + use baml_compiler2_hir::type_ref::{TypeRefId, TypeRefStore}; + use baml_compiler2_ppir::item_data::{ImplSubjectData, MethodOwner, method_owner}; + use baml_compiler2_tir::{ + generics::substitute_ty, + infer_context::TirTypeError, + lower_type_expr::{ScopeCtx, lower_type_expr, lower_type_ref}, + ty::Ty, + }; - let param_names: Vec = func_data - .params - .iter() - .map(|p| p.name.to_string()) - .collect(); + // A generic param's single optional `extends` bound as `(store, id)` — enclosing + // (class/interface/impl) and function bounds live in different arenas. + type BoundRef<'a> = Option<(&'a TypeRefStore, TypeRefId)>; + + let file = func_loc.file(db); + let func = function_data(db, func_loc); + // The arena holding this function's own signature type refs (params, return). + let func_store = &func.type_refs; + + let param_names: Vec = func.params.iter().map(|p| p.name.to_string()).collect(); let param_has_default: Vec = parameter_defaults .params .iter() @@ -3375,102 +3391,90 @@ fn compute_function_metadata_from_item_tree( attr: baml_type::TyAttr::default(), }; - let item_tree = file_item_tree(db, file); - // The out-of-body `implement … for …` block whose method list contains this - // function, if any (mirrors MIR's `enclosing_free_impl`). Yields the block so - // both its `for_target` (for `Self` substitution) and its declared - // generics/bounds are recoverable — replacing the removed - // `item_tree.implements_for`, which exposed those as flat fields. - let owner = item_tree.method_owners.get(&func_id); + // The item this method belongs to, via the firewall (mirrors MIR's enclosing + // lookups; replaces the removed `method_owners`/`implements_for` flat fields). + // Each `*_data` result carries its own `TypeRefStore` for the refs read below. + let owner = method_owner(db, func_loc); let enclosing_free_impl = match owner { - Some(MethodOwner::FreeImpl(impl_id)) => Some((*impl_id, &item_tree.impls[impl_id])), - Some(MethodOwner::Class(_) | MethodOwner::Interface(_)) | None => None, + Some(MethodOwner::FreeImpl(impl_loc)) => Some(impl_block_data(db, impl_loc)), + _ => None, }; - let enclosing_impl_for_target = - enclosing_free_impl.and_then(|(_, block)| match &block.subject { - baml_compiler2_hir::item_tree::ImplSubject::Free { for_target, .. } => Some(for_target), - baml_compiler2_hir::item_tree::ImplSubject::InClass { .. } => None, - }); let enclosing_class = match owner { - Some(MethodOwner::Class(class_id)) => Some(&item_tree[*class_id]), - Some(MethodOwner::FreeImpl(_) | MethodOwner::Interface(_)) | None => None, + Some(MethodOwner::Class(class_loc)) => Some(class_data(db, class_loc)), + _ => None, }; let enclosing_interface = match owner { - Some(MethodOwner::Interface(iface_id)) => Some(&item_tree[*iface_id]), - Some(MethodOwner::Class(_) | MethodOwner::FreeImpl(_)) | None => None, + Some(MethodOwner::Interface(iface_loc)) => Some(interface_data(db, iface_loc)), + _ => None, }; - let self_replacement = enclosing_impl_for_target - .cloned() - .or_else(|| { - enclosing_class.map(|class_data| { - type_expr_for_name_with_generic_args( - class_data.name.clone(), - &class_data.generic_params, - ) - }) - }) - .or_else(|| { - enclosing_interface.map(|iface_data| { - type_expr_for_name_with_generic_args( - iface_data.name.clone(), - &iface_data.generic_params, - ) - }) - }); // For methods on generic classes/interfaces/impls, the enclosing generic // params are in scope inside the method signature. Mirror // `MirLowerer::enclosing_generic_params`: enclosing params come first, then // function-level params. - let (scoped_generic_param_names, scoped_generic_bound_exprs) = if let Some((_, block)) = - enclosing_free_impl - { - // The impl block's declared generics as `(names, each's single optional - // bound)` — the flat form the removed `implements_for` exposed directly - // (mirrors MIR's `free_impl_generics`). Only the first `&`-bound per param - // is kept, matching the legacy shape. - let (mut names, mut bounds): (Vec, Vec>) = match &block.subject { - baml_compiler2_hir::item_tree::ImplSubject::Free { generics, .. } => ( - generics.iter().map(|g| g.name.clone()).collect(), - generics.iter().map(|g| g.bounds.first().cloned()).collect(), - ), - baml_compiler2_hir::item_tree::ImplSubject::InClass { .. } => (Vec::new(), Vec::new()), - }; - names.extend(func_data.generic_params.iter().cloned()); - bounds.extend(func_data.generic_param_bounds.iter().cloned()); - (names, bounds) - } else if let Some(iface_data) = enclosing_interface { - let mut names = iface_data.generic_params.clone(); - names.extend(func_data.generic_params.iter().cloned()); - let mut bounds = iface_data.generic_param_bounds.clone(); - bounds.extend(func_data.generic_param_bounds.iter().cloned()); - (names, bounds) - } else { - let mut names = enclosing_class - .map(|class_data| class_data.generic_params.clone()) - .unwrap_or_default(); - names.extend(func_data.generic_params.iter().cloned()); - let mut bounds = enclosing_class - .map(|class_data| class_data.generic_param_bounds.clone()) - .unwrap_or_default(); - bounds.extend(func_data.generic_param_bounds.iter().cloned()); - (names, bounds) + let func_bounds = || { + func.generic_param_bounds + .iter() + .map(move |o| o.map(|id| (func_store, id))) }; + let (scoped_generic_param_names, scoped_generic_bound_refs): (Vec, Vec) = + if let Some(block) = enclosing_free_impl { + // The impl block's declared generics as `(names, each's single optional + // bound)` — the flat form the removed `implements_for` exposed directly + // (mirrors MIR's `free_impl_generics`). Only the first `&`-bound per + // param is kept, matching the legacy shape. + let (mut names, mut bounds): (Vec, Vec) = match &block.subject { + ImplSubjectData::Free { generics, .. } => ( + generics.iter().map(|g| g.name.clone()).collect(), + generics + .iter() + .map(|g| g.bounds.first().copied().map(|id| (&block.type_refs, id))) + .collect(), + ), + ImplSubjectData::InClass { .. } => (Vec::new(), Vec::new()), + }; + names.extend(func.generic_params.iter().cloned()); + bounds.extend(func_bounds()); + (names, bounds) + } else if let Some(iface) = enclosing_interface { + let mut names = iface.generic_params.clone(); + names.extend(func.generic_params.iter().cloned()); + let mut bounds: Vec = iface + .generic_param_bounds + .iter() + .map(|o| o.map(|id| (&iface.type_refs, id))) + .collect(); + bounds.extend(func_bounds()); + (names, bounds) + } else { + let mut names = enclosing_class + .map(|c| c.generic_params.clone()) + .unwrap_or_default(); + names.extend(func.generic_params.iter().cloned()); + let mut bounds: Vec = enclosing_class + .map(|c| { + c.generic_param_bounds + .iter() + .map(|o| o.map(|id| (&c.type_refs, id))) + .collect() + }) + .unwrap_or_default(); + bounds.extend(func_bounds()); + (names, bounds) + }; let enclosing_generics = scoped_generic_param_names.clone(); // Every type variable in scope for this signature, keyed by name, with its // interface bounds. `function_in_scope_generic_param_bounds` covers the // enclosing class/interface plus the function's own params; an out-of-body - // impl's own generics are added on top. Threaded into every `lower_type_expr` - // below so a `T.member` projection resolves through `T`'s declared bound - // *during* lowering — the modern replacement for the removed post-hoc + // impl's own generics are added on top. Threaded into every lowering below so a + // `T.member` projection resolves through `T`'s declared bound *during* lowering + // — the modern replacement for the removed post-hoc // `AssociatedProjectionResolver::resolve_deep` pass. - let func_loc = baml_compiler2_hir::loc::FunctionLoc::new(db, file, func_id); let mut scope_bounds = baml_compiler2_tir::lower_type_expr::function_in_scope_generic_param_bounds(db, func_loc) .clone(); - if let Some((impl_id, _)) = enclosing_free_impl { - let impl_loc = baml_compiler2_hir::loc::ImplLoc::new(db, file, impl_id); + if let Some(MethodOwner::FreeImpl(impl_loc)) = owner { scope_bounds.extend( baml_compiler2_tir::lower_type_expr::impl_generic_param_bounds(db, impl_loc) .iter() @@ -3485,21 +3489,19 @@ fn compute_function_metadata_from_item_tree( // recipe as TIR's signature realization) — and the qualifier of each // `Self.` projection built below. let self_declaring_interface: Option = - enclosing_interface.and_then(|iface_data| { - let def = pkg_items.lookup_type(&pkg_info.namespace_path, &iface_data.name)?; + enclosing_interface.and_then(|iface| { + let def = pkg_items.lookup_type(&pkg_info.namespace_path, &iface.name)?; if !matches!( def, baml_compiler2_hir::contributions::Definition::Interface(_) ) { return None; } - let qtn = baml_compiler2_tir::lower_type_expr::qualify_def(db, def, &iface_data.name); - let args = iface_data + let qtn = baml_compiler2_tir::lower_type_expr::qualify_def(db, def, &iface.name); + let args = iface .generic_params .iter() - .map(|p| { - baml_compiler2_tir::ty::Ty::TypeVar(p.clone(), baml_type::TyAttr::default()) - }) + .map(|p| Ty::TypeVar(p.clone(), baml_type::TyAttr::default())) .collect(); Some(baml_type::Interface::new(qtn, args, Vec::new())) }); @@ -3512,107 +3514,126 @@ fn compute_function_metadata_from_item_tree( // way the method body does. Binding each associated-type name to the projection // `Self.` (and `Self` to its rigid type variable) keeps a bare `Item` in a // signature as a faithful `Self.Item` projection rather than an unresolved type. - // Empty for non-interface methods (the `self_replacement` path below handles + // Empty for non-interface methods (the `receiver_ty` path below handles // class/impl receivers). Only the interface's own associated types are bound; // names inherited through `requires` are not (that ambiguity-aware resolution // lived in the removed `interface_self_projection_bindings`). - let self_var = - || baml_compiler2_tir::ty::Ty::TypeVar(Name::new("Self"), baml_type::TyAttr::default()); - let interface_signature_bindings: rustc_hash::FxHashMap = - match enclosing_interface { - Some(iface_data) => { - let mut bindings: rustc_hash::FxHashMap = - enclosing_generics - .iter() - .map(|p| { - ( - p.clone(), - baml_compiler2_tir::ty::Ty::TypeVar( - p.clone(), - baml_type::TyAttr::default(), - ), - ) - }) - .collect(); - bindings.insert(Name::new("Self"), self_var()); - for assoc in &iface_data.associated_types { - bindings.insert( - assoc.name.clone(), - baml_compiler2_tir::ty::Ty::AssociatedTypeProjection { - base: Box::new(self_var()), - // The declaring interface resolved above; we are in the - // `Some(iface_data)` arm, so it is present. - interface: Box::new(self_declaring_interface.clone().unwrap_or_else( - || unreachable!("interface method has a declaring interface"), - )), - member: assoc.name.clone(), - attr: baml_type::TyAttr::default(), - }, - ); - } - bindings + let self_var = || Ty::TypeVar(Name::new("Self"), baml_type::TyAttr::default()); + let interface_signature_bindings: rustc_hash::FxHashMap = match enclosing_interface { + Some(iface) => { + let mut bindings: rustc_hash::FxHashMap = enclosing_generics + .iter() + .map(|p| { + ( + p.clone(), + Ty::TypeVar(p.clone(), baml_type::TyAttr::default()), + ) + }) + .collect(); + bindings.insert(Name::new("Self"), self_var()); + for assoc in &iface.associated_types { + bindings.insert( + assoc.name.clone(), + Ty::AssociatedTypeProjection { + base: Box::new(self_var()), + // The declaring interface resolved above; we are in the + // `Some(iface)` arm, so it is present. + interface: Box::new(self_declaring_interface.clone().unwrap_or_else( + || unreachable!("interface method has a declaring interface"), + )), + member: assoc.name.clone(), + attr: baml_type::TyAttr::default(), + }, + ); } - None => rustc_hash::FxHashMap::default(), - }; - - // The concrete receiver (`ClassName` or a free-impl `for` target), lowered - // once. A non-interface method's `Self` / `Self.Assoc` then root at it through the - // `self_ty` channel — the same projection path the interface branch drives with its - // rigid `Self` type variable. `None` for a free function (no receiver in scope) and - // unused for interface methods (which bind `Self` via `interface_signature_bindings`). - let receiver_ty: Option = if enclosing_interface.is_none() { - self_replacement.as_ref().map(|replacement| { - let mut receiver_diags = Vec::new(); - baml_compiler2_tir::lower_type_expr::lower_type_expr( - replacement, - &baml_compiler2_tir::lower_type_expr::ScopeCtx { - db, - package_items: pkg_items, - ns_context: &pkg_info.namespace_path, - generic_params: &enclosing_generics, - bounds: &scope_bounds, - self_ty: None, - }, - &mut receiver_diags, - ) - }) + bindings + } + None => rustc_hash::FxHashMap::default(), + }; + // The interface branch's generic-param scope: every name it binds (`Self`, the + // interface's params, its associated types), so a bare `Item` lowers to + // `TypeVar(Item)` before substitution. + let interface_binding_params: Vec = + interface_signature_bindings.keys().cloned().collect(); + + // The concrete receiver (`ClassName` for a class method, or a free-impl + // `for` target), lowered once. A non-interface method's `Self` / `Self.Assoc` + // then root at it through the `self_ty` channel — the same projection path the + // interface branch drives with its rigid `Self` type variable. `None` for a + // free function (no receiver in scope) and for interface methods (which bind + // `Self` via `interface_signature_bindings`). The class/interface receiver is a + // synthetic `Name` path (no item-tree read); the free-impl receiver is + // its `for_target` ref, lowered from the impl block's arena. + let receiver_ty: Option = if enclosing_interface.is_some() { + None + } else if let Some(block) = enclosing_free_impl { + match &block.subject { + ImplSubjectData::Free { for_target, .. } => { + let mut diags = Vec::new(); + Some(lower_type_ref( + &block.type_refs, + *for_target, + &ScopeCtx { + db, + package_items: pkg_items, + ns_context: &pkg_info.namespace_path, + generic_params: &enclosing_generics, + bounds: &scope_bounds, + self_ty: None, + }, + &mut diags, + )) + } + ImplSubjectData::InClass { .. } => None, + } + } else if let Some(class) = enclosing_class { + let te = type_expr_for_name_with_generic_args(class.name.clone(), &class.generic_params); + let mut diags = Vec::new(); + Some(lower_type_expr( + &te, + &ScopeCtx { + db, + package_items: pkg_items, + ns_context: &pkg_info.namespace_path, + generic_params: &enclosing_generics, + bounds: &scope_bounds, + self_ty: None, + }, + &mut diags, + )) } else { None }; - // Lower a signature type expression against this method's scope, recording any - // diagnostics into `diags`. For an interface method the associated-type / `Self` - // bindings are applied by lowering with their names in scope (so `Item` lowers - // to `TypeVar(Item)`) and then substituting; for every other method `Self` is - // bound to the concrete `receiver_ty` via the `self_ty` channel. In both cases - // `scope_bounds` drives projection resolution. Namespace-relative resolution - // (e.g. `MyLorem` in a signature under `ns_lorem/`) uses the file's namespace so - // a non-root-ns class does not erase to `unknown`. - let lower_scoped = |te: &TypeExpr, - diags: &mut Vec| - -> baml_compiler2_tir::ty::Ty { + // Lower a signature type ref (in `store`) against this method's scope. For an + // interface method the associated-type / `Self` bindings are applied by lowering + // with their names in scope (so `Item` lowers to `TypeVar(Item)`) and then + // substituting; for every other method `Self` is bound to the concrete + // `receiver_ty` via the `self_ty` channel. In both cases `scope_bounds` drives + // projection resolution. Namespace-relative resolution (e.g. `MyLorem` in a + // signature under `ns_lorem/`) uses the file's namespace so a non-root-ns class + // does not erase to `unknown`. + let lower_scoped = |store: &TypeRefStore, id: TypeRefId, diags: &mut Vec| -> Ty { if enclosing_interface.is_some() { - let generic_params: Vec = interface_signature_bindings.keys().cloned().collect(); - let lowered = baml_compiler2_tir::lower_type_expr::lower_type_expr( - te, - &baml_compiler2_tir::lower_type_expr::ScopeCtx { + let lowered = lower_type_ref( + store, + id, + &ScopeCtx { db, package_items: pkg_items, ns_context: &pkg_info.namespace_path, - generic_params: &generic_params, + generic_params: &interface_binding_params, bounds: &scope_bounds, self_ty: None, }, diags, ); - return baml_compiler2_tir::generics::substitute_ty( - &lowered, - &interface_signature_bindings, - ); + return substitute_ty(&lowered, &interface_signature_bindings); } - baml_compiler2_tir::lower_type_expr::lower_type_expr( - te, - &baml_compiler2_tir::lower_type_expr::ScopeCtx { + lower_type_ref( + store, + id, + &ScopeCtx { db, package_items: pkg_items, ns_context: &pkg_info.namespace_path, @@ -3627,32 +3648,23 @@ fn compute_function_metadata_from_item_tree( // Each scoped generic parameter's bound as a displayable `Ty`, kept only when it // lowers cleanly (a bound that fails to resolve is dropped rather than shown as // `unknown`). Rendered into `display_type_params` below. - let generic_param_bounds: HashMap = - scoped_generic_param_names - .iter() - .enumerate() - .filter_map(|(idx, name)| { - let bound_te = scoped_generic_bound_exprs.get(idx)?.as_ref()?; - let mut diags = Vec::new(); - let bound_ty = lower_scoped(bound_te, &mut diags); - diags.is_empty().then(|| (name.clone(), bound_ty)) - }) - .collect(); + let generic_param_bounds: HashMap = scoped_generic_param_names + .iter() + .enumerate() + .filter_map(|(idx, name)| { + let (store, id) = scoped_generic_bound_refs.get(idx).copied().flatten()?; + let mut diags = Vec::new(); + let bound_ty = lower_scoped(store, id, &mut diags); + diags.is_empty().then(|| (name.clone(), bound_ty)) + }) + .collect(); // Projection resolution is folded into `lower_scoped` (via `scope_bounds`), so - // no separate resolve pass is needed. - let resolve_display_tir = |te: &TypeExpr| -> baml_compiler2_tir::ty::Ty { + // no separate resolve pass is needed. Diagnostics are discarded — the display + // fields keep whatever resolved. + let resolve_display_tir = |store: &TypeRefStore, id: TypeRefId| -> Ty { let mut diags = Vec::new(); - lower_scoped(te, &mut diags) - }; - - let runtime_from_display_tir = |tir_ty: &baml_compiler2_tir::ty::Ty| -> baml_type::RuntimeTy { - // `resolve_display_tir` already resolved associated projections against - // statically-known bounds. Convert what remains faithfully — type - // variables and symbolic projections are carried by `RuntimeTy` so the - // runtime can resolve them; erasing them to `unknown` would discard the - // information needed to do that. - cache.convert(tir_ty) + lower_scoped(store, id, &mut diags) }; let display_type_params: Vec = scoped_generic_param_names @@ -3666,31 +3678,56 @@ fn compute_function_metadata_from_item_tree( }) .collect(); - let mut param_types = Vec::with_capacity(func_data.params.len()); - let mut display_param_types = Vec::with_capacity(func_data.params.len()); - for param in &func_data.params { - let resolved = if let Some(te) = ¶m.type_expr { - Some(resolve_display_tir(te)) + // The receiver type used for a `self` parameter with no written annotation. For + // an interface method it is the interface at its own params, resolved through + // the same binding path (a synthetic `Name` path — no item-tree read); + // for every other method it is the already-lowered `receiver_ty`. + let self_param_ty = || -> Option { + match enclosing_interface { + Some(iface) => { + let te = + type_expr_for_name_with_generic_args(iface.name.clone(), &iface.generic_params); + let mut diags = Vec::new(); + let lowered = lower_type_expr( + &te, + &ScopeCtx { + db, + package_items: pkg_items, + ns_context: &pkg_info.namespace_path, + generic_params: &interface_binding_params, + bounds: &scope_bounds, + self_ty: None, + }, + &mut diags, + ); + Some(substitute_ty(&lowered, &interface_signature_bindings)) + } + None => receiver_ty.clone(), + } + }; + + let mut param_types = Vec::with_capacity(func.params.len()); + let mut display_param_types = Vec::with_capacity(func.params.len()); + for param in &func.params { + let resolved = if let Some(id) = param.type_ref { + Some(resolve_display_tir(func_store, id)) } else if param.name.as_str() == "self" { - self_replacement.as_ref().map(&resolve_display_tir) + self_param_ty() } else { None }; if let Some(tir_ty) = resolved { display_param_types.push(tir_ty.render_user_facing()); - param_types.push(runtime_from_display_tir(&tir_ty)); + param_types.push(cache.convert(&tir_ty)); } else { display_param_types.push("null".to_string()); param_types.push(null_ty()); } } - let resolved_return_type = func_data.return_type.as_ref().map(resolve_display_tir); - let (return_type, display_return_type) = if let Some(tir_ty) = resolved_return_type { - ( - runtime_from_display_tir(&tir_ty), - tir_ty.render_user_facing(), - ) + let (return_type, display_return_type) = if let Some(id) = func.return_type { + let tir_ty = resolve_display_tir(func_store, id); + (cache.convert(&tir_ty), tir_ty.render_user_facing()) } else { (null_ty(), "null".to_string()) }; @@ -3702,9 +3739,9 @@ fn compute_function_metadata_from_item_tree( return_type, // TIR's inferred transitive throw set — richer than the declared // clause (a declared clause is a firewall the inference respects). - throws_type: compute_throws_type(db, file, &func_data.name, cache), - docstring: func_data.docstring.clone(), - name: Some(func_data.name.to_string()), + throws_type: compute_throws_type(db, file, &func.name, cache), + docstring: func.docstring.clone(), + name: Some(func.name.to_string()), display_type_params, display_param_types, display_return_type, @@ -4118,12 +4155,10 @@ fn emit_functions_serial( // the Stage 6 "only dirty files are lowered" evidence counter. record_lowered_file(&rel_path); let line_starts = build_line_starts(file.text(db)); - let item_tree = file_item_tree(db, *file); let pkg_info_pass4 = file_package(db, *file); let is_builtin_file = file.path(db).to_string_lossy().starts_with("/"); let cache_pass4 = &alias_caches[&pkg_info_pass4.package]; - for (local_id, func_data) in &item_tree.functions { - let func_loc = FunctionLoc::new(db, *file, *local_id); + for &func_loc in file_functions(db, *file) { let mir = lower_function(db, func_loc, opt); let fq_name = mir.item_ref.to_string(); @@ -4187,9 +4222,7 @@ fn emit_functions_serial( attach_function_metadata( db, - *file, - *local_id, - func_data, + func_loc, cache_pass4, is_builtin_file, &fq_name, @@ -4389,12 +4422,11 @@ fn emit_functions_parallel( } record_lowered_file(&rel_path); let line_starts: std::sync::Arc<[u32]> = build_line_starts(file.text(db)).into(); - let item_tree = file_item_tree(db, *file); let is_builtin_file = file.path(db).to_string_lossy().starts_with("/"); - for local_id in item_tree.functions.keys() { + for &func_loc in file_functions(db, *file) { seeds.push(FnSeed { file: *file, - local_id: *local_id, + local_id: func_loc.id(db), source_file: rel_path.clone(), line_starts: line_starts.clone(), is_builtin_file, @@ -4505,15 +4537,12 @@ fn emit_functions_parallel( } }; - let item_tree = file_item_tree(db, item.file); - let func_data = &item_tree.functions[&item.local_id]; + let func_loc = FunctionLoc::new(db, item.file, item.local_id); let pkg_info = file_package(db, item.file); let cache = &alias_caches[&pkg_info.package]; attach_function_metadata( db, - item.file, - item.local_id, - func_data, + func_loc, cache, item.is_builtin_file, &item.fq_name, @@ -4678,60 +4707,51 @@ fn builtin_emit_function(kind: BuiltinKind, fq_name: &str, arity: usize) -> Opti /// passes. Every lookup here is a salsa query, so this always runs on the /// serial control thread. #[allow(clippy::too_many_arguments)] -fn attach_function_metadata( - db: &dyn baml_compiler2_mir::Db, - file: baml_base::SourceFile, - local_id: baml_compiler2_hir::ids::LocalItemId, - func_data: &baml_compiler2_hir::item_tree::Function, +fn attach_function_metadata<'db>( + db: &'db dyn baml_compiler2_mir::Db, + func_loc: baml_compiler2_hir::loc::FunctionLoc<'db>, cache: &ResolvedAliases, is_builtin_file: bool, fq_name: &str, compiled_fn: &mut Function, ) { + let func = function_data(db, func_loc); // Set function metadata from signature - let func_loc = FunctionLoc::new(db, file, local_id); let parameter_defaults = baml_compiler2_ppir::function_parameter_defaults(db, func_loc); - let signature_metadata = compute_function_metadata_from_item_tree( - db, - file, - local_id, - func_data, - ¶meter_defaults, - cache, - ); + let signature_metadata = compute_function_metadata(db, func_loc, ¶meter_defaults, cache); apply_signature_metadata(compiled_fn, &signature_metadata); - compiled_fn.origin = emitted_function_origin(fq_name, is_builtin_file, func_data.origin); - - // Set LLM-specific body_meta if this is an LLM function - if let Some(baml_compiler2_ast::DeclarativeMeta::Llm(llm_meta)) = &func_data.declarative_meta { - // NOTE (canary merge): canary removed the runtime `Function.stream_return_type` - // field and its plumbing (the pre-existing streaming infra from PRs #3362/#3755). - // The stream return type is now carried by the synthesized `$stream` companion's - // own `return_type` (see ppir's `companion_stream_return_type`), so the old - // emit-side pre-computation block was dropped. BEP-049 M5e stream-path rendering - // of `ctx.output_format` should be re-verified against canary's streaming. - if let Some(client) = &llm_meta.client { - // New-mode (BEP-049 M5) functions have no Jinja `prompt` - // text — the compiled closure renders it — but they still - // need a registry entry so `get_return_type` / - // `get_stream_return_type` (used by `__make_stream` and the - // streaming `Context`) resolve by name. The empty template - // is never read for them (their `prompt_closure` is non-null, - // so the Jinja `get_jinja_template` branch is skipped). - let prompt_template = llm_meta - .prompt - .as_ref() - .map(|p| p.text.clone()) - .unwrap_or_default(); - compiled_fn.body_meta = Some(FunctionMeta::Llm { - prompt_template, - client: client.to_string(), - }); - compiled_fn.capture = FunctionCaptureProps::disabled() - .with_auto(CaptureCategory::Input) - .with_auto(CaptureCategory::Output) - .with_auto(CaptureCategory::Error); - } + compiled_fn.origin = emitted_function_origin(fq_name, is_builtin_file, func.origin); + + // Set LLM-specific body_meta if this is an LLM function with a client. + // + // NOTE (canary merge): canary removed the runtime `Function.stream_return_type` + // field and its plumbing (the pre-existing streaming infra from PRs #3362/#3755). + // The stream return type is now carried by the synthesized `$stream` companion's + // own `return_type` (see ppir's `companion_stream_return_type`), so the old + // emit-side pre-computation block was dropped. BEP-049 M5e stream-path rendering + // of `ctx.output_format` should be re-verified against canary's streaming. + if let Some(llm_meta) = function_llm_meta(db, func_loc) + && let Some(client) = &llm_meta.client_name + { + // New-mode (BEP-049 M5) functions have no Jinja `prompt` text — the compiled + // closure renders it — but they still need a registry entry so + // `get_return_type` / `get_stream_return_type` (used by `__make_stream` and + // the streaming `Context`) resolve by name. The empty template is never read + // for them (their `prompt_closure` is non-null, so the Jinja + // `get_jinja_template` branch is skipped). The prompt text is fetched from + // the span-carrying `function_llm_prompt` sibling of `function_llm_meta`. + let prompt_template = function_llm_prompt(db, func_loc) + .as_ref() + .map(|p| p.text.clone()) + .unwrap_or_default(); + compiled_fn.body_meta = Some(FunctionMeta::Llm { + prompt_template, + client: client.to_string(), + }); + compiled_fn.capture = FunctionCaptureProps::disabled() + .with_auto(CaptureCategory::Input) + .with_auto(CaptureCategory::Output) + .with_auto(CaptureCategory::Error); } } @@ -5241,13 +5261,16 @@ mod tests { ); db.project = Some(Project::new(&db, PathBuf::from("."), vec![file])); - let item_tree = baml_compiler2_ppir::file_item_tree(&db, file); - let (function_id, func_data) = item_tree - .functions + let func_loc = baml_compiler2_ppir::item_data::file_functions(&db, file) .iter() - .find(|(_, f)| f.name.as_str() == "f") + .copied() + .find(|&loc| { + baml_compiler2_ppir::item_data::function_data(&db, loc) + .name + .as_str() + == "f" + }) .expect("test file declares `f`"); - let func_loc = baml_compiler2_hir::loc::FunctionLoc::new(&db, file, *function_id); let parameter_defaults = baml_compiler2_hir::signature::function_parameter_defaults(&db, func_loc); let cache = ResolvedAliases { @@ -5255,14 +5278,7 @@ mod tests { recursive: HashSet::new(), }; - let metadata = compute_function_metadata_from_item_tree( - &db, - file, - *function_id, - func_data, - ¶meter_defaults, - &cache, - ); + let metadata = compute_function_metadata(&db, func_loc, ¶meter_defaults, &cache); assert_eq!(metadata.param_has_default, vec![false, true, false]); } diff --git a/baml_language/crates/baml_tests/snapshots/compiles/o1_allowed_roles/baml_tests__compiles__o1_allowed_roles__06_codegen.snap b/baml_language/crates/baml_tests/snapshots/compiles/o1_allowed_roles/baml_tests__compiles__o1_allowed_roles__06_codegen.snap index 8bf5e48207f..d1ca9e252c7 100644 --- a/baml_language/crates/baml_tests/snapshots/compiles/o1_allowed_roles/baml_tests__compiles__o1_allowed_roles__06_codegen.snap +++ b/baml_language/crates/baml_tests/snapshots/compiles/o1_allowed_roles/baml_tests__compiles__o1_allowed_roles__06_codegen.snap @@ -5,11 +5,11 @@ function $init() -> null { call $init_let_0 store_global user.O1Client call $init_let_1 - store_global user.O1WithExplicitRoles + store_global user.O1MiniClient call $init_let_2 store_global user.Gpt4oClient call $init_let_3 - store_global user.O1MiniClient + store_global user.O1WithExplicitRoles load_const null return } diff --git a/baml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded.snap b/baml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded.snap index 60be83e4426..5299616311a 100644 --- a/baml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded.snap +++ b/baml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded.snap @@ -9,17 +9,17 @@ function assert.approx_equal(actual: float, expected: float, eps: float) -> null 4 jump +4 (to 8) 5 pop 1 6 load_var 3 (eps) - 7 call 136 ntypeargs=0 (baml.Float.is_nan) + 7 call 95 ntypeargs=0 (baml.Float.is_nan) 8 pop_jump_if_false +2 (to 10) 9 jump +45 (to 54) 80 10 load_var2 1 2 11 sub_float - 12 call 129 ntypeargs=0 (baml.Float.abs) + 12 call 98 ntypeargs=0 (baml.Float.abs) 13 store_var 4 (delta) 81 14 load_var 4 (delta) - 15 call 136 ntypeargs=0 (baml.Float.is_nan) + 15 call 95 ntypeargs=0 (baml.Float.is_nan) 16 jump_if_false +2 (to 18) 17 jump +4 (to 21) 18 pop 1 @@ -33,19 +33,19 @@ function assert.approx_equal(actual: float, expected: float, eps: float) -> null 81 24 jump +32 (to 56) 84 25 load_var 4 (delta) - 26 call 772 ntypeargs=0 (assert.format_operand) + 26 call 771 ntypeargs=0 (assert.format_operand) 27 store_var 5 (_18) 86 28 load_var 3 (eps) - 29 call 772 ntypeargs=0 (assert.format_operand) + 29 call 771 ntypeargs=0 (assert.format_operand) 30 store_var 6 (_20) 88 31 load_var 1 (actual) - 32 call 772 ntypeargs=0 (assert.format_operand) + 32 call 771 ntypeargs=0 (assert.format_operand) 33 store_var 7 (_21) 90 34 load_var 2 (expected) - 35 call 772 ntypeargs=0 (assert.format_operand) + 35 call 771 ntypeargs=0 (assert.format_operand) 36 store_var 8 (_22) 84 37 load_const 2 ("assertion failed: |left - right| = ") @@ -63,17 +63,17 @@ function assert.approx_equal(actual: float, expected: float, eps: float) -> null 49 bin_op + 50 load_var 8 (_22) 51 bin_op + - 52 call 244 ntypeargs=0 (baml.sys.panic) + 52 call 246 ntypeargs=0 (baml.sys.panic) 53 jump +3 (to 56) 78 54 load_const 6 ("assertion failed: epsilon must be a non-negative number") - 55 call 244 ntypeargs=0 (baml.sys.panic) + 55 call 246 ntypeargs=0 (baml.sys.panic) 56 return } function assert.contains(haystack: string, needle: string) -> null { 100 0 load_var2 1 2 - 1 call 181 ntypeargs=0 (baml.String.includes) + 1 call 147 ntypeargs=0 (baml.String.includes) 2 unary_op ! 3 pop_jump_if_false +2 (to 5) 4 jump +3 (to 7) @@ -83,13 +83,13 @@ function assert.contains(haystack: string, needle: string) -> null { 100 6 jump +3 (to 9) 101 7 load_const 1 ("assertion failed: string does not contain expected substring") - 8 call 244 ntypeargs=0 (baml.sys.panic) + 8 call 246 ntypeargs=0 (baml.sys.panic) 9 return } function assert.equal(actual: unknown, expected: unknown) -> null { 50 0 load_var2 1 2 - 1 call 651 ntypeargs=0 (baml.ops.equals_equals) + 1 call 638 ntypeargs=0 (baml.ops.equals_equals) 2 unary_op ! 3 pop_jump_if_false +2 (to 5) 4 jump +3 (to 7) @@ -99,11 +99,11 @@ function assert.equal(actual: unknown, expected: unknown) -> null { 50 6 jump +15 (to 21) 53 7 load_var 1 (actual) - 8 call 772 ntypeargs=0 (assert.format_operand) + 8 call 771 ntypeargs=0 (assert.format_operand) 9 store_var 3 (_8) 55 10 load_var 2 (expected) - 11 call 772 ntypeargs=0 (assert.format_operand) + 11 call 771 ntypeargs=0 (assert.format_operand) 12 store_var 4 (_9) 53 13 load_const 1 ("assertion failed: left = ") @@ -113,13 +113,13 @@ function assert.equal(actual: unknown, expected: unknown) -> null { 17 bin_op + 18 load_var 4 (_9) 19 bin_op + - 20 call 244 ntypeargs=0 (baml.sys.panic) + 20 call 246 ntypeargs=0 (baml.sys.panic) 21 return } function assert.format_operand(value: unknown) -> string { 32 0 load_var 1 (value) - 1 call 153 ntypeargs=0 (baml.String.from) + 1 call 138 ntypeargs=0 (baml.String.from) 2 return } @@ -134,14 +134,14 @@ function assert.is_true(condition: bool) -> null { 5 5 jump +3 (to 8) 6 6 load_const 1 ("assertion failed: expected true") - 7 call 244 ntypeargs=0 (baml.sys.panic) + 7 call 246 ntypeargs=0 (baml.sys.panic) 8 return } function assert.not_null(value: unknown | null) -> null { 14 0 load_var 1 (value) 1 load_const 0 (null) - 2 call 651 ntypeargs=0 (baml.ops.equals_equals) + 2 call 638 ntypeargs=0 (baml.ops.equals_equals) 3 pop_jump_if_false +2 (to 5) 4 jump +3 (to 7) @@ -150,7 +150,7 @@ function assert.not_null(value: unknown | null) -> null { 14 6 jump +3 (to 9) 15 7 load_const 1 ("assertion failed: expected non-null value") - 8 call 244 ntypeargs=0 (baml.sys.panic) + 8 call 246 ntypeargs=0 (baml.sys.panic) 9 return } @@ -176,7 +176,7 @@ function testing.$invoke_collector(collector: (testing.TestCollector) -> void th } function testing.FailFast() -> (testing.TestSetChild[]) -> testing.TestSetReport throws never { - 101 0 make_closure 1386 0 + 101 0 make_closure 1413 0 1 return } @@ -197,11 +197,11 @@ function testing.PassRate(threshold: float) -> (testing.TestSetChild[]) -> testi 12 pop_jump_if_false +4 (to 16) 69 13 load_const 2 ("testing.PassRate requires 0.0 <= threshold <= 1.0") - 14 call 244 ntypeargs=0 (baml.sys.panic) + 14 call 246 ntypeargs=0 (baml.sys.panic) 15 pop 1 74 16 load_var 1 (threshold) - 17 make_closure 1399 1 + 17 make_closure 1408 1 18 return } @@ -231,16 +231,16 @@ function testing.Quorum(n: int, m: int) -> (() -> testing.TestReport throws neve 20 pop_jump_if_false +8 (to 28) 5 21 load_const 1 ("testing.Quorum requires 0 <= m <= n") - 22 call 244 ntypeargs=0 (baml.sys.panic) + 22 call 246 ntypeargs=0 (baml.sys.panic) 23 pop 1 24 jump +4 (to 28) 3 25 load_const 2 ("testing.Quorum requires n > 0") - 26 call 244 ntypeargs=0 (baml.sys.panic) + 26 call 246 ntypeargs=0 (baml.sys.panic) 27 pop 1 10 28 load_var2 1 2 - 29 make_closure 1417 2 + 29 make_closure 1392 2 30 return } @@ -255,16 +255,16 @@ function testing.Retry(max_attempts: int) -> (() -> testing.TestReport throws ne 6 pop_jump_if_false +4 (to 10) 36 7 load_const 1 ("testing.Retry requires max_attempts > 0") - 8 call 244 ntypeargs=0 (baml.sys.panic) + 8 call 246 ntypeargs=0 (baml.sys.panic) 9 pop 1 41 10 load_var 1 (max_attempts) - 11 make_closure 1408 1 + 11 make_closure 1402 1 12 return } function testing.Sequential() -> (testing.TestSetChild[]) -> testing.TestSetReport throws never { - 95 0 make_closure 1390 0 + 95 0 make_closure 1411 0 1 return } @@ -397,7 +397,7 @@ function testing.TestCollector.register_test(self: testing.TestCollector, name: 45 load_var 10 (t) 46 load_field 0 (name) 47 load_var 7 (hash_prefix) - 48 call 152 ntypeargs=0 (baml.String.starts_with) + 48 call 148 ntypeargs=0 (baml.String.starts_with) 49 pop_jump_if_false -21 (to 28) 50 load_var 6 (count) 51 load_const 9 (1) @@ -421,7 +421,7 @@ function testing.TestCollector.register_test(self: testing.TestCollector, name: 68 load_var 6 (count) 69 load_const 9 (1) 70 add_int - 71 call 153 ntypeargs=1 (baml.String.from) + 71 call 138 ntypeargs=1 (baml.String.from) 72 store_var 13 (_30) 73 load_var2 12 13 74 bin_op + @@ -433,7 +433,7 @@ function testing.TestCollector.register_test(self: testing.TestCollector, name: 79 load_var2 11 3 80 load_var 4 (runner) 81 init_instance 0 (testing.TestRegistration .name, .body, .runner) - 82 call 9 ntypeargs=1 (baml.Array.push) + 82 call 4 ntypeargs=1 (baml.Array.push) 83 pop 1 26 84 load_const 13 (null) @@ -493,7 +493,7 @@ function testing.TestCollector.register_test_set(self: testing.TestCollector, na 45 load_var 10 (ts) 46 load_field 0 (name) 47 load_var 7 (hash_prefix) - 48 call 152 ntypeargs=0 (baml.String.starts_with) + 48 call 148 ntypeargs=0 (baml.String.starts_with) 49 pop_jump_if_false -21 (to 28) 50 load_var 6 (count) 51 load_const 9 (1) @@ -517,7 +517,7 @@ function testing.TestCollector.register_test_set(self: testing.TestCollector, na 68 load_var 6 (count) 69 load_const 9 (1) 70 add_int - 71 call 153 ntypeargs=1 (baml.String.from) + 71 call 138 ntypeargs=1 (baml.String.from) 72 store_var 13 (_30) 73 load_var2 12 13 74 bin_op + @@ -529,7 +529,7 @@ function testing.TestCollector.register_test_set(self: testing.TestCollector, na 79 load_var2 11 3 80 load_var 4 (runner) 81 init_instance 0 (testing.TestSetRegistration .name, .collector, .runner) - 82 call 9 ntypeargs=1 (baml.Array.push) + 82 call 4 ntypeargs=1 (baml.Array.push) 83 pop 1 37 84 load_const 13 (null) @@ -562,18 +562,18 @@ function testing.TestRegistry.expand_set(self: testing.TestRegistry, name: strin 21 pop_jump_if_false -14 (to 7) 198 22 load_var2 1 5 - 23 call 749 ntypeargs=0 (testing.TestRegistry.expand_testset_registry) + 23 call 737 ntypeargs=0 (testing.TestRegistry.expand_testset_registry) 24 pop 1 199 25 load_var 1 (self) - 26 call 732 ntypeargs=0 (testing.TestRegistry.serialize) + 26 call 729 ntypeargs=0 (testing.TestRegistry.serialize) 27 jump +33 (to 60) 203 28 load_type 5 29 load_type 6 30 load_var 1 (self) 31 load_field 1 (expansions) - 32 call 11 ntypeargs=2 (baml.Map.keys) + 32 call 35 ntypeargs=2 (baml.Map.keys) 33 load_type 7 34 load_const 8 ("iter") 35 virtual_call nargs=1 ntypeargs=0 @@ -599,11 +599,11 @@ function testing.TestRegistry.expand_set(self: testing.TestRegistry, name: strin 205 53 load_var2 2 8 54 load_const 11 ("/") 55 bin_op + - 56 call 152 ntypeargs=0 (baml.String.starts_with) + 56 call 148 ntypeargs=0 (baml.String.starts_with) 57 pop_jump_if_false -20 (to 37) 206 58 load_var2 9 2 - 59 call 737 ntypeargs=0 (testing.TestRegistry.expand_set) + 59 call 736 ntypeargs=0 (testing.TestRegistry.expand_set) 60 return 209 61 load_const 12 ("TestSet not found for expansion: ") @@ -619,14 +619,14 @@ function testing.TestRegistry.expand_testset_registry(self: testing.TestRegistry 3 load_field 1 (expansions) 4 load_var 2 (ts) 5 load_field 0 (name) - 6 call 44 ntypeargs=2 (baml.Map.get) + 6 call 38 ntypeargs=2 (baml.Map.get) 7 store_var 3 (_3) 8 load_var 3 (_3) 9 is_type 2 10 pop_jump_if_false +2 (to 12) 11 jump +36 (to 47) - 216 12 call 249 ntypeargs=0 (baml.sys.now_ms) + 216 12 call 248 ntypeargs=0 (baml.sys.now_ms) 13 store_var 4 (start) 217 14 load_var 2 (ts) @@ -643,7 +643,7 @@ function testing.TestRegistry.expand_testset_registry(self: testing.TestRegistry 24 call_indirect 25 pop 1 - 219 26 call 249 ntypeargs=0 (baml.sys.now_ms) + 219 26 call 248 ntypeargs=0 (baml.sys.now_ms) 27 store_var 6 (_19) 221 28 load_var 5 (sub_collector) @@ -664,7 +664,7 @@ function testing.TestRegistry.expand_testset_registry(self: testing.TestRegistry 40 load_var 2 (ts) 41 load_field 0 (name) 42 load_var 7 (sub_registry) - 43 call 12 ntypeargs=2 (baml.Map.set) + 43 call 37 ntypeargs=2 (baml.Map.set) 44 pop 1 226 45 load_var 7 (sub_registry) @@ -677,7 +677,7 @@ function testing.TestRegistry.expand_testset_registry(self: testing.TestRegistry function testing.TestRegistry.list_filtered(self: testing.TestRegistry, include: string[], exclude: string[]) -> string[] { 189 0 load_var2 1 2 1 load_var 3 (exclude) - 2 call 731 ntypeargs=0 (testing.select_names) + 2 call 756 ntypeargs=0 (testing.select_names) 3 return } @@ -694,9 +694,9 @@ function testing.TestRegistry.new(collector: testing.TestCollector) -> testing.T function testing.TestRegistry.run_all(self: testing.TestRegistry) -> testing.TestSetReport { 166 0 load_var 1 (self) - 1 call 747 ntypeargs=0 (testing.testset_children) + 1 call 738 ntypeargs=0 (testing.testset_children) 2 load_const 0 (null) - 3 call 725 ntypeargs=0 (testing.run_testset) + 3 call 748 ntypeargs=0 (testing.run_testset) 4 return } @@ -720,14 +720,14 @@ function testing.TestRegistry.run_filtered(self: testing.TestRegistry, include: 182 16 load_var2 1 2 17 load_var 3 (exclude) - 18 call 731 ntypeargs=0 (testing.select_names) + 18 call 756 ntypeargs=0 (testing.select_names) 19 store_var 6 (_9) 20 load_var2 1 6 - 21 call 722 ntypeargs=0 (testing.TestRegistry.run_selected) + 21 call 733 ntypeargs=0 (testing.TestRegistry.run_selected) 22 jump +3 (to 25) 180 23 load_var 1 (self) - 24 call 744 ntypeargs=0 (testing.TestRegistry.run_all) + 24 call 732 ntypeargs=0 (testing.TestRegistry.run_all) 184 25 call 760 ntypeargs=0 (testing.flatten_with_tolerated) 26 return @@ -735,9 +735,9 @@ function testing.TestRegistry.run_filtered(self: testing.TestRegistry, include: function testing.TestRegistry.run_selected(self: testing.TestRegistry, names: string[]) -> testing.TestSetReport { 170 0 load_var2 1 2 - 1 call 728 ntypeargs=0 (testing.testset_children_selected) + 1 call 739 ntypeargs=0 (testing.testset_children_selected) 2 load_const 0 (null) - 3 call 725 ntypeargs=0 (testing.run_testset) + 3 call 748 ntypeargs=0 (testing.run_testset) 4 return } @@ -770,14 +770,14 @@ function testing.TestRegistry.run_test(self: testing.TestRegistry, name: string) 23 load_field 1 (body) 24 load_var 5 (t) 25 load_field 2 (runner) - 26 call 759 ntypeargs=0 (testing.run_test) + 26 call 747 ntypeargs=0 (testing.run_test) 27 jump +33 (to 60) 140 28 load_type 5 29 load_type 6 30 load_var 1 (self) 31 load_field 1 (expansions) - 32 call 11 ntypeargs=2 (baml.Map.keys) + 32 call 35 ntypeargs=2 (baml.Map.keys) 33 load_type 7 34 load_const 8 ("iter") 35 virtual_call nargs=1 ntypeargs=0 @@ -803,11 +803,11 @@ function testing.TestRegistry.run_test(self: testing.TestRegistry, name: string) 143 53 load_var2 2 8 54 load_const 11 ("/") 55 bin_op + - 56 call 152 ntypeargs=0 (baml.String.starts_with) + 56 call 148 ntypeargs=0 (baml.String.starts_with) 57 pop_jump_if_false -20 (to 37) 144 58 load_var2 9 2 - 59 call 736 ntypeargs=0 (testing.TestRegistry.run_test) + 59 call 730 ntypeargs=0 (testing.TestRegistry.run_test) 60 return 147 61 load_const 12 ("Test not found: ") @@ -842,18 +842,18 @@ function testing.TestRegistry.run_testset(self: testing.TestRegistry, name: stri 21 pop_jump_if_false -14 (to 7) 153 22 load_var2 1 5 - 23 call 749 ntypeargs=0 (testing.TestRegistry.expand_testset_registry) - 24 call 747 ntypeargs=0 (testing.testset_children) + 23 call 737 ntypeargs=0 (testing.TestRegistry.expand_testset_registry) + 24 call 738 ntypeargs=0 (testing.testset_children) 25 load_var 5 (ts) 26 load_field 2 (runner) - 27 call 725 ntypeargs=0 (testing.run_testset) + 27 call 748 ntypeargs=0 (testing.run_testset) 28 jump +33 (to 61) 156 29 load_type 5 30 load_type 6 31 load_var 1 (self) 32 load_field 1 (expansions) - 33 call 11 ntypeargs=2 (baml.Map.keys) + 33 call 35 ntypeargs=2 (baml.Map.keys) 34 load_type 7 35 load_const 8 ("iter") 36 virtual_call nargs=1 ntypeargs=0 @@ -879,11 +879,11 @@ function testing.TestRegistry.run_testset(self: testing.TestRegistry, name: stri 158 54 load_var2 2 8 55 load_const 11 ("/") 56 bin_op + - 57 call 152 ntypeargs=0 (baml.String.starts_with) + 57 call 148 ntypeargs=0 (baml.String.starts_with) 58 pop_jump_if_false -20 (to 38) 159 59 load_var2 9 2 - 60 call 740 ntypeargs=0 (testing.TestRegistry.run_testset) + 60 call 731 ntypeargs=0 (testing.TestRegistry.run_testset) 61 return 162 62 load_const 12 ("TestSet not found: ") @@ -920,7 +920,7 @@ function testing.TestRegistry.serialize(self: testing.TestRegistry) -> (testing. 110 21 load_var 4 (_5) 22 load_field 0 (name) 23 init_instance 0 (testing.SerializedTest .type, .name) - 24 call 9 ntypeargs=0 (baml.Array.push) + 24 call 4 ntypeargs=0 (baml.Array.push) 25 pop 1 26 jump -16 (to 10) @@ -949,7 +949,7 @@ function testing.TestRegistry.serialize(self: testing.TestRegistry) -> (testing. 48 load_field 1 (expansions) 49 load_var 7 (ts) 50 load_field 0 (name) - 51 call 44 ntypeargs=2 (baml.Map.get) + 51 call 38 ntypeargs=2 (baml.Map.get) 52 store_var 8 (expanded) 115 53 load_var 8 (expanded) @@ -962,7 +962,7 @@ function testing.TestRegistry.serialize(self: testing.TestRegistry) -> (testing. 59 load_var 7 (ts) 60 load_field 0 (name) 61 init_instance 1 (testing.SerializedTest .type, .name) - 62 call 9 ntypeargs=0 (baml.Array.push) + 62 call 4 ntypeargs=0 (baml.Array.push) 63 pop 1 64 jump -30 (to 34) @@ -974,7 +974,7 @@ function testing.TestRegistry.serialize(self: testing.TestRegistry) -> (testing. 69 store_var 10 (_27) 119 70 load_var 9 (sub) - 71 call 732 ntypeargs=0 (testing.TestRegistry.serialize) + 71 call 729 ntypeargs=0 (testing.TestRegistry.serialize) 72 store_var 11 (_28) 117 73 load_var2 2 10 @@ -982,7 +982,7 @@ function testing.TestRegistry.serialize(self: testing.TestRegistry) -> (testing. 120 75 load_field 2 (loading_time_ms) 76 init_instance 2 (testing.SerializedTestSet .name, .items, .loadingTimeMs) - 77 call 9 ntypeargs=0 (baml.Array.push) + 77 call 4 ntypeargs=0 (baml.Array.push) 78 pop 1 79 jump -45 (to 34) @@ -1009,7 +1009,7 @@ function testing._has_selected_descendant(prefix: string, names: string[]) -> bo 310 15 load_const 5 ("/") 16 bin_op + - 17 call 152 ntypeargs=0 (baml.String.starts_with) + 17 call 148 ntypeargs=0 (baml.String.starts_with) 312 18 pop_jump_if_false -13 (to 5) @@ -1023,14 +1023,14 @@ function testing._has_selected_descendant(prefix: string, names: string[]) -> bo function testing._int_to_float(value: int) -> float { 125 0 load_type 0 1 load_var 1 (value) - 2 call 153 ntypeargs=1 (baml.String.from) - 3 call 127 ntypeargs=0 (baml.Float.parse) + 2 call 138 ntypeargs=1 (baml.String.from) + 3 call 130 ntypeargs=0 (baml.Float.parse) 4 jump +5 (to 9) 5 load_var 2 (e) 6 throw_if_panic 126 7 load_const 1 ("failed to convert int to float") - 8 call 244 ntypeargs=0 (baml.sys.panic) + 8 call 246 ntypeargs=0 (baml.sys.panic) 9 return } @@ -1100,7 +1100,7 @@ function testing.aggregate_reports(named_results: testing.NamedChildReport[]) -> 30 store_var 10 (result) 329 31 load_var2 6 10 - 32 call 9 ntypeargs=0 (baml.Array.push) + 32 call 4 ntypeargs=0 (baml.Array.push) 33 pop 1 330 34 load_var 10 (result) @@ -1117,7 +1117,7 @@ function testing.aggregate_reports(named_results: testing.NamedChildReport[]) -> 334 45 load_var 11 (outcome) 46 load_const 10 ("pass") - 47 call 651 ntypeargs=0 (baml.ops.equals_equals) + 47 call 638 ntypeargs=0 (baml.ops.equals_equals) 48 pop_jump_if_false +2 (to 50) 49 jump +55 (to 104) @@ -1175,13 +1175,13 @@ function testing.aggregate_reports(named_results: testing.NamedChildReport[]) -> 347 93 load_var2 5 15 - 346 94 call 9 ntypeargs=0 (baml.Array.push) + 346 94 call 4 ntypeargs=0 (baml.Array.push) 95 pop 1 96 jump -12 (to 84) 349 97 load_var 11 (outcome) 98 load_const 16 ("error") - 99 call 651 ntypeargs=0 (baml.ops.equals_equals) + 99 call 638 ntypeargs=0 (baml.ops.equals_equals) 100 pop_jump_if_false -83 (to 17) 350 101 load_const 17 (true) @@ -1251,13 +1251,13 @@ function testing.any_pattern_matches(pats: testing.FilterPat[], function_name: s 526 16 load_field 0 (func_pat) 17 load_var 2 (function_name) - 18 call 745 ntypeargs=0 (testing.filter_match) + 18 call 753 ntypeargs=0 (testing.filter_match) 19 jump_if_false +6 (to 25) 20 pop 1 21 load_var 6 (p) 22 load_field 1 (test_pat) 23 load_var 3 (test_name) - 24 call 745 ntypeargs=0 (testing.filter_match) + 24 call 753 ntypeargs=0 (testing.filter_match) 25 pop_jump_if_false -20 (to 5) 527 26 load_const 5 (true) @@ -1291,7 +1291,7 @@ function testing.collect_leaf_messages(results: (testing.TestReport | testing.Te 19 load_var 5 (r) 20 load_field 5 (results) 21 load_var 2 (out) - 22 call 738 ntypeargs=0 (testing.collect_leaf_messages) + 22 call 761 ntypeargs=0 (testing.collect_leaf_messages) 23 pop 1 24 jump -19 (to 5) 25 load_var 5 (r) @@ -1315,7 +1315,7 @@ function testing.collect_leaf_messages(results: (testing.TestReport | testing.Te 665 42 load_field 0 (outcome) 43 load_const 10 ("pass") - 44 call 651 ntypeargs=0 (baml.ops.equals_equals) + 44 call 638 ntypeargs=0 (baml.ops.equals_equals) 45 unary_op ! 46 pop_jump_if_false -15 (to 31) @@ -1327,7 +1327,7 @@ function testing.collect_leaf_messages(results: (testing.TestReport | testing.Te 667 52 load_var2 2 9 - 666 53 call 9 ntypeargs=0 (baml.Array.push) + 666 53 call 4 ntypeargs=0 (baml.Array.push) 54 pop 1 55 jump -24 (to 31) @@ -1360,7 +1360,7 @@ function testing.collect_leaf_names(registry: testing.TestRegistry) -> string[] 564 19 load_var2 2 4 563 20 load_field 0 (name) - 21 call 9 ntypeargs=0 (baml.Array.push) + 21 call 4 ntypeargs=0 (baml.Array.push) 22 pop 1 23 jump -13 (to 10) @@ -1383,7 +1383,7 @@ function testing.collect_leaf_names(registry: testing.TestRegistry) -> string[] 567 40 load_var2 1 6 - 566 41 call 750 ntypeargs=0 (testing.collect_subtree_names) + 566 41 call 758 ntypeargs=0 (testing.collect_subtree_names) 567 42 load_type 10 43 load_const 11 ("iter") @@ -1401,7 +1401,7 @@ function testing.collect_leaf_names(registry: testing.TestRegistry) -> string[] 568 55 load_var2 2 8 - 567 56 call 9 ntypeargs=0 (baml.Array.push) + 567 56 call 4 ntypeargs=0 (baml.Array.push) 57 pop 1 58 jump -12 (to 46) @@ -1411,8 +1411,8 @@ function testing.collect_leaf_names(registry: testing.TestRegistry) -> string[] function testing.collect_subtree_names(registry: testing.TestRegistry, ts: testing.TestSetRegistration) -> string[] { 580 0 load_var2 1 2 - 1 call 749 ntypeargs=0 (testing.TestRegistry.expand_testset_registry) - 2 call 733 ntypeargs=0 (testing.collect_leaf_names) + 1 call 737 ntypeargs=0 (testing.TestRegistry.expand_testset_registry) + 2 call 757 ntypeargs=0 (testing.collect_leaf_names) 3 jump +20 (to 23) 4 load_var 3 (e) 5 type_tag @@ -1483,7 +1483,7 @@ function testing.count_leaves(results: (testing.TestReport | testing.TestSetRepo 34 load_var 11 (tsr) 35 load_field 0 (outcome) 36 load_const 7 ("pass") - 37 call 651 ntypeargs=0 (baml.ops.equals_equals) + 37 call 638 ntypeargs=0 (baml.ops.equals_equals) 38 store_var 12 (ft) 615 39 load_var 11 (tsr) @@ -1527,14 +1527,14 @@ function testing.count_leaves(results: (testing.TestReport | testing.TestSetRepo 616 71 load_var 11 (tsr) 72 load_field 5 (results) 73 load_var 12 (ft) - 74 call 735 ntypeargs=0 (testing.count_leaves) + 74 call 759 ntypeargs=0 (testing.count_leaves) 75 store_var 10 (delta) 76 jump +30 (to 106) 603 77 load_var 9 (r) 78 load_field 0 (outcome) 79 load_const 8 ("pass") - 80 call 651 ntypeargs=0 (baml.ops.equals_equals) + 80 call 638 ntypeargs=0 (baml.ops.equals_equals) 605 81 pop_jump_if_false +2 (to 83) 82 jump +18 (to 100) @@ -1622,7 +1622,7 @@ function testing.filter_match(expr: string, subject: string) -> bool { 4 jump +4 (to 8) 520 5 load_var2 2 1 - 6 call 743 ntypeargs=0 (testing.glob_match) + 6 call 752 ntypeargs=0 (testing.glob_match) 7 jump +2 (to 9) 518 8 load_const 1 (true) @@ -1633,7 +1633,7 @@ function testing.flatten_with_tolerated(report: testing.TestSetReport) -> testin 637 0 load_var 1 (report) 1 load_field 0 (outcome) 2 load_const 0 ("pass") - 3 call 651 ntypeargs=0 (baml.ops.equals_equals) + 3 call 638 ntypeargs=0 (baml.ops.equals_equals) 4 store_var 2 (top_tolerated) 638 5 load_var 1 (report) @@ -1677,7 +1677,7 @@ function testing.flatten_with_tolerated(report: testing.TestSetReport) -> testin 639 37 load_var 1 (report) 38 load_field 5 (results) 39 load_var 2 (top_tolerated) - 40 call 735 ntypeargs=0 (testing.count_leaves) + 40 call 759 ntypeargs=0 (testing.count_leaves) 41 store_var 3 (counts) 645 42 load_type 2 @@ -1687,7 +1687,7 @@ function testing.flatten_with_tolerated(report: testing.TestSetReport) -> testin 646 45 load_var 1 (report) 46 load_field 5 (results) 47 load_var 5 (messages) - 48 call 738 ntypeargs=0 (testing.collect_leaf_messages) + 48 call 761 ntypeargs=0 (testing.collect_leaf_messages) 49 pop 1 648 50 load_var 1 (report) @@ -1716,7 +1716,7 @@ function testing.flatten_with_tolerated(report: testing.TestSetReport) -> testin function testing.glob_match(subject: string, pattern: string) -> bool { 489 0 load_var 2 (pattern) 1 load_const 0 ("*") - 2 call 144 ntypeargs=0 (baml.String.split) + 2 call 150 ntypeargs=0 (baml.String.split) 3 store_var 3 (parts) 490 4 load_var 3 (parts) @@ -1741,26 +1741,26 @@ function testing.glob_match(subject: string, pattern: string) -> bool { 20 store_var 6 (last) 496 21 load_var2 1 5 - 22 call 152 ntypeargs=0 (baml.String.starts_with) + 22 call 148 ntypeargs=0 (baml.String.starts_with) 23 unary_op ! 24 pop_jump_if_false +2 (to 26) 25 jump +69 (to 94) 497 26 load_var2 1 6 - 27 call 140 ntypeargs=0 (baml.String.ends_with) + 27 call 149 ntypeargs=0 (baml.String.ends_with) 28 unary_op ! 29 pop_jump_if_false +2 (to 31) 30 jump +62 (to 92) 498 31 load_var 5 (first) - 32 call 160 ntypeargs=0 (baml.String.length) + 32 call 139 ntypeargs=0 (baml.String.length) 33 store_var 7 (start) 499 34 load_var 1 (subject) - 35 call 160 ntypeargs=0 (baml.String.length) + 35 call 139 ntypeargs=0 (baml.String.length) 36 store_var 9 (_22) 37 load_var 6 (last) - 38 call 160 ntypeargs=0 (baml.String.length) + 38 call 139 ntypeargs=0 (baml.String.length) 39 store_var 10 (_23) 40 load_var2 9 10 41 sub_int @@ -1796,9 +1796,9 @@ function testing.glob_match(subject: string, pattern: string) -> bool { 505 65 load_var2 1 11 66 load_var 8 (end_limit) - 67 call 163 ntypeargs=0 (baml.String.substring) + 67 call 153 ntypeargs=0 (baml.String.substring) 68 load_var 13 (part) - 69 call 173 ntypeargs=0 (baml.String.index_of) + 69 call 155 ntypeargs=0 (baml.String.index_of) 70 store_var 14 (_38) 71 load_var 14 (_38) 72 is_type 2 @@ -1814,7 +1814,7 @@ function testing.glob_match(subject: string, pattern: string) -> bool { 79 store_var 15 (_45) 506 80 load_var 13 (part) - 81 call 160 ntypeargs=0 (baml.String.length) + 81 call 139 ntypeargs=0 (baml.String.length) 82 load_var 15 (_45) 83 add_int 84 store_var 11 (pos) @@ -1841,14 +1841,14 @@ function testing.glob_match(subject: string, pattern: string) -> bool { function testing.leaf_selected(name: string, include: testing.FilterPat[], exclude: testing.FilterPat[]) -> bool { 536 0 load_var 1 (name) - 1 call 755 ntypeargs=0 (testing.split_top) + 1 call 750 ntypeargs=0 (testing.split_top) 2 store_var 4 (split) 537 3 load_var2 3 4 4 load_field 0 (head) 5 load_var 4 (split) 6 load_field 1 (tail) - 7 call 757 ntypeargs=0 (testing.any_pattern_matches) + 7 call 754 ntypeargs=0 (testing.any_pattern_matches) 8 pop_jump_if_false +2 (to 10) 9 jump +17 (to 26) @@ -1865,7 +1865,7 @@ function testing.leaf_selected(name: string, include: testing.FilterPat[], exclu 19 load_field 0 (head) 20 load_var 4 (split) 21 load_field 1 (tail) - 22 call 757 ntypeargs=0 (testing.any_pattern_matches) + 22 call 754 ntypeargs=0 (testing.any_pattern_matches) 23 jump +4 (to 27) 541 24 load_const 1 (true) @@ -1899,7 +1899,7 @@ function testing.parse_filter_patterns(raw: string[]) -> testing.FilterPat[] { 476 19 load_var 5 (s) 20 load_const 6 ("::") - 21 call 173 ntypeargs=0 (baml.String.index_of) + 21 call 155 ntypeargs=0 (baml.String.index_of) 22 store_var 6 (_9) 23 load_var 6 (_9) 24 is_type 7 @@ -1909,14 +1909,14 @@ function testing.parse_filter_patterns(raw: string[]) -> testing.FilterPat[] { 479 27 load_var2 2 5 28 load_const 8 ("") 29 init_instance 0 (testing.FilterPat .func_pat, .test_pat) - 30 call 9 ntypeargs=0 (baml.Array.push) + 30 call 4 ntypeargs=0 (baml.Array.push) 31 pop 1 480 32 load_var 2 (out) 33 load_const 9 ("") 34 load_var 5 (s) 35 init_instance 1 (testing.FilterPat .func_pat, .test_pat) - 36 call 9 ntypeargs=0 (baml.Array.push) + 36 call 4 ntypeargs=0 (baml.Array.push) 37 pop 1 38 jump -30 (to 8) @@ -1926,21 +1926,21 @@ function testing.parse_filter_patterns(raw: string[]) -> testing.FilterPat[] { 477 41 load_var 5 (s) 42 load_const 7 (0) 43 load_var 7 (idx) - 44 call 163 ntypeargs=0 (baml.String.substring) + 44 call 153 ntypeargs=0 (baml.String.substring) 45 store_var 8 (_13) 46 load_var 5 (s) - 47 call 160 ntypeargs=0 (baml.String.length) + 47 call 139 ntypeargs=0 (baml.String.length) 48 store_var 10 (_18) 49 load_var2 5 7 50 load_const 10 (2) 51 add_int 52 load_var 10 (_18) - 53 call 163 ntypeargs=0 (baml.String.substring) + 53 call 153 ntypeargs=0 (baml.String.substring) 54 store_var 9 (_15) 55 load_var2 2 8 56 load_var 9 (_15) 57 init_instance 2 (testing.FilterPat .func_pat, .test_pat) - 58 call 9 ntypeargs=0 (baml.Array.push) + 58 call 4 ntypeargs=0 (baml.Array.push) 59 pop 1 60 jump -52 (to 8) @@ -1978,29 +1978,29 @@ function testing.run_children_parallel(children: testing.TestSetChild[]) -> test 24 store_deref 5 370 25 load_var 5 (child) - 26 make_closure 1332 1 + 26 make_closure 1326 1 27 load_const 6 (null) 28 load_const 6 (null) 29 spawn 30 store_var 6 (_11) 31 load_var2 2 6 - 32 call 9 ntypeargs=0 (baml.Array.push) + 32 call 4 ntypeargs=0 (baml.Array.push) 33 pop 1 34 jump -23 (to 11) 374 35 load_type 7 36 load_type 8 37 load_var 2 (futures) - 38 call 505 ntypeargs=2 (baml.future.all_complete) + 38 call 508 ntypeargs=2 (baml.future.all_complete) 39 await 40 jump +5 (to 45) 41 load_var 7 (e) 42 throw_if_panic 375 43 load_const 9 ("unexpected test child failure") - 44 call 244 ntypeargs=0 (baml.sys.panic) + 44 call 246 ntypeargs=0 (baml.sys.panic) - 377 45 call 729 ntypeargs=0 (testing.aggregate_reports) + 377 45 call 745 ntypeargs=0 (testing.aggregate_reports) 46 return } @@ -2034,7 +2034,7 @@ function testing.run_children_sequential(children: testing.TestSetChild[], fail_ 23 load_field 0 (name) 24 load_var 7 (report) 25 init_instance 0 (testing.NamedChildReport .name, .report) - 26 call 9 ntypeargs=0 (baml.Array.push) + 26 call 4 ntypeargs=0 (baml.Array.push) 27 pop 1 111 28 load_var 7 (report) @@ -2054,16 +2054,16 @@ function testing.run_children_sequential(children: testing.TestSetChild[], fail_ 41 pop 1 42 load_var 8 (outcome) 43 load_const 7 ("pass") - 44 call 651 ntypeargs=0 (baml.ops.equals_equals) + 44 call 638 ntypeargs=0 (baml.ops.equals_equals) 45 unary_op ! 46 pop_jump_if_false -38 (to 8) 116 47 load_var 3 (named_results) - 48 call 729 ntypeargs=0 (testing.aggregate_reports) + 48 call 745 ntypeargs=0 (testing.aggregate_reports) 49 jump +3 (to 52) 121 50 load_var 3 (named_results) - 51 call 729 ntypeargs=0 (testing.aggregate_reports) + 51 call 745 ntypeargs=0 (testing.aggregate_reports) 52 return } @@ -2073,7 +2073,7 @@ function testing.run_test(body: () -> void throws unknown, runner: ((() -> testi 2 store_var 1 382 3 load_var 1 (body) - 4 make_closure 1380 1 + 4 make_closure 1336 1 5 store_var 3 (base_run) 406 6 load_var 2 (runner) @@ -2105,17 +2105,17 @@ function testing.run_testset(children: testing.TestSetChild[], runner: ((testing 7 jump +3 (to 10) 418 8 load_var 1 (children) - 9 call 742 ntypeargs=0 (testing.run_children_parallel) + 9 call 746 ntypeargs=0 (testing.run_children_parallel) 10 return } function testing.select_names(registry: testing.TestRegistry, include: string[], exclude: string[]) -> string[] { 549 0 load_var 2 (include) - 1 call 730 ntypeargs=0 (testing.parse_filter_patterns) + 1 call 751 ntypeargs=0 (testing.parse_filter_patterns) 2 store_var 4 (inc) 550 3 load_var 3 (exclude) - 4 call 730 ntypeargs=0 (testing.parse_filter_patterns) + 4 call 751 ntypeargs=0 (testing.parse_filter_patterns) 5 store_var 5 (exc) 551 6 load_type 0 @@ -2123,7 +2123,7 @@ function testing.select_names(registry: testing.TestRegistry, include: string[], 8 store_var 6 (out) 552 9 load_var 1 (registry) - 10 call 733 ntypeargs=0 (testing.collect_leaf_names) + 10 call 757 ntypeargs=0 (testing.collect_leaf_names) 11 load_type 1 12 load_const 2 ("iter") 13 virtual_call nargs=1 ntypeargs=0 @@ -2141,11 +2141,11 @@ function testing.select_names(registry: testing.TestRegistry, include: string[], 25 store_var_load_var 9 (name) 553 26 load_var2 4 5 - 27 call 758 ntypeargs=0 (testing.leaf_selected) + 27 call 755 ntypeargs=0 (testing.leaf_selected) 28 pop_jump_if_false -13 (to 15) 554 29 load_var2 6 9 - 30 call 9 ntypeargs=0 (baml.Array.push) + 30 call 4 ntypeargs=0 (baml.Array.push) 31 pop 1 32 jump -17 (to 15) @@ -2156,7 +2156,7 @@ function testing.select_names(registry: testing.TestRegistry, include: string[], function testing.split_top(path: string) -> testing.NameSplit { 463 0 load_var 1 (path) 1 load_const 0 ("/") - 2 call 173 ntypeargs=0 (baml.String.index_of) + 2 call 155 ntypeargs=0 (baml.String.index_of) 3 store_var 2 (_2) 4 load_var 2 (_2) 5 is_type 1 @@ -2174,15 +2174,15 @@ function testing.split_top(path: string) -> testing.NameSplit { 464 14 load_var 1 (path) 15 load_const 1 (0) 16 load_var 3 (idx) - 17 call 163 ntypeargs=0 (baml.String.substring) + 17 call 153 ntypeargs=0 (baml.String.substring) 18 load_var 1 (path) - 19 call 160 ntypeargs=0 (baml.String.length) + 19 call 139 ntypeargs=0 (baml.String.length) 20 store_var 4 (_10) 21 load_var2 1 3 22 load_const 3 (1) 23 add_int 24 load_var 4 (_10) - 25 call 163 ntypeargs=0 (baml.String.substring) + 25 call 153 ntypeargs=0 (baml.String.substring) 26 init_instance 1 (testing.NameSplit .head, .tail) 27 return } @@ -2198,7 +2198,7 @@ function testing.test_child(name: string, body: () -> void throws unknown, runne 268 6 load_var2 1 2 270 7 load_var 3 (runner) - 8 make_closure 1351 2 + 8 make_closure 1303 2 9 init_instance 0 (testing.TestSetChild .name, .run) 10 return } @@ -2215,7 +2215,7 @@ function testing.testset_child(registry: testing.TestRegistry, ts: testing.TestS 7 load_field 0 (name) 277 8 load_var2 1 2 - 9 make_closure 1369 2 + 9 make_closure 1305 2 10 init_instance 0 (testing.TestSetChild .name, .run) 11 return } @@ -2236,7 +2236,7 @@ function testing.testset_child_selected(registry: testing.TestRegistry, ts: test 289 11 load_var2 1 2 12 load_var 3 (names) - 13 make_closure 1384 3 + 13 make_closure 1307 3 14 init_instance 0 (testing.TestSetChild .name, .run) 15 return } @@ -2270,10 +2270,10 @@ function testing.testset_children(registry: testing.TestRegistry) -> testing.Tes 23 load_field 1 (body) 24 load_var 5 (t) 25 load_field 2 (runner) - 26 call 748 ntypeargs=0 (testing.test_child) + 26 call 740 ntypeargs=0 (testing.test_child) 27 store_var 6 (_10) 28 load_var2 2 6 - 29 call 9 ntypeargs=0 (baml.Array.push) + 29 call 4 ntypeargs=0 (baml.Array.push) 30 pop 1 31 jump -21 (to 10) @@ -2296,11 +2296,11 @@ function testing.testset_children(registry: testing.TestRegistry) -> testing.Tes 238 48 load_var2 1 8 - 237 49 call 756 ntypeargs=0 (testing.testset_child) + 237 49 call 741 ntypeargs=0 (testing.testset_child) 50 store_var 9 (_21) 238 51 load_var2 2 9 - 52 call 9 ntypeargs=0 (baml.Array.push) + 52 call 4 ntypeargs=0 (baml.Array.push) 53 pop 1 54 jump -15 (to 39) @@ -2334,7 +2334,7 @@ function testing.testset_children_selected(registry: testing.TestRegistry, names 246 21 load_field 0 (name) 22 load_var 2 (names) - 23 call 752 ntypeargs=0 (testing._name_selected) + 23 call 743 ntypeargs=0 (testing._name_selected) 24 pop_jump_if_false -14 (to 10) 247 25 load_var 6 (t) @@ -2343,10 +2343,10 @@ function testing.testset_children_selected(registry: testing.TestRegistry, names 28 load_field 1 (body) 29 load_var 6 (t) 30 load_field 2 (runner) - 31 call 748 ntypeargs=0 (testing.test_child) + 31 call 740 ntypeargs=0 (testing.test_child) 32 store_var 7 (_13) 33 load_var2 3 7 - 34 call 9 ntypeargs=0 (baml.Array.push) + 34 call 4 ntypeargs=0 (baml.Array.push) 35 pop 1 36 jump -26 (to 10) @@ -2371,15 +2371,15 @@ function testing.testset_children_selected(registry: testing.TestRegistry, names 258 55 load_field 0 (name) 56 load_var 2 (names) - 57 call 734 ntypeargs=0 (testing._has_selected_descendant) + 57 call 744 ntypeargs=0 (testing._has_selected_descendant) 58 pop_jump_if_false -14 (to 44) 259 59 load_var2 1 10 60 load_var 2 (names) - 61 call 761 ntypeargs=0 (testing.testset_child_selected) + 61 call 742 ntypeargs=0 (testing.testset_child_selected) 62 store_var 11 (_26) 63 load_var2 3 11 - 64 call 9 ntypeargs=0 (baml.Array.push) + 64 call 4 ntypeargs=0 (baml.Array.push) 65 pop 1 66 jump -22 (to 44) @@ -2396,7 +2396,7 @@ function user.User.promote(self: User, bonus: int) -> Report { 5 store_field 1 (age) 10 6 load_var2 1 2 - 7 call 775 ntypeargs=0 (user.score) + 7 call 776 ntypeargs=0 (user.score) 8 store_var 3 (base) 11 9 load_var 3 (base) diff --git a/baml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded_unoptimized.snap b/baml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded_unoptimized.snap index ad6b67cab0c..5c5867317af 100644 --- a/baml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded_unoptimized.snap +++ b/baml_language/crates/baml_tests/tests/bytecode_format/snapshots/bytecode_format__bytecode_display_expanded_unoptimized.snap @@ -9,17 +9,17 @@ function assert.approx_equal(actual: float, expected: float, eps: float) -> null 4 jump +4 (to 8) 5 pop 1 6 load_var 3 (eps) - 7 call 136 ntypeargs=0 (baml.Float.is_nan) + 7 call 95 ntypeargs=0 (baml.Float.is_nan) 8 pop_jump_if_false +2 (to 10) 9 jump +45 (to 54) 80 10 load_var2 1 2 11 sub_float - 12 call 129 ntypeargs=0 (baml.Float.abs) + 12 call 98 ntypeargs=0 (baml.Float.abs) 13 store_var 4 (delta) 81 14 load_var 4 (delta) - 15 call 136 ntypeargs=0 (baml.Float.is_nan) + 15 call 95 ntypeargs=0 (baml.Float.is_nan) 16 jump_if_false +2 (to 18) 17 jump +4 (to 21) 18 pop 1 @@ -33,19 +33,19 @@ function assert.approx_equal(actual: float, expected: float, eps: float) -> null 81 24 jump +32 (to 56) 84 25 load_var 4 (delta) - 26 call 772 ntypeargs=0 (assert.format_operand) + 26 call 771 ntypeargs=0 (assert.format_operand) 27 store_var 5 (_18) 86 28 load_var 3 (eps) - 29 call 772 ntypeargs=0 (assert.format_operand) + 29 call 771 ntypeargs=0 (assert.format_operand) 30 store_var 6 (_20) 88 31 load_var 1 (actual) - 32 call 772 ntypeargs=0 (assert.format_operand) + 32 call 771 ntypeargs=0 (assert.format_operand) 33 store_var 7 (_21) 90 34 load_var 2 (expected) - 35 call 772 ntypeargs=0 (assert.format_operand) + 35 call 771 ntypeargs=0 (assert.format_operand) 36 store_var 8 (_22) 84 37 load_const 2 ("assertion failed: |left - right| = ") @@ -63,17 +63,17 @@ function assert.approx_equal(actual: float, expected: float, eps: float) -> null 49 bin_op + 50 load_var 8 (_22) 51 bin_op + - 52 call 244 ntypeargs=0 (baml.sys.panic) + 52 call 246 ntypeargs=0 (baml.sys.panic) 53 jump +3 (to 56) 78 54 load_const 6 ("assertion failed: epsilon must be a non-negative number") - 55 call 244 ntypeargs=0 (baml.sys.panic) + 55 call 246 ntypeargs=0 (baml.sys.panic) 56 return } function assert.contains(haystack: string, needle: string) -> null { 100 0 load_var2 1 2 - 1 call 181 ntypeargs=0 (baml.String.includes) + 1 call 147 ntypeargs=0 (baml.String.includes) 2 unary_op ! 3 pop_jump_if_false +2 (to 5) 4 jump +3 (to 7) @@ -83,13 +83,13 @@ function assert.contains(haystack: string, needle: string) -> null { 100 6 jump +3 (to 9) 101 7 load_const 1 ("assertion failed: string does not contain expected substring") - 8 call 244 ntypeargs=0 (baml.sys.panic) + 8 call 246 ntypeargs=0 (baml.sys.panic) 9 return } function assert.equal(actual: unknown, expected: unknown) -> null { 50 0 load_var2 1 2 - 1 call 651 ntypeargs=0 (baml.ops.equals_equals) + 1 call 638 ntypeargs=0 (baml.ops.equals_equals) 2 unary_op ! 3 pop_jump_if_false +2 (to 5) 4 jump +3 (to 7) @@ -99,11 +99,11 @@ function assert.equal(actual: unknown, expected: unknown) -> null { 50 6 jump +15 (to 21) 53 7 load_var 1 (actual) - 8 call 772 ntypeargs=0 (assert.format_operand) + 8 call 771 ntypeargs=0 (assert.format_operand) 9 store_var 3 (_8) 55 10 load_var 2 (expected) - 11 call 772 ntypeargs=0 (assert.format_operand) + 11 call 771 ntypeargs=0 (assert.format_operand) 12 store_var 4 (_9) 53 13 load_const 1 ("assertion failed: left = ") @@ -113,13 +113,13 @@ function assert.equal(actual: unknown, expected: unknown) -> null { 17 bin_op + 18 load_var 4 (_9) 19 bin_op + - 20 call 244 ntypeargs=0 (baml.sys.panic) + 20 call 246 ntypeargs=0 (baml.sys.panic) 21 return } function assert.format_operand(value: unknown) -> string { 32 0 load_var 1 (value) - 1 call 153 ntypeargs=0 (baml.String.from) + 1 call 138 ntypeargs=0 (baml.String.from) 2 return } @@ -134,14 +134,14 @@ function assert.is_true(condition: bool) -> null { 5 5 jump +3 (to 8) 6 6 load_const 1 ("assertion failed: expected true") - 7 call 244 ntypeargs=0 (baml.sys.panic) + 7 call 246 ntypeargs=0 (baml.sys.panic) 8 return } function assert.not_null(value: unknown | null) -> null { 14 0 load_var 1 (value) 1 load_const 0 (null) - 2 call 651 ntypeargs=0 (baml.ops.equals_equals) + 2 call 638 ntypeargs=0 (baml.ops.equals_equals) 3 pop_jump_if_false +2 (to 5) 4 jump +3 (to 7) @@ -150,7 +150,7 @@ function assert.not_null(value: unknown | null) -> null { 14 6 jump +3 (to 9) 15 7 load_const 1 ("assertion failed: expected non-null value") - 8 call 244 ntypeargs=0 (baml.sys.panic) + 8 call 246 ntypeargs=0 (baml.sys.panic) 9 return } @@ -176,7 +176,7 @@ function testing.$invoke_collector(collector: (testing.TestCollector) -> void th } function testing.FailFast() -> (testing.TestSetChild[]) -> testing.TestSetReport throws never { - 101 0 make_closure 1386 0 + 101 0 make_closure 1413 0 1 store_var 1 (_0) 2 load_var 1 (_0) 3 return @@ -199,11 +199,11 @@ function testing.PassRate(threshold: float) -> (testing.TestSetChild[]) -> testi 12 pop_jump_if_false +4 (to 16) 69 13 load_const 2 ("testing.PassRate requires 0.0 <= threshold <= 1.0") - 14 call 244 ntypeargs=0 (baml.sys.panic) + 14 call 246 ntypeargs=0 (baml.sys.panic) 15 pop 1 74 16 load_var 1 (threshold) - 17 make_closure 1399 1 + 17 make_closure 1408 1 18 store_var 2 (_0) 19 load_var 2 (_0) 20 return @@ -235,16 +235,16 @@ function testing.Quorum(n: int, m: int) -> (() -> testing.TestReport throws neve 20 pop_jump_if_false +8 (to 28) 5 21 load_const 1 ("testing.Quorum requires 0 <= m <= n") - 22 call 244 ntypeargs=0 (baml.sys.panic) + 22 call 246 ntypeargs=0 (baml.sys.panic) 23 pop 1 24 jump +4 (to 28) 3 25 load_const 2 ("testing.Quorum requires n > 0") - 26 call 244 ntypeargs=0 (baml.sys.panic) + 26 call 246 ntypeargs=0 (baml.sys.panic) 27 pop 1 10 28 load_var2 1 2 - 29 make_closure 1417 2 + 29 make_closure 1392 2 30 store_var 3 (_0) 31 load_var 3 (_0) 32 return @@ -261,18 +261,18 @@ function testing.Retry(max_attempts: int) -> (() -> testing.TestReport throws ne 6 pop_jump_if_false +4 (to 10) 36 7 load_const 1 ("testing.Retry requires max_attempts > 0") - 8 call 244 ntypeargs=0 (baml.sys.panic) + 8 call 246 ntypeargs=0 (baml.sys.panic) 9 pop 1 41 10 load_var 1 (max_attempts) - 11 make_closure 1408 1 + 11 make_closure 1402 1 12 store_var 2 (_0) 13 load_var 2 (_0) 14 return } function testing.Sequential() -> (testing.TestSetChild[]) -> testing.TestSetReport throws never { - 95 0 make_closure 1390 0 + 95 0 make_closure 1411 0 1 store_var 1 (_0) 2 load_var 1 (_0) 3 return @@ -413,7 +413,7 @@ function testing.TestCollector.register_test(self: testing.TestCollector, name: 45 load_var 11 (t) 46 load_field 0 (name) 47 load_var 8 (hash_prefix) - 48 call 152 ntypeargs=0 (baml.String.starts_with) + 48 call 148 ntypeargs=0 (baml.String.starts_with) 49 pop_jump_if_false -21 (to 28) 50 load_var 7 (count) 51 load_const 9 (1) @@ -437,7 +437,7 @@ function testing.TestCollector.register_test(self: testing.TestCollector, name: 68 load_var 7 (count) 69 load_const 9 (1) 70 add_int - 71 call 153 ntypeargs=1 (baml.String.from) + 71 call 138 ntypeargs=1 (baml.String.from) 72 store_var 14 (_30) 73 load_var2 13 14 74 bin_op + @@ -449,7 +449,7 @@ function testing.TestCollector.register_test(self: testing.TestCollector, name: 79 load_var2 12 3 80 load_var 4 (runner) 81 init_instance 0 (testing.TestRegistration .name, .body, .runner) - 82 call 9 ntypeargs=1 (baml.Array.push) + 82 call 4 ntypeargs=1 (baml.Array.push) 83 pop 1 26 84 load_const 13 (null) @@ -511,7 +511,7 @@ function testing.TestCollector.register_test_set(self: testing.TestCollector, na 45 load_var 11 (ts) 46 load_field 0 (name) 47 load_var 8 (hash_prefix) - 48 call 152 ntypeargs=0 (baml.String.starts_with) + 48 call 148 ntypeargs=0 (baml.String.starts_with) 49 pop_jump_if_false -21 (to 28) 50 load_var 7 (count) 51 load_const 9 (1) @@ -535,7 +535,7 @@ function testing.TestCollector.register_test_set(self: testing.TestCollector, na 68 load_var 7 (count) 69 load_const 9 (1) 70 add_int - 71 call 153 ntypeargs=1 (baml.String.from) + 71 call 138 ntypeargs=1 (baml.String.from) 72 store_var 14 (_30) 73 load_var2 13 14 74 bin_op + @@ -547,7 +547,7 @@ function testing.TestCollector.register_test_set(self: testing.TestCollector, na 79 load_var2 12 3 80 load_var 4 (runner) 81 init_instance 0 (testing.TestSetRegistration .name, .collector, .runner) - 82 call 9 ntypeargs=1 (baml.Array.push) + 82 call 4 ntypeargs=1 (baml.Array.push) 83 pop 1 37 84 load_const 13 (null) @@ -582,18 +582,18 @@ function testing.TestRegistry.expand_set(self: testing.TestRegistry, name: strin 21 pop_jump_if_false -14 (to 7) 198 22 load_var2 1 5 - 23 call 749 ntypeargs=0 (testing.TestRegistry.expand_testset_registry) + 23 call 737 ntypeargs=0 (testing.TestRegistry.expand_testset_registry) 24 pop 1 199 25 load_var 1 (self) - 26 call 732 ntypeargs=0 (testing.TestRegistry.serialize) + 26 call 729 ntypeargs=0 (testing.TestRegistry.serialize) 27 jump +33 (to 60) 203 28 load_type 5 29 load_type 6 30 load_var 1 (self) 31 load_field 1 (expansions) - 32 call 11 ntypeargs=2 (baml.Map.keys) + 32 call 35 ntypeargs=2 (baml.Map.keys) 33 load_type 7 34 load_const 8 ("iter") 35 virtual_call nargs=1 ntypeargs=0 @@ -619,11 +619,11 @@ function testing.TestRegistry.expand_set(self: testing.TestRegistry, name: strin 205 53 load_var2 2 8 54 load_const 11 ("/") 55 bin_op + - 56 call 152 ntypeargs=0 (baml.String.starts_with) + 56 call 148 ntypeargs=0 (baml.String.starts_with) 57 pop_jump_if_false -20 (to 37) 206 58 load_var2 9 2 - 59 call 737 ntypeargs=0 (testing.TestRegistry.expand_set) + 59 call 736 ntypeargs=0 (testing.TestRegistry.expand_set) 60 return 209 61 load_const 12 ("TestSet not found for expansion: ") @@ -639,14 +639,14 @@ function testing.TestRegistry.expand_testset_registry(self: testing.TestRegistry 3 load_field 1 (expansions) 4 load_var 2 (ts) 5 load_field 0 (name) - 6 call 44 ntypeargs=2 (baml.Map.get) + 6 call 38 ntypeargs=2 (baml.Map.get) 7 store_var 3 (_3) 8 load_var 3 (_3) 9 is_type 2 10 pop_jump_if_false +2 (to 12) 11 jump +37 (to 48) - 216 12 call 249 ntypeargs=0 (baml.sys.now_ms) + 216 12 call 248 ntypeargs=0 (baml.sys.now_ms) 13 store_var 5 (start) 217 14 load_var 2 (ts) @@ -663,7 +663,7 @@ function testing.TestRegistry.expand_testset_registry(self: testing.TestRegistry 24 call_indirect 25 pop 1 - 219 26 call 249 ntypeargs=0 (baml.sys.now_ms) + 219 26 call 248 ntypeargs=0 (baml.sys.now_ms) 27 load_var 5 (start) 28 sub_int 29 store_var 7 (elapsed) @@ -685,7 +685,7 @@ function testing.TestRegistry.expand_testset_registry(self: testing.TestRegistry 41 load_var 2 (ts) 42 load_field 0 (name) 43 load_var 8 (sub_registry) - 44 call 12 ntypeargs=2 (baml.Map.set) + 44 call 37 ntypeargs=2 (baml.Map.set) 45 pop 1 226 46 load_var 8 (sub_registry) @@ -701,7 +701,7 @@ function testing.TestRegistry.expand_testset_registry(self: testing.TestRegistry function testing.TestRegistry.list_filtered(self: testing.TestRegistry, include: string[], exclude: string[]) -> string[] { 189 0 load_var2 1 2 1 load_var 3 (exclude) - 2 call 731 ntypeargs=0 (testing.select_names) + 2 call 756 ntypeargs=0 (testing.select_names) 3 return } @@ -720,9 +720,9 @@ function testing.TestRegistry.new(collector: testing.TestCollector) -> testing.T function testing.TestRegistry.run_all(self: testing.TestRegistry) -> testing.TestSetReport { 166 0 load_var 1 (self) - 1 call 747 ntypeargs=0 (testing.testset_children) + 1 call 738 ntypeargs=0 (testing.testset_children) 2 load_const 0 (null) - 3 call 725 ntypeargs=0 (testing.run_testset) + 3 call 748 ntypeargs=0 (testing.run_testset) 4 return } @@ -746,14 +746,14 @@ function testing.TestRegistry.run_filtered(self: testing.TestRegistry, include: 182 16 load_var2 1 2 17 load_var 3 (exclude) - 18 call 731 ntypeargs=0 (testing.select_names) + 18 call 756 ntypeargs=0 (testing.select_names) 19 store_var 6 (_9) 20 load_var2 1 6 - 21 call 722 ntypeargs=0 (testing.TestRegistry.run_selected) + 21 call 733 ntypeargs=0 (testing.TestRegistry.run_selected) 22 jump +3 (to 25) 180 23 load_var 1 (self) - 24 call 744 ntypeargs=0 (testing.TestRegistry.run_all) + 24 call 732 ntypeargs=0 (testing.TestRegistry.run_all) 184 25 call 760 ntypeargs=0 (testing.flatten_with_tolerated) 26 return @@ -761,9 +761,9 @@ function testing.TestRegistry.run_filtered(self: testing.TestRegistry, include: function testing.TestRegistry.run_selected(self: testing.TestRegistry, names: string[]) -> testing.TestSetReport { 170 0 load_var2 1 2 - 1 call 728 ntypeargs=0 (testing.testset_children_selected) + 1 call 739 ntypeargs=0 (testing.testset_children_selected) 2 load_const 0 (null) - 3 call 725 ntypeargs=0 (testing.run_testset) + 3 call 748 ntypeargs=0 (testing.run_testset) 4 return } @@ -796,14 +796,14 @@ function testing.TestRegistry.run_test(self: testing.TestRegistry, name: string) 23 load_field 1 (body) 24 load_var 5 (t) 25 load_field 2 (runner) - 26 call 759 ntypeargs=0 (testing.run_test) + 26 call 747 ntypeargs=0 (testing.run_test) 27 jump +33 (to 60) 140 28 load_type 5 29 load_type 6 30 load_var 1 (self) 31 load_field 1 (expansions) - 32 call 11 ntypeargs=2 (baml.Map.keys) + 32 call 35 ntypeargs=2 (baml.Map.keys) 33 load_type 7 34 load_const 8 ("iter") 35 virtual_call nargs=1 ntypeargs=0 @@ -829,11 +829,11 @@ function testing.TestRegistry.run_test(self: testing.TestRegistry, name: string) 143 53 load_var2 2 8 54 load_const 11 ("/") 55 bin_op + - 56 call 152 ntypeargs=0 (baml.String.starts_with) + 56 call 148 ntypeargs=0 (baml.String.starts_with) 57 pop_jump_if_false -20 (to 37) 144 58 load_var2 9 2 - 59 call 736 ntypeargs=0 (testing.TestRegistry.run_test) + 59 call 730 ntypeargs=0 (testing.TestRegistry.run_test) 60 return 147 61 load_const 12 ("Test not found: ") @@ -868,18 +868,18 @@ function testing.TestRegistry.run_testset(self: testing.TestRegistry, name: stri 21 pop_jump_if_false -14 (to 7) 153 22 load_var2 1 5 - 23 call 749 ntypeargs=0 (testing.TestRegistry.expand_testset_registry) - 24 call 747 ntypeargs=0 (testing.testset_children) + 23 call 737 ntypeargs=0 (testing.TestRegistry.expand_testset_registry) + 24 call 738 ntypeargs=0 (testing.testset_children) 25 load_var 5 (ts) 26 load_field 2 (runner) - 27 call 725 ntypeargs=0 (testing.run_testset) + 27 call 748 ntypeargs=0 (testing.run_testset) 28 jump +33 (to 61) 156 29 load_type 5 30 load_type 6 31 load_var 1 (self) 32 load_field 1 (expansions) - 33 call 11 ntypeargs=2 (baml.Map.keys) + 33 call 35 ntypeargs=2 (baml.Map.keys) 34 load_type 7 35 load_const 8 ("iter") 36 virtual_call nargs=1 ntypeargs=0 @@ -905,11 +905,11 @@ function testing.TestRegistry.run_testset(self: testing.TestRegistry, name: stri 158 54 load_var2 2 8 55 load_const 11 ("/") 56 bin_op + - 57 call 152 ntypeargs=0 (baml.String.starts_with) + 57 call 148 ntypeargs=0 (baml.String.starts_with) 58 pop_jump_if_false -20 (to 38) 159 59 load_var2 9 2 - 60 call 740 ntypeargs=0 (testing.TestRegistry.run_testset) + 60 call 731 ntypeargs=0 (testing.TestRegistry.run_testset) 61 return 162 62 load_const 12 ("TestSet not found: ") @@ -947,7 +947,7 @@ function testing.TestRegistry.serialize(self: testing.TestRegistry) -> (testing. 23 load_var 6 (t) 24 load_field 0 (name) 25 init_instance 0 (testing.SerializedTest .type, .name) - 26 call 9 ntypeargs=0 (baml.Array.push) + 26 call 4 ntypeargs=0 (baml.Array.push) 27 pop 1 28 jump -18 (to 10) @@ -976,7 +976,7 @@ function testing.TestRegistry.serialize(self: testing.TestRegistry) -> (testing. 50 load_field 1 (expansions) 51 load_var 9 (ts) 52 load_field 0 (name) - 53 call 44 ntypeargs=2 (baml.Map.get) + 53 call 38 ntypeargs=2 (baml.Map.get) 54 store_var 10 (expanded) 115 55 load_var 10 (expanded) @@ -989,7 +989,7 @@ function testing.TestRegistry.serialize(self: testing.TestRegistry) -> (testing. 61 load_var 9 (ts) 62 load_field 0 (name) 63 init_instance 1 (testing.SerializedTest .type, .name) - 64 call 9 ntypeargs=0 (baml.Array.push) + 64 call 4 ntypeargs=0 (baml.Array.push) 65 pop 1 66 jump -30 (to 36) @@ -1001,7 +1001,7 @@ function testing.TestRegistry.serialize(self: testing.TestRegistry) -> (testing. 71 store_var 12 (_27) 119 72 load_var 11 (sub) - 73 call 732 ntypeargs=0 (testing.TestRegistry.serialize) + 73 call 729 ntypeargs=0 (testing.TestRegistry.serialize) 74 store_var 13 (_28) 117 75 load_var2 3 12 @@ -1009,7 +1009,7 @@ function testing.TestRegistry.serialize(self: testing.TestRegistry) -> (testing. 120 77 load_field 2 (loading_time_ms) 78 init_instance 2 (testing.SerializedTestSet .name, .items, .loadingTimeMs) - 79 call 9 ntypeargs=0 (baml.Array.push) + 79 call 4 ntypeargs=0 (baml.Array.push) 80 pop 1 81 jump -45 (to 36) @@ -1043,7 +1043,7 @@ function testing._has_selected_descendant(prefix: string, names: string[]) -> bo 19 store_var 6 (selected) 312 20 load_var2 6 3 - 21 call 152 ntypeargs=0 (baml.String.starts_with) + 21 call 148 ntypeargs=0 (baml.String.starts_with) 22 pop_jump_if_false -13 (to 9) 313 23 load_const 6 (true) @@ -1056,14 +1056,14 @@ function testing._has_selected_descendant(prefix: string, names: string[]) -> bo function testing._int_to_float(value: int) -> float { 125 0 load_type 0 1 load_var 1 (value) - 2 call 153 ntypeargs=1 (baml.String.from) - 3 call 127 ntypeargs=0 (baml.Float.parse) + 2 call 138 ntypeargs=1 (baml.String.from) + 3 call 130 ntypeargs=0 (baml.Float.parse) 4 jump +5 (to 9) 5 load_var 2 (e) 6 throw_if_panic 126 7 load_const 1 ("failed to convert int to float") - 8 call 244 ntypeargs=0 (baml.sys.panic) + 8 call 246 ntypeargs=0 (baml.sys.panic) 9 return } @@ -1136,7 +1136,7 @@ function testing.aggregate_reports(named_results: testing.NamedChildReport[]) -> 30 store_var 11 (result) 329 31 load_var2 7 11 - 32 call 9 ntypeargs=0 (baml.Array.push) + 32 call 4 ntypeargs=0 (baml.Array.push) 33 pop 1 330 34 load_var 11 (result) @@ -1160,7 +1160,7 @@ function testing.aggregate_reports(named_results: testing.NamedChildReport[]) -> 334 49 load_var 12 (outcome) 50 load_const 10 ("pass") - 51 call 651 ntypeargs=0 (baml.ops.equals_equals) + 51 call 638 ntypeargs=0 (baml.ops.equals_equals) 52 pop_jump_if_false +2 (to 54) 53 jump +57 (to 110) @@ -1219,13 +1219,13 @@ function testing.aggregate_reports(named_results: testing.NamedChildReport[]) -> 98 store_var 19 (name) 347 99 load_var2 6 19 - 100 call 9 ntypeargs=0 (baml.Array.push) + 100 call 4 ntypeargs=0 (baml.Array.push) 101 pop 1 102 jump -14 (to 88) 349 103 load_var 12 (outcome) 104 load_const 16 ("error") - 105 call 651 ntypeargs=0 (baml.ops.equals_equals) + 105 call 638 ntypeargs=0 (baml.ops.equals_equals) 106 pop_jump_if_false -89 (to 17) 350 107 load_const 17 (true) @@ -1297,13 +1297,13 @@ function testing.any_pattern_matches(pats: testing.FilterPat[], function_name: s 526 16 load_field 0 (func_pat) 17 load_var 2 (function_name) - 18 call 745 ntypeargs=0 (testing.filter_match) + 18 call 753 ntypeargs=0 (testing.filter_match) 19 jump_if_false +6 (to 25) 20 pop 1 21 load_var 6 (p) 22 load_field 1 (test_pat) 23 load_var 3 (test_name) - 24 call 745 ntypeargs=0 (testing.filter_match) + 24 call 753 ntypeargs=0 (testing.filter_match) 25 pop_jump_if_false -20 (to 5) 527 26 load_const 5 (true) @@ -1339,7 +1339,7 @@ function testing.collect_leaf_messages(results: (testing.TestReport | testing.Te 673 21 load_field 5 (results) 22 load_var 2 (out) - 23 call 738 ntypeargs=0 (testing.collect_leaf_messages) + 23 call 761 ntypeargs=0 (testing.collect_leaf_messages) 24 pop 1 25 jump -20 (to 5) @@ -1365,7 +1365,7 @@ function testing.collect_leaf_messages(results: (testing.TestReport | testing.Te 665 44 load_field 0 (outcome) 45 load_const 10 ("pass") - 46 call 651 ntypeargs=0 (baml.ops.equals_equals) + 46 call 638 ntypeargs=0 (baml.ops.equals_equals) 47 unary_op ! 48 pop_jump_if_false -15 (to 33) @@ -1378,7 +1378,7 @@ function testing.collect_leaf_messages(results: (testing.TestReport | testing.Te 55 store_var 12 (m) 667 56 load_var2 2 12 - 57 call 9 ntypeargs=0 (baml.Array.push) + 57 call 4 ntypeargs=0 (baml.Array.push) 58 pop 1 59 jump -26 (to 33) @@ -1414,7 +1414,7 @@ function testing.collect_leaf_names(registry: testing.TestRegistry) -> string[] 564 21 load_var2 3 6 22 load_field 0 (name) - 23 call 9 ntypeargs=0 (baml.Array.push) + 23 call 4 ntypeargs=0 (baml.Array.push) 24 pop 1 25 jump -15 (to 10) @@ -1438,7 +1438,7 @@ function testing.collect_leaf_names(registry: testing.TestRegistry) -> string[] 43 store_var 9 (ts) 567 44 load_var2 1 9 - 45 call 750 ntypeargs=0 (testing.collect_subtree_names) + 45 call 758 ntypeargs=0 (testing.collect_subtree_names) 46 load_type 10 47 load_const 11 ("iter") 48 virtual_call nargs=1 ntypeargs=0 @@ -1456,7 +1456,7 @@ function testing.collect_leaf_names(registry: testing.TestRegistry) -> string[] 60 store_var 12 (name) 568 61 load_var2 3 12 - 62 call 9 ntypeargs=0 (baml.Array.push) + 62 call 4 ntypeargs=0 (baml.Array.push) 63 pop 1 64 jump -14 (to 50) @@ -1468,8 +1468,8 @@ function testing.collect_leaf_names(registry: testing.TestRegistry) -> string[] function testing.collect_subtree_names(registry: testing.TestRegistry, ts: testing.TestSetRegistration) -> string[] { 580 0 load_var2 1 2 - 1 call 749 ntypeargs=0 (testing.TestRegistry.expand_testset_registry) - 2 call 733 ntypeargs=0 (testing.collect_leaf_names) + 1 call 737 ntypeargs=0 (testing.TestRegistry.expand_testset_registry) + 2 call 757 ntypeargs=0 (testing.collect_leaf_names) 3 jump +20 (to 23) 4 load_var 3 (e) 5 type_tag @@ -1540,7 +1540,7 @@ function testing.count_leaves(results: (testing.TestReport | testing.TestSetRepo 34 load_var 12 (tsr) 35 load_field 0 (outcome) 36 load_const 7 ("pass") - 37 call 651 ntypeargs=0 (baml.ops.equals_equals) + 37 call 638 ntypeargs=0 (baml.ops.equals_equals) 38 store_var 13 (ft) 615 39 load_var 12 (tsr) @@ -1584,7 +1584,7 @@ function testing.count_leaves(results: (testing.TestReport | testing.TestSetRepo 616 71 load_var 12 (tsr) 72 load_field 5 (results) 73 load_var 13 (ft) - 74 call 735 ntypeargs=0 (testing.count_leaves) + 74 call 759 ntypeargs=0 (testing.count_leaves) 75 store_var 10 (delta) 76 jump +31 (to 107) @@ -1593,7 +1593,7 @@ function testing.count_leaves(results: (testing.TestReport | testing.TestSetRepo 605 79 load_field 0 (outcome) 80 load_const 8 ("pass") - 81 call 651 ntypeargs=0 (baml.ops.equals_equals) + 81 call 638 ntypeargs=0 (baml.ops.equals_equals) 82 pop_jump_if_false +2 (to 84) 83 jump +18 (to 101) @@ -1682,7 +1682,7 @@ function testing.filter_match(expr: string, subject: string) -> bool { 4 jump +4 (to 8) 520 5 load_var2 2 1 - 6 call 743 ntypeargs=0 (testing.glob_match) + 6 call 752 ntypeargs=0 (testing.glob_match) 7 jump +2 (to 9) 518 8 load_const 1 (true) @@ -1693,7 +1693,7 @@ function testing.flatten_with_tolerated(report: testing.TestSetReport) -> testin 637 0 load_var 1 (report) 1 load_field 0 (outcome) 2 load_const 0 ("pass") - 3 call 651 ntypeargs=0 (baml.ops.equals_equals) + 3 call 638 ntypeargs=0 (baml.ops.equals_equals) 4 store_var 2 (top_tolerated) 638 5 load_var 1 (report) @@ -1737,7 +1737,7 @@ function testing.flatten_with_tolerated(report: testing.TestSetReport) -> testin 639 37 load_var 1 (report) 38 load_field 5 (results) 39 load_var 2 (top_tolerated) - 40 call 735 ntypeargs=0 (testing.count_leaves) + 40 call 759 ntypeargs=0 (testing.count_leaves) 41 store_var 3 (counts) 645 42 load_type 2 @@ -1747,7 +1747,7 @@ function testing.flatten_with_tolerated(report: testing.TestSetReport) -> testin 646 45 load_var 1 (report) 46 load_field 5 (results) 47 load_var 5 (messages) - 48 call 738 ntypeargs=0 (testing.collect_leaf_messages) + 48 call 761 ntypeargs=0 (testing.collect_leaf_messages) 49 pop 1 648 50 load_var 1 (report) @@ -1776,7 +1776,7 @@ function testing.flatten_with_tolerated(report: testing.TestSetReport) -> testin function testing.glob_match(subject: string, pattern: string) -> bool { 489 0 load_var 2 (pattern) 1 load_const 0 ("*") - 2 call 144 ntypeargs=0 (baml.String.split) + 2 call 150 ntypeargs=0 (baml.String.split) 3 store_var 3 (parts) 490 4 load_var 3 (parts) @@ -1801,26 +1801,26 @@ function testing.glob_match(subject: string, pattern: string) -> bool { 20 store_var 6 (last) 496 21 load_var2 1 5 - 22 call 152 ntypeargs=0 (baml.String.starts_with) + 22 call 148 ntypeargs=0 (baml.String.starts_with) 23 unary_op ! 24 pop_jump_if_false +2 (to 26) 25 jump +71 (to 96) 497 26 load_var2 1 6 - 27 call 140 ntypeargs=0 (baml.String.ends_with) + 27 call 149 ntypeargs=0 (baml.String.ends_with) 28 unary_op ! 29 pop_jump_if_false +2 (to 31) 30 jump +64 (to 94) 498 31 load_var 5 (first) - 32 call 160 ntypeargs=0 (baml.String.length) + 32 call 139 ntypeargs=0 (baml.String.length) 33 store_var 7 (start) 499 34 load_var 1 (subject) - 35 call 160 ntypeargs=0 (baml.String.length) + 35 call 139 ntypeargs=0 (baml.String.length) 36 store_var 9 (_22) 37 load_var 6 (last) - 38 call 160 ntypeargs=0 (baml.String.length) + 38 call 139 ntypeargs=0 (baml.String.length) 39 store_var 10 (_23) 40 load_var2 9 10 41 sub_int @@ -1856,9 +1856,9 @@ function testing.glob_match(subject: string, pattern: string) -> bool { 505 65 load_var2 1 11 66 load_var 8 (end_limit) - 67 call 163 ntypeargs=0 (baml.String.substring) + 67 call 153 ntypeargs=0 (baml.String.substring) 68 load_var 13 (part) - 69 call 173 ntypeargs=0 (baml.String.index_of) + 69 call 155 ntypeargs=0 (baml.String.index_of) 70 store_var 14 (_38) 71 load_var 14 (_38) 72 is_type 2 @@ -1875,7 +1875,7 @@ function testing.glob_match(subject: string, pattern: string) -> bool { 80 add_int 81 store_var 16 (_45) 82 load_var 13 (part) - 83 call 160 ntypeargs=0 (baml.String.length) + 83 call 139 ntypeargs=0 (baml.String.length) 84 load_var 16 (_45) 85 add_int 86 store_var 11 (pos) @@ -1902,14 +1902,14 @@ function testing.glob_match(subject: string, pattern: string) -> bool { function testing.leaf_selected(name: string, include: testing.FilterPat[], exclude: testing.FilterPat[]) -> bool { 536 0 load_var 1 (name) - 1 call 755 ntypeargs=0 (testing.split_top) + 1 call 750 ntypeargs=0 (testing.split_top) 2 store_var 4 (split) 537 3 load_var2 3 4 4 load_field 0 (head) 5 load_var 4 (split) 6 load_field 1 (tail) - 7 call 757 ntypeargs=0 (testing.any_pattern_matches) + 7 call 754 ntypeargs=0 (testing.any_pattern_matches) 8 pop_jump_if_false +2 (to 10) 9 jump +17 (to 26) @@ -1926,7 +1926,7 @@ function testing.leaf_selected(name: string, include: testing.FilterPat[], exclu 19 load_field 0 (head) 20 load_var 4 (split) 21 load_field 1 (tail) - 22 call 757 ntypeargs=0 (testing.any_pattern_matches) + 22 call 754 ntypeargs=0 (testing.any_pattern_matches) 23 jump +4 (to 27) 541 24 load_const 1 (true) @@ -1960,7 +1960,7 @@ function testing.parse_filter_patterns(raw: string[]) -> testing.FilterPat[] { 476 19 load_var 6 (s) 20 load_const 6 ("::") - 21 call 173 ntypeargs=0 (baml.String.index_of) + 21 call 155 ntypeargs=0 (baml.String.index_of) 22 store_var 7 (_9) 23 load_var 7 (_9) 24 is_type 7 @@ -1970,14 +1970,14 @@ function testing.parse_filter_patterns(raw: string[]) -> testing.FilterPat[] { 479 27 load_var2 3 6 28 load_const 8 ("") 29 init_instance 0 (testing.FilterPat .func_pat, .test_pat) - 30 call 9 ntypeargs=0 (baml.Array.push) + 30 call 4 ntypeargs=0 (baml.Array.push) 31 pop 1 480 32 load_var 3 (out) 33 load_const 9 ("") 34 load_var 6 (s) 35 init_instance 1 (testing.FilterPat .func_pat, .test_pat) - 36 call 9 ntypeargs=0 (baml.Array.push) + 36 call 4 ntypeargs=0 (baml.Array.push) 37 pop 1 38 jump -30 (to 8) @@ -1987,21 +1987,21 @@ function testing.parse_filter_patterns(raw: string[]) -> testing.FilterPat[] { 477 41 load_var 6 (s) 42 load_const 7 (0) 43 load_var 8 (idx) - 44 call 163 ntypeargs=0 (baml.String.substring) + 44 call 153 ntypeargs=0 (baml.String.substring) 45 store_var 9 (_13) 46 load_var 6 (s) - 47 call 160 ntypeargs=0 (baml.String.length) + 47 call 139 ntypeargs=0 (baml.String.length) 48 store_var 11 (_18) 49 load_var2 6 8 50 load_const 10 (2) 51 add_int 52 load_var 11 (_18) - 53 call 163 ntypeargs=0 (baml.String.substring) + 53 call 153 ntypeargs=0 (baml.String.substring) 54 store_var 10 (_15) 55 load_var2 3 9 56 load_var 10 (_15) 57 init_instance 2 (testing.FilterPat .func_pat, .test_pat) - 58 call 9 ntypeargs=0 (baml.Array.push) + 58 call 4 ntypeargs=0 (baml.Array.push) 59 pop 1 60 jump -52 (to 8) @@ -2041,29 +2041,29 @@ function testing.run_children_parallel(children: testing.TestSetChild[]) -> test 24 store_deref 5 370 25 load_var 5 (child) - 26 make_closure 1332 1 + 26 make_closure 1326 1 27 load_const 6 (null) 28 load_const 6 (null) 29 spawn 30 store_var 6 (_11) 31 load_var2 2 6 - 32 call 9 ntypeargs=0 (baml.Array.push) + 32 call 4 ntypeargs=0 (baml.Array.push) 33 pop 1 34 jump -23 (to 11) 374 35 load_type 7 36 load_type 8 37 load_var 2 (futures) - 38 call 505 ntypeargs=2 (baml.future.all_complete) + 38 call 508 ntypeargs=2 (baml.future.all_complete) 39 await 40 jump +5 (to 45) 41 load_var 7 (e) 42 throw_if_panic 375 43 load_const 9 ("unexpected test child failure") - 44 call 244 ntypeargs=0 (baml.sys.panic) + 44 call 246 ntypeargs=0 (baml.sys.panic) - 377 45 call 729 ntypeargs=0 (testing.aggregate_reports) + 377 45 call 745 ntypeargs=0 (testing.aggregate_reports) 46 return } @@ -2097,7 +2097,7 @@ function testing.run_children_sequential(children: testing.TestSetChild[], fail_ 23 load_field 0 (name) 24 load_var 7 (report) 25 init_instance 0 (testing.NamedChildReport .name, .report) - 26 call 9 ntypeargs=0 (baml.Array.push) + 26 call 4 ntypeargs=0 (baml.Array.push) 27 pop 1 111 28 load_var 7 (report) @@ -2124,16 +2124,16 @@ function testing.run_children_sequential(children: testing.TestSetChild[], fail_ 45 pop 1 46 load_var 8 (outcome) 47 load_const 7 ("pass") - 48 call 651 ntypeargs=0 (baml.ops.equals_equals) + 48 call 638 ntypeargs=0 (baml.ops.equals_equals) 49 unary_op ! 50 pop_jump_if_false -42 (to 8) 116 51 load_var 3 (named_results) - 52 call 729 ntypeargs=0 (testing.aggregate_reports) + 52 call 745 ntypeargs=0 (testing.aggregate_reports) 53 jump +3 (to 56) 121 54 load_var 3 (named_results) - 55 call 729 ntypeargs=0 (testing.aggregate_reports) + 55 call 745 ntypeargs=0 (testing.aggregate_reports) 56 return } @@ -2143,7 +2143,7 @@ function testing.run_test(body: () -> void throws unknown, runner: ((() -> testi 2 store_var 1 382 3 load_var 1 (body) - 4 make_closure 1380 1 + 4 make_closure 1336 1 5 store_var 3 (base_run) 406 6 load_var 2 (runner) @@ -2179,17 +2179,17 @@ function testing.run_testset(children: testing.TestSetChild[], runner: ((testing 9 jump +3 (to 12) 418 10 load_var 1 (children) - 11 call 742 ntypeargs=0 (testing.run_children_parallel) + 11 call 746 ntypeargs=0 (testing.run_children_parallel) 12 return } function testing.select_names(registry: testing.TestRegistry, include: string[], exclude: string[]) -> string[] { 549 0 load_var 2 (include) - 1 call 730 ntypeargs=0 (testing.parse_filter_patterns) + 1 call 751 ntypeargs=0 (testing.parse_filter_patterns) 2 store_var 5 (inc) 550 3 load_var 3 (exclude) - 4 call 730 ntypeargs=0 (testing.parse_filter_patterns) + 4 call 751 ntypeargs=0 (testing.parse_filter_patterns) 5 store_var 6 (exc) 551 6 load_type 0 @@ -2197,7 +2197,7 @@ function testing.select_names(registry: testing.TestRegistry, include: string[], 8 store_var 7 (out) 552 9 load_var 1 (registry) - 10 call 733 ntypeargs=0 (testing.collect_leaf_names) + 10 call 757 ntypeargs=0 (testing.collect_leaf_names) 11 load_type 1 12 load_const 2 ("iter") 13 virtual_call nargs=1 ntypeargs=0 @@ -2215,11 +2215,11 @@ function testing.select_names(registry: testing.TestRegistry, include: string[], 25 store_var_load_var 10 (name) 553 26 load_var2 5 6 - 27 call 758 ntypeargs=0 (testing.leaf_selected) + 27 call 755 ntypeargs=0 (testing.leaf_selected) 28 pop_jump_if_false -13 (to 15) 554 29 load_var2 7 10 - 30 call 9 ntypeargs=0 (baml.Array.push) + 30 call 4 ntypeargs=0 (baml.Array.push) 31 pop 1 32 jump -17 (to 15) @@ -2232,7 +2232,7 @@ function testing.select_names(registry: testing.TestRegistry, include: string[], function testing.split_top(path: string) -> testing.NameSplit { 463 0 load_var 1 (path) 1 load_const 0 ("/") - 2 call 173 ntypeargs=0 (baml.String.index_of) + 2 call 155 ntypeargs=0 (baml.String.index_of) 3 store_var 2 (_2) 4 load_var 2 (_2) 5 is_type 1 @@ -2250,15 +2250,15 @@ function testing.split_top(path: string) -> testing.NameSplit { 464 14 load_var 1 (path) 15 load_const 1 (0) 16 load_var 3 (idx) - 17 call 163 ntypeargs=0 (baml.String.substring) + 17 call 153 ntypeargs=0 (baml.String.substring) 18 load_var 1 (path) - 19 call 160 ntypeargs=0 (baml.String.length) + 19 call 139 ntypeargs=0 (baml.String.length) 20 store_var 4 (_10) 21 load_var2 1 3 22 load_const 3 (1) 23 add_int 24 load_var 4 (_10) - 25 call 163 ntypeargs=0 (baml.String.substring) + 25 call 153 ntypeargs=0 (baml.String.substring) 26 init_instance 1 (testing.NameSplit .head, .tail) 27 return } @@ -2274,7 +2274,7 @@ function testing.test_child(name: string, body: () -> void throws unknown, runne 268 6 load_var2 1 2 270 7 load_var 3 (runner) - 8 make_closure 1351 2 + 8 make_closure 1303 2 9 init_instance 0 (testing.TestSetChild .name, .run) 10 store_var 4 (_0) 11 load_var 4 (_0) @@ -2293,7 +2293,7 @@ function testing.testset_child(registry: testing.TestRegistry, ts: testing.TestS 7 load_field 0 (name) 277 8 load_var2 1 2 - 9 make_closure 1369 2 + 9 make_closure 1305 2 10 init_instance 0 (testing.TestSetChild .name, .run) 11 store_var 3 (_0) 12 load_var 3 (_0) @@ -2316,7 +2316,7 @@ function testing.testset_child_selected(registry: testing.TestRegistry, ts: test 289 11 load_var2 1 2 12 load_var 3 (names) - 13 make_closure 1384 3 + 13 make_closure 1307 3 14 init_instance 0 (testing.TestSetChild .name, .run) 15 store_var 4 (_0) 16 load_var 4 (_0) @@ -2352,10 +2352,10 @@ function testing.testset_children(registry: testing.TestRegistry) -> testing.Tes 23 load_field 1 (body) 24 load_var 6 (t) 25 load_field 2 (runner) - 26 call 748 ntypeargs=0 (testing.test_child) + 26 call 740 ntypeargs=0 (testing.test_child) 27 store_var 7 (_10) 28 load_var2 3 7 - 29 call 9 ntypeargs=0 (baml.Array.push) + 29 call 4 ntypeargs=0 (baml.Array.push) 30 pop 1 31 jump -21 (to 10) @@ -2379,10 +2379,10 @@ function testing.testset_children(registry: testing.TestRegistry) -> testing.Tes 49 store_var 10 (ts) 238 50 load_var2 1 10 - 51 call 756 ntypeargs=0 (testing.testset_child) + 51 call 741 ntypeargs=0 (testing.testset_child) 52 store_var 11 (_21) 53 load_var2 3 11 - 54 call 9 ntypeargs=0 (baml.Array.push) + 54 call 4 ntypeargs=0 (baml.Array.push) 55 pop 1 56 jump -17 (to 39) @@ -2418,7 +2418,7 @@ function testing.testset_children_selected(registry: testing.TestRegistry, names 246 21 load_field 0 (name) 22 load_var 2 (names) - 23 call 752 ntypeargs=0 (testing._name_selected) + 23 call 743 ntypeargs=0 (testing._name_selected) 24 pop_jump_if_false -14 (to 10) 247 25 load_var 7 (t) @@ -2427,10 +2427,10 @@ function testing.testset_children_selected(registry: testing.TestRegistry, names 28 load_field 1 (body) 29 load_var 7 (t) 30 load_field 2 (runner) - 31 call 748 ntypeargs=0 (testing.test_child) + 31 call 740 ntypeargs=0 (testing.test_child) 32 store_var 8 (_13) 33 load_var2 4 8 - 34 call 9 ntypeargs=0 (baml.Array.push) + 34 call 4 ntypeargs=0 (baml.Array.push) 35 pop 1 36 jump -26 (to 10) @@ -2455,15 +2455,15 @@ function testing.testset_children_selected(registry: testing.TestRegistry, names 258 55 load_field 0 (name) 56 load_var 2 (names) - 57 call 734 ntypeargs=0 (testing._has_selected_descendant) + 57 call 744 ntypeargs=0 (testing._has_selected_descendant) 58 pop_jump_if_false -14 (to 44) 259 59 load_var2 1 11 60 load_var 2 (names) - 61 call 761 ntypeargs=0 (testing.testset_child_selected) + 61 call 742 ntypeargs=0 (testing.testset_child_selected) 62 store_var 12 (_26) 63 load_var2 4 12 - 64 call 9 ntypeargs=0 (baml.Array.push) + 64 call 4 ntypeargs=0 (baml.Array.push) 65 pop 1 66 jump -22 (to 44) @@ -2482,7 +2482,7 @@ function user.User.promote(self: User, bonus: int) -> Report { 5 store_field 1 (age) 10 6 load_var2 1 2 - 7 call 775 ntypeargs=0 (user.score) + 7 call 776 ntypeargs=0 (user.score) 8 store_var 4 (base) 11 9 load_var 4 (base) From 8f6857730a9d640a84cc289e9c443346d0a4c4fa Mon Sep 17 00:00:00 2001 From: 2kai2kai2 Date: Tue, 21 Jul 2026 17:08:53 -0700 Subject: [PATCH 09/10] Hide `ItemTree` --- baml_language/ARCHITECTURE.md | 4 +- .../crates/baml_compiler2_hir/src/lib.rs | 18 +++----- .../baml_compiler2_hir/src/semantic_index.rs | 7 +++ .../crates/baml_compiler2_ppir/src/lib.rs | 13 +++++- baml_language/crates/baml_project/src/db.rs | 44 ++++++++----------- 5 files changed, 45 insertions(+), 41 deletions(-) diff --git a/baml_language/ARCHITECTURE.md b/baml_language/ARCHITECTURE.md index 49795644960..73d922bebbd 100644 --- a/baml_language/ARCHITECTURE.md +++ b/baml_language/ARCHITECTURE.md @@ -202,7 +202,7 @@ The parser produces a **CST** (Concrete Syntax Tree), which is a lossless, error - SAP (streaming attribute propagation) attributes - **The canonical item layer** — `ppir::file_item_tree` merges original items with the synthetic stream items, and the per-item **firewall queries** (`item_data`: enumeration + `*_data` + `*_source_map`) that front the item tree live here. -**How it works:** The PPIR generates synthetic AST items (the stream variants) and re-runs the HIR builder over the *merged* list — originals first, then synthetics appended. The flow is HIR → PPIR → (re-run the HIR builder on merged items) → TIR. PPIR's tree is **canonical**, but it is an internal substrate: downstream layers read it **only through the firewall queries** in `item_data` (enumeration + `*_data` + `*_source_map`) — never `file_item_tree` directly, and never the HIR pre-expansion tree. A `ClassLoc`/`FunctionLoc` therefore unambiguously means a canonical item. (Originals keep identical `LocalItemId`s in the pre-expansion and canonical trees because they are allocated first, in the same order — which is what makes a HIR-derived `*Loc` safe to pass to a firewall query. Migrating the remaining direct `file_item_tree` readers onto the firewall queries is in progress.) +**How it works:** The PPIR generates synthetic AST items (the stream variants) and re-runs the HIR builder over the *merged* list — originals first, then synthetics appended. The flow is HIR → PPIR → (re-run the HIR builder on merged items) → TIR. PPIR's tree is **canonical**, but it is an internal substrate: downstream layers read it **only through the firewall queries** in `item_data` (enumeration + `*_data` + `*_source_map`) — never `file_item_tree` directly, and never the HIR pre-expansion tree. A `ClassLoc`/`FunctionLoc` therefore unambiguously means a canonical item. (Originals keep identical `LocalItemId`s in the pre-expansion and canonical trees because they are allocated first, in the same order — which is what makes a HIR-derived `*Loc` safe to pass to a firewall query. This is enforced: `file_item_tree` is `pub(crate)` in both HIR and PPIR, so no downstream crate can reach the raw tree at all.) **Key Salsa queries:** - `ppir_expansion_items(db, file)` — Synthetic stream items per file @@ -745,7 +745,7 @@ User adds `// comment` to `file_a.baml`. File B is untouched. 4. `namespace_items(user_root)` re-runs and early-cuts when the name set is unchanged. (Exception: a file already holding a *duplicate-name* conflict currently carries a `name_span` in the conflict record, so a cosmetic edit there loses cutoff — a known gap being closed.) 5. `file_semantic_index(file_b)` — NOT re-run (its input `file_b.text` is unchanged), so nothing about file B recomputes. -**Status / caveat.** The firewall queries above exist and cut off, but many downstream consumers are **not yet migrated onto them** — notably `infer_scope_types`, which still reads the coarse `no_eq` `file_semantic_index` directly and therefore re-runs on *any* edit to its file today. Realizing end-to-end cutoff (a comment edit not re-running type inference) requires migrating those consumers to the firewall queries; that work is in progress. Treat this section as the mechanism, not a fully-realized guarantee — the incremental tests in `baml_tests` pin what actually holds today, and one of them (`comment_edit_does_not_reexecute_type_inference`) is deliberately `#[ignore]`d precisely because inference is not yet migrated. +**Status / caveat.** The **item layer** is fully behind the firewall: every consumer (TIR, MIR, emit, LSP, project, CLI, tests) reads items through the `item_data` queries, and the raw doors (`file_item_tree` in both HIR and PPIR) are `pub(crate)`. The remaining red edge is the **scope tree**: `infer_scope_types` (and the LSP scope walkers) still read the coarse `no_eq` `file_semantic_index` directly for scopes/bindings, and therefore re-run on *any* edit to their file today. Realizing end-to-end cutoff (a comment edit not re-running type inference) requires fronting the scope tree with the same kind of fine-grained queries (`scope_owner`/`function_scope` exist; the per-scope data queries do not yet). The incremental tests in `baml_tests` pin what actually holds today, and one of them (`comment_edit_does_not_reexecute_type_inference`) is deliberately `#[ignore]`d precisely because inference still reads the coarse index. --- diff --git a/baml_language/crates/baml_compiler2_hir/src/lib.rs b/baml_language/crates/baml_compiler2_hir/src/lib.rs index 67148709370..4a7f33f2935 100644 --- a/baml_language/crates/baml_compiler2_hir/src/lib.rs +++ b/baml_language/crates/baml_compiler2_hir/src/lib.rs @@ -35,7 +35,7 @@ pub use semantic_index::PathResolution; use crate::{ contributions::FileSymbolContributions, - item_tree::{ItemTree, ItemTreeSourceMap}, + item_tree::ItemTree, semantic_index::{FileSemanticIndex, ScopeBindings}, }; @@ -194,18 +194,14 @@ pub fn file_symbol_contributions( /// Returns the item tree for a file (clones the Arc — O(1)). /// /// Not tracked — the item tree is cached via `file_semantic_index`. -/// This helper is for convenience in downstream queries. -pub fn file_item_tree(db: &dyn Db, file: SourceFile) -> Arc { - let index = file_semantic_index(db, file); - Arc::clone(&index.item_tree) -} - -/// Returns the item tree source map for a file (clones the Arc — O(1)). /// -/// Not tracked — the source map is cached via `file_semantic_index`. -pub fn file_item_tree_source_map(db: &dyn Db, file: SourceFile) -> Arc { +/// `pub(crate)`: the raw `ItemTree` is an implementation detail behind the +/// PPIR item-data firewall (`baml_compiler2_ppir::item_data`). Consumers use +/// the enumeration (`file_classes`/`file_functions`/…) and lookup +/// (`class_data`/`function_data`/…) queries there, never the tree itself. +pub(crate) fn file_item_tree(db: &dyn Db, file: SourceFile) -> Arc { let index = file_semantic_index(db, file); - Arc::clone(&index.item_tree_source_map) + Arc::clone(&index.item_tree) } /// Returns the `ScopeBindings` for a given scope. diff --git a/baml_language/crates/baml_compiler2_hir/src/semantic_index.rs b/baml_language/crates/baml_compiler2_hir/src/semantic_index.rs index a69beffb431..ed1cb9a9786 100644 --- a/baml_language/crates/baml_compiler2_hir/src/semantic_index.rs +++ b/baml_language/crates/baml_compiler2_hir/src/semantic_index.rs @@ -232,6 +232,13 @@ pub struct FileSemanticIndex<'db> { pub item_scopes: FxHashMap, /// Per-file item tree — maps `LocalItemId` to item data. + /// + /// Reachable only inside HIR and PPIR: the `file_item_tree` doors in both + /// crates are `pub(crate)`, and everything downstream uses the PPIR + /// `item_data` firewall queries instead. This field stays `pub` solely + /// because PPIR (a separate crate) builds and reads the index; do not read + /// it from any other crate. (Collapsing HIR+PPIR onto one index would let + /// this become `pub(crate)` — see the plan's Fork B follow-up.) pub item_tree: Arc, /// Source map for item tree — field/variant name spans. diff --git a/baml_language/crates/baml_compiler2_ppir/src/lib.rs b/baml_language/crates/baml_compiler2_ppir/src/lib.rs index 89809e256f6..b8577ae8ded 100644 --- a/baml_language/crates/baml_compiler2_ppir/src/lib.rs +++ b/baml_language/crates/baml_compiler2_ppir/src/lib.rs @@ -623,13 +623,22 @@ pub fn file_symbol_contributions( } /// Canonical item tree (original + *$stream types). -pub fn file_item_tree(db: &dyn Db, file: SourceFile) -> Arc { +/// +/// `pub(crate)`: the raw `ItemTree` is the substrate the `item_data` firewall +/// queries are built on. Consumers use the enumeration +/// (`file_classes`/`file_functions`/…) and lookup (`class_data`/ +/// `function_data`/…) queries, never the tree itself — that is what gives +/// per-item invalidation instead of per-file. +pub(crate) fn file_item_tree(db: &dyn Db, file: SourceFile) -> Arc { let index = file_semantic_index(db, file); Arc::clone(&index.item_tree) } /// Canonical item-tree source map (original + *$stream types). -pub fn file_item_tree_source_map(db: &dyn Db, file: SourceFile) -> Arc { +/// +/// `pub(crate)`: spans are served by the per-item `*_source_map` firewall +/// queries in `item_data`. +pub(crate) fn file_item_tree_source_map(db: &dyn Db, file: SourceFile) -> Arc { let index = file_semantic_index(db, file); Arc::clone(&index.item_tree_source_map) } diff --git a/baml_language/crates/baml_project/src/db.rs b/baml_language/crates/baml_project/src/db.rs index 511d78f3e1e..b410e49b5a9 100644 --- a/baml_language/crates/baml_project/src/db.rs +++ b/baml_language/crates/baml_project/src/db.rs @@ -670,8 +670,8 @@ impl ProjectDatabase { let mut result = None; for source_file in self.file_map.values().copied() { - let index = baml_compiler2_ppir::file_semantic_index(self, source_file); - for (local_id, func_data) in &index.item_tree.functions { + for &func_loc in baml_compiler2_ppir::item_data::file_functions(self, source_file) { + let func_data = baml_compiler2_ppir::item_data::function_data(self, func_loc); if !self.function_name_matches_source_name( source_file, &func_data.name, @@ -680,8 +680,6 @@ impl ProjectDatabase { continue; } - let func_loc = - baml_compiler2_hir::loc::FunctionLoc::new(self, source_file, *local_id); let func_span = baml_compiler2_ppir::item_data::function_source_map(self, func_loc).span; let body = baml_compiler2_ppir::function_body(self, func_loc); @@ -844,8 +842,8 @@ impl ProjectDatabase { fn function_header_title(&self, function_name: &str) -> Option { let mut unique_title = None; for source_file in self.file_map.values().copied() { - let index = baml_compiler2_ppir::file_semantic_index(self, source_file); - for (local_id, func_data) in &index.item_tree.functions { + for &func_loc in baml_compiler2_ppir::item_data::file_functions(self, source_file) { + let func_data = baml_compiler2_ppir::item_data::function_data(self, func_loc); if !self.function_name_matches_source_name( source_file, &func_data.name, @@ -853,8 +851,6 @@ impl ProjectDatabase { ) { continue; } - let func_loc = - baml_compiler2_hir::loc::FunctionLoc::new(self, source_file, *local_id); let func_span = baml_compiler2_ppir::item_data::function_source_map(self, func_loc).span; let text = source_file.text(self); @@ -1298,17 +1294,16 @@ impl ProjectDatabase { // A declarative LLM function and its `$stream`/`$parse_stream` companions // share one declaration span, hence one scope range — so multiple // functions match here. Prefer the user-authored one (origin order). - let (local_id, _) = index - .item_tree - .functions + let func_loc = baml_compiler2_ppir::item_data::file_functions(self, source_file) .iter() - .filter(|(id, _)| { - let loc = baml_compiler2_hir::loc::FunctionLoc::new(self, source_file, **id); + .copied() + .filter(|&loc| { baml_compiler2_ppir::item_data::function_source_map(self, loc).span == func_scope_range }) - .min_by_key(|(_, func_data)| func_origin_rank(func_data.origin))?; - let func_loc = baml_compiler2_hir::loc::FunctionLoc::new(self, source_file, *local_id); + .min_by_key(|&loc| { + func_origin_rank(baml_compiler2_ppir::item_data::function_data(self, loc).origin) + })?; let sig = baml_compiler2_ppir::function_signature(self, func_loc); let body = baml_compiler2_ppir::function_body(self, func_loc); let is_workflow = matches!( @@ -1326,8 +1321,8 @@ impl ProjectDatabase { let mut memberships = Vec::new(); for source_file in self.file_map.values().copied() { - let index = baml_compiler2_ppir::file_semantic_index(self, source_file); - for (local_id, func_data) in &index.item_tree.functions { + for &func_loc in baml_compiler2_ppir::item_data::file_functions(self, source_file) { + let func_data = baml_compiler2_ppir::item_data::function_data(self, func_loc); let func_name = self.playground_function_name_for_source_file(source_file, &func_data.name); if func_data.name.as_str() == target_function_name @@ -1336,8 +1331,6 @@ impl ProjectDatabase { continue; // Skip self } - let func_loc = - baml_compiler2_hir::loc::FunctionLoc::new(self, source_file, *local_id); let body = baml_compiler2_ppir::function_body(self, func_loc); // Only workflow (Expr) functions can call other functions @@ -1417,18 +1410,17 @@ impl ProjectDatabase { }; let func_scope_range = index.scopes[func_scope_id.index() as usize].range; - if let Some((local_id, _)) = index - .item_tree - .functions + if let Some(func_loc) = baml_compiler2_ppir::item_data::file_functions(self, source_file) .iter() - .filter(|(id, _)| { - let loc = baml_compiler2_hir::loc::FunctionLoc::new(self, source_file, **id); + .copied() + .filter(|&loc| { baml_compiler2_ppir::item_data::function_source_map(self, loc).span == func_scope_range }) - .min_by_key(|(_, func_data)| func_origin_rank(func_data.origin)) + .min_by_key(|&loc| { + func_origin_rank(baml_compiler2_ppir::item_data::function_data(self, loc).origin) + }) { - let func_loc = baml_compiler2_hir::loc::FunctionLoc::new(self, source_file, *local_id); let Some(source_map) = baml_compiler2_ppir::function_body_source_map(self, func_loc) else { return (None, vec![]); From 63c6339453c191f146d507ed0528fe1d758e3653 Mon Sep 17 00:00:00 2001 From: 2kai2kai2 Date: Wed, 22 Jul 2026 14:26:48 -0700 Subject: [PATCH 10/10] Coderabbit fix --- .../baml_lsp2_actions/src/completions.rs | 16 ++-------- .../baml_lsp2_actions/src/definition.rs | 4 +-- .../crates/baml_lsp2_actions/src/type_info.rs | 7 +---- .../crates/baml_lsp2_actions/src/utils.rs | 31 +++++++++++++++++++ 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/baml_language/crates/baml_lsp2_actions/src/completions.rs b/baml_language/crates/baml_lsp2_actions/src/completions.rs index 6c9ffd6b5c6..c2cad539737 100644 --- a/baml_language/crates/baml_lsp2_actions/src/completions.rs +++ b/baml_language/crates/baml_lsp2_actions/src/completions.rs @@ -1270,13 +1270,8 @@ fn local_variable_ty( ScopeKind::Function => { // Function parameter — look up from function signature. let func_scope_range = enclosing_scope_data.range; - let func_loc = baml_compiler2_ppir::item_data::file_functions(db, file) - .iter() - .copied() - .find(|&loc| { - baml_compiler2_ppir::item_data::function_source_map(db, loc).span - == func_scope_range - })?; + let func_loc = + crate::utils::function_at_scope_range(db, file, func_scope_range)?; let sig = baml_compiler2_hir::signature::function_signature(db, func_loc); sig.params.get(param_idx).map(|param| { let pkg_info = baml_compiler2_hir::file_package::file_package(db, file); @@ -1366,12 +1361,7 @@ fn find_binding_ty_for_local( // 2. Start from the outermost Function scope → find its body. let func_range = func_range?; - let func_loc = baml_compiler2_ppir::item_data::file_functions(db, file) - .iter() - .copied() - .find(|&loc| { - baml_compiler2_ppir::item_data::function_source_map(db, loc).span == func_range - })?; + let func_loc = crate::utils::function_at_scope_range(db, file, func_range)?; let body = baml_compiler2_hir::body::function_body(db, func_loc); let baml_compiler2_hir::body::FunctionBody::Expr(ref top_body) = *body else { return None; diff --git a/baml_language/crates/baml_lsp2_actions/src/definition.rs b/baml_language/crates/baml_lsp2_actions/src/definition.rs index 3b1fae7c349..db465f4d104 100644 --- a/baml_language/crates/baml_lsp2_actions/src/definition.rs +++ b/baml_language/crates/baml_lsp2_actions/src/definition.rs @@ -129,9 +129,7 @@ fn local_definition_location( let func_scope_range = index.scopes[enclosing_func_scope.index() as usize].range; // Find the function by matching the scope range against its declaration span. - let func_loc = *item_data::file_functions(db, file) - .iter() - .find(|func_loc| item_data::function_source_map(db, **func_loc).span == func_scope_range)?; + let func_loc = crate::utils::function_at_scope_range(db, file, func_scope_range)?; match site { DefinitionSite::Statement(stmt_id) => { diff --git a/baml_language/crates/baml_lsp2_actions/src/type_info.rs b/baml_language/crates/baml_lsp2_actions/src/type_info.rs index 66e7a0c2a26..d3d2132501c 100644 --- a/baml_language/crates/baml_lsp2_actions/src/type_info.rs +++ b/baml_language/crates/baml_lsp2_actions/src/type_info.rs @@ -640,12 +640,7 @@ fn local_type_info( let func_scope_range = index.scopes[enclosing_func_scope.index() as usize].range; // Match scope range to a function via the firewall enumeration. - let func_loc = baml_compiler2_ppir::item_data::file_functions(db, file) - .iter() - .copied() - .find(|&loc| { - baml_compiler2_ppir::item_data::function_source_map(db, loc).span == func_scope_range - })?; + let func_loc = crate::utils::function_at_scope_range(db, file, func_scope_range)?; match site { DefinitionSite::Parameter(param_idx) => { diff --git a/baml_language/crates/baml_lsp2_actions/src/utils.rs b/baml_language/crates/baml_lsp2_actions/src/utils.rs index a298424a2ce..cef99af8022 100644 --- a/baml_language/crates/baml_lsp2_actions/src/utils.rs +++ b/baml_language/crates/baml_lsp2_actions/src/utils.rs @@ -516,3 +516,34 @@ pub fn display_type_ref( }; humanize_type_string(&rendered) } + +// ── function_at_scope_range ─────────────────────────────────────────────────── + +/// Resolve the function whose declaration span equals `range`, preferring the +/// user-authored declaration. +/// +/// Span equality alone is ambiguous: an LLM function's synthesized companions +/// (`{parent}$parse`, `{parent}$stream`, …) share their parent's declaration +/// span, so every companion matches too. Picking by origin makes the +/// user-authored preference explicit instead of leaning on the enumeration's +/// name tiebreak (a companion's `{parent}$…` name happens to sort after its +/// parent's, but that is a naming convention, not a contract). +pub(crate) fn function_at_scope_range( + db: &dyn crate::Db, + file: SourceFile, + range: TextRange, +) -> Option> { + use baml_compiler2_ast::ast::FunctionOrigin; + baml_compiler2_ppir::item_data::file_functions(db, file) + .iter() + .copied() + .filter(|&loc| baml_compiler2_ppir::item_data::function_source_map(db, loc).span == range) + .min_by_key( + |&loc| match baml_compiler2_ppir::item_data::function_data(db, loc).origin { + FunctionOrigin::UserDefined => 0u8, + FunctionOrigin::Companion => 1, + FunctionOrigin::Internal => 2, + FunctionOrigin::AutoDerive => 3, + }, + ) +}