Skip to content

Commit 86dae68

Browse files
committed
Reflection: Add SILBoxTypeRef, which can come up in capture descriptors
1 parent 5f18de5 commit 86dae68

File tree

10 files changed

+77
-1
lines changed

10 files changed

+77
-1
lines changed

docs/ABI.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,7 @@ Types
935935
type ::= 'Xw' type // @weak type
936936
type ::= 'XF' impl-function-type // function implementation type
937937
type ::= 'Xf' type type // @thin function type
938+
type ::= 'Xb' type // SIL @box type
938939
nominal-type ::= known-nominal-type
939940
nominal-type ::= substitution
940941
nominal-type ::= nominal-type-kind declaration-name

include/swift/Reflection/TypeRef.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,33 @@ class UnmanagedStorageTypeRef final : public ReferenceStorageTypeRef {
703703
}
704704
};
705705

706+
class SILBoxTypeRef final : public TypeRef {
707+
const TypeRef *BoxedType;
708+
709+
static TypeRefID Profile(const TypeRef *BoxedType) {
710+
TypeRefID ID;
711+
ID.addPointer(BoxedType);
712+
return ID;
713+
}
714+
public:
715+
SILBoxTypeRef(const TypeRef *BoxedType)
716+
: TypeRef(TypeRefKind::SILBox), BoxedType(BoxedType) {}
717+
718+
template <typename Allocator>
719+
static const SILBoxTypeRef *create(Allocator &A,
720+
const TypeRef *BoxedType) {
721+
FIND_OR_CREATE_TYPEREF(A, SILBoxTypeRef, BoxedType);
722+
}
723+
724+
const TypeRef *getBoxedType() const {
725+
return BoxedType;
726+
}
727+
728+
static bool classof(const TypeRef *TR) {
729+
return TR->getKind() == TypeRefKind::SILBox;
730+
}
731+
};
732+
706733
template <typename ImplClass, typename RetTy = void, typename... Args>
707734
class TypeRefVisitor {
708735
public:

include/swift/Reflection/TypeRefBuilder.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ class TypeRefBuilder {
229229
return WeakStorageTypeRef::create(*this, base);
230230
}
231231

232+
const SILBoxTypeRef *createSILBoxType(const TypeRef *base) {
233+
return SILBoxTypeRef::create(*this, base);
234+
}
235+
232236
const ObjCClassTypeRef *
233237
createObjCClassType(const std::string &mangledName) {
234238
return ObjCClassTypeRef::create(*this, mangledName);

include/swift/Reflection/TypeRefs.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ TYPEREF(Opaque, TypeRef)
3333
TYPEREF(UnownedStorage, TypeRef)
3434
TYPEREF(UnmanagedStorage, TypeRef)
3535
TYPEREF(WeakStorage, TypeRef)
36+
TYPEREF(SILBox, TypeRef)
3637

3738
#undef TYPEREF

include/swift/Remote/MetadataReader.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ class TypeDecoder {
243243
return BuiltType();
244244
return Builder.createWeakStorageType(base);
245245
}
246+
case NodeKind::SILBoxType: {
247+
auto base = decodeMangledType(Node->getChild(0));
248+
if (!base)
249+
return BuiltType();
250+
return Builder.createSILBoxType(base);
251+
}
246252
default:
247253
return BuiltType();
248254
}

lib/RemoteAST/RemoteAST.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ class RemoteASTTypeBuilder {
362362
return WeakStorageType::get(base, Ctx);
363363
}
364364

365+
Type createSILBoxType(Type base) {
366+
return SILBoxType::get(base->getCanonicalType());
367+
}
368+
365369
Type createObjCClassType(StringRef name) {
366370
Identifier ident = Ctx.getIdentifier(name);
367371
auto typeDecl =

stdlib/public/Reflection/TypeLowering.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,11 @@ class HasSingletonMetatype
552552
return MetatypeRepresentation::Thin;
553553
}
554554

555+
MetatypeRepresentation
556+
visitSILBoxTypeRef(const SILBoxTypeRef *SB) {
557+
return MetatypeRepresentation::Thin;
558+
}
559+
555560
MetatypeRepresentation
556561
visitGenericTypeParameterTypeRef(const GenericTypeParameterTypeRef *GTP) {
557562
assert(false && "Must have concrete TypeRef");
@@ -844,6 +849,11 @@ class LowerType
844849
return visitAnyStorageTypeRef(US->getType(), ReferenceKind::Unmanaged);
845850
}
846851

852+
const TypeInfo *visitSILBoxTypeRef(const SILBoxTypeRef *SB) {
853+
return TC.getReferenceTypeInfo(ReferenceKind::Strong,
854+
ReferenceCounting::Native);
855+
}
856+
847857
const TypeInfo *visitOpaqueTypeRef(const OpaqueTypeRef *O) {
848858
assert(false && "Can't lower opaque TypeRef");
849859
return nullptr;

stdlib/public/Reflection/TypeRef.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ class PrintTypeRef : public TypeRefVisitor<PrintTypeRef, void> {
204204
OS << ')';
205205
}
206206

207+
void visitSILBoxTypeRef(const SILBoxTypeRef *SB) {
208+
printHeader("sil_box");
209+
printRec(SB->getBoxedType());
210+
OS << ')';
211+
}
212+
207213
void visitOpaqueTypeRef(const OpaqueTypeRef *O) {
208214
printHeader("opaque");
209215
OS << ')';
@@ -298,6 +304,10 @@ struct TypeRefIsConcrete
298304
bool visitUnmanagedStorageTypeRef(const UnmanagedStorageTypeRef *US) {
299305
return visit(US->getType());
300306
}
307+
308+
bool visitSILBoxTypeRef(const SILBoxTypeRef *SB) {
309+
return visit(SB->getBoxedType());
310+
}
301311
};
302312

303313
const OpaqueTypeRef *
@@ -508,6 +518,10 @@ class ThickenMetatype
508518
return US;
509519
}
510520

521+
const TypeRef *visitSILBoxTypeRef(const SILBoxTypeRef *SB) {
522+
return SILBoxTypeRef::create(Builder, visit(SB->getBoxedType()));
523+
}
524+
511525
const TypeRef *visitOpaqueTypeRef(const OpaqueTypeRef *O) {
512526
return O;
513527
}
@@ -660,6 +674,10 @@ class TypeRefSubstitution
660674
return UnmanagedStorageTypeRef::create(Builder, visit(US->getType()));
661675
}
662676

