Thread overview
Make rt.util.utf publicly available
Dec 03
bauss
4 days ago
Jacob Carlborg
December 03
Hello, everyone.

I've been looking over Phobos' `std.utf` and druntime's `rt.util.utf` as there is some code duplication and I would like to start removing that.

I want to be able to import some of the existing druntime functionality in Phobos, so we can remove the duplication: ex. isValidDchar, toUTF*, etc.

I'm not able to do so, since, as far as I can tell, the `rt` is private: it's not part of the `druntime/import/` folder.

Could you please tell me what's the reasoning behind this decision and what would be the course of action going forward?

Thank you,
Edi
December 03
On Monday, 3 December 2018 at 10:40:03 UTC, Eduard Staniloiu wrote:
> Hello, everyone.
>
> I've been looking over Phobos' `std.utf` and druntime's `rt.util.utf` as there is some code duplication and I would like to start removing that.
>
> I want to be able to import some of the existing druntime functionality in Phobos, so we can remove the duplication: ex. isValidDchar, toUTF*, etc.
>
> I'm not able to do so, since, as far as I can tell, the `rt` is private: it's not part of the `druntime/import/` folder.
>
> Could you please tell me what's the reasoning behind this decision and what would be the course of action going forward?
>
> Thank you,
> Edi

I think the reason behind the duplications is that the runtime shouldn't be dependent on Phobos and Phobos shouldn't be dependent on the runtime.

At least if I remember correctly about other duplications existing.
December 03
On Monday, 3 December 2018 at 10:50:07 UTC, bauss wrote:
> On Monday, 3 December 2018 at 10:40:03 UTC, Eduard Staniloiu wrote:
>> [...]
>
> I think the reason behind the duplications is that the runtime shouldn't be dependent on Phobos and Phobos shouldn't be dependent on the runtime.
>
> At least if I remember correctly about other duplications existing.

Phobos definitely depends on druntime, druntime definitely doesn't depend on Phobos
December 03
On Monday, December 3, 2018 3:40:03 AM MST Eduard Staniloiu via Digitalmars- d wrote:
> Hello, everyone.
>
> I've been looking over Phobos' `std.utf` and druntime's `rt.util.utf` as there is some code duplication and I would like to start removing that.
>
> I want to be able to import some of the existing druntime functionality in Phobos, so we can remove the duplication: ex. isValidDchar, toUTF*, etc.
>
> I'm not able to do so, since, as far as I can tell, the `rt` is private: it's not part of the `druntime/import/` folder.
>
> Could you please tell me what's the reasoning behind this decision and what would be the course of action going forward?

At the moment, I can't remember the exact reasoning behind why the rt stuff is separate, but if you want to consolidate its utf stuff so that Phobos can import it, then just move it into core.internal.utf and have the rt stuff import it.

That being said, this is not a simple case of druntime copying Phobos or vice versa like it was with some traits. I don't know how close the internals are in terms of the resultant logic when operating on arrays, but std.utf's version of things is very much generic, operating on ranges, not arrays specifically, and it uses some stuff from Phobos (especially in its tests), making consolidating the code far less straightforward. So, while I don't disagree that consolidating that code so that druntime and Phobos are guaranteed to use the same logic for arrays is desirable, you're going to need to be very careful about how you go about it if you want to make Phobos depend on druntime in this case.

- Jonathan M Davis



December 05
On Monday, 3 December 2018 at 12:56:01 UTC, John Colvin wrote:
> On Monday, 3 December 2018 at 10:50:07 UTC, bauss wrote:
>> On Monday, 3 December 2018 at 10:40:03 UTC, Eduard Staniloiu wrote:
>>> [...]
>>
>> I think the reason behind the duplications is that the runtime shouldn't be dependent on Phobos and Phobos shouldn't be dependent on the runtime.
>>
>> At least if I remember correctly about other duplications existing.
>
> Phobos definitely depends on druntime, druntime definitely doesn't depend on Phobos

This is also my reasoning on the matter.
December 05
On Monday, 3 December 2018 at 17:02:30 UTC, Jonathan M Davis wrote:
>
> At the moment, I can't remember the exact reasoning behind why the rt stuff is separate, but if you want to consolidate its utf stuff so that Phobos can import it, then just move it into core.internal.utf and have the rt stuff import it.
>
> That being said, this is not a simple case of druntime copying Phobos or vice versa like it was with some traits. I don't know how close the internals are in terms of the resultant logic when operating on arrays, but std.utf's version of things is very much generic, operating on ranges, not arrays specifically, and it uses some stuff from Phobos (especially in its tests), making consolidating the code far less straightforward. So, while I don't disagree that consolidating that code so that druntime and Phobos are guaranteed to use the same logic for arrays is desirable, you're going to need to be very careful about how you go about it if you want to make Phobos depend on druntime in this case.
>
> - Jonathan M Davis

Thanks.

I'll take this course of action. The plan is to have Phobos import the common sub-set of functionality, that is present in druntime.

Cheers,
Edi
4 days ago
On 2018-12-03 11:40, Eduard Staniloiu wrote:

> Could you please tell me what's the reasoning behind this decision and
> what would be the course of action going forward?

The "rt" package is for internal usage by the compiler or druntime. "core" is for external users.

-- 
/Jacob Carlborg