Skip to content

Fix ThinSList size and unify EMPTY_BASES definitions#127911

Merged
steveisok merged 9 commits into
mainfrom
copilot/fix-slist-size-on-msvc
May 11, 2026
Merged

Fix ThinSList size and unify EMPTY_BASES definitions#127911
steveisok merged 9 commits into
mainfrom
copilot/fix-slist-size-on-msvc

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 7, 2026

Found that SList was taking up two pointer sizes because MSVC does not do empty base class optimization by default. We already have EMPTY_BASES_DECL, but it is not defined in NativeAOT. Given that SList is used in both CoreCLR and NativeAOT I also refactored EMPTY_BASES_DECL to be defined in minipal so it can be accessed by both builds.

Changes

  • src/coreclr/pal/inc/pal.h — removed the unconditional #define EMPTY_BASES_DECL (always empty, wrong on MSVC). pal.h already #includes <minipal/utils.h> above that line, so the minipal definition takes effect automatically.
  • src/coreclr/inc/slist.h — switched to #include <minipal/utils.h> and EMPTY_BASES_DECL directly; moved SListLayoutValidationElem and related static_asserts under #ifdef _DEBUG so they don't affect release builds.

src/native/minipal/utils.h is now the single source of truth for EMPTY_BASES_DECL.

Copilot AI and others added 5 commits May 7, 2026 03:04
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/48302404-6028-4077-9e01-90f0d226f7ee

Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/48302404-6028-4077-9e01-90f0d226f7ee

Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/48302404-6028-4077-9e01-90f0d226f7ee

Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/3a0b1409-2a17-4878-9e92-ae06a0676dfb

Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/665e5e53-fc68-4f49-863b-33fbba8270b7

Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com>
Copilot AI self-assigned this May 7, 2026
Copilot AI review requested due to automatic review settings May 7, 2026 12:55
Copilot AI review requested due to automatic review settings May 7, 2026 12:55
@github-actions github-actions Bot added the area-PAL-coreclr only for closed issues label May 7, 2026
Copilot AI requested a review from max-charlamb May 7, 2026 13:08
@max-charlamb max-charlamb changed the title Remove redundant EMPTY_BASES_DECL definitions; keep only the minipal one Fix ThinSList size and unify EMPTY_BASES_DECL definitions May 7, 2026
@max-charlamb max-charlamb marked this pull request as ready for review May 7, 2026 14:49
Copilot AI review requested due to automatic review settings May 7, 2026 14:49
@max-charlamb max-charlamb requested a review from jkotas May 7, 2026 14:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR centralizes the EMPTY_BASES_DECL macro in minipal and applies it to SList so MSVC can perform empty base class optimization, reducing SList’s footprint (notably for thin/head-only lists) and aligning behavior across CoreCLR and NativeAOT.

Changes:

  • Define EMPTY_BASES_DECL in src/native/minipal/utils.h (MSVC: __declspec(empty_bases), otherwise empty).
  • Remove local/overriding EMPTY_BASES_DECL definitions from CoreCLR PAL headers so the minipal definition is used consistently.
  • Apply EMPTY_BASES_DECL to SList and add debug-only layout static_asserts to validate expected sizing.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/native/minipal/utils.h Adds the canonical EMPTY_BASES_DECL definition (MSVC vs non-MSVC).
src/coreclr/pal/inc/pal.h Removes the unconditional empty EMPTY_BASES_DECL override so minipal’s definition can take effect.
src/coreclr/inc/slist.h Includes minipal utils, applies EMPTY_BASES_DECL to SList, and adds layout validation assertions (currently _DEBUG-gated).
src/coreclr/inc/palclr.h Removes the local EMPTY_BASES_DECL definition in favor of the minipal definition (palclr already includes <minipal/utils.h>).

Comment thread src/coreclr/inc/slist.h Outdated
Comment thread src/native/minipal/utils.h Outdated
@max-charlamb max-charlamb enabled auto-merge (squash) May 7, 2026 17:13
@max-charlamb max-charlamb changed the title Fix ThinSList size and unify EMPTY_BASES_DECL definitions Fix ThinSList size and unify EMPTY_BASES definitions May 7, 2026
@max-charlamb
Copy link
Copy Markdown
Member

/ba-g test infra issue

1 similar comment
@max-charlamb

This comment was marked as duplicate.

@max-charlamb max-charlamb disabled auto-merge May 10, 2026 02:30
Copilot AI review requested due to automatic review settings May 10, 2026 02:31
@max-charlamb

This comment was marked as duplicate.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Comment thread docs/design/features/cross-dac.md
@max-charlamb
Copy link
Copy Markdown
Member

/ba-g test infra issue

@max-charlamb max-charlamb enabled auto-merge (squash) May 10, 2026 02:53
@steveisok steveisok disabled auto-merge May 11, 2026 14:53
@steveisok steveisok merged commit 195e37b into main May 11, 2026
170 of 181 checks passed
@steveisok steveisok deleted the copilot/fix-slist-size-on-msvc branch May 11, 2026 14:54
jakobbotsch pushed a commit to jakobbotsch/runtime that referenced this pull request May 12, 2026
Found that SList was taking up two pointer sizes because MSVC does not
do empty base class optimization by default. We already have
`EMPTY_BASES_DECL`, but it is not defined in NativeAOT. Given that SList
is used in both CoreCLR and NativeAOT I also refactored
`EMPTY_BASES_DECL` to be defined in minipal so it can be accessed by
both builds.

## Changes

- **`src/coreclr/pal/inc/pal.h`** — removed the unconditional `#define
EMPTY_BASES_DECL` (always empty, wrong on MSVC). `pal.h` already
`#include`s `<minipal/utils.h>` above that line, so the minipal
definition takes effect automatically.
- **`src/coreclr/inc/slist.h`** — switched to `#include
<minipal/utils.h>` and `EMPTY_BASES_DECL` directly; moved
`SListLayoutValidationElem` and related `static_assert`s under `#ifdef
_DEBUG` so they don't affect release builds.

`src/native/minipal/utils.h` is now the single source of truth for
`EMPTY_BASES_DECL`.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com>
Co-authored-by: Max Charlamb <maxcharlamb@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-PAL-coreclr only for closed issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants