Skip to content

Commit

Permalink
ENHANCED: Allow suppressing autoload warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
JanWielemaker committed Nov 21, 2024
1 parent a1b7b50 commit 21f46ad
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
24 changes: 24 additions & 0 deletions boot/autoload.pl
Original file line number Diff line number Diff line change
Expand Up @@ -966,10 +966,15 @@
* CHECK *
*******************************/

%! warn_autoload(+TargetModule, :PI) is det.
%
% @arg PI is of the shape LoadModule:Name/Arity.

warn_autoload(TargetModule, PI) :-
current_prolog_flag(warn_autoload, true),
\+ current_prolog_flag(xref, true),
\+ nb_current('$autoload_warning', true),
\+ nowarn_autoload(TargetModule, PI),
'$pi_head'(PI, Head),
source_file(Head, File),
expansion_hook(P),
Expand All @@ -987,6 +992,25 @@
expansion_hook(system:goal_expansion(_,_)).
expansion_hook(system:goal_expansion(_,_,_,_)).

%! nowarn_autoload(+TargetModule, +LoadModulePI) is semidet.
%
% True when LoadModule:'$nowarn_autoload'(PI,TargetModule) is defined
% and true.
%
% @tbd As is, these facts must be defined by the library being
% autoloaded. Possibly we want a specific autoload declaration. As all
% this only affects the Prolog libraries, we can always change this.
% One option might be this, where `How` is one of `true`, `false` or
% `warning`.
%
% :- autoloadable(PI, How)

nowarn_autoload(TargetModule, LoadModule:PI) :-
NoWarn = LoadModule:'$nowarn_autoload'(PI,TargetModule),
'$c_current_predicate'(_, NoWarn),
\+ '$get_predicate_attribute'(NoWarn, imported, _From),
call(NoWarn).


/*******************************
* REQUIRE *
Expand Down
9 changes: 8 additions & 1 deletion library/debug.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Author: Jan Wielemaker
E-mail: [email protected]
WWW: http://www.swi-prolog.org
Copyright (c) 2002-2023, University of Amsterdam
Copyright (c) 2002-2024, University of Amsterdam
VU University Amsterdam
CWI, Amsterdam
SWI-Prolog Solutions b.v.
Expand Down Expand Up @@ -488,3 +488,10 @@
:- multifile sandbox:safe_meta/2.

sandbox:safe_meta(prolog_debug:assertion(X), [X]).

/*******************************
* SUPPRESS AUTOLOAD WARNINGS *
*******************************/

'$nowarn_autoload'(debug/1, _).
'$nowarn_autoload'(nodebug/1, _).

0 comments on commit 21f46ad

Please sign in to comment.