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

Experimental constraint solver #450

Merged
merged 85 commits into from
Dec 31, 2022
Merged

Commits on Dec 30, 2022

  1. Configuration menu
    Copy the full SHA
    b6ebd79 View commit details
    Browse the repository at this point in the history
  2. First iteration of the constraint solver

    This is my first stab at the constraint solver. It is only very
    lightly tested and is not hooked in to the type checker yet.
    josefs authored and erszcz committed Dec 30, 2022
    Configuration menu
    Copy the full SHA
    0db747f View commit details
    Browse the repository at this point in the history
  3. Fix haskellism in list comprehension

    josefs authored and erszcz committed Dec 30, 2022
    Configuration menu
    Copy the full SHA
    c4027c5 View commit details
    Browse the repository at this point in the history
  4. Call constraint solver when checking functions

    When checking toplevel functions, call the constraint solver to work
    out if the existential types are correct.
    
    Unimplemented:
    
    * Applying the substitution on the remaining types.
    * Check that the remaining constraints are compatible with the
      constraints declared in the spec.
    
    I fixed a few bugs in the process.
    josefs authored and erszcz committed Dec 30, 2022
    Configuration menu
    Copy the full SHA
    8ab1daa View commit details
    Browse the repository at this point in the history
  5. Fix typespec in constraints

    josefs authored and erszcz committed Dec 30, 2022
    Configuration menu
    Copy the full SHA
    cdfee19 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    0b7ec2e View commit details
    Browse the repository at this point in the history
  7. Fix variable lookup bug in constraint solver

    A variable might not have any constraints and that's fine!
    josefs authored and erszcz committed Dec 30, 2022
    Configuration menu
    Copy the full SHA
    59dfb02 View commit details
    Browse the repository at this point in the history
  8. Drop constraints when typechecking unions

    Keeping the constraints when checking unions requires having a union
    of constraints and the current implementation doesn't support that. So
    right now we just drop the constraints.
    
    This means that we currently don't report as many type errors as one
    might expect.
    josefs authored and erszcz committed Dec 30, 2022
    Configuration menu
    Copy the full SHA
    e0df9bd View commit details
    Browse the repository at this point in the history
  9. Revamp type variable instantiation

    josefs authored and erszcz committed Dec 30, 2022
    Configuration menu
    Copy the full SHA
    19c6362 View commit details
    Browse the repository at this point in the history
  10. Drop constraints from expect_*_type functions

    The current representation for constraints cannot handle union types
    so the constraints are dropped for now.
    
    This means that some type errors will not be caught.
    josefs authored and erszcz committed Dec 30, 2022
    Configuration menu
    Copy the full SHA
    bf92627 View commit details
    Browse the repository at this point in the history
  11. Fix spec of instantiate_fun_type/1

    josefs authored and erszcz committed Dec 30, 2022
    Configuration menu
    Copy the full SHA
    cd0fbef View commit details
    Browse the repository at this point in the history
  12. Fix typespec for listsspecs:join/0

    josefs authored and erszcz committed Dec 30, 2022
    Configuration menu
    Copy the full SHA
    2f9df31 View commit details
    Browse the repository at this point in the history
  13. Reuse already defined type

    josefs authored and erszcz committed Dec 30, 2022
    Configuration menu
    Copy the full SHA
    60466f1 View commit details
    Browse the repository at this point in the history
  14. Update expect_fun_type1 to the new instantiate_fun_type

    The function instantiate_fun_type now returns constraints which
    have to be propagated.
    
    This was caught by dialyzer
    josefs authored and erszcz committed Dec 30, 2022
    Configuration menu
    Copy the full SHA
    9ef6700 View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    b6f3af6 View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    083d901 View commit details
    Browse the repository at this point in the history
  17. Reindent and unify style

    erszcz committed Dec 30, 2022
    Configuration menu
    Copy the full SHA
    83635c6 View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    cd65e7c View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    975f31f View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    9e3a7c3 View commit details
    Browse the repository at this point in the history
  21. Add a type var / union / case expr test

    Test that a type var is solved to a union type given there's a case expression with multiple
    patterns matching on an actual var the type var is assigned to.
    erszcz committed Dec 30, 2022
    Configuration menu
    Copy the full SHA
    9544819 View commit details
    Browse the repository at this point in the history
  22. Configuration menu
    Copy the full SHA
    cdd8ac1 View commit details
    Browse the repository at this point in the history
  23. Clean up compiler warnings

    erszcz committed Dec 30, 2022
    Configuration menu
    Copy the full SHA
    7b563f1 View commit details
    Browse the repository at this point in the history
  24. Fix test/absform_tests.erl

    erszcz committed Dec 30, 2022
    Configuration menu
    Copy the full SHA
    1268d93 View commit details
    Browse the repository at this point in the history
  25. Configuration menu
    Copy the full SHA
    642dbfe View commit details
    Browse the repository at this point in the history
  26. Fix self-check issue of #constraints{} field unavailable when checkin…

    …g typechecker.erl
    
    This is probably a bug, since this record is not accessed directly in typechecker.erl,
    but a crash in get_record_fields() still happened.
    erszcz committed Dec 30, 2022
    Configuration menu
    Copy the full SHA
    4a57eed View commit details
    Browse the repository at this point in the history
  27. Configuration menu
    Copy the full SHA
    7875be9 View commit details
    Browse the repository at this point in the history
  28. Configuration menu
    Copy the full SHA
    cb6131d View commit details
    Browse the repository at this point in the history
  29. Don't print the column in constraint violation ('not a subtype of') e…

    …rrors
    
    The columns are always 1 as they're taken from the enclosing function location.
    erszcz committed Dec 30, 2022
    Configuration menu
    Copy the full SHA
    02a8e48 View commit details
    Browse the repository at this point in the history
  30. Configuration menu
    Copy the full SHA
    cc19d7e View commit details
    Browse the repository at this point in the history
  31. Configuration menu
    Copy the full SHA
    e1d90d7 View commit details
    Browse the repository at this point in the history
  32. Configuration menu
    Copy the full SHA
    7220b6e View commit details
    Browse the repository at this point in the history
  33. Configuration menu
    Copy the full SHA
    6a1eb2d View commit details
    Browse the repository at this point in the history
  34. Configuration menu
    Copy the full SHA
    4e0f412 View commit details
    Browse the repository at this point in the history
  35. Configuration menu
    Copy the full SHA
    c2d3bc2 View commit details
    Browse the repository at this point in the history
  36. Configuration menu
    Copy the full SHA
    e441263 View commit details
    Browse the repository at this point in the history
  37. Configuration menu
    Copy the full SHA
    1765c3f View commit details
    Browse the repository at this point in the history
  38. Fix instantiate/2 spec and type checking error

    This is equivalent to the problem of typelib:remove_pos() which couldn't type check,
    as it declared accepting a type(), whereas in fact some clauses it had matched type() inner nodes,
    not the top level nodes. type() seems to be quite an unwieldy representation :/
    erszcz committed Dec 30, 2022
    Configuration menu
    Copy the full SHA
    4f8c49a View commit details
    Browse the repository at this point in the history
  39. Configuration menu
    Copy the full SHA
    c27a693 View commit details
    Browse the repository at this point in the history
  40. Configuration menu
    Copy the full SHA
    0e3258b View commit details
    Browse the repository at this point in the history
  41. Configuration menu
    Copy the full SHA
    099116d View commit details
    Browse the repository at this point in the history
  42. Configuration menu
    Copy the full SHA
    8584a9b View commit details
    Browse the repository at this point in the history
  43. Configuration menu
    Copy the full SHA
    b595e89 View commit details
    Browse the repository at this point in the history
  44. Configuration menu
    Copy the full SHA
    00bc397 View commit details
    Browse the repository at this point in the history
  45. Configuration menu
    Copy the full SHA
    c58515c View commit details
    Browse the repository at this point in the history
  46. Configuration menu
    Copy the full SHA
    22786c3 View commit details
    Browse the repository at this point in the history
  47. Configuration menu
    Copy the full SHA
    3c3d398 View commit details
    Browse the repository at this point in the history
  48. Configuration menu
    Copy the full SHA
    d82a03f View commit details
    Browse the repository at this point in the history
  49. Configuration menu
    Copy the full SHA
    29007ed View commit details
    Browse the repository at this point in the history
  50. Configuration menu
    Copy the full SHA
    d9f465a View commit details
    Browse the repository at this point in the history
  51. Configuration menu
    Copy the full SHA
    9b77f09 View commit details
    Browse the repository at this point in the history
  52. Configuration menu
    Copy the full SHA
    7530e12 View commit details
    Browse the repository at this point in the history

