February 18, 2018
On 2/18/2018 11:26 AM, Manu wrote:
> and most lines get 3-4 times longer because of these casts...

I'm curious, can you please post an example?
February 18, 2018
On Sunday, 18 February 2018 at 19:26:43 UTC, Manu wrote:
>
> The 'solution' so add cast(int) and then cast back is not okay. I have code
> that does a lot of work on bytes/shorts (colour components are small
> integers that receive a lot of maths), and most lines get 3-4 times longer
> because of these casts...
> I can't accept that.
>
> If change the behaviour (is done), then just let the code be broken! Emitting these terrible noises, and encouraging people to make their code even noisier than the compiler output is much worse than broken code.

Silently breaking code by changing language semantics is not an option; we do that accidentally sometimes and it makes upgrading to a newer compiler very very hard on large codebases. Let's cherish the few users of D in production code. The deprecation messages are annoying perhaps, but necessary.

> There are hundreds of lines I need to molest to make the compiler shut up. I won't type another line of code on my colour library until this noise is gone... I will not maintain it. I am emotionally incapable of assaulting my code with those casts.

Using the `-transition=intpromote` compile flag is no option for you?

- Johan

February 18, 2018
On Sunday, February 18, 2018 11:26:43 Manu via Digitalmars-d wrote:
> The 'solution' so add cast(int) and then cast back is not okay. I have
> code that does a lot of work on bytes/shorts (colour components are small
> integers that receive a lot of maths), and most lines get 3-4 times
> longer because of these casts...
> I can't accept that.
>
> If change the behaviour (is done), then just let the code be broken! Emitting these terrible noises, and encouraging people to make their code even noisier than the compiler output is much worse than broken code. There are hundreds of lines I need to molest to make the compiler shut up. I won't type another line of code on my colour library until this noise is gone... I will not maintain it. I am emotionally incapable of assaulting my code with those casts.

You could always create a wrapper type that does the casts for you. IIRC, someone already discussed a solution like that in this thread in order to make (u)byte and (u)short arithmetic more pleasant even without the recent changes. I suspect that if you're doing a lot of arithmetic on (u)bytes or (u)shorts, that eventually becomes pretty much the only way to maintain your sanity - and it could be made to add runtime checks for overflow if that was desired instead of just making the compiler shut up. Then, it could become a runtime check instead of a blunt compile-time check if that's what's preferred.

All in all though, this is one of those areas where trying to make it so that C code is either valid D code with the same semantics, or it doesn't compile gets ugly.

I suspect that the vast majority of programmers will rarely be affected by this, because most code doesn't need to do anything with (u)bytes or (u)shorts, but if you have a use case where you're doing a lot with them, then I can certainly see why it would get _really_ annoying.

- Jonathan M Davis

February 18, 2018
On Sunday, February 18, 2018 19:42:07 Johan Engelen via Digitalmars-d wrote:
> > There are hundreds of lines I need to molest to make the compiler shut up. I won't type another line of code on my colour library until this noise is gone... I will not maintain it. I am emotionally incapable of assaulting my code with those casts.
>
> Using the `-transition=intpromote` compile flag is no option for you?

Since that's a transition flag, it's really only a stop-gap solution. So, if his issue is that he doesn't like having the casts in his code as opposed to not wanting to deal with updating his code right now, the flag really doesn't help.

I'd say that if he's not going to abandon his library, he either needs to just grit his teeth and use the explicit casts, or he's going to need to refactor the code so that the casts are unnecessary.

- Jonathan M Davis

February 18, 2018
On 18 February 2018 at 11:37, Walter Bright via Digitalmars-d < digitalmars-d@puremagic.com> wrote:

> On 2/18/2018 11:21 AM, Guillaume Piolat wrote:
>
>> D used to not promote integer like C in the case of -short, -byte, ~ubyte etc. Which is a strange discrepancy as all other integer arithmetic are the same.
>>
>
> It was a bug, plain and simple. Whether it was always there, or was inadvertently introduced at some point, I don't know.
>

I'm complaining about the deprecation messages.


February 18, 2018
On 18 February 2018 at 12:01, Jonathan M Davis via Digitalmars-d < digitalmars-d@puremagic.com> wrote:

