diff mbox series

[fortran] Add -fwrite-module-files option

Message ID 69b6de3d-7df0-bc43-5b89-3e830b0b9c0f@netcologne.de
State New
Headers show
Series [fortran] Add -fwrite-module-files option | expand

Commit Message

Thomas Koenig Jan. 13, 2019, 10:28 p.m. UTC
Hello world,

the attached patch adds a -fwrite-module-files options, but the main
point is that it adds its opposite, -fno-write-module-files.

This has advantages in parallel compiling, as it is quite fast to
generate a module file with -fsyntax-only, and a subsequent
compilation with -fno-write-module-files will not overwrite this.

Yes, submodules also address some of the same issues.

For details, see the PR.

Regression-tested. Documentation tested with "make info",
"make dvi" and "make pdf".  Test case... well, it works
when run by hand, and I'm not sure how to check
for the presence or absence of a module file in dejagnu.

OK for trunk?

Regards

	Thomas

2019-01-13  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/82215
         * invoke.texi: Document -fwrite-module-files.
         * lang.opt: Add -fwrite-module-files.
         * parse.c (gfc_parse_file): Write module only if
         -f-write-module-files is in effect.

Comments

Steve Kargl Jan. 14, 2019, 1:12 a.m. UTC | #1
On Sun, Jan 13, 2019 at 11:28:00PM +0100, Thomas Koenig wrote:
> 
> the attached patch adds a -fwrite-module-files options, but the main
> point is that it adds its opposite, -fno-write-module-files.
> 
> This has advantages in parallel compiling, as it is quite fast to
> generate a module file with -fsyntax-only, and a subsequent
> compilation with -fno-write-module-files will not overwrite this.

A worker checks out a copy of the code from the community
source repository.  At the same time, her coworker checks
the same revision.  She then works for a week on the project
and adds new public routines to a module.  She checks her 
work into the master repositrory.  Meanwhile, her coworker
used -fsyntax-only to generate module files, and then added
the -fno-write-module-files option in his local Makefiles.
He now syncs his local sources with the repository.  If
-fno-write-module-files prevents writing a module file,
how do the new interfaces magically appear.  There isn't
a magic bullet for proper dependencies with parallel
compiling.
Thomas Koenig Jan. 14, 2019, 7:25 a.m. UTC | #2
Hi Steve,

> On Sun, Jan 13, 2019 at 11:28:00PM +0100, Thomas Koenig wrote:
>>
>> the attached patch adds a -fwrite-module-files options, but the main
>> point is that it adds its opposite, -fno-write-module-files.
>>
>> This has advantages in parallel compiling, as it is quite fast to
>> generate a module file with -fsyntax-only, and a subsequent
>> compilation with -fno-write-module-files will not overwrite this.
> 
> A worker checks out a copy of the code from the community
> source repository.  At the same time, her coworker checks
> the same revision.  She then works for a week on the project
> and adds new public routines to a module.  She checks her
> work into the master repositrory.  Meanwhile, her coworker
> used -fsyntax-only to generate module files, and then added
> the -fno-write-module-files option in his local Makefiles.
> He now syncs his local sources with the repository.  If
> -fno-write-module-files prevents writing a module file,
> how do the new interfaces magically appear.  There isn't
> a magic bullet for proper dependencies with parallel
> compiling.

I agree there is a possibility for misuse, which is why I put

"When code has been changed and
@option{-fno-write-module-files} is used, it is possible to generate
inconsistent module files, which will lead to hard-to-find bugs. Use
with care." into the documentation.

Still, if changing basic compilation methology is not communicated
among team members who may be affected, I whould say that this
is a severe case of project management failure, not a compiler
problem, and I do see a legitimate use case for this.

Regards

	Thomas
diff mbox series

Patch

Index: invoke.texi
===================================================================
--- invoke.texi	(Revision 267903)
+++ invoke.texi	(Arbeitskopie)
@@ -102,6 +102,7 @@  one is not the default.
                         and register usage.
 * Interoperability Options::  Options for interoperability with other
                               languages.
