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 21756 - make cast(immutable)arrayLiteral @nogc #12329

Closed
wants to merge 1 commit into from
Closed

fix 21756 - make cast(immutable)arrayLiteral @nogc #12329

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Mar 31, 2021

adjust array literal semantics so that

cast(immutable) <arrayLiteral>

gets rewritten to a DeclExp comma VarExp

(static immutable __array = <arrayLiteral>, __array)

allowing immutable array literals to be @nogc

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @tungstenheart! 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
21756 major Immutable array literals cause runtime GC allocation instead of static readonly section allocation

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#12329"

adjust array literal semantics so that

```d
cast(immutable) <arrayLiteral>
```

get rewritten to a DeclExp comma VarExp

```d
(static immutable __array = <arrayLiteral>, __array)
```

allowing immutable array literals to be `@nogc`
Copy link
Member

@Geod24 Geod24 left a comment

Choose a reason for hiding this comment

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

I don't think that's a good thing. It's too much magic with no justification. As commented on the issue, using static immutable directly achieves what the user want.

@ghost
Copy link
Author

ghost commented Apr 1, 2021

This breaks legit code anyway. When the elements are not statically evaluable, you can stll put them in an array literal and cast this array as immutable. That would break. That stuff is never done in the test suite as you can see.

@ghost ghost closed this Apr 1, 2021
@ghost ghost deleted the issue-21756 branch May 17, 2021 00:20
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants