-
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
Associative domain / array combinations permit nil
storage in non-nilable array
#14367
Comments
It seems like at the very least we could start by emitting some sort of error message to prevent this bug from slipping through the cracks, and then we can work towards a more general solution. |
Agreed. The lack of an error message was the main thing that caused me to file this. The brainstorming about add() methods and the like was thinking about how one would modify the domain in a safe/sane way w.r.t. nilability. |
After fiddling with some simple solutions and thinking about it some more, it seems like the In the future, we could lighten this constraint by saying the following...
In the even further future, assuming we have support for it, we could say the following:
At the very least, we should prohibit this in the near term in order to prevent buggy programs, with a message along the lines of:
Whenever an array with a value type that is a non-nilable class is declared. We can then expand support to allow for initializer expressions. Thoughts? |
I'm OK with this conservative error message as a means of avoiding having people write incorrect code for the time being. It would also cause people who genuinely need such support to step up and complain. |
I've encountered an issue that has blindsided me a little bit, which is what to do about the The I would like the |
Taking a bit more time to stew on this, I'm remembering that an approach I proposed awhile back is to have the map store nilable C when it's asked to store non-nilable C and then to take care of any casts from nilable to non-nilable in its implementation, knowing that there will never be problems. |
This is what i was thinking we could do as well. The only question is what order of work it is, and what the code will end up looking like. If there is an elegant pattern for unwrapping/rewrapping I could see this approach working. |
Until we either have support for associative arrays of non-nilable classes or decide for certain that we won't do so? Yeah, I agree. |
As of #15747 maps of If we want to support building something like So I thought I'd chip in and offer my opinions on a few different approaches to get discussion moving along. 1) proc DefaultAssociativeDom.add(idx: idxType, ...?t)This is the original idea proposed by @bradcray. Pros:
Cons:
2) proc DefaultAssociativeArr.addIndexAndValue(idx: idxType, val: eltType)This idea would add a method to associative arrays that has a constraint similar to Pros:
Cons:
3) proc DefaultAssociativeArr.addIndexAndValueToAll(idx: idxType, val: eltType)This was an idea brought up in discussion with @mppf. It is an alternative implementation of Pros:
Cons:
4) Do not allow adding to a domain if an array contains a non-default-initializable value typePros:
Cons:
|
Spitballing here: Is there an option in which the author of an associative array of non-nilable could register a factory function/method of some sort that would say what default value should be used for that array? For example, maybe I would allocate a sentinel object for the array and have all "uninitialized" elements point to that sentinel object? |
That's a cool take. Initialization from a callback might not be that flexible, but it could feasibly support By having the default handler be a halt, we could exist in the same world as we do today while offering a workaround. There might be situations where that doesn't make sense (i.e. for |
Support compiling maps of tuple of non-nilable class (#15747) This PR enables compilation of map(int, (shared T, shared T)). Prior to this PR compilation of such maps would fail because internal code was trying to default initialize tuples containing a non-nilable class. Remove two `chpl__supportedDataTypeForBulkTransfer` overloads guarded by where clauses and move their code into the body of the param type function with the same name. The param type function handles special cases by declaring a temp value and calling out to appropriately typed overloads. This temp triggered default initialization errors for tuples containing a non-nilable class. Incorporate changes made to `isDefaultInitializable` in #15744 that add support for tuple types. Add an additional test to verify the correct behavior. Adjust the `_doDefaultInitSlot` method for associative arrays to halt when the array value type is non-default-initializable. See future work in #15744. --- Future work: - Consider adjusting associative array API to allow some means of adding a key/value to an associative array without default initializing: #14367 - Avoid generating `_defaultOf` for tuples containing a non-default- initializable element: #15750 - Add map implemented using an associative domain/array to packages as a proof of concept --- Testing: - [x] ALL on linux64 when COMM=none - [x] ALL on linux64 when COMM=gasnet --- Reviewed by @mppf.
@dlongnecke-cray could this be closed because it is superseded by something else? |
P.S. also #16250 with pointers to some specific proposals. |
See the section "Supporting Resized Arrays of Non-Nilable Classes" in https://chapel-lang.org/releaseNotes/1.24/04-ongoing.pdf |
Summary of Problem
At present, given an associative array that stores non-nilable class objects, it is possible to store nil in those objects by simply never assigning the corresponding array element. This is likely an instance of the more general problem in issue #13602.
My current thinking is that there ought to be an overload of the .add() method that takes a varargs list of (array, initial value) pairs and initializes the corresponding array element for the new index to the respective initial value. That is, given a call like
MyAssocDom.add(idx, (arr1, init1), (arr2, init2), ...))
,idx
would be added toMyAssocDom
and then the listed arrays would be initialized asarr1[idx] = init1
,arr2[idx] = init2
, and so forth (any associated arrays that had no corresponding argument would be default initialized as usual).Steps to Reproduce
Source Code:
This issue also relates loosely to deferred initialization (issue #14271), though I think doing deferred initialization correctly / sanely for individual array elements is a challenging topic.
Compile command:
chpl foo.chpl
Execution command:
./foo
Configuration Information
chpl --version
: 1.20.0The text was updated successfully, but these errors were encountered: