Skip to content

[SwiftCompilerSources] Moved Test into Optimizer. #69009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented Oct 6, 2023

Based on #69007 .

In order to change the type of the context argument to FunctionPassContext. In the fullness of time could be sunk into the SIL module.

@nate-chandler nate-chandler requested a review from atrick October 6, 2023 02:00
@nate-chandler nate-chandler force-pushed the swiftcompilersources/test-in-optimizer branch from 04fc29f to bafef1c Compare October 6, 2023 02:01
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

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

If we want the SIL module to be useful, rather than just adding unnecessary layering complexity, then we'll need to move Context along with a slew of other SIL utilities. But that's a separate task. For now, it doesn't really make sense to put much of anything in the SIL module.

FunctionPassContext is the only context that makes sense for FunctionTest and doesn't seem at all specific to running a pass. So it's right to assume that all SIL tests should get one. We could have a separate FunctionTestContext that duplicates everything in FunctionPassContext, but that just seems pointless.

@nate-chandler nate-chandler marked this pull request as ready for review October 6, 2023 13:59
And changed the type of the context argument to FunctionPassContext.
@nate-chandler nate-chandler force-pushed the swiftcompilersources/test-in-optimizer branch from bafef1c to ae1f950 Compare October 8, 2023 04:23
@nate-chandler
Copy link
Contributor Author

@swift-ci please smoke test and merge

@swift-ci swift-ci merged commit 622ff07 into swiftlang:main Oct 8, 2023
@nate-chandler nate-chandler deleted the swiftcompilersources/test-in-optimizer branch October 8, 2023 16:08
@eeckstein
Copy link
Contributor

eeckstein commented Oct 9, 2023

@atrick, @nate-chandler

If we want the SIL module to be useful, rather than just adding unnecessary layering complexity, then we'll need to move Context along with a slew of other SIL utilities.

SIL is not a layer but the data definition for SIL. It's currently bridging to C++ but at some day (far in the future) SIL will be purely implemented in swift.
Nevertheless, I agree that it makes sense to move some basic Context types to SIL.

FunctionPassContext is the only context that makes sense for FunctionTest [...]

See my comment in the other PR.

With test context there is a more fundamental layering problem. The test context needs to provide things like the dominator tree, but analysis are implemented in the optimizer. This makes it impossible to implement tests for SIL utilities which depend on analysis like the dominator tree.

What I think we should do in the longer term is to split out tests into a separate module, which can depend on the optimizer module. Or even split the optimizer into multiple modules, where one of this contains all the analysis (Analysis).

@nate-chandler
Copy link
Contributor Author

to split out tests into a separate module

An important aspect of these tests is that they're inline, next to the code being tested, able even to test code that isn't exported from a module.

The test context needs to provide things like the dominator tree, but analysis are implemented in the optimizer. This makes it impossible to implement tests for SIL utilities which depend on analysis like the dominator tree.

As long as the driver is able to produce a dominator tree and provide it to the test, it's fine for the dominator tree to depend on things that aren't visible in the module.

@eeckstein
Copy link
Contributor

eeckstein commented Oct 9, 2023

As discussed offline, we could move all the Analysis types from the Optimizer to the SIL module.

@atrick
Copy link
Contributor

atrick commented Oct 10, 2023

Note that it would be fine to have a more basic TestContext that does not depend on the Optimizer. But to get things working, we need a context that has all the capabilities of a function pass. I initially called that FunctionPassTestContext, but Nate didn't want separate FunctionTest and FunctionPassTest. I agree that we don't need both.

@atrick
Copy link
Contributor

atrick commented Oct 10, 2023

As discussed offline, we could move all the Analysis types from the Optimizer to the SIL module.

For anyone trying to understand the compiler architecture, there is a helpful distinction between logic that (1) defines valid SIL, (2) makes it possible to work with SIL, and (3) pure optimization. I would expect the first two to be part of the SIL module. Things like intrusive data types obviously need to be in SIL because they are tightly coupled. Most utilities and basic analyses need to be in SIL. AliasAnalysis is a good example of something that should have an interface in SIL but should ideally be mostly implemented in the optimizer. (Ideally valid SIL only depends on trivial disambiguation, not arbitrarily complex analysis). Today, we rely on full AliasAnalysis for valid SIL. That's an important (controversial) architectural decision which would be made clear by moving AliasAnalysis to SIL.

I don't know if there's any other reason to split things into modules. I think the "data model" is an implementation detail. We can encode information about a SIL type in a routine or cache the information in flags. They're both part of SIL.

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