www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18877] New: std.allocator: RCIAllocator's .alignment() method


          Issue ID: 18877
           Summary: std.allocator: RCIAllocator's .alignment() method is
                    not readable at compile-time
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: minor
          Priority: P5
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: dlang-bugzilla thecybershadow.net

Created attachment 1696
  --> https://issues.dlang.org/attachment.cgi?id=1696&action=edit
Draft patch for making alignment a method

Many building block allocators have a line such as:

    enum uint alignment = Allocator.alignment;


    alias alignment = ParentAllocator.alignment;

This doesn't work when the parent allocator is an opaque class.

Possible solutions:

- Forego use of alignment as a compile-time value, instead treating it as a
runtime value everywhere. Rely on compiler optimizations to punch through the
layers as needed.

  This is probably not feasible as many allocators rely on the underlying types
having a predefined, constant alignment. Using ParentAllocator.init.alignment
allows hacking around this, though.

  Attached is a draft patch towards this approach.

- Declare alignment as an enum/alias iff ParentAllocator's alignment can be
read at compile-time. For allocators that require knowing the alignment
beforehand, this can be made as an explicit check (to produce a human-readable
error message if they are used with e.g. RCIAllocator).

May 19 2018