diff --git a/compiler/builtin_lib_types.m b/compiler/builtin_lib_types.m index c68678f37..96cd42af9 100644 --- a/compiler/builtin_lib_types.m +++ b/compiler/builtin_lib_types.m @@ -75,9 +75,11 @@ % :- pred type_is_type_info_or_ctor_type(mer_type::in) is semidet. - % Check whether a type is the `typeclass_info' type. + % Check whether a type is represents either a type_info or typeclass_info, + % or their type_ctor_info and base_typeclass_info components. + % These are the types of the variables that can occur in rtti_varmaps. % -:- pred type_is_typeclass_info_type(mer_type::in) is semidet. +:- pred type_is_rtti_relevant_type(mer_type::in) is semidet. %---------------------------------------------------------------------------% % @@ -297,17 +299,29 @@ build_type_info_type(Type) = TypeInfoType :- %---------------------% -type_is_type_info_or_ctor_type(TypeInfoType) :- - type_to_ctor_and_args(TypeInfoType, TypeCtor, []), +type_is_type_info_or_ctor_type(Type) :- + type_to_ctor_and_args(Type, TypeCtor, []), TypeCtor = type_ctor(qualified(ModuleName, TypeName), 0), - ModuleName = mercury_private_builtin_module, ( TypeName = "type_info" ; TypeName = "type_ctor_info" - ). + ), + ModuleName = mercury_private_builtin_module. -type_is_typeclass_info_type(TypeClassInfoType) :- - type_to_ctor_and_args(TypeClassInfoType, TypeCtor, []), - TypeCtor = type_ctor(qualified(ModuleName, "typeclass_info"), 0), +type_is_rtti_relevant_type(Type) :- + type_to_ctor_and_args(Type, TypeCtor, []), + TypeCtor = type_ctor(qualified(ModuleName, TypeName), 0), + % NOTE polymorphism_type_class_info.m actually creates + % base_typeclass_info variables with their types being + % "typeclass_info", NOT "base_typeclass_info". However, other parts + % of the compiler do look out for them under the type name + % "base_typeclass_info", probably because this used to be true + % in the past. Including that name in the test here is preparing + % for a possible return to that state of affairs. + ( TypeName = "type_info" + ; TypeName = "type_ctor_info" + ; TypeName = "typeclass_info" + ; TypeName = "base_typeclass_info" + ), ModuleName = mercury_private_builtin_module. %---------------------------------------------------------------------------% diff --git a/compiler/float_regs.m b/compiler/float_regs.m index 9829dc83e..3a8314c3e 100644 --- a/compiler/float_regs.m +++ b/compiler/float_regs.m @@ -1259,11 +1259,7 @@ insert_reg_wrappers_method_call(ClassId, MethodProcNum, Vars0, Vars, take_non_rtti_types_from_tail([], []). take_non_rtti_types_from_tail([Type | Types0], Types) :- take_non_rtti_types_from_tail(Types0, TypesTail), - ( if - ( type_is_typeclass_info_type(Type) - ; type_is_type_info_or_ctor_type(Type) - ) - then + ( if type_is_rtti_relevant_type(Type) then Types = TypesTail else Types = [Type | TypesTail] diff --git a/compiler/saved_vars.m b/compiler/saved_vars.m index da4bcd48b..572f34418 100644 --- a/compiler/saved_vars.m +++ b/compiler/saved_vars.m @@ -222,7 +222,7 @@ saved_vars_in_conj([Goal0 | Goals0], Goals, NonLocals, !SlotInfo) :- ok_to_duplicate(Feature) = yes ) ), - slot_info_ok_to_duplicate_var(!.SlotInfo, Var), + slot_info_ok_to_duplicate_var(!.SlotInfo, Var) = yes, skip_constant_constructs(Goals0, Constants, OtherGoals), OtherGoals = [First | _Rest], can_push(Var, First) = yes @@ -666,17 +666,24 @@ saved_vars_rename_var(Var, NewVar, Substitution, !SlotInfo) :- % it is possible that liveness.m will want to refer to the rtti_varmaps % to calculate which type_infos are live (see the comments at the top % of liveness.m). If we duplicated any type_info variables here, - % then this could cause problems because the rtti_varmaps would not + % then this could cause problems, because the rtti_varmaps would not % be able to be kept consistent. Therefore we don't allow type_infos - % to be duplicated when TypeInfoLiveness is set. + % to be duplicated when TypeInfoLiveness is set. The same reasoning + % applies to typeclass_info types. % -:- pred slot_info_ok_to_duplicate_var(slot_info::in, prog_var::in) is semidet. +:- func slot_info_ok_to_duplicate_var(slot_info, prog_var) = bool. -slot_info_ok_to_duplicate_var(SlotInfo, Var) :- +slot_info_ok_to_duplicate_var(SlotInfo, Var) = OkToDuplicate :- SlotInfo = slot_info(VarTable, _, TypeInfoLiveness), - TypeInfoLiveness = yes, lookup_var_type(VarTable, Var, Type), - not type_is_type_info_or_ctor_type(Type). + ( if + TypeInfoLiveness = yes, + type_is_rtti_relevant_type(Type) + then + OkToDuplicate = no + else + OkToDuplicate = yes + ). %-----------------------------------------------------------------------------% :- end_module ll_backend.saved_vars.