[m-rev.] for post-commit review: make zm_eq20.m compile in 2.5s (hlc.gc)

Mark Brown mark at csse.unimelb.edu.au
Mon Sep 21 15:16:41 AEST 2009


On 16-Sep-2009, Zoltan Somogyi <zs at csse.unimelb.edu.au> wrote:
> For review by anyone, but I would especially like Mark to review
> restrict_rtti_varmaps in hlds_rtti.m.

...

> Index: compiler/hlds_rtti.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/compiler/hlds_rtti.m,v
> retrieving revision 1.17
> diff -u -b -r1.17 hlds_rtti.m
> --- compiler/hlds_rtti.m	3 Sep 2009 23:07:27 -0000	1.17
> +++ compiler/hlds_rtti.m	16 Sep 2009 02:02:53 -0000
> @@ -439,47 +445,133 @@
>      map.init(TypeMap),
>      map.init(ConstraintMap).
>  
> -rtti_varmaps_no_tvars(VarMaps) :-
> -    map.is_empty(VarMaps ^ ti_varmap).
> +restrict_rtti_varmaps(VarUses, !RttiVarMaps) :-
> +    % This code makes the assumption that if a type_ctor_info, type_info,
> +    % base_typeclass_info or typeclass_info variable is not needed, then
> +    % any code that refers to the constraints reachable from those variables
> +    % has also been removed from the procedure. (This would happen by being
> +    % moved to a procedure of its own by lambda.m.)
> +    !.RttiVarMaps = rtti_varmaps(TCIMap0, TIMap0, TypeMap0, ConstraintMap0),
> +
> +    map.to_assoc_list(TIMap0, TIList0),
> +    filter_type_info_varmap(TIList0, [], RevTIList, VarUses),
> +    list.reverse(RevTIList, TIList),
> +    map.from_sorted_assoc_list(TIList, TIMap),

You can use map.from_rev_sorted_assoc_list here, and below.

> +
> +    map.to_assoc_list(TypeMap0, TypeList0),
> +    filter_type_info_map(TypeList0, [], RevTypeList, VarUses),
> +    list.reverse(RevTypeList, TypeList),
> +    map.from_sorted_assoc_list(TypeList, TypeMap),
> +
> +    map.to_assoc_list(ConstraintMap0, ConstraintList0),
> +    filter_constraint_map(ConstraintList0, [], RevConstraintList,
> +        TCIMap0, TCIMap, VarUses),
> +    list.reverse(RevConstraintList, ConstraintList),
> +    map.from_sorted_assoc_list(ConstraintList, ConstraintMap),
> +
> +    !:RttiVarMaps = rtti_varmaps(TCIMap, TIMap, TypeMap, ConstraintMap).
> +
> +:- pred filter_type_info_varmap(assoc_list(tvar, type_info_locn)::in,
> +    assoc_list(tvar, type_info_locn)::in,
> +    assoc_list(tvar, type_info_locn)::out,
> +    array(bool)::in) is det.
> +
> +filter_type_info_varmap([], !RevTVarLocns, _VarUses).
> +filter_type_info_varmap([TVarLocn | TVarLocns], !RevTVarLocns, VarUses) :-
> +    TVarLocn = _TVar - Locn,
> +    ( Locn = type_info(Var)
> +    ; Locn = typeclass_info(Var, _)
> +    ),
> +    VarNum = var_to_int(Var),
> +    array.unsafe_lookup(VarUses, VarNum, Used),
> +    (
> +        Used = yes,
> +        !:RevTVarLocns = [TVarLocn | !.RevTVarLocns]
> +    ;
> +        Used = no
> +    ),
> +    filter_type_info_varmap(TVarLocns, !RevTVarLocns, VarUses).
> +
> +:- pred filter_type_info_map(assoc_list(prog_var, mer_type)::in,
> +    assoc_list(prog_var, mer_type)::in, assoc_list(prog_var, mer_type)::out,
> +    array(bool)::in) is det.
> +
> +filter_type_info_map([], !RevVarTypes, _VarUses).
> +filter_type_info_map([VarType | VarTypes], !RevVarTypes, VarUses) :-
> +    VarType = Var - _Type,
> +    VarNum = var_to_int(Var),
> +    array.unsafe_lookup(VarUses, VarNum, Used),
> +    (
> +        Used = yes,
> +        !:RevVarTypes = [VarType | !.RevVarTypes]
> +    ;
> +        Used = no
> +    ),
> +    filter_type_info_map(VarTypes, !RevVarTypes, VarUses).
> +
> +:- pred filter_constraint_map(assoc_list(prog_var, prog_constraint)::in,
> +    assoc_list(prog_var, prog_constraint)::in,
> +    assoc_list(prog_var, prog_constraint)::out,
> +    typeclass_info_varmap::in, typeclass_info_varmap::out,
> +    array(bool)::in) is det.
> +
> +filter_constraint_map([], !RevVarConstraints, !TCIMap, _VarUses).
> +filter_constraint_map([VarConstraint | VarConstraints], !RevVarConstraints,
> +        !TCIMap, VarUses) :-
> +    VarConstraint = Var - Constraint,
> +    VarNum = var_to_int(Var),
> +    array.unsafe_lookup(VarUses, VarNum, Used),
> +    (
> +        Used = yes,
> +        !:RevVarConstraints = [VarConstraint | !.RevVarConstraints]
> +    ;
> +        Used = no,
> +        map.delete(!.TCIMap, Constraint, !:TCIMap)

This seems the hard way to do it.  Why not filter this map via an assoc_list
as is done with the others?  In the worst case behaviour that we had, this
map would have been quite small and it would be better to filter it directly
rather than delete lots of keys that mostly won't be there.

Cheers,
Mark.

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