Skip to content

Commit

Permalink
(core) p_unit: save native/2 and regtype/2 info in lib cache
Browse files Browse the repository at this point in the history
Src-commit: 5db0586d103c9557be5c63b2c8f8138ef71e3e6b
  • Loading branch information
jfmc committed Aug 2, 2024
1 parent 9b4f18b commit 81677f2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
8 changes: 4 additions & 4 deletions core/lib/compiler/p_unit/p_unit.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,7 @@
prop_to_native(Prop,_NProp):-
var(Prop), !, throw(error(instantiation_error(Prop), prop_to_native/2)).
prop_to_native(Prop,NProp2):-
current_fact(pgm_regtype(Prop,NProp0)), !,
prop_regtype(Prop,NProp0), !,
NProp2=regtype(NProp),
( prop_to_native_(Prop,NProp) -> true % TODO: why?
; NProp=NProp0
Expand All @@ -1808,7 +1808,7 @@

% TODO: Creates choicepoints. Intended?
prop_to_native_(Prop,NProp):-
current_fact(pgm_native(Prop,NProp)).
prop_native(Prop,NProp).
prop_to_native_(Prop,NProp):-
native_property(Prop,NProp). % builtin tables

Expand All @@ -1821,9 +1821,9 @@
native_to_prop(NProp2,Prop) :-
( NProp2 = regtype(NProp) -> RegType=yes ; NProp=NProp2, RegType=no ),
%
( current_fact(pgm_native(Prop0,NProp)) -> Prop=Prop0 % TODO: bad indexing
( prop_native(Prop0,NProp) -> Prop=Prop0 % TODO: bad indexing
; native_property(Prop0,NProp) -> Prop=Prop0 % builtin tables % TODO: bad indexing
; RegType=yes, current_fact(pgm_regtype(Prop0,NProp)) -> Prop=Prop0 % TODO: bad indexing
; RegType=yes, prop_regtype(Prop0,NProp) -> Prop=Prop0 % TODO: bad indexing
; fail
).

Expand Down
20 changes: 19 additions & 1 deletion core/lib/compiler/p_unit/p_unit_db.pl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
removeall_assertion_read/9,
ref_assertion_read/10,
assertion_of/9, % TODO: DO NOT EXPORT! erase after normalization
prop_regtype/2,
prop_native/2,
% ------
% (clause_db)
clause_read/7,
Expand Down Expand Up @@ -163,7 +165,10 @@
%
retractall_fact(lib_assertion_read(_,_,_,_,_,_,_,_,_)),
%
retractall_fact(lib_prop_clause_read(_,_,_,_,_,_,_)).
retractall_fact(lib_prop_clause_read(_,_,_,_,_,_,_)),
%
retractall_fact(lib_native(_,_)),
retractall_fact(lib_regtype(_,_)).

% ===========================================================================
%! # Module interface (itf)
Expand Down Expand Up @@ -481,6 +486,16 @@
assertion_type(assertion_read(_,_,_,Type,_,_,_,_,_),Type).
assertion_type(pgm_assertion_read(_,_,_,Type,_,_,_,_,_),Type).

prop_native(Goal,Prop) :-
pgm_native(Goal,Prop).
prop_native(Goal,Prop) :-
lib_native(Goal,Prop).

prop_regtype(Goal,Prop) :-
pgm_regtype(Goal,Prop).
prop_regtype(Goal,Prop) :-
lib_regtype(Goal,Prop).

% ===========================================================================
%! # Clauses (and other directives)

Expand Down Expand Up @@ -574,6 +589,9 @@
%
dump_lib_data(lib_prop_clause_read(M, Head, Body, VarNames, Source, LB, LE)) :-
prop_clause_read(M, Head, Body, VarNames, Source, LB, LE).
%
dump_lib_data(lib_regtype(Goal,Prop)) :- prop_regtype(Goal,Prop), get_module_from_sg(Goal,M), \+ fake_module_name(M). % TODO: \+ fake needed here?
dump_lib_data(lib_native(Goal,Prop)) :- prop_native(Goal,Prop), get_module_from_sg(Goal,M), \+ fake_module_name(M). % TODO: \+ fake needed here?

% Adding data (for restoring)
add_lib_data(lib_defines_module(A,B)) :- !,
Expand Down

0 comments on commit 81677f2

Please sign in to comment.