+* File Output Options:: Which files the compiler generates during compilation.
 * Environment Variables:: Environment variables that affect @command{gfortran}.
 @end menu
 
@@ -178,6 +179,10 @@  and warnings}.
 @xref{Interoperability Options,,Options for interoperability}.
 @gccoptlist{-fc-prototypes}
 
+@item File Output Options
+@xref{File Output Options,,Options for determining output of files}.
+@gccoptlist{-fwrite-module-files}
+
 @item Code Generation Options
 @xref{Code Gen Options,,Options for code generation conventions}.
 @gccoptlist{-faggressive-function-elimination -fblas-matmul-limit=@var{n} @gol
@@ -791,9 +796,12 @@  messages produced.
 @item -fsyntax-only
 @opindex @code{fsyntax-only}
 @cindex syntax checking
-Check the code for syntax errors, but do not actually compile it.  This
-will generate module files for each module present in the code, but no
-other output file.
+Check the code for syntax errors, but do not actually compile it.
+This will generate module files for each module present in the code,
+but no other output file.  Using this option, it is possible to
+generate module files much faster.  Together with the
+@option{-fwrite-module-files} options, it can be used for speeding up
+compilation processes.
 
 @item -Wpedantic
 @itemx -pedantic
@@ -1865,6 +1873,44 @@  where the C code intended for interoperating with
 then  uses @code{#include "foo.h"}.
 @end table
 
+@node File Output Options
+@section Which files the compiler generates during compilation
+
+@table @asis
+
+@item -fwrite-module-files
+@opindex @code{write-module-files}
+@cindex Writing out module files
+This option will write out a @file{foo.mod} file when the module
+@code{foo} has been successfully compiled.  This file will be read in
+later when @code{use foo} is encountered in the code.
+Writing out the file is the default.
+
+The negative form, @option{-fno-write-module-files}, supresses writing
+of module files.  This can be useful when the module files have
+previously been generated with @option{-fsyntax-only}, for example to
+support a more parallel make process.  When code has been changed and
+@option{-fno-write-module-files} is used, it is possible to generate
+inconsistent module files, which will lead to hard-to-find bugs. Use
+with care.
+
+An example of how this could be used is the following Makefile
+snippet.  It assumes that @file{foo.f90} contains a module @code{foo},
+which is used by module @code{bar} in @file{bar.f90}.  This would
+allow parallel compilation of @file{foo.f90} and @file{bar.f90}.
+
+@smallexample
+foo.mod: foo.f90
+         gfortran -fmodule-files=only foo.f90
+
+foo.o: foo.f90
+       gfortran -fmodule-files=no foo.f90
+
+bar.o: bar.f90 foo.mod
+       gfortran -c bar.f90
+@end smallexample
+@end table
+
 @node Environment Variables
 @section Environment variables affecting @command{gfortran}
 @cindex environment variable
Index: lang.opt
===================================================================
--- lang.opt	(Revision 267903)
+++ lang.opt	(Arbeitskopie)
@@ -722,6 +722,10 @@  frepack-arrays
 Fortran Var(flag_repack_arrays)
 Copy array sections into a contiguous block on procedure entry.
 
+fwrite-module-files
+Fortran Var(flag_write_module_files) Init(1)
+Write module files.
+
 fcoarray=
 Fortran RejectNegative Joined Enum(gfc_fcoarray) Var(flag_coarray) Init(GFC_FCOARRAY_NONE)
 -fcoarray=<none|single|lib>	Specify which coarray parallelization should be used.
Index: parse.c
===================================================================
--- parse.c	(Revision 267903)
+++ parse.c	(Arbeitskopie)
@@ -6284,7 +6284,9 @@  loop:
   gfc_get_errors (NULL, &errors);
   if (s.state == COMP_MODULE || s.state == COMP_SUBMODULE)
     {
-      gfc_dump_module (s.sym->name, errors_before == errors);
+      if (flag_write_module_files)
+	gfc_dump_module (s.sym->name, errors_before == errors);
+
       gfc_current_ns->derived_types = gfc_derived_types;
       gfc_derived_types = NULL;
       goto prog_units;