-
Notifications
You must be signed in to change notification settings - Fork 421
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13253 from lydia-duncan/privateUse
Support public and private use statements [reviewed by @benharsh] Prior to this change, all use statements were public, with no option to change that. This meant that symbols needed for your module would get bled into your users' namespaces. For instance, in the following code: ```chapel module A { proc someFunc() { ... } } module B { use A; ... } module C { use B; } ``` module C would have `someFunc` as part of its namespace. This could lead to problems like name conflicts, shadowing due to one function having a more specific signature, etc. We would frequently work around this by limiting the scope of the use statement, e.g. putting the use inside of the function where the symbols were needed - but this could lead to redundant use statements in the case where multiple functions in a module needed the same module. This change adds the ability to declare a use statement as public or private. Public is still the default (though we may look into changing that). Declaring a use as private will mean that the symbols it brings into scope are only accessible by the scope in which the use is declared. The changes to support it are fairly minor. We needed to add parser support and a new field to UseStmts (impacting how we create them), and then check that field when performing scope and function resolution. The most effort was put into function resolution, where we needed to check the visibility relative to the scope where the call occurred, and relative to the instantiation point of the call if it was within a generic function. I also renamed a method on ModuleSymbol - the method would drop use statement information about pretty much everything except the module being used on the floor, but won't cause problems since it is only used by dead code elimination. In discussing with Michael, we don't like that it does this, but don't think it is worth taking on the effort to fix it until it causes problems. I left a note at the offending line for if we get back to it - hopefully renaming will ensure that no one tries to use it when doing so would cause problems. Resolves #6093 This change adds 30 tests of the new feature. They check: - except lists on the private use to ensure the avoided symbols are not accidentally exposed, both in the module with the private use and in any clients of that module - private use statements containing multiple modules, to ensure that all modules used are used privately - only lists on the private use to ensure the symbols that aren't named are not accidentally exposed, both in the module with the private use and in any clients of that module - renaming symbols via a private use, to ensure that the rename works in the module with the use, and that the new name is not visible to clients of that module - privately using a module that defines a secondary method, to ensure the method is not exposed beyond the module with the private use. - privately and publicly using the same module so that some symbols are available to clients and the rest only to the module with the use statement - privately using a module that defines a type, to ensure the type is not exposed beyond the module with the private use - that privately using a module with a public use doesn't behave badly - and various point of instantiation tests that are difficult to describe succinctly (ran them by Michael to be sure I wasn't crazy, though most of them resemble tests that already exist and are not a serious departure from them) Passed a full paratest with futures. Later todos: - modify error message so that it isn't confusing when a symbol is not found because of privacy - private uses by default? - private use of: - root module - ChapelStandard - Fortran module
- Loading branch information
Showing
83 changed files
with
5,515 additions
and
4,704 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.