From c0e9d084ff90d59564ea3d346a93c6c769ff7ef7 Mon Sep 17 00:00:00 2001 From: Antonio Sarosi Date: Wed, 27 Nov 2024 22:40:03 +0000 Subject: [PATCH] Resolve some TODOs --- engine/baml-lib/baml-types/src/field_type/mod.rs | 5 +---- engine/baml-lib/parser-database/src/types/mod.rs | 5 ++++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/engine/baml-lib/baml-types/src/field_type/mod.rs b/engine/baml-lib/baml-types/src/field_type/mod.rs index 479256fe9..eb153252b 100644 --- a/engine/baml-lib/baml-types/src/field_type/mod.rs +++ b/engine/baml-lib/baml-types/src/field_type/mod.rs @@ -245,10 +245,7 @@ impl FieldType { .zip(other_items) .all(|(self_item, other_item)| self_item.is_subtype_of(other_item)) } - // TODO: Can this cause infinite recursion? - // Should the final resolved type (following all the aliases) be - // included in the variant so that we skip recursion? - (FieldType::Alias { target, .. }, _) => target.is_subtype_of(other), + (FieldType::Alias { resolution, .. }, _) => resolution.is_subtype_of(other), (FieldType::Tuple(_), _) => false, (FieldType::Primitive(_), _) => false, (FieldType::Enum(_), _) => false, diff --git a/engine/baml-lib/parser-database/src/types/mod.rs b/engine/baml-lib/parser-database/src/types/mod.rs index f49c678d8..b7a2f348d 100644 --- a/engine/baml-lib/parser-database/src/types/mod.rs +++ b/engine/baml-lib/parser-database/src/types/mod.rs @@ -379,6 +379,9 @@ fn visit_class<'db>( /// /// The type would resolve to `SomeClass | AnotherClass | int`, which is not /// stored in the AST. +/// +/// **Important**: This function can only be called once infinite cycles have +/// been detected! Otherwise it'll stack overflow. pub fn resolve_type_alias(field_type: &FieldType, db: &ParserDatabase) -> FieldType { match field_type { // For symbols we need to check if we're dealing with aliases. @@ -400,7 +403,7 @@ pub fn resolve_type_alias(field_type: &FieldType, db: &ParserDatabase) -> FieldT return resolved.to_owned(); } - // Recurse... TODO: Recursive types and infinite cycles :( + // Recurse... let resolved = resolve_type_alias(&db.ast[*alias_id].value, db); // Sync arity. Basically stuff like: