Skip to content

Commit

Permalink
Merge pull request swiftlang#14397 from apple/revert-14185-field-desc…
Browse files Browse the repository at this point in the history
…-for-imported-structs

Revert "[WIP][IRGen] Emit type field descriptors for imported structs"
  • Loading branch information
xedin authored Feb 3, 2018
2 parents cc1d258 + 8667eb6 commit 73a7ebc
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 59 deletions.
4 changes: 0 additions & 4 deletions include/swift/Reflection/Records.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,6 @@ class FieldDescriptor {
Kind == FieldDescriptorKind::ObjCProtocol);
}

bool isStruct() const {
return Kind == FieldDescriptorKind::Struct;
}

const_iterator begin() const {
auto Begin = getFieldRecordBuffer();
auto End = Begin + NumFields;
Expand Down
24 changes: 3 additions & 21 deletions lib/IRGen/GenReflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,8 @@ class ReflectionMetadataBuilder {
IGM.ImportedClasses.insert(CD);
else if (auto PD = dyn_cast<ProtocolDecl>(Nominal))
IGM.ImportedProtocols.insert(PD);
else {
if (auto *SD = dyn_cast<StructDecl>(Nominal))
IGM.ImportedStructs.insert(SD);

else
IGM.OpaqueTypes.insert(Nominal);
}
}
});
}
Expand Down Expand Up @@ -345,15 +341,6 @@ class FieldTypeMetadataBuilder : public ReflectionMetadataBuilder {
} else {
addTypeRef(value->getModuleContext(), type);
addBuiltinTypeRefs(type);

// Trigger foreign struct metadata generation for each field,
// this is going to be used later on by reflection library.
type.visit([&](CanType nestedType) {
if (auto *NTD = nestedType->getAnyNominal()) {
if (NTD->hasClangNode() && isa<StructDecl>(NTD))
(void) IGM.getAddrOfForeignTypeMetadataCandidate(nestedType);
}
});
}

if (IGM.IRGen.Opts.EnableReflectionNames) {
Expand Down Expand Up @@ -381,13 +368,12 @@ class FieldTypeMetadataBuilder : public ReflectionMetadataBuilder {
B.addInt16(fieldRecordSize);

// Imported classes don't need field descriptors
if (NTD->hasClangNode() && isa<ClassDecl>(NTD)) {
if (NTD->hasClangNode()) {
assert(isa<ClassDecl>(NTD));
B.addInt32(0);
return;
}

assert(!NTD->hasClangNode() || isa<StructDecl>(NTD));

auto properties = NTD->getStoredProperties();
B.addInt32(std::distance(properties.begin(), properties.end()));
for (auto property : properties)
Expand Down Expand Up @@ -449,7 +435,6 @@ class FieldTypeMetadataBuilder : public ReflectionMetadataBuilder {
void layout() override {
if (NTD->hasClangNode() &&
!isa<ClassDecl>(NTD) &&
!isa<StructDecl>(NTD) &&
!isa<ProtocolDecl>(NTD))
return;

Expand Down Expand Up @@ -956,9 +941,6 @@ void IRGenModule::emitBuiltinReflectionMetadata() {
for (auto PD : ImportedProtocols)
emitFieldMetadataRecord(PD);

for (auto SD : ImportedStructs)
emitFieldMetadataRecord(SD);

for (auto builtinType : BuiltinTypes)
emitBuiltinTypeMetadataRecord(builtinType);

Expand Down
3 changes: 0 additions & 3 deletions lib/IRGen/IRGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -920,9 +920,6 @@ class IRGenModule {
/// Imported protocols referenced by types in this module when emitting
/// reflection metadata.
llvm::SetVector<const ProtocolDecl *> ImportedProtocols;
/// Imported structs referenced by types in this module when emitting
/// reflection metadata.
llvm::SetVector<const StructDecl *> ImportedStructs;

llvm::Constant *getAddrOfStringForTypeRef(StringRef Str);
llvm::Constant *getAddrOfFieldName(StringRef Name);
Expand Down
8 changes: 3 additions & 5 deletions stdlib/public/Reflection/TypeLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,18 +1057,16 @@ class LowerType

const TypeInfo *visitAnyNominalTypeRef(const TypeRef *TR) {
const auto &FD = TC.getBuilder().getFieldTypeInfo(TR);
if (FD.first == nullptr || FD.first->isStruct()) {
if (FD.first == nullptr) {
// Maybe this type is opaque -- look for a builtin
// descriptor to see if we at least know its size
// and alignment.
if (auto ImportedTypeDescriptor = TC.getBuilder().getBuiltinTypeInfo(TR))
return TC.makeTypeInfo<BuiltinTypeInfo>(ImportedTypeDescriptor);

// Otherwise, we're out of luck.
if (FD.first == nullptr) {
DEBUG(std::cerr << "No TypeInfo for nominal type: "; TR->dump());
return nullptr;
}
DEBUG(std::cerr << "No TypeInfo for nominal type: "; TR->dump());
return nullptr;
}

switch (FD.first->Kind) {
Expand Down
26 changes: 0 additions & 26 deletions test/Reflection/typeref_decoding_imported.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,6 @@
// CHECK-32: mce: __C.MyCEnum
// CHECK-32: (struct __C.MyCEnum)

// CHECK-32: __C.MyCStruct
// CHECK-32: -------------
// CHECK-32: i: Swift.Int32
// CHECK-32: (struct Swift.Int32)

// CHECK-32: ip: Swift.Optional<Swift.UnsafeMutablePointer<Swift.Int32>>
// CHECK-32: (bound_generic_enum Swift.Optional
// CHECK-32: (bound_generic_struct Swift.UnsafeMutablePointer
// CHECK-32: (struct Swift.Int32)))

// CHECK-32: c: Swift.Int8
// CHECK-32: (struct Swift.Int8)

// CHECK-32: TypesToReflect.AlsoHasCTypes
// CHECK-32: ----------------------------

Expand Down Expand Up @@ -95,19 +82,6 @@
// CHECK-64: mcu: __C.MyCUnion
// CHECK-64: (struct __C.MyCUnion)

// CHECK-64: __C.MyCStruct
// CHECK-64: -------------
// CHECK-64: i: Swift.Int32
// CHECK-64: (struct Swift.Int32)

// CHECK-64: ip: Swift.Optional<Swift.UnsafeMutablePointer<Swift.Int32>>
// CHECK-64: (bound_generic_enum Swift.Optional
// CHECK-64: (bound_generic_struct Swift.UnsafeMutablePointer
// CHECK-64: (struct Swift.Int32)))

// CHECK-64: c: Swift.Int8
// CHECK-64: (struct Swift.Int8)

// CHECK-64: TypesToReflect.AlsoHasCTypes
// CHECK-64: ----------------------------

Expand Down

0 comments on commit 73a7ebc

Please sign in to comment.