[Issue 18877] New: std.allocator: RCIAllocator's .alignment() method is not readable at compile-time

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat May 19 17:27:04 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=18877

          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 at puremagic.com
          Reporter: dlang-bugzilla at 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;

or:

    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).

--


More information about the Digitalmars-d-bugs mailing list