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

(feat) Type Inference Constraints #72

merged 29 commits into from
Apr 17, 2025

Conversation

AlSchlo
Copy link
Collaborator

@AlSchlo AlSchlo commented Apr 14, 2025

quick overview

This PR is the first step to type inference. Specifically:

  1. Extracts all type annotations (explicit and implicit) during the initial from_ast conversion type. All other types that cannot be directly inferred are assigned a strictly monotonic unknown_id.
  2. During scope checking, we also generate type constraints, which I added in a Solver struct.
  3. Some bug fixes in the HIR.

No real new tests, as it makes more sense to test inference as a whole feature later on.

next steps

Writing the solver is the next logical step. More details coming in subsequent PRs.

@AlSchlo AlSchlo changed the title Alexis/type infer (feat) Type Inference Apr 15, 2025
@codecov-commenter
Copy link

codecov-commenter commented Apr 15, 2025

Codecov Report

Attention: Patch coverage is 77.90850% with 338 lines in your changes missing coverage. Please review.

Project coverage is 78.9%. Comparing base (07f8873) to head (47f6880).

Files with missing lines Patch % Lines
optd-dsl/src/analyzer/type_infer/generate.rs 66.4% 227 Missing ⚠️
optd-dsl/src/cli/main.rs 0.0% 41 Missing ⚠️
optd-dsl/src/analyzer/types.rs 93.7% 28 Missing ⚠️
optd-dsl/src/compile.rs 0.0% 20 Missing ⚠️
optd-dsl/src/analyzer/type_infer/solver.rs 60.0% 16 Missing ⚠️
optd-dsl/src/analyzer/from_ast/expr.rs 95.0% 4 Missing ⚠️
optd-dsl/src/analyzer/registry_check/adt_check.rs 96.4% 1 Missing ⚠️
...td-dsl/src/analyzer/registry_check/cycle_detect.rs 0.0% 1 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
optd-dsl/src/analyzer/context.rs 89.0% <ø> (ø)
optd-dsl/src/analyzer/errors.rs 29.6% <ø> (ø)
optd-dsl/src/analyzer/from_ast/converter.rs 98.5% <100.0%> (+<0.1%) ⬆️
optd-dsl/src/analyzer/from_ast/pattern.rs 94.1% <100.0%> (+<0.1%) ⬆️
optd-dsl/src/analyzer/from_ast/types.rs 96.1% <100.0%> (+0.5%) ⬆️
optd-dsl/src/analyzer/hir.rs 76.7% <100.0%> (-2.5%) ⬇️
optd-dsl/src/engine/eval/core.rs 98.9% <100.0%> (+<0.1%) ⬆️
optd-dsl/src/engine/eval/expr.rs 98.3% <100.0%> (+<0.1%) ⬆️
optd-dsl/src/engine/eval/match.rs 99.3% <100.0%> (+<0.1%) ⬆️
optd-dsl/src/engine/mod.rs 64.5% <100.0%> (ø)
... and 17 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AlSchlo AlSchlo marked this pull request as ready for review April 15, 2025 14:28
@AlSchlo AlSchlo changed the title (feat) Type Inference (feat) Type Inference Constraints Apr 15, 2025
@AlSchlo AlSchlo merged commit 665f98b into main Apr 17, 2025
12 checks passed
@AlSchlo AlSchlo deleted the alexis/type-infer branch April 17, 2025 20:46
AlSchlo added a commit that referenced this pull request Apr 17, 2025
### quick overview

This PR is the next step for type inference in our DSL, and follows #72
.

To solve the constraints, we need two core functions:
`greatest_lower_bound` and `least_upper_bound`.
- The least upper bound is the most specific type that is a supertype of
both input types.
- The greatest lower bound is the most general type that is a subtype of
both input types.
See tests for examples.

Furthermore, some code in `types.rs` was broken, but is now fixed.
- Map key was not contravariant, but covariant.
- `T` was not a subtype of `Optional[T]`.

### next steps

Writing the solver is the next and final step for practical type
inference. We would still need to handle `Generics` properly, and
propagate `Costed`/`Stored`.
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.

2 participants