[m-dev.] for review: allow clauses in instance declarations

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Sep 8 17:08:37 AEDT 2000


> Allow typeclass instance declarations to contain clauses, as an
> alternative to the current `pred(<MethodName>) is <ImplName>)' syntax.
> This avoids the need for the user to explicitly define names for
> procedures that just implement type class methods.
> 
> XXX Note that currently we only permit one clause per method.

I forgot to include one of the files that I had changed in the diff.
Here it is.

----------

compiler/intermod.m:
	Add code to handle typeclass instances defined using the new syntax.
	For now we just don't do intermodule optimization of such instances.

Workspace: /home/pgrad/fjh/ws/hg
Index: compiler/intermod.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/intermod.m,v
retrieving revision 1.81
diff -u -d -r1.81 intermod.m
--- compiler/intermod.m	2000/08/09 07:46:46	1.81
+++ compiler/intermod.m	2000/09/06 09:06:42
@@ -512,6 +512,19 @@
 		intermod_info::in, intermod_info::out) is det.
 
 intermod__add_proc(PredId, DoWrite) -->
+	( { invalid_pred_id(PredId) } ->
+		% This will happen for type class instance methods
+		% defined using the clause syntax.  Currently we
+		% can't handle intermodule-optimization of those.
+		{ DoWrite = no }
+	;
+		intermod__add_proc_2(PredId, DoWrite)
+	).
+
+:- pred intermod__add_proc_2(pred_id::in, bool::out,
+		intermod_info::in, intermod_info::out) is det.
+
+intermod__add_proc_2(PredId, DoWrite) -->
 	intermod_info_get_module_info(ModuleInfo),
 	{ module_info_pred_info(ModuleInfo, PredId, PredInfo) },
 	{ pred_info_import_status(PredInfo, Status) },
@@ -907,8 +920,9 @@
 	pred_info_arg_types(MethodCallPredInfo, MethodCallTVarSet, _,
 		MethodCallArgTypes),
 	InstanceMethod0 = instance_method(PredOrFunc, MethodName,
-			InstanceMethodName0, MethodArity, MethodContext),
+			InstanceMethodDefn0, MethodArity, MethodContext),
 	(
+		InstanceMethodDefn0 = name(InstanceMethodName0),
 		PredOrFunc = function,
 		module_info_get_predicate_table(ModuleInfo, PredicateTable),
 		(
@@ -928,15 +942,31 @@
 			    "intermod__qualify_instance_method: undefined ",
 			    MethodStr, Msg),
 			error(Msg)
-		)
+		),
+		InstanceMethodDefn = name(InstanceMethodName)
 	;
+		InstanceMethodDefn0 = name(InstanceMethodName0),
 		PredOrFunc = predicate,
 		typecheck__resolve_pred_overloading(ModuleInfo,
 			MethodCallArgTypes, MethodCallTVarSet,
-			InstanceMethodName0, InstanceMethodName, PredId)
+			InstanceMethodName0, InstanceMethodName, PredId),
+		InstanceMethodDefn = name(InstanceMethodName)
+	;
+		InstanceMethodDefn0 = clauses(_ItemList),
+		%
+		% XXX for methods defined using this syntax
+		% it is a little tricky to write out the .opt files,
+		% so for now I've just disabled intermodule optimization
+		% for type class instance declarations using the new
+		% syntax.
+		%
+		% This will force intermod__add_proc to return DoWrite = no
+		invalid_pred_id(PredId),
+		% We can just leave the method definition unchanged
+		InstanceMethodDefn = InstanceMethodDefn0
 	),
 	InstanceMethod = instance_method(PredOrFunc, MethodName,
-			InstanceMethodName, MethodArity, MethodContext).
+			InstanceMethodDefn, MethodArity, MethodContext).
 
 %-----------------------------------------------------------------------------%
 

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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