ciao-lang / ciao

Ciao is a modern Prolog implementation that builds up from a logic-based simple kernel designed to be portable, extensible, and modular.
https://ciao-lang.org
GNU Lesser General Public License v3.0
272 stars 21 forks source link

Cannot use predicate_property/2 to query module predicate properties #28

Open pmoura opened 4 years ago

pmoura commented 4 years ago

With a loaded module, e.g.

?- current_module(between).

yes

is not possible to query the properties of predicates exported by the module:

?- between:predicate_property(between(_,_,_), P).
ERROR: Bad module qualification of predicate_property/2, module user(/Users/pmoura/ciao/core/library/toplevel/toplevel_scope) does not import the predicate from module between
{ERROR: $bad_qualification$:predicate_property/2 - existence error: procedure:$bad_qualification$:predicate_property/2 does not exist}

aborted
?- predicate_property(between:between(_,_,_), P).
ERROR: Bad module qualification of between/3, module user(/Users/pmoura/ciao/core/library/toplevel/toplevel_scope) does not import the predicate from module between

no
jfmc commented 2 years ago

Some details of what is happening (in Ciao's module system):

If Ciao semantics are too restrictive we can relax them, at least for code using the strict ISO compatibility mode.

Is there a test in Logtalk test suite that reflects the expected behavior? Thanks!

pmoura commented 2 years ago

When calling a Prolog module predicate from within a Logtalk object (or category), the compiler must be able to access key predicate properties such as a meta-predicate template so that the call is compiled correctly. For reliability, this require that the module is already loaded. An example is:

https://github.com/LogtalkDotOrg/logtalk3/tree/master/examples/symbiosis

If I modify this example to run load on Ciao, by using its hiordlib library, I get:

?- {loader}.
Note: module hiordlib already in executable, just made visible
% [ /Users/pmoura/logtalk/library/types/comparingp.lgt loaded ]
% [ /Users/pmoura/logtalk/library/types/termp.lgt loaded ]
% [ /Users/pmoura/logtalk/library/types/term.lgt loaded ]
% [ /Users/pmoura/logtalk/library/types/atomic.lgt loaded ]
% [ /Users/pmoura/logtalk/library/types/atom.lgt loaded ]
% [ /Users/pmoura/logtalk/library/types/number.lgt loaded ]
% [ /Users/pmoura/logtalk/library/types/float.lgt loaded ]
% [ /Users/pmoura/logtalk/library/types/integer.lgt loaded ]
% [ /Users/pmoura/logtalk/library/types/compound.lgt loaded ]
% [ /Users/pmoura/logtalk/library/types/listp.lgt loaded ]
% [ /Users/pmoura/logtalk/library/types/list.lgt loaded ]
% [ /Users/pmoura/logtalk/library/types/type.lgt loaded ]
% [ /Users/pmoura/logtalk/library/basic_types/loader.lgt loaded ]
ERROR: Bad module qualification of maplist/2, module user(/opt/local/share/logtalk/adapters/ciao) does not import the predicate from module hiordlib
ERROR: Bad module qualification of maplist/3, module user(/opt/local/share/logtalk/adapters/ciao) does not import the predicate from module hiordlib
ERROR: Bad module qualification of maplist/3, module user(/opt/local/share/logtalk/adapters/ciao) does not import the predicate from module hiordlib
ERROR: Bad module qualification of maplist/3, module user(/opt/local/share/logtalk/adapters/ciao) does not import the predicate from module hiordlib
ERROR: Bad module qualification of maplist/3, module user(/opt/local/share/logtalk/adapters/ciao) does not import the predicate from module hiordlib
ERROR: Bad module qualification of maplist/2, module user(/opt/local/share/logtalk/adapters/ciao) does not import the predicate from module hiordlib
ERROR: Bad module qualification of maplist/3, module user(/opt/local/share/logtalk/adapters/ciao) does not import the predicate from module hiordlib
{Compiling /Users/pmoura/Documents/Logtalk/logtalk3/examples/symbiosis/.lgt_tmp/symbiosis_2978548357_45120_lgt.pl
ERROR: (lns 21-21) Bad module qualification of maplist/2, predicate not imported from module hiordlib
ERROR: (lns 22-22) Bad module qualification of maplist/3, predicate not imported from module hiordlib
ERROR: (lns 24-24) Bad module qualification of maplist/3, predicate not imported from module hiordlib
ERROR: (lns 25-25) Bad module qualification of maplist/3, predicate not imported from module hiordlib
ERROR: (lns 26-26) Bad module qualification of maplist/3, predicate not imported from module hiordlib
ERROR: (lns 28-28) Bad module qualification of maplist/2, predicate not imported from module hiordlib
ERROR: (lns 29-29) Bad module qualification of maplist/3, predicate not imported from module hiordlib
ERROR: Aborted module compilation
}
% [ /Users/pmoura/Documents/Logtalk/logtalk3/examples/symbiosis/symbiosis.lgt loaded ]
% [ /Users/pmoura/Documents/Logtalk/logtalk3/examples/symbiosis/loader.lgt loaded ]
% (0 warnings)

The loader.lgt file includes the directive:

:- use_module(library(hiordlib), []).

This directive loads the module into user. But despite that we get the errors above on explicitly-qualified calls to the hiordlib exported predicates (from code that's also being loaded into user). Same errors if we use instead a use_module/1 directive.