Skip to content

Conversation

@nate-chandler
Copy link
Contributor

When inlining from the SwiftCompilerSources, sometimes a "best effort" list of instructions (in function order) more or less representing which instructions were cloned into the caller is constructed. A loop from the first instruction to the last instruction in that range is performed, and the instructions found are broadcasted to have changed. If the first instruction has been deleted, walking over the instructions in function order doesn't work, so instead of using the apply which inlining deletes, walk from the instruction "which is where the apply used to be" after inlining. And if the last instruction has been deleted, waklnig over the instructions never stops because no instruction seen when walking the instructions in function order is ever equal to the deleted instruction. Rather than just saying that every single instruction after the apply is changed, just don't bother to broadcast if the end of the range is deleted. This matches the preexisting best effort approach which also doesn't broadcast if for example the inlined callee is a begin_apply immediately followed by any end_apply.

Fixes a compiler crash.

rdar://161433604

During inlining, the apply is deleted.  So when publishing this best
effort list of which instructions were "changed" during inlining, start
from the instruction before the deleted apply.
During inlining, some instructions in the caller may be deleted.  So
when publishing this best effort list of instructions which were
"changed" during inlining, don't start from a deleted instruction.
Instead just don't publish, as already happens in other cases.

Without actually addressing
```
// TODO: get a list of cloned instructions from the `inlineFunction`
```
this is somewhat better than checking for having reached the end of the
function during the walk because that will result in falsely
broadcasting that some unchanged instructions have changed whereas this
change only results in not broadcasting which is already being done in
some cases (e.g. when a `begin_apply` is immediately followed by an
`end_apply`).
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler marked this pull request as ready for review October 1, 2025 21:08
@nate-chandler nate-chandler merged commit 5945606 into swiftlang:main Oct 1, 2025
5 checks passed
@nate-chandler nate-chandler deleted the rdar161433604 branch October 1, 2025 21:08
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.

1 participant