-
Notifications
You must be signed in to change notification settings - Fork 428
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
visibility of private use in submodules using parent #15314
Comments
I prefer not giving
module parent {
module child {
proc secretFunction(a: int) {
return a*3;
}
}
private var parentPrivateVar = 1;
private proc parentPrivateFn() { return 2; }
private use child;
module sibling {
use parent; // does this bring in secretFunction or not?
proc main() {
import super.child.secretFunction; // added this: I need to access some of my sibling's symbols
writeln(parentPrivateVar); // ok
writeln(parentPrivateFn()); // ok
writeln(secretFunction(11)); // error? or ok?
}
}
} |
I prefer approach 1. I think the organization of submodules is more likely to reflect similarities between the symbols within the submodule, rather than necessarily that they should be harder barriers. Consider the following scenario: module Parent {
private module HelperFuncs {
proc x(): int { ... }
}
private use HelperFuncs;
public module ImportantSub {
proc usefulFunc() {
var res = x();
...
}
}
module ImportantSub2 {
proc usefulFunc() {
var res = x();
...
}
}
} In this scenario, HelperFuncs is a nice place to put all the helper functions required by the parent and its submodules. In this case, you'd want a private use of the helper at the parent's scope so you don't have to write a use or import in every single submodule. |
I'm not sure I agree with this perspective. For example, I think it's been proposed that all standard modules should potentially be submodules of a module named My concern with your example-based argument is that it focuses more on convenience than on expressiveness / safety. If The inconvenience in your example of having each child module say |
But distinguishing between "I want this to be visible to outer modules" and "I only want this to be visible to my submodules" seems useful. Does that imply that we should look at ways to distinguish between these strategies (e.g. |
I'm arguing that private module-scope code is an appropriate way to say "I only want this to be visible to my submodules" and that there's no additional semantic benefit to pushing such code into a submodule if nobody has to actually name that submodule to get at it. |
There's the mental benefit of having it neatly filed away in a module for general helper functions as opposed to scattered through out the parent module, or arbitrarily sorted to the beginning or end of it. It all comes down to code organization preferences. I probably should have said that I have occasionally used submodules as a way to sort common helper routines for a library |
To physically separate a set of routines without putting them into their own namespace, maybe what you want is the ability to |
For a regular variable, making the variable
private
will allow submodules to see it (even if the parent module must be imported to be available). But making a variable available with aprivate use
will not allow submodules to have access to the same variable even if theyuse
the parent module (after PR #15312).This comes down to a question of how to treat
private
inprivate use
/private import
(which is the default). There are two approaches:private use
is likeprivate var x
in that submodules can access it but other modules cannotprivate use
never makes theuse
d symbols available outside of the module and it is the same for submodules.For example:
The above program compiles if it is
public use child
. Is the author of the parent module required to make a symbol from a submodule public in order to make it available to submodules?Associated Future Test(s):
test/visibility/private/moduleSymbols/accessPrivateUsedSibling2.chpl #15312
test/visibility/private/moduleSymbols/accessPrivateUsedSibling2a.chpl #15312
The text was updated successfully, but these errors were encountered: