Skip to content
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

fix Issue 16997 - Integral promotion rules not being followed for neg… #7013

Merged
merged 1 commit into from
Oct 23, 2017

Conversation

WalterBright
Copy link
Member

…ation expressions

Not following integral promotion rules is a serious bug. Don't pull this yet, I want to see what impact fixing this has first.

@dlang-bot
Copy link
Contributor

dlang-bot commented Jul 22, 2017

Thanks for your pull request, @WalterBright!

Bugzilla references

Auto-close Bugzilla Description
16997 Integral promotion rules not being followed for unary + - ~ expressions

⚠️⚠️⚠️ Warnings ⚠️⚠️⚠️

@WalterBright
Copy link
Member Author

Blocked by dlang/phobos#5646


This is corrected when one of the following command line switches are used:

-transition=promote
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps -transition=intpromote for a little bit more of a hint as to the meaning when users encounter the flag in makefiles/…?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

src/ddmd/dcast.d Outdated
case Tchar:
case Twchar:
case Tdchar:
ue.warning("integral promotion not done for `%s`, use '-transition=promote' switch or `%scast(int)(%s)`",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-transition=intpromote

@MartinNowak
Copy link
Member

This breaks lots of packages because this PR is using warnings instead of deprecations. This is an outdated practice from before the -dw and -de switches were added, and deprecations were changed to non-fatal by default.
Most people (and currently dub by default) treat warnings as fatal and deprecations as non-fatal, following dmd's no-noise warnings approach.
Also, fairly simple, we should handle deprecations in the language like those in libraries.

Also see dlang/dub#493

@WalterBright
Copy link
Member Author

The new arrayop stuff you wrote breaks with this:

src/core/internal/arrayop.d-mixin-56(56): Warning: integral promotion not done for `-_param_2[pos]`, use '-transition=promote' switch or `-cast(int)(_param_2[pos])`

It's a bit hard to see where that is coming from in arrayop.d - can you have a look, please? In general, the idea is to replace -x with 0-x and ~x with -1-x

@MartinNowak
Copy link
Member

MartinNowak commented Aug 19, 2017

It's a bit hard to see where that is coming from in arrayop.d - can you have a look, please? In general, the idea is to replace -x with 0-x and ~x with -1-x

Well the existing arrayop as well as the new implementation only perform a single cast.

// byte[] = -byte[];
foreach (i; 0 .. result.length)
  result[i] = cast(byte)(-a[i]);
// byte[] = -byte[] + byte[];
foreach (i; 0 .. result.length)
  result[i] = cast(byte)(-a[i] + b[i]);

There is one final cast before assigning that deals with intermediate integer promotions.
So it's somewhat of a false error of your deprecation. Could you check whether the expressions gets promoted or cast anyhow?
It's somewhat laborious to add a workaround for this, as arrayops support arbitrary mixed types. I'd need to change the architecture of the codegen to run type inference of sub-expressions alongside the codegeneration in order to be able to add special code for some type+operation combinations.

@andralex
Copy link
Member

So what's the outlook on this? Deprecate or warn? I'm okay with each seeing that each approach has been massively used by various languages. Since we're not making this language change as part of a major general language update, deprecation seems a lot more sensible. @WalterBright can you please use deprecation?

@WalterBright WalterBright force-pushed the fix16997 branch 8 times, most recently from fb78b21 to ca7483d Compare October 20, 2017 09:05
@WalterBright
Copy link
Member Author

Blocked by dlang/phobos#5793

@WalterBright
Copy link
Member Author

@andralex it's using deprecation now, and is passing.

@andralex andralex merged commit 7253190 into dlang:master Oct 23, 2017
@WalterBright WalterBright deleted the fix16997 branch October 23, 2017 22:58
@schveiguy
Copy link
Member

Note, the changelog here didn't reflect the update to doing deprecations instead of warnings. See https://issues.dlang.org/show_bug.cgi?id=18148

@Geod24
Copy link
Member

Geod24 commented Mar 17, 2020

This deprecation triggers on valid code and is fairly annoying. See https://issues.dlang.org/show_bug.cgi?id=20678

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants