[m-rev.] for review: delete old code for invoking the C# compiler

Julien Fischer jfischer at opturion.com
Sun Aug 17 15:10:55 AEST 2025


For review by anyone.

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

Delete old code for invoking the C# compiler.

There are currently two separate predicates used for invoking the C# compiler.
One is in make.module_target and is used to create executables and libraries
in the C# grade. The other is compile_target_code and was previously used
by the old .NET backend to compile additional C# source files. It is currently
plugged into the code that compiles the source files used for fact tables, but
as they are not supported by the C# backed, it has never been used in practice
for this purpose.

Delete the code for invoking the C# compiler in compile_target_code, since it
has no users and is almost certainly affected by bitrot at this point.

compiler/compile_target_code.m:
     Delete the compile_csharp_file/8 predicate. It is unused.

compiler/make.module_target.m:
    Abort if we are requested to build a Java or C# foreign code file.
    The only thing that currently makes such requests is compilation of
    fact tables and neither the Java or C# backend supports those.

    Add an explanation of an issue in an XXX.

compiler/link_target_code.m:
    Add an XXX about the MS C# compiler that needs to be investigated.

Julien.

diff --git a/compiler/compile_target_code.m b/compiler/compile_target_code.m
index 702cd6905..2495bc3f3 100644
--- a/compiler/compile_target_code.m
+++ b/compiler/compile_target_code.m
@@ -10,7 +10,10 @@
 % File: compile_target_code.m.
 % Main authors: fjh, stayl.
 %
