Skip to content

(feat) Type Inference Constraints #72

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

Merged
merged 29 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
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
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions optd-dsl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ariadne = "0.5.1"
async-trait = "0.1.88"
chumsky = "0.9.3"
clap = { version = "4.5.35", features = ["derive"] }
colored = "3.0.0"
enum_dispatch = "0.3.13"
futures = "0.3.31"
ordered-float = "5.0.0"
Expand Down
2 changes: 1 addition & 1 deletion optd-dsl/src/analyzer/context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{
error::AnalyzerErrorKind,
errors::AnalyzerErrorKind,
hir::{ExprMetadata, Identifier, NoMetadata, TypedSpan},
};
use crate::analyzer::hir::Value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::hir::Identifier;
use crate::utils::{
error::Diagnose,
errors::Diagnose,
span::{Span, Spanned},
};
use ariadne::{Color, Label, Report, ReportKind, Source};
Expand Down
20 changes: 16 additions & 4 deletions optd-dsl/src/analyzer/from_ast/converter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::analyzer::error::AnalyzerErrorKind;
use crate::analyzer::errors::AnalyzerErrorKind;
use crate::analyzer::hir::{Annotation, FunKind, Identifier, UdfKind};
use crate::analyzer::types::create_function_type;
use crate::analyzer::{
context::Context,
hir::{CoreData, HIR, TypedSpan, Value},
Expand All @@ -20,6 +21,8 @@ pub struct ASTConverter {
pub(super) context: Context<TypedSpan>,
/// Annotations for HIR expressions.
pub(super) annotations: HashMap<Identifier, Vec<Annotation>>,
/// Unique id counter for Unknown types.
unknown_id: usize,
}

impl ASTConverter {
Expand Down Expand Up @@ -66,10 +69,17 @@ impl ASTConverter {
))
}

/// Gets and increments the next unknown type.
pub(super) fn next_unknown(&mut self) -> Type {
let id = self.unknown_id;
self.unknown_id += 1;
Type::Unknown(id)
}

/// Registers a function AST node and adds it to the context.
///
/// Handles function parameters, return type, and body conversion.
pub(super) fn register_function(
pub fn register_function(
&mut self,
spanned_fn: &Spanned<Function>,
) -> Result<(), Box<AnalyzerErrorKind>> {
Expand All @@ -90,8 +100,10 @@ impl ASTConverter {
.collect();

let params = self.get_parameters(func, &generics)?;
let param_types = params.iter().map(|(_, ty)| ty.clone()).collect::<Vec<_>>();

let return_type = self.convert_type(&func.return_type, &generics)?;
let fn_type = Self::create_function_type(&params, &return_type);
let fn_type = create_function_type(&param_types, &return_type);

match &func.body {
Some(body_expr) => {
Expand Down Expand Up @@ -138,7 +150,7 @@ impl ASTConverter {
/// Collects parameter names and types from both the receiver (if present)
/// and the parameter list.
fn get_parameters(
&self,
&mut self,
func: &Function,
generics: &HashSet<Identifier>,
) -> Result<Vec<(Identifier, Type)>, Box<AnalyzerErrorKind>> {
Expand Down
Loading