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

Fix for boxing qtype and debugging improvements #47

Merged
merged 6 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions derivers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ local pretty_print = {
local idx = t.__index or {}
t.__index = idx
idx["pretty_print"] = record_pretty_printer(info)
if not t["__tostring"] then
t["__tostring"] = idx["pretty_print"]
end
end,
enum = function(t, info)
local idx = t.__index or {}
Expand Down Expand Up @@ -199,6 +202,9 @@ local pretty_print = {
local compiled, message = load(chunk, "derive-pretty_print_enum", "t")
assert(compiled, message)
idx["pretty_print"] = compiled(variant_printers)
if not t["__tostring"] then
t["__tostring"] = idx["pretty_print"]
end
end,
}

Expand Down
19 changes: 13 additions & 6 deletions evaluator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,12 @@ local function fitsinto_record_generator(trait, t, info)
if self == other then
return true
end
if self.kind ~= other.kind then
print("fitsinto_fail kind check failed for self, other")
print(self)
print(other)
return false, fitsinto_fail("incompatible kinds: " .. self.kind .. ", " .. other.kind)
end
local ok, err
%s
return true
Expand Down Expand Up @@ -832,11 +838,12 @@ function infer(
if not f_param_info:unwrap_param_info():unwrap_visibility():is_explicit() then
error("infer: nyi implicit parameters")
end
if not fitsinto(arg_type, f_param_type) then
print "function arg match failure"
print(f_param_type:pretty_print())
print(arg_type:pretty_print())
error("infer: mismatch in arg type and param type of function application")
local fitsinto_ok, fitsinto_err = fitsinto(arg_type, f_param_type)
if not fitsinto_ok then
print("function arg match failure")
print("f_param_type", f_param_type:pretty_print())
print("arg_type", arg_type:pretty_print())
error("infer: mismatch in arg type and param type of function application. fitsinto_err: " .. tostring(fitsinto_err))
end
local application_result_type =
apply_value(f_result_type, evaluate(arg_term, typechecking_context:get_runtime_context()))
Expand Down Expand Up @@ -1475,7 +1482,7 @@ function evaluate(typed_term, runtime_context)
local type_term = typed_term:unwrap_prim_boxed_type()
local type_value = evaluate(type_term, runtime_context)
local quantity, backing_type = type_value:unwrap_qtype()
return qtype(quantity, value.prim_boxed_type(backing_type))
return value.qtype(quantity, value.prim_boxed_type(backing_type))
elseif typed_term:is_prim_box() then
local content = typed_term:unwrap_prim_box()
return value.prim(evaluate(content, runtime_context))
Expand Down
1 change: 1 addition & 0 deletions terms.lua
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ for _, deriver in ipairs { derivers.as, derivers.pretty_print } do
quantity:derive(deriver)
visibility:derive(deriver)
value:derive(deriver)
neutral_value:derive(deriver)
binding:derive(deriver)
end

Expand Down
3 changes: 3 additions & 0 deletions test-derive-pretty-print.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ local c2 = mytype3(mytype1.foo, mytype2.middle(mytype1.baz))
local n = nest1.n(nest1.n(nest1.n(nest1.n(nest1.n(nest1.n(nest1.base(x2)))))))
print(x2:pretty_print())
print(n:pretty_print())
print(n)

assert(tostring(n) == n:pretty_print())
Loading