-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add support for namespaced modules #823
Conversation
When the project name changes in fpm.toml, command `fpm update` is not able to update the dependency tree because of the different name of the root dependency. Allow `update` to instead build the whole project from scratch when its name has changed
Just to make sure I understand the idea here. module projA_FPM_mod
! Import all public entities from the non-namespaced module
use mod, only: foo
implicit none(type,external)
private
public :: foo
end module module projB_FPM_mod
! Import all public entities from the non-namespaced module
use mod, only: foo
implicit none(type,external)
private
public :: foo
end module There will still be 2 |
Very smart comment, thank you. I want to set up some unit tests for these edge cases cause I want to see how compilers behave (is the global function name renamed/duplicated in the object table or not?). One possible workaround to force each name to be in the namespaces module would be to copy the whole dummy argument list and also create wrappers, this should work at least for functions and subroutines, and parameter variables, but certainly not with non-parameter variables and classes: module projB_FPM_mod
! Import all public entities from the non-namespaced module
use mod, only: foo_orig => foo
implicit none(type,external)
private
public :: foo
contains
subroutine foo(same,dummy,args)
call foo_orig(same,dummy,args)
end subroutine foo
end module But as said, I need to lay out some tests to define the solution that works for the most cases |
I don't understand. All we need is to enforce prefixing all module names with a prefix, that by default is the package name, and can be changed in This PR seems very complicated. |
Thank you @certik. I may have gotten too far with the design trying to account for all possible edge cases. You mean to rename all module names in all source files instead of creating prefixed module wrappers? |
I think fpm should not rename anything, it should simply enforce the convention. After that is implemented, we can brainstorm if anything else is needed, but probably not. |
Sounds good @certik. The reason I had thought of adding the prefixed modules was to not break existing buids. I will rework this PR in the way you're suggesting and let's see what it looks like afterwards. Is it OK that the prefix looks for an |
I don't think there's any need for a separator. So long as a module name starts with the name of the package (or specified prefix), it's fine. |
Yes it makes sense, and I also think this does not need a derived type for modules anymore. So I think I will open a new PR to start from a clean branch. |
Yes, keep this PR open for reference, but open a new PR with a minimal clean implementation. Provide a command line option to disable this check, that way existing packages will still build, just not by default. @everythingfunctional should we require underscore, that is: package name + "_" ? |
I was going to go with no, as it simplifies the rules, even if one wants to have a single "public" module for a package. I.e. there is only module for strff, but it's named strff, which starts with the package name, so it satisfies the rule. No special cases needed. Most people probably will use an underscore for separation, but that's fine. |
So probably also the |
Why? If the rule is "all of a package's library modules (i.e. those in |
Good point, haven't thought of that. Although some authors might prefer the |
This was superseded by #828 , I will close this PR now. |
The STF project aims to enable support for namespaced modules (See #153, #819) as a means to prevent name collisions among modules of different packages.
This will require pretty substantial changes to fpm, so I'm opening a draft pull request to enable discussion and community review of this work.
Compiler/standard limitations will still limit the flexibility of this approach (e.g., directly
use
ing modules with the same name from two different packages), but I don't think it is a good idea to have fpm modify any of the source codes on-the-fly. Anyways we can remove most of the friction to the user with how we design this feature. This is a tentative to-do list:type(string_t)
to atype(module_t)
which contains all necessary information and procedures, with fallback to default behavior (aka no namespace) where no specifications are madeAs long as the object files of the non-namespaced modules stay within their own library file, there should be no issues even in presence of collisions, but FPM must prompt for them during build.
CC: @fortran-lang/admins @fortran-lang/fpm @certik @awvwgk @milancurcic @everythingfunctional @arteevraina @henilp105 @minhqdao