dmd icon indicating copy to clipboard operation
dmd copied to clipboard

Fix Issue 22536 - CTFE: Missing destruction of array literal argument for scope slice parameter

Open RazvanN7 opened this issue 3 years ago • 6 comments

It appears that CTFE does not know how to destroy array literal temporaries that are put on stack. My solution first collects the temporary destructors that are created here [1] and interprets them after the function call was interpreted.

[1] https://github.com/dlang/dmd/blob/master/src/dmd/expressionsem.d#L2074

RazvanN7 avatar Jan 06 '22 15:01 RazvanN7

Thanks for your pull request and interest in making D better, @RazvanN7! 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
22536 blocker CTFE: Missing destruction of array literal argument for scope slice parameter

⚠️⚠️⚠️ 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#13496"

dlang-bot avatar Jan 06 '22 15:01 dlang-bot

cc @kinke as this is blocking a fix of yours.

RazvanN7 avatar Jan 06 '22 15:01 RazvanN7

Related issue with -preview=in that ~~might be~~ is fixed by this patch:

int previewIn()
{
    int numDtor;

    struct S
    {
        int x;
        ~this() { ++numDtor; }
    }

    static accept(in S s) {}
    accept(S(1));
    return numDtor;
}

static assert(previewIn() == 1);

MoonlightSentinel avatar Jan 06 '22 16:01 MoonlightSentinel

@MoonlightSentinel is this addition acceptable?

RazvanN7 avatar Jan 10 '22 10:01 RazvanN7

@MoonlightSentinel Done.

RazvanN7 avatar Jan 11 '22 10:01 RazvanN7

@MoonlightSentinel I have addressed your review.

RazvanN7 avatar Feb 01 '22 13:02 RazvanN7