RFC: internal language versioning

Hi Ewa!

In commit 93786d8e264d095256169a6a2552970ea785036f, you wrote: “Removing isSwiftVersion4, isSwiftVersion5. We’ll need to come up with a better way to conditionalize code based on language version.”

This is certainly true! I wondered what would happen as new versions came along. :-)

It seems to me like the right approach is this:

    bool isSwiftVersionLessThan(unsigned major, unsigned minor = 0);
    // hopefully we’ll never need ’minor’ level precession

With such an API, bug fixes, version specific behavior, and future features are easy to implement:

// Bug fixed in version 4
if (isSwiftVersionLessThan(4)) {
  // old way
} else {
  // new way

// Version 7 feature work
if (isSwiftVersionLessThan(7)) {
  // pre feature logic
} else {
  // new feature work logic

// Broken behavior specific to version 3 and 4, but not version 1, 2, and 5+
if (isSwiftVersionLessThan(5) && !isSwiftVersionLessThan(3)) {
  // Swift 3 and 4 code
} else {
  // normal path

Alternatively, the API could be “isSwiftVersionGreaterThanOrEqualTo()” but that seems like a mouthful. Similarly, the API could be “isSwiftVersionInHalfOpenRange()”, but that seems awkward because the future is hopefully endless.

What to people think?