Skip to content

Conversation

@PetarKirov
Copy link
Member

No description provided.

When the `in` parameter storage class changes its meaning to `scope const` we would get
the following errors:

source/dub/dependency.d(83): Error: scope variable `ver` assigned to `this` with longer lifetime
source/dub/dependency.d(84): Error: scope variable `ver` assigned to `this` with longer lifetime

This commit fixes this.
@dlang-bot
Copy link
Collaborator

Thanks for your pull request, @PetarKirov!

@PetarKirov PetarKirov changed the title Fix DIP1000 compatibility and future in=scope const dmd change Fix compilation with DIP1000 and compatibility with future in=scope const dmd change Oct 31, 2019
if (platform.platform.canFind("windows"))
return settings.targetName ~ ".exe";
else return settings.targetName;
else return settings.targetName.idup;
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't this copy be avoided by annotating settings with return?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that should work and I thought about that, but I decided not to change the interface. I think it's more of compiler deficiency that it doesn't recognize that settings.targetName in GC allocated and so it has infinite lifetime, and so it's safe to escape it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually I now remember why I didn't add the return attribute. The reason is that in all, but this single case, this function doesn't escape any part of it's parameter. Although this may sound too theoretical, in principle adding return attribute essentially limits callers of the function, meaning that just because of this single case they will need ensure that lifetime of settings is as long as the one of the result, which is mildly annoying.
A better solution than the idup is a function (with potentially the same name) that returns the argument as it is (without copying) if it is immutable with infinite lifetime.

@PetarKirov
Copy link
Member Author

One of the AppVeyor builds is failing with out of memory since several other PRs, so it's unrelated.

@wilzbach wilzbach merged commit 1bb989e into dlang:master Nov 1, 2019
@wilzbach
Copy link
Contributor

wilzbach commented Nov 1, 2019

Thanks!

@PetarKirov PetarKirov deleted the fix-in-param-attr branch November 1, 2019 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants