www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10527] New: Eliding more postblit constructor calls

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10527

           Summary: Eliding more postblit constructor calls
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: tommitissari hotmail.com



Definitions:
1) 'Str' is a struct type which has a postblit constructor
2) 'var' is a variable whose unqualified type is Str
3) 'cpy' is a copy of the variable var

Proposed language change:
Whenever a copy is made from var to cpy (either by making a new variable or by
passing var to a function by value) and the compiler can determine (either
through analysing code or by deduction from a function signature) that during
the lifetime of cpy, no mutation is done to var nor to any data reachable from
it, the language should guarantee these two things:
1) cpy's postblit constructor is omitted when cpy is constructed
2) cpy's destructor is omitted when cpy goes out of scope

Examples:
Here are some examples, where the compiler can deduce that it's safe to omit
the postblit and destructor of cpy by merely looking at the function signature:
1)
int foo(T, U)(const Str cpy, const T t, immutable U u) pure { }

2)
void foo(T, U)(immutable Str cpy, T t, U u) { }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 03 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10527





 [..] the language should guarantee these two things:
 1) cpy's postblit constructor is omitted when cpy is constructed
 2) cpy's destructor is omitted when cpy goes out of scope
Let's change this proposal so that the language would guarantee to do those optimisations only when it can deduce that it can be done from looking at function signatures. And the compiler can choose whether or not it wants to try to do more postblit/destructor elisions through static analysis. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 03 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10527





 2) 'var' is a variable whose unqualified type is Str
By this I mean: is(std.traits.Unqual!(typeof(var)) == Str) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 03 2013