Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

[REG 2.084] hashOf will fail to compile for some structs/unions that recursively contain shared enums #3376

Merged
merged 1 commit into from
Mar 3, 2021

Conversation

n8sh
Copy link
Member

@n8sh n8sh commented Feb 17, 2021

No description provided.

@dlang-bot
Copy link
Contributor

dlang-bot commented Feb 17, 2021

Thanks for your pull request, @n8sh!

Bugzilla references

Auto-close Bugzilla Severity Description
21642 regression [REG 2.084] hashOf will fail to compile for some structs/unions that recursively contain shared enums

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "stable + druntime#3376"

@dlang-bot dlang-bot added the Bug Fix Include reference to corresponding bugzilla issue label Feb 17, 2021
@n8sh n8sh added the Regression PRs that fix regressions label Feb 17, 2021
// Also test the underlying reason the above was failing.
import core.internal.convert : toUbyte;
shared C c;
cast(void) toUbyte(c);
Copy link
Member

Choose a reason for hiding this comment

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

Instead of casting to void here and above, it's better to check if the return value is the expected one.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a check here. Above there is no particular value the hash code is supposed to be.

Copy link
Member

Choose a reason for hiding this comment

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

My motivation is the question: why would an optimizing compiler not remove a call to a pure function, if it's result is not used?

Technically such optimization happens after semantic analysis (where the bug manifests), in the backend, but in theory the frontend could also discard such function calls, so it's better to make the code more robust.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a change you would suggest that wouldn't make the test brittle?

Copy link
Contributor

Choose a reason for hiding this comment

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

@PetarKirov Pure functions that may throw exceptions should not be optimized away. This pattern is prevalent in druntime: a function that does some checks and throws if the input is not the expected one.

@RazvanN7
Copy link
Contributor

RazvanN7 commented Mar 2, 2021

@n8sh This seems to fail the tester pipeline. Any update on that?

@@ -769,7 +769,7 @@ const(ubyte)[] toUbyte(T)(const ref T val) if (is(T == enum))
if (__ctfe)
{
static if (is(T V == enum)){}
return toUbyte(cast(const V) val);
return toUbyte(*cast(const V*) &val);
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is reported to not be covered by any tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

The coverage report doesn't take into account the tests directory. It is covered by the new test added in this PR.

@n8sh
Copy link
Member Author

n8sh commented Mar 3, 2021

Accidentally rebased on master instead of stable. Fixing.

…ructs/unions that recursively contain shared enums
@dlang-bot dlang-bot merged commit 150823d into dlang:stable Mar 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Fix Include reference to corresponding bugzilla issue Enhancement New functionality Regression PRs that fix regressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants