Skip to content
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

Add chpl__defaultHash for borrowed object?and adjust class tests for set #15592

Merged

Conversation

dlongnecke-cray
Copy link
Contributor

@dlongnecke-cray dlongnecke-cray commented Apr 24, 2020

This PR adds an overload of chpl__defaultHash for borrowed object?. The overload of chpl__defaultHash for non-nilable objects has been removed, because non-nilable classes will coerce to nilable object. Futures for sets of classes that pass after adding the overload have been migrated to normal tests.

Prior to this PR sets of nilable classes failed to instantiate because they were unable to resolve a call to chpl__defaultHash. The compiler is able to automatically coerce arguments of type owned, shared, and unmanaged to borrowed when resolving a function call. However we did not offer an overload of chpl__defaultHash that accepted a nilable borrowed, causing resolution of the set initializer to fail when the element type was a nilable class.


Testing:

  • ALL on linux64 when CHPL_COMM=none
  • ALL on linux64 when CHPL_COMM=gasnet

@dlongnecke-cray dlongnecke-cray self-assigned this Apr 24, 2020
@dlongnecke-cray dlongnecke-cray marked this pull request as draft May 5, 2020 17:37
@dlongnecke-cray dlongnecke-cray marked this pull request as ready for review May 11, 2020 22:30
@dlongnecke-cray dlongnecke-cray requested review from mppf and removed request for mppf May 11, 2020 22:34
@dlongnecke-cray
Copy link
Contributor Author

@mppf Would you be willing to review this?

A quick update on what is left:

@dlongnecke-cray dlongnecke-cray requested a review from mppf May 12, 2020 00:11
Copy link
Member

@mppf mppf left a comment

Choose a reason for hiding this comment

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

Generally looking good but I'd like you to try making just one hash function for classes.

}

// Nilable classes will coerce to this.
inline proc chpl__defaultHash(o: borrowed object?): uint {
Copy link
Member

Choose a reason for hiding this comment

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

Actually you should be able to just have this version and leave out the above since any class should coerce to borrowed object?. Could you give that a try?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should have thought about that. That should work nicely.

compilerError('Sets do not support tuples containing ' +
'non-nilable classes', 2);

// In the future we might support it if the set is not default-inited.
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, but if it were default-initialized, the compiler should figure out the concrete type.

@@ -441,7 +445,7 @@ module Set {
:return: An array containing a copy of each of the elements in this set.
:rtype: `[] eltType`
*/
proc const toArray(): [] eltType {
proc const toArray(): [] eltType where isCopyableType(eltType) {
Copy link
Member

Choose a reason for hiding this comment

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

For functions like this, I generally prefer the approach of a param conditional guarding a compilation error. The error can be more friendly than the resolution error. But there might be a reason the resolution error is nicer here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm actually going to remove the where clauses from this PR and come back to them in another effort, because I just discovered the |= operators aren't working as expected 🤭

@dlongnecke-cray dlongnecke-cray merged commit 8260f89 into chapel-lang:master May 12, 2020
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.

2 participants