Skip to content

Commit 61a09ef

Browse files
committed
[NFC] Rename EmitTypeMetadataRefForLayout to reflect its actual job
This visitor used to directly return type metadata, but at some point we simplified the code a lot by just doing a type rewrite and then calling into the normal type metadata emitter. Apparently we didn't rename the visitor at the time, though, so it's got this very misleading name.
1 parent c27e2c7 commit 61a09ef

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

lib/IRGen/MetadataRequest.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3259,20 +3259,30 @@ llvm::Function *irgen::getOrCreateTypeMetadataAccessFunction(IRGenModule &IGM,
32593259
}
32603260

32613261
namespace {
3262-
/// A visitor class for emitting a reference to type metatype for a
3263-
/// SILType, i.e. a lowered representation type. In general, the type
3264-
/// metadata produced here might not correspond to the formal type that
3265-
/// would belong to the unlowered type. For correctness, it is important
3266-
/// not to cache the result as if it were the metadata for a formal type
3267-
/// unless the type actually cannot possibly be a formal type, e.g. because
3268-
/// it is one of the special lowered type kinds like SILFunctionType.
3262+
/// A visitor class for rewriting a lowered (SIL) type to a formal
3263+
/// type with the same type layout that we can fetch metadata for.
3264+
/// We need type metadata in order to do value operations on some
3265+
/// lowered types (like allocating or copying them), but we can
3266+
/// only fetch type metadata for formal types. We can't reliably
3267+
/// reverse the type lowering process to get the original formal
3268+
/// type, but we should be able to reliably find a formal type with
3269+
/// the same layout as a lowered type.
3270+
///
3271+
/// We can't reliably do this on types expressed in terms of builtin
3272+
/// types, because there aren't type metadata for all builtin types.
3273+
/// Fortunately, we really shouldn't need type metadata to do value
3274+
/// operations on builtin types, and we shouldn't ever see compound
3275+
/// types with them that would require metadata to manipulate (like
3276+
/// a tuple of a builtin type and a resilient type) --- we can rely
3277+
/// on stdlib programmers to not write such types, and we can rely on
3278+
/// SIL transformations not introducing them unnecessarily.
32693279
///
32703280
/// NOTE: If you modify the special cases in this, you should update
32713281
/// isTypeMetadataForLayoutAccessible in SIL.cpp.
3272-
class EmitTypeMetadataRefForLayout
3273-
: public CanTypeVisitor<EmitTypeMetadataRefForLayout, CanType> {
3282+
class GetFormalTypeWithSameLayout
3283+
: public CanTypeVisitor<GetFormalTypeWithSameLayout, CanType> {
32743284
public:
3275-
EmitTypeMetadataRefForLayout() {}
3285+
GetFormalTypeWithSameLayout() {}
32763286

32773287
/// For most types, we can just emit the usual metadata.
32783288
CanType visitType(CanType t) { return t; }
@@ -3293,7 +3303,7 @@ class EmitTypeMetadataRefForLayout
32933303
}
32943304

32953305
CanType visitPackType(CanPackType ty) {
3296-
llvm_unreachable("");
3306+
llvm_unreachable("requesting type metadata for a pack type?");
32973307
}
32983308

32993309
CanType visitPackExpansionType(CanPackExpansionType ty) {
@@ -3399,7 +3409,7 @@ IRGenFunction::emitTypeMetadataRefForLayout(SILType ty,
33993409

34003410
// Map to a layout equivalent AST type.
34013411
auto layoutEquivalentType =
3402-
EmitTypeMetadataRefForLayout().visit(ty.getASTType());
3412+
GetFormalTypeWithSameLayout().visit(ty.getASTType());
34033413
auto response = emitTypeMetadataRef(layoutEquivalentType, request);
34043414
setScopedLocalTypeMetadataForLayout(ty.getObjectType(), response);
34053415
return response.getMetadata();

0 commit comments

Comments
 (0)