-% Code to compile the generated `.c', `.java', etc files.
+% Code to compile the generated `.c' and `.java' files.
+%
+% (This module does *not* handle compilation of `.cs' files; that is done
+% in make.module_target.m.)
 %
 %---------------------------------------------------------------------------%

@@ -25,7 +28,6 @@
 :- import_module mdbcomp.sym_name.
 :- import_module parse_tree.
 :- import_module parse_tree.file_names.
-:- import_module parse_tree.module_dep_info.

 :- import_module bool.
 :- import_module io.
@@ -70,15 +72,6 @@
 :- pred compile_java_files(globals::in, io.text_output_stream::in,
     string::in, list(string)::in, maybe_succeeded::out, io::di, io::uo) is det.

-%---------------------%
-
-    % compile_csharp_file(Globals, ProgressStream, ErrorStream,
-    %   CSharpFile, DLLFile, Succeeded, !IO)
-    %
-:- pred compile_csharp_file(globals::in, io.text_output_stream::in,
-    module_dep_info::in, file_name::in, file_name::in, maybe_succeeded::out,
-    io::di, io::uo) is det.
-
 %---------------------%

     % make_library_init_file(Globals, ProgressStream,
@@ -143,7 +136,7 @@

 %---------------------------------------------------------------------------%
 %
-% used for standalone interfaces.
+% Used for standalone interfaces.
 %

     % make_standalone_interface(Globals, ProgressStream, BaseName, !IO):
@@ -211,13 +204,10 @@
 :- import_module libs.system_cmds.
 :- import_module libs.trace_params.
 :- import_module parse_tree.module_cmds.
-:- import_module parse_tree.prog_data_foreign.
-:- import_module parse_tree.prog_foreign.

 :- import_module dir.
 :- import_module io.file.
 :- import_module require.
-:- import_module set.
 :- import_module string.

 %---------------------------------------------------------------------------%
@@ -651,115 +641,6 @@ is_minus_j_flag(FlagStr) :-

 %---------------------------------------------------------------------------%

-compile_csharp_file(Globals, ProgressStream, ModuleDepInfo,
-        CSharpFileName0, DLLFileName, Succeeded, !IO) :-
-    globals.lookup_bool_option(Globals, verbose, Verbose),
-    (
-        Verbose = no
-    ;
-        Verbose = yes,
-        io.format(ProgressStream, "%% Compiling `%s':\n",
-            [s(CSharpFileName)], !IO)
-    ),
-    globals.lookup_string_option(Globals, csharp_compiler, CSC),
-    globals.lookup_accumulating_option(Globals, csharp_flags, CSCFlagsList),
-    join_string_list(CSCFlagsList, "", "", " ", CSCFlags),
-
-    % XXX This is because the MS C# compiler doesn't understand
-    % / as a directory separator.
-    CSharpFileName = string.replace_all(CSharpFileName0, "/", "\\\\"),
-
-    globals.lookup_bool_option(Globals, target_debug, Debug),
-    (
-        Debug = yes,
-        % XXX This needs testing before it can be enabled (see the comments
-        % for install_debug_library in library/Mmakefile).
-
-        % DebugOpt = "-debug+ -debug:full "
-        DebugOpt = ""
-    ;
-        Debug = no,
-        DebugOpt = ""
-    ),
-
-    % XXX Should we use a separate dll_directories options?
-    % NOTE: we use the -option style options in preference to the /option
-    % style in order to avoid problems with POSIX style shells.
-    globals.lookup_accumulating_option(Globals, link_library_directories,
-        DLLDirs),
-    DLLDirOpts = "-lib:Mercury/dlls " ++
-        string.append_list(list.condense(list.map(
-            (func(DLLDir) = ["-lib:", DLLDir, " "]), DLLDirs))),
-
-    module_dep_info_get_module_name(ModuleDepInfo, ModuleName),
-    ( if mercury_std_library_module_name(ModuleName) then
-        Prefix = "-addmodule:"
-    else
-        Prefix = "-r:"
-    ),
-    module_dep_info_get_fims(ModuleDepInfo, FIMSpes),
-    list.filter_map(
-        ( pred(FS::in, M::out) is semidet :-
-            FS = fim_spec(lang_csharp, _),
-            M = fim_spec_module_name_from_module(FS, ModuleName)
-        ), set.to_sorted_list(FIMSpes), ForeignDeps),
-    module_dep_info_get_int_deps(ModuleDepInfo, IntDeps),
-    module_dep_info_get_imp_deps(ModuleDepInfo, ImpDeps),
-    set.union(IntDeps, ImpDeps, IntImpDeps),
-    set.insert_list(ForeignDeps, IntImpDeps, IntImpForeignDeps),
-    ReferencedDlls = referenced_csharp_dlls(ModuleName, IntImpForeignDeps),
-    list.map(
-        ( pred(Mod::in, Result::out) is det :-
-            % XXX LEGACY
-            module_name_to_file_name(Globals, $pred,
-                ext_cur_gs(ext_cur_gs_lib_cil_dll), Mod,
-                FileName, _FileNameProposed),
-            Result = [Prefix, FileName, " "]
-        ), set.to_sorted_list(ReferencedDlls), ReferencedDllsList),
-    ReferencedDllsStr = string.append_list(
-        list.condense(ReferencedDllsList)),
-
-    string.append_list([CSC, DebugOpt,
-        " -t:library ", DLLDirOpts, CSCFlags, ReferencedDllsStr,
-        " -out:", DLLFileName, " ", CSharpFileName], Command),
-    invoke_system_command(Globals, ProgressStream, ProgressStream,
-        cmd_verbose_commands, Command, Succeeded, !IO).
-
-    % Generate the list of .NET DLLs which could be referred to by this module
-    % (including the module itself).
-    %
-    % If we are compiling a module within the standard library we should
-    % reference the runtime DLLs and all other library DLLs. If we are
-    % outside the library we should just reference mercury.dll (which will
-    % contain all the DLLs).
-    %
-:- func referenced_csharp_dlls(module_name, set(module_name))
-    = set(module_name).
-
-referenced_csharp_dlls(Module, DepModules0) = Modules :-
-    set.insert(Module, DepModules0, DepModules),
-
-    % If we are not compiling a module in the mercury std library, then
-    % replace all the std library dlls with one reference to mercury.dll.
-    ( if mercury_std_library_module_name(Module) then
-        % In the standard library we need to add the runtime dlls.
-        AddedModules =
-            [unqualified("mercury_dotnet"), unqualified("mercury_il")],
-        set.insert_list(AddedModules, DepModules, Modules)
-    else
-        F = ( func(M) =
-                ( if mercury_std_library_module_name(M) then
-                    unqualified("mercury")
-                else
-                    % A sub module is located in the top level assembly.
-                    unqualified(outermost_qualifier(M))
-                )
-            ),
-        Modules = set.map(F, DepModules)
-    ).
-
-%---------------------------------------------------------------------------%
-
 make_library_init_file(Globals, ProgressStream, MainModuleName, AllModules,
         Succeeded, !IO) :-
     globals.lookup_string_option(Globals, mkinit_command, MkInit),
diff --git a/compiler/link_target_code.m b/compiler/link_target_code.m
index 9def9e97a..34d42e8c1 100644
--- a/compiler/link_target_code.m
+++ b/compiler/link_target_code.m
@@ -1377,6 +1377,9 @@ create_exe_or_lib_for_csharp(Globals,
ProgressStream, LinkedTargetType,
     % Older MS C# compilers only allowed \ as the path separator, so we convert
     % all / into \ when using an MS C# compiler on Windows.
     %
+    % XXX do current MS C# compilers still have this behaviour?
+    % - juliensf, 2025-08-17
+    %
 :- func csharp_file_name(env_type, csharp_compiler_type, file_name)
     = file_name.

diff --git a/compiler/make.module_target.m b/compiler/make.module_target.m
index 36aa672a0..bce039083 100644
--- a/compiler/make.module_target.m
+++ b/compiler/make.module_target.m
@@ -479,7 +479,7 @@ build_target_2(ProgressStream, ErrorStream,
Globals, Task, ModuleName,
         % if an interrupt arrives.
         call_in_forked_process(
             compile_foreign_code_file(Globals, ProgressStream, PIC,
-                ModuleDepInfo, FactTableForeignCode),
+                FactTableForeignCode),
             Succeeded, !IO)
     ).

@@ -506,6 +506,11 @@ build_object_code(ProgressStream, ErrorStream,
Globals, Target, PIC,
         % XXX This code uses infrastructure we built for *linking several
         % files* as a way to *compile just one file*. It would be nice
         % to know the reasoning behind that decision.
+        %
+        % The reason for this is that C# has no direct analog of object
+        % or class files, so we have to fake the effect of building an
+        % object file by creating a .dll - juliensf.
+        %
         % XXX LEGACY
         module_name_to_file_name_create_dirs(Globals, $pred,
             ext_cur_ngs_gs(ext_cur_ngs_gs_target_cs),
@@ -520,23 +525,20 @@ build_object_code(ProgressStream, ErrorStream,
Globals, Target, PIC,
     ).

 :- pred compile_foreign_code_file(globals::in, io.text_output_stream::in,
-    pic::in, module_dep_info::in, foreign_code_file::in, maybe_succeeded::out,
-    io::di, io::uo) is det.
+    pic::in, foreign_code_file::in, maybe_succeeded::out, io::di,
io::uo) is det.

-compile_foreign_code_file(Globals, ProgressStream, PIC, ModuleDepInfo,
-        ForeignCodeFile, Succeeded, !IO) :-
+compile_foreign_code_file(Globals, ProgressStream, PIC, ForeignCodeFile,
+        Succeeded, !IO) :-
     (
         ForeignCodeFile = foreign_code_file(lang_c, CFile, ObjFile),
         do_compile_c_file(Globals, ProgressStream, PIC,
             CFile, ObjFile, Succeeded, !IO)
     ;
-        ForeignCodeFile = foreign_code_file(lang_java, JavaFile, _ClassFile),
-        compile_java_files(Globals, ProgressStream, JavaFile, [],
-            Succeeded, !IO)
+        ForeignCodeFile = foreign_code_file(lang_java, _, _),
+        unexpected($pred, "compiling Java foreign code file not supported")
     ;
-        ForeignCodeFile = foreign_code_file(lang_csharp, CSharpFile, DLLFile),
-        compile_csharp_file(Globals, ProgressStream, ModuleDepInfo,
-            CSharpFile, DLLFile, Succeeded, !IO)
+        ForeignCodeFile = foreign_code_file(lang_csharp, _, _),
+        unexpected($pred, "compiling C# foreign code file not supported")
     ).

 :- func do_task_in_separate_process(module_compilation_task_type) = bool.


More information about the reviews mailing list