Branch: refs/heads/main
Revision: 1c1a1af
Author: dlongnecke-cray
Link: https://github.com/chapel-lang/chapel/pull/19203
Log Message:
Merge pull request #19203 from dlongnecke-cray/manage-prevent-overloaded-return-intents
manage: Errors for inferred resources when multiple return intents exist (#19203)
Manage statements now emit errors when a resource is specified without
storage (e.g., var
) and multiple return intents exist for the
enterThis()
method.
Note that it is fine for multiple return intents of enterThis()
to
exist - it just means that each resource declaration for such a
manager must specify an explicit storage.
For example:
// Some sort of manager specifying both 'value' and 'ref'.
record manager {
var x = 0;
proc enterThis(): int { return x; }
proc enterThis() ref: int { return x; }
proc leaveThis(in err: owned Error?) {
if err then halt();
}
}
var man = new manager();
// Compiler error, cannot infer storage for 'res'
manage man as res do res += 1;
// OK, we know 'res' is 'ref'
manage man as ref res do res += 1;
This should allow for backwards compatibility in the event that
overloaded return intents are popular and users request some sort of
disambiguation order.
TESTING:
- [x]
ALL
onlinux64
whenCOMM=none
Reviewed by @lydia-duncan. Thanks!
Signed-off-by: David Longnecker dlongnecke-cray@users.noreply.github.com
Modified Files:
A test/statements/manage/ExplicitConstRefResourceMutation.chpl
A test/statements/manage/ExplicitConstRefResourceMutation.good
A test/statements/manage/InferredResourceMultipleReturnIntents1.chpl
A test/statements/manage/InferredResourceMultipleReturnIntents1.good
M compiler/resolution/preFold.cpp
M test/statements/manage/ContextManagerSyntax.chpl
M test/statements/manage/ContextManagerSyntax.good
M test/statements/manage/InferredConstRefResourceMutation.chpl
M test/statements/manage/InferredConstRefResourceMutation.good
M test/statements/manage/InferredResourceStorage.chpl
M test/statements/manage/InferredResourceStorage.good
Compare: https://github.com/chapel-lang/chapel/compare/86d1584a9b67...1c1a1afa3c2c