> On Sunday, February 18, 2018 19:42:07 Johan Engelen via Digitalmars-d wrote:
> > > There are hundreds of lines I need to molest to make the compiler shut up. I won't type another line of code on my colour library until this noise is gone... I will not maintain it. I am emotionally incapable of assaulting my code with those casts.
> >
> > Using the `-transition=intpromote` compile flag is no option for you?
>
> Since that's a transition flag, it's really only a stop-gap solution. So,
> if
> his issue is that he doesn't like having the casts in his code as opposed
> to
> not wanting to deal with updating his code right now, the flag really
> doesn't help.
>
> I'd say that if he's not going to abandon his library, he either needs to just grit his teeth and use the explicit casts, or he's going to need to refactor the code so that the casts are unnecessary.
>
> - Jonathan M Davis
>

Here's one file for instance (they all do this, although I can rearrange
the noise somewhat):

std\experimental\normint.d(526,24): Deprecation: integral promotion not
done for `-convertNormBits(((v ^ 512u) == 0u ? ~v : -v) & 511u)`, use
'-transition=intpromote' switch or `-cast(int)(convertNormBits(((v ^ 512u)
== 0u ? ~v : -v) & 511u))`
std\experimental\normint.d(526,119): Deprecation: integral promotion not
done for `~v`, use '-transition=intpromote' switch or `~cast(int)(v)`
std\experimental\normint.d(526,124): Deprecation: integral promotion not
done for `-v`, use '-transition=intpromote' switch or `-cast(int)(v)`
std\experimental\normint.d-mixin-78(78,1): Deprecation: integral promotion
not done for `+this.value`, use '-transition=intpromote' switch or
`+cast(int)(this.value)`
std\experimental\normint.d-mixin-78(78,1): Deprecation: integral promotion
not done for `-this.value`, use '-transition=intpromote' switch or
`-cast(int)(this.value)`
std\experimental\normint.d-mixin-78(78,1): Deprecation: integral promotion
not done for `~this.value`, use '-transition=intpromote' switch or
`~cast(int)(this.value)`
std\experimental\normint.d-mixin-78(78,1): Deprecation: integral promotion
not done for `~this.value`, use '-transition=intpromote' switch or
`~cast(int)(this.value)`
std\experimental\normint.d-mixin-78(78,1): Deprecation: integral promotion
not done for `-this.value`, use '-transition=intpromote' switch or
`-cast(int)(this.value)`
std\experimental\normint.d(526,119): Deprecation: integral promotion not
done for `~v`, use '-transition=intpromote' switch or `~cast(int)(v)`
std\experimental\normint.d(526,124): Deprecation: integral promotion not
done for `-v`, use '-transition=intpromote' switch or `-cast(int)(v)`
std\experimental\normint.d(526,24): Deprecation: integral promotion not
done for `-convertNormBits(cast(ubyte)(((cast(int)v ^ 128) == 0 ?
cast(int)~v : cast(int)-v) & 127))`, use '-transition=intpromote' switch or
`-cast(int)(convertNormBits(cast(ubyte)(((cast(int)v ^ 128) == 0 ?
cast(int)~v : cast(int)-v) & 127)))`
std\experimental\normint.d(526,119): Deprecation: integral promotion not
done for `~v`, use '-transition=intpromote' switch or `~cast(int)(v)`
std\experimental\normint.d(526,124): Deprecation: integral promotion not
done for `-v`, use '-transition=intpromote' switch or `-cast(int)(v)`
std\experimental\normint.d(526,24): Deprecation: integral promotion not
done for `-convertNormBits(cast(ushort)(((cast(int)v ^ 32768) == 0 ?
cast(int)~v : cast(int)-v) & 32767))`, use '-transition=intpromote' switch
or `-cast(int)(convertNormBits(cast(ushort)(((cast(int)v ^ 32768) == 0 ?
cast(int)~v : cast(int)-v) & 32767)))`
std\experimental\normint.d(526,24): Deprecation: integral promotion not
done for `-convertNormBits(((v ^ 2u) == 0u ? ~v : -v) & 1u)`, use
'-transition=intpromote' switch or `-cast(int)(convertNormBits(((v ^ 2u) ==
0u ? ~v : -v) & 1u))`
std\experimental\normint.d(526,24): Deprecation: integral promotion not
done for `-convertNormBits(((v ^ 4u) == 0u ? ~v : -v) & 3u)`, use
'-transition=intpromote' switch or `-cast(int)(convertNormBits(((v ^ 4u) ==
0u ? ~v : -v) & 3u))`
std\experimental\normint.d-mixin-78(78,1): Deprecation: integral promotion
not done for `+this.value`, use '-transition=intpromote' switch or
`+cast(int)(this.value)`
std\experimental\normint.d(526,119): Deprecation: integral promotion not
done for `~v`, use '-transition=intpromote' switch or `~cast(int)(v)`
std\experimental\normint.d(526,124): Deprecation: integral promotion not
done for `-v`, use '-transition=intpromote' switch or `-cast(int)(v)`
std\experimental\normint.d(526,24): Deprecation: integral promotion not
done for `-convertNormBits(cast(const(ubyte))(((cast(int)v ^ 128) == 0 ?
cast(int)~v : cast(int)-v) & 127))`, use '-transition=intpromote' switch or
`-cast(int)(convertNormBits(cast(const(ubyte))(((cast(int)v ^ 128) == 0 ?
cast(int)~v : cast(int)-v) & 127)))`
std\experimental\normint.d(526,119): Deprecation: integral promotion not
done for `~v`, use '-transition=intpromote' switch or `~cast(int)(v)`
std\experimental\normint.d(526,124): Deprecation: integral promotion not
done for `-v`, use '-transition=intpromote' switch or `-cast(int)(v)`
std\experimental\normint.d(526,24): Deprecation: integral promotion not
done for `-convertNormBits(cast(const(ushort))(((cast(int)v ^ 32768) == 0 ?
cast(int)~v : cast(int)-v) & 32767))`, use '-transition=intpromote' switch
or `-cast(int)(convertNormBits(cast(const(ushort))(((cast(int)v ^ 32768) ==
0 ? cast(int)~v : cast(int)-v) & 32767)))`

