mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-14 05:12:33 +00:00
The ultimate purpose of this diff is to prepare for future improvements
in type representations, allowing values of some data types to be represented
more compactly than up to now.
The main way this diff does that is by creating a separate pass for deciding
how values of each type should be represented. We have traditionally decided
data representations for each type as its type definition was processed
during the make_hlds pass, but these decisions were always tentative,
and could be overridden later, e.g. when we processed foreign_type or
foreign_enum pragmas for the type. This dispersed decision making algorithm
is hard to understand, and therefore to change.
This diff centralizes decisions about type representations in a separate
pass that does nothing else. It leaves the algorithm distributed among
several files (du_type_layout.m, make_tags.m, and add_foreign_enum.m) for now,
to make reviewing this diff easier, but soon after it is committed I intend
to move all the relevant code to du_type_layout.m, to centralize the decision
code in "space" as well as in time.
For the reason why this pass runs before any of the semantic analysis
passes, instead of after all of them as I originally intended and as we
discussed on m-dev in late october 2017, see the big comment at the start of
du_type_layout.m.
As per another part of that same discussion on m-dev, this diff
makes a start on implementing a new type of item, the type_repn item,
which is intended *only* to be used in compiler-generated interface files,
*not* in source files. It is only a start because we can use these items
only *after* the creation of a separate type representation decision pass,
and this diff is already very big. The code for making the compiler understand
these items will be added later. The code for generating them will be added
later still, once the code for understanding them has been installed on
all our systems.
Since I was going to be working on the affected code anyway, this diff
also carries out two other decisions that came out of that discussion:
- the deletion of the ability to reserve a tag in a type for HAL,
either via a compiler option or via a pragma, and
- the deletion of the ability to represent a functor using the address
of a statically allocated object (which we haven't used and won't use,
because it slows down accesses to *all the other functors* of the type).
compiler/mercury_compile_front_end.m:
Invoke the new pass for making decisions about type representations
after the make_hlds pass. (We used to do only the final part of it then.)
Fix a bad dump stage name.
Add an extra check for what it means for a module to be error free.
Make a sub-switch explicit.
compiler/hlds.m:
compiler/make_hlds.m:
Move the modules that implement the new pass from the make_hlds package
to the hlds package, to give the compiler's top level access to them.
Make the same move for the modules that the new pass's modules need.
Since they are now part of hlds, they cannot reach into make_hlds,
and I think this is a cleaner solution than forwarding predicates.
Delete some forwarding predicates that are no longer needed.
compiler/notes/compiler_design.html:
Document the updated location of the moved modules.
Add an XXX to note a place where the documentation has not been
updated in the past.
compiler/du_type_layout.m:
Add code to implement the new pass.
Keep the algorithm for deciding type representations as close
to the previously used algorithm as possible, since this diff
is already big enough. (The previous algorithm was scattered across
add_type.m, add_foreign_enum.m, and make_hlds_passes.m.)
Simplifications and optimizations will come later, after this module
is merged with make_tags.m and with (at least) the foreign_enum half of
add_foreign_enum.m.
compiler/make_tags.m:
Keep the functionality of this module, which does both the first part
of deciding type representations (tentatively assigning tags to functors,
an assignment that may be overridden later), and the last part (packing
multiple adjacent less-than-word-sized enum args into a single word,
if possible.), but simplify it where possible, and note possibilities
for further improvements.
compiler/add_foreign_enum.m:
This module has two halves, one dealing with foreign_enum pragmas
and one dealing with foreign_export_enum pragmas.
Change the half that deals with foreign_enum pragmas to just build
a data structure that du_type_layout.m will need to make its decisions,
this structure being a map from type_ctors to the foreign enum
specification applicable to the current target language. Include
in this structure a component that add_foreign_enum.m itself can use
to report better error messages for duplicate foreign_enum pragmas;
this component records, for each type_ctor and language, the context
of the previous foreign_enum pragma for that combo.
Change the input for the half that deals with foreign_export_enum pragmas
to reflect the fact that it is invoked by du_type_layout.m after all
decisions about type representations have already been made.
compiler/add_special_pred.m:
Move this module from the make_hlds package to the hlds package,
since the code that adds special preds for type is now called from
du_type_layout.m.
Change the names of predicates to make clear whether they add
only the declaration of a predicate, only its definition, or both.
Don't try to pre-guess whether the implementation of a type's
compare predicate will need an index predicate. Let the code
that generates calls to the index predicate both declare and define
the index predicate. This change removes the potential for
inconsistencies between the two pieces of code.
compiler/add_pred.m:
Move this module from the make_hlds package to the hlds package,
since add_special_pred.m needs access to it.
compiler/add_type.m:
When adding a type definition to the HLDS, don't try to decide
its representation. Any such decision was tentative anyway, due
to the possibility of e.g. the later processing of foreign_type
or foreign_enum pragmas for the type. Likewise, don't try to
create the special (unify, compare) predicates for the type.
Leave both tasks to the du_type_layout pass.
Likewise, don't try to pack the representation of types, or record
no_tag types in the table of no_tag types, during the post-processing
pass either; leave both of these to du_type_layout as well.
Rename the predicate that post_processes type definitions to reflect
the two tasks left for it to do.
compiler/prog_data.m:
Do not store width information about the arguments of those data
constructors in the parse tree. That information is not computed
until later; until then, it was always filled in with dummy values.
(But see hlds_data.m below.)
Use bespoke types to represent the presence or absence of user-specified
unify and compare predicates.
Change the representation of data constructors to use a single "maybe"
type, not two lists, to denote the presence or absence of existentially
typed arguments.
Give the HLDS the ability to hold representation information about
abstract types that in the future we will get from type_repn items
in the defining modules' interface files.
Delete the uses_reserved_tag type, since we never use reserved tags
anymore.
compiler/prog_item.m:
Add the new type_repn item type, which is not used yet.
Delete the reserve_tag pragma.
Fix an earlier mistake in the wording of a context message.
compiler/hlds_data.m:
Put all the fields of hlds_du_type (the type definition variant dealing
with discriminated union types) that deal with type representation
issues in a single "maybe" field that is set to "no" before the
type representation decision pass has been run.
Add new type, constructor_repn, that stores the same information as the old
constructor type (defined in prog_data.m), PLUS the information
describing how terms with that data constructor are stored.
Likewise, add a new type ctor_arg_rep, which likewise stores
the widths of each constructor argument. When we implement
argument reordering, we would store the offset of the arg as well.
Since the parse tree representations of constructors and their arguments
don't store representation information anymore, the cons_table they
are stored in doesn't either. Make the lookup of representation information
for a given constructor possible by adding a map to the new "maybe" field
of hlds_du_type.
Provide some utility predicates.
Optimize some existing predicates.
Rename some types to better reflect their meaning.
compiler/hlds_module.m:
Provide a slot in the module_info for storing the information
gathered by make_hlds.m that is needed by the new pass.
compiler/make_hlds_separate_items.m:
When we see either a foreign_enum or a foreign_export_enum pragma,
return values of a bespoke type for them (a type defined in
hlds_module.m), instead of an item_pragma. This makes handling them
considerably easier.
compiler/make_hlds_passes.m:
With the changes in this diff, adding a type to the HLDS won't
decide its representation. Therefore delete the code that used
to loop over foreign_export_enum pragmas; in the absence of
the final type representation information, it won't work right.
Record the information that the du_type_layout pass will need
in the module_info.
compiler/add_pragma.m:
Delete the code for passing on foreign_enum and foreign_export_enum
pragmas to add_foreign_enum.m; they are now passed to add_foreign_enum.m
by du_type_layout.m.
Move a utility predicate to make_hlds_error.m, to allow add_foreign_enum.m
to call it.
compiler/make_hlds_error.m:
Add the utility predicate moved from add_pragma.m.
Move the module from the make_hlds to the hlds package.
compiler/module_qual.m:
Provide a mechanism for recording error messages about e.g. undefined
types without recording that we found an undefined type. This sounds
strange, but there is a valid use case.
When a type definition declares a functor's argument to be of an
undefined type, that error is usually fatal; we stop the compiler
from proceeding even to typechecking, since the typechecker will
probably abort with a map lookup failure. Most other references
to undefined types are similarly fatal for the same reason. However,
if e.g. a foreign_export_enum pragma refers to an undefined type,
that error *won't* be visible to the typechecker, and therefore
won't crash it. The error will still cause the compiler to exit
without generating any target language code, but at least it will be
able to run the typechecker and other semantic analysis passes.
Without this change, the compiler will report only one error in
the ee_invalid.m test case; with it, it reports *every* error
in the test case expected output.
compiler/module_qual.qualify_items.m:
Use the capability describe above for undefined types in
foreign_export_enum pragmas.
compiler/module_qual.qual_errors.m:
Delete a (somewhat incorrect) copy of a predicate in prog_item.m,
to reduce code duplication.
compiler/prog_type.m:
Add ways to represent abstract types whose representations are nevertheless
known (from type_repn items in the defining modules' interface files)
to be notag or dummy types. This will be needed to fix Mantis bug #441,
a fix that will probably be one of the first later changes to build
on this diff.
Delete a type moved to type_util.m.
compiler/type_util.m:
Provide extra versions of some predicates, with the difference between
the old and the new versions being that one requires type representations
to have been decided already, and the other one does not.
Move the definition of the ctor_defn type here from prog_type.m,
since prog_type.m itself does not use it, but type_util.m does.
Give some predicates more meaningful names.
compiler/parse_type_defn.m:
Simplify the code for parsing type definitions, to make it easier
to reuse to parse type_repn items.
Add a sanity check that requires existential constraints to have
*some* existential variables to apply to.
Allow "type_is_representable_in_n_bits" as a synonym for
"type_is_abstract_enum", since in the future we want to be able to pack
e.g. multiple int8s, not just multiple enums, into a single word.
Generate more specific error messages for some classes of malformed input.
compiler/parse_type_repn.m:
New module to parse type_repn items.
compiler/polymorphism.m:
Make some predicates that operate on type constructors take
the type constructors themselves as input arguments, not a whole type
*using* that type constructor. Put the arguments of those predicates
in a more standard order.
Note that some predicates don't belong in this module.
compiler/special_pred.m:
Make the code that decides whether a special predicate for a type
constructor can be defined lazily avoid using type representation
information. (Actually, we now make decisions about lazy vs eager
definitions after type representation is available, but that was
not so in an earlier version of this change, and the new code
is more robust.)
compiler/unify_proc.m:
When we decide to generate code for a compare predicate that needs
the type to have an index predicate, don't presume that the index
predicate has already been declared and defined; instead, declare
and define it then and there. (Index predicates are *never* called
from anywhere else.)
Pack the information needed to define a special predicate
into a single structure, to simplify the above.
Since the creation of a clause for a compare predicate may now require
the declaration and definition of an index predicate, the module_info
field of the unify_proc_info is now a writeable field.
Give some predicates and function symbols more meaningful names.
Note some problems with the existing code.
compiler/add_class.m:
compiler/add_clause.m:
compiler/add_foreign_proc.m:
compiler/add_mode.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pragma_tabling.m:
compiler/add_pragma_type_spec.m:
compiler/add_solver.m:
compiler/check_typeclass.m:
compiler/code_info.m:
compiler/comp_unit_interface.m:
compiler/ctgc.selector.m:
compiler/ctgc.util.m:
compiler/default_func_mode.m:
compiler/det_report.m:
compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
compiler/erl_code_gen.m:
compiler/export.m:
compiler/foreign.m:
compiler/get_dependencies.m:
compiler/goal_expr_to_goal.m:
compiler/hhf.m:
compiler/higher_order.m:
compiler/hlds_code_util.m:
compiler/hlds_out_module.m:
compiler/inst_check.m:
compiler/inst_test.m:
compiler/inst_util.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/make_hlds_warn.m:
compiler/ml_accurate_gc.m:
compiler/ml_simplify_switch.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
compiler/mode_util.m:
compiler/modecheck_goal.m:
compiler/module_qual.collect_mq_info.m:
compiler/modules.m:
compiler/parse_item.m:
compiler/parse_pragma.m:
compiler/parse_tree.m:
compiler/parse_tree_out.m:
compiler/parse_tree_out_pragma.m:
compiler/post_term_analysis.m:
compiler/proc_requests.m:
compiler/prog_item_stats.m:
compiler/qual_info.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/resolve_unify_functor.m:
compiler/rtti.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/simplify_goal_ite.m:
compiler/stack_opt.m:
compiler/state_var.m:
compiler/structure_reuse.direct.choose_reuse.m:
compiler/superhomogeneous.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_constr_build.m:
compiler/term_norm.m:
compiler/trailing_analysis.m:
compiler/type_constraints.m:
compiler/type_ctor_info.m:
compiler/typecheck.m:
compiler/unify_gen.m:
compiler/untupling.m:
compiler/unused_imports.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
Conform to the changes above.
tests/invalid/Mmakefile:
Disable the reserve_tag test case, as it is not applicable anymore.
tests/invalid/exported_foreign_enum.{m,err_exp}:
tests/invalid/pragma_qual_error.{m,err_exp}:
Delete reserve_tag pragmas from these test cases, and its effects
from the expected outputs.
tests/invalid/bad_foreign_type.err_exp:
tests/invalid/bigtest.err_exp:
tests/invalid/foreign_enum_invalid.err_exp:
tests/invalid/type_lhs_var.err_exp:
tests/invalid/uu_type.err_exp:
tests/invalid/where_abstract_enum.err_exp:
tests/invalid/where_direct_arg.err_exp:
Expect the updated messages for some errors.
tests/valid/Mmake.valid.common:
tests/valid/Mmakefile:
Disable any reserve_tag test cases, as they are not applicable anymore.
399 lines
16 KiB
Mathematica
399 lines
16 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%---------------------------------------------------------------------------%
|
|
% Copyright (C) 2015 The Mercury team.
|
|
% This file may only be copied under the terms of the GNU General
|
|
% Public License - see the file COPYING in the Mercury distribution.
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% File: comp_unit_interface.m.
|
|
% Authors: fjh (original version), zs (current version).
|
|
%
|
|
% Given the raw compilation unit of a module, extract the part of that module
|
|
% that will go into the .int file of the module.
|
|
%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module parse_tree.comp_unit_interface.
|
|
:- interface.
|
|
|
|
:- import_module libs.
|
|
:- import_module libs.globals.
|
|
:- import_module mdbcomp.
|
|
:- import_module mdbcomp.sym_name.
|
|
:- import_module parse_tree.prog_item.
|
|
|
|
:- import_module list.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- type maybe_include_impl_types
|
|
---> dont_include_impl_types
|
|
; include_impl_types.
|
|
|
|
% Given the raw compilation unit of a module, extract and return
|
|
% the part of that module that will go into the .int file of the module.
|
|
% This will typically mostly be the interface section of the module,
|
|
% but it may also contain parts of the implementation section as well.
|
|
% Both parts may be somewhat modified; for example, we may remove
|
|
% the bodies of instance definitions in an interface section,
|
|
% but put the original, non-abstract instance definition in the
|
|
% implementation section.
|
|
%
|
|
:- pred get_interface(maybe_include_impl_types::in,
|
|
raw_compilation_unit::in, raw_compilation_unit::out) is det.
|
|
|
|
% As above, but also return ...
|
|
% XXX ITEM_LIST document EXACTLY what the second list of item blocks is.
|
|
%
|
|
:- pred get_int_and_impl(maybe_include_impl_types::in,
|
|
raw_compilation_unit::in,
|
|
list(raw_item_block)::out, list(raw_item_block)::out) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
% This predicate is exported for use by modules.m.
|
|
%
|
|
% XXX ITEM_LIST They shouldn't be needed; the representation of the
|
|
% compilation unit should have all this information separate from
|
|
% the items.
|
|
%
|
|
:- pred add_needed_foreign_import_module_items_to_item_blocks(module_name::in,
|
|
MS::in, list(item_block(MS))::in, list(item_block(MS))::out) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
% This predicate is exported for use by module_imports.m.
|
|
%
|
|
% XXX ITEM_LIST They shouldn't be needed; the representation of the
|
|
% compilation unit should have all this information separate from
|
|
% the items.
|
|
%
|
|
:- pred get_foreign_self_imports_from_item_blocks(list(item_block(MS))::in,
|
|
list(foreign_language)::out) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module parse_tree.item_util.
|
|
:- import_module parse_tree.prog_data_foreign.
|
|
|
|
:- import_module cord.
|
|
:- import_module maybe.
|
|
:- import_module require.
|
|
:- import_module set.
|
|
:- import_module term.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
get_interface(IncludeImplTypes, RawCompUnit, InterfaceRawCompUnit) :-
|
|
RawCompUnit =
|
|
raw_compilation_unit(ModuleName, ModuleNameContext, RawItemBlocks),
|
|
% XXX ITEM_LIST Don't compute _NonIFileItemBlocksCord
|
|
% just to throw it away. If we mode-specialize
|
|
% get_ifile_and_noifile_in_raw_item_blocks_acc for
|
|
% dont_gather_noifile_items, will the compiler optimize away
|
|
% the arguments for NoIFileItemBlocks?
|
|
get_ifile_and_noifile_in_raw_item_blocks_acc(IncludeImplTypes,
|
|
dont_gather_noifile_items, RawItemBlocks,
|
|
cord.init, IFileItemBlocksCord, cord.init, _NoIFileItemBlocksCord),
|
|
IFileItemBlocks0 = cord.list(IFileItemBlocksCord),
|
|
% XXX ITEM_LIST The ms_interface is a guess.
|
|
add_needed_foreign_import_module_items_to_item_blocks(ModuleName,
|
|
ms_interface, IFileItemBlocks0, IFileItemBlocks),
|
|
InterfaceRawCompUnit =
|
|
raw_compilation_unit(ModuleName, ModuleNameContext, IFileItemBlocks).
|
|
|
|
get_int_and_impl(IncludeImplTypes, RawCompUnit,
|
|
IFileItemBlocks, NoIFileItemBlocks) :-
|
|
RawCompUnit =
|
|
raw_compilation_unit(ModuleName, _ModuleNameContext, RawItemBlocks),
|
|
get_ifile_and_noifile_in_raw_item_blocks_acc(IncludeImplTypes,
|
|
gather_noifile_items, RawItemBlocks,
|
|
cord.init, IFileItemBlocksCord, cord.init, NoIFileItemBlocksCord),
|
|
IFileItemBlocks0 = cord.list(IFileItemBlocksCord),
|
|
NoIFileItemBlocks = cord.list(NoIFileItemBlocksCord),
|
|
% XXX ITEM_LIST The ms_interface is a guess.
|
|
add_needed_foreign_import_module_items_to_item_blocks(ModuleName,
|
|
ms_interface, IFileItemBlocks0, IFileItemBlocks).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- type maybe_gather_noifile_items
|
|
---> dont_gather_noifile_items
|
|
; gather_noifile_items.
|
|
|
|
:- mode gather_noifile_items == in(bound(gather_noifile_items)).
|
|
:- mode dont_gather_noifile_items == in(bound(dont_gather_noifile_items)).
|
|
|
|
:- pred get_ifile_and_noifile_in_raw_item_blocks_acc(maybe_include_impl_types,
|
|
maybe_gather_noifile_items, list(raw_item_block),
|
|
cord(raw_item_block), cord(raw_item_block),
|
|
cord(raw_item_block), cord(raw_item_block)).
|
|
:- mode get_ifile_and_noifile_in_raw_item_blocks_acc(in,
|
|
dont_gather_noifile_items, in, in, out, in, out) is det.
|
|
:- mode get_ifile_and_noifile_in_raw_item_blocks_acc(in,
|
|
gather_noifile_items, in, in, out, in, out) is det.
|
|
|
|
get_ifile_and_noifile_in_raw_item_blocks_acc(_, _,
|
|
[], !IFileItemBlocksCord, !NoIFileItemBlocksCord).
|
|
get_ifile_and_noifile_in_raw_item_blocks_acc(IncludeImplTypes,
|
|
GatherNoIFileItems, [RawItemBlock | RawItemBlocks],
|
|
!IFileItemBlocksCord, !NoIFileItemBlocksCord) :-
|
|
RawItemBlock = item_block(Section, SectionContext, Incls, Avails, Items),
|
|
(
|
|
Section = ms_interface,
|
|
IFileIncls = Incls,
|
|
IFileAvails = Avails,
|
|
NoIFileIncls = [],
|
|
NoIFileAvails = []
|
|
;
|
|
Section = ms_implementation,
|
|
(
|
|
IncludeImplTypes = dont_include_impl_types,
|
|
IFileIncls = [],
|
|
IFileAvails = []
|
|
;
|
|
IncludeImplTypes = include_impl_types,
|
|
IFileIncls = Incls,
|
|
IFileAvails = Avails
|
|
),
|
|
(
|
|
GatherNoIFileItems = dont_gather_noifile_items,
|
|
NoIFileIncls = [],
|
|
NoIFileAvails = []
|
|
;
|
|
GatherNoIFileItems = gather_noifile_items,
|
|
NoIFileIncls = Incls,
|
|
NoIFileAvails = Avails
|
|
)
|
|
),
|
|
get_ifile_and_noifile_in_items_acc(IncludeImplTypes, GatherNoIFileItems,
|
|
Section, Items,
|
|
cord.init, IFileItemsCord, cord.init, NoIFileItemsCord),
|
|
IFileItems = cord.list(IFileItemsCord),
|
|
NoIFileItems = cord.list(NoIFileItemsCord),
|
|
( if
|
|
IFileIncls = [],
|
|
IFileAvails = [],
|
|
IFileItems = []
|
|
then
|
|
true
|
|
else
|
|
IFileItemBlock = item_block(Section, SectionContext,
|
|
IFileIncls, IFileAvails, IFileItems),
|
|
!:IFileItemBlocksCord =
|
|
cord.snoc(!.IFileItemBlocksCord, IFileItemBlock)
|
|
),
|
|
( if
|
|
NoIFileIncls = [],
|
|
NoIFileAvails = [],
|
|
NoIFileItems = []
|
|
then
|
|
true
|
|
else
|
|
NoIFileItemBlock = item_block(Section, SectionContext,
|
|
NoIFileIncls, NoIFileAvails, NoIFileItems),
|
|
!:NoIFileItemBlocksCord =
|
|
cord.snoc(!.NoIFileItemBlocksCord, NoIFileItemBlock)
|
|
),
|
|
get_ifile_and_noifile_in_raw_item_blocks_acc(IncludeImplTypes,
|
|
GatherNoIFileItems, RawItemBlocks,
|
|
!IFileItemBlocksCord, !NoIFileItemBlocksCord).
|
|
|
|
:- pred get_ifile_and_noifile_in_items_acc(maybe_include_impl_types,
|
|
maybe_gather_noifile_items, module_section, list(item),
|
|
cord(item), cord(item), cord(item), cord(item)).
|
|
:- mode get_ifile_and_noifile_in_items_acc(in,
|
|
dont_gather_noifile_items, in, in, in, out, in, out) is det.
|
|
:- mode get_ifile_and_noifile_in_items_acc(in,
|
|
gather_noifile_items, in, in, in, out, in, out) is det.
|
|
|
|
get_ifile_and_noifile_in_items_acc(_, _, _,
|
|
[], !IFileItemsCord, !NoIFileItemsCord).
|
|
get_ifile_and_noifile_in_items_acc(IncludeImplTypes, GatherNoIFileItems,
|
|
Section, [Item | Items], !IFileItemsCord, !NoIFileItemsCord) :-
|
|
(
|
|
Section = ms_interface,
|
|
( if Item = item_instance(ItemInstance) then
|
|
% Include the abstract version of the instance in the
|
|
% interface, ...
|
|
AbstractItemInstance = make_instance_abstract(ItemInstance),
|
|
AbstractItem = item_instance(AbstractItemInstance),
|
|
!:IFileItemsCord = cord.snoc(!.IFileItemsCord, AbstractItem),
|
|
|
|
% ... and the concrete version in the implementation.
|
|
(
|
|
GatherNoIFileItems = dont_gather_noifile_items
|
|
;
|
|
GatherNoIFileItems = gather_noifile_items,
|
|
!:NoIFileItemsCord = cord.snoc(!.NoIFileItemsCord, Item)
|
|
)
|
|
else
|
|
!:IFileItemsCord = cord.snoc(!.IFileItemsCord, Item)
|
|
)
|
|
;
|
|
Section = ms_implementation,
|
|
(
|
|
GatherNoIFileItems = dont_gather_noifile_items
|
|
;
|
|
GatherNoIFileItems = gather_noifile_items,
|
|
!:NoIFileItemsCord = cord.snoc(!.NoIFileItemsCord, Item)
|
|
),
|
|
% XXX ITEM_LIST Unify include_in_int_file_implementation with
|
|
% include_in_short_interface.
|
|
( if
|
|
IncludeImplTypes = include_impl_types,
|
|
include_in_int_file_implementation(Item) = yes(IFileItem)
|
|
then
|
|
!:IFileItemsCord = cord.snoc(!.IFileItemsCord, IFileItem)
|
|
else
|
|
true
|
|
)
|
|
),
|
|
get_ifile_and_noifile_in_items_acc(IncludeImplTypes, GatherNoIFileItems,
|
|
Section, Items, !IFileItemsCord, !NoIFileItemsCord).
|
|
|
|
:- func include_in_int_file_implementation(item) = maybe(item).
|
|
|
|
include_in_int_file_implementation(Item) = MaybeIFileItem :-
|
|
(
|
|
% `:- typeclass declarations' may be referred to by the constructors
|
|
% in type declarations. Since these constructors are abstractly
|
|
% exported, we won't need the local instance declarations.
|
|
Item = item_type_defn(ItemTypeDefnInfo),
|
|
maybe_make_abstract_type_defn(sifk_int2,
|
|
ItemTypeDefnInfo, MaybeAbstractItemTypeDefnInfo),
|
|
AbstractItem = item_type_defn(MaybeAbstractItemTypeDefnInfo),
|
|
MaybeIFileItem = yes(AbstractItem)
|
|
;
|
|
Item = item_typeclass(ItemTypeClassInfo),
|
|
make_abstract_typeclass(ItemTypeClassInfo, AbstractItemTypeClassInfo),
|
|
AbstractItem = item_typeclass(AbstractItemTypeClassInfo),
|
|
MaybeIFileItem = yes(AbstractItem)
|
|
;
|
|
Item = item_pragma(ItemPragma),
|
|
ItemPragma = item_pragma_info(Pragma, _, _, _),
|
|
(
|
|
( Pragma = pragma_foreign_import_module(_)
|
|
; Pragma = pragma_foreign_enum(_)
|
|
),
|
|
MaybeIFileItem = yes(Item)
|
|
;
|
|
% XXX I am not sure about the proper value of MaybeIFileItem
|
|
% for some of these. -zs
|
|
( Pragma = pragma_foreign_decl(_)
|
|
; Pragma = pragma_foreign_code(_)
|
|
; Pragma = pragma_foreign_proc(_)
|
|
; Pragma = pragma_foreign_proc_export(_)
|
|
; Pragma = pragma_foreign_export_enum(_)
|
|
; Pragma = pragma_external_proc(_)
|
|
; Pragma = pragma_type_spec(_)
|
|
; Pragma = pragma_inline(_)
|
|
; Pragma = pragma_no_inline(_)
|
|
; Pragma = pragma_consider_used(_)
|
|
; Pragma = pragma_unused_args(_)
|
|
; Pragma = pragma_exceptions(_)
|
|
; Pragma = pragma_trailing_info(_)
|
|
; Pragma = pragma_mm_tabling_info(_)
|
|
; Pragma = pragma_obsolete(_)
|
|
; Pragma = pragma_no_detism_warning(_)
|
|
; Pragma = pragma_require_tail_recursion(_)
|
|
; Pragma = pragma_oisu(_)
|
|
; Pragma = pragma_tabled(_)
|
|
; Pragma = pragma_fact_table(_)
|
|
; Pragma = pragma_promise_eqv_clauses(_)
|
|
; Pragma = pragma_promise_pure(_)
|
|
; Pragma = pragma_promise_semipure(_)
|
|
; Pragma = pragma_termination_info(_)
|
|
; Pragma = pragma_termination2_info(_)
|
|
; Pragma = pragma_terminates(_)
|
|
; Pragma = pragma_does_not_terminate(_)
|
|
; Pragma = pragma_check_termination(_)
|
|
; Pragma = pragma_mode_check_clauses(_)
|
|
; Pragma = pragma_structure_sharing(_)
|
|
; Pragma = pragma_structure_reuse(_)
|
|
; Pragma = pragma_require_feature_set(_)
|
|
),
|
|
MaybeIFileItem = no
|
|
)
|
|
;
|
|
( Item = item_clause(_)
|
|
; Item = item_inst_defn(_)
|
|
; Item = item_mode_defn(_)
|
|
; Item = item_pred_decl(_)
|
|
; Item = item_mode_decl(_)
|
|
; Item = item_promise(_)
|
|
; Item = item_instance(_)
|
|
; Item = item_initialise(_)
|
|
; Item = item_finalise(_)
|
|
; Item = item_mutable(_)
|
|
; Item = item_nothing(_)
|
|
),
|
|
MaybeIFileItem = no
|
|
;
|
|
Item = item_type_repn(_),
|
|
% XXX TYPE_REPN Implement this.
|
|
unexpected($pred, "item_type_repn")
|
|
).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
add_needed_foreign_import_module_items_to_item_blocks(ModuleName, Section,
|
|
ItemBlocks0, ItemBlocks) :-
|
|
list.foldl(accumulate_foreign_import_langs_in_item_block, ItemBlocks0,
|
|
set.init, LangSet),
|
|
set.to_sorted_list(LangSet, Langs),
|
|
(
|
|
Langs = [],
|
|
ItemBlocks = ItemBlocks0
|
|
;
|
|
Langs = [_ | _],
|
|
ImportItems = list.map(make_foreign_import(ModuleName), Langs),
|
|
ImportItemBlock = item_block(Section, term.context_init,
|
|
[], [], ImportItems),
|
|
ItemBlocks = [ImportItemBlock | ItemBlocks0]
|
|
).
|
|
|
|
%---------------------%
|
|
|
|
get_foreign_self_imports_from_item_blocks(ItemBlocks, Langs) :-
|
|
list.foldl(accumulate_foreign_import_langs_in_item_block, ItemBlocks,
|
|
set.init, LangSet),
|
|
set.to_sorted_list(LangSet, Langs).
|
|
|
|
:- pred accumulate_foreign_import_langs_in_item_block(item_block(MS)::in,
|
|
set(foreign_language)::in, set(foreign_language)::out) is det.
|
|
|
|
accumulate_foreign_import_langs_in_item_block(ItemBlock, !LangSet) :-
|
|
ItemBlock = item_block(_, _, _, _, Items),
|
|
list.foldl(accumulate_foreign_import_langs_in_item, Items, !LangSet).
|
|
|
|
:- pred accumulate_foreign_import_langs_in_item(item::in,
|
|
set(foreign_language)::in, set(foreign_language)::out) is det.
|
|
|
|
accumulate_foreign_import_langs_in_item(Item, !LangSet) :-
|
|
Langs = item_needs_foreign_imports(Item),
|
|
set.insert_list(Langs, !LangSet).
|
|
|
|
%---------------------%
|
|
|
|
:- func make_foreign_import(module_name, foreign_language) = item.
|
|
|
|
make_foreign_import(ModuleName, Lang) = Item :-
|
|
Attrs = item_compiler_attributes(do_not_allow_export, is_not_mutable),
|
|
Origin = item_origin_compiler(Attrs),
|
|
FIM = foreign_import_module_info(Lang, ModuleName),
|
|
Info = pragma_info_foreign_import_module(FIM),
|
|
Pragma = pragma_foreign_import_module(Info),
|
|
ItemPragma = item_pragma_info(Pragma, Origin, term.context_init, -1),
|
|
Item = item_pragma(ItemPragma).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
:- end_module parse_tree.comp_unit_interface.
|
|
%---------------------------------------------------------------------------%
|