677+
const TypeRef *visitSILBoxTypeRef(const SILBoxTypeRef *SB) {
678+
return SILBoxTypeRef::create(Builder, visit(SB->getBoxedType()));
679+
}
680+
663681
const TypeRef *visitOpaqueTypeRef(const OpaqueTypeRef *O) {
664682
return O;
665683
}

stdlib/public/Reflection/TypeRefBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ void ClosureContextInfo::dump(std::ostream &OS) {
284284
else
285285
MS.second->dump(OS);
286286
}
287+
OS << "\n";
287288
}
288289

289290
void TypeRefBuilder::dumpCaptureSection(std::ostream &OS) {

test/Reflection/typeref_decoding.result.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,15 +660,18 @@ BUILTIN TYPES:
660660
CAPTURE DESCRIPTORS:
661661
====================
662662
- Capture types:
663-
!!! Invalid typeref
663+
(sil_box
664+
(generic_type_parameter depth=0 index=0))
664665
- Metadata sources:
665666
(generic_type_parameter depth=0 index=0)
666667
(closure_binding index=0)
668+
667669
- Capture types:
668670
(struct Swift.Int)
669671
- Metadata sources:
670672
(generic_type_parameter depth=0 index=0)
671673
!!! Invalid matadata source
674+
672675
- Capture types:
673676
(bound_generic_class TypesToReflect.C1
674677
(generic_type_parameter depth=0 index=1))
@@ -679,3 +682,4 @@ CAPTURE DESCRIPTORS:
679682
(generic_argument index=0
680683
(reference_capture index=1))
681684

685+

0 commit comments

Comments
 (0)