Skip to content

Commit 39fb638

Browse files
committed
[Frontend/AST] Make it possible to determine Swift compiler version used to build a ModuleDecl
1 parent 3bd4853 commit 39fb638

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

include/swift/AST/Module.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ class ModuleDecl
254254

255255
mutable Identifier PublicModuleName;
256256

257+
/// Indicates that version of the Swift compiler this module was built with.
258+
mutable llvm::VersionTuple SwiftCompilerVersion;
259+
257260
public:
258261
/// Produces the components of a given module's full name in reverse order.
259262
///
@@ -518,11 +521,20 @@ class ModuleDecl
518521
PublicModuleName = name;
519522
}
520523

524+
/// The version of the Swift compiler this module was built with.
525+
llvm::VersionTuple getSwiftCompilerVersion() const {
526+
return SwiftCompilerVersion;
527+
}
528+
529+
void setSwiftCompilerVersion(llvm::VersionTuple version) {
530+
SwiftCompilerVersion = version;
531+
}
532+
521533
/// Retrieve the actual module name of an alias used for this module (if any).
522534
///
523-
/// For example, if '-module-alias Foo=Bar' is passed in when building the main module,
524-
/// and this module is (a) not the main module and (b) is named Foo, then it returns
525-
/// the real (physically on-disk) module name Bar.
535+
/// For example, if '-module-alias Foo=Bar' is passed in when building the
536+
/// main module, and this module is (a) not the main module and (b) is named
537+
/// Foo, then it returns the real (physically on-disk) module name Bar.
526538
///
527539
/// If no module aliasing is set, it will return getName(), i.e. Foo.
528540
Identifier getRealName() const;

lib/Frontend/Frontend.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,9 @@ ModuleDecl *CompilerInstance::getMainModule() const {
14891489
if (Invocation.getSILOptions().EnableSerializePackage)
14901490
MainModule->setSerializePackageEnabled();
14911491

1492+
MainModule->setSwiftCompilerVersion(
1493+
Invocation.getFrontendOptions().SwiftCompilerVersion);
1494+
14921495
// Register the main module with the AST context.
14931496
Context->addLoadedModule(MainModule);
14941497
Context->MainModule = MainModule;

0 commit comments

Comments
 (0)