Skip to content

Conversation

kavon
Copy link
Member

@kavon kavon commented Feb 3, 2022

The problem is in OptimizeHopToExecutor::collectActors, which is
causing removeRedundantHopToExecutors to drop the hop_to_executor. The issue
is triggered by the order in which the Actors map is populated, and the reuse
of a SILValue representing an executor. Suppose we have a function like this:

bb0:
  %7 = builtin "getCurrentExecutor"() : $Optional<Builtin.Executor>
  // ...
  cond_br %12, bb2, bb1

bb1:
  // ...
  hop_to_executor %7 : $Optional<Builtin.Executor>

bb2:
  // ...
  hop_to_executor %7 : $Optional<Builtin.Executor>
  // ...
  hop_to_executor %28 : $MainActor

Since collectActors goes through each function's instructions top-down,
and assigns to each unique SILValue an ID equal to the size of the Actors map
prior to inserting the SILValue in the map, and we end up with the wrong actor IDs.

This commit changes the ID numbering scheme to correct the issue.

Resolves rdar://88285600 / SR-15789

@kavon kavon requested a review from eeckstein February 3, 2022 03:13
@kavon
Copy link
Member Author

kavon commented Feb 3, 2022

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Feb 3, 2022

Build failed
Swift Test Linux Platform
Git Sha - 6ace8f2f1922c4b7d77dfdd8bd6e52092eaf9673

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

The problem is in `OptimizeHopToExecutor::collectActors`, which is
causing `removeRedundantHopToExecutors` to drop the `hop_to_executor`. The issue
is triggered by the order in which the Actors map is populated, and the reuse
of a SILValue representing an executor. Suppose we have a function like this:

```
bb0:
  %7 = builtin "getCurrentExecutor"() : $Optional<Builtin.Executor>
  // ...
  cond_br %12, bb2, bb1

bb1:
  // ...
  hop_to_executor %7 : $Optional<Builtin.Executor>

bb2:
  // ...
  hop_to_executor %7 : $Optional<Builtin.Executor>
  // ...
  hop_to_executor %28 : $MainActor
```

Since `collectActors` goes through each function's instructions top-down,
and assigns to each unique SILValue an ID equal to the size of the Actors map
prior to inserting the SILValue in the map, and we end up with the wrong actor IDs.

This commit changes the ID numbering scheme to correct the issue.
@kavon
Copy link
Member Author

kavon commented Feb 3, 2022

@swift-ci please smoke test and merge

@kavon
Copy link
Member Author

kavon commented Feb 3, 2022

random failure on Linux for:

/home/build-user/swiftpm/Tests/CommandsTests/PackageToolTests.swift:2377: error: PackageToolTests.testPluginCompilationBeforeBuilding : XCTAssertTrue failed - unexpected failure matching 'Compiling plugin MyBuildToolPlugin...

@kavon
Copy link
Member Author

kavon commented Feb 4, 2022

@swift-ci please smoke test and merge

@kavon kavon merged commit 46a637c into swiftlang:main Feb 4, 2022
@kavon kavon deleted the fix-sr15789 branch February 4, 2022 18:18
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.

4 participants