Skip to content

Conversation

@eeckstein
Copy link
Contributor

  • Explanation: In case of ObjectiveC classes, the runtime type can differ from its declared type. Therefore a cast between (compile-time) unrelated classes may succeed at runtime. It turned out that this kind of runtime vs. formal type mismatch appears quite often in real world code. This change disables ObjectiveC class casts in the cast optimizer which makes the generated code in release builds behave the same way as in debug builds.
  • Risk: low: It's a simple change which cast optimizer more conservative when dealing with ObjectiveC classes.
  • Testing: Tested by lit tests
  • Issue: rdar://149810124
  • Reviewer: @mikeash , @tbkka
  • Main branch PR: CastOptimizer: don't assume dynamic casts from ObjectiveC classes to unrelated classes will fail #81203

…unrelated classes will fail

In case of ObjectiveC classes, the runtime type can differ from its declared type.
Therefore a cast between (compile-time) unrelated classes may succeed at runtime.

rdar://149810124
@eeckstein eeckstein requested a review from a team as a code owner May 2, 2025 05:33
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein requested review from mikeash and tbkka May 2, 2025 05:35
@eeckstein
Copy link
Contributor Author

@swift-ci test linux

1 similar comment
@eeckstein
Copy link
Contributor Author

@swift-ci test linux

@eeckstein eeckstein merged commit 8464b77 into swiftlang:release/6.2 May 5, 2025
5 checks passed
@eeckstein eeckstein deleted the fix-objc-class-casting-6.2 branch May 5, 2025 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants