@@ -315,9 +315,8 @@ getRuntimeVersionThatSupportsDemanglingType(CanType type) {
315315// where completing the metadata during demangling might cause cyclic
316316// dependencies.
317317static std::pair<llvm::Constant *, unsigned >
318- getTypeRefByFunction (IRGenModule &IGM,
319- CanGenericSignature sig,
320- CanType t) {
318+ getTypeRefByFunction (IRGenModule &IGM, CanGenericSignature sig, CanType t,
319+ MangledTypeRefRole role) {
321320 IRGenMangler mangler (IGM.Context );
322321 std::string symbolName =
323322 mangler.mangleSymbolNameForMangledMetadataAccessorString (
@@ -433,7 +432,11 @@ getTypeRefByFunction(IRGenModule &IGM,
433432 // Form the mangled name with its relative reference.
434433 auto S = B.beginStruct ();
435434 S.setPacked (true );
436- S.add (llvm::ConstantInt::get (IGM.Int8Ty , 255 ));
435+ if (role == MangledTypeRefRole::DefaultAssociatedTypeWitness) {
436+ S.add (llvm::ConstantInt::get (
437+ IGM.Int8Ty ,
438+ ProtocolRequirementFlags::AssociatedTypeInProtocolContextByte));
439+ }
437440 S.add (llvm::ConstantInt::get (IGM.Int8Ty , 9 ));
438441 S.addCompactFunctionReference (accessor);
439442
@@ -513,7 +516,7 @@ getTypeRefImpl(IRGenModule &IGM,
513516 // the field will be artificially hidden to reflectors.
514517 if (isAlwaysNoncopyable) {
515518 IGM.IRGen .noteUseOfTypeMetadata (type);
516- return getTypeRefByFunction (IGM, sig, type);
519+ return getTypeRefByFunction (IGM, sig, type, role );
517520 }
518521 }
519522 LLVM_FALLTHROUGH;
@@ -524,12 +527,12 @@ getTypeRefImpl(IRGenModule &IGM,
524527 // ensuring that we can always reconstruct type metadata from a mangled name
525528 // in-process.
526529 IGM.IRGen .noteUseOfTypeMetadata (type);
527-
530+
528531 // If the minimum deployment target's runtime demangler wouldn't understand
529532 // this mangled name, then fall back to generating a "mangled name" with a
530533 // symbolic reference with a callback function.
531534 if (mangledNameIsUnknownToDeployTarget (IGM, type)) {
532- return getTypeRefByFunction (IGM, sig, type);
535+ return getTypeRefByFunction (IGM, sig, type, role );
533536 }
534537
535538 break ;
0 commit comments