Files
mercury/tests/hard_coded/direct_arg_opt.m
Peter Wang 9f84fec4f5 Fix bug with direct-arg ctors and intermodule optimisation.
If the compiler decides that a du type should use the direct-arg
representation for some of its constructors, it must include information
about that into the .opt file of the module defining the type, in the
form of `where direct_arg is' clauses, which will be used by modules
opt-importing that module and that type. That information was not being
included for du types defined in the *interface* section of a module.

Also fix a related issue that was uncovered: a word_aligned_pointer
assertion on a foreign_type definition would have no effect if there is
a no-tag du type definition for the same type constructor.

compiler/intermod.m:
compler/intermod_decide.m:
    Make should_opt_export_type_defn and some_type_needs_to_be_written
    succeed for `status_exported' du type definitions with direct-arg
    constructors. While `status_exported' suggests those type
    definitions would be redundant in .opt files, the information about
    the direct-arg constructors is not redundant.

compiler/du_type_layout.m:
    Add a is_word_aligned_ptr() value to the ComponentTypeMap if a
    no-tag du type also has a foreign_type definition for the current
    target language with a word_aligned_pointer assertion. Previously,
    this was only being done for single ctor NON no-tag du types.

    Add a XXX mentioning that we silently ignore word_aligned_pointer
    assertions in other cases.

tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/hard_coded/direct_arg_opt.m:
tests/hard_coded/direct_arg_opt_helper_1.m:
tests/hard_coded/direct_arg_opt_helper_1.direct_arg_opt_helper_2.m:
tests/hard_coded/direct_arg_opt.exp:
    Add a test case.
2026-01-12 11:33:56 +11:00

40 lines
1.4 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
%
% With intermodule optimisation enabled, the body of indirect_new_object is
% inlined into main/2, including the construction:
%
% yes_object(Ob : test_object) : maybe_object
%
% Because the type `test_object' is opt-imported (but not imported) from
% direct_arg_opt_helper_1.direct_arg_opt_helper_2.m, the compiler depends on
% information from direct_arg_opt_helper_1.direct_arg_opt_helper_2.opt
% to state which constructors of maybe_object need to use the direct-arg
% representation.
%
% The problem was that that information was missing from the .opt file
% because maybe_object is defined in the interface section of its module,
% i.e. it was already exported.
%
:- module direct_arg_opt.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module direct_arg_opt_helper_1.
% The bug we are testing for only occurred if
% direct_arg_opt_helper_1.direct_arg_opt_helper_2 is NOT imported directly.
main(!IO) :-
indirect_new_object(Ob),
indirect_check_object(Ob, !IO).