Skip to content

Conversation

@aidan-hall
Copy link
Contributor

@aidan-hall aidan-hall commented Nov 12, 2025

rdar://164515160

We can avoid issues with loweredType failing by not calling it. We should also only get the SILType for results that we actually intend to explode.

Attempting to explode packs containing generic type parameters lead to compiler crashes. It is preferable to wait until generic types have been replaced with concrete types to explode packs, since we can only pass exploded pack elements directly if we know they are loadable.

@aidan-hall aidan-hall self-assigned this Nov 12, 2025
@aidan-hall aidan-hall marked this pull request as ready for review November 12, 2025 18:11
@aidan-hall
Copy link
Contributor Author

@swift-ci smoke test

Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

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

It would still be good to explode packs that contain indirect elements (such as type parameters not constrained to AnyObject), because passing multiple indirect parameters can still lead to better optimization opportunities than passing a pack.

@aidan-hall aidan-hall marked this pull request as draft November 13, 2025 11:19
@aidan-hall aidan-hall force-pushed the pack-opt-fix-weather-swb branch from 125c351 to f6d9ef7 Compare November 14, 2025 21:06
@aidan-hall
Copy link
Contributor Author

It would still be good to explode packs that contain indirect elements (such as type parameters not constrained to AnyObject), because passing multiple indirect parameters can still lead to better optimization opportunities than passing a pack.

This would be preferable. I haven't investigated whether the crashes I mentioned were caused by a bug in PackSpecialization yet, and I'm focusing on correct behaviour for now, so that can come in a follow-up PR.

@aidan-hall aidan-hall marked this pull request as ready for review November 14, 2025 21:14
@aidan-hall
Copy link
Contributor Author

@swift-ci smoke test

@aidan-hall
Copy link
Contributor Author

@swift-ci smoke test

@aidan-hall
Copy link
Contributor Author

@swift-ci test windows

@aidan-hall aidan-hall force-pushed the pack-opt-fix-weather-swb branch from f6d9ef7 to e55cdbf Compare November 18, 2025 16:42
@aidan-hall
Copy link
Contributor Author

@swift-ci smoke test

@aidan-hall aidan-hall marked this pull request as draft November 19, 2025 11:15
Refactor certain functions to make them simpler. and avoid calling
AST.Type.loweredType, which can fail. Instead, access the types of the
function's (SIL) arguments directly.

Correctly handle exploding packs that contain generic type parameters by using
the "interfaceTypeOfArchetype" computed attribute.

@Substituted types cause the shouldExplode predicate to be unreliable for AST
types, so restrict it to just SIL.Type. Add test cases for functions that have
@Substituted types.

Re-enable PackSpecialization in FunctionPass pipeline.

Add a check to avoid emitting a destructure_tuple of the original function's
return tuple when it is void/().
@aidan-hall aidan-hall force-pushed the pack-opt-fix-weather-swb branch from e55cdbf to aa7daed Compare November 19, 2025 15:58
@aidan-hall aidan-hall marked this pull request as ready for review November 19, 2025 16:21
@aidan-hall aidan-hall requested a review from eeckstein November 19, 2025 16:21
@aidan-hall
Copy link
Contributor Author

@swift-ci test

let mappedParameterInfos = argument.type.packElements.map { element in
ParameterInfo(
type: element.canonicalType,
type: element.isArchetype ? element.rawType.interfaceTypeOfArchetype.canonical : element.canonicalType,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eeckstein Does this change to support generic types in parameter packs look reasonable? I've made the same change for results.

@aidan-hall
Copy link
Contributor Author

@swift-ci smoke test linux

@aidan-hall
Copy link
Contributor Author

@swift-ci smoke test macos

@aidan-hall
Copy link
Contributor Author

@swift-ci please benchmark

let mappedParameterInfos = argument.type.packElements.map { element in
ParameterInfo(
type: element.canonicalType,
type: element.isArchetype ? element.rawType.interfaceTypeOfArchetype.canonical : element.canonicalType,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use mapTypeOutOfContext instead (#84648)

@aidan-hall aidan-hall marked this pull request as draft November 19, 2025 17:10
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.

3 participants