model description fixes & additions, correct memoisation in synthesizer (rec test passed)

This commit is contained in:
ProgramSnail 2026-03-15 12:26:47 +00:00
parent 0b261943db
commit 036322903b
3 changed files with 39 additions and 10 deletions

View file

@ -9,6 +9,19 @@
*TODO: проблемы с добавлением if в будущем: как записать write and not write ?*
Нужно будет добавить во write-flag модальности: `not write` | `may write` | `always write`
Добавление condition-исполнения - выбор из нескольких блоков. Варианты:
- & of | of & -вложенные блоки ?
- добавить несколько альтернативны тел функциям. Но тогда придётся при трансляции if-блоки выносить в функции
Лямбды - нужно тоже будет как-то находить лямбды и ля них тоже синтезировать атрибуты
вызов лямбд будет нужен в модели?
- lambda-аргумент - вложенные теги?, должна быть одна и та же сигнтура
можно ввести отдельные сигнатуры-определения?
проблема простой семантики: вызов лямбд: могут быть модифицируемые функции
== Синтаксис
#h(10pt)
@ -146,7 +159,7 @@ $d space @ space overline(x)$ - запись применения функции
name: [ is correct],
$isOut tag -> isWrite tag$, // NOTE; strong requirment should write
$isRead tag -> isIn tag$,
$isWrite tag -> isWrite sigma(x)$, // NOTE: may tag => should sigma(x)
$isWrite tag and (isOut tag or not isCopy tag) -> isWrite sigma(x)$, // NOTE: may tag => should sigma(x)
$isRead tag -> mu (sigma(x)) != bot$, // NOTE: may tag -> ...
$isCorrect_(cl sigma, mu cr) (tag, x)$,

View file

@ -520,6 +520,14 @@ struct
list_dropo n' ys xs' }
}
let rec list_not_membero xs x = ocanren {
xs == [] |
{ fresh x', xs' in
xs == x' :: xs' &
x' =/= x &
list_not_membero xs' x }
}
let visited_checko state f_id =
let open St in
ocanren {
@ -528,8 +536,13 @@ struct
List.membero visited f_id
}
(* TODO *)
(* let visited_not_checko state f_id = ??? *)
let not_visited_checko state f_id =
let open St in
ocanren {
fresh _env, _mem, _mem_len, visited in
state == St (_env, _mem, _mem_len, visited) &
list_not_membero visited f_id
}
let visited_addo state f_id state' =
let open St in
@ -546,16 +559,21 @@ struct
let open FunDecl in
let open Tag in
ocanren {
{ fresh f_id, args, f, args', state_after_call, state_with_visited, arg_tags, _body in
{ fresh f_id, args, f, args', state_after_call, arg_tags, _body in
stmt == Call (f_id, args) &
list_ntho prog f_id f &
FunDecl (arg_tags, _body) == f &
List.mapo arg_to_lvalueo args args' &
(* TODO: FIXME: memoisation, do not do calls on check successfull *)
eval_funo state prog f args' state_after_call &
(* NOTE: tmp simplification for less branching (TODO?) *)
visited_addo state_after_call f_id state_with_visited &
st_spoil_by_argso state_with_visited arg_tags args state' } |
{ { fresh state_with_visited in
not_visited_checko state f_id &
visited_addo state f_id state_with_visited &
eval_funo state_with_visited prog f args' state_after_call } |
{ visited_checko state f_id &
state_after_call == state } } &
st_spoil_by_argso state_after_call arg_tags args state' } |
{ fresh id in stmt == Read id & mem_checko state id & state == state' } |
{ fresh id, tag, _mem_id in
stmt == Write id &

View file

@ -57,7 +57,5 @@ let%expect_test "synthesis test 7" = print_endline (synt_t7 ()); [%expect {| [[V
let%expect_test "synthesis test 8" = print_endline (synt_t8 ()); [%expect {| [[Val; Val]; [Val; Ref]] |}]
let%expect_test "synthesis test 9" = print_endline (synt_t9 ()); [%expect {| [[Val; Ref]; [Val; Val]] |}]
(* TODO: FIXME: implement memoization cuts *)
(* NOTE: inf test in current model (without additional functional interfaces and ) *)
(* let%expect_test "recursive eval test" = print_endline (rec_eval_t ()); [%expect {| [St ([], [], O, [])] |}] *)
let%expect_test "recursive eval test" = print_endline (rec_eval_t ()); [%expect {| [St ([], [], O, [O])] |}]