Skip to content

Conversation

LKedward
Copy link
Member

  • Adds: new example package for including c code;
  • Adds: new example package for using submodules;
  • Adds: README describing each example package and supported fpm version;
  • Fixes: parsing bug where submodule names were not added to modules_provided array;
  • Fixes: parsing bug where leading spaces were not removed from parsed strings.

@milancurcic
Copy link
Member

👍 from me. Do you agree on also adding this example package:

module_in_program_source/
  app/
    main.f90
  fpm.toml

where main.f90 is:

module greet_m
  implicit none
  character(*), parameter :: greeting = 'Hello, fpm!' 
end module greet_m

program module_in_program_source
  use greet_m, only: greeting
  implicit none
  print *, greeting
end program module_in_program_source

We're supporting this implicitly without special care, but we should make sure to not break the support.

@LKedward
Copy link
Member Author

Thanks @milancurcic. Good point yes I agree, I'll add that example in too.

@everythingfunctional
Copy link
Member

I'm not sure I agree that we do want to support having a module in the same file with a program. We don't support having multiple modules in one file. Is there a reason for wanting this capability?

@milancurcic
Copy link
Member

  1. For me it's convenience for toy programs;
  2. It's valid Fortran;
  3. There is existing production Fortran software that does this (multiple modules in one source file)

We don't support having multiple modules in one file.

We do, I just tried it. :)

I get that many people may not care about this, but I think you need a strong argument to disallow valid code.

@LKedward
Copy link
Member Author

I similarly find it useful now and again to put a module and a program together for small supporting programs like tests, demos and benches. This is fairly common usage I believe.

My main quarrel with disallowing this, and other valid fortran layouts, is with the enforcement of design decisions on users by constraint. This is not the job of a build tool IMO.

Regarding existing support, I believe it is supported to the extent that the module in question is not used by any other file.

@everythingfunctional
Copy link
Member

I find it somewhat useful when tooling (if not the language itself) can at least discourage known, poor design decisions. Similar to the way most modern languages don't have a goto. But if there is sufficient desire, and some use cases where it would lead to better design, I'm ok with it. I don't know if that's the case, but I'm open to being shown some.

Are there any other languages that allow multiple modules in one file?

If a program is found at the end of a source file, it will override any previous definition of unit_type to FPM_UNIT_PROGRAM.
If a module dependency is satisfied in the same file, it is not added to file_dependencies.
Use two-pass procedure to count the number of actual file_dependencies required for module resolution.
@certik
Copy link
Member

certik commented Sep 19, 2020 via email

@certik
Copy link
Member

certik commented Sep 19, 2020 via email

@milancurcic
Copy link
Member

I agree with having fpm print a warning (recommendation, really) if it finds multiple modules or module + program in a source file.

I don't like the idea of restricting this with an option because if you expressly don't want to do this, then you're already not writing code that needs to be restricted. Conversely, if the default is to restrict it, then having to add an option to enable it somewhat defeats the purpose of me using it for convenience.

If you're against a correct default behavior that is supported in the present and want to disable it as a feature, you need to convince others, not the other way around. "known, poor design decisions" is subjective and not meaningful without elaborating why.

@certik
Copy link
Member

certik commented Sep 19, 2020 via email

@LKedward
Copy link
Member Author

Technically the main issue as I see it is that if we start with being restrictive, we can always relax the requirements later without breaking any existing fpm package.

I don't think we should consider deferring this decision.

I think Milan makes a very important point: having no restrictions does not affect those who want to conform to their own standard for layout, but enforcing restrictions does affect those who do not. By placing restrictions on otherwise valid Fortran you are enforcing one group's subjective preference on everyone.

Regarding the warning, I don't know if I would like to be getting warnings for things that are allowed.

There are some situations where I learn to live with certain compiler warnings, because I know why those warnings exist and why I have chosen to ignore them. This would be the same in this case.

@certik
Copy link
Member

certik commented Sep 20, 2020 via email

@LKedward
Copy link
Member Author

If we make this decision, will it be warning by default, and you can turn off the warning in fpm.toml with an option?

Yes, a warning by default.

There are huge advantages that come from having a restrictive default layout.

Are these advantages for fpm developers or advantages for fpm users? My argument is based on prioritising the latter over the former.

@certik
Copy link
Member

certik commented Sep 20, 2020 via email

@milancurcic
Copy link
Member

Thanks @certik.

Perhaps a nuanced but important point that may have been missed: I don't argue here for relaxing any restriction. I argue for including a test case of a pattern that is presently both permitted (within our planned restriction set) and working, rather than leaving it untested.

I was assuming that the file/module layout and naming restriction we impose follows from #153 where we agreed that we will require the module name to be prefixed with package name. This helps prevent name collisions.

I was also assuming that we don't anymore require the module name to be the same as the source file name. I don't think it does anything for us given #153. Do you agree?

So, if we don't require the module name to be the same as the source file name, I see no practical reason to forbid module+program or multi-module in source file. However, if we do require it, then we can't do what I proposed in this thread.

As an afterthought, given #153 we should rename the modules in current example packages to reflect this (even though we're not enforcing it yet).

@certik
Copy link
Member

certik commented Sep 20, 2020 via email

@milancurcic
Copy link
Member

I think all doors should stay open. If we later decide to make the module naming more strict, we remove this test. If it shows to be problematic for implementation, we remove it. Adding this test doesn't close any doors.

Copy link
Member

@certik certik left a comment

Choose a reason for hiding this comment

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

Let's merge this. We can improve upon this later.

Thanks @LKedward !

@certik certik merged commit 313fe32 into fortran-lang:master Sep 21, 2020
@LKedward LKedward deleted the more_examples branch December 9, 2020 16:17
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.

4 participants