Add "-swift-version <n>" that sets LangOpts.EffectiveLanguageVersion.

This flag switches the "effective language version" of the compiler,
at least to any version supported (as of this change: "3" or "3.0").

At the moment nothing uses it except the language version build
configuration statements (#if swift(...)) and various other places
that report, encode, or otherwise check version numbers.

In the future, it's intended as scaffolding for backwards compatibility.

Fixes SR-2582
This commit is contained in:
Graydon Hoare
2016-09-20 15:11:37 -07:00
parent 04b7201431
commit 8970d44675
16 changed files with 133 additions and 22 deletions

View File

@@ -583,7 +583,8 @@ void Serializer::writeHeader(const SerializationOptions &options) {
llvm::raw_svector_ostream versionString(versionStringBuf);
versionString << Version::getCurrentLanguageVersion();
size_t shortVersionStringLength = versionString.tell();
versionString << '/' << version::getSwiftFullVersion();
versionString << '/' << version::getSwiftFullVersion(
M->getASTContext().LangOpts.EffectiveLanguageVersion);
Metadata.emit(ScratchRecord,
VERSION_MAJOR, VERSION_MINOR, shortVersionStringLength,
versionString.str());
@@ -626,12 +627,14 @@ void Serializer::writeDocHeader() {
control_block::MetadataLayout Metadata(Out);
control_block::TargetLayout Target(Out);
auto& LangOpts = M->getASTContext().LangOpts;
Metadata.emit(ScratchRecord,
VERSION_MAJOR, VERSION_MINOR,
/*short version string length*/0,
version::getSwiftFullVersion());
version::getSwiftFullVersion(
LangOpts.EffectiveLanguageVersion));
Target.emit(ScratchRecord, M->getASTContext().LangOpts.Target.str());
Target.emit(ScratchRecord, LangOpts.Target.str());
}
}