[m-rev.] for review: typeclass support in Erlang backend

Peter Ross pro at missioncriticalit.com
Mon May 28 12:01:15 AEST 2007


On Thu, May 24, 2007 at 11:20:20AM +1000, Peter Wang wrote:
> Estimated hours taken: 30
> Branches: main
> 
> Add initial support for typeclasses in the Erlang backend.
> 
> Fix some bugs in the Erlang backend.  Most of these are related to the
> optimisation that does away with unused and dummy arguments.  We cannot drop
> those arguments for higher order functions, and we must materialise any
> references to dummy arguments if they appear for some reason, e.g. in
> contexts where they can't be dropped.
> 
> compiler/elds.m:
> 	Extend the ELDS for Erlang functions that, when called, return
> 	structures containing RTTI data.
> 
> 	Collapse the representations of plain calls, higher order calls and
> 	calls to builtins so they share a single function symbol.
> 
> 	Add references to RTTI data as a new type of ELDS expression.
> 
> 	Simplify the implementation of join_exprs, whic also works better if
> 	one of the expressions to be joined could be an empty elds_block.
> 
> 	Add some more helper predicates.
> 
> compiler/elds_to_erlang.m:
> 	Generate to code of standard modules to mercury__<module>.erl files,
> 	rather than <module>.erl.
> 
> 	Output RTTI function definitions and export them to other modules.
> 
> 	Fix a bug where opt_imported predicates were being qualified with their
> 	declaring module, even though the code was being generated in the
> 	current module.
> 
> 	Quote more atoms which are spelt the same as Erlang keywords.
> 
> 	Conform to other changes in the ELDS.
> 
> compiler/erl_call_gen.m:
> 	Generate code for class method calls.
> 
> 	Materialise variables of dummy types if they appear in the argument
> 	lists of calls.
> 
> 	Fix bugs in which arguments of dummy types were being dropped from
> 	the argument lists of higher order procedure calls.
> 
> 	Refactor some code which was duplicated between plain calls, higher
> 	order calls and class method calls.
> 
> compiler/erl_code_gen.m:
> 	Fix some cases where references to unbound variables would show up
> 	after `erroneous' goals.
> 
> 	Generate code for promise_purity and barrier scopes goals.
> 
> compiler/erl_code_util.m:
> 	Add a parameter to erl_gen_arg_list to control whether dummy and
> 	unused arguments should be discarded when dividing call arguments
> 	into inputs and outputs.
> 
> 	Add erl_gen_arg_list_arg_modes which can be used instead of
> 	erl_gen_arg_list_arg_modes when only arg_modes are available
> 	(instead of modes).
> 
> 	Add erl_base_typeclass_info_method_offset which returns the offset
> 	into the typeclass_info tuple of the first typeclass method.
> 
> 	Conform to changes in the ELDS.
> 
> compiler/erl_rtti.m:
> 	New module to generate ELDS functions that return RTTI data structures.
> 	Currently we only generate functions for base_typeclass_infos.
> 
> compiler/erl_backend.m:
> 	Include erl_rtti.
> 
> compiler/erl_unify_gen.m:
> 	Ignore assignment unifications between variables of dummy types.
> 
> 	Handle construction of partially instantiated data structures
> 	by assigning free variables to `false' before the construction.
> 
> 	Handle construction of type ctor infos (incomplete due to missing
> 	RTTI function definitions), base typeclass infos and type infos and
> 	typeclass infos.
> 
> 	Handle dummy arguments properly when creating higher order terms.
> 
> compiler/instmap.m:
> 	Fix an assumption in `var_is_bound_in_instmap_delta' that the instmap
> 	and instmap_delta that it is passed are reachable.  It used to succeed
> 	for unreachable instmaps (deltas) implying that the variable was bound.
> 	In some cases this resulted in Erlang code not binding some variables
> 	that it should have when `erroneous' code was reached.
> 
> 	The only other user of `var_is_bound_in_instmap_delta' is the dependent
> 	parallel conjunction transformation.  Currently `erroneous' goals are
> 	not allowed in parallel conjunctions anyway.
> 
> compiler/mercury_compile.m:
> 	Call the code to generate ELDS function definitions for RTTI data.
> 
> compiler/notes/compiler_design.html:
> 	Mention erl_rtti.m.
> 
> 	s/mlds_to_rtti/rtti_to_mlds/ in a spot.
> 
> 

> Index: compiler/erl_code_util.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/compiler/erl_code_util.m,v
> retrieving revision 1.3
> diff -u -r1.3 erl_code_util.m
> --- compiler/erl_code_util.m	18 May 2007 06:04:23 -0000	1.3
> +++ compiler/erl_code_util.m	24 May 2007 01:04:30 -0000
> @@ -531,6 +565,26 @@
>  
>  %-----------------------------------------------------------------------------%
>  
> +    % This function returns the offset to add to the method number
> +    % for a type class method to get its field number within the
> +    % base_typeclass_info.
> +    %   field 0 is num_extra
> +    %   field 1 is num_constraints
> +    %   field 2 is num_superclasses
> +    %   field 3 is class_arity
> +    %   field 4 is num_methods
> +    %   field 5 is the 1st method
> +    %   field 6 is the 2nd method
> +    %   etc.
> +    %   (See the base_typeclass_info type in rtti.m or the
> +    %   description in notes/type_class_transformation.html for
> +    %   more information about the layout of base_typeclass_infos.)
> +    % Hence the offset is 4.
> +    %
> +erl_base_typeclass_info_method_offset = 4.
> +
Do you need to add a pointer to this code anywhere, so people don't
forget to change this magic number?


Otherwise looks fine.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list