Bug 19573 – usage of delegate literals at compile-time allocates closure at run-time

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-01-10T14:29:27Z
Last change time
2023-04-25T13:45:18Z
Assigned to
No Owner
Creator
dayllenger

Comments

Comment #0 by regnellday — 2019-01-10T14:29:27Z
Minimal example: --- void main() { int i; static assert(isCallable!(() => i)); // allocates static assert(is(typeof(() => i))); // ok } template isCallable(T...) { enum bool isCallable = true; } --- dmd -vcg-ast output: --- import object; void main() { int i = 0; return 0; } enum bool isCallable(T...) = true; isCallable!(delegate () => i) { enum bool isCallable = true; } ---
Comment #1 by razvan.nitu1305 — 2023-04-25T13:45:18Z
No closure is allocated. What you are seeing is just an instantiation of isCallable with a delegate type (which is the correct type, given that the context of main is accessed). However if you look at the disassembly code: 000000000004271c <_Dmain>: 4271c: 55 push %rbp 4271d: 48 8b ec mov %rsp,%rbp 42720: 48 83 ec 10 sub $0x10,%rsp 42724: 31 c0 xor %eax,%eax 42726: 89 45 f8 mov %eax,-0x8(%rbp) 42729: c9 leaveq 4272a: c3 retq No closure allocated. Closing as invalid. Please reopen if any other information that makes a compelling case for the bug report is presented.