[m-rev.] for review: finer-grained fucntions for configuration information

Julien Fischer jfischer at opturion.com
Sat Sep 9 17:12:09 AEST 2023


For review by Zoltan.

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

Finer-grained functions for configuration information.

library/library.m:
     Add finer-grained functions for returning configuration information.
     Implement the existing version/2 predicate using these new functions.

compiler/handle_options.m:
profiler/mercury_profile.m:
slice/mcov.m:
     Use the new functions.

NEWS.md:
     Announce the new functions.

Julien.

diff --git a/NEWS.md b/NEWS.md
index 89f9f7c..18fbdde 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -479,6 +479,14 @@ Changes to the Mercury standard library
      - pred `have_make_temp_directory/0`
      - pred `get_temp_directory/3`

+### Changes to the `library` module
+
+* The following functions have been added:
+
+    - func `architecture/0`
+    - func `mercury_version/0`
+    - func `package_version/`
+
  ### Changes to the `list` module

  * The following predicates and functions have been added:
diff --git a/compiler/handle_options.m b/compiler/handle_options.m
index ea5e4f7..f93509c 100644
--- a/compiler/handle_options.m
+++ b/compiler/handle_options.m
@@ -3116,7 +3116,7 @@ disable_smart_recompilation(ProgressStream, OptionDescr, !Globals, !IO) :-
  %---------------------------------------------------------------------------%

  display_compiler_version(ProgressStream, !IO) :-
-    library.version(Version, _FullArch),
+    Version = library.mercury_version,
      io.format(ProgressStream, "Mercury Compiler, version %s", [s(Version)],
          !IO),
      Package = library.package_version,
diff --git a/library/library.m b/library/library.m
index e135614..f0aaed9 100644
--- a/library/library.m
+++ b/library/library.m
@@ -21,7 +21,15 @@
      %
  :- pred version(string::out, string::out) is det.

-    % Return the package version.
+    % Return the Mercury version string.
+    %
+:- func mercury_version = string.
+
+    % Return the architecture string.
+    %
+:- func architecture = string.
+
+    % Return the package version string.
      %
  :- func package_version = string.

@@ -227,43 +235,77 @@
  :- import_module term_size_prof_builtin.
  :- import_module test_bitset.

-% version must be implemented using pragma foreign_proc,
-% so we can get at the MR_VERSION and MR_FULLARCH configuration parameters.
-% We can't just generate library.m from library.m.in at configuration time,
-% because that would cause bootstrapping problems: we might not have
-% a working Mercury compiler to compile library.m with.
+%---------------------------------------------------------------------------%

-:- pragma no_inline(pred(library.version/2)).
+version(Version, Fullarch) :-
+    Version = mercury_version,
+    Fullarch = architecture.
+
+%---------------------%
+
+% mercury_version, architecture and package_version must be implemented using
+% pragma foreign_proc, so we can get at the MR_VERSION, MR_FULLARCH and
+% MR_PACKAGE configuration parameters (and their C# and Java equivalents).
+% We cannot just generate library.m from library.m.in at configuration time,
+% because that would cause bootstrapping problems: we might not have a working
+% Mercury compiler to compile library.m with.
+
+:- pragma no_inline(func(mercury_version/0)).

  :- pragma foreign_proc("C",
-    version(Version::out, Fullarch::out),
+    mercury_version = (Version::out),
      [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail],
  "
      MR_ConstString version_string = MR_VERSION;
-    MR_ConstString fullarch_string = MR_FULLARCH;
-
-    // We need to cast away const here, because Mercury declares Version
-    // and Fullarch to have type MR_String, not MR_ConstString.
+    // We need to cast away const here, because Mercury declares Version to
+    // have type MR_String, not MR_ConstString.
      Version = (MR_String) (MR_Word) version_string;
-    Fullarch = (MR_String) (MR_Word) fullarch_string;
  ").

  :- pragma foreign_proc("C#",
-    version(Version::out, Fullarch::out),
+    mercury_version = (Version::out),
      [will_not_call_mercury, promise_pure, thread_safe],
  "
      Version = runtime.Constants.MR_VERSION;
-    Fullarch = runtime.Constants.MR_FULLARCH;
  ").

  :- pragma foreign_proc("Java",
-    version(Version::out, Fullarch::out),
+    mercury_version = (Version::out),
      [will_not_call_mercury, promise_pure, thread_safe],
  "
      Version = jmercury.runtime.Constants.MR_VERSION;
+").
+
+%---------------------%
+
+:- pragma no_inline(func(architecture/0)).
+
+:- pragma foreign_proc("C",
+    architecture = (Fullarch::out),
+    [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail],
+"
+    MR_ConstString fullarch_string = MR_FULLARCH;
+    // We need to cast away const here, because Mercury declares Fullarch to
+    // have type MR_String, not MR_ConstString.
+    Fullarch = (MR_String) (MR_Word) fullarch_string;
+").
+
+:- pragma foreign_proc("C#",
+    architecture = (Fullarch::out),
+    [will_not_call_mercury, promise_pure, thread_safe],
+"
+    Fullarch = runtime.Constants.MR_FULLARCH;
+").
+
+:- pragma foreign_proc("Java",
+    architecture = (Fullarch::out),
+    [will_not_call_mercury, promise_pure, thread_safe],
+"
      Fullarch = jmercury.runtime.Constants.MR_FULLARCH;
  ").

+%---------------------%
+
  :- pragma no_inline(func(package_version/0)).

  :- pragma foreign_proc("C",
@@ -271,6 +313,8 @@
      [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail],
  "
      MR_ConstString package_string = MR_PKGVERSION;
+    // We need to cast away const here, because Mercury declares Package to
+    // have type MR_String, not MR_ConstString.
      Package = (MR_String) (MR_Word) package_string;
  ").

diff --git a/profiler/mercury_profile.m b/profiler/mercury_profile.m
index 3c14c7a..e42be34 100644
--- a/profiler/mercury_profile.m
+++ b/profiler/mercury_profile.m
@@ -92,7 +92,7 @@ postprocess_options(Args, !IO) :-
  :- pred display_version(io.text_output_stream::in, io::di, io::uo) is det.

  display_version(OutputStream, !IO) :-
-    library.version(Version, _FullArch),
+    Version = library.mercury_version,
      io.format(OutputStream, "Mercury profiler, version %s", [s(Version)],
          !IO),
      Package = library.package_version,
diff --git a/slice/mcov.m b/slice/mcov.m
index 8839ca2..aab3ebd 100644
--- a/slice/mcov.m
+++ b/slice/mcov.m
@@ -437,7 +437,7 @@ write_path_port_for_user(OutStream, port_and_path(Port, Path), !IO) :-
  :- pred display_version(io.text_output_stream::in, io::di, io::uo) is det.

  display_version(OutStream, !IO) :-
-    library.version(Version, _FullArch),
+    Version = library.mercury_version,
      io.format(OutStream,
          "Mercury Coverage Testing Tool, version %s",
          [s(Version)], !IO),



More information about the reviews mailing list