Skip to content

Conversation

@expipiplus1
Copy link
Collaborator

Closes #8964

@expipiplus1 expipiplus1 added the pr: non-breaking PRs without breaking changes label Nov 13, 2025
@expipiplus1 expipiplus1 changed the title Return slang_unknown_size from api where appropriate Remove uses of raw integer types in type layout passes Nov 13, 2025
Copy link
Collaborator

@jkwak-work jkwak-work left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@expipiplus1
Copy link
Collaborator Author

/format

@slangbot
Copy link
Contributor

🌈 Formatted, please merge the changes from this PR

expipiplus1 and others added 17 commits November 18, 2025 16:52
- Fixed multiplication and comparison operators in various files
- Updated getFiniteValue() calls to handle LayoutOffset return type
- Added proper invalid state handling in IR generation
- Fixed reflection API to handle invalid layout sizes safely
- Fixed comparison operators in slang-parameter-binding.cpp and slang-type-layout.cpp
- Updated all uses of size == 0 and count == 0 to use proper compare functions
- Fixed _roundToAlignment to handle LayoutOffset properly and check for invalid states
- Removed ad-hoc special values in favor of proper invalid state handling
- Fixed all LayoutOffset conversion issues in slang-parameter-binding.cpp
- Applied safe pattern of checking isValid() before using getValidValue()
- Updated all remaining comparison operators to use compare() function
- Handled invalid states properly in string formatting and allocation
This commit completes the implementation of invalid state handling for LayoutSize,
matching the pattern used in LayoutOffset. Key changes include:

- Fixed all remaining compilation errors from the API changes
- Updated getFiniteValue() method to be inline to avoid linking issues
- Applied safe error handling patterns throughout the codebase
- Ensured invalid states propagate correctly through all operations
- Replaced all ad-hoc comparisons with proper compare() function calls
- Fixed arithmetic operations between LayoutSize and LayoutOffset types

The implementation now provides type-safe layout size calculations with
proper error propagation and eliminates the use of magic values.
Fixed GetElementCount() function to return LayoutSize::invalid() instead of
magic value 0 in cases where the element count cannot be determined:
- Generic parameter bounds
- Polynomial integer values
- Function call integer values

This ensures proper error propagation through the layout system and eliminates
the use of magic values in favor of typed invalid states.
@expipiplus1
Copy link
Collaborator Author

/format

@slangbot
Copy link
Contributor

🌈 Formatted, please merge the changes from this PR

@expipiplus1 expipiplus1 marked this pull request as ready for review November 18, 2025 09:57
@expipiplus1 expipiplus1 requested a review from a team as a code owner November 18, 2025 09:57
@expipiplus1
Copy link
Collaborator Author

/format

@slangbot
Copy link
Contributor

🌈 Formatted, please merge the changes from this PR

@expipiplus1 expipiplus1 changed the title Remove uses of raw integer types in type layout passes Return SLANG_UNKNOWN_SIZE or SLANG_UNBOUNDED_SIZE for all type layout api functions where appropriate Nov 23, 2025
@expipiplus1 expipiplus1 added pr: breaking change PRs with breaking changes and removed pr: non-breaking PRs without breaking changes labels Nov 23, 2025
@expipiplus1
Copy link
Collaborator Author

/format

@slangbot
Copy link
Contributor

🌈 Formatted, please merge the changes from this PR

Copy link
Collaborator

@jkwak-work jkwak-work left a comment

Choose a reason for hiding this comment

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

Looks good to me.

But please fill in the details of the PR description.
Because this will be a breaking change, the description will show up at the top of the release note.
People will need to also know how to fix their code if it actually breaks.

// only useful if `getKind() == Kind::Array`
/** Get the number of elements in an array or vector type.
*
* Only useful if `getKind() == Kind::Array` or `Kind::Vector`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we have an assertion check for this case?

value |= value >> 4;
value |= value >> 8;
value |= value >> 16;
if (sizeof(size_t) > 4)
Copy link
Collaborator

Choose a reason for hiding this comment

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

some compilers may warn to use if constexpr

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

Labels

pr: breaking change PRs with breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Link time constant robustness: Remove uses of raw integer types in type layout passes

4 participants