Resolve a Layering Violation in libBasic

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.
This commit is contained in:
Robert Widmann
2022-09-08 18:35:56 -07:00
parent 6b85bdfe23
commit 18b79ffcfd
17 changed files with 350 additions and 303 deletions

View File

@@ -30,7 +30,7 @@
namespace swift {
class DiagnosticEngine;
class VersionParser;
class SourceLoc;
namespace version {
@@ -53,6 +53,7 @@ namespace version {
/// a: [0 - 999]
/// b: [0 - 999]
class Version {
friend class swift::VersionParser;
SmallVector<unsigned, 5> Components;
public:
/// Create the empty compiler version - this always compares greater
@@ -63,11 +64,6 @@ public:
/// Create a literal version from a list of components.
Version(std::initializer_list<unsigned> Values) : Components(Values) {}
/// Create a version from a string in source code.
///
/// Must include only groups of digits separated by a dot.
Version(StringRef VersionString, SourceLoc Loc, DiagnosticEngine *Diags);
/// Return a string to be used as an internal preprocessor define.
///
/// The components of the version are multiplied element-wise by
@@ -129,29 +125,6 @@ public:
/// Return this Version struct as the appropriate version string for APINotes.
std::string asAPINotesVersionString() const;
/// Parse a version in the form used by the _compiler_version(string-literal)
/// \#if condition.
///
/// \note This is \em only used for the string literal version, so it includes
/// backwards-compatibility logic to convert it to something that can be
/// compared with a modern SWIFT_COMPILER_VERSION.
static Optional<Version> parseCompilerVersionString(StringRef VersionString,
SourceLoc Loc,
DiagnosticEngine *Diags);
/// Parse a generic version string of the format [0-9]+(.[0-9]+)*
///
/// Version components can be any unsigned 64-bit number.
static Optional<Version> parseVersionString(StringRef VersionString,
SourceLoc Loc,
DiagnosticEngine *Diags);
/// Returns a version from the currently defined SWIFT_COMPILER_VERSION.
///
/// If SWIFT_COMPILER_VERSION is undefined, this will return the empty
/// compiler version.
static Version getCurrentCompilerVersion();
/// Returns a version from the currently defined SWIFT_VERSION_MAJOR and
/// SWIFT_VERSION_MINOR.
static Version getCurrentLanguageVersion();
@@ -190,7 +163,7 @@ std::string getSwiftFullVersion(Version effectiveLanguageVersion =
StringRef getSwiftRevision();
/// Is the running compiler built with a version tag for distribution?
/// When true, \c Version::getCurrentCompilerVersion returns a valid version
/// When true, \c version::getCurrentCompilerVersion returns a valid version
/// and \c getCurrentCompilerTag returns the version tuple in string format.
bool isCurrentCompilerTagged();