39
39
using namespace swift ;
40
40
using FileDependency = SerializationOptions::FileDependency;
41
41
42
+ #define SWIFT_INTERFACE_FORMAT_VERSION_KEY " swift-interface-format-version"
42
43
#define SWIFT_TOOLS_VERSION_KEY " swift-tools-version"
43
44
#define SWIFT_MODULE_FLAGS_KEY " swift-module-flags"
44
45
46
+ static swift::version::Version InterfaceFormatVersion ({1 , 0 });
47
+
45
48
static bool
46
49
extractSwiftInterfaceVersionAndArgs (DiagnosticEngine &Diags,
47
50
clang::vfs::FileSystem &FS,
@@ -56,7 +59,7 @@ extractSwiftInterfaceVersionAndArgs(DiagnosticEngine &Diags,
56
59
return true ;
57
60
}
58
61
auto SB = FileOrError.get ()->getBuffer ();
59
- auto VersRe = getSwiftInterfaceToolsVersionRegex ();
62
+ auto VersRe = getSwiftInterfaceFormatVersionRegex ();
60
63
auto FlagRe = getSwiftInterfaceModuleFlagsRegex ();
61
64
SmallVector<StringRef, 1 > VersMatches, FlagMatches;
62
65
if (!VersRe.match (SB, &VersMatches)) {
@@ -286,6 +289,17 @@ static bool buildSwiftModuleFromSwiftInterface(
286
289
return ;
287
290
}
288
291
292
+ // For now: we support anything with the same "major version" and assume
293
+ // minor versions might be interesting for debugging, or special-casing a
294
+ // compatible field variant.
295
+ if (Vers.asMajorVersion () != InterfaceFormatVersion.asMajorVersion ()) {
296
+ Diags.diagnose (SourceLoc (),
297
+ diag::unsupported_version_of_parseable_interface,
298
+ InPath, Vers);
299
+ SubError = true ;
300
+ return ;
301
+ }
302
+
289
303
if (SubInvocation.parseArgs (SubArgs, Diags)) {
290
304
SubError = true ;
291
305
return ;
@@ -415,21 +429,26 @@ static void diagnoseScopedImports(DiagnosticEngine &diags,
415
429
}
416
430
}
417
431
418
- // / Prints to \p out a comment containing a tool-versions identifier as well
419
- // / as any relevant command-line flags in \p Opts used to construct \p M.
432
+ // / Prints to \p out a comment containing a format version number, tool version
433
+ // / string as well as any relevant command-line flags in \p Opts used to
434
+ // / construct \p M.
420
435
static void printToolVersionAndFlagsComment (raw_ostream &out,
421
436
ParseableInterfaceOptions const &Opts,
422
437
ModuleDecl *M) {
423
438
auto &Ctx = M->getASTContext ();
439
+ auto ToolsVersion = swift::version::getSwiftFullVersion (
440
+ Ctx.LangOpts .EffectiveLanguageVersion );
441
+ out << " // " SWIFT_INTERFACE_FORMAT_VERSION_KEY " : "
442
+ << InterfaceFormatVersion << " \n " ;
424
443
out << " // " SWIFT_TOOLS_VERSION_KEY " : "
425
- << Ctx. LangOpts . EffectiveLanguageVersion << " \n " ;
444
+ << ToolsVersion << " \n " ;
426
445
out << " // " SWIFT_MODULE_FLAGS_KEY " : "
427
446
<< Opts.ParseableInterfaceFlags << " \n " ;
428
447
}
429
448
430
- llvm::Regex swift::getSwiftInterfaceToolsVersionRegex () {
431
- return llvm::Regex (" ^// " SWIFT_TOOLS_VERSION_KEY " : ([0-9 \\ .]+)$ " ,
432
- llvm::Regex::Newline);
449
+ llvm::Regex swift::getSwiftInterfaceFormatVersionRegex () {
450
+ return llvm::Regex (" ^// " SWIFT_INTERFACE_FORMAT_VERSION_KEY
451
+ " : ([0-9 \\ .]+)$ " , llvm::Regex::Newline);
433
452
}
434
453
435
454
llvm::Regex swift::getSwiftInterfaceModuleFlagsRegex () {
0 commit comments