Branch: refs/heads/master
Revision: a0a4dd2
Author: lydia-duncan
Log Message:
Merge pull request #16976 from lydia-duncan/typeAndMethods
Enable use and import statements to impact methods on listed types
[reviewed by @mppf]
Prior to this change, a type could only be included in an import
statement’s unqualified
list or in the only
or except
list of a use statement if the type was visible from that scope.
With this change, a type can be included in these lists if the scope defines methods on that
type, and the visibility of such methods will be impacted by the type being present in these
lists. For instance, if a method doSomething
was defined on a record MyType
in a module
Lib
:
module Lib {
use DefinesMyType; // The location where MyType is originally defined
proc MyType.doSomething(...) { ... }
}
then importing MyType
from Lib
will enable instances of MyType
in the scope with the
import to call doSomething
:
import Lib.MyType;
var x = new MyType(...);
x.doSomething(...);
}
use Lib only MyType
will behave similarly, while use Lib except MyType
will prevent the
doSomething
method from being callable in that scope.
Resolves #16710
Resolves Cray/chapel-private#1556
Resolves Cray/chapel-private#1557
Adjusts scope resolution and visible functions determination to take this new functionality
into account.
Adjusts ResolveScope::extend to keep track of types that have methods defined in its
scope. This list will be checked if we don’t find a direct match for a name.
Adjusts ResolveScope::lookupForImport and the methods that rely on it (UseStmt and
ImportStmt’s scopeResolve methods). Instead of always returning the symbol listed (which
is not possible when listing a type for enabling its methods), return a pair of Symbol and
const char*. When the symbol listed is a module (or enum for use statements), the const
char* part of the return will just be an empty string. When the symbol listed is not a module,
the symbol’s name will be returned in the const char* portion and the enclosing module will
be the symbol returned. This enables us to simplify the ImportStmt and UseStmt
scopeResolve methods due to a reduction in the error cases that are handled on their side,
and due to not needing to compute the module storing the symbol when importing a
non-module symbol.
Adjusts the import statement’s validation of its unqualified list and the use statement’s
validation of its only or except list to allow the symbol listed to not be “found” in the
scope being imported as long as methods on that name are found instead.
Adds methods typeWasNamed to import and use statements, which take in a type and
return type names that should be allowed on the this argument when resolving methods,
based on the limitation clause for the import or use. In the case of only lists and the
import statement, this is all matched viable names; in the case of except lists, only names
not found in the except list are returned. Viable names can include:
- the name of the type provided
- the name of its generic base class if it is a generic instantiation
- the name of any parent type
Adds an alternate version of some getVisibleMethods helper functions that take in a list
of type names to check if the _this argument to the method matches. If a call to the
typeWasNamed method returns any type names when determining whether to follow a
use or import, then we will call this version with those names as a filter. While in that
mode, we will be sure to use the intersection of that filter and filters that would be
applicable to later uses and imports.
Resolves the test/visibility/blockSecondaryMethod.chpl and
test/visibility/only/canSeeSecondaryMethod2.chpl futures. Adds a bunch of tests
locking in behavior with forwarding, generic instantiations, and inheritance, for import
statements with and without {}
, and use statements with only and except lists.
Updates a couple of tests as a result of the simplification of lookupForImport - when
failing due to trying to use a non-module symbol, we no longer output the location of that
symbol.
Passed a full paratest with futures
Modified Files:
A test/visibility/except/cannotSeeSecondaryMethod.chpl
A test/visibility/except/cannotSeeSecondaryMethod.good
A test/visibility/except/forwarding-containerListed.chpl
A test/visibility/except/forwarding-containerListed.good
A test/visibility/except/forwarding-forwardedListed.chpl
A test/visibility/except/forwarding-forwardedListed.good
A test/visibility/except/genericInstantiationTertiary.chpl
A test/visibility/except/genericInstantiationTertiary.good
A test/visibility/except/genericTertiary.chpl
A test/visibility/except/genericTertiary.good
A test/visibility/except/inheritance-grandparentClassListed.chpl
A test/visibility/except/inheritance-grandparentClassListed.good
A test/visibility/except/inheritance-parentClassListed.chpl
A test/visibility/except/inheritance-parentClassListed.good
A test/visibility/except/inheritance-subclassListed.chpl
A test/visibility/except/inheritance-subclassListed.good
A test/visibility/except/inheritance-subclassListed2.chpl
A test/visibility/except/inheritance-subclassListed2.good
A test/visibility/import/enablesUnqualified/canSeeSecondaryMethod.chpl
A test/visibility/import/enablesUnqualified/canSeeSecondaryMethod.good
A test/visibility/import/enablesUnqualified/forwarding-containerListed1.chpl
A test/visibility/import/enablesUnqualified/forwarding-containerListed1.good
A test/visibility/import/enablesUnqualified/forwarding-containerListed2.chpl
A test/visibility/import/enablesUnqualified/forwarding-containerListed2.good
A test/visibility/import/enablesUnqualified/forwarding-forwardedListed1.chpl
A test/visibility/import/enablesUnqualified/forwarding-forwardedListed1.good
A test/visibility/import/enablesUnqualified/forwarding-forwardedListed2.chpl
A test/visibility/import/enablesUnqualified/forwarding-forwardedListed2.good
A test/visibility/import/enablesUnqualified/genericInstantiationTertiary1.chpl
A test/visibility/import/enablesUnqualified/genericInstantiationTertiary1.good
A test/visibility/import/enablesUnqualified/genericInstantiationTertiary2.chpl
A test/visibility/import/enablesUnqualified/genericInstantiationTertiary2.good
A test/visibility/import/enablesUnqualified/genericTertiary1.chpl
A test/visibility/import/enablesUnqualified/genericTertiary1.good
A test/visibility/import/enablesUnqualified/genericTertiary2.chpl
A test/visibility/import/enablesUnqualified/genericTertiary2.good
A test/visibility/import/enablesUnqualified/inheritance-grandparentClassListed1.chpl
A test/visibility/import/enablesUnqualified/inheritance-grandparentClassListed1.good
A test/visibility/import/enablesUnqualified/inheritance-grandparentClassListed2.chpl
A test/visibility/import/enablesUnqualified/inheritance-grandparentClassListed2.good
A test/visibility/import/enablesUnqualified/inheritance-parentClassListed1.chpl
A test/visibility/import/enablesUnqualified/inheritance-parentClassListed1.good
A test/visibility/import/enablesUnqualified/inheritance-parentClassListed2.chpl
A test/visibility/import/enablesUnqualified/inheritance-parentClassListed2.good
A test/visibility/import/enablesUnqualified/inheritance-subclassListed1a.chpl
A test/visibility/import/enablesUnqualified/inheritance-subclassListed1a.good
A test/visibility/import/enablesUnqualified/inheritance-subclassListed1b.chpl
A test/visibility/import/enablesUnqualified/inheritance-subclassListed1b.good
A test/visibility/import/enablesUnqualified/inheritance-subclassListed2a.chpl
A test/visibility/import/enablesUnqualified/inheritance-subclassListed2a.good
A test/visibility/import/enablesUnqualified/inheritance-subclassListed2b.chpl
A test/visibility/import/enablesUnqualified/inheritance-subclassListed2b.good
A test/visibility/import/enablesUnqualified/secondaryMethod.chpl
A test/visibility/import/enablesUnqualified/secondaryMethod.notest
A test/visibility/only/forwarding-containerListed.chpl
A test/visibility/only/forwarding-containerListed.good
A test/visibility/only/forwarding-forwardedListed.chpl
A test/visibility/only/forwarding-forwardedListed.good
A test/visibility/only/genericInstantiationTertiary.chpl
A test/visibility/only/genericInstantiationTertiary.good
A test/visibility/only/genericTertiary.chpl
A test/visibility/only/genericTertiary.good
A test/visibility/only/inheritance-grandparentClassListed.chpl
A test/visibility/only/inheritance-grandparentClassListed.good
A test/visibility/only/inheritance-parentClassListed.chpl
A test/visibility/only/inheritance-parentClassListed.good
A test/visibility/only/inheritance-subclassListed.chpl
A test/visibility/only/inheritance-subclassListed.good
A test/visibility/only/inheritance-subclassListed2.chpl
A test/visibility/only/inheritance-subclassListed2.good
R test/visibility/except/blockSecondaryMethod.bad
R test/visibility/except/blockSecondaryMethod.future
R test/visibility/only/canSeeSecondaryMethod2.bad
R test/visibility/only/canSeeSecondaryMethod2.future
M compiler/AST/ImportStmt.cpp
M compiler/AST/UseStmt.cpp
M compiler/include/ImportStmt.h
M compiler/include/ResolveScope.h
M compiler/include/UseStmt.h
M compiler/include/stmt.h
M compiler/passes/ResolveScope.cpp
M compiler/resolution/visibleFunctions.cpp
M test/modules/deitz/test_module_class_conflict2.good
M test/modules/deitz/test_module_use4.good
M test/modules/vass/use-a-Math-function.bad
M test/modules/vass/use-a-Reflection-function.bad
M test/visibility/except/blockSecondaryMethod.good
Compare: https://github.com/chapel-lang/chapel/compare/6e6bf4f2be1a...a0a4dd2525d4