Skip to content

Commit

Permalink
remove duplicate function
Browse files Browse the repository at this point in the history
  • Loading branch information
imalsogreg committed Oct 23, 2024
1 parent 7508237 commit 7f2b597
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use baml_types::{BamlMap, Constraint};
use baml_types::BamlMap;
use internal_baml_core::ir::FieldType;
use internal_baml_jinja::types::{Class, Name};

Expand All @@ -11,7 +11,7 @@ use crate::deserializer::{

use super::ParsingContext;

// Name, type, description, constraints.
// Name, type, description.
type FieldValue = (Name, FieldType, Option<String>);

impl TypeCoercer for Class {
Expand Down
33 changes: 1 addition & 32 deletions engine/baml-lib/jsonish/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,37 +106,6 @@ fn find_enum_value(
Ok(Some((name, desc)))
}

/// Eliminate the `FieldType::Constrained` variant by searching for it, and stripping
/// it off of its base type, returning a tulpe of the base type and any constraints found
/// (if called on an argument that is not Constrained, the returned constraints Vec is
/// empty).
///
/// If the function encounters directly nested Constrained types,
/// (i.e. `FieldType::Constrained { base: FieldType::Constrained { .. }, .. } `)
/// then the constraints of the two levels will be combined into a single vector.
/// So, we always return a base type that is not FieldType::Constrained.
fn distribute_constraints(field_type: &FieldType) -> (&FieldType, Vec<Constraint>) {

match field_type {
// Check the first level to see if it's constrained.
FieldType::Constrained { base, constraints } => {
match base.as_ref() {
// If so, we must check the second level to see if we need to combine
// constraints across levels.
// The recursion here means that arbitrarily nested `FieldType::Constrained`s
// will be collapsed before the function returns.
FieldType::Constrained{..} => {
let (sub_base, sub_constraints) = distribute_constraints(base);
let combined_constraints = vec![constraints.clone(), sub_constraints].into_iter().flatten().collect();
(sub_base, combined_constraints)
},
_ => (base, constraints.clone()),
}
},
_ => (field_type, Vec::new()),
}
}

// TODO: (Greg) Is the use of `String` as a hash key safe? Is there some way to
// get a collision that results in some type not getting put onto the stack?
fn relevant_data_models<'a>(
Expand All @@ -151,7 +120,7 @@ fn relevant_data_models<'a>(

while !start.is_empty() {
let output = start.pop().unwrap();
match distribute_constraints(&output) {
match output.distribute_constraints() {
(FieldType::Enum(enm), constraints) => {
if checked_types.insert(output.to_string()) {
let walker = ir.find_enum(enm);
Expand Down

0 comments on commit 7f2b597

Please sign in to comment.