fix Issue 23145 - Stack allocation of scope new variables defeats @safe
Timon's idea on how to fix this - disallow constructors for stack allocation for operator new unless the constructor is scope.
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"
This is not a regression, the problem is as old as dip1000.
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.
@kinke you're right. It'll probably have to go behind a preview switch.
Or perhaps we should just start doing attribute inference for constructors.
Let's see how far this gets before deciding the best way to deal with older code.
I don't understand your point. Putting this in stable will destabilize stable.
These tests:
Failed tests:
test/unit/interfaces/check_implementations_20861.d:100
[Tuple!(string, Kind)("object", private_), Tuple!(string, Kind)("std.stdio", public_), Tuple!(string, Kind)("std.file", private_)]
all fail with master on my Ubuntu machine, too. If anyone could find just what code this PR is failing on, I'd appreciate the help.
More and more it seems the vast bulk of my debugging time is spent just trying to figure out what file where is failing in the test suites. The easy ones to find are the ones in test/runnable, test/compilable, and test/fail_compilation. I dread failures anywhere else, because they are rube goldberg maze.
circleci fails with:
../dmd/generated/linux/debug/64/dmd -conf= -I../dmd/druntime/import -w -de -preview=dip1000 -preview=dtorfields -preview=fieldwise -m64 -fPIC -g -debug -lib -ofgenerated/linux/debug/64/libphobos2.a ../dmd/druntime/../generated/linux/debug/64/libdruntime.a std/array.d std/ascii.d std/base64.d std/bigint.d std/bitmanip.d std/checkedint.d std/compiler.d std/complex.d std/concurrency.d std/conv.d std/csv.d std/demangle.d std/encoding.d std/exception.d std/file.d std/functional.d std/getopt.d std/int128.d std/json.d std/mathspecial.d std/meta.d std/mmfile.d std/numeric.d std/outbuffer.d std/package.d std/parallelism.d std/path.d std/process.d std/random.d std/signals.d std/socket.d std/stdint.d std/stdio.d std/string.d std/sumtype.d std/system.d std/traits.d std/typecons.d std/uri.d std/utf.d std/uuid.d std/variant.d std/xml.d std/zip.d std/zlib.d std/algorithm/comparison.d std/algorithm/iteration.d std/algorithm/mutation.d std/algorithm/package.d std/algorithm/searching.d std/algorithm/setops.d std/algorithm/sorting.d std/container/array.d std/container/binaryheap.d std/container/dlist.d std/container/package.d std/container/rbtree.d std/container/slist.d std/container/util.d std/datetime/date.d std/datetime/interval.d std/datetime/package.d std/datetime/stopwatch.d std/datetime/systime.d std/datetime/timezone.d std/digest/crc.d std/digest/hmac.d std/digest/md.d std/digest/murmurhash.d std/digest/package.d std/digest/ripemd.d std/digest/sha.d std/experimental/allocator/common.d std/experimental/allocator/gc_allocator.d std/experimental/allocator/mallocator.d std/experimental/allocator/mmap_allocator.d std/experimental/allocator/package.d std/experimental/allocator/showcase.d std/experimental/allocator/typed.d std/experimental/allocator/building_blocks/affix_allocator.d std/experimental/allocator/building_blocks/aligned_block_list.d std/experimental/allocator/building_blocks/allocator_list.d std/experimental/allocator/building_blocks/ascending_page_allocator.d std/experimental/allocator/building_blocks/bucketizer.d std/experimental/allocator/building_blocks/fallback_allocator.d std/experimental/allocator/building_blocks/free_list.d std/experimental/allocator/building_blocks/free_tree.d std/experimental/allocator/building_blocks/bitmapped_block.d std/experimental/allocator/building_blocks/kernighan_ritchie.d std/experimental/allocator/building_blocks/null_allocator.d std/experimental/allocator/building_blocks/package.d std/experimental/allocator/building_blocks/quantizer.d std/experimental/allocator/building_blocks/region.d std/experimental/allocator/building_blocks/scoped_allocator.d std/experimental/allocator/building_blocks/segregator.d std/experimental/allocator/building_blocks/stats_collector.d std/experimental/logger/core.d std/experimental/logger/filelogger.d std/experimental/logger/nulllogger.d std/experimental/logger/multilogger.d std/experimental/logger/package.d std/format/package.d std/format/read.d std/format/spec.d std/format/write.d std/format/internal/floats.d std/format/internal/read.d std/format/internal/write.d std/math/algebraic.d std/math/constants.d std/math/exponential.d std/math/hardware.d std/math/operations.d std/math/package.d std/math/remainder.d std/math/rounding.d std/math/traits.d std/math/trigonometry.d std/net/curl.d std/net/isemail.d std/uni/package.d std/experimental/checkedint.d std/experimental/typecons.d std/range/interfaces.d std/range/package.d std/range/primitives.d std/regex/package.d std/regex/internal/generator.d std/regex/internal/ir.d std/regex/internal/parser.d std/regex/internal/backtracking.d std/regex/internal/tests.d std/regex/internal/tests2.d std/regex/internal/thompson.d std/regex/internal/kickstart.d std/windows/charset.d std/windows/registry.d std/windows/syserror.d etc/c/curl.d etc/c/odbc/sql.d etc/c/odbc/sqlext.d etc/c/odbc/sqltypes.d etc/c/odbc/sqlucode.d etc/c/sqlite3.d etc/c/zlib.d std/algorithm/internal.d std/digest/digest.d std/internal/cstring.d std/internal/digest/sha_SSSE3.d std/internal/math/biguintcore.d std/internal/math/biguintnoasm.d std/internal/math/biguintx86.d std/internal/math/errorfunction.d std/internal/math/gammafunction.d std/internal/scopebuffer.d std/internal/test/dummyrange.d std/internal/test/range.d std/internal/unicode_comp.d std/internal/unicode_decomp.d std/internal/unicode_grapheme.d std/internal/unicode_norm.d std/internal/unicode_tables.d std/internal/windows/advapi32.d std/typetuple.d generated/linux/debug/64/etc/c/zlib/adler32.o generated/linux/debug/64/etc/c/zlib/compress.o generated/linux/debug/64/etc/c/zlib/crc32.o generated/linux/debug/64/etc/c/zlib/deflate.o generated/linux/debug/64/etc/c/zlib/gzclose.o generated/linux/debug/64/etc/c/zlib/gzlib.o generated/linux/debug/64/etc/c/zlib/gzread.o generated/linux/debug/64/etc/c/zlib/gzwrite.o generated/linux/debug/64/etc/c/zlib/infback.o generated/linux/debug/64/etc/c/zlib/inffast.o generated/linux/debug/64/etc/c/zlib/inflate.o generated/linux/debug/64/etc/c/zlib/inftrees.o generated/linux/debug/64/etc/c/zlib/trees.o generated/linux/debug/64/etc/c/zlib/uncompr.o generated/linux/debug/64/etc/c/zlib/zutil.o
../dmd/generated/linux/debug/64/dmd -conf= -I../dmd/druntime/import -w -de -preview=dip1000 -preview=dtorfields -preview=fieldwise -m64 -fPIC -g -debug -shared -defaultlib= -debuglib= -L-lpthread -L-lm -ofgenerated/linux/debug/64/libphobos2.so.0.100.1 -L-soname=libphobos2.so.0.100 ../dmd/druntime/../generated/linux/debug/64/libdruntime.so.a -L-ldl std/array.d std/ascii.d std/base64.d std/bigint.d std/bitmanip.d std/checkedint.d std/compiler.d std/complex.d std/concurrency.d std/conv.d std/csv.d std/demangle.d std/encoding.d std/exception.d std/file.d std/functional.d std/getopt.d std/int128.d std/json.d std/mathspecial.d std/meta.d std/mmfile.d std/numeric.d std/outbuffer.d std/package.d std/parallelism.d std/path.d std/process.d std/random.d std/signals.d std/socket.d std/stdint.d std/stdio.d std/string.d std/sumtype.d std/system.d std/traits.d std/typecons.d std/uri.d std/utf.d std/uuid.d std/variant.d std/xml.d std/zip.d std/zlib.d std/algorithm/comparison.d std/algorithm/iteration.d std/algorithm/mutation.d std/algorithm/package.d std/algorithm/searching.d std/algorithm/setops.d std/algorithm/sorting.d std/container/array.d std/container/binaryheap.d std/container/dlist.d std/container/package.d std/container/rbtree.d std/container/slist.d std/container/util.d std/datetime/date.d std/datetime/interval.d std/datetime/package.d std/datetime/stopwatch.d std/datetime/systime.d std/datetime/timezone.d std/digest/crc.d std/digest/hmac.d std/digest/md.d std/digest/murmurhash.d std/digest/package.d std/digest/ripemd.d std/digest/sha.d std/experimental/allocator/common.d std/experimental/allocator/gc_allocator.d std/experimental/allocator/mallocator.d std/experimental/allocator/mmap_allocator.d std/experimental/allocator/package.d std/experimental/allocator/showcase.d std/experimental/allocator/typed.d std/experimental/allocator/building_blocks/affix_allocator.d std/experimental/allocator/building_blocks/aligned_block_list.d std/experimental/allocator/building_blocks/allocator_list.d std/experimental/allocator/building_blocks/ascending_page_allocator.d std/experimental/allocator/building_blocks/bucketizer.d std/experimental/allocator/building_blocks/fallback_allocator.d std/experimental/allocator/building_blocks/free_list.d std/experimental/allocator/building_blocks/free_tree.d std/experimental/allocator/building_blocks/bitmapped_block.d std/experimental/allocator/building_blocks/kernighan_ritchie.d std/experimental/allocator/building_blocks/null_allocator.d std/experimental/allocator/building_blocks/package.d std/experimental/allocator/building_blocks/quantizer.d std/experimental/allocator/building_blocks/region.d std/experimental/allocator/building_blocks/scoped_allocator.d std/experimental/allocator/building_blocks/segregator.d std/experimental/allocator/building_blocks/stats_collector.d std/experimental/logger/core.d std/experimental/logger/filelogger.d std/experimental/logger/nulllogger.d std/experimental/logger/multilogger.d std/experimental/logger/package.d std/format/package.d std/format/read.d std/format/spec.d std/format/write.d std/format/internal/floats.d std/format/internal/read.d std/format/internal/write.d std/math/algebraic.d std/math/constants.d std/math/exponential.d std/math/hardware.d std/math/operations.d std/math/package.d std/math/remainder.d std/math/rounding.d std/math/traits.d std/math/trigonometry.d std/net/curl.d std/net/isemail.d std/uni/package.d std/experimental/checkedint.d std/experimental/typecons.d std/range/interfaces.d std/range/package.d std/range/primitives.d std/regex/package.d std/regex/internal/generator.d std/regex/internal/ir.d std/regex/internal/parser.d std/regex/internal/backtracking.d std/regex/internal/tests.d std/regex/internal/tests2.d std/regex/internal/thompson.d std/regex/internal/kickstart.d std/windows/charset.d std/windows/registry.d std/windows/syserror.d etc/c/curl.d etc/c/odbc/sql.d etc/c/odbc/sqlext.d etc/c/odbc/sqltypes.d etc/c/odbc/sqlucode.d etc/c/sqlite3.d etc/c/zlib.d std/algorithm/internal.d std/digest/digest.d std/internal/cstring.d std/internal/digest/sha_SSSE3.d std/internal/math/biguintcore.d std/internal/math/biguintnoasm.d std/internal/math/biguintx86.d std/internal/math/errorfunction.d std/internal/math/gammafunction.d std/internal/scopebuffer.d std/internal/test/dummyrange.d std/internal/test/range.d std/internal/unicode_comp.d std/internal/unicode_decomp.d std/internal/unicode_grapheme.d std/internal/unicode_norm.d std/internal/unicode_tables.d std/internal/windows/advapi32.d std/typetuple.d generated/linux/debug/64/etc/c/zlib/adler32.o generated/linux/debug/64/etc/c/zlib/compress.o generated/linux/debug/64/etc/c/zlib/crc32.o generated/linux/debug/64/etc/c/zlib/deflate.o generated/linux/debug/64/etc/c/zlib/gzclose.o generated/linux/debug/64/etc/c/zlib/gzlib.o generated/linux/debug/64/etc/c/zlib/gzread.o generated/linux/debug/64/etc/c/zlib/gzwrite.o generated/linux/debug/64/etc/c/zlib/infback.o generated/linux/debug/64/etc/c/zlib/inffast.o generated/linux/debug/64/etc/c/zlib/inflate.o generated/linux/debug/64/etc/c/zlib/inftrees.o generated/linux/debug/64/etc/c/zlib/trees.o generated/linux/debug/64/etc/c/zlib/uncompr.o generated/linux/debug/64/etc/c/zlib/zutil.o
posix.mak:338: recipe for target 'generated/linux/debug/64/libphobos2.a' failed
Nice and useless.
If anyone could find just what code this PR is failing on, I'd appreciate the help.
Not sure if you really just didn't find the corresponding file: https://github.com/dlang/dmd/blob/540d57657f391e84b60ba01af7205622ab0d852e/compiler/test/unit/interfaces/check_implementations_20861.d#L78-L101 [These 'unit' tests use DMD as a library, so it tests an expected error for https://github.com/dlang/dmd/blob/540d57657f391e84b60ba01af7205622ab0d852e/compiler/test/unit/interfaces/check_implementations_20861.d#L83-L93.]
circleci fails with: […] Nice and useless.
Only if you ignore the line below that (remember Mathias suggesting to grep for *** for Makefile errors):
make: *** [generated/linux/debug/64/libphobos2.a] Killed
After a quick look at CircleCI log and script, it compiles a first compiler, and then uses that one to recompile itself (with coverage). This almost certainly means that the aforementioned regressions for the frontend itself (scope-allocated Visitor instances; edit: only surfacing when using itself as host compiler) do indeed lead to observable higher memory requirements when compiling Phobos and lead to an out-of-memory error for the 4 GB CircleCI machines (and 2 CPU cores).
I changed it so it is allowed without comment in unsafe code. In @safe code, a deprecation message is emitted.
@thewilsonator I still don't understand why you want this in stable.
Adding Spec PR tag to clarify scope attribute applied to constructors.