[m-dev.] diff: avoid spurious Aditi error messages
Simon TAYLOR
stayl at cs.mu.OZ.AU
Fri May 26 18:15:35 AEST 2000
Estimated hours taken: 1.5
Avoid generating error messages for imported Aditi predicates
which are not used. The check for abstract types in the arguments
of Aditi relations must be performed for imported predicates which
are used because discriminated union types are written as abstract
types in `.int2' files. A type for which the body is available in
the module defining a predicate may be seen as an abstract type
in an importing module.
compiler/magic.m:
Only process imported Aditi procedures which are used.
tests/valid/Mmakefile:
tests/valid/aditi_error_bug.m:
tests/valid/aditi_error_bug2.m:
tests/valid/aditi_error_bug3.m:
Test case.
Index: compiler/magic.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/magic.m,v
retrieving revision 1.18
diff -u -u -r1.18 magic.m
--- compiler/magic.m 2000/05/22 17:59:33 1.18
+++ compiler/magic.m 2000/05/25 06:25:05
@@ -207,7 +207,21 @@
{ module_info_aditi_dependency_ordering(ModuleInfo3, Ordering) },
{ magic_info_init(ModuleInfo3, Info0) },
{ module_info_predids(ModuleInfo3, PredIds) },
- { magic__process_imported_procs(PredIds, Info0, Info1) },
+
+ %
+ % Only preprocess imported Aditi predicates which are used,
+ % to avoid performing error checking (e.g. checking for abstract
+ % types) on predicates which are not used. The check for abstract
+ % types needs to be done in importing modules because an imported
+ % predicate's declaration may use types which are indirectly imported
+ % from another module. Discriminated union types are written as
+ % abstract types to `.int2' files.
+ %
+ { set__init(UsedImportedPreds0) },
+ { list__foldl(magic__find_used_imported_aditi_preds(ModuleInfo3),
+ Ordering, UsedImportedPreds0, UsedImportedPreds) },
+ { magic__process_imported_procs(PredIds, UsedImportedPreds,
+ Info0, Info1) },
globals__io_lookup_bool_option(very_verbose, Verbose),
% Add magic procedures, do some transformation on the goals.
@@ -378,29 +392,83 @@
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
+ % Find all imported procedures which are called within
+ % a local Aditi procedure. The magic sets version of their
+ % interface must be produced.
+:- pred magic__find_used_imported_aditi_preds(module_info::in,
+ aditi_scc::in, set(pred_id)::in, set(pred_id)::out) is det.
+
+magic__find_used_imported_aditi_preds(ModuleInfo, SCC, Preds0, Preds) :-
+ SCC = aditi_scc(SCCPredProcIds0, _EntryPoints),
+ list__condense(SCCPredProcIds0, SCCPredProcIds),
+ list__foldl(magic__find_used_imported_aditi_preds_2(ModuleInfo),
+ SCCPredProcIds, Preds0, Preds).
+
+:- pred magic__find_used_imported_aditi_preds_2(module_info::in,
+ pred_proc_id::in, set(pred_id)::in, set(pred_id)::out) is det.
+
+magic__find_used_imported_aditi_preds_2(ModuleInfo,
+ PredProcId, Preds0, Preds) :-
+ module_info_pred_proc_info(ModuleInfo, PredProcId, _, ProcInfo),
+ proc_info_goal(ProcInfo, Goal),
+
+ % Generate all pred_ids called by a goal.
+ Generator = (pred(P::out) is nondet :- goal_calls_pred_id(Goal, P)),
+
+ % Add all used imported Aditi predicates to the accumulator.
+ Accumulator =
+ (pred(CalledPredId::in, UsedPreds0::in, UsedPreds::out) is det :-
+ module_info_pred_info(ModuleInfo,
+ CalledPredId, CalledPredInfo),
+ (
+ pred_info_is_imported(CalledPredInfo),
+ pred_info_is_aditi_relation(CalledPredInfo)
+ ->
+ set__insert(UsedPreds0, CalledPredId, UsedPreds)
+ ;
+ UsedPreds = UsedPreds0
+ )
+ ),
+
+ Preds = promise_only_solution(
+ (pred(Preds1::out) is cc_multi :-
+ unsorted_aggregate(Generator, Accumulator,
+ Preds0, Preds1)
+ )).
+
% Convert imported Aditi procedures for the magic sets interface.
-:- pred magic__process_imported_procs(list(pred_id)::in,
+:- pred magic__process_imported_procs(list(pred_id)::in, set(pred_id)::in,
magic_info::in, magic_info::out) is det.
-magic__process_imported_procs([]) --> [].
-magic__process_imported_procs([PredId | PredIds]) -->
+magic__process_imported_procs([], _) --> [].
+magic__process_imported_procs([PredId | PredIds], UsedPreds) -->
magic_info_get_module_info(ModuleInfo),
{ module_info_pred_info(ModuleInfo, PredId, PredInfo) },
(
{ pred_info_is_imported(PredInfo) },
- { hlds_pred__is_derived_relation(ModuleInfo, PredId) }
+ { hlds_pred__is_derived_relation(ModuleInfo, PredId) },
+ { set__member(PredId, UsedPreds) }
->
{ pred_info_procids(PredInfo, ProcIds) },
magic__process_imported_procs_2(PredId, ProcIds)
;
- { hlds_pred__pred_info_is_base_relation(PredInfo) }
+ { hlds_pred__pred_info_is_base_relation(PredInfo) },
+ {
+ % Always preprocess base relations defined in
+ % this module.
+ module_info_name(ModuleInfo, ModuleName),
+ pred_info_module(PredInfo, PredModuleName),
+ ModuleName = PredModuleName
+ ;
+ set__member(PredId, UsedPreds)
+ }
->
{ pred_info_procids(PredInfo, ProcIds) },
list__foldl(magic__process_base_relation(PredId), ProcIds)
;
[]
),
- magic__process_imported_procs(PredIds).
+ magic__process_imported_procs(PredIds, UsedPreds).
:- pred magic__process_imported_procs_2(pred_id::in, list(proc_id)::in,
magic_info::in, magic_info::out) is det.
Index: tests/valid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/valid/Mmakefile,v
retrieving revision 1.64
diff -u -u -r1.64 Mmakefile
--- tests/valid/Mmakefile 2000/05/21 11:50:36 1.64
+++ tests/valid/Mmakefile 2000/05/25 07:12:00
@@ -27,6 +27,7 @@
instance_unconstrained_tvar.m
ADITI_SOURCES= \
+ aditi_error_bug.m \
aditi_update.m \
base_relation.m \
base_relation2.m \
@@ -196,6 +197,9 @@
GRADEFLAGS-complex_failure = --use-trail
GRADEFLAGS-semi_fail_in_non_ite = --use-trail
+MCFLAGS-aditi_error_bug = --aditi
+MCFLAGS-aditi_error_bug2 = --aditi
+MCFLAGS-aditi_error_bug3 = --aditi
MCFLAGS-aditi_update = --aditi
MCFLAGS-base_relation = --aditi
MCFLAGS-base_relation2 = --aditi
Index: tests/valid/aditi_error_bug.m
===================================================================
RCS file: aditi_error_bug.m
diff -N aditi_error_bug.m
--- /dev/null Fri May 26 18:06:41 2000
+++ aditi_error_bug.m Thu May 25 17:04:04 2000
@@ -0,0 +1,16 @@
+:- module aditi_error_bug.
+
+:- interface.
+
+:- import_module aditi.
+
+:- pred query(aditi__state::aditi_mui, int::out) is nondet.
+:- pragma aditi(query/2).
+
+:- implementation.
+
+:- import_module aditi_error_bug2.
+
+query(DB, Number) :-
+ murders(DB, "New York", "New York", 1995, Number).
+
Index: tests/valid/aditi_error_bug2.m
===================================================================
RCS file: aditi_error_bug2.m
diff -N aditi_error_bug2.m
--- /dev/null Fri May 26 18:06:41 2000
+++ aditi_error_bug2.m Thu May 25 17:07:32 2000
@@ -0,0 +1,52 @@
+%% Simple test for various things related to "crimes" database.
+
+:- module aditi_error_bug2.
+
+:- interface.
+
+:- import_module aditi.
+:- import_module aditi_error_bug3.
+
+:- pred murders(aditi:state,city,us_state,year,count).
+:- mode murders(aditi:aditi_mui,out,out,out,out) is nondet.
+:- pragma aditi(assaults/5).
+
+:- pred assaults(aditi:state,city,us_state,year,count).
+:- mode assaults(aditi:aditi_mui,out,out,out,out) is nondet.
+:- pragma aditi(murders/5).
+
+:- pred crime(aditi:state,crime_type,city,us_state,year,count).
+:- mode crime(aditi:aditi_mui,out,out,out,out,out) is nondet.
+:- pragma aditi(crime/6).
+
+:- pred crimes(
+ aditi:state::aditi:aditi_mui,
+ city::out, % city name
+ us_state::out, % state name
+ year::out, % year
+ count::out, % crime index total
+ count::out, % modified crime index total
+ count::out, % murders
+ count::out, % rapes
+ count::out, % robberies
+ count::out, % aggravated assaults
+ count::out, % burglaries
+ count::out, % larceny thefts
+ count::out, % MV thefts
+ count::out % arsons
+ ) is nondet.
+:- pragma base_relation(crimes/14).
+
+:- implementation.
+
+murders(DB,City,State,Year,Number) :-
+ crimes(DB,City,State,Year,_,_,Number,_,_,_,_,_,_,_).
+
+assaults(DB,City,State,Year,Number) :-
+ crimes(DB,City,State,Year,_,_,_,_,_,Number,_,_,_,_).
+
+crime(DB,murder,City,State,Year,Number) :-
+ murders(DB,City,State,Year,Number).
+crime(DB,assault,City,State,Year,Number) :-
+ assaults(DB,City,State,Year,Number).
+
Index: tests/valid/aditi_error_bug3.m
===================================================================
RCS file: aditi_error_bug3.m
diff -N aditi_error_bug3.m
--- /dev/null Fri May 26 18:06:41 2000
+++ aditi_error_bug3.m Thu May 25 17:02:07 2000
@@ -0,0 +1,17 @@
+:- module aditi_error_bug3.
+:- interface.
+
+:- import_module list.
+
+:- type real == float.
+:- type count == int.
+
+:- type city == string.
+:- type us_state == string.
+:- type year == int.
+:- type rate == real.
+:- type region == string.
+:- type percent == real.
+:- type crime_type ---> rape ; robbery ; murder ; assault ; arson ; mv_theft.
+
+:- type ints == list(int).
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list