Created attachment 32558 [details] Code to reproduce issue. Equivalence statements in equivalence statements results in quickly growing number of duplicated statements in nested module files. The attached file shows the issue. Compiled with > gfortran equiv_mod.f90 Resulting module files grow from 3.1 kb to 128 kb. (This issue is somewhat mitigated by compressing modules in latest gfortran, but duplicate statements still exist). The fortran interface to HDF5 is affected by this. In code that uses HDF5 in nested fashion module files can grow to multiple GB in size resulting in ICE when memory is exhausted. May be related to pr 38171. Reproduced in 4.4.7, 4.6.1, 4.8.2 and recent git clone.
> Equivalence statements in equivalence statements Should read "Equivalence statements in modules". Apologies.
> May be related to pr 38171. Rather related to pr40958 comment 13.
Any hope for movement on this? I've made some attempts at diagnosing the issue, but not sure why equivalences behave differently than other statements in the modules.
I have doubled the number of modules to get the following results gcc version 4.8.5 21.907u 0.994s 0:23.00 99.5% 0+0k 0+22io 3pf+0w -rw-r--r-- 1 dominiq staff 2923 Mar 9 10:59 module0.mod -rw-r--r-- 1 dominiq staff 3079 Mar 9 10:59 module1.mod -rw-r--r-- 1 dominiq staff 4230 Mar 9 10:59 module2.mod -rw-r--r-- 1 dominiq staff 6376 Mar 9 10:59 module3.mod -rw-r--r-- 1 dominiq staff 10512 Mar 9 10:59 module4.mod -rw-r--r-- 1 dominiq staff 18628 Mar 9 10:59 module5.mod -rw-r--r-- 1 dominiq staff 34704 Mar 9 10:59 module6.mod -rw-r--r-- 1 dominiq staff 66700 Mar 9 10:59 module7.mod -rw-r--r-- 1 dominiq staff 130536 Mar 9 10:59 module8.mod -rw-r--r-- 1 dominiq staff 258052 Mar 9 10:59 module9.mod -rw-r--r-- 1 dominiq staff 512931 Mar 9 10:59 module10.mod -rw-r--r-- 1 dominiq staff 1022530 Mar 9 10:59 module11.mod -rw-r--r-- 1 dominiq staff 2041569 Mar 9 10:59 module12.mod -rw-r--r-- 1 dominiq staff 4079488 Mar 9 10:59 module13.mod -rw-r--r-- 1 dominiq staff 8155167 Mar 9 10:59 module14.mod -rw-r--r-- 1 dominiq staff 16306366 Mar 9 10:59 module15.mod -rw-r--r-- 1 dominiq staff 32608774 Mar 9 10:59 module16.mod gcc version 4.9.3 5.432u 0.389s 0:06.00 96.8% 0+0k 8+19io 1355pf+0w -rw-r--r-- 1 dominiq staff 485 Mar 9 11:03 module0.mod -rw-r--r-- 1 dominiq staff 498 Mar 9 11:03 module1.mod -rw-r--r-- 1 dominiq staff 526 Mar 9 11:03 module2.mod -rw-r--r-- 1 dominiq staff 560 Mar 9 11:03 module3.mod -rw-r--r-- 1 dominiq staff 602 Mar 9 11:03 module4.mod -rw-r--r-- 1 dominiq staff 668 Mar 9 11:03 module5.mod -rw-r--r-- 1 dominiq staff 770 Mar 9 11:03 module6.mod -rw-r--r-- 1 dominiq staff 952 Mar 9 11:03 module7.mod -rw-r--r-- 1 dominiq staff 1279 Mar 9 11:03 module8.mod -rw-r--r-- 1 dominiq staff 1911 Mar 9 11:03 module9.mod -rw-r--r-- 1 dominiq staff 3165 Mar 9 11:03 module10.mod -rw-r--r-- 1 dominiq staff 5650 Mar 9 11:03 module11.mod -rw-r--r-- 1 dominiq staff 10603 Mar 9 11:03 module12.mod -rw-r--r-- 1 dominiq staff 20493 Mar 9 11:03 module13.mod -rw-r--r-- 1 dominiq staff 40276 Mar 9 11:03 module14.mod -rw-r--r-- 1 dominiq staff 79811 Mar 9 11:03 module15.mod -rw-r--r-- 1 dominiq staff 158891 Mar 9 11:03 module16.mod gcc version 5.0.0 5.525u 0.381s 0:06.06 97.3% 0+0k 9+23io 1605pf+0w -rw-r--r-- 1 dominiq staff 485 Mar 9 11:07 module0.mod -rw-r--r-- 1 dominiq staff 500 Mar 9 11:07 module1.mod -rw-r--r-- 1 dominiq staff 529 Mar 9 11:07 module2.mod -rw-r--r-- 1 dominiq staff 562 Mar 9 11:07 module3.mod -rw-r--r-- 1 dominiq staff 606 Mar 9 11:07 module4.mod -rw-r--r-- 1 dominiq staff 672 Mar 9 11:07 module5.mod -rw-r--r-- 1 dominiq staff 774 Mar 9 11:07 module6.mod -rw-r--r-- 1 dominiq staff 956 Mar 9 11:07 module7.mod -rw-r--r-- 1 dominiq staff 1283 Mar 9 11:07 module8.mod -rw-r--r-- 1 dominiq staff 1915 Mar 9 11:07 module9.mod -rw-r--r-- 1 dominiq staff 3170 Mar 9 11:07 module10.mod -rw-r--r-- 1 dominiq staff 5650 Mar 9 11:07 module11.mod -rw-r--r-- 1 dominiq staff 10603 Mar 9 11:07 module12.mod -rw-r--r-- 1 dominiq staff 20493 Mar 9 11:07 module13.mod -rw-r--r-- 1 dominiq staff 40276 Mar 9 11:07 module14.mod -rw-r--r-- 1 dominiq staff 79811 Mar 9 11:07 module15.mod -rw-r--r-- 1 dominiq staff 158891 Mar 9 11:07 module16.mod gcc version 5.0.0 with the patch in pr40958 comment 18 0.045u 0.034s 0:00.24 29.1% 0+0k 12+18io 1767pf+0w -rw-r--r-- 1 dominiq staff 485 Mar 9 11:07 module0.mod -rw-r--r-- 1 dominiq staff 500 Mar 9 11:07 module1.mod -rw-r--r-- 1 dominiq staff 515 Mar 9 11:09 module2.mod -rw-r--r-- 1 dominiq staff 527 Mar 9 11:09 module3.mod -rw-r--r-- 1 dominiq staff 539 Mar 9 11:09 module4.mod -rw-r--r-- 1 dominiq staff 552 Mar 9 11:09 module5.mod -rw-r--r-- 1 dominiq staff 567 Mar 9 11:09 module6.mod -rw-r--r-- 1 dominiq staff 578 Mar 9 11:09 module7.mod -rw-r--r-- 1 dominiq staff 590 Mar 9 11:09 module8.mod -rw-r--r-- 1 dominiq staff 603 Mar 9 11:09 module9.mod -rw-r--r-- 1 dominiq staff 621 Mar 9 11:09 module10.mod -rw-r--r-- 1 dominiq staff 632 Mar 9 11:09 module11.mod -rw-r--r-- 1 dominiq staff 647 Mar 9 11:09 module12.mod -rw-r--r-- 1 dominiq staff 663 Mar 9 11:09 module13.mod -rw-r--r-- 1 dominiq staff 677 Mar 9 11:09 module14.mod -rw-r--r-- 1 dominiq staff 692 Mar 9 11:09 module15.mod -rw-r--r-- 1 dominiq staff 728 Mar 9 11:09 module16.mod Without the patch the module sizes double each time a module is added (asymptotic behavior) while the prefactor for 4.9 and 5.0 is ~200 smaller compared to 4.8. With the patch, the compile time is negligible and the module sizes increase is quite small (linear?). May be the patch should be submitted to fortran@gcc.gnu.org (for next stage1).
The patch for 40958 is simple enough that we may be able to just commit it to trunk. Fortran is not release critical. With the patch do we have any problems with known large code bases like CP2K? Is 40958 a duplicate of this PR or is there something else lurking?
> Is 40958 a duplicate of this PR or is there something else lurking? AFAIU pr40958 comment 13, Janne was anticipating possible exponential behaviors from a rather theoretical point of view. This PR is an instance of such exponential behavior. IMO pr40958 should be closed and new PRs for exponential behavior opened when new instances are found.
> May be the patch should be submitted to fortran@gcc.gnu.org (for next stage1). I'd be happy if this could be resolved. Should I submit or someone with more clout among the gfortran maintainers/developers?
Author: kargl Date: Fri Jun 5 16:54:53 2015 New Revision: 224159 URL: https://gcc.gnu.org/viewcvs?rev=224159&root=gcc&view=rev Log: 2015-06-03 Russell Whitesides <russelldub@gmail.com> Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/40958 PR fortran/60780 PR fortran/66377 * module.c (load_equiv): Add check for loading duplicate EQUIVALENCEs from different modules. Eliminate the pruning of unused equivalence-objects 2015-06-03 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/66377 gfortran.dg/equiv_9.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/equiv_9.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/module.c trunk/gcc/testsuite/ChangeLog
Author: kargl Date: Fri Jun 5 20:40:35 2015 New Revision: 224171 URL: https://gcc.gnu.org/viewcvs?rev=224171&root=gcc&view=rev Log: 2015-06-03 Russell Whitesides <russelldub@gmail.com> Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/40958 PR fortran/60780 PR fortran/66377 * module.c (load_equiv): Add check for loading duplicate EQUIVALENCEs from different modules. Eliminate the pruning of unused equivalence-objects 2015-06-03 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/66377 gfortran.dg/equiv_9.f90: New test. Added: branches/gcc-5-branch/gcc/testsuite/gfortran.dg/equiv_9.f90 Modified: branches/gcc-5-branch/gcc/fortran/ChangeLog branches/gcc-5-branch/gcc/fortran/module.c branches/gcc-5-branch/gcc/testsuite/ChangeLog
Fixed on trunk and 5-branch. Thanks for the PR and patch.