[m-rev.] for review: improvements for foreign_type

Peter Ross pro at missioncriticalit.com
Fri Jun 28 22:17:51 AEST 2002


On Fri, Jun 28, 2002 at 06:30:46PM +1000, Simon Taylor wrote:
> 
> For review by Pete or Tyson.
> 
> Simon.
> 
> 
> Estimated hours taken: 10
> Branches: main
> 
> Improvements for `:- pragma foreign_type'.
> - Allow default Mercury definitions. The Mercury definition must define
>   a discriminated union type. The type is treated as abstract except
>   in predicates or functions which have implementations for all the
>   foreign languages the type has implementations for (the check for
>   this isn't quite right).

I found when the data constructors of a type difficult to understand,
maybe it would be better to reword in the positive sense. ie

The data constructors of the Mercury type are only visible in predicates
which ...., in all other predicates the type is treated as an abstract
type.

> - Allow polymorphic foreign types.
> - Don't require the `:- pragma foreign_type' for exported foreign types
>   to be in the interface. We now only require that all definitions
>   have the same visibility.
> 
> compiler/make_hlds.m:
> 	Handle Mercury definitions for foreign types.
> 
> 	Separate out the code to add constructors and special predicates
> 	to the HLDS into a separate pass. For foreign types, we don't know
> 	what to add until all type definitions have been seen.
> 
> 	Use the C definition for foreign types with `--target asm'.
> 
I haven't reviewed this changes to this file yet.

> compiler/typecheck.m:
> 	Check that a predicate or function has foreign clauses before
> 	allowing the use of a constructor of a type which also has 
> 	foreign definitions.
> 
> tests/hard_coded/Mmakefile:
> tests/hard_coded/foreign_type2.{m,exp}:
> tests/hard_coded/foreign_type.m:
> tests/invalid/Mmakefile:
> tests/invalid/foreign_type_2.{m,err_exp}:
> tests/invalid/foreign_type_visibility.{m,err_exp}:
> 	Test cases.
> 	Test cases.
> 
Duplicate line.

It took me a while to determine what foreign_type2 was testing.  A comment
that is testing mercury clauses defined as field access functions would
be useful.


> Index: compiler/error_util.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/error_util.m,v
> retrieving revision 1.18
> diff -u -u -r1.18 error_util.m
> --- compiler/error_util.m	20 Mar 2002 12:36:08 -0000	1.18
> +++ compiler/error_util.m	26 Jun 2002 09:40:46 -0000
> @@ -67,6 +67,10 @@
>  :- pred write_error_pieces(prog_context::in, int::in,
>  	list(format_component)::in, io__state::di, io__state::uo) is det.
>  
> +	% Display the given error message, but indent the first line.

I would explain here when this is useful.

> +:- pred write_error_pieces_not_first_line(prog_context::in, int::in,
> +	list(format_component)::in, io__state::di, io__state::uo) is det.
> +
>  :- pred write_error_pieces_maybe_with_context(maybe(prog_context)::in, int::in,
>  	list(format_component)::in, io__state::di, io__state::uo) is det.
>  
> Index: compiler/hlds_data.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/hlds_data.m,v
> retrieving revision 1.69
> diff -u -u -r1.69 hlds_data.m
> --- compiler/hlds_data.m	7 May 2002 11:02:44 -0000	1.69
> +++ compiler/hlds_data.m	24 Jun 2002 06:05:39 -0000
> @@ -259,9 +259,9 @@
>  
>  :- type hlds_type_defn.
>  
> -:- pred hlds_data__set_type_defn(tvarset, list(type_param),
> -	hlds_type_body, import_status, prog_context, hlds_type_defn).
> -:- mode hlds_data__set_type_defn(in, in, in, in, in, out) is det.
> +:- pred hlds_data__set_type_defn(tvarset, list(type_param), hlds_type_body,
> +	import_status, need_qualifier, prog_context, hlds_type_defn).
> +:- mode hlds_data__set_type_defn(in, in, in, in, in, in, out) is det.
>  
>  :- pred hlds_data__get_type_defn_tvarset(hlds_type_defn, tvarset).
>  :- mode hlds_data__get_type_defn_tvarset(in, out) is det.
> @@ -275,6 +275,10 @@
>  :- pred hlds_data__get_type_defn_status(hlds_type_defn, import_status).
>  :- mode hlds_data__get_type_defn_status(in, out) is det.
>  
> +:- pred hlds_data__get_type_defn_need_qualifier(hlds_type_defn,
> +		need_qualifier).
> +:- mode hlds_data__get_type_defn_need_qualifier(in, out) is det.
> +
>  :- pred hlds_data__get_type_defn_context(hlds_type_defn, prog_context).
>  :- mode hlds_data__get_type_defn_context(in, out) is det.
>  

This need_qualifier change doesn't appear to be mention in the log message.

> Index: compiler/prog_data.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/prog_data.m,v
> retrieving revision 1.83
> diff -u -u -r1.83 prog_data.m
> --- compiler/prog_data.m	7 May 2002 11:03:11 -0000	1.83
> +++ compiler/prog_data.m	23 Jun 2002 16:13:12 -0000
> @@ -172,8 +172,9 @@
>  			% PredName, Predicate or Function, Vars/Mode, 
>  			% VarNames, Foreign Code Implementation Info
>  
> -	;	foreign_type(foreign_language_type, (type), sym_name)
> -			% ForeignType, MercuryType, MercuryTypeName
> +	;	foreign_type(foreign_language_type, tvarset,
> +			sym_name, list(type_param))
> +			% ForeignType, TVarSet, MercuryType, MercuryTypeName
>  
This comment looks out of date.

>  	;	foreign_import_module(foreign_language, module_name)
>  			% Equivalent to
> Index: doc/reference_manual.texi
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/doc/reference_manual.texi,v
> retrieving revision 1.249
> diff -u -u -r1.249 reference_manual.texi
> --- doc/reference_manual.texi	30 May 2002 08:00:15 -0000	1.249
> +++ doc/reference_manual.texi	28 Jun 2002 08:10:52 -0000
> @@ -5221,12 +5218,18 @@
>  @var{MercuryTypeName} is treated as an abstract type at all times in
>  Mercury code.
>  However, if @var{MercuryTypeName} is one of the parameters of a
> -foreign_proc for @var{Lang}, it will be passed to that foreign_proc as
> +foreign_proc for @var{Lang}, and the @samp{pragma foreign_type} declaration
> +is visible to the foreign_proc, it will be passed to that foreign_proc as
>  specified by @var{ForeignTypeDescriptor}.
>  
>  Multiple foreign language definitions may be given for the same type ---
>  the appropriate definition will be used for the appropriate language (see the
> -language specific information below for details).
> +language specific information below for details).  All definitions
> +must have the same visibility.  A Mercury definition, which must define
> +a discriminated union type, may also be given.  The constructors for the
> +type will only be visible in clauses for for predicates or functions with
> + at samp{pragma foreign_proc} clauses for all of the languages for which there
> +are @samp{foreign_type} declarations for the type. 
>  
s/for for/for/

s/visible in clauses/visible in Mercury clauses/
emphasises more that we are talking about Mercury clauses, not clauses defined
by a foreign proc.

>  You can use Mercury foreign language interfacing declarations           
>  which specify language @var{X} to interface to types that are actually
--------------------------------------------------------------------------
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