@@ -3958,33 +3958,39 @@ swift::TypeBase *SwiftASTContext::ReconstructType(ConstString mangled_typename,
3958
3958
.getPointer ();
3959
3959
assert (!found_type || &found_type->getASTContext () == ast_ctx);
3960
3960
3961
- // Objective-C classes sometimes have private subclasses that are invisible to
3962
- // the Swift compiler because they are declared and defined in a .m file. If
3963
- // we can't reconstruct an ObjC type, walk up the type hierarchy until we find
3964
- // something we can import, or until we run out of types
3965
- while (!found_type) {
3966
- CompilerType clang_type = GetAsClangType (mangled_typename);
3967
- if (!clang_type)
3968
- break ;
3961
+ // If the typeref type system is disabled GetAsClangType will eventually call
3962
+ // ReconstructType again, eventually leading to a stack overflow.
3963
+ if (ModuleList::GetGlobalModuleListProperties ()
3964
+ .GetUseSwiftTypeRefTypeSystem ()) {
3965
+ // Objective-C classes sometimes have private subclasses that are invisible
3966
+ // to the Swift compiler because they are declared and defined in a .m file.
3967
+ // If we can't reconstruct an ObjC type, walk up the type hierarchy until we
3968
+ // find something we can import, or until we run out of types
3969
+ while (!found_type) {
3970
+ CompilerType clang_type = GetAsClangType (mangled_typename);
3971
+ if (!clang_type)
3972
+ break ;
3969
3973
3970
- auto clang_ctx =
3971
- clang_type.GetTypeSystem ().dyn_cast_or_null <TypeSystemClang>();
3972
- if (!clang_ctx)
3973
- break ;
3974
- auto *interface_decl = TypeSystemClang::GetAsObjCInterfaceDecl (clang_type);
3975
- if (!interface_decl)
3976
- break ;
3977
- auto *super_interface_decl = interface_decl->getSuperClass ();
3978
- if (!super_interface_decl)
3979
- break ;
3980
- CompilerType super_type = clang_ctx->GetTypeForDecl (super_interface_decl);
3981
- if (!super_type)
3982
- break ;
3983
- auto super_mangled_typename = super_type.GetMangledTypeName ();
3984
- found_type = swift::Demangle::getTypeForMangling (
3985
- *ast_ctx, super_mangled_typename.GetStringRef ())
3986
- .getPointer ();
3987
- assert (!found_type || &found_type->getASTContext () == ast_ctx);
3974
+ auto clang_ctx =
3975
+ clang_type.GetTypeSystem ().dyn_cast_or_null <TypeSystemClang>();
3976
+ if (!clang_ctx)
3977
+ break ;
3978
+ auto *interface_decl =
3979
+ TypeSystemClang::GetAsObjCInterfaceDecl (clang_type);
3980
+ if (!interface_decl)
3981
+ break ;
3982
+ auto *super_interface_decl = interface_decl->getSuperClass ();
3983
+ if (!super_interface_decl)
3984
+ break ;
3985
+ CompilerType super_type = clang_ctx->GetTypeForDecl (super_interface_decl);
3986
+ if (!super_type)
3987
+ break ;
3988
+ auto super_mangled_typename = super_type.GetMangledTypeName ();
3989
+ found_type = swift::Demangle::getTypeForMangling (
3990
+ *ast_ctx, super_mangled_typename.GetStringRef ())
3991
+ .getPointer ();
3992
+ assert (!found_type || &found_type->getASTContext () == ast_ctx);
3993
+ }
3988
3994
}
3989
3995
3990
3996
if (found_type) {
0 commit comments