Bug 14211 – Compiler should devirtualize calls to members of final class

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-02-20T21:31:00Z
Last change time
2017-07-19T17:38:49Z
Keywords
performance, pull
Assigned to
nobody
Creator
r.sagitario

Comments

Comment #0 by r.sagitario — 2015-02-20T21:31:22Z
Compile with -m64 -inline -release -O: class Mutex { void lock() {} } final class GCMutex : Mutex { //final override void lock() { super.lock(); } } void test() { GCMutex gcLock = new GCMutex; gcLock.lock(); } The disassembly for test() is: _D4test4testFZv: 0000000000000000: 55 push rbp 0000000000000001: 48 8B EC mov rbp,rsp 0000000000000004: 48 8D 0D 00 00 00 lea rcx,[_D4test7GCMutex7__ClassZ] 000000000000000B: 48 83 EC 20 sub rsp,20h 000000000000000F: E8 00 00 00 00 call _d_newclass 0000000000000014: 48 83 C4 20 add rsp,20h 0000000000000018: 48 89 C1 mov rcx,rax 000000000000001B: 48 83 EC 20 sub rsp,20h 000000000000001F: 48 8B 01 mov rax,qword ptr [rcx] 0000000000000022: 48 FF 50 28 call qword ptr [rax+28h] 0000000000000026: 48 83 C4 20 add rsp,20h 000000000000002A: 5D pop rbp 000000000000002B: C3 ret I.e. the call to lock is still made through the virtual function table although the class GCMutex is declared final. If the commented code in GCMutex is enabled, the call is deviertualized, but not inlined.
Comment #1 by k.hara.pg — 2015-02-21T07:27:41Z
Comment #2 by github-bugzilla — 2015-02-21T09:04:12Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/1f87794054502ce0b852fb0f1c6bd9a38dfad141 fix Issue 14211 - Compiler should devirtualize calls to members of final class Add `CallExp::directcall` to handle devirtualizing of virtual function call in front-end. It can also handle a direct call with `DotTypeExp` by the same logic. https://github.com/D-Programming-Language/dmd/commit/fdafca92dd937d70f295c8b5bb1a713f88bd04fc Merge pull request #4427 from 9rnsr/fix14211 Issue 14211 - Compiler should devirtualize calls to members of final class
Comment #3 by github-bugzilla — 2015-02-21T09:11:57Z
Comment #4 by github-bugzilla — 2015-06-17T21:01:05Z
Commits pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/1f87794054502ce0b852fb0f1c6bd9a38dfad141 fix Issue 14211 - Compiler should devirtualize calls to members of final class https://github.com/D-Programming-Language/dmd/commit/fdafca92dd937d70f295c8b5bb1a713f88bd04fc Merge pull request #4427 from 9rnsr/fix14211
Comment #5 by github-bugzilla — 2017-07-19T17:38:49Z
Commits pushed to dmd-cxx at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/1f87794054502ce0b852fb0f1c6bd9a38dfad141 fix Issue 14211 - Compiler should devirtualize calls to members of final class https://github.com/dlang/dmd/commit/fdafca92dd937d70f295c8b5bb1a713f88bd04fc Merge pull request #4427 from 9rnsr/fix14211