Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename BAML class #1518

Merged
merged 2 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions engine/baml-lib/baml-core/src/ir/ir_helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ mod error_utils;
pub mod scope_diagnostics;
mod to_baml_arg;

use std::collections::HashSet;

use indexmap::IndexMap;
use internal_baml_diagnostics::Span;
use internal_baml_schema_ast::ast::{WithIdentifier, WithSpan};
use itertools::Itertools;

use self::scope_diagnostics::ScopeStack;
Expand All @@ -14,6 +18,7 @@ use crate::{
TypeAlias,
},
};

use anyhow::Result;
use baml_types::{
BamlMap, BamlValue, BamlValueWithMeta, Constraint, ConstraintLevel, FieldType, LiteralValue,
Expand Down Expand Up @@ -50,6 +55,9 @@ pub trait IRHelper {
function: &'a FunctionWalker<'a>,
test_name: &str,
) -> Result<TestCaseWalker<'a>>;

fn find_class_locations(&self, type_name: &str) -> Vec<Span>;

fn check_function_params<'a>(
&'a self,
function: &'a FunctionWalker<'a>,
Expand Down Expand Up @@ -233,6 +241,70 @@ impl IRHelper for IntermediateRepr {
}
}

fn find_class_locations(&self, class_name: &str) -> Vec<Span> {
let mut locations = vec![];

for cls in self.walk_classes() {
// First look for the definition of the class.
if cls.name() == class_name {
locations.push(
cls.item
.attributes
.identifier_span
.as_ref()
.unwrap()
.to_owned(),
);
}

// After that we'll find all the references to this class in the
// fields of other classes.
for field in cls.walk_fields() {
field
.elem()
.r#type
.attributes
.symbol_spans
.iter()
.for_each(|(name, spans)| {
if name == class_name {
locations.extend(spans.iter().cloned());
}
});
}
}

// Now do the same for type aliases.
for alias in self.walk_type_aliases() {
alias
.elem()
.r#type
.attributes
.symbol_spans
.iter()
.for_each(|(name, spans)| {
if name == class_name {
locations.extend(spans.iter().cloned());
}
});
}

// Then find function inputs and outputs pointing to this class.
for func in self.walk_functions() {
func.item
.attributes
.symbol_spans
.iter()
.for_each(|(name, spans)| {
if name == class_name {
locations.extend(spans.iter().cloned());
}
});
}

locations
}

fn check_function_params<'a>(
&'a self,
function: &'a FunctionWalker<'a>,
Expand Down
Loading
Loading