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

allow ref on locals, globals, and statics #16428

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

WalterBright
Copy link
Member

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @WalterBright!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

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

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.

are these such refs implicitly scope? if not should they be? Also this needs a changelog entry

compiler/src/dmd/dsymbolsem.d Outdated Show resolved Hide resolved
@thewilsonator thewilsonator added the Needs Changelog A changelog entry needs to be added to /changelog label Apr 30, 2024
@WalterBright
Copy link
Member Author

are these such refs implicitly scope`?

Yes.

@thewilsonator
Copy link
Contributor

Good to hear. Please add a fail_compilation (e.g. to diag9679.d) that tests that.

@WalterBright WalterBright force-pushed the refLocal branch 2 times, most recently from c0e8beb to 828b0cf Compare April 30, 2024 07:38
@WalterBright
Copy link
Member Author

Please add a fail_compilation (e.g. to diag9679.d) that tests that.

done.

@WalterBright WalterBright force-pushed the refLocal branch 4 times, most recently from 3aa3fdd to 93446d1 Compare May 1, 2024 01:48
@WalterBright
Copy link
Member Author

Cybershadow/DAutoTest gives no indication why it failed.

@thewilsonator
Copy link
Contributor

As always , scroll to the bottom and work your way back up:

object.Exception@../tools/changed.d(256): Changelog entries should consist of one title line, a blank separator line, and a description.

@WalterBright
Copy link
Member Author

@thewilsonator I did scroll through it, but did not see that message, lost in the thousands of lines of output. Thanks for finding it for me!

@thewilsonator thewilsonator added Pending DIP Approval and removed Needs Changelog A changelog entry needs to be added to /changelog labels May 1, 2024
Copy link
Contributor

@ntrel ntrel left a comment

Choose a reason for hiding this comment

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

What about (ref i) { ref r = i; ... } - is the declaration of r an error?

changelog/dmd.reflocal.dd Outdated Show resolved Hide resolved
changelog/dmd.reflocal.dd Show resolved Hide resolved
@WalterBright
Copy link
Member Author

@ntrel it's the same as the way ref is used in any other context. Same semantics.

@WalterBright WalterBright force-pushed the refLocal branch 6 times, most recently from c36e4d1 to 543387e Compare May 2, 2024 15:16
@WalterBright
Copy link
Member Author

@ntrel it's the same behavior as:

void foo(ref int x);
void bar(ref int y)
{
    foo(y);
}

@WalterBright
Copy link
Member Author

This is ready to go now.

Copy link
Contributor

@dkorpel dkorpel left a comment

Choose a reason for hiding this comment

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

The changelog makes it sound like the DIP was already accepted. Should we wait with merging or word is as a preview feature?

@thewilsonator
Copy link
Contributor

We should wait, the DIP has not even been submitted, let alone reviewed by the wider community.

@WalterBright
Copy link
Member Author

the DIP has not even been submitted, let alone reviewed by the wider community

That's what https://www.digitalmars.com/d/archives/digitalmars/dip/development/First_Draft_ref_For_Variable_Declarations_74.html is for.

@@ -0,0 +1,14 @@
`ref` can now be applied to local, static, extern, and global variables

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
See the [DIP](https://github.com/WalterBright/documents/blob/master/varRef.md).

@@ -0,0 +1,14 @@
`ref` can now be applied to local, static, extern, and global variables
Copy link
Contributor

Choose a reason for hiding this comment

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

The DIP says:

This DIP is for declaring local variables as ref. Not globals, statics, externs, __gshareds or fields.

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