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