Don't compute has_main/no_main.

That info hasn't been used in a long time (since we deleted the IL backend,
according to an old comment).

compiler/module_imports.m:
    Delete the has_main field from the module_and_imports structure.

compiler/convert_parse_tree.m:
compiler/get_dependencies.m:
    Don't look for main/2.

compiler/make.module_dep_file.m:
    When reading in module_dep structures, ignore the contents of the
    no_main/has_main field. The value in that field used to be stored
    elsewhere, but it was never used.

    When writing out module_dep structures, always put "no_main"
    into the no_main/has_main field.

    Add comments describing possible changes to the on-disk module_dep
    structure.

compiler/grab_modules.m:
    Conform to the changes above.
This commit is contained in:
Zoltan Somogyi
2020-11-07 14:14:07 +11:00
parent 1045c37bd3
commit b0d147b057
5 changed files with 39 additions and 148 deletions

View File

@@ -1652,17 +1652,15 @@ check_convert_raw_comp_unit_to_module_src(Globals, RawCompUnit,
% minus the parts that are subject to the calls to expect below,
% in the ParseTreeModuleSrc, to avoid the need to compute it again later.
IntContents = item_contents(IntForeignIncludeFilesCord,
IntFactTablesSet, _IntLangSet, IntForeignExportLangs, _IntHasMain),
IntFactTablesSet, _IntLangSet, IntForeignExportLangs),
ImpContents = item_contents(_ImpForeignIncludeFilesCord,
_ImpFactTablesSet, _ImpLangSet, _ImpForeignExportLangs, ImpHasMain),
_ImpFactTablesSet, _ImpLangSet, _ImpForeignExportLangs),
expect(cord.is_empty(IntForeignIncludeFilesCord), $pred,
"interface has foreign include files"),
expect(set.is_empty(IntFactTablesSet), $pred,
"interface has fact tables"),
expect(set.is_empty(IntForeignExportLangs), $pred,
"interface has foreign export languages"),
expect(unify(ImpHasMain, no_main), $pred,
"implementation has main"),
ParseTreeModuleSrc = parse_tree_module_src(ModuleName, ModuleNameContext,
IntInclMap, ImpInclMap, InclMap,
@@ -2365,35 +2363,6 @@ classify_src_items_int([Item | Items],
!:RevInstances = [ItemInstanceInfo | !.RevInstances]
;
Item = item_pred_decl(ItemPredDeclInfo),
% XXX ITEM_LIST This code can't handle `main/2' beinng declared
% using `with_type`, since those haven't been expanded at this point.
%
% Given that that most compiler invocations do not care whether
% the module being compiled defines main/2 or not, we should
%
% - delete the ic_has_main field, and the field in the
% module_and_imports structure that it sets, and instead
%
% - get the code that actually needs to know this info to scan
% the list of predicate declarations in the module, preferable
% *after* with_type expansion.
ItemPredDeclInfo = item_pred_decl_info(SymName, PorF, ArgTypes,
_, WithType, _, _, _, _, _, _, _, _, _),
( if
(
SymName = unqualified(_),
unexpected($pred, "unqualified SymName")
;
SymName = qualified(_, "main")
),
PorF = pf_predicate,
ArgTypes = [_, _],
WithType = no
then
!Contents ^ ic_has_main := has_main
else
true
),
!:RevPredDecls = [ItemPredDeclInfo | !.RevPredDecls]
;
Item = item_mode_decl(ItemModeDeclInfo),

View File

@@ -165,8 +165,7 @@
ic_fifos :: cord(foreign_include_file_info),
ic_fact_tables :: set(string),
ic_langs :: set(foreign_language),
ic_foreign_export_langs :: set(foreign_language),
ic_has_main :: has_main
ic_foreign_export_langs :: set(foreign_language)
).
:- func init_item_contents = item_contents.
@@ -1117,7 +1116,7 @@ add_implicit_avail(Implicit, ModuleName, !ImportUseMap) :-
%---------------------------------------------------------------------------%
init_item_contents =
item_contents(cord.init, set.init, set.init, set.init, no_main).
item_contents(cord.init, set.init, set.init, set.init).
get_implicits_foreigns_fact_tables(IntItems, ImpItems,
IntImplicitAvailNeeds, IntImpImplicitAvailNeeds, !:Contents) :-
@@ -1125,13 +1124,8 @@ get_implicits_foreigns_fact_tables(IntItems, ImpItems,
!:Contents = init_item_contents,
get_implicits_foreigns_fact_tables_acc(IntItems,
ImplicitAvailNeeds0, IntImplicitAvailNeeds, !Contents),
IntHasMain = !.Contents ^ ic_has_main,
get_implicits_foreigns_fact_tables_acc(ImpItems,
IntImplicitAvailNeeds, IntImpImplicitAvailNeeds, !Contents),
% We ignore declarations of predicates named "main" in the
% implementation section, because nonexported predicates cannot serve
% as program entry points.
!Contents ^ ic_has_main := IntHasMain.
IntImplicitAvailNeeds, IntImpImplicitAvailNeeds, !Contents).
:- pred get_implicits_foreigns_fact_tables_acc(list(item)::in,
implicit_avail_needs::in, implicit_avail_needs::out,
@@ -1278,39 +1272,10 @@ get_implicits_foreigns_fact_tables_acc([Item | Items],
FELangs0 = !.Contents ^ ic_foreign_export_langs,
set.insert_list(all_foreign_languages, FELangs0, FELangs),
!Contents ^ ic_foreign_export_langs := FELangs
;
Item = item_pred_decl(ItemPredDecl),
ItemPredDecl = item_pred_decl_info(SymName, PorF, ArgTypes,
_, WithType, _, _, _, _, _, _, _, _, _),
( if
% XXX ITEM_LIST Could the predicate name be unqualified?
(
SymName = unqualified(_),
unexpected($pred, "unqualified SymName")
;
SymName = qualified(_, "main")
),
PorF = pf_predicate,
% XXX The comment below is obsolete, and was probably wrong
% even before it became obsolete.
% XXX We should allow `main/2' to be declared using `with_type`,
% but equivalences haven't been expanded at this point.
% The `has_main' field is only used for some special case handling
% of the module containing main for the IL backend (we generate
% a `.exe' file rather than a `.dll' file). This would arguably
% be better done by generating a `.dll' file as normal, and a
% separate `.exe' file containing initialization code and a call
% to `main/2', as we do with the `_init.c' file in the C backend.
ArgTypes = [_, _],
WithType = no
then
!Contents ^ ic_has_main := has_main
else
true
)
;
( Item = item_inst_defn(_)
; Item = item_mode_defn(_)
; Item = item_pred_decl(_)
; Item = item_mode_decl(_)
; Item = item_typeclass(_)
; Item = item_foreign_export_enum(_)

View File

@@ -176,7 +176,7 @@ grab_qual_imported_modules_augment(Globals, SourceFileName,
get_implicits_foreigns_fact_tables(IntItems, ImpItems,
_IntImplicitImportNeeds, _IntImpImplicitImportNeeds, Contents),
Contents = item_contents(ForeignIncludeFilesCord, FactTablesSet,
LangSet, ForeignExportLangs, HasMain),
LangSet, ForeignExportLangs),
set.to_sorted_list(LangSet, Langs),
ImplicitFIMs = list.map(make_foreign_import(ModuleName), Langs),
FactTables = set.to_sorted_list(FactTablesSet),
@@ -203,7 +203,7 @@ grab_qual_imported_modules_augment(Globals, SourceFileName,
make_module_and_imports(Globals, SourceFileName, SourceFileModuleName,
ParseTreeModuleSrc, PublicChildren, NestedChildren, FactTables,
ForeignIncludeFilesCord, ForeignExportLangs, HasMain,
ForeignIncludeFilesCord, ForeignExportLangs,
MaybeTimestampMap, !:ModuleAndImports),
module_and_imports_add_specs(ConvertSpecs, !ModuleAndImports),
!:Specs = [],
@@ -342,7 +342,7 @@ grab_unqual_imported_modules_make_int(Globals, SourceFileName,
get_implicits_foreigns_fact_tables(IntItems, ImpItems,
_IntImplicitImportNeeds, IntImpImplicitImportNeeds, Contents),
Contents = item_contents(_ForeignInclFiles, _FactTables,
LangSet, ForeignExportLangs, HasMain),
LangSet, ForeignExportLangs),
warn_if_duplicate_use_import_decls(ModuleName, ModuleNameContext,
IntImportsMap0, IntImportsMap1, IntUsesMap0, IntUsesMap1,
@@ -373,7 +373,7 @@ grab_unqual_imported_modules_make_int(Globals, SourceFileName,
make_module_and_imports(Globals, SourceFileName, SourceFileModuleName,
ParseTreeModuleSrc, PublicChildren, NestedChildren, FactDeps,
ForeignIncludeFiles, ForeignExportLangs, HasMain,
ForeignIncludeFiles, ForeignExportLangs,
MaybeTimestampMap, !:ModuleAndImports),
RCUMap0 = !.HaveReadModuleMaps ^ hrmm_rcu,

View File

@@ -53,7 +53,6 @@
:- import_module parse_tree.mercury_to_mercury.
:- import_module parse_tree.parse_error.
:- import_module parse_tree.parse_sym_name.
:- import_module parse_tree.prog_data.
:- import_module parse_tree.prog_data_foreign.
:- import_module parse_tree.prog_item.
:- import_module parse_tree.prog_out.
@@ -72,6 +71,18 @@
% `pragma foreign_code'. We continue to write version 1 files when
% possible.
%
% XXX We should consider
%
% - adding a version 3 that differs from 2 in deleting the field
% that now *always* contains "no_main", and
% - switching to always generating version 3.
%
% XXX The precise on-disk representation of each (current) module_dep file
% format version should be explicitly documented. This documentation
% should explain what the meaning of each field is, what purposes
% does it servce, an what invariants (if any) apply to it. It should
% also have some examples to help readers understand it all.
%
:- type module_dep_file_version
---> module_dep_file_v1
; module_dep_file_v2.
@@ -358,7 +369,6 @@ do_write_module_dep_file_2(ModuleAndImports, Version, !IO) :-
module_and_imports_get_c_j_cs_fims(ModuleAndImports, CJCsEFIMs),
module_and_imports_get_foreign_include_files(ModuleAndImports,
ForeignIncludeFiles),
module_and_imports_get_has_main(ModuleAndImports, HasMain),
io.write_string("module(", !IO),
version_number(Version, VersionNumber),
io.write_int(VersionNumber, !IO),
@@ -404,8 +414,9 @@ do_write_module_dep_file_2(ModuleAndImports, Version, !IO) :-
ContainsForeignExportStr),
io.write_string(ContainsForeignExportStr, !IO),
io.write_string(",\n\t", !IO),
has_main_to_string(HasMain, HasMainStr),
io.write_string(HasMainStr, !IO),
% The has_main/no_main slot is not needed anymore, so we just put no_main
% in there always.
io.write_string("no_main", !IO),
(
Version = module_dep_file_v1
;
@@ -451,19 +462,6 @@ contains_foreign_export_to_string(ContainsForeignExport,
ContainsForeignExportStr = "no_foreign_export"
).
:- pred has_main_to_string(has_main, string).
:- mode has_main_to_string(in, out) is det.
:- mode has_main_to_string(out, in) is semidet.
has_main_to_string(HasMain, HasMainStr) :-
(
HasMain = has_main,
HasMainStr = "has_main"
;
HasMain = no_main,
HasMainStr = "no_main"
).
%-----------------------------------------------------------------------------%
:- pred read_module_dependencies_search(globals::in, rebuild_module_deps::in,
@@ -551,7 +549,7 @@ read_module_dependencies_3(Globals, SearchDirs, ModuleName, ModuleDir,
ForeignLanguagesTerm,
ForeignImportsTerm,
ContainsForeignExportTerm,
HasMainTerm
_HasMainTerm
| ModuleArgsTail
],
@@ -574,8 +572,6 @@ read_module_dependencies_3(Globals, SearchDirs, ModuleName, ModuleDir,
contains_foreign_export_term(ContainsForeignExportTerm,
ContainsForeignExport),
has_main_term(HasMainTerm, HasMain),
(
Version = module_dep_file_v1,
ModuleArgsTail = [],
@@ -593,7 +589,7 @@ read_module_dependencies_3(Globals, SearchDirs, ModuleName, ModuleDir,
SourceFileModuleName, ModuleName,
Parents, Children, NestedChildren, IntDeps, ImpDeps, FactDeps,
ForeignImports, ForeignIncludes,
ContainsForeignCode, ContainsForeignExport, HasMain,
ContainsForeignCode, ContainsForeignExport,
ModuleAndImports),
% Discard the module dependencies if the module is a local module
@@ -702,12 +698,6 @@ contains_foreign_export_term(Term, ContainsForeignExport) :-
atom_term(Term, Atom, []),
contains_foreign_export_to_string(ContainsForeignExport, Atom).
:- pred has_main_term(term::in, has_main::out) is semidet.
has_main_term(Term, HasMain) :-
atom_term(Term, String, []),
has_main_to_string(HasMain, String).
:- pred some_bad_module_dependency(make_info::in, list(module_name)::in)
is semidet.

View File

@@ -204,7 +204,7 @@
:- pred make_module_and_imports(globals::in, file_name::in,
module_name::in, parse_tree_module_src::in, module_names_contexts::in,
set(module_name)::in, list(string)::in, foreign_include_file_infos::in,
set(foreign_language)::in, has_main::in,
set(foreign_language)::in,
maybe(module_timestamp_map)::in, module_and_imports::out) is det.
% Construct a module_and_imports structure for inclusion in
@@ -220,7 +220,7 @@
list(module_name)::in, list(string)::in,
list(fim_spec)::in, list(foreign_include_file_info)::in,
contains_foreign_code::in, contains_foreign_export::in,
has_main::in, module_and_imports::out) is det.
module_and_imports::out) is det.
%---------------------------------------------------------------------------%
%
@@ -261,8 +261,6 @@
contains_foreign_code::out) is det.
:- pred module_and_imports_get_contains_foreign_export(module_and_imports::in,
contains_foreign_export::out) is det.
:- pred module_and_imports_get_has_main(module_and_imports::in,
has_main::out) is det.
:- pred module_and_imports_get_parse_tree_module_src(module_and_imports::in,
parse_tree_module_src::out) is det.
:- pred module_and_imports_get_ancestor_int_specs(module_and_imports::in,
@@ -534,9 +532,6 @@
% declarations?
mai_has_foreign_export :: contains_foreign_export,
% Does this module contain main/2?
mai_has_main :: has_main,
% The contents of the module and its imports.
mai_src :: parse_tree_module_src,
mai_ancestor_int_specs :: map(module_name, ancestor_int_spec),
@@ -748,7 +743,7 @@ init_module_and_imports(Globals, FileName, SourceFileModuleName,
get_implicits_foreigns_fact_tables(IntItems, ImpItems,
IntImplicitImportNeeds, IntImpImplicitImportNeeds, Contents),
Contents = item_contents(NewForeignInclFilesCord, FactTables, _NewLangs,
NewForeignExportLangs, HasMain),
NewForeignExportLangs),
set.to_sorted_list(FactTables, SortedFactTables),
globals.get_backend_foreign_languages(Globals, BackendLangs),
set.intersect(set.list_to_set(BackendLangs), NewForeignExportLangs,
@@ -807,7 +802,7 @@ init_module_and_imports(Globals, FileName, SourceFileModuleName,
set.list_to_set(Ancestors), ChildrenMap, PublicChildrenMap,
NestedDeps, IntDepsMap, IntImpDepsMap, IndirectDeps,
SortedFactTables, ForeignImports, ForeignIncludeFilesCord,
ContainsForeignCode, ContainsForeignExport, HasMain,
ContainsForeignCode, ContainsForeignExport,
ParseTreeModuleSrc, AncestorIntSpecs, DirectIntSpecs, IndirectIntSpecs,
PlainOpts, TransOpts, IntForOptSpecs,
VersionNumbers, MaybeTimestampMap, Specs, Errors,
@@ -843,8 +838,8 @@ accumulate_foreign_import_langs_in_item(Item, !LangSet) :-
make_module_and_imports(Globals, SourceFileName, SourceFileModuleName,
ParseTreeModuleSrc, PublicChildrenMap, NestedChildren, FactDeps,
ForeignIncludeFiles, ForeignExportLangs, HasMain,
MaybeTimestampMap, ModuleAndImports) :-
ForeignIncludeFiles, ForeignExportLangs, MaybeTimestampMap,
ModuleAndImports) :-
set.init(Ancestors),
map.init(IntDeps),
map.init(ImpDeps),
@@ -877,7 +872,7 @@ make_module_and_imports(Globals, SourceFileName, SourceFileModuleName,
Ancestors, ChildrenMap, PublicChildrenMap, NestedChildren,
IntDeps, ImpDeps, IndirectDeps, FactDeps,
ForeignImports, ForeignIncludeFiles,
foreign_code_langs_unknown, ContainsForeignExport, HasMain,
foreign_code_langs_unknown, ContainsForeignExport,
ParseTreeModuleSrc, AncestorSpecs, DirectIntSpecs, IndirectIntSpecs,
PlainOpts, TransOpts, IntForOptSpecs,
VersionNumbers, MaybeTimestampMap, Specs, Errors,
@@ -889,8 +884,7 @@ make_module_dep_module_and_imports(SourceFileName, ModuleDir,
SourceFileModuleName, ModuleName,
Ancestors, Children, NestedChildren, IntDeps, ImpDeps, FactDeps,
ForeignImports, ForeignIncludes,
ContainsForeignCode, ContainsForeignExport, HasMain,
ModuleAndImports) :-
ContainsForeignCode, ContainsForeignExport, ModuleAndImports) :-
ModuleNameContext = term.dummy_context_init,
AddDummyContext =
( func(MN) = MN - one_or_more(term.dummy_context_init, []) ),
@@ -925,7 +919,7 @@ make_module_dep_module_and_imports(SourceFileName, ModuleDir,
set.list_to_set(NestedChildren),
IntDepsContexts, ImpDepsContexts, IndirectDeps, FactDeps,
ForeignImportModules, cord.from_list(ForeignIncludes),
ContainsForeignCode, ContainsForeignExport, HasMain,
ContainsForeignCode, ContainsForeignExport,
ParseTreeModuleSrc, AncestorIntSpecs, DirectIntSpecs, IndirectIntSpecs,
PlainOpts, TransOpts, IntForOptSpecs,
ModuleVersionNumbers, MaybeTimestamps, Specs, Errors,
@@ -1364,31 +1358,6 @@ module_and_imports_get_contains_foreign_export(ModuleAndImports, X) :-
),
X = ModuleAndImports ^ mai_has_foreign_export
).
module_and_imports_get_has_main(ModuleAndImports, X) :-
promise_pure (
trace [compile_time(flag("mai-stats"))] (
semipure get_accesses(Accesses0),
Method = ModuleAndImports ^ mai_construction_method,
(
Method = mcm_init,
Fields0 = Accesses0 ^ mfk_init,
Fields = Fields0 ^ mf_has_main := accessed,
Accesses = Accesses0 ^ mfk_init := Fields
;
Method = mcm_make,
Fields0 = Accesses0 ^ mfk_make,
Fields = Fields0 ^ mf_has_main := accessed,
Accesses = Accesses0 ^ mfk_make := Fields
;
Method = mcm_read,
Fields0 = Accesses0 ^ mfk_read,
Fields = Fields0 ^ mf_has_main := accessed,
Accesses = Accesses0 ^ mfk_read := Fields
),
impure set_accesses(Accesses)
),
X = ModuleAndImports ^ mai_has_main
).
module_and_imports_get_parse_tree_module_src(ModuleAndImports, X) :-
promise_pure (
trace [compile_time(flag("mai-stats"))] (
@@ -1971,7 +1940,6 @@ module_and_imports_get_aug_comp_unit(ModuleAndImports,
mf_foreign_include_files :: maybe_accessed,
mf_contains_foreign_code :: maybe_accessed,
mf_contains_foreign_export :: maybe_accessed,
mf_has_main :: maybe_accessed,
mf_src :: maybe_accessed,
mf_ancestor_int_specs :: maybe_accessed,
@@ -2005,7 +1973,7 @@ init_mai_fields =
not_accessed, not_accessed, not_accessed, not_accessed,
not_accessed, not_accessed, not_accessed, not_accessed, not_accessed,
not_accessed, not_accessed, not_accessed, not_accessed,
not_accessed, not_accessed, not_accessed, not_accessed,
not_accessed, not_accessed, not_accessed,
@@ -2037,13 +2005,13 @@ write_mai_fields_stats(Stream, Kind, Fields, !IO) :-
SrcFileModuleName, ModuleName, ModuleNameContext,
Ancestors, Children, PublicChildren, NestedChildren,
IntDepsMap, ImpDepsMap, IndirectDeps, FactTableDeps,
FIMs, ForeignIncludeFiles, HasForeignCode, HasForeignExport, HasMain,
FIMs, ForeignIncludeFiles, HasForeignCode, HasForeignExport,
ParseTreeModuleSrc, AncestorSpecs, DirectIntSpecs, IndirectIntSpecs,
PlainOpts, TransOpts, IntForOptSpecs,
VersionNumbersMap, MaybeTimestamMap, Specs, Errors),
io.format(Stream,
"%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s " ++
"%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n",
"%s %s %s %s %s %s %s %s %s %s %s %s %s %s\n",
[s(Kind),
s(acc_str(SrcFileName)),
s(acc_str(ModuleDir)),
@@ -2062,7 +2030,6 @@ write_mai_fields_stats(Stream, Kind, Fields, !IO) :-
s(acc_str(ForeignIncludeFiles)),
s(acc_str(HasForeignCode)),
s(acc_str(HasForeignExport)),
s(acc_str(HasMain)),
s(acc_str(ParseTreeModuleSrc)),
s(acc_str(AncestorSpecs)),
s(acc_str(DirectIntSpecs)),