Skip to content

Resolve a Layering Violation in libBasic #61014

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
Sep 9, 2022

Conversation

CodaFi
Copy link
Contributor

@CodaFi CodaFi commented Sep 9, 2022

Basic should not be allowed to link Parse, yet it was doing so to allow Version to provide a constructor that would conveniently parse a StringRef. This entrypoint also emitted diagnostics, so it pulled in libAST.

Sink the version parser entrypoint down into Parse where it belongs and point all the clients to the right place.

@CodaFi CodaFi requested review from compnerd and etcwilde September 9, 2022 01:38
@CodaFi CodaFi marked this pull request as ready for review September 9, 2022 01:39
Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

Thanks for cleaning up the dependency issue.

@@ -0,0 +1,45 @@
//===--- VersionParser.h - Parser Swift Version Numbers ---------*- C++ -*-===//
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't match the name of the file. VersionParser.h seems more in line with the rest of the tree.

Version getCurrentCompilerVersion();
} // namespace version

class VersionParser final {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to make this a class and add static methods rather than a namespace and free functions for parseCompilerVersionString and parseVersionString?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to friend Version so I can poke at the component vector.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see. That probably deserves a comment.

@DougGregor
Copy link
Member

@swift-ci please smoke test

@CodaFi CodaFi changed the title Resolve a Priority Inversion in libBasic Resolve a Layering Violation in libBasic Sep 9, 2022
@CodaFi CodaFi force-pushed the version-militude branch 2 times, most recently from 376fef9 to 3c9645f Compare September 9, 2022 05:06
@CodaFi
Copy link
Contributor Author

CodaFi commented Sep 9, 2022

swiftlang/llvm-project#5269

@swift-ci smoke test

Copy link
Member

@etcwilde etcwilde left a comment

Choose a reason for hiding this comment

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

friends are gross, but meh, I'll allow it.
It looks like you should be able to parse out the numbers and then use the Version constructor to emit the version once you've computed everything instead of needing to manipulate the components list directly. Then we can drop the friend.

I merged the other patch to get clean builds.
If you want to, feel free to remove the circular link edge. If not, I can do it later.
https://github.com/apple/swift/blob/4b7db51477d08f0c20d57d11a9e7b2b2f7ae281f/lib/Basic/CMakeLists.txt#L101-L103

Basic should not be allowed to link Parse, yet it was doing so
to allow Version to provide a constructor that would conveniently
parse a StringRef. This entrypoint also emitted diagnostics, so it
pulled in libAST.

Sink the version parser entrypoint down into Parse where it belongs
and point all the clients to the right place.
@CodaFi
Copy link
Contributor Author

CodaFi commented Sep 9, 2022

swiftlang/llvm-project#5269

@swift-ci smoke test

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

I like @etcwilde's suggestion for using the ctor for Version rather than friend and then making the functions free functions rather than part of an empty class, but that seems less important than the circular dependency issues.

@CodaFi CodaFi merged commit 9172d66 into swiftlang:main Sep 9, 2022
@CodaFi CodaFi deleted the version-militude branch September 9, 2022 14:44
CodaFi added a commit to CodaFi/swift that referenced this pull request Nov 29, 2022
This is set on a per-file basis and was not forwarded when
swiftlang#61014 was integrated.

This is a short-term fix for this issue. I don't see a reason
this version number should be applied to individual files instead
of being passed as an argument to every translation unit.

rdar://102731783
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