Skip to content

[SourceKit] Remove dependency of SwiftLang on Core #3101

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

Conversation

briancroom
Copy link
Contributor

What's in this pull request?

SourceKit's SwiftLang (SwiftLangSupport class) and Core (Context class) libraries currently depend on each other. At @jrose-apple's suggestion, I have broken this coupling by requiring SwiftLangSupport to be injected into Context.

See also: #3080


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

Triggering Swift CI

The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:

Smoke Testing

Platform Comment
All supported platforms @swift-ci Please smoke test
All supported platforms @swift-ci Please smoke test and merge
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
All supported platforms @swift-ci Please test and merge
OS X platform @swift-ci Please test OS X platform
OS X platform @swift-ci Please benchmark
Linux platform @swift-ci Please test Linux platform

Lint Testing

Language Comment
Python @swift-ci Please Python lint

Note: Only members of the Apple organization can trigger swift-ci.

@briancroom
Copy link
Contributor Author

@swift-ci please test

@gribozavr
Copy link
Contributor

@akyrtzi @benlangmuir @nkcsgexi Could you review, please?

@briancroom briancroom force-pushed the sourcekit-break-circular-dependency branch from 5781426 to 6370242 Compare June 21, 2016 18:00
@akyrtzi
Copy link
Contributor

akyrtzi commented Jun 21, 2016

I'd suggest a simpler way to break the cycle, which would result in much fewer changes.

-Change the Context constructor to something like this:
Context(StringRef RuntimeLibPath, llvm::function_ref<std::unique_ptr<LangSupport>(Context &)> LangSupportFactoryFn)
Have the constructor call the factory function to get the LangSupport pointer.

-Introduce static std::unique_ptr<LangSupport> SwiftLangSupport::create(SourceKit::Context &SKCtx) function

  • At the points where Context is constructed also pass the above function reference.

@briancroom
Copy link
Contributor Author

@akyrtzi oh nice, yeah that sounds like a great solution! I'll update the PR a bit later accordingly.

@briancroom briancroom force-pushed the sourcekit-break-circular-dependency branch from 6370242 to 4f4004d Compare June 22, 2016 15:33
@briancroom
Copy link
Contributor Author

@swift-ci please test

@briancroom
Copy link
Contributor Author

Ok, I've pushed a simplified version now based on @akyrtzi's suggestion. Note that I opted to keep the new Factory.h header, because the SwiftLang module had no public headers at all previously, and I wanted to avoid requiring clients to depend on the entire SwiftLangSupport.h header. Does that seem sensible?

@briancroom briancroom force-pushed the sourcekit-break-circular-dependency branch from 4f4004d to d74c8ff Compare June 22, 2016 16:20
@briancroom
Copy link
Contributor Author

@swift-ci please test

class LangSupport;
class Context;

std::unique_ptr<LangSupport> createSwiftLangSupport(Context &SKCtx);
Copy link
Contributor

Choose a reason for hiding this comment

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

Headers should generally include the headers that they depend on, in this case it should get a #include <memory> (because of std::unique_ptr)

@akyrtzi
Copy link
Contributor

akyrtzi commented Jun 22, 2016

LGTM, with only a couple of nitpicks, thank you!

@briancroom briancroom force-pushed the sourcekit-break-circular-dependency branch from d74c8ff to fac7440 Compare June 22, 2016 17:26
@briancroom
Copy link
Contributor Author

@swift-ci Please test and merge

@swift-ci swift-ci merged commit 202e991 into swiftlang:master Jun 22, 2016
@briancroom briancroom deleted the sourcekit-break-circular-dependency branch June 22, 2016 20:42
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