Skip to content

Dynamically select alignment of a dyn Trait local value #71695

Closed
@pnkfelix

Description

@pnkfelix
Member

Spawned off of #71416

Specifically this comment: #71416 (comment)

quoted here:

Unlike the other unsound features, this is one where we don't even have a plan for how to soundly implement it. Not sure how much I like keeping that around.

Can't we do something dynamic where we allocate size + (align - 1) and align it ourselves?
Also, this has been discussed before, hasn't it?

Activity

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
requires-nightlyThis issue requires a nightly compiler in some way.
on Apr 29, 2020
pnkfelix

pnkfelix commented on Apr 29, 2020

@pnkfelix
MemberAuthor

@rustbot prioritize

added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Apr 29, 2020
RalfJung

RalfJung commented on Apr 29, 2020

@RalfJung
Member

@pnkfelix (in #71694)

which actually I guess would have to be done via alloca if we cannot put an upper-bound on align

size is also statically unknown here, so yes this needs alloca, that is indeed the entire point. ;)

spastorino

spastorino commented on Apr 30, 2020

@spastorino
Member

Assigning P-medium as discussed as part of the Prioritization Working Group process and removing I-prioritize.

Assigning to myself as a followup of #68304.

added and removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Apr 30, 2020
self-assigned this
on May 5, 2020
ldr709

ldr709 commented on Dec 21, 2020

@ldr709
Contributor

Can't we do something dynamic where we allocate size + (align - 1) and align it ourselves?

Here's a small optimization: pick some default alignment, maybe 16, then allocate size + max(align - default_align, 0) bytes. If align >= default_align then align % default_align == 0 because they are both powers of two, so the offset required to align to align bytes is i * default_align for i < align / default_align, which is at most (align / default_align - 1) * default_align = align - default_align. If align < default_align then the allocation will already be properly aligned, no offset required.

removed their assignment
on Aug 30, 2022
added a commit that references this issue on May 13, 2023

Auto merge of rust-lang#111374 - tmiasko:align-unsized-locals, r=cjgi…

2c41369
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    F-unsized_locals`#![feature(unsized_locals)]`P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @spastorino@pnkfelix@RalfJung@ldr709@rustbot

      Issue actions

        Dynamically select alignment of a `dyn Trait` local value · Issue #71695 · rust-lang/rust