Thread overview |
---|
July 07, 2014 [dmd 2.066-b1] std.range.array with shared objects and AA rehash | ||||
---|---|---|---|---|
| ||||
I am using ranges (wrapped in InputRangeObject for use in interfaces) of shared objects, with new beta some cases are broken: ``` import std.range; class A {} InputRange!(shared A) foo() { return [new A].inputRangeObject; } void bar() { auto res = foo.array; } void main() {} ``` Fails with: ``` source/app.d(7): Error: cannot implicitly convert expression (inputRangeObject([new A])) of type std.range.InputRangeObject!(A[]).InputRangeObject to std.range.InputRange!(shared(A)).InputRange /usr/include/dmd/phobos/std/conv.d(3914): Error: cannot implicitly convert expression (arg) of type shared(A) to app.A /usr/include/dmd/phobos/std/array.d(2476): Error: template instance std.conv.emplaceRef!(shared(A)).emplaceRef!(shared(A)) error instantiating /usr/include/dmd/phobos/std/array.d(64): instantiated from here: put!(shared(A)) source/app.d(12): instantiated from here: array!(InputRange!(shared(A))) ``` And also AA starts behave strange in shared context: ``` shared string[][string] map; void main() { map.rehash; } ``` My AA is stored in shared class, the shared is inferred implicitly. Also following workaround works: ``` void main() { (cast(shared(string[])[string])map).rehash; } ``` Is this behavior a bug, or it works as expected? |
July 07, 2014 Re: [dmd 2.066-b1] std.range.array with shared objects and AA rehash | ||||
---|---|---|---|---|
| ||||
Posted in reply to NCrashed | On Monday, 7 July 2014 at 09:53:22 UTC, NCrashed wrote:
> I am using ranges (wrapped in InputRangeObject for use in interfaces) of shared objects, with new beta some cases are broken:
> ```
> import std.range;
>
> class A {}
>
> InputRange!(shared A) foo()
> {
> return [new A].inputRangeObject;
> }
>
> void bar()
> {
> auto res = foo.array;
> }
>
> void main() {}
> ```
> Fails with:
> ```
> source/app.d(7): Error: cannot implicitly convert expression (inputRangeObject([new A])) of type std.range.InputRangeObject!(A[]).InputRangeObject to std.range.InputRange!(shared(A)).InputRange
> /usr/include/dmd/phobos/std/conv.d(3914): Error: cannot implicitly convert expression (arg) of type shared(A) to app.A
> /usr/include/dmd/phobos/std/array.d(2476): Error: template instance std.conv.emplaceRef!(shared(A)).emplaceRef!(shared(A)) error instantiating
> /usr/include/dmd/phobos/std/array.d(64): instantiated from here: put!(shared(A))
> source/app.d(12): instantiated from here: array!(InputRange!(shared(A)))
> ```
>
> And also AA starts behave strange in shared context:
> ```
> shared string[][string] map;
>
> void main()
> {
> map.rehash;
> }
> ```
> My AA is stored in shared class, the shared is inferred implicitly. Also following workaround works:
> ```
> void main()
> {
> (cast(shared(string[])[string])map).rehash;
> }
> ```
>
> Is this behavior a bug, or it works as expected?
I don't know about your second problem, but the fix for your first problem is to construct a shared A. You're trying to create a normal A and have it implicitly casted to shared, which the compiler won't do.
InputRange!(shared A) foo()
{
//"new shared A" instead of "new A"
return [new shared A].inputRangeObject;
}
|
July 08, 2014 Re: [dmd 2.066-b1] std.range.array with shared objects and AA rehash | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On Monday, 7 July 2014 at 15:34:33 UTC, Meta wrote: > On Monday, 7 July 2014 at 09:53:22 UTC, NCrashed wrote: >> I am using ranges (wrapped in InputRangeObject for use in interfaces) of shared objects, with new beta some cases are broken: >> ``` >> import std.range; >> >> class A {} >> >> InputRange!(shared A) foo() >> { >> return [new A].inputRangeObject; >> } >> >> void bar() >> { >> auto res = foo.array; >> } >> >> void main() {} >> ``` >> Fails with: >> ``` >> source/app.d(7): Error: cannot implicitly convert expression (inputRangeObject([new A])) of type std.range.InputRangeObject!(A[]).InputRangeObject to std.range.InputRange!(shared(A)).InputRange >> /usr/include/dmd/phobos/std/conv.d(3914): Error: cannot implicitly convert expression (arg) of type shared(A) to app.A >> /usr/include/dmd/phobos/std/array.d(2476): Error: template instance std.conv.emplaceRef!(shared(A)).emplaceRef!(shared(A)) error instantiating >> /usr/include/dmd/phobos/std/array.d(64): instantiated from here: put!(shared(A)) >> source/app.d(12): instantiated from here: array!(InputRange!(shared(A))) >> ``` >> >> And also AA starts behave strange in shared context: >> ``` >> shared string[][string] map; >> >> void main() >> { >> map.rehash; >> } >> ``` >> My AA is stored in shared class, the shared is inferred implicitly. Also following workaround works: >> ``` >> void main() >> { >> (cast(shared(string[])[string])map).rehash; >> } >> ``` >> >> Is this behavior a bug, or it works as expected? > > I don't know about your second problem, but the fix for your first problem is to construct a shared A. You're trying to create a normal A and have it implicitly casted to shared, which the compiler won't do. > > InputRange!(shared A) foo() > { > //"new shared A" instead of "new A" > return [new shared A].inputRangeObject; > } Oops, I forgot shared at new. But the major issue is that doesn't fix the problem: ``` import std.range; class A {} InputRange!(shared A) foo() { return [new shared A].inputRangeObject; } void bar() { auto res = foo.array; } void main() {} ``` Output: ``` /usr/include/dmd/phobos/std/conv.d(3914): Error: cannot implicitly convert expression (arg) of type shared(A) to app.A /usr/include/dmd/phobos/std/array.d(2476): Error: template instance std.conv.emplaceRef!(shared(A)).emplaceRef!(shared(A)) error instantiating /usr/include/dmd/phobos/std/array.d(64): instantiated from here: put!(shared(A)) source/app.d(12): instantiated from here: array!(InputRange!(shared(A))) ``` |
July 08, 2014 Re: [dmd 2.066-b1] std.range.array with shared objects and AA rehash | ||||
---|---|---|---|---|
| ||||
Posted in reply to NCrashed | On Tuesday, 8 July 2014 at 12:42:44 UTC, NCrashed wrote:
> Oops, I forgot shared at new. But the major issue is that doesn't fix the problem:
> ```
> import std.range;
>
> class A {}
>
> InputRange!(shared A) foo()
> {
> return [new shared A].inputRangeObject;
> }
>
> void bar()
> {
> auto res = foo.array;
> }
>
> void main() {}
> ```
> Output:
> ```
> /usr/include/dmd/phobos/std/conv.d(3914): Error: cannot implicitly convert expression (arg) of type shared(A) to app.A
> /usr/include/dmd/phobos/std/array.d(2476): Error: template instance std.conv.emplaceRef!(shared(A)).emplaceRef!(shared(A)) error instantiating
> /usr/include/dmd/phobos/std/array.d(64): instantiated from here: put!(shared(A))
> source/app.d(12): instantiated from here: array!(InputRange!(shared(A)))
> ```
Hmmm, it worked when I compiled it on Dpaste, so you must be using a different compiler. There were some changes to shared in the current 2.066 beta, so that may be the cause. Somebody more experienced with shared than me will have to answer.
|
July 08, 2014 Re: [dmd 2.066-b1] std.range.array with shared objects and AA rehash | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On Tuesday, 8 July 2014 at 13:07:57 UTC, Meta wrote:
> On Tuesday, 8 July 2014 at 12:42:44 UTC, NCrashed wrote:
>> Oops, I forgot shared at new. But the major issue is that doesn't fix the problem:
>> ```
>> import std.range;
>>
>> class A {}
>>
>> InputRange!(shared A) foo()
>> {
>> return [new shared A].inputRangeObject;
>> }
>>
>> void bar()
>> {
>> auto res = foo.array;
>> }
>>
>> void main() {}
>> ```
>> Output:
>> ```
>> /usr/include/dmd/phobos/std/conv.d(3914): Error: cannot implicitly convert expression (arg) of type shared(A) to app.A
>> /usr/include/dmd/phobos/std/array.d(2476): Error: template instance std.conv.emplaceRef!(shared(A)).emplaceRef!(shared(A)) error instantiating
>> /usr/include/dmd/phobos/std/array.d(64): instantiated from here: put!(shared(A))
>> source/app.d(12): instantiated from here: array!(InputRange!(shared(A)))
>> ```
>
> Hmmm, it worked when I compiled it on Dpaste, so you must be using a different compiler. There were some changes to shared in the current 2.066 beta, so that may be the cause. Somebody more experienced with shared than me will have to answer.
I appreciate you help, the error smells like a bug. That compiles on dmd 2.065, but I am testing new dmd 2.066-b1 to not suddenly get dozens of such errors when it becomes a release.
|
Copyright © 1999-2021 by the D Language Foundation