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 issues 22130, 17635 - pure factory functions #12890

Merged
merged 8 commits into from
Jan 25, 2022
Merged

Conversation

aG0aep6G
Copy link
Contributor

Issue 22130 - [REG2.080.1][DIP1000] pure factory functions stopped working
Issue 17635 - [REG 2.066.0] cannot convert unique immutable(int)** to
immutable

Immutable parameters are not needed for strong purity. Const is enough.
Mutability in the return type is an additional condition on top of strong
purity when considering side effects.

The test case for issue 17635 was inverted without good reason in
#8048. Flipping again to revert that
mistake.

@dlang-bot
Copy link
Contributor

dlang-bot commented Jul 19, 2021

Thanks for your pull request and interest in making D better, @aG0aep6G! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
17635 regression [REG 2.066.0] cannot convert unique immutable(int)** to immutable
22130 regression [REG2.080.1][DIP1000] pure factory functions stopped working

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

To target stable perform these two steps:

  1. Rebase your branch to upstream/stable:
git rebase --onto upstream/stable upstream/master
  1. Change the base branch of your PR to stable

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 "master + dmd#12890"

Copy link
Contributor

@thewilsonator thewilsonator left a comment

Choose a reason for hiding this comment

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

This PR breaks a number of projects on buildkite (with warnings as errors), most of the error seem to be of the form

src\object.d(3824): Warning: calling `object.dup!(Sunsafe).dup` without side effects discards return value of type `Sunsafe[]`; prepend a `cast(void)` if intentional
src\object.d(3875): Warning: calling `object.dup!(Sunsafe).dup` without side effects discards return value of type `Sunsafe[]`; prepend a `cast(void)` if intentional
src/dmd/link.d(707): Warning: calling `dmd.root.rmem.Mem.error` without side effects discards return value of type `void*`; prepend a `cast(void)` if intentional
/src/ocean/core/SmartUnion.d(549): Warning: calling `ocean.core.SmartUnion.SmartUnion!(HasDuplicates).SmartUnion.opCall` without side effects discards return value of type `SmartUnion!(HasDuplicates)`; prepend a `cast(void)` if intentional

and a number of segfaults (which may just be OOMs)

src/dmd/frontend.h Show resolved Hide resolved
src/dmd/mtype.d Show resolved Hide resolved
@thewilsonator
Copy link
Contributor

the src/dmd/link.d(707) warning seems to come from an unconditional assert(0)

    static void* error() pure nothrow @nogc @safe
    {
        onOutOfMemoryError();
        assert(0);
    }

used like

    static void* check(void* p) pure nothrow @nogc
    {
        return p ? p : error();
    }

Not sure about the other.

@thewilsonator
Copy link
Contributor

src/dmd/link.d(707) seems to be the only caller of root.rmem.Mem.error() so if you want to change

dmd/src/dmd/link.d

Lines 705 to 707 in 1a1b81d

auto buf = (cast(char*) malloc(bufsize))[0 .. bufsize];
if (!buf)
Mem.error();

to a call to Mem.check() that should fix that problem

@aG0aep6G
Copy link
Contributor Author

src/dmd/link.d(707) seems to be the only caller of root.rmem.Mem.error() so if you want to change

dmd/src/dmd/link.d

Lines 705 to 707 in 1a1b81d

auto buf = (cast(char*) malloc(bufsize))[0 .. bufsize];
if (!buf)
Mem.error();

to a call to Mem.check() that should fix that problem

Sounds good. Done.

@thewilsonator
Copy link
Contributor

Dependant PRs merged

@aG0aep6G
Copy link
Contributor Author

Some test results seem to be outdated. E.g., the Azure pipelines show warnings in druntime that I already addressed.

Others I can't reproduce locally. E.g., CyberShadow/DAutoTest says that dlang.org's test_dspec fails with "double free or corruption", but it works for me locally.

How do I push this forward?

@thewilsonator
Copy link
Contributor

Im pretty sure you'll need to restart the pipelines by rebasing (or force pushing) as for the doublefree IDK

@aG0aep6G
Copy link
Contributor Author

The outdated test results are gone. But I'm still stuck at the ones I can't reproduce locally.

Looking at buildkite, there seems to be memory corruption related to tempCString ("Failed to stat file [garbage]"). That could happen if a tempCString were wrongly reused, which is something that this PR might introduce. But I can't tell how it happens, and I can't reproduce the error.

@dkorpel
Copy link
Contributor

dkorpel commented Nov 13, 2021

@aG0aep6G Now that #13047 is merged, could you rebase this? I'm hoping the segfault goes away.

@aG0aep6G
Copy link
Contributor Author

@aG0aep6G Now that #13047 is merged, could you rebase this? I'm hoping the segfault goes away.

rebased

dkorpel added a commit to dkorpel/ocean that referenced this pull request Nov 14, 2021
Buildkite fails on this dmd PR:
dlang/dmd#12890

