Skip to content

[IRGen] Query the VFS for legacy type layouts. #27658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/IRGen/GenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1105,8 +1105,9 @@ TypeConverter::createImmovable(llvm::Type *type, Size size, Alignment align) {

static TypeInfo *invalidTypeInfo() { return (TypeInfo*) 1; }

bool TypeConverter::readLegacyTypeInfo(StringRef path) {
auto fileOrErr = llvm::MemoryBuffer::getFile(path);
bool TypeConverter::readLegacyTypeInfo(llvm::vfs::FileSystem &fs,
StringRef path) {
auto fileOrErr = fs.getBufferForFile(path);
if (!fileOrErr)
return true;

Expand Down Expand Up @@ -1209,6 +1210,8 @@ TypeConverter::TypeConverter(IRGenModule &IGM)
llvm::SmallString<128> defaultPath;

StringRef path = IGM.IRGen.Opts.ReadLegacyTypeInfoPath;
auto fs =
IGM.getSwiftModule()->getASTContext().SourceMgr.getFileSystem();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IGM.Context.SourceMgr

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's simpler, thanks!

if (path.empty()) {
const auto &Triple = IGM.Context.LangOpts.Target;

Expand All @@ -1225,7 +1228,7 @@ TypeConverter::TypeConverter(IRGenModule &IGM)
bool found = false;
for (auto &RuntimeLibraryPath
: IGM.Context.SearchPathOpts.RuntimeLibraryPaths) {
if (llvm::sys::fs::exists(RuntimeLibraryPath)) {
if (fs->exists(RuntimeLibraryPath)) {
defaultPath.append(RuntimeLibraryPath);
found = true;
break;
Expand All @@ -1245,7 +1248,7 @@ TypeConverter::TypeConverter(IRGenModule &IGM)
path = defaultPath;
}

bool error = readLegacyTypeInfo(path);
bool error = readLegacyTypeInfo(*fs, path);
if (error)
llvm::report_fatal_error("Cannot read '" + path + "'");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenType.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class TypeConverter {

/// Read a YAML legacy type layout dump. Returns false on success, true on
/// error.
bool readLegacyTypeInfo(StringRef path);
bool readLegacyTypeInfo(llvm::vfs::FileSystem &fs, StringRef path);

Optional<YAMLTypeInfoNode> getLegacyTypeInfo(NominalTypeDecl *decl) const;

Expand Down
14 changes: 14 additions & 0 deletions test/IRGen/Inputs/legacy_type_info/vfsoverlay.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
'version': 0,
'use-external-names': false,
'roots': [
{
'name': 'OUT_DIR', 'type': 'directory',
'contents': [
{ 'name': 'a_moved.yaml', 'type': 'file',
'external-contents': 'INPUT_DIR/legacy_type_info/a.yaml'
},
]
},
]
}
4 changes: 4 additions & 0 deletions test/IRGen/class_update_callback_with_fixed_layout.sil
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
// RUN: %target-swift-frontend -I %t -emit-ir -enable-library-evolution %s -read-legacy-type-info-path=%S/Inputs/legacy_type_info/a.yaml | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize -DINT=i%target-ptrsize
// RUN: %target-swift-frontend -I %t -emit-ir -enable-library-evolution -O %s -read-legacy-type-info-path=%S/Inputs/legacy_type_info/a.yaml

// Verify that this feature works with the VFS.
// RUN: sed -e "s|INPUT_DIR|%/S/Inputs|g" -e "s|OUT_DIR|%/t|g" %S/Inputs/legacy_type_info/vfsoverlay.yaml > %t/overlay.yaml
// RUN: %target-swift-frontend -vfsoverlay %/t/overlay.yaml -I %t -emit-ir -enable-library-evolution -O %s -read-legacy-type-info-path=%t/a_moved.yaml

// We only use fragile class layouts when Objective-C interop is enabled.

// REQUIRES: objc_interop
Expand Down