[m-rev.] for review: fix github issue #116

Julien Fischer jfischer at opturion.com
Wed Mar 22 01:36:22 AEDT 2023


For review by anyone.

---------------------

Fix Github issue #116.

Building programs with --intermodule-optimization fails when using a library
containing submodules that was *not* installed with --intermodule-optimization
enabled. This is because the compiler is trying to find the .int0 files for the
library, but these are only installed when the library is built with
--intermodule-optimization enabled. The fix is to always install any .int0
files for a library.

compiler/make.program_target.m:
compiler/write_deps_file.m:
     Always install the .int0 files for libraries.

Julien.

diff --git a/compiler/make.program_target.m b/compiler/make.program_target.m
index b1716b0..170ead9 100644
--- a/compiler/make.program_target.m
+++ b/compiler/make.program_target.m
@@ -2,7 +2,7 @@
  % vim: ft=mercury ts=4 sw=4 et
  %---------------------------------------------------------------------------%
  % Copyright (C) 2002-2012 The University of Melbourne.
-% Copyright (C) 2013-2017, 2019-2022 The Mercury team.
+% Copyright (C) 2013-2017, 2019-2023 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.
  %---------------------------------------------------------------------------%
@@ -1509,27 +1509,31 @@ install_ints_and_headers(Globals, SubdirLinkSucceeded, ModuleName, Succeeded,
          !Info, !IO),
      (
          MaybeModuleDepInfo = some_module_dep_info(ModuleDepInfo),
+        % We always install the `.int0' files for a library even though they
+        % are only required by the `.opt' files. This is because when building
+        % a program with --intermodule-optimization enabled, the compiler will
+        % look for `.int0' files of any libraries the program uses. It will do
+        % this even for libraries that were not installed with
+        % --intermodule-optimization enabled, returning an error if it cannot
+        % find the `.int0' file.
+        module_dep_info_get_children(ModuleDepInfo, Children),
+        ( if set.is_empty(Children) then
+            Exts0 = []
+        else
+            Exts0 = [{other_ext(".int0"), "int0s"}]
+        ),
          globals.get_any_intermod(Globals, AnyIntermod),
          (
              AnyIntermod = yes,
-            % `.int0' files are imported by `.opt' files.
-            module_dep_info_get_children(ModuleDepInfo, Children),
-            ( if set.is_empty(Children) then
-                Exts0 = [{other_ext(".opt"), "opts"}]
-            else
-                Exts0 = [{other_ext(".int0"), "int0s"},
-                    {other_ext(".opt"), "opts"}]
-            )
+            Exts1 = [{other_ext(".opt"), "opts"} | Exts0]
          ;
              AnyIntermod = no,
-            Exts0 = []
+            Exts1 = Exts0
          ),
-
          Exts = [{other_ext(".int"), "ints"},
              {other_ext(".int2"), "int2s"},
              {other_ext(".int3"), "int3s"},
-            {other_ext(".module_dep"), "module_deps"}
-            | Exts0],
+            {other_ext(".module_dep"), "module_deps"} | Exts1],
          globals.lookup_string_option(Globals, install_prefix, Prefix),
          LibDir = Prefix/"lib"/"mercury",
          list.map_foldl(
diff --git a/compiler/write_deps_file.m b/compiler/write_deps_file.m
index b2c631f..64877f0 100644
--- a/compiler/write_deps_file.m
+++ b/compiler/write_deps_file.m
@@ -2,6 +2,7 @@
  % vim: ft=mercury ts=4 sw=4 et
  %---------------------------------------------------------------------------%
  % Copyright (C) 2008-2011 The University of Melbourne.
+% Copyright (C) 2013-2017, 2019-2023 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.
  %---------------------------------------------------------------------------%
@@ -1471,7 +1472,7 @@ generate_dependencies_write_d_file(Globals, Dep,
      TransOptRuleInfo = trans_opt_deps_from_order(TransOptOrder),
      MaybeInclTransOptRule = include_trans_opt_rule(TransOptRuleInfo),

-    % Note that even if a fatal error occured for one of the files
+    % Note that even if a fatal error occurred for one of the files
      % that the current Module depends on, a .d file is still produced,
      % even though it probably contains incorrect information.
      ModuleErrors = Baggage ^ mb_errors,
@@ -1799,7 +1800,7 @@ generate_dv_file(Globals, SourceFileName, ModuleName, DepsMap,
      % that it contains .int0 files for all modules, regardless of whether
      % they should have been created or not. It is used by the rule for
      % `mmake realclean' to ensure that we clean up all the .int0 files,
-    % including the ones that were accidently created by the bug described
+    % including the ones that were accidentally created by the bug described
      % above.
      MmakeVarAllInt0s = mmake_var_defn(ModuleMakeVarName ++ ".all_int0s",
          string.format("$(%s.mods:%%=$(int0s_subdir)%%.int0)",
@@ -2269,7 +2270,6 @@ generate_dep_file_install_targets(Globals, ModuleName, DepsMap,
          MaybeSpaceOptStr = ""
      ),
      ( if
-        Intermod = yes,
          some [BurdenedModule] (
              map.member(DepsMap, _, deps(_, BurdenedModule)),
              ParseTreeModuleSrc = BurdenedModule ^ bm_module,
@@ -2277,8 +2277,8 @@ generate_dep_file_install_targets(Globals, ModuleName, DepsMap,
              not map.is_empty(IncludeMap)
          )
      then
-        % The `.int0' files only need to be installed with
-        % `--intermodule-optimization'.
+        % We always install `.int0' files; see the comment in the body of
+        % make.program_target.install_ints_and_headers/8 for the reason why.
          SpaceInt0Str = " int0",
          ModuleVarNameInt0s = "$(" ++ ModuleMakeVarName ++ ".int0s)",
          MaybeModuleVarNameInt0sSpace = ModuleVarNameInt0s ++ " ",


More information about the reviews mailing list