[m-rev.] for review: grade independent .mh files (bug #52)

Peter Wang novalazy at gmail.com
Thu Mar 27 15:58:33 AEDT 2008


On 2008-03-27, Julien Fischer <juliensf at csse.unimelb.edu.au> wrote:
>
> On Thu, 27 Mar 2008, Julien Fischer wrote:
>
>> For review by anyone.
>>
>> Estimated hours taken: 2
>> Branches: main
>>
>> Make the .mh files grade independent again.  They were not grade independent
>> because the types of the globals used to implement mutables can differ 
>> between
>> the high- and low-level C backends.  The fix is to output declarations for
>> both backends in .mh files and select between them using #ifdef 
>> MR_HIGHLEVEL_CODE.
>>
>> compiler/make_hlds_passes.m:
>> 	Write out #ifdef protected declarations for the globals used to
>> 	implement mutables that are appropriate for both C backends.
>>
>> 	Separate out the code for generating the mutable declarations and
>> 	definitions.  While there is some common structure the above change
>> 	makes it quite hard to follow if they are combined.  In this case
>> 	separating them is the lesser of two evils.
>>
>> compiler/handle_options.m:
>> 	Add a comment mentioning that if the value of the
>> 	mutable_always_boxed option is changed then the code in
>> 	make_hlds_passes that processes mutable declarations will need to be
>> 	updated.
>
> The original diff was broken in several places; here is the correct one.
>

> Index: make_hlds_passes.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/compiler/make_hlds_passes.m,v
> retrieving revision 1.77
> diff -u -r1.77 make_hlds_passes.m
> --- make_hlds_passes.m	15 Feb 2008 08:31:58 -0000	1.77
> +++ make_hlds_passes.m	27 Mar 2008 04:35:02 -0000
...
> @@ -1668,23 +1671,34 @@
>      % The bool argument says whether the mutable is a constant mutable
>      % or not.
>      %
> -:- pred get_c_mutable_global_foreign_decl_defn(module_info::in, mer_type::in,
> +:- pred get_c_mutable_global_foreign_decl(module_info::in, mer_type::in,
>      string::in, bool::in, mutable_thread_local::in, prog_context::in,
> -    item::out, item::out) is det.
> +    item::out) is det.
>
> -get_c_mutable_global_foreign_decl_defn(ModuleInfo, Type, TargetMutableName,
> -        IsConstant, IsThreadLocal, Context, DeclItem, DefnItem) :-
> -    module_info_get_globals(ModuleInfo, Globals),
> -    globals.lookup_bool_option(Globals, mutable_always_boxed, AlwaysBoxed),
> +get_c_mutable_global_foreign_decl(ModuleInfo, Type, TargetMutableName,
> +        IsConstant, IsThreadLocal, Context, DeclItem) :-
> +    % This declaration will be included in the .mh files.  Since these are
> +    % grade independent we need to output both the high- and low-level C
> +    % declarations for the global used to implement the mutable and make
> +    % the choice conditional on whether MR_HIGHLEVEL_CODE is defined.
> +    %

s/independent/dependent

>      (
>          IsThreadLocal = mutable_not_thread_local,
> -        TypeName = global_foreign_type_name(AlwaysBoxed, lang_c,
> -            ModuleInfo, Type)
> +        % The first argument in the following calls to
> +        % global_foreign_type_name says whether the mutable should always be
> +        % boxed or not.  The only difference between the high- and low-level
> +        % C backends is that in the latter mutables are *always* boxed,
> +        % whereas in the former they may not be.
> +        HighLevelTypeName = global_foreign_type_name(no, lang_c, ModuleInfo,
> +            Type),
> +        LowLevelTypeName = global_foreign_type_name(yes, lang_c, ModuleInfo,
> +            Type)
>      ;
>          IsThreadLocal = mutable_thread_local,
>          % For thread-local mutables, the variable holds an index into an
>          % array.
> -        TypeName = "MR_Unsigned"
> +        HighLevelTypeName = "MR_Unsigned",
> +        LowLevelTypeName  = "MR_Unsigned"
>      ),
>
>      % Constant mutables do not require mutexes as their values are never

Looks fine.

Peter

--------------------------------------------------------------------------
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