diff --git a/changes-5.1.html b/changes-5.1.html
index b8785c31a..a602e077d 100644
--- a/changes-5.1.html
+++ b/changes-5.1.html
@@ -7,7 +7,7 @@
YAP change log
-
+xb
@@ -17,6 +17,9 @@
Yap-5.1.3:
+- SPEEDUP: quickly check if we are importing an undefined goal.
+- FIXED: current_predicate/1 should enumerate all predicates
+ visible (obs from Nicos Angelopoulos).
- NEW: time/1 (based on the SWI-Prolog time/1 predicate; request from Paulo Moura).
- FIXED: with 64 bits indexing would separate ints from atoms (obs from A N Saravanaraj).
- FIXED: duplicated clause when starting from trace (obs from A N Saravanaraj).
diff --git a/pl/boot.yap b/pl/boot.yap
index 1136586d1..b14dba934 100644
--- a/pl/boot.yap
+++ b/pl/boot.yap
@@ -810,21 +810,15 @@ not(G) :- \+ '$execute'(G).
'$undefp'([M|G]) :-
% make sure we do not loop on undefined predicates
% for undefined_predicates.
+ (
+ recorded('$import','$import'(NM,M,Goal,G,_,_),_)
+ ;
'$enter_undefp',
- '$find_undefp_handler'(G,M,Goal,NM), !,
+ once('$find_undefp_handler'(G,M,Goal,NM))
+ ),
+ !,
'$execute0'(Goal,NM).
-'$find_undefp_handler'(G,M,NG,S) :-
- recorded('$import','$import'(S,M,NG,G,_,_),_),
- S \= M, % can't try importing from the module itself.
- !,
- '$exit_undefp'.
-/*
-'$find_undefp_handler'(G,M,NG,M) :-
- '$is_expand_goal_or_meta_predicate'(G,M),
- '$system_catch'(goal_expansion(G, M, NG), user, _, fail), !,
- '$exit_undefp'.
-*/
'$find_undefp_handler'(G,M,NG,user) :-
\+ '$undefined'(unknown_predicate_handler(_,_,_), user),
'$system_catch'(unknown_predicate_handler(G,M,NG), user, Error, '$leave_undefp'(Error)), !,
diff --git a/pl/preds.yap b/pl/preds.yap
index 4490157e9..ff1978a0a 100644
--- a/pl/preds.yap
+++ b/pl/preds.yap
@@ -884,3 +884,92 @@ predicate_erased_statistics(M:P,NCls,Sz,ISz) :- !,
predicate_erased_statistics(P,NCls,Sz,ISz) :-
'$current_module'(M),
'$predicate_erased_statistics'(M:P,NCls,Sz,_,ISz).
+
+current_predicate(A,T) :- var(T), !, % only for the predicate
+ '$current_module'(M),
+ '$current_predicate_no_modules'(M,A,T).
+current_predicate(A,M:T) :- % module specified
+ var(M), !,
+ current_module(M),
+ M \= prolog,
+ '$current_predicate_no_modules'(M,A,T).
+current_predicate(A,M:T) :- % module specified
+ nonvar(T),
+ !,
+ functor(T,A,_),
+ '$pred_exists'(T,M).
+current_predicate(A,M:T) :- % module specified
+ !,
+ '$current_predicate_no_modules'(M,A,T).
+current_predicate(A,T) :- % only for the predicate
+ '$current_module'(M),
+ '$current_predicate_no_modules'(M,A,T).
+
+current_predicate(F) :- var(F), !, % only for the predicate
+ '$current_module'(M),
+ '$current_predicate3'(M,F).
+current_predicate(M:F) :- % module specified
+ var(M), !,
+ '$current_module'(M),
+ M \= prolog,
+ '$current_predicate3'(M,F).
+current_predicate(M:F) :- % module specified
+ !,
+ '$current_predicate3'(M,F).
+current_predicate(S) :- % only for the predicate
+ '$current_module'(M),
+ '$current_predicate3'(M,S).
+
+system_predicate(A,P) :-
+ '$current_predicate_no_modules'(prolog,A,P),
+ \+ '$hidden'(A).
+
+system_predicate(P) :-
+ '$current_module'(M),
+ '$system_predicate'(P,M).
+
+'$current_predicate_no_modules'(M,A,T) :-
+ '$current_predicate'(M,A,Arity),
+ functor(T,A,Arity),
+ '$pred_exists'(T,M).
+
+'$current_predicate3'(M,A/Arity) :- nonvar(A), nonvar(Arity), !,
+ (
+ '$current_predicate'(M,A,Arity)
+ ->
+ functor(T,A,Arity),
+ '$pred_exists'(T,M)
+ ;
+ '$current_predicate'(prolog,A,Arity)
+ ->
+ functor(T,A,Arity),
+ '$pred_exists'(T,M)
+ ;
+ recorded('$import','$import'(NM,M,G,T,A,Arity),_)
+ ->
+ '$pred_exists'(G,NM)
+ ).
+'$current_predicate3'(M,A/Arity) :- !,
+ (
+ '$current_predicate'(M,A,Arity),
+ functor(T,A,Arity),
+ '$pred_exists'(T,M)
+ ;
+ '$current_predicate'(prolog,A,Arity),
+ functor(T,A,Arity),
+ '$pred_exists'(T,M)
+ ;
+ recorded('$import','$import'(NM,M,G,T,A,Arity),_),
+ functor(T,A,Arity),
+ '$pred_exists'(G,NM)
+ ).
+'$current_predicate3'(M,BadSpec) :- % only for the predicate
+ '$do_error'(type_error(predicate_indicator,BadSpec),current_predicate(M:BadSpec)).
+
+current_key(A,K) :-
+ '$current_predicate'(idb,A,Arity),
+ functor(K,A,Arity).
+current_key(A,K) :-
+ '$current_immediate_key'(A,K).
+
+
diff --git a/pl/utils.yap b/pl/utils.yap
index f988b01b7..d2391f240 100644
--- a/pl/utils.yap
+++ b/pl/utils.yap
@@ -381,68 +381,6 @@ current_atom(A) :- % generate
current_atom(A) :- % generate
'$current_wide_atom'(A).
-current_predicate(A,T) :- var(T), !, % only for the predicate
- '$current_module'(M),
- '$current_predicate_no_modules'(M,A,T).
-current_predicate(A,M:T) :- % module specified
- var(M), !,
- current_module(M),
- M \= prolog,
- '$current_predicate_no_modules'(M,A,T).
-current_predicate(A,M:T) :- % module specified
- nonvar(T),
- !,
- functor(T,A,_),
- '$pred_exists'(T,M).
-current_predicate(A,M:T) :- % module specified
- !,
- '$current_predicate_no_modules'(M,A,T).
-current_predicate(A,T) :- % only for the predicate
- '$current_module'(M),
- '$current_predicate_no_modules'(M,A,T).
-
-current_predicate(F) :- var(F), !, % only for the predicate
- '$current_module'(M),
- '$current_predicate3'(M,F).
-current_predicate(M:F) :- % module specified
- var(M), !,
- '$current_module'(M),
- M \= prolog,
- '$current_predicate3'(M,F).
-current_predicate(M:F) :- % module specified
- !,
- '$current_predicate3'(M,F).
-current_predicate(S) :- % only for the predicate
- '$current_module'(M),
- '$current_predicate3'(M,S).
-
-system_predicate(A,P) :-
- '$current_predicate_no_modules'(prolog,A,P),
- \+ '$hidden'(A).
-
-system_predicate(P) :-
- '$current_module'(M),
- '$system_predicate'(P,M).
-
-'$current_predicate_no_modules'(M,A,T) :-
- '$current_predicate'(M,A,Arity),
- functor(T,A,Arity),
- '$pred_exists'(T,M).
-
-'$current_predicate3'(M,A/Arity) :- !,
- '$current_predicate'(M,A,Arity),
- functor(T,A,Arity),
- '$pred_exists'(T,M).
-'$current_predicate3'(M,BadSpec) :- % only for the predicate
- '$do_error'(type_error(predicate_indicator,BadSpec),current_predicate(M:BadSpec)).
-
-current_key(A,K) :-
- '$current_predicate'(idb,A,Arity),
- functor(K,A,Arity).
-current_key(A,K) :-
- '$current_immediate_key'(A,K).
-
-
%%% The unknown predicate,
% informs about what the user wants to be done when
% there are no clauses for a certain predicate */