```
./submodules/ocean/src/ocean/core/SmartUnion.d(549): Warning: calling `ocean.core.SmartUnion.SmartUnion!(HasDuplicates).SmartUnion.opCall` without side effects discards return value of type `SmartUnion!(HasDuplicates)`; prepend a `cast(void)` if intentional
```
@RazvanN7 RazvanN7 closed this Nov 16, 2021
@RazvanN7 RazvanN7 reopened this Nov 16, 2021
@@ -302,8 +302,7 @@ public:
//property(name, "impure");
break;
case PURE.weak: return property(name, "weak");
case PURE.const_: return property(name, "const");
case PURE.strong: return property(name, "strong");
case PURE.const_: return property(name, "strong");
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this mismatch deliberate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this mismatch deliberate?

You mean "const_" vs "strong"? I can rename the enum if you like. I just kept it as "PURE.const_" to make sure that I'm not missing "PURE.strong" being used with the old meaning.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think PURE.strong is a better name, but I'm fine with this as well for this PR, it can easily be renamed later. I just wanted to make sure this wasn't a mistake.

return 1;
}

/* The rest of this is too strict; fix later.
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation of this comment (and others) is off

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indentation of this comment (and others) is off

fixed

* Determine mutability of indirections in (ref) t.
*
* Returns: When the type has any mutable indirections, returns 0.
* When all indirections are immutable, returns 2.
Copy link
Contributor

@dkorpel dkorpel Nov 16, 2021

Choose a reason for hiding this comment

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

Missing a Params: section

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missing a Params: section

fixed

Geod24 pushed a commit to sociomantic-tsunami/ocean that referenced this pull request Nov 23, 2021
Buildkite fails on this dmd PR:
dlang/dmd#12890

```
./submodules/ocean/src/ocean/core/SmartUnion.d(549): Warning: calling `ocean.core.SmartUnion.SmartUnion!(HasDuplicates).SmartUnion.opCall` without side effects discards return value of type `SmartUnion!(HasDuplicates)`; prepend a `cast(void)` if intentional
```
@dkorpel
Copy link
Contributor

dkorpel commented Nov 23, 2021

The PR for 'ocean' is merged, a rebase should make buildkite green now.

@aG0aep6G
Copy link
Contributor Author

The PR for 'ocean' is merged, a rebase should make buildkite green now.

rebased

@Geod24
Copy link
Member

Geod24 commented Dec 12, 2021

What's the plan here ? I personally don't like this warning, because, like every warnings, it can have a high number of false positives. Did it find any issue(s) in the project that are tested ?

Issue 22130 - [REG2.080.1][DIP1000] pure factory functions stopped working
Issue 17635 - [REG 2.066.0] cannot convert unique immutable(int)** to
immutable

Immutable parameters are not needed for strong purity. Const is enough.
Mutability in the return type is an additional condition on top of strong
purity when considering side effects.

The test case for issue 17635 was inverted without good reason in
<dlang#8048>. Flipping again to revert that
mistake.
@aG0aep6G
Copy link
Contributor Author

What's the plan here ? I personally don't like this warning, because, like every warnings, it can have a high number of false positives. Did it find any issue(s) in the project that are tested ?

My plan is to fix issues 22130 and 17635. I don't care about the warning.

@dkorpel
Copy link
Contributor

dkorpel commented Dec 12, 2021

I personally don't like this warning, because, like every warnings, it can have a high number of false positives.

The warning was always there, this PR just makes it more accurate. It's similar to when exit() was changed to be noreturn, spawning new 'unreachable code' warnings in e.g. case X: exit(1); break;. It's really annoying when buildkite projects treat warnings as errors, because that makes improvements to dmd that affect warnings a breaking change. I wish dub wouldn't treat warnings as errors by default.

@dkorpel
Copy link
Contributor

dkorpel commented Jan 24, 2022

@RazvanN7 Can you help advance this PR? It's blocked by buildkite because swarm and turtle need to use the newest version of ocean (see sociomantic-tsunami/ocean#857), but I can't get any answer from anyone at sociomantic on GitHub or Slack and I've been trying for weeks now.

I also thought maybe the buildkite configuration could be changed to not treat warnings as errors, but I don't see buildkite configuration files in this repository, so it seems I need a buildkite account with access before I can look at that.

@MoonlightSentinel
Copy link
Contributor

I also thought maybe the buildkite configuration could be changed to not treat warnings as errors, but I don't see buildkite configuration files in this repository, so it seems I need a buildkite account with access before I can look at that.

The BuildKite configuration is stored in the CI repo, i.e. the buildkite directory

@RazvanN7
Copy link
Contributor

@dkorpel I have privately contacted @Geod24 to ask for some pointers on how we can move on with updating turtle and swarm. I am waiting for his response. Not treating warnings as errors is a viable alternative in my opinion.

@RazvanN7
Copy link
Contributor

@dkorpel I restarted the buildkite pipeline and toggled auto-merge on. However, a rebase might be necessary to pick-up the latest version of buildkite. I hope not, but let's see.

Thanks @aG0aep6G and @dkorpel for seeing this through.

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