Skip to content

Commit 0a606c3

Browse files
authored
Merge pull request #27658 from DougGregor/legacy-type-layout-vfs
[IRGen] Query the VFS for legacy type layouts.
2 parents b6b310f + a29a5f1 commit 0a606c3

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

lib/IRGen/GenType.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,8 +1105,9 @@ TypeConverter::createImmovable(llvm::Type *type, Size size, Alignment align) {
11051105

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

1108-
bool TypeConverter::readLegacyTypeInfo(StringRef path) {
1109-
auto fileOrErr = llvm::MemoryBuffer::getFile(path);
1108+
bool TypeConverter::readLegacyTypeInfo(llvm::vfs::FileSystem &fs,
1109+
StringRef path) {
1110+
auto fileOrErr = fs.getBufferForFile(path);
11101111
if (!fileOrErr)
11111112
return true;
11121113

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

12111212
StringRef path = IGM.IRGen.Opts.ReadLegacyTypeInfoPath;
1213+
auto fs =
1214+
IGM.getSwiftModule()->getASTContext().SourceMgr.getFileSystem();
12121215
if (path.empty()) {
12131216
const auto &Triple = IGM.Context.LangOpts.Target;
12141217

@@ -1225,7 +1228,7 @@ TypeConverter::TypeConverter(IRGenModule &IGM)
12251228
bool found = false;
12261229
for (auto &RuntimeLibraryPath
12271230
: IGM.Context.SearchPathOpts.RuntimeLibraryPaths) {
1228-
if (llvm::sys::fs::exists(RuntimeLibraryPath)) {
1231+
if (fs->exists(RuntimeLibraryPath)) {
12291232
defaultPath.append(RuntimeLibraryPath);
12301233
found = true;
12311234
break;
@@ -1245,7 +1248,7 @@ TypeConverter::TypeConverter(IRGenModule &IGM)
12451248
path = defaultPath;
12461249
}
12471250

1248-
bool error = readLegacyTypeInfo(path);
1251+
bool error = readLegacyTypeInfo(*fs, path);
12491252
if (error)
12501253
llvm::report_fatal_error("Cannot read '" + path + "'");
12511254
}

lib/IRGen/GenType.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class TypeConverter {
208208

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

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
'version': 0,
3+
'use-external-names': false,
4+
'roots': [
5+
{
6+
'name': 'OUT_DIR', 'type': 'directory',
7+
'contents': [
8+
{ 'name': 'a_moved.yaml', 'type': 'file',
9+
'external-contents': 'INPUT_DIR/legacy_type_info/a.yaml'
10+
},
11+
]
12+
},
13+
]
14+
}

test/IRGen/class_update_callback_with_fixed_layout.sil

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
// 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
55
// 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
66

7+
// Verify that this feature works with the VFS.
8+
// 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
9+
// 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
10+
711
// We only use fragile class layouts when Objective-C interop is enabled.
812

913
// REQUIRES: objc_interop

0 commit comments

Comments
 (0)