Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend the C++ module scanner to handle Fortran, too. #8095

Merged
merged 1 commit into from
Dec 25, 2020

Conversation

jpakkane
Copy link
Member

This will probably fail to the tests, but let's just get this out there for people to test and comment on. So ping all Fortran users, such as @scivision.

The main advantage of this approach is that we can drop all the prescan hacks we have and instead do Fortran automatically and reliably out of the box. I.e. moving module definitions from one file to another should just work without needing to run Meson reconfiguration.

@dcbaker dcbaker requested a review from scivision December 14, 2020 17:55
Copy link
Member

@dcbaker dcbaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few small nits, but overall this looks good to me. Probably should get scivision to give his input though.

@@ -872,7 +872,11 @@ def generate_target(self, target):
self.generate_shlib_aliases(target, self.get_target_dir(target))
self.add_build(elem)

def should_scan_target(self, target):
def should_use_dyndeps_for_target(self, target):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def should_use_dyndeps_for_target(self, target):
def should_use_dyndeps_for_target(self, target: 'build.BuildTarget') -> bool:

FORTRAN_USE_PAT = r"^\s*use,?\s*(?:non_intrinsic)?\s*(?:::)?\s*(\w+)"

fortran_module_re = re.compile(FORTRAN_MODULE_PAT)
fortran_use_re = re.compile(FORTRAN_USE_PAT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should really all be all caps per PEP8, as they're module constants.

Comment on lines 912 to 916
all_suffixes = set()
for s in compilers.lang_suffixes['cpp']:
all_suffixes.add(s)
for s in compilers.lang_suffixes['fortran']:
all_suffixes.add(s)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
all_suffixes = set()
for s in compilers.lang_suffixes['cpp']:
all_suffixes.add(s)
for s in compilers.lang_suffixes['fortran']:
all_suffixes.add(s)
all_suffixes = set(compilers.lang_suffixes['cpp']) | set(compilers.lang_suffixes['fortran'])

elif suffix in lang_suffixes['cpp']:
self.scan_fortran_file(fname)
else:
sys.exit('Can not scan files with suffix .{}.'.format(suffix))
Copy link
Member

@scivision scivision Dec 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think raise SystemExit is preferred to sys.exit in general.
However, in this case should it rather be raise RuntimeError?

cpp_import_re = re.compile('\w*import ([a-zA-Z0-9]+);')
cpp_export_re = re.compile('\w*export module ([a-zA-Z0-9]+);')

FORTRAN_INCLUDE_PAT = r"^\s*#?include\s*['\"](\w+\.\w+)['\"]"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be in a separate PR, but to speed this up, the #include syntax isn't used by any compiler I've found. I added this when I was overhauling the regex for Fortran, but since realized no current compiler allows this syntax.

Suggest:

FORTRAN_INCLUDE_PAT = r"^\s*include\s*['\"](\w+\.\w+)['\"]"

@scivision
Copy link
Member

scivision commented Dec 15, 2020

Most of the Fortran project tests

python .\run_project_tests.py --only fortran

fail with this setup (only one I tried):

  • Ninja 1.10.2
  • GCC 10.2.0 (MSYS2)
  • Windows 10

Typical build-time errors

test 3

ninja: build stopped: dependency cycle: use_syntax.exe.p/circle.mod -> use_syntax.exe.p/circle.mod.

test 4

ninja: build stopped: dependency cycle: libselfmod.dll.p/b.mod -> libselfmod.dll.p/b.mod.

and so on.

@scivision
Copy link
Member

3cd6586 fails at a list | list I think maybe it's meant to have those variables be sets?

@jpakkane jpakkane force-pushed the fortranmodscan branch 4 times, most recently from a0aa0c7 to 2aa674a Compare December 25, 2020 15:41
@jpakkane
Copy link
Member Author

Finally it passes all project tests. I'll fix the mypy issues later.

@lgtm-com
Copy link

lgtm-com bot commented Dec 25, 2020

This pull request introduces 1 alert when merging 2aa674a into cb10ba7 - view on LGTM.com

new alerts:

  • 1 for Unused local variable

@scivision
Copy link
Member

scivision commented Dec 25, 2020

Yes this works for me with Gfortran 10 as well.

I can't effectively test with the Intel Windows compiler yet, as the Intel oneAPI "gold" official release a few weeks ago actually broke a bunch of things that previously worked throughout the beta period, including independently breaking Meson and CMake.

https://community.intel.com/t5/Intel-oneAPI-HPC-Toolkit/Gold-oneAPI-release-broken-but-betas-worked-fine-Linux-Windows/m-p/1236017#M7421

Intel has confirmed the issues and referred to internal team.

Once Intel fixes oneAPI, this commit is necessary to recognize the new compilers (which replace the old) scivision@c6c2c53

@jpakkane
Copy link
Member Author

That is unrelated to this issue, so merging.

@jpakkane jpakkane merged commit 2f836e3 into master Dec 25, 2020
@jpakkane jpakkane deleted the fortranmodscan branch December 25, 2020 23:39
@scivision
Copy link
Member

yes that's correct, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants