Skip to content

Conversation

AlSchlo
Copy link
Collaborator

@AlSchlo AlSchlo commented Apr 29, 2025

What

Adds list pattern matching in the DSL. This partially addresses #81 .

Programs as follows now properly type check.

data Logical =
    | Add(left: Logical, right: Logical)
    | List(bla: [Logical])
    \ Const(val: I64)
    
data Physical
data LogicalProperties
data PhysicalProperties

fn (log: Logical) fold = x -> x

fn arr_as_function(other: Logical, idx: I64, closure: I64 -> Logical?) = closure(idx)

fn main(log: Logical): Logical? = match log 
    | Add(Add(_, _), right: Const(val)) -> {
        let closure = x -> right in
        closure(5)
    }
    | fooo -> arr_as_function(fooo, 0, [log])
    | List(bla) -> match bla
        | vla -> vla(0)
        \ [] -> none
    | Add(left, right) -> left
    \ _ -> fail("brru")

fn (log: [Logical]) vla(): [Logical] = match log 
    \ [Const(5) .. [List([Const(5) .. _]) .. v]] -> v

How

Added the Constraint::Scrutinee constraint, and the InvalidArrayDecomposition error. Most of the code that used to be in generate.rs has been moved to solver.rs as the type contained in the array needs to be properly resolved before we can check if the nested pattern fields are valid.

Next steps

Continue addressing #81 , specifically generic types and concatenation.

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

codecov-commenter commented Apr 29, 2025

Codecov Report

Attention: Patch coverage is 85.08159% with 64 lines in your changes missing coverage. Please review.

Project coverage is 88.8%. Comparing base (41b2c19) to head (3f744f2).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
optd/src/dsl/analyzer/errors.rs 28.5% 35 Missing ⚠️
optd/src/dsl/analyzer/type_checks/solver.rs 91.1% 29 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
optd/src/dsl/analyzer/from_ast/expr.rs 94.7% <100.0%> (+0.1%) ⬆️
optd/src/dsl/analyzer/from_ast/pattern.rs 94.2% <100.0%> (-0.4%) ⬇️
optd/src/dsl/analyzer/type_checks/generate.rs 90.9% <100.0%> (+4.2%) ⬆️
optd/src/dsl/analyzer/type_checks/registry.rs 96.9% <100.0%> (+0.1%) ⬆️
optd/src/dsl/analyzer/type_checks/solver.rs 92.9% <91.1%> (+4.4%) ⬆️
optd/src/dsl/analyzer/errors.rs 27.6% <28.5%> (+<0.1%) ⬆️

... and 3 files with indirect coverage changes

🚀 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 29, 2025 22:06
@AlSchlo AlSchlo changed the title (fix) Type Inference (feat) Array Decomposition Type Inference Apr 29, 2025
@AlSchlo AlSchlo added the dsl label Apr 29, 2025
@AlSchlo AlSchlo self-assigned this Apr 29, 2025
@AlSchlo AlSchlo merged commit c38a7d8 into main Apr 29, 2025
12 checks passed
@AlSchlo AlSchlo deleted the alexis/type-infer-fixes branch April 29, 2025 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants