[m-rev.] diff: clean ups related to searching for files

Peter Wang novalazy at gmail.com
Fri Jul 31 16:00:12 AEST 2009


Branches: main

compiler/file_util.m:
        Add search_for_file_mod_time which returns the last modification time
        of the found file.

        Add parameters to search_for_file and search_for_file_returning_dir
        that chooses whether the found file should be left open as the input
        stream on success.

        Avoid dir.make_path_name where possible as it is slow.

compiler/make.util.m:
        Use search_for_file_mod_time instead of something complicated.

compiler/file_names.m:
        Make file_is_arch_or_grade_dependent not consider further clauses after
        stripping the ".tmp" suffix off a filename.

compiler/compile_target_code.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
compiler/mercury_compile.m:
compiler/mmc_analysis.m:
compiler/module_cmds.m:
compiler/options_file.m:
compiler/prog_io.m:
compiler/read_modules.m:
compiler/write_deps_file.m:
        Conform to changes.

diff --git a/compiler/compile_target_code.m b/compiler/compile_target_code.m
index 1fd804d..471f3c9 100644
--- a/compiler/compile_target_code.m
+++ b/compiler/compile_target_code.m
@@ -2273,14 +2273,11 @@ process_link_library(MercuryLibDirs, LibName, LinkerOpt, !Succeeded, !IO) :-
             do_not_create_dirs, LibFileName, !IO),
         globals.io_set_option(use_grade_subdirs, bool(UseGradeSubdirs), !IO),
 
