From 95ab5899f6aaf2b549e9376069608e0f91f17760 Mon Sep 17 00:00:00 2001 From: Zoltan Somogyi Date: Fri, 29 Sep 2023 03:54:12 +1000 Subject: [PATCH] Fix comment rot. Improve the names of the predicates and function symbols. --- compiler/deps_map.m | 18 +++++++-------- compiler/generate_dep_d_files.m | 40 +++++++++++++++++++-------------- compiler/make.module_dep_file.m | 9 +++++--- compiler/module_baggage.m | 9 ++------ compiler/module_dep_info.m | 6 ++++- 5 files changed, 45 insertions(+), 37 deletions(-) diff --git a/compiler/deps_map.m b/compiler/deps_map.m index 71e15be14..a40970121 100644 --- a/compiler/deps_map.m +++ b/compiler/deps_map.m @@ -194,7 +194,7 @@ generate_deps_map_step(ProgressStream, Globals, Search, !ModuleExpCs, !DepsMap, !Specs, !IO) :- % Look up the module's dependencies, and determine whether % it has been processed yet. - lookup_or_find_dependencies(ProgressStream, Globals, Search, + lookup_or_find_dependency_info_for_module(ProgressStream, Globals, Search, Module, ExpectationContexts, MaybeDeps0, !DepsMap, !Specs, !IO), % If the module hadn't been processed yet, then add its imports, parents, @@ -325,18 +325,18 @@ add_module_name_and_context(SeenModules0, Context, ModuleName, !ModuleExpCs) :- % If we don't know its dependencies, read the module and % save the dependencies in the dependency map. % -:- pred lookup_or_find_dependencies(io.text_output_stream::in, globals::in, - maybe_search::in, module_name::in, expectation_contexts::in, +:- pred lookup_or_find_dependency_info_for_module(io.text_output_stream::in, + globals::in, maybe_search::in, module_name::in, expectation_contexts::in, maybe(deps)::out, deps_map::in, deps_map::out, list(error_spec)::in, list(error_spec)::out, io::di, io::uo) is det. -lookup_or_find_dependencies(ProgressStream, Globals, Search, +lookup_or_find_dependency_info_for_module(ProgressStream, Globals, Search, ModuleName, ExpectationContexts, MaybeDeps, !DepsMap, !Specs, !IO) :- ( if map.search(!.DepsMap, ModuleName, Deps) then MaybeDeps = yes(Deps) else - read_dependencies(ProgressStream, Globals, Search, ModuleName, - ExpectationContexts, BurdenedModules, !Specs, !IO), + read_src_file_for_dependency_info(ProgressStream, Globals, Search, + ModuleName, ExpectationContexts, BurdenedModules, !Specs, !IO), ( BurdenedModules = [_ | _], list.foldl(insert_into_deps_map, BurdenedModules, !DepsMap), @@ -370,12 +370,12 @@ insert_into_deps_map(BurdenedModule, !DepsMap) :- % and any nested submodules it contains. Return the burdened_module % structure for both the named module and each of its nested submodules. % -:- pred read_dependencies(io.text_output_stream::in, globals::in, - maybe_search::in, module_name::in, expectation_contexts::in, +:- pred read_src_file_for_dependency_info(io.text_output_stream::in, + globals::in, maybe_search::in, module_name::in, expectation_contexts::in, list(burdened_module)::out, list(error_spec)::in, list(error_spec)::out, io::di, io::uo) is det. -read_dependencies(ProgressStream, Globals, Search, ModuleName, +read_src_file_for_dependency_info(ProgressStream, Globals, Search, ModuleName, ExpectationContexts, BurdenedModules, !Specs, !IO) :- % XXX If HaveReadModuleSrc contains error messages, any parse tree % it may also contain may not be complete, and the rest of this predicate diff --git a/compiler/generate_dep_d_files.m b/compiler/generate_dep_d_files.m index e37e47943..bba159f21 100644 --- a/compiler/generate_dep_d_files.m +++ b/compiler/generate_dep_d_files.m @@ -113,24 +113,26 @@ generate_dep_file_for_module(ProgressStream, Globals, ModuleName, Specs, !IO) :- map.init(DepsMap), - generate_dependencies(ProgressStream, Globals, output_all_dependencies, - do_not_search, ModuleName, DepsMap, Specs, !IO). + generate_dot_dx_files(ProgressStream, Globals, + output_all_program_dot_dx_files, do_not_search, + ModuleName, DepsMap, Specs, !IO). generate_dep_file_for_file(ProgressStream, Globals, FileName, Specs, !IO) :- build_initial_deps_map_for_file(ProgressStream, Globals, FileName, ModuleName, DepsMap0, !IO), - generate_dependencies(ProgressStream, Globals, output_all_dependencies, - do_not_search, ModuleName, DepsMap0, Specs, !IO). + generate_dot_dx_files(ProgressStream, Globals, + output_all_program_dot_dx_files, do_not_search, + ModuleName, DepsMap0, Specs, !IO). generate_d_file_for_module(ProgressStream, Globals, ModuleName, Specs, !IO) :- map.init(DepsMap), - generate_dependencies(ProgressStream, Globals, output_d_file_only, + generate_dot_dx_files(ProgressStream, Globals, output_module_dot_d_file, do_search, ModuleName, DepsMap, Specs, !IO). generate_d_file_for_file(ProgressStream, Globals, FileName, Specs, !IO) :- build_initial_deps_map_for_file(ProgressStream, Globals, FileName, ModuleName, DepsMap0, !IO), - generate_dependencies(ProgressStream, Globals, output_d_file_only, + generate_dot_dx_files(ProgressStream, Globals, output_module_dot_d_file, do_search, ModuleName, DepsMap0, Specs, !IO). %---------------------------------------------------------------------------% @@ -166,15 +168,19 @@ build_initial_deps_map_for_file(ProgressStream, Globals, FileName, ModuleName, %---------------------------------------------------------------------------% -:- type generate_dependencies_mode - ---> output_d_file_only - ; output_all_dependencies. +:- type which_dot_dx_files + ---> output_module_dot_d_file + % Output the given module's .d file. + ; output_all_program_dot_dx_files. + % The given module is (or should be!) the main module of a program. + % Output the program's .dep and .gv files, and the .d file + % of every module in the program. -:- pred generate_dependencies(io.text_output_stream::in, globals::in, - generate_dependencies_mode::in, maybe_search::in, module_name::in, +:- pred generate_dot_dx_files(io.text_output_stream::in, globals::in, + which_dot_dx_files::in, maybe_search::in, module_name::in, deps_map::in, list(error_spec)::out, io::di, io::uo) is det. -generate_dependencies(ProgressStream, Globals, Mode, Search, ModuleName, +generate_dot_dx_files(ProgressStream, Globals, Mode, Search, ModuleName, DepsMap0, !:Specs, !IO) :- % First, build up a map of the dependencies. generate_deps_map(ProgressStream, Globals, Search, ModuleName, @@ -199,9 +205,9 @@ generate_dependencies(ProgressStream, Globals, Mode, Search, ModuleName, ) else ( - Mode = output_d_file_only + Mode = output_module_dot_d_file ; - Mode = output_all_dependencies, + Mode = output_all_program_dot_dx_files, SourceFileName = Baggage ^ mb_source_file_name, generate_dependencies_write_dv_file(Globals, SourceFileName, ModuleName, DepsMap, !IO), @@ -327,10 +333,10 @@ generate_dependencies(ProgressStream, Globals, Mode, Search, ModuleName, ext_cur_ngs_gs_max_ngs(ext_cur_ngs_gs_max_ngs_opt_trans), TransOptDepsOrdering, TransOptOrder, !IO), ( - Mode = output_d_file_only, + Mode = output_module_dot_d_file, DFilesToWrite = [ModuleDep] ; - Mode = output_all_dependencies, + Mode = output_all_program_dot_dx_files, DFilesToWrite = DepsList ), generate_dependencies_write_d_files(Globals, DFilesToWrite, @@ -348,7 +354,7 @@ generate_dependencies(ProgressStream, Globals, Mode, Search, ModuleName, globals.get_target(Globals, Target), ( if Target = target_java, - Mode = output_all_dependencies + Mode = output_all_program_dot_dx_files then create_java_shell_script(Globals, ModuleName, _Succeeded, !IO) else diff --git a/compiler/make.module_dep_file.m b/compiler/make.module_dep_file.m index 23cc981f8..57bc79fed 100644 --- a/compiler/make.module_dep_file.m +++ b/compiler/make.module_dep_file.m @@ -77,13 +77,16 @@ % The version 1 module_dep file format is the same as version 2 except that % it does not include a list of files included by `pragma foreign_decl' and - % `pragma foreign_code'. We continue to write version 1 files when - % possible. + % `pragma foreign_code'. We stopped generating version 1 .module_dep files + % on 2021 Jul 31. % % XXX We should consider % % - adding a version 3 that differs from 2 in deleting the field - % that now *always* contains "no_main", and + % that now *always* contains "no_main", + % - replacing the braces that wrap the contents of each structured field + % with a function symbol that explicitly specifies the meaning of + % that contents, and % - switching to always generating version 3. % % XXX The precise on-disk representation of each (current) .module_dep diff --git a/compiler/module_baggage.m b/compiler/module_baggage.m index 926216718..d217189ef 100644 --- a/compiler/module_baggage.m +++ b/compiler/module_baggage.m @@ -235,14 +235,9 @@ % % deps_map.m % generate_dep_d_files.m - % make.module_dep_file.m + % make.get_module_dep_info.m % - % for building dependency maps between modules. The aug_compilation_units - % it builds have only one field filled in, the one containing - % the parse_tree_module_src. - % - % XXX Do the callers fill in the other fields, or do they need *only* - % the parse_tree_module_src? If the latter, we should return only *that*. + % for building dependency maps between modules. % :- pred parse_tree_src_to_burdened_module_list(globals::in, file_name::in, parse_tree_src::in, read_module_errors::in, diff --git a/compiler/module_dep_info.m b/compiler/module_dep_info.m index 3fbd08d35..21ac57bd2 100644 --- a/compiler/module_dep_info.m +++ b/compiler/module_dep_info.m @@ -31,7 +31,7 @@ % a given module depends on may be either % % - the contents of that module' source file (this is represented - % by module_dep_info_imports), or + % by module_dep_info_full), or % % - the contents of the module's .module_dep file (this is represented % by module_dep_info_summary). @@ -42,6 +42,10 @@ :- type module_dep_summary ---> module_dep_summary( + % Note that unlike the mb_source_file_dir field in + % module_baggage structures, which is always set to the current + % directory, the mds_source_file_dir field here *can* refer + % to other directories. mds_source_file_name :: string, mds_source_file_dir :: string, mds_source_file_module_name :: module_name,