-
Notifications
You must be signed in to change notification settings - Fork 426
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 isCopyable etc #14842
Add isCopyable etc #14842
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks good.
Note that your PR message would lead to closing #13195 upon merge. I suggest fixing that unless that's the intention.
The interface looks good to me, given that we need to have this information. The only thing that gave me pause is I suggest to coordinate the choice of the name for the above with the error that the compiler issues when default-initializing a non-nilable variable or a record without |
These routine names look good to me. It looks like |
I think either is fine, but prefer |
I think if we were to use isDefaultInitializable we would perhaps want e.g. isCopyInitializable. |
I have some concern that Therefore I'd like to use |
I assumed |
All of these functions in Types, like |
While it is a bit more wordy I think that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of comments related to the future, but otherwise I think this is good
Adjust tryResolve to return false when compilerError encountered Resolves #13195. This PR updates resolution handling of tryResolve to hide compilerErrors encountered along the way and instead just make tryResolve return false in that case. Additionally, it adjusts tryResolve to include a boolean argument indicating if the body of the called function should also be resolved (so that if it contains a compilerError call we can handle that appropriately). The PR also makes some adjustments to misc.cpp towards making it possible to capture and re-issue all errors but that is not currently used. However I am including it here because I think it is an improvement to the structure of error reporting. This PR takes no particular action for resolving functions called by the function being attempted. These are resolved in whatever order resolution gets to them normally. I started on this patch because in working on #13600 I needed a way to mark an `init=` or `=` function as not resolveable (see #8065) so that isCopyable etc (from PR #14842) can return false. Future work: Answer the open design questions in this area 1. Should canResolve always try to resolve the body of the called function? 2. Should canResolve always try to resolve the body of the called function and all functions called within it, recursively? 3. Should canResolve return false for other errors besides compilerError? - [x] full local testing Reviewed by @lydia-duncan - thanks!
Motivated by work in PR #14835, I realized that
list
needs to avoidhaving an
init=
or=
function when the element type is a non-nilableowned, e.g.
owned C
. The problem is that in that event, the source listelements would be transferred out of and then store
nil
. Additionallylist
should not include aninit=
function if the elements do notinclude one.
In order to solve that problem,
list
will need to be able to querywhether or not the elements are copyable. In addition it makes sense to
be able to query if a type is only copyable from a
ref
, which is thecase for
owned C?
(say).This PR adds the following queries to the Types standard module:
isConstCopyable
returns true if the type can be initialized from aconst
value (var x = myConstValue
)isCopyable
returns true if the type can be copy-initialized at all(but it might only be initializable from a mutable other variable, as
is the case with
owned
)isConstAssignable
returns true if the type can be assigned from aconst
value (x = myConstValue
)isAssignable
returns true if the type can be assigned at all (but itmight only be assignable from a mutable rhs variable, as is the case
with
owned
).isDefaultInitializable
returns true if the type has a default value(e.g. supports
var z: MyType;
)isCopyable
andisConstCopyable
are chosen because some types(including
map
after PR #14793) use the ref-if-modified intent ininit=
. For these types, it is not known at resolution time whether theintent will be
ref
orconst ref
.This PR adds the new functions to Types.chpl and the related primitives
and support in preFold. Flags are computed and applied to a type so that
multiple calls to
isCopyable
will not result in trying to resolveinit=
each time. Additionally, this PR adjusts the expiring valueanalysis to avoid visiting task functions twice and tidies some
whitespace in preFold.cpp.
Reviewed by @vasslitvinov and @lydia-duncan - thanks!
Future Work:
containing non-nilable owned