-        io.input_stream(InputStream, !IO),
-        search_for_file_returning_dir(MercuryLibDirs, LibFileName,
-            SearchResult, !IO),
+        search_for_file_returning_dir(do_not_open_file, MercuryLibDirs,
+            LibFileName, SearchResult, !IO),
         (
             SearchResult = ok(DirName),
-            LinkerOpt = DirName/LibFileName,
-            io.set_input_stream(InputStream, LibInputStream, !IO),
-            io.close_input(LibInputStream, !IO)
+            LinkerOpt = DirName/LibFileName
         ;
             SearchResult = error(Error),
             LinkerOpt = "",
diff --git a/compiler/file_names.m b/compiler/file_names.m
index 4a4ffbf..77466d9 100644
--- a/compiler/file_names.m
+++ b/compiler/file_names.m
@@ -1,7 +1,7 @@
 %-----------------------------------------------------------------------------%
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
-% Copyright (C) 2008 The University of Melbourne.
+% Copyright (C) 2008-2009 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
@@ -506,29 +506,12 @@ get_class_dir_name(ClassDirName, !IO) :-
 file_is_arch_or_grade_dependent(_, Ext) :-
     file_is_arch_or_grade_dependent_2(Ext).
 file_is_arch_or_grade_dependent(Globals, Ext0) :-
-    string.append(Ext, ".tmp", Ext0), % for mercury_update_interface.
-    file_is_arch_or_grade_dependent(Globals, Ext).
-file_is_arch_or_grade_dependent(Globals, Ext) :-
-    globals.lookup_string_option(Globals, executable_file_extension, Ext).
-file_is_arch_or_grade_dependent(Globals, Ext) :-
-    (
-        globals.lookup_string_option(Globals,
-            object_file_extension, ObjExt)
-    ;
-        globals.lookup_string_option(Globals,
-            pic_object_file_extension, ObjExt)
+    % for mercury_update_interface
+    ( string.remove_suffix(Ext0, ".tmp", Ext) ->
+        file_is_arch_or_grade_dependent(Globals, Ext)
     ;
-        globals.lookup_string_option(Globals,
-            link_with_pic_object_file_extension, ObjExt)
-    ),
-    ( Ext = ObjExt
-    ; Ext = "_init" ++ ObjExt
+        file_is_arch_or_grade_dependent_3(Globals, Ext0)
     ).
-file_is_arch_or_grade_dependent(Globals, Ext) :-
-    globals.lookup_string_option(Globals, library_extension, LibExt),
-    Ext = LibExt.
-file_is_arch_or_grade_dependent(Globals, Ext) :-
-    globals.lookup_string_option(Globals, shared_library_extension, Ext).
 
 :- pred file_is_arch_or_grade_dependent_2(string::in) is semidet.
 
@@ -573,6 +556,33 @@ file_is_arch_or_grade_dependent_2("_init.$O").
 file_is_arch_or_grade_dependent_2("_init.erl").
 file_is_arch_or_grade_dependent_2("_init.beam").
 
+:- pred file_is_arch_or_grade_dependent_3(globals::in, string::in) is semidet.
+
+file_is_arch_or_grade_dependent_3(Globals, Ext) :-
+    (
+        globals.lookup_string_option(Globals, executable_file_extension, Ext)
+    ;
+        globals.lookup_string_option(Globals, library_extension, Ext)
+    ;
+        globals.lookup_string_option(Globals, shared_library_extension, Ext)
+    ).
+file_is_arch_or_grade_dependent_3(Globals, Ext) :-
+    (
+        globals.lookup_string_option(Globals,
+            object_file_extension, ObjExt)
+    ;
+        globals.lookup_string_option(Globals,
+            pic_object_file_extension, ObjExt)
+    ;
+        globals.lookup_string_option(Globals,
+            link_with_pic_object_file_extension, ObjExt)
+    ),
+    (
+        Ext = ObjExt
+    ;
+        Ext = "_init" ++ ObjExt
+    ).
+
 %-----------------------------------------------------------------------------%
 
 :- func this_file = string.
diff --git a/compiler/file_util.m b/compiler/file_util.m
index a7403ec..02955c7 100644
--- a/compiler/file_util.m
+++ b/compiler/file_util.m
@@ -1,7 +1,7 @@
 %-----------------------------------------------------------------------------e
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------e
-% Copyright (C) 2008 The University of Melbourne.
+% Copyright (C) 2008-2009 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
@@ -20,6 +20,7 @@
 :- import_module io.
 :- import_module list.
 :- import_module maybe.
+:- import_module time.
 
 %-----------------------------------------------------------------------------%
 
@@ -29,24 +30,42 @@
     % Open a source or interface file, returning `ok(FileInfo)' on success
     % (where FileInfo is information about the file such as the file name
     % or the directory in which it was found), or `error(Message)' on failure.
-:- type open_file(FileInfo) == pred(maybe_error(FileInfo), io, io).
-:- inst open_file == (pred(out, di, uo) is det).
+:- type open_file_pred(FileInfo) == pred(maybe_error(FileInfo), io, io).
+:- inst open_file_pred == (pred(out, di, uo) is det).
 
-    % search_for_file(Dirs, FileName, FoundFileName, !IO):
+:- type maybe_open_file
+    --->    open_file
+    ;       do_not_open_file.
+
+    % search_for_file(MaybeOpen, Dirs, FileName, FoundFileName, !IO):
+    %
+    % Search Dirs for FileName, returning the path name of the file that was
+    % found.  If requested, the found file will be left
+    % open as the current input stream.
     %
-    % Search Dirs for FileName, opening the file if it is found,
-    % and returning the path name of the file that was found.
+    % NB. Consider using search_for_file_returning_dir, which does not
+    % canonicalise the path so is more efficient.
     %
-:- pred search_for_file(list(dir_name)::in, file_name::in,
+:- pred search_for_file(maybe_open_file::in, list(dir_name)::in, file_name::in,
     maybe_error(file_name)::out, io::di, io::uo) is det.
 
-    % search_for_file_returning_dir(Dirs, FileName, FoundDirName, !IO):
+    % search_for_file_returning_dir(MaybeOpen, Dirs, FileName, FoundDirName,
+    %   !IO):
+    %
+    % Search Dirs for FileName, returning the name of the directory in
+    % which the file was found.  If requested, the found file will be left
+    % open as the current input stream.
+    %
+:- pred search_for_file_returning_dir(maybe_open_file::in, list(dir_name)::in,
+    file_name::in, maybe_error(dir_name)::out, io::di, io::uo) is det.
+
+    % search_for_file_mod_time(Dirs, FileName, FoundModTime, !IO)
     %
-    % Search Dirs for FileName, opening the file if it is found, and returning
-    % the name of the directory in which the file was found.
+    % Search Dirs for FileName, returning the last modification time of the
+    % file that was found.  Does NOT open the file for reading.
     %
-:- pred search_for_file_returning_dir(list(dir_name)::in, file_name::in,
-    maybe_error(dir_name)::out, io::di, io::uo) is det.
+:- pred search_for_file_mod_time(list(dir_name)::in, file_name::in,
+    maybe_error(time_t)::out, io::di, io::uo) is det.
 
 %-----------------------------------------------------------------------------%
 
@@ -94,13 +113,14 @@
 :- import_module libs.handle_options.
 :- import_module libs.options.
 
+:- import_module char.
 :- import_module dir.
 :- import_module string.
 
 %-----------------------------------------------------------------------------%
 
-search_for_file(Dirs, FileName, Result, !IO) :-
-    search_for_file_returning_dir(Dirs, FileName, Result0, !IO),
+search_for_file(MaybeOpen, Dirs, FileName, Result, !IO) :-
+    search_for_file_returning_dir(MaybeOpen, Dirs, FileName, Result0, !IO),
     (
         Result0 = ok(Dir),
         ( dir.this_directory(Dir) ->
@@ -114,8 +134,9 @@ search_for_file(Dirs, FileName, Result, !IO) :-
         Result = error(Message)
     ).
 
-search_for_file_returning_dir(Dirs, FileName, Result, !IO) :-
-    search_for_file_returning_dir_2(Dirs, FileName, MaybeDir, !IO),
+search_for_file_returning_dir(MaybeOpen, Dirs, FileName, Result, !IO) :-
+    do_search_for_file(check_file_return_dir(MaybeOpen), Dirs, FileName,
+        MaybeDir, !IO),
     (
         MaybeDir = yes(Dir),
         Result = ok(Dir)
@@ -126,23 +147,73 @@ search_for_file_returning_dir(Dirs, FileName, Result, !IO) :-
         Result = error(Msg)
     ).
 
-:- pred search_for_file_returning_dir_2(list(dir_name)::in,
-    file_name::in, maybe(dir_name)::out, io::di, io::uo) is det.
+:- pred check_file_return_dir(maybe_open_file::in, dir_name::in, file_name::in,
+    io.res(dir_name)::out, io::di, io::uo) is det.
 
-search_for_file_returning_dir_2([], _FileName, no, !IO).
-search_for_file_returning_dir_2([Dir | Dirs], FileName, MaybeDir, !IO) :-
-    ( dir.this_directory(Dir) ->
-        ThisFileName = FileName
+check_file_return_dir(MaybeOpen, Dir, FileName, Result, !IO) :-
+    make_path_name_noncanon(Dir, FileName, PathName),
+    io.open_input(PathName, OpenResult, !IO),
+    (
+        OpenResult = ok(Stream),
+        (
+            MaybeOpen = open_file,
+            io.set_input_stream(Stream, _, !IO)
+        ;
+            MaybeOpen = do_not_open_file,
+            io.close_input(Stream, !IO)
+        ),
+        Result = ok(Dir)
     ;
-        ThisFileName = dir.make_path_name(Dir, FileName)
-    ),
-    io.see(ThisFileName, SeeResult0, !IO),
+        OpenResult = error(Error),
+        Result = error(Error)
+    ).
+
+search_for_file_mod_time(Dirs, FileName, Result, !IO) :-
+    do_search_for_file(check_file_mod_time, Dirs, FileName, MaybeTime, !IO),
+    (
+        MaybeTime = yes(Time),
+        Result = ok(Time)
+    ;
+        MaybeTime = no,
+        Msg = "cannot find `" ++ FileName ++ "' in directories " ++
+            string.join_list(", ", Dirs),
+        Result = error(Msg)
+    ).
+
+:- pred check_file_mod_time(dir_name::in, file_name::in, io.res(time_t)::out,
+    io::di, io::uo) is det.
+
+check_file_mod_time(Dir, FileName, Result, !IO) :-
+    make_path_name_noncanon(Dir, FileName, PathName),
+    io.file_modification_time(PathName, Result, !IO).
+
+:- pred do_search_for_file(
+    pred(dir_name, file_name, io.res(T), io, io)
+        ::in(pred(in, in, out, di, uo) is det),
+    list(dir_name)::in, file_name::in, maybe(T)::out, io::di, io::uo) is det.
+
+do_search_for_file(_P, [], _FileName, no, !IO).
+do_search_for_file(P, [Dir | Dirs], FileName, Result, !IO) :-
+    P(Dir, FileName, Result0, !IO),
     (
-        SeeResult0 = ok,
-        MaybeDir = yes(Dir)
+        Result0 = ok(TimeT),
+        Result = yes(TimeT)
+    ;
+        Result0 = error(_),
+        do_search_for_file(P, Dirs, FileName, Result, !IO)
+    ).
+
+:- pred make_path_name_noncanon(dir_name::in, file_name::in, file_name::out)
+    is det.
+
+make_path_name_noncanon(Dir, FileName, PathName) :-
+    ( dir.this_directory(Dir) ->
+        PathName = FileName
     ;
-        SeeResult0 = error(_),
-        search_for_file_returning_dir_2(Dirs, FileName, MaybeDir, !IO)
+        % dir.make_path_name is slow so we avoid it when path names don't
+        % need to be canonicalised.
+        Sep = string.from_char(dir.directory_separator),
+        PathName = string.append_list([Dir, Sep, FileName])
     ).
 
 %-----------------------------------------------------------------------------%
diff --git a/compiler/make.module_dep_file.m b/compiler/make.module_dep_file.m
index e8fc7d7..d0a6259 100644
--- a/compiler/make.module_dep_file.m
+++ b/compiler/make.module_dep_file.m
@@ -1,7 +1,7 @@
 %-----------------------------------------------------------------------------%
 % vim: ft=mercury ts=4 sw=4 expandtab
 %-----------------------------------------------------------------------------%
-% Copyright (C) 2002-2008 The University of Melbourne.
+% Copyright (C) 2002-2009 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
@@ -381,8 +381,8 @@ read_module_dependencies_2(RebuildModuleDeps, SearchDirs, ModuleName, !Info,
     module_name_to_search_file_name(ModuleName, make_module_dep_file_extension,
         ModuleDepFile, !IO),
     io.input_stream(OldInputStream, !IO),
-    search_for_file_returning_dir(SearchDirs, ModuleDepFile, SearchResult,
-        !IO),
+    search_for_file_returning_dir(open_file, SearchDirs, ModuleDepFile,
+        SearchResult, !IO),
     (
         SearchResult = ok(ModuleDir),
         parser.read_term(ImportsTermResult, !IO),
diff --git a/compiler/make.program_target.m b/compiler/make.program_target.m
index 590e5d2..9d20c31 100644
--- a/compiler/make.program_target.m
+++ b/compiler/make.program_target.m
@@ -2069,11 +2069,10 @@ check_library_is_installed(Dirs, Grade, LibName, !Succeeded, !IO) :-
     % whether its .init file exists.  This will work because all libraries
     % have a grade dependent .init file.
     InitFileName = LibName ++ ".init",
-    search_for_file(Dirs, InitFileName, SearchResult, !IO),
+    search_for_file_returning_dir(do_not_open_file, Dirs, InitFileName,
+        SearchResult, !IO),
     (
-        SearchResult = ok(_),
-        % search_for_file/5 has opened the file, so close it.
-        io.seen(!IO)
+        SearchResult = ok(_)
     ;
         SearchResult = error(_),
         io.stderr_stream(Stderr, !IO),
diff --git a/compiler/make.util.m b/compiler/make.util.m
index c95e4c0..11e48e5 100644
--- a/compiler/make.util.m
+++ b/compiler/make.util.m
@@ -1252,24 +1252,12 @@ get_file_timestamp(SearchDirs, FileName, MaybeTimestamp, !Info, !IO) :-
     ( MaybeTimestamp0 = !.Info ^ file_timestamps ^ elem(FileName) ->
         MaybeTimestamp = MaybeTimestamp0
     ;
-        io.input_stream(OldInputStream, !IO),
-        search_for_file(SearchDirs, FileName, SearchResult, !IO),
+        search_for_file_mod_time(SearchDirs, FileName, SearchResult, !IO),
         (
-            SearchResult = ok(_),
-            io.input_stream_name(FullFileName, !IO),
-            io.set_input_stream(OldInputStream, FileStream, !IO),
-            io.close_input(FileStream, !IO),
-            io.file_modification_time(FullFileName, TimeTResult, !IO),
-            (
-                TimeTResult = ok(TimeT),
-                Timestamp = time_t_to_timestamp(TimeT),
-                MaybeTimestamp = ok(Timestamp)
-            ;
-                TimeTResult = error(Error),
-                MaybeTimestamp = error(io.error_message(Error))
-            ),
-            !:Info = !.Info ^ file_timestamps ^ elem(FileName)
-                := MaybeTimestamp
+            SearchResult = ok(TimeT),
+            Timestamp = time_t_to_timestamp(TimeT),
+            MaybeTimestamp = ok(Timestamp),
+            !Info ^ file_timestamps ^ elem(FileName) := MaybeTimestamp
         ;
             SearchResult = error(_),
             MaybeTimestamp = error("file `" ++ FileName ++ "' not found")
diff --git a/compiler/mercury_compile.m b/compiler/mercury_compile.m
index c8ab910..2685cd1 100644
--- a/compiler/mercury_compile.m
+++ b/compiler/mercury_compile.m
@@ -2431,11 +2431,11 @@ maybe_write_optfile(MakeOptInt, !HLDS, !DumpInfo, !IO) :-
         ; UseOptFiles = yes ->
             module_info_get_name(!.HLDS, ModuleName),
             module_name_to_search_file_name(ModuleName, ".opt", OptName, !IO),
-            search_for_file(IntermodDirs, OptName, Found, !IO),
+            search_for_file_returning_dir(do_not_open_file, IntermodDirs,
+                OptName, Found, !IO),
             (
                 Found = ok(_),
-                UpdateStatus = yes,
-                io.seen(!IO)
+                UpdateStatus = yes
             ;
                 Found = error(_),
                 UpdateStatus = no
diff --git a/compiler/mmc_analysis.m b/compiler/mmc_analysis.m
index 7f39f7e..71c41ea 100644
--- a/compiler/mmc_analysis.m
+++ b/compiler/mmc_analysis.m
@@ -1,7 +1,7 @@
 %-----------------------------------------------------------------------------%
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
-% Copyright (C) 2003-2006, 2008 The University of Melbourne.
+% Copyright (C) 2003-2006, 2008-2009 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
@@ -116,14 +116,7 @@
 mmc_module_name_to_read_file_name(ModuleName, Ext, MaybeFileName, !IO) :-
     module_name_to_search_file_name(ModuleName, Ext, FileName0, !IO),
     globals.io_lookup_accumulating_option(intermod_directories, Dirs, !IO),
-    search_for_file(Dirs, FileName0, MaybeFileName, !IO),
-    (
-        MaybeFileName = ok(_),
-        % `search_for_file' actually opens the file.
-        io.seen(!IO)
-    ;
-        MaybeFileName = error(_)
-    ).
+    search_for_file(do_not_open_file, Dirs, FileName0, MaybeFileName, !IO).
 
 :- pred mmc_module_name_to_write_file_name(module_name::in, string::in,
     string::out, io::di, io::uo) is det.
diff --git a/compiler/module_cmds.m b/compiler/module_cmds.m
index 17adb97..e841f83 100644
--- a/compiler/module_cmds.m
+++ b/compiler/module_cmds.m
@@ -1,7 +1,7 @@
 %-----------------------------------------------------------------------------%
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
-% Copyright (C) 2008 The University of Melbourne.
+% Copyright (C) 2008-2009 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
@@ -937,14 +937,11 @@ find_erlang_library_path(MercuryLibDirs, LibName, LibPath, !Succeeded, !IO) :-
         do_not_create_dirs, LibFileName, !IO),
     globals.io_set_option(use_grade_subdirs, bool(UseGradeSubdirs), !IO),
 
-    io.input_stream(InputStream, !IO),
-    search_for_file_returning_dir(MercuryLibDirs, LibFileName,
-        SearchResult, !IO),
+    search_for_file_returning_dir(do_not_open_file, MercuryLibDirs,
+        LibFileName, SearchResult, !IO),
     (
         SearchResult = ok(DirName),
-        LibPath = DirName/LibFileName,
-        io.set_input_stream(InputStream, LibInputStream, !IO),
-        io.close_input(LibInputStream, !IO)
+        LibPath = DirName/LibFileName
     ;
         SearchResult = error(Error),
         LibPath = "",
diff --git a/compiler/options_file.m b/compiler/options_file.m
index f542f97..90a54a0 100644
--- a/compiler/options_file.m
+++ b/compiler/options_file.m
@@ -1,7 +1,7 @@
 %-----------------------------------------------------------------------------%
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
-% Copyright (C) 2002-2008 The University of Melbourne.
+% Copyright (C) 2002-2009 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
@@ -260,7 +260,8 @@ read_options_file_params(ErrorIfNotExist, Search, MaybeDirName, OptionsFile0,
             FileToFind = OptionsFile0
         ),
         io.input_stream(OldInputStream, !IO),
-        search_for_file_returning_dir(Dirs, FileToFind, MaybeDir, !IO),
+        search_for_file_returning_dir(open_file, Dirs, FileToFind, MaybeDir,
+            !IO),
         (
             MaybeDir = ok(FoundDir),
             debug_msg(write_reading_options_file(FoundDir/FileToFind), !IO),
diff --git a/compiler/prog_io.m b/compiler/prog_io.m
index 5fc8a3a..b1206ff 100644
--- a/compiler/prog_io.m
+++ b/compiler/prog_io.m
@@ -1,7 +1,7 @@
 %-----------------------------------------------------------------------------e
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------e
-% Copyright (C) 1993-2008 The University of Melbourne.
+% Copyright (C) 1993-2009 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
@@ -89,12 +89,12 @@
     % DefaultModuleName if there is no `:- module' declaration.
     % Specs is a list of warning/error messages. Program is the parse tree.
     %
-:- pred read_module(open_file(FileInfo)::in(open_file),
+:- pred read_module(open_file_pred(FileInfo)::in(open_file_pred),
     module_name::in, maybe_return_timestamp::in, maybe(FileInfo)::out,
     module_name::out, list(item)::out, list(error_spec)::out,
     module_error::out, maybe(io.res(timestamp))::out, io::di, io::uo) is det.
 
-:- pred read_module_if_changed(open_file(FileInfo)::in(open_file),
+:- pred read_module_if_changed(open_file_pred(FileInfo)::in(open_file_pred),
     module_name::in, timestamp::in, maybe(FileInfo)::out, module_name::out,
     list(item)::out, list(error_spec)::out, module_error::out,
     maybe(io.res(timestamp))::out, io::di, io::uo) is det.
@@ -228,8 +228,9 @@ read_module_if_changed(OpenFile, DefaultModuleName, OldTimestamp, FileData,
 
 read_opt_file(FileName, DefaultModuleName, Items, Specs, Error, !IO) :-
     globals.io_lookup_accumulating_option(intermod_directories, Dirs, !IO),
-    read_module_2(search_for_file(Dirs, FileName), DefaultModuleName, no,
-        do_not_return_timestamp, _, ModuleName, Items, Specs, Error, _, !IO),
+    read_module_2(search_for_file(open_file, Dirs, FileName),
+        DefaultModuleName, no, do_not_return_timestamp, _, ModuleName, Items,
+        Specs, Error, _, !IO),
     check_module_has_expected_name(FileName, DefaultModuleName, ModuleName,
         !IO).
 
@@ -252,7 +253,7 @@ check_module_has_expected_name(FileName, ExpectedName, ActualName, !IO) :-
     % and then reverse them afterwards. (Using difference lists would require
     % late-input modes.)
     %
-:- pred read_module_2(open_file(T)::in(open_file), module_name::in,
+:- pred read_module_2(open_file_pred(T)::in(open_file_pred), module_name::in,
     maybe(timestamp)::in, maybe_return_timestamp::in, maybe(T)::out,
     module_name::out, list(item)::out, list(error_spec)::out,
     module_error::out, maybe(io.res(timestamp))::out, io::di, io::uo) is det.
@@ -355,13 +356,8 @@ search_for_module_source(Dirs, InterfaceDirs, ModuleName, MaybeFileName,
             ;
                 module_name_to_file_name(ModuleName, ".int",
                     do_not_create_dirs, IntFile, !IO),
-                search_for_file_returning_dir(InterfaceDirs, IntFile,
-                    MaybeIntDir, !IO),
-                ( MaybeIntDir = ok(_) ->
-                    io.seen(!IO)
-                ;
-                    true
-                ),
+                search_for_file_returning_dir(do_not_open_file, InterfaceDirs,
+                    IntFile, MaybeIntDir, !IO),
                 (
                     MaybeIntDir = ok(IntDir),
                     IntDir \= dir.this_directory
@@ -405,7 +401,7 @@ search_for_module_source_2(Dirs, ModuleName, PartialModuleName, MaybeFileName,
         !IO) :-
     module_name_to_file_name(PartialModuleName, ".m", do_not_create_dirs,
         FileName, !IO),
-    search_for_file(Dirs, FileName, MaybeFileName0, !IO),
+    search_for_file(open_file, Dirs, FileName, MaybeFileName0, !IO),
     (
         MaybeFileName0 = ok(_),
         MaybeFileName = MaybeFileName0
diff --git a/compiler/read_modules.m b/compiler/read_modules.m
index 34d8e3c..f033072 100644
--- a/compiler/read_modules.m
+++ b/compiler/read_modules.m
@@ -1,7 +1,7 @@
 %-----------------------------------------------------------------------------%
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
-% Copyright (C) 1996-2008 The University of Melbourne.
+% Copyright (C) 1996-2009 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
@@ -199,7 +199,7 @@ do_read_module(IgnoreErrors, ModuleName, Extension, Descr, Search,
         OpenFile = search_for_module_source(SearchDirs,
             InterfaceSearchDirs, ModuleName)
     ;
-        OpenFile = search_for_file(SearchDirs, FileName0)
+        OpenFile = search_for_file(open_file, SearchDirs, FileName0)
     ),
     (
         MaybeOldTimestamp = yes(OldTimestamp),
@@ -276,7 +276,7 @@ read_module_from_file(FileName, Extension, Descr, Search, ReturnTimestamp,
         Search = do_not_search,
         SearchDirs = [dir.this_directory]
     ),
-    OpenFile = search_for_file(SearchDirs, FullFileName),
+    OpenFile = search_for_file(open_file, SearchDirs, FullFileName),
     prog_io.read_module(OpenFile, DefaultModuleName, ReturnTimestamp,
         _, ModuleName, Items, Specs, Error, MaybeTimestamp0, !IO),
     check_timestamp(FullFileName, MaybeTimestamp0, MaybeTimestamp, !IO),
diff --git a/compiler/write_deps_file.m b/compiler/write_deps_file.m
index afe392c..8b2dba3 100644
--- a/compiler/write_deps_file.m
+++ b/compiler/write_deps_file.m
@@ -1,7 +1,7 @@
 %-----------------------------------------------------------------------------%
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
-% Copyright (C) 2008 The University of Melbourne.
+% Copyright (C) 2008-2009 The University of Melbourne.
 % This file may only be copied under the terms of the GNU General
 % Public License - see the file COPYING in the Mercury distribution.
 %-----------------------------------------------------------------------------%
@@ -2358,21 +2358,21 @@ get_both_opt_deps(BuildOptFiles, [Dep | Deps], IntermodDirs,
         Found = no,
         module_name_to_file_name(Dep, ".opt", do_not_create_dirs,
             OptName, !IO),
-        search_for_file(IntermodDirs, OptName, Result2, !IO),
+        search_for_file_returning_dir(do_not_open_file, IntermodDirs,
+            OptName, Result2, !IO),
         (
             Result2 = ok(_),
-            !:OptDeps = [Dep | !.OptDeps],
-            io.seen(!IO)
+            !:OptDeps = [Dep | !.OptDeps]
         ;
             Result2 = error(_)
         ),
         module_name_to_file_name(Dep, ".trans_opt", do_not_create_dirs,
             TransOptName, !IO),
-        search_for_file(IntermodDirs, TransOptName, Result3, !IO),
+        search_for_file_returning_dir(do_not_open_file, IntermodDirs,
+            TransOptName, Result3, !IO),
         (
             Result3 = ok(_),
-            !:TransOptDeps = [Dep | !.TransOptDeps],
-            io.seen(!IO)
+            !:TransOptDeps = [Dep | !.TransOptDeps]
         ;
             Result3 = error(_)
         )
@@ -2404,11 +2404,10 @@ get_opt_deps(BuildOptFiles, [Dep | Deps], IntermodDirs, Suffix, !:OptDeps,
     (
         Found = no,
         module_name_to_search_file_name(Dep, Suffix, OptName, !IO),
-        search_for_file(IntermodDirs, OptName, Result2, !IO),
+        search_for_file(do_not_open_file, IntermodDirs, OptName, Result2, !IO),
         (
             Result2 = ok(_),
-            !:OptDeps = [Dep | !.OptDeps],
-            io.seen(!IO)
+            !:OptDeps = [Dep | !.OptDeps]
         ;
             Result2 = error(_)
         )

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list