Fix bugs in dependency analysis
This commit is contained in:
parent
e7d3a5b9f2
commit
d23208c191
@ -49,7 +49,7 @@ fold(Alg = #alg{zero = Zero, plus = Plus, scoped = Scoped}, Fun, K, X) ->
|
|||||||
{type_def, _, I, _, D} -> Plus(BindType(I), Decl(D));
|
{type_def, _, I, _, D} -> Plus(BindType(I), Decl(D));
|
||||||
{fun_decl, _, _, T} -> Type(T);
|
{fun_decl, _, _, T} -> Type(T);
|
||||||
{letval, _, F, T, E} -> Sum([BindExpr(F), Type(T), Expr(E)]);
|
{letval, _, F, T, E} -> Sum([BindExpr(F), Type(T), Expr(E)]);
|
||||||
{letfun, _, F, Xs, T, E} -> Sum([BindExpr(F), Type(T), Scoped(BindExpr(Xs), Expr(E))]);
|
{letfun, _, F, Xs, T, E} -> Sum([BindExpr(F), Type(T), Expr(Xs ++ [E])]);
|
||||||
%% typedef()
|
%% typedef()
|
||||||
{alias_t, T} -> Type(T);
|
{alias_t, T} -> Type(T);
|
||||||
{record_t, Fs} -> Type(Fs);
|
{record_t, Fs} -> Type(Fs);
|
||||||
@ -74,7 +74,7 @@ fold(Alg = #alg{zero = Zero, plus = Plus, scoped = Scoped}, Fun, K, X) ->
|
|||||||
{list_comp, _, Y, []} -> Expr(Y);
|
{list_comp, _, Y, []} -> Expr(Y);
|
||||||
{list_comp, A, Y, [{comprehension_bind, I, E}|R]} ->
|
{list_comp, A, Y, [{comprehension_bind, I, E}|R]} ->
|
||||||
Plus(Expr(E), Scoped(BindExpr(I), Expr({list_comp, A, Y, R})));
|
Plus(Expr(E), Scoped(BindExpr(I), Expr({list_comp, A, Y, R})));
|
||||||
{list_comp, A, Y, [{comprehension_if, E}|R]} ->
|
{list_comp, A, Y, [{comprehension_if, _, E}|R]} ->
|
||||||
Plus(Expr(E), Expr({list_comp, A, Y, R}));
|
Plus(Expr(E), Expr({list_comp, A, Y, R}));
|
||||||
{list_comp, A, Y, [D = {letval, _, F, _, _} | R]} ->
|
{list_comp, A, Y, [D = {letval, _, F, _, _} | R]} ->
|
||||||
Plus(Decl(D), Scoped(BindExpr(F), Expr({list_comp, A, Y, R})));
|
Plus(Decl(D), Scoped(BindExpr(F), Expr({list_comp, A, Y, R})));
|
||||||
@ -92,7 +92,7 @@ fold(Alg = #alg{zero = Zero, plus = Plus, scoped = Scoped}, Fun, K, X) ->
|
|||||||
{field, _, LV, E} -> Expr([LV, E]);
|
{field, _, LV, E} -> Expr([LV, E]);
|
||||||
{field, _, LV, _, E} -> Expr([LV, E]);
|
{field, _, LV, _, E} -> Expr([LV, E]);
|
||||||
%% arg()
|
%% arg()
|
||||||
{arg, _, X, T} -> Plus(Expr(X), Type(T));
|
{arg, _, Y, T} -> Plus(BindExpr(Y), Type(T));
|
||||||
%% alt()
|
%% alt()
|
||||||
{'case', _, P, E} -> Scoped(BindExpr(P), Expr(E));
|
{'case', _, P, E} -> Scoped(BindExpr(P), Expr(E));
|
||||||
%% elim()
|
%% elim()
|
||||||
@ -124,12 +124,12 @@ used_types([Top] = _CurrentNS, T) ->
|
|||||||
entity_alg() ->
|
entity_alg() ->
|
||||||
IsBound = fun({K, _}) -> lists:member(K, [bound_term, bound_type]) end,
|
IsBound = fun({K, _}) -> lists:member(K, [bound_term, bound_type]) end,
|
||||||
Unbind = fun(bound_term) -> term; (bound_type) -> type end,
|
Unbind = fun(bound_term) -> term; (bound_type) -> type end,
|
||||||
Remove = fun(Keys, Map) -> lists:foldl(fun maps:remove/2, Map, Keys) end,
|
Remove = fun(Keys, Map) -> maps:without(Keys, Map) end,
|
||||||
Scoped = fun(Xs, Ys) ->
|
Scoped = fun(Xs, Ys) ->
|
||||||
Bound = [E || E <- maps:keys(Ys), IsBound(E)],
|
Bound = [E || E <- maps:keys(Xs), IsBound(E)],
|
||||||
Others = Remove(Bound, Ys),
|
|
||||||
Bound1 = [ {Unbind(Tag), X} || {Tag, X} <- Bound ],
|
Bound1 = [ {Unbind(Tag), X} || {Tag, X} <- Bound ],
|
||||||
maps:merge(Remove(Bound1, Xs), Others)
|
Others = Remove(Bound1, Ys),
|
||||||
|
maps:merge(Remove(Bound, Xs), Others)
|
||||||
end,
|
end,
|
||||||
#alg{ zero = #{}
|
#alg{ zero = #{}
|
||||||
, plus = fun maps:merge/2
|
, plus = fun maps:merge/2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user