I'll admit I'm wildly overreacting, but I don't want to explicitly write
the implicit casts.
It's a library for other people to use; so the suggestion is really "tell
everyone using the lib to build with -transition=intpromote".

If -x does implicit int promotion, fine... but I don't want to explicitly
cast to int everywhere to silence the noise up when the cast is actually
implicit!
How long is this message meant to hang around? I think I'd rather wait
until it's gone than change the code...


February 18, 2018
On 02/18/2018 08:26 PM, Manu wrote:
> If change the behaviour (is done), then just let the code be broken! Emitting these terrible noises, and encouraging people to make their code even noisier than the compiler output is much worse than broken code. There are hundreds of lines I need to molest to make the compiler shut up. I won't type another line of code on my colour library until this noise is gone... I will not maintain it. I am emotionally incapable of assaulting my code with those casts.

Best solution, write a custom Int type that doesn't use C's horrible
promotion rules.
I've long wanted some SafeInt library that doesn't silently promote and
supports saturation, overflow, and errors.

-Martin
February 18, 2018
On 18 February 2018 at 13:17, Martin Nowak via Digitalmars-d < digitalmars-d@puremagic.com> wrote:

> On 02/18/2018 08:26 PM, Manu wrote:
> > If change the behaviour (is done), then just let the code be broken! Emitting these terrible noises, and encouraging people to make their code even noisier than the compiler output is much worse than broken code. There are hundreds of lines I need to molest to make the compiler shut
> up.
> > I won't type another line of code on my colour library until this noise
> is
> > gone... I will not maintain it. I am emotionally incapable of assaulting
> my
> > code with those casts.
>
> Best solution, write a custom Int type that doesn't use C's horrible
> promotion rules.
> I've long wanted some SafeInt library that doesn't silently promote and
> supports saturation, overflow, and errors.
>

That's pretty much what this particular code implements ;)


February 18, 2018
Just replying to the n.g. would be fine, no need to cc me on email and cc the mailing list.

Also, your postings are double size again - html and plain text. Just the plain text, please.
February 18, 2018
On 2/18/2018 1:17 PM, Martin Nowak wrote:
> Best solution, write a custom Int type that doesn't use C's horrible
> promotion rules.
> I've long wanted some SafeInt library that doesn't silently promote and
> supports saturation, overflow, and errors.

Doesn't https://dlang.org/phobos/std_experimental_checkedint.html do that? It supports saturation, overflow, errors, and has hooks for operators.