Commits on Dec 31, 2022

  1. Configuration menu
    Copy the full SHA
    20cb6fc View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    e0394a5 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    1339e00 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    50c1530 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    f3a5547 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    f5a2e9b View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    4c88113 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    d632a90 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    3a12b2f View commit details
    Browse the repository at this point in the history
  10. Rename: test/should_pass/{=> poly_}lists_map_constraints_pass.erl

    Also add the `solve_constraints` attribute.
    erszcz committed Dec 31, 2022
    Configuration menu
    Copy the full SHA
    eced46c View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    46d90e4 View commit details
    Browse the repository at this point in the history
  12. Rename: test/should_pass/poly_lists_map_constraints_pass.erl -> test/…

    …known_problems/should_pass/poly_lists_map_constraints_should_pass.erl
    erszcz committed Dec 31, 2022
    Configuration menu
    Copy the full SHA
    5c9f58b View commit details
    Browse the repository at this point in the history
  13. Move tests from test/known_problems/should_fail/poly_union_lower_boun…

    …d_should_fail.erl to test/should_fail/poly_union_lower_bound_fail.erl
    erszcz committed Dec 31, 2022
    Configuration menu
    Copy the full SHA
    68f0116 View commit details
    Browse the repository at this point in the history
  14. Move tests from test/known_problems/should_fail/poly_should_fail.erl …

    …to test/should_fail/poly_fail.erl
    erszcz committed Dec 31, 2022
    Configuration menu
    Copy the full SHA
    c800934 View commit details
    Browse the repository at this point in the history
  15. Move test from test/should_pass/poly_union_lower_bound_pass.erl to te…

    …st/known_problems/should_pass/poly_lists_map_constraints_should_pass.erl
    erszcz committed Dec 31, 2022
    Configuration menu
    Copy the full SHA
    a84487d View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    dcc11c7 View commit details
    Browse the repository at this point in the history
  17. Rename: test/known_problems/should_pass/poly_lists_map_constraints_sh…

    …ould_pass.erl -> test/should_pass/poly_lists_map_constraints_pass.erl
    erszcz committed Dec 31, 2022
    Configuration menu
    Copy the full SHA
    1ffa0e0 View commit details
    Browse the repository at this point in the history
  18. Add test to test/known_problems/should_pass/poly_should_pass.erl

    Based on:
    
        -spec get_unassigned_fields(Fields, All) -> [atom()] when
              Fields :: [record_field() | typed_record_field()],
              All :: [typed_record_field()].
        get_unassigned_fields(Fields, All) ->
            FieldNames = lists:flatmap(fun
                                           (?record_field(Field)) -> [Field];
                                           (?typed_record_field(Field)) -> [Field];
                                           %% We might run into values like this, which don't match above:
                                           %% {record_field, _, {var,{12,11},'_'}, _}
                                           (_) -> []
                                       end, Fields),
            AllNames = lists:map(fun (?typed_record_field(Field)) -> Field end, All),
            AllNames -- FieldNames.
    
    Which currently raises:
    
        ebin/typechecker.beam: Lower bound record_field() | typed_record_field()
            of type variable A_typechecker_3467_838 on line 2026 is not a subtype
            of {A_typechecker_3467_838_typechecker_1226_848,
                A_typechecker_3467_838_typechecker_1226_849,
                A_typechecker_3467_838_typechecker_1226_850}
    erszcz committed Dec 31, 2022
    Configuration menu
    Copy the full SHA
    8a5722a View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    95de84f View commit details
    Browse the repository at this point in the history
  20. Move test from test/known_problems/should_pass/poly_should_pass.erl t…

    …o test/should_pass/poly_union_lower_bound_pass.erl
    erszcz committed Dec 31, 2022
    Configuration menu
    Copy the full SHA
    13f552b View commit details
    Browse the repository at this point in the history
  21. Configuration menu
    Copy the full SHA
    34f76af View commit details
    Browse the repository at this point in the history
  22. Configuration menu
    Copy the full SHA
    f29449b View commit details
    Browse the repository at this point in the history
  23. Configuration menu
    Copy the full SHA
    c3499a1 View commit details
    Browse the repository at this point in the history
  24. Configuration menu
    Copy the full SHA
    f2aa9da View commit details
    Browse the repository at this point in the history
  25. Configuration menu
    Copy the full SHA
    d8ef301 View commit details
    Browse the repository at this point in the history
  26. Reindent

    erszcz committed Dec 31, 2022
    Configuration menu
    Copy the full SHA
    8c6f5c3 View commit details
    Browse the repository at this point in the history
  27. Configuration menu
    Copy the full SHA
    3961582 View commit details
    Browse the repository at this point in the history
  28. Fix type_var/1 spec

    erszcz committed Dec 31, 2022
    Configuration menu
    Copy the full SHA
    796c56f View commit details
    Browse the repository at this point in the history
  29. Configuration menu
    Copy the full SHA
    94d9d6a View commit details
    Browse the repository at this point in the history
  30. Add test to test/should_pass/poly_union_lower_bound_pass.erl

    Based on:
    
        -spec combine_clauses_argument_constraints([type()], constraints:t(), map(), env()) -> constraints:t().
        combine_clauses_argument_constraints(ArgsTys, Cs, CatchAllArgs, Env) ->
            ArgsTyVars = lists:flatmap(fun
                                           ({var, _, Var}) -> [Var];
                                           (_) -> []
                                       end, ArgsTys),
            ...
    
    The catch-all pattern does not register a constraint, while the tuple pattern does.
    Because of that the type checker fails matching any type() with the funs clauses and returns a warning,
    even though any type() instance will be handled by the fun.
    erszcz committed Dec 31, 2022
    Configuration menu
    Copy the full SHA
    80afeee View commit details
    Browse the repository at this point in the history
  31. Configuration menu
    Copy the full SHA
    1f78c53 View commit details
    Browse the repository at this point in the history
  32. Configuration menu
    Copy the full SHA
    ebbd798 View commit details
    Browse the repository at this point in the history
  33. Configuration menu
    Copy the full SHA
    d9e2bfd View commit details
    Browse the repository at this point in the history