[m-rev.] for review: fix testing of `ground' matches `bound'

David Overton dmo at cs.mu.OZ.AU
Mon Jul 14 16:26:24 AEST 2003


On Tue, Jul 08, 2003 at 04:46:30PM +1000, Fergus Henderson wrote:
> On 08-Jul-2003, David Overton <dmo at cs.mu.OZ.AU> wrote:
> > compiler/modules.m:
> > 	When writing discriminated union types to the .int2 file, write
> > 	out the full type definition rather than an abstract type
> > 	declaration.
> 
> Won't that cause problems for types with user-defined equality or
> comparison procedures?  The .int2 file would then contain a reference
> to a procedure which had not been declared.

What is the best way to handle this?  Should I just ensure that the
user-defined equality/comparison annotation does not appear on the type?

> 
> > +++ compiler/type_util.m	8 Jul 2003 01:43:51 -0000
> > @@ -1851,14 +1851,8 @@
> >  
> >  maybe_get_cons_id_arg_types(ModuleInfo, MaybeType, ConsId0, Arity, MaybeTypes)
> >  		:-
> > -	( ConsId0 = cons(SymName, _) ->
> > -		( SymName = qualified(_, Name) ->
> > -			% get_cons_id_non_existential_arg_types
> > -			% expects an unqualified cons_id.
> > -			ConsId = cons(unqualified(Name), Arity)
> > -		;
> > -			ConsId = ConsId0
> > -		),
> > +	( ConsId0 = cons(_SymName, _) ->
> > +		ConsId = ConsId0,
> 
> This change violates the documentation for
> get_cons_id_non_existential_arg_types, which says that
> that procedure expects an unqualified cons_id.
> If that documentation is wrong, it should be changed.

The documentation appears to be wrong.  I've removed those comments.

> 
> > Index: tests/invalid/undef_symbol.err_exp
> ...
> > -undef_symbol.m:025: In clause for predicate `undef_symbol.q/2':
> > -undef_symbol.m:025:   error: undefined symbol `term.context/2'
> > -undef_symbol.m:025:   (the module `term' has not been imported).
> >  For more information, try recompiling with `-E'.
> 
> I agree with Simon's review comment.
> Failing to report that error would be a bug.

Done.  See interdiff below.


diff -u compiler/type_util.m compiler/type_util.m
--- compiler/type_util.m	8 Jul 2003 01:43:51 -0000
+++ compiler/type_util.m	14 Jul 2003 03:08:37 -0000
@@ -230,7 +230,6 @@
 	% Work out the types of the arguments of a functor,
 	% given the cons_id and type of the functor.
 	% Aborts if the functor is existentially typed.
-	% The cons_id is expected to be un-module-qualified.
 	% Note that this will substitute appropriate values for
 	% any type variables in the functor's argument types,
 	% to match their bindings in the functor's type.
@@ -240,7 +239,6 @@
 	% The same as type_util__get_cons_id_arg_types except that it
 	% fails rather than aborting if the functor is existentially
 	% typed.
-	% The cons_id is expected to be un-module-qualified.
 :- pred type_util__get_cons_id_non_existential_arg_types(module_info::in,
 		(type)::in, cons_id::in, list(type)::out) is semidet.
 
reverted:
--- tests/invalid/undef_symbol.err_exp	7 Jul 2003 23:56:15 -0000
+++ tests/invalid/undef_symbol.err_exp	17 Jan 2003 05:57:10 -0000	1.3
@@ -3,4 +3,7 @@
 undef_symbol.m:019: In clause for predicate `undef_symbol.p/2':
 undef_symbol.m:019:   error: undefined predicate `string.append/3'
 undef_symbol.m:019:   (the module `string' has not been imported).
+undef_symbol.m:025: In clause for predicate `undef_symbol.q/2':
+undef_symbol.m:025:   error: undefined symbol `term.context/2'
+undef_symbol.m:025:   (the module `term' has not been imported).
 For more information, try recompiling with `-E'.
only in patch2:
--- compiler/typecheck.m	29 May 2003 18:17:15 -0000	1.340
+++ compiler/typecheck.m	14 Jul 2003 06:19:15 -0000
@@ -3301,6 +3301,7 @@
 
 :- type cons_error
 	--->	foreign_type_constructor(type_ctor, hlds_type_defn)
+	;	abstract_imported_type
 	;	invalid_field_update(ctor_field_name, hlds_ctor_field_defn,
 			tvarset, list(tvar)).
 
@@ -4865,11 +4866,11 @@
 	% if there are no foreign clauses. Errors will be caught when creating
 	% the `.opt' file.
 	%
+	typecheck_info_get_predid(TypeCheckInfo, PredId),
+	typecheck_info_get_module_info(TypeCheckInfo, ModuleInfo),
+	module_info_pred_info(ModuleInfo, PredId, PredInfo),
 	(
 		Body ^ du_type_is_foreign_type = yes(_),
-		typecheck_info_get_predid(TypeCheckInfo, PredId),
-		typecheck_info_get_module_info(TypeCheckInfo, ModuleInfo),
-		module_info_pred_info(ModuleInfo, PredId, PredInfo),
 		\+ pred_info_get_goal_type(PredInfo, clauses_and_pragmas),
 		\+ is_unify_or_compare_pred(PredInfo),
 		\+ pred_info_import_status(PredInfo, opt_imported)
@@ -4877,6 +4878,14 @@
 		ConsTypeInfo = error(foreign_type_constructor(TypeCtor,
 				TypeDefn))
 	;
+		% Do not allow constructors for abstract_imported types unless
+		% the current predicate is opt_imported.
+		hlds_data__get_type_defn_status(TypeDefn, abstract_imported),
+		\+ is_unify_or_compare_pred(PredInfo),
+		\+ pred_info_import_status(PredInfo, opt_imported)
+	->
+		ConsTypeInfo = error(abstract_imported_type)
+	;
 		construct_type(TypeCtor, ConsTypeParams, ConsType),
 		UnivConstraints = [],
 		Constraints = constraints(UnivConstraints, ExistConstraints),
@@ -6402,6 +6411,11 @@
 		words("for those foreign types.")] },
 	error_util__write_error_pieces_not_first_line(Context,
 		0, ErrorPieces).
+
+report_cons_error(_, abstract_imported_type) --> [].
+		% For `abstract_imported_type' errors, the "undefined symbol"
+		% error written by `report_error_undef_cons' is sufficient so
+		% we do not print an additional error message here.
 
 report_cons_error(_,
 		invalid_field_update(FieldName, FieldDefn, TVarSet, TVars)) -->
only in patch2:
--- compiler/make_hlds.m	27 May 2003 05:57:13 -0000	1.442
+++ compiler/make_hlds.m	14 Jul 2003 03:08:24 -0000
@@ -2233,7 +2233,18 @@
 	{ module_info_types(Module0, Types0) },
 	{ list__length(Args, Arity) },
 	{ TypeCtor = Name - Arity },
-	{ Body = abstract_type ->
+	{
+		(
+			Body = abstract_type
+		;
+			Body = du_type(_, _, _, _, _, _),
+			string__suffix(term__context_file(Context), ".int2")
+			% If the type definition comes from a .int2 file then
+			% we need to treat it as abstract.  The constructors
+			% may only be used by the mode system for comparing
+			% `bound' insts to `ground'.
+		)
+	->
 		make_status_abstract(Status0, Status1)
 	;
 		Status1 = Status0


-- 
David Overton                  Uni of Melbourne     +61 3 8344 1354
dmo at cs.mu.oz.au                Monash Uni (Clayton) +61 3 9905 5779
http://www.cs.mu.oz.au/~dmo    Mobile Phone         +61 4 0337 4393
--------------------------------------------------------------------------
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