Bug 21429 – Cannot sort large tuple arrays at compile time

Status
NEW
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2020-11-26T13:35:30Z
Last change time
2024-12-01T16:38:04Z
Keywords
CTFE
Assigned to
No Owner
Creator
Max Samukha
See also
https://issues.dlang.org/show_bug.cgi?id=21888
Moved to GitHub: phobos#10448 →

Comments

Comment #0 by maxsamukha — 2020-11-26T13:35:30Z
import std.algorithm; import std.typecons; auto foo() { enum n = 1000; auto x = new Tuple!int[n]; x.sort; return x; } enum a = foo; void main() { } /dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/mutation.d(2825): Error: reinterpreting cast from Tuple!int* to ubyte* is not supported in CTFE Compiles for n == 100.
Comment #1 by bugzilla — 2021-05-03T14:03:20Z
Meanwhile n == 100 produces: /home/D/Repo/dmd/generated/linux/release/64/../../../../../druntime/import/core/lifetime.d(2105): Error: `memcpy` cannot be interpreted at compile time, because it has no available source code (using DMD64 D Compiler v2.096.1-242-g9fd50d0be) It still works for n <= 5.
Comment #2 by tim.dlang — 2021-11-04T18:23:06Z
It also fails for small arrays, but only if some elements have to be swapped: enum x = (){ import std.algorithm, std.typecons; auto x = [tuple!int(2), tuple!int(1)]; x.sort; return x; }(); The problem can also be reproduced by calling swap directly: enum x = (){ import std.algorithm, std.typecons; Tuple!int a, b; swap(a, b); return 0; }();
Comment #3 by nick — 2023-12-18T12:24:33Z
I've split out the swap error to issue #24285. With the swap fix, the comment #1 error still happens.
Comment #4 by robert.schadek — 2024-12-01T16:38:04Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10448 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB