Skip to content

[Custom Descriptors] Fix accidental placeholder use in GTO#7914

Merged
tlively merged 6 commits intomainfrom
gto-placeholder-bystander
Sep 23, 2025
Merged

[Custom Descriptors] Fix accidental placeholder use in GTO#7914
tlively merged 6 commits intomainfrom
gto-placeholder-bystander

Conversation

@tlively
Copy link
Copy Markdown
Member

@tlively tlively commented Sep 23, 2025

GTO inserts placeholder describee types by overriding getSortedTypes
and returning a list of types with extra structs added where the
placeholders will go. Previously we used the empty struct to reserve
space in the list for the placeholders, but when the empty struct was a
public type (and therefore did not appear after the placeholders in the
sorted list of rebuilt types), this had the unfortunate effect of
replacing the empty struct with one of the placeholders throughout the
module. This did not happen when the emptry struct was a private type
because then it would appear later in the list of sorted types and its
type-to-index mapping in GlobalTypeRewriter::rebuildTypes would be
updated to map to the non-placeholder index. When the type is public,
this later entry does not exist and the type ends up being mapped to the
placeholder index.

To fix the problem, change how we save space for placeholder describees
in the list of sorted types to ensure the placeholder is represented by
a private type that will appear later in the list of types. This will
ensure that the final mapping of types to indices will always map types
to the index of their "real" appearance rather than the index of a
placeholder type, and will also ensure that public types are never
mapped to anything else. Specifically, we now save space for a described
type using the descriptor type that will eventually describe it.

While refactoring this, also simplify things by placing the placeholder
describee types directly before their descriptor types in the sorted
list. This saves us from having to map from descriptor types to the
index of their placeholders since we can determine the placeholder's
index from its descriptor's index.

GTO inserts placeholder describee types by overriding getSortedTypes
and returning a list of types with extra structs added where the
placeholders will go. Previously we used the empty struct to reserve
space in the list for the placeholders, but when the empty struct was a
public type (and therefore did not appear after the placeholders in the
sorted list of rebuilt types), this had the unfortunate effect of
replacing the empty struct with one of the placeholders throughout the
module. This did not happen when the emptry struct was a private type
because then it would appear later in the list of sorted types and its
type-to-index mapping in GlobalTypeRewriter::rebuildTypes would be
updated to map to the non-placeholder index. When the type is public,
this later entry does not exist and the type ends up being mapped to the
placeholder index.

To fix the problem, change how we save space for placeholder describees
in the list of sorted types to ensure the placeholder is represented by
a private type that will appear later in the list of types. This will
ensure that the final mapping of types to indices will always map types
to the index of their "real" appearance rather than the index of a
placeholder type, and will also ensure that public types are never
mapped to anything else. Specifically, we now save space for a described
type using the descriptor type that will eventually describe it.

While refactoring this, also simplify things by placing the placeholder
describee types directly before their descriptor types in the sorted
list. This saves us from having to map from descriptor types to the
index of their placeholders since we can determine the placeholder's
index from its descriptor's index.
@tlively tlively requested a review from kripken September 23, 2025 04:35
@tlively tlively changed the title [Custom Descriptors] Fix accidental placholder use in GTO [Custom Descriptors] Fix accidental placeholder use in GTO Sep 23, 2025
GlobalTypeOptimization& parent;
InsertOrderedMap<HeapType, Index> placeholderIndices;
InsertOrderedMap<HeapType, Index>::iterator placeholderIt;
bool sawPlaceholder = false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Worth a comment for this cycling value.

@tlively tlively merged commit e6f3dec into main Sep 23, 2025
16 checks passed
@tlively tlively deleted the gto-placeholder-bystander branch September 23, 2025 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants