From 21f46ad65c0374c16140a231dea78891058b9787 Mon Sep 17 00:00:00 2001 From: Jan Wielemaker Date: Thu, 21 Nov 2024 10:50:59 +0100 Subject: [PATCH] ENHANCED: Allow suppressing autoload warnings. --- boot/autoload.pl | 24 ++++++++++++++++++++++++ library/debug.pl | 9 ++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/boot/autoload.pl b/boot/autoload.pl index 5df6b3e209..db0ebc302d 100644 --- a/boot/autoload.pl +++ b/boot/autoload.pl @@ -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), @@ -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 * diff --git a/library/debug.pl b/library/debug.pl index 16913782aa..0a273e972b 100644 --- a/library/debug.pl +++ b/library/debug.pl @@ -3,7 +3,7 @@ Author: Jan Wielemaker E-mail: J.Wielemaker@vu.nl 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. @@ -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, _).