checkpoint

This commit is contained in:
Kacper Marzecki 2025-07-12 12:23:14 +02:00
parent e5485995ed
commit 61e95be622
3 changed files with 16 additions and 13 deletions

View File

@ -606,9 +606,9 @@ defmodule Tdd.Debug do
# --- TDD Graph Printing (Kept as it was, assuming it's for a different purpose) --- # --- TDD Graph Printing (Kept as it was, assuming it's for a different purpose) ---
@doc "Prints a formatted representation of a TDD graph structure." @doc "Prints a formatted representation of a TDD graph structure."
def print_tdd_graph(id, store_module \\ Tdd.Store) do def print_tdd_graph(id, label \\ "") do
IO.puts("--- TDD Graph (ID: #{id}) ---") IO.puts("---#{label} TDD Graph (ID: #{id}) ---")
do_print_tdd_node(id, 0, MapSet.new(), store_module) do_print_tdd_node(id, 0, MapSet.new(), Tdd.Store)
IO.puts("------------------------") IO.puts("------------------------")
end end

View File

@ -1357,6 +1357,7 @@ defmodule Tdd.Algo do
Store.put_op_cache(cache_key, result_id) Store.put_op_cache(cache_key, result_id)
result_id result_id
end end
|> simplify()
end end
# This function is correct and does not need to be changed. # This function is correct and does not need to be changed.
@ -2120,9 +2121,13 @@ defmodule Tdd.Compiler do
Store.init() Store.init()
id1 = spec_to_id(spec1) id1 = spec_to_id(spec1)
Debug.print_tdd_graph(id1, "IS_SUBTYPE id1")
id2 = spec_to_id(spec2) id2 = spec_to_id(spec2)
Debug.print_tdd_graph(id2, "IS_SUBTYPE id2")
neg_id2 = Algo.negate(id2) neg_id2 = Algo.negate(id2)
Debug.print_tdd_graph(neg_id2, "IS_SUBTYPE neg_id2")
intersect_id = Algo.apply(:intersect, &op_intersect_terminals/2, id1, neg_id2) intersect_id = Algo.apply(:intersect, &op_intersect_terminals/2, id1, neg_id2)
Debug.print_tdd_graph(intersect_id, "IS_SUBTYPE intersect")
# The crash was because `intersect_id` was not an integer, which should not # The crash was because `intersect_id` was not an integer, which should not
# happen if `apply` works correctly on valid IDs. By fixing the state # happen if `apply` works correctly on valid IDs. By fixing the state

View File

@ -380,22 +380,20 @@ defmodule TddSystemTest do
# These tests target the most complex features: recursive and polymorphic types. # These tests target the most complex features: recursive and polymorphic types.
# --- # ---
describe "Tdd.Compiler: Advanced Features (μ, Λ, Apply)" do describe "Tdd.Compiler: Advanced Features (μ, Λ, Apply)" do
@doc """ test "list subtyping: list(int) <: list(any)" do
It checks for covariance in generic types: a list of integers is a subtype of a list of anything,
but the reverse is not true. This requires the system to correctly handle coinductive reasoning
on the recursive TDD nodes.
"""
test "the previously crashing recursive subtype test now passes" do
int_list = {:list_of, :integer} int_list = {:list_of, :integer}
any_list = {:list_of, :any} any_list = {:list_of, :any}
assert_subtype(:integer, :any) assert_subtype(:integer, :any)
# The key test that was failing due to the bug
assert_subtype(int_list, any_list) assert_subtype(int_list, any_list)
refute_subtype(any_list, int_list)
# Also test instances against the recursive type
assert_subtype({:cons, {:literal, 1}, {:literal, []}}, int_list) assert_subtype({:cons, {:literal, 1}, {:literal, []}}, int_list)
end
test "list subtyping: list(any) <! list(integer)" do
int_list = {:list_of, :integer}
any_list = {:list_of, :any}
assert_subtype(:integer, :any)
refute_subtype({:cons, {:literal, :a}, {:literal, []}}, int_list) refute_subtype({:cons, {:literal, :a}, {:literal, []}}, int_list)
refute_subtype(any_list, int_list)
end end
@doc "Tests that manually-defined recursive types (like a binary tree) can be compiled and checked correctly." @doc "Tests that manually-defined recursive types (like a binary tree) can be compiled and checked correctly."