[m-rev.] Re: for review: check for pred methods with no modes
Fergus Henderson
fjh at cs.mu.OZ.AU
Sun Apr 29 16:32:32 AEST 2001
On 25-Apr-2001, Fergus Henderson <fjh at cs.mu.oz.au> wrote:
> Fix a bug where the compiler was silently accepting invalid code.
>
> doc/reference_manual.texi:
> Document that type class methods must have their modes and
> determinism explicitly declared.
>
> compiler/make_hlds.m:
> Report errors for predicate type class methods with no modes
> or with modes but no determinism.
After further testing, I found that in some cases the compiler was
getting internal errors and (after I fixed that) producing spurious
flow-on error messages. Hence I made the following additional
changes. I'll go ahead and commit this now.
--- CHANGES2.old Sun Apr 29 16:25:54 2001
+++ CHANGES2 Sun Apr 29 16:26:52 2001
@@ -1,5 +1,5 @@
-Estimated hours taken: 4
+Estimated hours taken: 6
Branches: main, release
Fix a bug where the compiler was silently accepting invalid code.
@@ -12,6 +12,12 @@
Report errors for predicate type class methods with no modes
or with modes but no determinism.
+compiler/check_typeclass.m:
+compiler/polymorphism.m:
+ Handle the case where a method has no declared determinism:
+ since make_hlds.m will have already reported the error,
+ we just need to avoid aborting or issuing spurious flow-on errors.
+
tests/invalid/Mmakefile:
tests/invalid/typeclass_missing_mode.m:
tests/invalid/typeclass_missing_mode.err_exp:
@@ -21,6 +27,8 @@
tests/invalid/typeclass_missing_det.err_exp:
tests/invalid/typeclass_missing_det_2.m:
tests/invalid/typeclass_missing_det_2.err_exp:
+tests/invalid/typeclass_missing_det_3.m:
+tests/invalid/typeclass_missing_det_3.err_exp:
Add some regression tests.
Index: check_typeclass.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/check_typeclass.m,v
retrieving revision 1.39
diff -u -d -u -r1.39 check_typeclass.m
--- check_typeclass.m 2001/01/15 07:15:28 1.39
+++ check_typeclass.m 2001/04/29 06:17:37
@@ -395,11 +395,15 @@
(
map__lookup(ProcTable, TheProcId, ProcInfo),
proc_info_argmodes(ProcInfo, Modes),
- proc_info_interface_determinism(ProcInfo,
- Detism),
+ % if the determinism declaration on the method
+ % was omitted, then make_hlds.m will have
+ % already issued an error message, so
+ % don't complain here.
+ proc_info_declared_determinism(ProcInfo,
+ MaybeDetism),
proc_info_inst_varset(ProcInfo, InstVarSet),
ModesAndDetism = modes_and_detism(Modes,
- InstVarSet, Detism)
+ InstVarSet, MaybeDetism)
)),
ProcIds,
ArgModes),
@@ -428,7 +432,7 @@
OrderedMethods, Errors, ModuleInfo, QualInfo).
:- type modes_and_detism
- ---> modes_and_detism(list(mode), inst_varset, determinism).
+ ---> modes_and_detism(list(mode), inst_varset, maybe(determinism)).
:- pred check_instance_pred_procs(class_id, list(tvar), sym_name, pred_markers,
hlds_instance_defn, hlds_instance_defn,
@@ -713,9 +717,9 @@
AddProc = lambda([ModeAndDet::in, NewProcId::out,
OldPredInfo::in, NewPredInfo::out] is det,
(
- ModeAndDet = modes_and_detism(Modes, InstVarSet, Det),
+ ModeAndDet = modes_and_detism(Modes, InstVarSet, MaybeDet),
add_new_proc(OldPredInfo, InstVarSet, PredArity, Modes,
- yes(Modes), no, yes(Det), Context, address_is_taken,
+ yes(Modes), no, MaybeDet, Context, address_is_taken,
NewPredInfo, NewProcId)
)),
list__map_foldl(AddProc, ArgModes, InstanceProcIds,
Index: polymorphism.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/polymorphism.m,v
retrieving revision 1.208
diff -u -d -u -r1.208 polymorphism.m
--- polymorphism.m 2001/04/07 14:04:53 1.208
+++ polymorphism.m 2001/04/29 06:10:03
@@ -3318,9 +3318,17 @@
(
Detism0 = yes(Detism1)
->
- Detism = Detism1
+ Detism = Detism1,
+ ModuleInfo1 = ModuleInfo0
;
- error("missing determinism decl. How did we get this far?")
+ % Omitting the determinism for a method is not allowed.
+ % But make_hlds.m will have already detected and reported
+ % the error. So here we can just pick some value at random;
+ % hopefully something that won't cause flow-on errors.
+ % We also mark the predicate as invalid, also to avoid
+ % flow-on errors.
+ Detism = nondet,
+ module_info_remove_predid(ModuleInfo0, PredId, ModuleInfo1)
),
% Work out which argument corresponds to the constraint which
@@ -3365,7 +3373,7 @@
),
map__det_update(PredTable0, PredId, PredInfo, PredTable),
- module_info_set_preds(ModuleInfo0, PredTable, ModuleInfo),
+ module_info_set_preds(ModuleInfo1, PredTable, ModuleInfo),
ProcNum is ProcNum0 + 1.
Index: ../tests/invalid/typeclass_missing_det_3.m
===================================================================
RCS file: typeclass_missing_det_3.m
diff -N typeclass_missing_det_3.m
--- /dev/null Wed Apr 11 00:52:25 2001
+++ typeclass_missing_det_3.m Sun Apr 29 16:21:06 2001
@@ -0,0 +1,20 @@
+% test the case of a type class mode declaration without any determinism,
+% and with an instance declaration in the same module.
+
+:- module typeclass_missing_det_3.
+
+:- interface.
+
+:- implementation.
+
+:- import_module io.
+
+:- typeclass writeable(T) where [
+ pred write(T::in, io__state::di, io__state::uo)
+].
+
+:- instance writeable(int) where [
+ (write(V) -->
+ write_string("a"),
+ write_int(V))
+].
Index: ../tests/invalid/typeclass_missing_det_3.err_exp
===================================================================
RCS file: typeclass_missing_det_3.err_exp
diff -N typeclass_missing_det_3.err_exp
--- /dev/null Wed Apr 11 00:52:25 2001
+++ typeclass_missing_det_3.err_exp Sun Apr 29 16:28:24 2001
@@ -0,0 +1,4 @@
+typeclass_missing_det_3.m: 1: Warning: interface for module `typeclass_missing_det_3' does not export anything.
+typeclass_missing_det_3.m:013: Error: no determinism declaration for type class method
+typeclass_missing_det_3.m:013: predicate `typeclass_missing_det_3:write/3'.
+For more information, try recompiling with `-E'.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
| of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list