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

Include type aliases in Jinja #1286

Merged
merged 5 commits into from
Jan 1, 2025

Conversation

antoniosarosi
Copy link
Contributor

@antoniosarosi antoniosarosi commented Jan 1, 2025

is_subtype_of now works with type aliases and this also allows better error reporting:

type ProjectId = int

function NormalAlias(pid: ProjectId) -> string {
  client "openai/gpt-4o"
  prompt #"Pid: {{ pid.id }}. Generate a fake name for it."#
}

Error:

// warning: 'pid' is a type alias ProjectId (resolves to int), expected class
//   -->  class/type_aliases_jinja.baml:5
//    | 
//  4 |   client "openai/gpt-4o"
//  5 |   prompt #"Pid: {{ pid.id }}. Generate a fake name for it."#
//    | 

Important

Add support for type aliases in Jinja templates, enhancing type checking and error reporting.

  • Behavior:
    • is_subtype_of now supports type aliases, improving error reporting in Jinja templates.
    • Type aliases are validated for cycles, with errors reported for infinite cycles.
  • Validation:
    • validate() in cycle.rs checks for non-structural type alias cycles and reports them.
    • validate() in template_strings.rs includes type aliases in defined types for Jinja validation.
  • Type System:
    • Adds Alias and RecursiveTypeAlias variants to Type enum in types.rs.
    • Updates is_subtype_of() to handle alias resolution.
  • Parser Database:
    • resolve_type_aliases() in types/mod.rs resolves type aliases before cycle validation.
    • recursive_alias_cycles replaces structural_recursive_alias_cycles in repr.rs and mod.rs.
  • Testing:
    • Adds type_aliases_jinja.baml to test type alias handling in Jinja templates.
    • Updates existing tests to cover new type alias functionality.

This description was created by Ellipsis for da038bd. It will automatically update as commits are pushed.

Copy link

vercel bot commented Jan 1, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
baml ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 1, 2025 6:26pm

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Reviewed everything up to 32c0a3a in 1 minute and 0 seconds

More details
  • Looked at 591 lines of code in 10 files
  • Skipped 0 files when reviewing.
  • Skipped posting 5 drafted comments based on config settings.
1. engine/baml-lib/baml-core/src/validate/validation_pipeline/validations/cycle.rs:20
  • Draft comment:
    The variable non_structural_type_aliases is correctly named to reflect its purpose of holding non-structural cycles. This aligns with the PR's intent to handle type alias cycles more effectively.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The function validate in cycle.rs is responsible for checking type alias cycles. The comment on line 17 mentions that cycles are allowed only for maps and lists, which is consistent with the changes in the PR. The variable non_structural_type_aliases is correctly renamed to reflect its purpose of holding non-structural cycles. The function report_infinite_cycles is used to report these cycles, which aligns with the PR's intent to handle type alias cycles more effectively.
2. engine/baml-lib/baml-core/src/validate/validation_pipeline/validations/template_strings.rs:21
  • Draft comment:
    Including walk_type_aliases to add type aliases to defined_types ensures that type aliases are considered during template string validation, aligning with the PR's intent.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The function validate in template_strings.rs is responsible for validating template strings. The addition of walk_type_aliases to include type aliases in the validation process aligns with the PR's intent to handle type aliases more effectively. This change ensures that type aliases are considered when validating template strings, which is consistent with the PR description.
3. engine/baml-lib/jinja/src/evaluate_type/types.rs:43
  • Draft comment:
    The Type enum now includes Alias and RecursiveTypeAlias, and the is_subtype_of method has been updated to handle these, aligning with the PR's intent to handle type aliases more effectively.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The Type enum in types.rs has been extended to include Alias and RecursiveTypeAlias, which aligns with the PR's intent to handle type aliases more effectively. The is_subtype_of method has been updated to handle these new variants, ensuring that type alias resolution is considered during type checking. This change is consistent with the PR description and improves the handling of type aliases.
4. engine/baml-lib/parser-database/src/types/mod.rs:82
  • Draft comment:
    The resolve_type_aliases function now computes recursive_alias_cycles using Tarjan's algorithm, ensuring type alias cycles are detected and resolved appropriately, aligning with the PR's intent.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The resolve_type_aliases function in mod.rs is responsible for resolving type aliases. The function now computes recursive_alias_cycles using Tarjan's algorithm, which aligns with the PR's intent to handle type alias cycles more effectively. This change ensures that type alias cycles are detected and resolved appropriately, consistent with the PR description.
5. engine/baml-lib/parser-database/src/walkers/mod.rs:295
  • Draft comment:
    The to_jinja_type function now correctly handles TypeAlias by including Alias and RecursiveTypeAlias, ensuring type aliases are represented in Jinja types, aligning with the PR's intent.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The to_jinja_type function in mod.rs converts FieldType to Type. The handling of TypeAlias has been updated to include Alias and RecursiveTypeAlias, which aligns with the PR's intent to handle type aliases more effectively. This change ensures that type aliases are correctly represented in Jinja types, consistent with the PR description.

Workflow ID: wflow_OajdfxE0FVbE1HRl


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Incremental review on 0b4ea0b in 45 seconds

More details
  • Looked at 69 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. engine/baml-lib/parser-database/src/walkers/mod.rs:152
  • Draft comment:
    The function is_recursive_type_alias is defined twice, once here and once in parser-database/src/lib.rs. Consider defining it once and reusing it to avoid redundancy.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    Without seeing lib.rs, I cannot verify if this function is actually duplicated. The comment could be correct, but it requires knowledge of another file to validate. Following our rules, if understanding requires more context from other files, we should delete the comment.
    The function duplication could be a real issue that would benefit from being fixed. By removing this comment, we might miss an opportunity to improve code organization.
    While the duplication might be real, we cannot verify it without seeing lib.rs. It's better to err on the side of caution than to keep a potentially incorrect comment.
    Remove the comment since we cannot verify the claimed duplication without seeing the other file, and our rules state that cross-file issues should be ignored.

Workflow ID: wflow_4i3q7UuPRlYSggjP


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Incremental review on da038bd in 34 seconds

More details
  • Looked at 19 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. integ-tests/python/tests/test_functions.py:40
  • Draft comment:
    Unresolved merge conflict markers found. Please resolve the conflict in the import section.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.

Workflow ID: wflow_HmGZki3gk4FO64LE


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skipped PR review on 6c97885 because no changed files had a supported extension. If you think this was in error, please contact us and we'll fix it right away.

@antoniosarosi antoniosarosi added this pull request to the merge queue Jan 1, 2025
Merged via the queue into canary with commit 207eab8 Jan 1, 2025
10 of 11 checks passed
@antoniosarosi antoniosarosi deleted the antonio/type-aliases-in-jinja-exprs branch January 1, 2025 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant