Skip to content

[Macros] Track plugin dependencies #65322

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 1 commit into from
Apr 25, 2023

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Apr 20, 2023

  • Factor out ASTContext plugin loading to newly introduced 'PluginLoader'
  • Insert 'DependencyTracker' to 'PluginLoader'
  • Add dependencies right before loading the plugins

rdar://104938481

@rintaro
Copy link
Member Author

rintaro commented Apr 20, 2023

@swift-ci Please smoke test

@rintaro rintaro requested review from DougGregor and removed request for xedin, slavapestov and hborla April 20, 2023 18:12
@rintaro rintaro force-pushed the plugin-loader-swiftdeps branch from a3ad6cb to 2a4f6db Compare April 20, 2023 18:17
Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

This looks great! Am I understanding correctly that this means we will rebuild every source file in the module when one of the macro implementations that the module uses will change, vs. only rebuilding those source files that use one of the macros?

Does there need to be a corresponding driver change to deal with these new dependencies, or is this all we need?


// Track the dependency.
if (DepTracker)
DepTracker->addDependency(resolvedPath, /*IsSystem=*/false);
Copy link
Member

Choose a reason for hiding this comment

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

Should we ever care to pass IsSystem=true here? I could imagine it being true for plugins loaded from lib/swift/host/plugins, but (1) I don't know if that will have any practical effect, and (2) that likely means we'd need to have both -system-plugin-path and -plugin-path, and that just feels annoying.

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks great! Am I understanding correctly that this means we will rebuild every source file in the module when one of the macro implementations that the module uses will change, vs. only rebuilding those source files that use one of the macros?

Does there need to be a corresponding driver change to deal with these new dependencies, or is this all we need?

@rintaro could we please add a test to examine the .swiftdeps produced when we have a non-primary source input use a plugin? Once this lands in a snapshot toolchain, would be great to also add a test in the driver incremental build test suite to validate the answer to Doug's question.

On the surface, it looks like .swiftdeps may contain dependencies on plugins from non-primary sources so this may cause coarse-grained incremental re-compilation, but I think that's an okay starting point. And I am pretty sure the driver should be able to handle this without any changes for now.

Comment on lines 31 to 36
PluginRegistry *Registry = nullptr;
std::unique_ptr<PluginRegistry> OwnedRegistry = nullptr;
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a short comment about the difference between Registry and OwnedRegistry?

@rintaro rintaro force-pushed the plugin-loader-swiftdeps branch from 2a4f6db to 332bae4 Compare April 20, 2023 18:32
@rintaro rintaro requested a review from artemcm as a code owner April 20, 2023 18:32
@@ -34,3 +35,5 @@
// CHECK-CONFIRM-ONELINE: {"name":{{.*}}]}

import Module2

@freestanding(expression) macro echo<T>(_: T) -> T = #externalMacro(module: "Plugin", type: "EchoMacro")
Copy link
Member Author

Choose a reason for hiding this comment

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

This is required to actually load the plugin, otherwise plugin dependencies are not recorded.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better if you put this declaration in Inputs/loaded_module_trace_compiler_plugin.swift, so that this is imported from a module like an actual macro adopter library would end up?

@rintaro rintaro force-pushed the plugin-loader-swiftdeps branch from 332bae4 to 0a42292 Compare April 20, 2023 18:48
@rintaro rintaro requested a review from tshortli April 20, 2023 20:28
@rintaro
Copy link
Member Author

rintaro commented Apr 20, 2023

@swift-ci Please smoke test

@rintaro rintaro force-pushed the plugin-loader-swiftdeps branch from 0a42292 to 4181f7a Compare April 20, 2023 21:48
@rintaro
Copy link
Member Author

rintaro commented Apr 20, 2023

@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented Apr 21, 2023

swiftlang/llvm-project#6695
@swift-ci Please smoke test

Copy link
Contributor

@artemcm artemcm left a comment

Choose a reason for hiding this comment

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

This looks good!

* Factor out ASTContext plugin loading to newly introduced 'PluginLoader'
* Insert 'DependencyTracker' to 'PluginLoader'
* Add dependencies right before loading the plugins

rdar://104938481
@rintaro rintaro force-pushed the plugin-loader-swiftdeps branch from 4181f7a to a551c01 Compare April 25, 2023 17:50
@rintaro
Copy link
Member Author

rintaro commented Apr 25, 2023

@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented Apr 25, 2023

swiftlang/llvm-project#6695
@swift-ci Please smoke test

@rintaro rintaro merged commit 473dafd into swiftlang:main Apr 25, 2023
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