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 Issue 23145 - Stack allocation of scope new variables defeats @safe #14175

Merged
merged 1 commit into from
Feb 9, 2023

Conversation

WalterBright
Copy link
Member

Timon's idea on how to fix this - disallow constructors for stack allocation for operator new unless the constructor is scope.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @WalterBright!

Bugzilla references

Auto-close Bugzilla Severity Description
23145 major Stack allocation of scope new variables defeats @safe

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

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 should target stable unless this is a master only problem.

@WalterBright
Copy link
Member Author

This is not a regression, the problem is as old as dip1000.

@kinke
Copy link
Contributor

kinke commented May 29, 2022

This is primarily a big functional change, definitely worth a big changelog entry. - E.g., I'm pretty sure this prevents all scope Visitor stack-allocation optimizations in the frontend itself. And requires even more attribute soup to get the previous behavior.

@WalterBright WalterBright force-pushed the fix23145 branch 2 times, most recently from a3da521 to 8d260c4 Compare May 30, 2022 00:45
@WalterBright
Copy link
Member Author

@kinke you're right. It'll probably have to go behind a preview switch.

@WalterBright
Copy link
Member Author

Or perhaps we should just start doing attribute inference for constructors.

@WalterBright WalterBright force-pushed the fix23145 branch 2 times, most recently from 92a528a to cae48c5 Compare May 30, 2022 01:39
@WalterBright
Copy link
Member Author

Let's see how far this gets before deciding the best way to deal with older code.

ibuclaw
ibuclaw previously requested changes Jun 4, 2022
src/dmd/nogc.d Outdated Show resolved Hide resolved
@WalterBright WalterBright force-pushed the fix23145 branch 5 times, most recently from 4eb4fa6 to 5128101 Compare June 6, 2022 07:02
@WalterBright WalterBright dismissed stale reviews from thewilsonator and ibuclaw June 6, 2022 22:04

this is a master only problem

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 is not a master only issue, please check before making such false assertions. This affects at least 2.099+ (checked on, run.dlang.io, trying all compilers results in a server error).

@WalterBright
Copy link
Member Author

I don't understand your point. Putting this in stable will destabilize stable.

ljmf00
ljmf00 previously requested changes Jul 23, 2022
compiler/test/compilable/test23145.d Outdated Show resolved Hide resolved
compiler/test/compilable/test23145.d Outdated Show resolved Hide resolved
compiler/src/dmd/dsymbolsem.d Show resolved Hide resolved
compiler/src/dmd/clone.d Show resolved Hide resolved
@ljmf00 ljmf00 added the Review:Needs Spec PR A PR updating the language specification needs to be submitted to dlang.org label Jul 23, 2022
@ljmf00
Copy link
Member

ljmf00 commented Jul 23, 2022

Adding Spec PR tag to clarify scope attribute applied to constructors.

Copy link
Contributor

@RazvanN7 RazvanN7 left a comment

Choose a reason for hiding this comment

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

Mind the nit and please address the other reviewers concerns. @ibuclaw @Geod24 any other objections?

import dmd.aggregate;
import dmd.apply;
import dmd.astenums;
import dmd.declaration;
import dmd.dscope;
import dmd.errors;
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding these 2 imports seems to be an unrelated change.

Copy link
Member Author

Choose a reason for hiding this comment

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

people keep removing core.stdc.stdio, and I keep adding it back in, because it is for the debugging printf's.

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.

Suggestion for the message

compiler/test/compilable/test23145.d Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Review:Needs Spec PR A PR updating the language specification needs to be submitted to dlang.org Severity:Bug Fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants