[Issue 21065] New: the new operator should lower to a template function call in object.d
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jul 23 00:45:30 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=21065
Issue ID: 21065
Summary: the new operator should lower to a template function
call in object.d
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: andrei at erdani.com
Currently the new expression lowers to a nontemplate call in druntime:
extern (C) Object _d_newclass(const ClassInfo ci);
followed by a call to the appropriate __ctor() if any. This approach has the
usual rigidity disadvantages of a runtime solution: loss of compile-time type
information in the implementation, awkward to instrument, bulkier code due to
indirections.
Calls to "new C(a1, a2, a3) should lower to ".object.__makeClassObject!(C)(a1,
a2, a3)". That way a function such as:
T __makeClassObject(T, A...)(auto ref A);
in object.d would carry the allocation and initialization.
Such a function would be trivial to instrument, see
https://github.com/dlang/dmd/pull/11381. In contrast, the current new
instrumentation code is unbearably slow because it uses hash tables.
--
More information about the Digitalmars-d-bugs
mailing list