Skip to content

Always build SwiftDriver and use it as default compiler driver #36377

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

Merged
merged 2 commits into from
Apr 27, 2021

Conversation

artemcm
Copy link
Contributor

@artemcm artemcm commented Mar 9, 2021

Always build (and use) the new SwiftDriver as the default compiler driver.
This will make sure that compiler developers are using the new driver when they build the compiler locally and use it.

  • Adds a new build-script product category: before_build_script_impl for products we wish to build before the impl products.
  • Adds a new EarlySwiftDriver product to that category, which gets built with the host toolchain.
    • Adds an escape hatch: --skip-early-swift-driver
  • Adjusts the swift CMake configuration with an additional step: swift_create_early_driver_symlinks which (if one was built) creates symlinks in the swift build bin directory to the EarlySwiftDriver swift-driver and swift-help executables.
  • Adds a new test subset : only_early_swiftdriver, which will get built into a corresponding CMake test target: check-swift-only_early_swiftdriver-* which runs a small subset of driver-related tests against the Early SwiftDriver.
    • This subset is run always when the compiler itself is tested (--test is specified)
      • With an escape disable-switch: --skip-test-early-swift-driver
    • All tests outside of only_early_swiftdriver are forced to run using the legacy C++ driver (to ensure it gets tested, still).
    • NOTE: SwiftDriver product (no 'Early') is still the main product used to build the driver for toolchain installation into and for executing the product's own tests. This change does not affect that.

@artemcm
Copy link
Contributor Author

artemcm commented Mar 10, 2021

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 5f373f14595a8d5fdbba9df10e37b9168397d794

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 5f373f14595a8d5fdbba9df10e37b9168397d794

@artemcm
Copy link
Contributor Author

artemcm commented Mar 11, 2021

@nkcsgexi curious what you think of this approach

@nkcsgexi
Copy link
Contributor

This is a great idea to enable compiler engineers to always test swift-driver as they do for the C++ driver. Thanks for working on this!

@artemcm artemcm force-pushed the NewDriverDefault branch 2 times, most recently from 7d7f6a0 to f9935f6 Compare March 12, 2021 18:51
@artemcm
Copy link
Contributor Author

artemcm commented Mar 12, 2021

Together with: swiftlang/swift-driver#537
@swift-ci please smoke test

@artemcm
Copy link
Contributor Author

artemcm commented Mar 12, 2021

Together with: swiftlang/swift-driver#537
@swift-ci please smoke test Linux platform

@artemcm
Copy link
Contributor Author

artemcm commented Mar 16, 2021

Together with: swiftlang/swift-driver#537
@swift-ci please smoke test

@artemcm artemcm force-pushed the NewDriverDefault branch 2 times, most recently from a10b822 to 4277506 Compare March 16, 2021 21:51
@artemcm
Copy link
Contributor Author

artemcm commented Mar 16, 2021

Together with: swiftlang/swift-driver#537
@swift-ci please smoke test macOS Platform

@artemcm
Copy link
Contributor Author

artemcm commented Mar 17, 2021

Together with: swiftlang/swift-driver#537
@swift-ci please smoke test macOS Platform

4 similar comments
@artemcm
Copy link
Contributor Author

artemcm commented Mar 19, 2021

Together with: swiftlang/swift-driver#537
@swift-ci please smoke test macOS Platform

@artemcm
Copy link
Contributor Author

artemcm commented Mar 19, 2021

Together with: swiftlang/swift-driver#537
@swift-ci please smoke test macOS Platform

@artemcm
Copy link
Contributor Author

artemcm commented Mar 19, 2021

Together with: swiftlang/swift-driver#537
@swift-ci please smoke test macOS Platform

@artemcm
Copy link
Contributor Author

artemcm commented Mar 25, 2021

Together with: swiftlang/swift-driver#537
@swift-ci please smoke test macOS Platform

@artemcm artemcm force-pushed the NewDriverDefault branch 6 times, most recently from 9beccee to 98ad24f Compare March 29, 2021 21:49
@artemcm
Copy link
Contributor Author

artemcm commented Mar 29, 2021

Together with: swiftlang/swift-driver#537
@swift-ci please smoke test macOS Platform

@atrick
Copy link
Contributor

atrick commented Apr 26, 2021

I'm not sure if my questions even make sense, so you don't need to repeat them verbatim in a doc. I'm confused about the design of the command line interfaces for our driver-like tools and not sure where to look.

@artemcm
Copy link
Contributor Author

artemcm commented Apr 26, 2021

Thanks for adding all the build-script info to the docs! Looks good to me.

I'm mostly curious about how to understand/debug differences between the old/new driver and other driver-like tools.

Will 'swiftc ... -###' always print the same set of commands for the old/new driver? Do they call 'swift-frontend' the same way?

The new swift-driver (Still invoked as swiftc) is meant to b a direct drop-in replacement. As such it has the exact same command-line interface. The expectation is that its behaviour closely matches the legacy driver; however, during, and after the transition to the new driver being the default its behaviour may start to diverge from the legacy driver as par for the course of its evolution and gaining new features, etc. Today, broadly-speaking, swift-frontend invocations generated by the two drivers are expected to be very similar.

What's the difference between invoking 'swiftc' vs. 'swift-driver' at the top level?

The mechanism by which we are deploying the new driver today is as follows:

  • The user invokes swiftc, which is the same executable as before, which forwards the invocation to the swift-driver executable if one is found alongside it. There are two escape hatches that will make swiftc avoid forwarding to the new driver:
  • -disallow-use-new-driver command line flag
  • SWIFT_USE_OLD_DRIVER environment variable
    These are meant to allow for a fallback to the legacy driver during the transition.
    If the user is to directly invoke the swift-driver executable, the behaviour should be the same as invoking swiftc executable, but without the option for a legacy driver fallback.

What's the difference between invoking 'swift -frontend' vs. 'swift-frontend' (I sure hope its nothing)?

AFAIK, there is no difference in doing this with either driver.

If there's a 'swift -frontend' to invoke 'swift-frontend' why isn't there a 'swift -c' to invoke 'swift-driver'?

swift -frontend bypasses any and all driver logic and invokes the compiler directly. With the new driver, once we go through this transition, swift and swiftc executables themselves will be the new driver executables (symlinks to swift-driver). So it seems that swift -c is a bit redundant. Unless I misunderstood this part?

These don't need to be answered in this PR, but I didn't happen to see an explanation in the docs and these are the important questions to me.

@atrick, thank you for these questions, I do think they highlight some pretty obvious gaps in documentation in this transition which must be documented, either in the docs here, or in the swift-driver repo, or both.

I like @gottesmm 's idea of having an F.A.Q. in the docs here, with the swift-driver's own documentation (in its corresponding repository) providing more in-depth docs.

@artemcm
Copy link
Contributor Author

artemcm commented Apr 26, 2021

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 750923a082acb0de11822c5f269436acdae3a718

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 750923a082acb0de11822c5f269436acdae3a718

artemcm added 2 commits April 26, 2021 12:17
…iver.

This will make sure that compiler developers are using the new driver when they build the compiler locally and use it.

- Adds a new build-script product category: before_build_script_impl for products we wish to build before the impl products.
- Adds a new EarlySwiftDriver product to that category, which gets built with the host toolchain.
- Adds an escape hatch: --skip-early-swift-driver
- Adjusts the swift CMake configuration with an additional step: swift_create_early_driver_symlinks which (if one was built) creates symlinks in the swift build bin directory to the EarlySwiftDriver swift-driver and swift-help executables.
- Adds a new test subset : only_early_swiftdriver, which will get built into a corresponding CMake test target: check-swift-only_early_swiftdriver-* which runs a small subset of driver-related tests against the Early SwiftDriver.
  - This subset is run always when the compiler itself is tested (--test is specified)
  - With an escape disable-switch: --skip-test-early-swift-driver
  - All tests outside of only_early_swiftdriver are forced to run using the legacy C++ driver (to ensure it gets tested, still).

NOTE: SwiftDriver product (no 'Early') is still the main product used to build the driver for toolchain installation into and for executing the product's own tests. This change does not affect that.
@artemcm
Copy link
Contributor Author

artemcm commented Apr 26, 2021

@swift-ci please test

@atrick
Copy link
Contributor

atrick commented Apr 26, 2021

Thanks Artem!

I think you can just cross reference Driver.md from this "debugging" document. Explaining the command line interface probably goes better in the driver docs.

swift -frontend bypasses any and all driver logic and invokes the compiler directly. With the new driver, once we go through this transition, swift and swiftc executables themselves will be the new driver executables (symlinks to swift-driver). So it seems that swift -c is a bit redundant. Unless I misunderstood this part?

swift -c is (I think) redundant with swiftc. My point is that swift -frontend is also (I think) redundant with swift-frontend. Is there a reason for the redundancy in one case and not the other. I don't have an opinion, I'm just trying to understand the CLI.

Also, swift has a different CLI from swiftc. So which one is the driver interface?

@artemcm
Copy link
Contributor Author

artemcm commented Apr 26, 2021

swift -c is (I think) redundant with swiftc. My point is that swift -frontend is also (I think) redundant with swift-frontend. Is there a reason for the redundancy in one case and not the other. I don't have an opinion, I'm just trying to understand the CLI.

That's a good point, it is redundant, and is just an artifact of the times before swift-frontend. The only thing keeping it around is that we may still have compiler clients who may be relying on it, e.g. things like SwiftPM may still be generating swift -frontend invocations. We should be able to deprecate it if we make sure the clients know to invoke swift-frontend directly.

Also, swift has a different CLI from swiftc. So which one is the driver interface?

Both are the driver, just two different "modes" of the driver. For swift, the driver's job is simply to create the swift-frontend -interpret job and setup its arguments correctly. For swiftc, he driver's job is to plan the build, as normal. The driver, internally, distinguishes them by knowing whether or not it was invoked as swift or swiftc. (or --driver-mode=[swift|swiftc] if invoking the swift-driver directly).

@artemcm
Copy link
Contributor Author

artemcm commented Apr 26, 2021

@swift-ci please test Windows platform

@artemcm artemcm merged commit 23452d5 into swiftlang:main Apr 27, 2021
@artemcm artemcm deleted the NewDriverDefault branch May 7, 2021 16:42
artemcm added a commit to artemcm/swift that referenced this pull request Jun 1, 2021
In the original implementation (swiftlang#36377), using `--infer` accidentally disables the `earlyswiftdriver` product (`before_impl_product_classes` set to always empty). This change fixes that and makes sure early SwiftDriver is always built, regardless of whether or not `--infer` is used.

This change also ensures that `install_all` setting triggered by `--infer` does not affect products which specify `is_ignore_install_all_product` to return True. This is useful for products which should not be installed into the toolchain (corresponding build products that use the just-built toolchain are the products that get installed, e.g. `swiftdriver` to `earlyswiftdriver`).
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.

5 participants