diff --git a/include/swift/AST/Decl.h b/include/swift/AST/Decl.h index b75ec916c86..4679da7b4ef 100644 --- a/include/swift/AST/Decl.h +++ b/include/swift/AST/Decl.h @@ -72,6 +72,7 @@ namespace swift { class TypeAliasDecl; class Stmt; class SubscriptDecl; + class UnboundGenericType; class ValueDecl; class VarDecl; @@ -413,9 +414,10 @@ class alignas(1 << DeclAlignInBits) Decl { friend class TypeAliasDecl; unsigned : NumGenericTypeDeclBits; - /// Whether the underlying type is an interface type that will be lazily - /// resolved to a context type. - unsigned HasInterfaceUnderlyingType : 1; + /// Whether we have completed validation of the typealias. + /// This is necessary because unlike other declarations, a + /// typealias will not get an interface type right away. + unsigned HasCompletedValidation : 1; }; enum { NumTypeAliasDeclBits = NumGenericTypeDeclBits + 1 }; static_assert(NumTypeAliasDeclBits <= 32, "fits in an unsigned"); @@ -2391,60 +2393,38 @@ public: /// TypeAliasDecl's always have 'MetatypeType' type. /// class TypeAliasDecl : public GenericTypeDecl { - /// The type that represents this (sugared) name alias. - mutable NameAliasType *AliasTy; - SourceLoc TypeAliasLoc; // The location of the 'typealias' keyword - mutable TypeLoc UnderlyingTy; - - Type computeUnderlyingContextType() const; + TypeLoc UnderlyingTy; public: TypeAliasDecl(SourceLoc TypeAliasLoc, Identifier Name, - SourceLoc NameLoc, TypeLoc UnderlyingTy, - GenericParamList *GenericParams, DeclContext *DC); + SourceLoc NameLoc, GenericParamList *GenericParams, + DeclContext *DC); SourceLoc getStartLoc() const { return TypeAliasLoc; } SourceRange getSourceRange() const; - /// getUnderlyingType - Returns the underlying type, which is - /// assumed to have been set. - Type getUnderlyingType() const { - if (TypeAliasDeclBits.HasInterfaceUnderlyingType) - return computeUnderlyingContextType(); - - assert(!UnderlyingTy.getType().isNull() && - "getting invalid underlying type"); - return UnderlyingTy.getType(); - } - - /// computeType - Compute the type (and declared type) of this type alias; - /// can only be called after the alias type has been resolved. - void computeType(); - - /// \brief Determine whether this type alias has an underlying type. - bool hasUnderlyingType() const { - return !UnderlyingTy.getType().isNull(); - } - TypeLoc &getUnderlyingTypeLoc() { - if (TypeAliasDeclBits.HasInterfaceUnderlyingType) - (void)computeUnderlyingContextType(); - return UnderlyingTy; } const TypeLoc &getUnderlyingTypeLoc() const { - if (TypeAliasDeclBits.HasInterfaceUnderlyingType) - (void)computeUnderlyingContextType(); - return UnderlyingTy; } - /// Set the underlying type after deserialization. - void setDeserializedUnderlyingType(Type type); + /// Set the underlying type, for deserialization and synthesized + /// aliases. + void setUnderlyingType(Type type); - /// getAliasType - Return the sugared version of this decl as a Type. - NameAliasType *getAliasType() const { return AliasTy; } + bool hasCompletedValidation() const { + return TypeAliasDeclBits.HasCompletedValidation; + } + + void setHasCompletedValidation() { + TypeAliasDeclBits.HasCompletedValidation = 1; + } + + /// For generic typealiases, return the unbound generic type. + UnboundGenericType *getUnboundGenericType() const; static bool classof(const Decl *D) { return D->getKind() == DeclKind::TypeAlias; diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index e3ad921a018..fd7afcc95c5 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -3661,7 +3661,7 @@ static NominalTypeDecl *findUnderlyingTypeInModule(ASTContext &ctx, if (auto typealias = dyn_cast(result)) { if (auto resolver = ctx.getLazyResolver()) resolver->resolveDeclSignature(typealias); - return typealias->getUnderlyingType()->getAnyNominal(); + return typealias->getDeclaredInterfaceType()->getAnyNominal(); } } diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp index abffce441a5..b2e00b7b834 100644 --- a/lib/AST/ASTDumper.cpp +++ b/lib/AST/ASTDumper.cpp @@ -460,8 +460,8 @@ namespace { void visitTypeAliasDecl(TypeAliasDecl *TAD) { printCommon(TAD, "typealias"); OS << " type='"; - if (TAD->hasUnderlyingType()) - OS << TAD->getUnderlyingType().getString(); + if (TAD->getUnderlyingTypeLoc().getType()) + OS << TAD->getUnderlyingTypeLoc().getType().getString(); else OS << "<<>>"; printInherited(TAD->getInherited()); diff --git a/lib/AST/ASTMangler.cpp b/lib/AST/ASTMangler.cpp index c1a225d2a54..73d2f2c3c0d 100644 --- a/lib/AST/ASTMangler.cpp +++ b/lib/AST/ASTMangler.cpp @@ -454,7 +454,7 @@ void ASTMangler::appendType(Type type) { TypeAliasDecl *decl = NameAliasTy->getDecl(); if (decl->getModuleContext() == decl->getASTContext().TheBuiltinModule) { // It's not possible to mangle the context of the builtin module. - return appendType(decl->getUnderlyingType()); + return appendType(decl->getDeclaredInterfaceType()); } // For the DWARF output we want to mangle the type alias + context, diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp index 4dff6376565..b56cd192a80 100644 --- a/lib/AST/ASTPrinter.cpp +++ b/lib/AST/ASTPrinter.cpp @@ -2141,9 +2141,8 @@ void PrintAST::visitTypeAliasDecl(TypeAliasDecl *decl) { printGenericSignature(genericSig, PrintParams | InnermostOnly); }); bool ShouldPrint = true; - Type Ty; - if (decl->hasUnderlyingType()) - Ty = decl->getUnderlyingType(); + Type Ty = decl->getUnderlyingTypeLoc().getType(); + // If the underlying type is private, don't print it. if (Options.SkipPrivateStdlibDecls && Ty && Ty.isPrivateStdlibType()) ShouldPrint = false; diff --git a/lib/AST/ArchetypeBuilder.cpp b/lib/AST/ArchetypeBuilder.cpp index 4b8fef87b72..a3ace11b266 100644 --- a/lib/AST/ArchetypeBuilder.cpp +++ b/lib/AST/ArchetypeBuilder.cpp @@ -413,19 +413,14 @@ auto ArchetypeBuilder::PotentialArchetype::getNestedType( // Resolve this nested type to this type alias. pa = new PotentialArchetype(this, alias); - if (!alias->hasUnderlyingType()) + if (!alias->hasInterfaceType()) builder.getLazyResolver()->resolveDeclSignature(alias); - if (!alias->hasUnderlyingType()) + if (!alias->hasInterfaceType()) continue; - auto type = alias->getUnderlyingType(); + auto type = alias->getDeclaredInterfaceType(); SmallVector identifiers; - // Map the type out of its context. - if (auto genericEnv = alias->getGenericEnvironmentOfContext()) { - type = genericEnv->mapTypeOutOfContext(type); - } - if (auto existingPA = builder.resolveArchetype(type)) { builder.addSameTypeRequirementBetweenArchetypes(pa, existingPA, redundantSource); diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index f2a127da144..53e7555e632 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -622,8 +622,8 @@ ImportKind ImportDecl::getBestImportKind(const ValueDecl *VD) { return ImportKind::Struct; case DeclKind::TypeAlias: { - Type underlyingTy = cast(VD)->getUnderlyingType(); - return getBestImportKind(underlyingTy->getAnyNominal()); + Type type = cast(VD)->getDeclaredInterfaceType(); + return getBestImportKind(type->getAnyNominal()); } case DeclKind::Func: @@ -1907,7 +1907,7 @@ Type TypeDecl::getDeclaredInterfaceType() const { return NTD->getDeclaredInterfaceType(); Type interfaceType = getInterfaceType(); - if (interfaceType.isNull() || interfaceType->hasError()) + if (interfaceType.isNull() || interfaceType->is()) return interfaceType; if (isa(this)) @@ -2191,17 +2191,11 @@ void GenericTypeDecl::setLazyGenericEnvironment(LazyMemberLoader *lazyLoader, } TypeAliasDecl::TypeAliasDecl(SourceLoc TypeAliasLoc, Identifier Name, - SourceLoc NameLoc, TypeLoc UnderlyingTy, - GenericParamList *GenericParams, DeclContext *DC) + SourceLoc NameLoc, GenericParamList *GenericParams, + DeclContext *DC) : GenericTypeDecl(DeclKind::TypeAlias, DC, Name, NameLoc, {}, GenericParams), - AliasTy(nullptr), TypeAliasLoc(TypeAliasLoc), UnderlyingTy(UnderlyingTy) { - TypeAliasDeclBits.HasInterfaceUnderlyingType = false; -} - -void TypeAliasDecl::computeType() { - ASTContext &Ctx = getASTContext(); - assert(!AliasTy && "already called computeType()"); - AliasTy = new (Ctx, AllocationArena::Permanent) NameAliasType(this); + TypeAliasLoc(TypeAliasLoc) { + TypeAliasDeclBits.HasCompletedValidation = false; } SourceRange TypeAliasDecl::getSourceRange() const { @@ -2210,6 +2204,33 @@ SourceRange TypeAliasDecl::getSourceRange() const { return { TypeAliasLoc, getNameLoc() }; } +void TypeAliasDecl::setUnderlyingType(Type underlying) { + setHasCompletedValidation(); + + // lldb creates global typealiases containing archetypes + // sometimes... + if (underlying->hasArchetype() && isGenericContext()) + underlying = mapTypeOutOfContext(underlying); + UnderlyingTy.setType(underlying); + + // Create a NameAliasType which will resolve to the underlying type. + ASTContext &Ctx = getASTContext(); + auto aliasTy = new (Ctx, AllocationArena::Permanent) NameAliasType(this); + aliasTy->setRecursiveProperties(getUnderlyingTypeLoc().getType() + ->getRecursiveProperties()); + + // Set the interface type of this declaration. + setInterfaceType(MetatypeType::get(aliasTy, Ctx)); +} + +UnboundGenericType *TypeAliasDecl::getUnboundGenericType() const { + assert(getGenericParams()); + return UnboundGenericType::get( + const_cast(this), + getDeclContext()->getDeclaredTypeOfContext(), + getASTContext()); +} + Type AbstractTypeParamDecl::getSuperclass() const { auto *dc = getDeclContext(); if (!dc->isValidGenericContext()) @@ -2223,22 +2244,6 @@ Type AbstractTypeParamDecl::getSuperclass() const { return nullptr; } -Type TypeAliasDecl::computeUnderlyingContextType() const { - Type type = UnderlyingTy.getType(); - if (auto genericEnv = getGenericEnvironmentOfContext()) { - type = genericEnv->mapTypeIntoContext(getParentModule(), type); - UnderlyingTy.setType(type); - } - - return type; -} - -void TypeAliasDecl::setDeserializedUnderlyingType(Type underlying) { - UnderlyingTy.setType(underlying); - if (underlying->hasTypeParameter()) - TypeAliasDeclBits.HasInterfaceUnderlyingType = true; -} - ArrayRef AbstractTypeParamDecl::getConformingProtocols() const { auto *dc = getDeclContext(); diff --git a/lib/AST/Mangle.cpp b/lib/AST/Mangle.cpp index dcf23c2dec5..b42001cd89d 100644 --- a/lib/AST/Mangle.cpp +++ b/lib/AST/Mangle.cpp @@ -854,7 +854,7 @@ void Mangler::mangleType(Type type, unsigned uncurryLevel) { TypeAliasDecl *decl = NameAliasTy->getDecl(); if (decl->getModuleContext() == decl->getASTContext().TheBuiltinModule) { // It's not possible to mangle the context of the builtin module. - return mangleType(decl->getUnderlyingType(), uncurryLevel); + return mangleType(NameAliasTy->getSinglyDesugaredType(), uncurryLevel); } Buffer << "a"; diff --git a/lib/AST/Module.cpp b/lib/AST/Module.cpp index 05cef8d02b4..f7cca704b3b 100644 --- a/lib/AST/Module.cpp +++ b/lib/AST/Module.cpp @@ -80,11 +80,9 @@ void BuiltinUnit::LookupCache::lookupValue( if (!Entry) { if (Type Ty = getBuiltinType(Ctx, Name.str())) { auto *TAD = new (Ctx) TypeAliasDecl(SourceLoc(), Name, SourceLoc(), - TypeLoc::withoutLoc(Ty), /*genericparams*/nullptr, const_cast(&M)); - TAD->computeType(); - TAD->setInterfaceType(MetatypeType::get(TAD->getAliasType(), Ctx)); + TAD->setUnderlyingType(Ty); TAD->setAccessibility(Accessibility::Public); Entry = TAD; } diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 630312604d2..339447ed2b7 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -1308,15 +1308,7 @@ TypeBase *ParenType::getSinglyDesugaredType() { } TypeBase *NameAliasType::getSinglyDesugaredType() { - auto *TAD = getDecl(); - - // The type for a generic TypeAliasDecl is an UnboundGenericType. - if (TAD->getGenericParams()) - return UnboundGenericType::get(TAD, - TAD->getDeclContext()->getDeclaredTypeInContext(), - TAD->getASTContext()); - - return getDecl()->getUnderlyingType().getPointer(); + return getDecl()->getUnderlyingTypeLoc().getType().getPointer(); } TypeBase *SyntaxSugarType::getSinglyDesugaredType() { @@ -3436,15 +3428,15 @@ case TypeKind::Id: case TypeKind::NameAlias: { auto alias = cast(base); - auto underlyingTy = alias->getDecl()->getUnderlyingType().transform(fn); - if (!underlyingTy) + auto underlyingTy = Type(alias->getSinglyDesugaredType()); + auto transformedTy = underlyingTy.transform(fn); + if (!transformedTy) return Type(); - if (underlyingTy.getPointer() == - alias->getDecl()->getUnderlyingType().getPointer()) + if (transformedTy.getPointer() == underlyingTy.getPointer()) return *this; - return underlyingTy; + return transformedTy; } case TypeKind::Paren: { diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index f7e13ee24f6..daa8619d246 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -1929,13 +1929,9 @@ namespace { Impl.importSourceLoc(Decl->getLocStart()), Name, Impl.importSourceLoc(Decl->getLocation()), - TypeLoc::withoutLoc( - underlying->getDeclaredInterfaceType()), /*genericparams*/nullptr, DC); - typealias->computeType(); - typealias->setInterfaceType( - MetatypeType::get(typealias->getAliasType(), - Impl.SwiftContext)); + typealias->setUnderlyingType( + underlying->getDeclaredInterfaceType()); Impl.SpecialTypedefNames[Decl->getCanonicalDecl()] = MappedTypeNameKind::DefineAndUse; @@ -1957,13 +1953,9 @@ namespace { Impl.importSourceLoc(Decl->getLocStart()), Name, Impl.importSourceLoc(Decl->getLocation()), - TypeLoc::withoutLoc( - proto->getDeclaredInterfaceType()), /*genericparams*/nullptr, DC); - typealias->computeType(); - typealias->setInterfaceType( - MetatypeType::get(typealias->getAliasType(), - Impl.SwiftContext)); + typealias->setUnderlyingType( + proto->getDeclaredInterfaceType()); Impl.SpecialTypedefNames[Decl->getCanonicalDecl()] = MappedTypeNameKind::DefineAndUse; @@ -2030,12 +2022,8 @@ namespace { Impl.importSourceLoc(Decl->getLocStart()), Name, Loc, - TypeLoc::withoutLoc(SwiftType), /*genericparams*/nullptr, DC); - Result->computeType(); - Result->setInterfaceType( - MetatypeType::get(Result->getAliasType(), - Impl.SwiftContext)); + Result->setUnderlyingType(SwiftType); // Make Objective-C's 'id' unavailable. if (Impl.SwiftContext.LangOpts.EnableObjCInterop && isObjCId(Decl)) { @@ -2302,13 +2290,8 @@ namespace { // public typealias ErrorType auto alias = Impl.createDeclWithClangNode( decl, Accessibility::Public, loc, C.Id_ErrorType, loc, - TypeLoc::withoutLoc( - errorWrapper->getDeclaredInterfaceType()), - /*genericSignature=*/nullptr, enumDecl); - alias->computeType(); - alias->setInterfaceType( - MetatypeType::get(alias->getAliasType(), - Impl.SwiftContext)); + /*genericparams=*/nullptr, enumDecl); + alias->setUnderlyingType(errorWrapper->getDeclaredInterfaceType()); enumDecl->addMember(alias); // Add the 'Code' enum to the error wrapper. @@ -4188,14 +4171,9 @@ namespace { Impl.importSourceLoc(decl->getLocStart()), name, Impl.importSourceLoc(decl->getLocation()), - TypeLoc::withoutLoc(typeDecl->getDeclaredInterfaceType()), /*genericparams=*/nullptr, dc); - typealias->computeType(); - typealias->setInterfaceType( - MetatypeType::get(typealias->getAliasType(), - Impl.SwiftContext)); - + typealias->setUnderlyingType(typeDecl->getDeclaredInterfaceType()); return typealias; } @@ -4430,11 +4408,8 @@ Decl *SwiftDeclConverter::importSwift2TypeAlias(const clang::NamedDecl *decl, decl, Accessibility::Public, Impl.importSourceLoc(decl->getLocStart()), swift2Name.getDeclName().getBaseName(), Impl.importSourceLoc(decl->getLocation()), - TypeLoc::withoutLoc(underlyingType), genericParams, dc); - alias->computeType(); - alias->setInterfaceType( - MetatypeType::get(alias->getAliasType(), - Impl.SwiftContext)); + genericParams, dc); + alias->setUnderlyingType(underlyingType); alias->setGenericEnvironment(genericEnv); // Record that this is the Swift 2 version of this declaration. diff --git a/lib/ClangImporter/ImportType.cpp b/lib/ClangImporter/ImportType.cpp index 252b2b5d18b..b24fbda2f0a 100644 --- a/lib/ClangImporter/ImportType.cpp +++ b/lib/ClangImporter/ImportType.cpp @@ -655,7 +655,8 @@ namespace { break; case MappedTypeNameKind::DefineOnly: if (auto typealias = dyn_cast(decl)) - mappedType = typealias->getUnderlyingType(); + mappedType = typealias->getDeclaredInterfaceType() + ->getDesugaredType(); break; } @@ -2233,7 +2234,7 @@ Type ClangImporter::Implementation::getNamedSwiftType(Module *module, if (auto *nominalDecl = dyn_cast(decl)) return nominalDecl->getDeclaredType(); - return cast(decl)->getAliasType(); + return decl->getDeclaredInterfaceType(); } Type ClangImporter::Implementation::getNamedSwiftType(StringRef moduleName, diff --git a/lib/IDE/CodeCompletion.cpp b/lib/IDE/CodeCompletion.cpp index f621d5530e4..658e8efbf06 100644 --- a/lib/IDE/CodeCompletion.cpp +++ b/lib/IDE/CodeCompletion.cpp @@ -2626,10 +2626,12 @@ public: setClangDeclKeywords(TAD, Pairs, Builder); addLeadingDot(Builder); Builder.addTextChunk(TAD->getName().str()); - if (TAD->hasUnderlyingType() && !TAD->getUnderlyingType()->is()) - addTypeAnnotation(Builder, TAD->getUnderlyingType()); - else { - addTypeAnnotation(Builder, TAD->getAliasType()); + if (TAD->hasInterfaceType()) { + auto underlyingType = TAD->getUnderlyingTypeLoc().getType(); + if (underlyingType->hasError()) + addTypeAnnotation(Builder, TAD->getDeclaredInterfaceType()); + else + addTypeAnnotation(Builder, underlyingType); } } @@ -2871,8 +2873,8 @@ public: if (auto *TAD = dyn_cast(D)) { addTypeAliasRef(TAD, Reason); - addConstructorCallsForType(TAD->getUnderlyingType(), TAD->getName(), - Reason); + auto type = TAD->mapTypeIntoContext(TAD->getUnderlyingTypeLoc().getType()); + addConstructorCallsForType(type, TAD->getName(), Reason); return; } @@ -2940,8 +2942,8 @@ public: if (auto *TAD = dyn_cast(D)) { addTypeAliasRef(TAD, Reason); - addConstructorCallsForType(TAD->getUnderlyingType(), TAD->getName(), - Reason); + auto type = TAD->mapTypeIntoContext(TAD->getDeclaredInterfaceType()); + addConstructorCallsForType(type, TAD->getName(), Reason); return; } diff --git a/lib/IRGen/DebugTypeInfo.cpp b/lib/IRGen/DebugTypeInfo.cpp index ac27b725f82..b64ddfe849a 100644 --- a/lib/IRGen/DebugTypeInfo.cpp +++ b/lib/IRGen/DebugTypeInfo.cpp @@ -68,7 +68,7 @@ DebugTypeInfo::DebugTypeInfo(TypeDecl *Decl, const TypeInfo &Info) : DeclCtx(Decl->getDeclContext()) { // Use the sugared version of the type, if there is one. if (auto AliasDecl = dyn_cast(Decl)) - Type = AliasDecl->getAliasType(); + Type = AliasDecl->getDeclaredInterfaceType().getPointer(); else Type = Decl->getInterfaceType().getPointer(); @@ -81,7 +81,7 @@ DebugTypeInfo::DebugTypeInfo(ValueDecl *Decl, llvm::Type *StorageTy, Size size, align(align) { // Use the sugared version of the type, if there is one. if (auto AliasDecl = dyn_cast(Decl)) - Type = AliasDecl->getAliasType(); + Type = AliasDecl->getDeclaredInterfaceType().getPointer(); else Type = Decl->getInterfaceType().getPointer(); diff --git a/lib/IRGen/IRGenDebugInfo.cpp b/lib/IRGen/IRGenDebugInfo.cpp index 3402a668d11..91cabecf4f5 100644 --- a/lib/IRGen/IRGenDebugInfo.cpp +++ b/lib/IRGen/IRGenDebugInfo.cpp @@ -820,9 +820,8 @@ TypeAliasDecl *IRGenDebugInfo::getMetadataType() { if (!MetadataTypeDecl) { MetadataTypeDecl = new (IGM.Context) TypeAliasDecl( SourceLoc(), IGM.Context.getIdentifier("$swift.type"), SourceLoc(), - TypeLoc::withoutLoc(IGM.Context.TheRawPointerType), /*genericparams*/nullptr, IGM.Context.TheBuiltinModule); - MetadataTypeDecl->computeType(); + MetadataTypeDecl->setUnderlyingType(IGM.Context.TheRawPointerType); } return MetadataTypeDecl; } @@ -1696,7 +1695,7 @@ llvm::DIType *IRGenDebugInfo::createType(DebugTypeInfo DbgTy, auto *NameAliasTy = cast(BaseTy); auto *Decl = NameAliasTy->getDecl(); auto L = getDebugLoc(SM, Decl); - auto AliasedTy = Decl->getUnderlyingType(); + auto AliasedTy = NameAliasTy->getSinglyDesugaredType(); auto File = getOrCreateFile(L.Filename); // For NameAlias types, the DeclContext for the aliasED type is // in the decl of the alias type. diff --git a/lib/Immediate/REPL.cpp b/lib/Immediate/REPL.cpp index 9361f9f1177..5e2c8081386 100644 --- a/lib/Immediate/REPL.cpp +++ b/lib/Immediate/REPL.cpp @@ -1061,7 +1061,9 @@ public: if (auto typeDecl = dyn_cast(result.getValueDecl())) { if (auto typeAliasDecl = dyn_cast(typeDecl)) { - TypeDecl *origTypeDecl = typeAliasDecl->getUnderlyingType() + TypeDecl *origTypeDecl = typeAliasDecl + ->getDeclaredInterfaceType() + ->getDesugaredType() ->getNominalOrBoundGenericNominal(); if (origTypeDecl) { printOrDumpDecl(origTypeDecl, doPrint); diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index a24bee96c40..7aba20e25d9 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -2985,8 +2985,8 @@ parseDeclTypeAlias(Parser::ParseDeclOptions Flags, DeclAttributes &Attributes) { } auto *TAD = new (Context) TypeAliasDecl(TypeAliasLoc, Id, IdLoc, - UnderlyingTy.getPtrOrNull(), genericParams, CurDeclContext); + TAD->getUnderlyingTypeLoc() = UnderlyingTy.getPtrOrNull(); TAD->getAttrs() = Attributes; // Exit the scope introduced for the generic parameters. diff --git a/lib/PrintAsObjC/PrintAsObjC.cpp b/lib/PrintAsObjC/PrintAsObjC.cpp index 6d32de15962..e28c59eed9d 100644 --- a/lib/PrintAsObjC/PrintAsObjC.cpp +++ b/lib/PrintAsObjC/PrintAsObjC.cpp @@ -628,7 +628,7 @@ private: const TypeAliasDecl *TAD = nullptr; while (auto aliasTy = dyn_cast(ty.getPointer())) { TAD = aliasTy->getDecl(); - ty = TAD->getUnderlyingType(); + ty = aliasTy->getSinglyDesugaredType(); } return TAD && TAD->getName() == ID_CFTypeRef && TAD->hasClangNode(); @@ -1125,7 +1125,7 @@ private: return; } - visitPart(alias->getUnderlyingType(), optionalKind); + visitPart(alias->getUnderlyingTypeLoc().getType(), optionalKind); } void maybePrintTagKeyword(const NominalTypeDecl *NTD) { @@ -1898,7 +1898,7 @@ public: } else if (auto TAD = dyn_cast(TD)) { (void)addImport(TD); // Just in case, make sure the underlying type is visible too. - finder.visit(TAD->getUnderlyingType()); + finder.visit(TAD->getUnderlyingTypeLoc().getType()); } else if (addImport(TD)) { return; } else if (auto ED = dyn_cast(TD)) { diff --git a/lib/Sema/CSApply.cpp b/lib/Sema/CSApply.cpp index 87dc4c38d7f..8678c8a0531 100644 --- a/lib/Sema/CSApply.cpp +++ b/lib/Sema/CSApply.cpp @@ -1730,13 +1730,13 @@ namespace { } } if (!MaxIntegerTypeDecl || - !MaxIntegerTypeDecl->hasUnderlyingType() || - !MaxIntegerTypeDecl->getUnderlyingType()->is()) { + !MaxIntegerTypeDecl->hasInterfaceType() || + !MaxIntegerTypeDecl->getDeclaredInterfaceType()->is()) { tc.diagnose(expr->getLoc(), diag::no_MaxBuiltinIntegerType_found); return nullptr; } tc.validateDecl(MaxIntegerTypeDecl); - auto maxType = MaxIntegerTypeDecl->getUnderlyingType(); + auto maxType = MaxIntegerTypeDecl->getUnderlyingTypeLoc().getType(); DeclName initName(tc.Context, tc.Context.Id_init, { tc.Context.Id_integerLiteral }); @@ -1823,13 +1823,13 @@ namespace { MaxFloatTypeDecl = dyn_cast(lookupResults.front()); } if (!MaxFloatTypeDecl || - !MaxFloatTypeDecl->hasUnderlyingType() || - !MaxFloatTypeDecl->getUnderlyingType()->is()) { + !MaxFloatTypeDecl->hasInterfaceType() || + !MaxFloatTypeDecl->getDeclaredInterfaceType()->is()) { tc.diagnose(expr->getLoc(), diag::no_MaxBuiltinFloatType_found); return nullptr; } tc.validateDecl(MaxFloatTypeDecl); - auto maxType = MaxFloatTypeDecl->getUnderlyingType(); + auto maxType = MaxFloatTypeDecl->getUnderlyingTypeLoc().getType(); DeclName initName(tc.Context, tc.Context.Id_init, { tc.Context.Id_floatLiteral }); diff --git a/lib/Sema/CSDiag.cpp b/lib/Sema/CSDiag.cpp index f91be494220..65f16ada767 100644 --- a/lib/Sema/CSDiag.cpp +++ b/lib/Sema/CSDiag.cpp @@ -7072,7 +7072,7 @@ static void noteArchetypeSource(const TypeLoc &loc, ArchetypeType *archetype, if (auto *nominal = dyn_cast(FoundDecl)) type = nominal->getDeclaredType(); else if (auto *typeAlias = dyn_cast(FoundDecl)) - type = typeAlias->getAliasType(); + type = typeAlias->getUnboundGenericType(); else type = FoundDecl->getDeclaredInterfaceType(); tc.diagnose(FoundDecl, diag::archetype_declared_in_type, archetype, type); diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp index 5d8cbdd172b..d1ad8f6852b 100644 --- a/lib/Sema/ConstraintSystem.cpp +++ b/lib/Sema/ConstraintSystem.cpp @@ -1034,7 +1034,7 @@ ConstraintSystem::getTypeOfMemberReference( // protocols. if (auto *alias = dyn_cast(value)) { if (baseObjTy->isExistentialType()) { - auto memberTy = alias->getUnderlyingType(); + auto memberTy = alias->getDeclaredInterfaceType(); auto openedType = FunctionType::get(baseObjTy, memberTy); return { openedType, memberTy }; } diff --git a/lib/Sema/ITCDecl.cpp b/lib/Sema/ITCDecl.cpp index 2bfeced73ad..e049dc627e7 100644 --- a/lib/Sema/ITCDecl.cpp +++ b/lib/Sema/ITCDecl.cpp @@ -307,10 +307,9 @@ void IterativeTypeChecker::processResolveTypeDecl( TypeDecl *typeDecl, UnsatisfiedDependency unsatisfiedDependency) { if (auto typeAliasDecl = dyn_cast(typeDecl)) { - if (typeAliasDecl->getDeclContext()->isModuleScopeContext()) { - // FIXME: This is silly. - if (!typeAliasDecl->getAliasType()) - typeAliasDecl->computeType(); + if (typeAliasDecl->getDeclContext()->isModuleScopeContext() && + typeAliasDecl->getGenericParams() == nullptr) { + typeAliasDecl->setHasCompletedValidation(); TypeResolutionOptions options; if (typeAliasDecl->getFormalAccess() <= Accessibility::FilePrivate) @@ -322,30 +321,12 @@ void IterativeTypeChecker::processResolveTypeDecl( if (TC.validateType(typeAliasDecl->getUnderlyingTypeLoc(), typeAliasDecl, options, &resolver, &unsatisfiedDependency)) { typeAliasDecl->setInvalid(); - typeAliasDecl->setInterfaceType(ErrorType::get(getASTContext())); typeAliasDecl->getUnderlyingTypeLoc().setInvalidType(getASTContext()); } if (typeAliasDecl->getUnderlyingTypeLoc().wasValidated()) { - // We create TypeAliasTypes with invalid underlying types, so we - // need to propagate recursive properties now. - typeAliasDecl->getAliasType()->setRecursiveProperties( - typeAliasDecl->getUnderlyingType()->getRecursiveProperties()); - - // Map the alias type out of context; if it is not dependent, - // we'll keep the sugar. - Type interfaceTy = typeAliasDecl->getAliasType(); - - // lldb creates global typealiases containing archetypes - // sometimes... - if (typeAliasDecl->getUnderlyingType()->hasArchetype() && - typeAliasDecl->isGenericContext()) { - interfaceTy = typeAliasDecl->mapTypeOutOfContext(interfaceTy); - } - - typeAliasDecl->setInterfaceType( - MetatypeType::get(interfaceTy, - typeDecl->getASTContext())); + typeAliasDecl->setUnderlyingType( + typeAliasDecl->getUnderlyingTypeLoc().getType()); } return; diff --git a/lib/Sema/MiscDiagnostics.cpp b/lib/Sema/MiscDiagnostics.cpp index 0a4d7fb968e..e38ed4165c9 100644 --- a/lib/Sema/MiscDiagnostics.cpp +++ b/lib/Sema/MiscDiagnostics.cpp @@ -3931,7 +3931,7 @@ static OmissionTypeName getTypeNameForOmission(Type type) { do { // Look through typealiases. if (auto aliasTy = dyn_cast(type.getPointer())) { - type = aliasTy->getDecl()->getUnderlyingType(); + type = aliasTy->getSinglyDesugaredType(); continue; } diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp index 238a16b808e..706153a86b7 100644 --- a/lib/Sema/TypeCheckDecl.cpp +++ b/lib/Sema/TypeCheckDecl.cpp @@ -3858,44 +3858,26 @@ public: TC.checkDeclAttributesEarly(TAD); TC.computeAccessibility(TAD); if (!IsSecondPass) { - if (!TAD->getAliasType()) + if (!TAD->hasCompletedValidation()) TC.validateDecl(TAD); TypeResolutionOptions options; if (TAD->getFormalAccess() <= Accessibility::FilePrivate) options |= TR_KnownNonCascadingDependency; - if (TAD->getDeclContext()->isModuleScopeContext()) { + if (TAD->getDeclContext()->isModuleScopeContext() && + TAD->getGenericParams() == nullptr) { IterativeTypeChecker ITC(TC); ITC.satisfy(requestResolveTypeDecl(TAD)); } else { bool invalid = false; if (TC.validateType(TAD->getUnderlyingTypeLoc(), TAD, options)) { TAD->setInvalid(); - TAD->setInterfaceType(ErrorType::get(TC.Context)); TAD->getUnderlyingTypeLoc().setInvalidType(TC.Context); invalid = true; } - // We create TypeAliasTypes with invalid underlying types, so we - // need to propagate recursive properties now. - TAD->getAliasType()->setRecursiveProperties( - TAD->getUnderlyingType()->getRecursiveProperties()); - - if (!invalid) { - // Map the alias type out of context; if it is not dependent, - // we'll keep the sugar. - Type interfaceTy = TAD->getAliasType(); - - // lldb creates global typealiases containing archetypes - // sometimes... - if (TAD->getUnderlyingType()->hasArchetype() && - TAD->isGenericContext()) { - interfaceTy = TAD->mapTypeOutOfContext(interfaceTy); - } - - TAD->setInterfaceType(MetatypeType::get(interfaceTy, TC.Context)); - } + TAD->setUnderlyingType(TAD->getUnderlyingTypeLoc().getType()); } } @@ -6930,13 +6912,13 @@ void TypeChecker::validateDecl(ValueDecl *D, bool resolveTypeParams) { auto typeAlias = cast(D); // Compute the declared type. - if (typeAlias->getAliasType()) { + if (typeAlias->hasCompletedValidation()) { - // If we have are recursing into validation and already have a type set... - // but also don't have the underlying type computed, then we are - // recursing into interface validation while checking the body of the - // type. Reject this with a circularity diagnostic. - if (!typeAlias->hasUnderlyingType()) { + // If we have are recursing into validation but also don't have the + // underlying type computed, then we are recursing into interface + // validation while checking the body of the type. Reject this + // with a circularity diagnostic. + if (!typeAlias->hasInterfaceType()) { diagnose(typeAlias->getLoc(), diag::circular_type_alias, typeAlias->getName()); typeAlias->getUnderlyingTypeLoc().setInvalidType(Context); @@ -6945,7 +6927,7 @@ void TypeChecker::validateDecl(ValueDecl *D, bool resolveTypeParams) { } return; } - typeAlias->computeType(); + typeAlias->setHasCompletedValidation(); // Check generic parameters, if needed. validateGenericTypeSignature(typeAlias); diff --git a/lib/Sema/TypeCheckExpr.cpp b/lib/Sema/TypeCheckExpr.cpp index a941797e1c4..709951c6c81 100644 --- a/lib/Sema/TypeCheckExpr.cpp +++ b/lib/Sema/TypeCheckExpr.cpp @@ -656,7 +656,7 @@ static Type lookupDefaultLiteralType(TypeChecker &TC, DeclContext *dc, if (auto *NTD = dyn_cast(TD)) return NTD->getDeclaredType(); - return cast(TD)->getAliasType(); + return cast(TD)->getDeclaredInterfaceType(); } Type TypeChecker::getDefaultType(ProtocolDecl *protocol, DeclContext *dc) { @@ -759,7 +759,7 @@ Type TypeChecker::getDefaultType(ProtocolDecl *protocol, DeclContext *dc) { // the name of the typealias itself anywhere. if (type && *type) { if (auto typeAlias = dyn_cast(type->getPointer())) - *type = typeAlias->getDecl()->getUnderlyingType(); + *type = typeAlias->getSinglyDesugaredType(); } } diff --git a/lib/Sema/TypeCheckGeneric.cpp b/lib/Sema/TypeCheckGeneric.cpp index c4b60fbeb50..ed46d8f6055 100644 --- a/lib/Sema/TypeCheckGeneric.cpp +++ b/lib/Sema/TypeCheckGeneric.cpp @@ -114,18 +114,17 @@ Type GenericTypeToArchetypeResolver::resolveTypeOfContext(DeclContext *dc) { } Type GenericTypeToArchetypeResolver::resolveTypeOfDecl(TypeDecl *decl) { + auto *dc = decl->getDeclContext(); + // Hack for 'out of context' GenericTypeParamDecls when resolving // a generic typealias if (auto *paramDecl = dyn_cast(decl)) { - return decl->getDeclContext()->getGenericEnvironmentOfContext() - ->mapTypeIntoContext(paramDecl->getDeclaredInterfaceType() - ->castTo()); + return dc->mapTypeIntoContext(paramDecl->getDeclaredInterfaceType()); } - auto *aliasDecl = cast(decl); - if (aliasDecl->isInvalid()) - return ErrorType::get(aliasDecl->getASTContext()); - return aliasDecl->getAliasType(); + return ArchetypeBuilder::mapTypeIntoContext( + dc->getParentModule(), GenericEnv, + decl->getDeclaredInterfaceType()); } void GenericTypeToArchetypeResolver::recordParamType(ParamDecl *decl, Type type) { diff --git a/lib/Sema/TypeCheckProtocol.cpp b/lib/Sema/TypeCheckProtocol.cpp index cef80509624..9a9ab189e84 100644 --- a/lib/Sema/TypeCheckProtocol.cpp +++ b/lib/Sema/TypeCheckProtocol.cpp @@ -2260,17 +2260,10 @@ void ConformanceChecker::recordTypeWitness(AssociatedTypeDecl *assocType, auto aliasDecl = new (TC.Context) TypeAliasDecl(SourceLoc(), assocType->getName(), SourceLoc(), - TypeLoc::withoutLoc(type), /*genericparams*/nullptr, DC); aliasDecl->setGenericEnvironment(DC->getGenericEnvironmentOfContext()); - aliasDecl->computeType(); - - aliasDecl->getAliasType()->setRecursiveProperties( - type->getRecursiveProperties()); - - auto interfaceTy = DC->mapTypeOutOfContext(aliasDecl->getAliasType()); - aliasDecl->setInterfaceType(MetatypeType::get(interfaceTy)); + aliasDecl->setUnderlyingType(type); aliasDecl->setImplicit(); if (type->hasError()) diff --git a/lib/Sema/TypeCheckType.cpp b/lib/Sema/TypeCheckType.cpp index 86b1874c363..7d185912fcd 100644 --- a/lib/Sema/TypeCheckType.cpp +++ b/lib/Sema/TypeCheckType.cpp @@ -379,8 +379,13 @@ Type TypeChecker::resolveTypeInContext( // If this is a typealias not in type context, we still need the // interface type; the typealias might be in a function context, and // its underlying type might reference outer generic parameters. - if (isa(typeDecl)) - return resolver->resolveTypeOfDecl(typeDecl); + if (auto *aliasDecl = dyn_cast(typeDecl)) { + // For a generic typealias, return the unbound generic form of the type. + if (aliasDecl->getGenericParams()) + return aliasDecl->getUnboundGenericType(); + + return resolver->resolveTypeOfDecl(aliasDecl); + } // When a nominal type used outside its context, return the unbound // generic form of the type. @@ -614,9 +619,19 @@ Type TypeChecker::applyUnboundGenericArguments( } // FIXME: Change callers to pass the right type in for generic typealiases - if (type->is() || isa(type.getPointer())) { - type = ArchetypeBuilder::mapTypeOutOfContext(TAD, TAD->getUnderlyingType()); - } + if (type->is() || isa(type.getPointer())) + type = TAD->getDeclaredInterfaceType(); + + // When resolving a generic typealias with a base type, we have a partially + // substituted type by now. Put the archetypes in the substitution map so that + // the subst() call leaves them alone. + // + // FIXME: Combine base type substitution step with applying generic arguments + // to avoid this gross hack. + type.visit([&](Type t) { + if (auto *archetype = t->getAs()) + subs[archetype] = archetype; + }); return type.subst(dc->getParentModule(), subs, SubstFlags::UseErrorType); } @@ -3731,9 +3746,9 @@ public: T->setInvalid(); } } else if (auto alias = dyn_cast_or_null(comp->getBoundDecl())) { - if (!alias->hasUnderlyingType()) + if (!alias->hasInterfaceType()) return; - auto type = alias->getUnderlyingType(); + auto type = Type(alias->getDeclaredInterfaceType()->getDesugaredType()); type.findIf([&](Type type) -> bool { if (T->isInvalid()) return false; diff --git a/lib/Sema/TypeChecker.cpp b/lib/Sema/TypeChecker.cpp index d42d9b68bd8..de67370dc41 100644 --- a/lib/Sema/TypeChecker.cpp +++ b/lib/Sema/TypeChecker.cpp @@ -326,7 +326,7 @@ static void bindExtensionDecl(ExtensionDecl *ED, TypeChecker &TC) { // Hack to allow extending a generic typealias. if (auto *unboundGeneric = extendedType->getAs()) { if (auto *aliasDecl = dyn_cast(unboundGeneric->getDecl())) { - extendedType = aliasDecl->getUnderlyingType()->getAnyNominal() + extendedType = aliasDecl->getDeclaredInterfaceType()->getAnyNominal() ->getDeclaredType(); ED->getExtendedTypeLoc().setType(extendedType); } diff --git a/lib/Serialization/Deserialization.cpp b/lib/Serialization/Deserialization.cpp index 47692bf940a..89ebc40d6f8 100644 --- a/lib/Serialization/Deserialization.cpp +++ b/lib/Serialization/Deserialization.cpp @@ -2321,16 +2321,17 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional ForcedContext) { return declOrOffset; auto alias = createDecl(SourceLoc(), getIdentifier(nameID), - SourceLoc(), TypeLoc(), - genericParams, DC); + SourceLoc(), genericParams, DC); declOrOffset = alias; + // FIXME: Do we need to read a GenericEnvironment even if we don't + // have our own generic parameters? The typealias might itself be in + // generic context. if (genericParams) { readLazyGenericEnvironment(alias); } - alias->setDeserializedUnderlyingType(getType(underlyingTypeID)); - alias->computeType(); + alias->setUnderlyingType(getType(underlyingTypeID)); if (auto accessLevel = getActualAccessibility(rawAccessLevel)) { alias->setAccessibility(*accessLevel); @@ -3505,7 +3506,7 @@ Type ModuleFile::getType(TypeID TID) { return nullptr; } - typeOrOffset = alias->getAliasType(); + typeOrOffset = alias->getDeclaredInterfaceType(); break; } diff --git a/lib/Serialization/Serialization.cpp b/lib/Serialization/Serialization.cpp index 4868e0a86ae..3f6f16de620 100644 --- a/lib/Serialization/Serialization.cpp +++ b/lib/Serialization/Serialization.cpp @@ -2355,14 +2355,7 @@ void Serializer::writeDecl(const Decl *D) { auto contextID = addDeclContextRef(typeAlias->getDeclContext()); - Type underlying; - if (typeAlias->hasUnderlyingType()) { - underlying = typeAlias->getUnderlyingType(); - if (underlying->hasArchetype()) { - auto genericEnv = typeAlias->getGenericEnvironmentOfContext(); - underlying = genericEnv->mapTypeOutOfContext(underlying); - } - } + auto underlying = typeAlias->getUnderlyingTypeLoc().getType(); uint8_t rawAccessLevel = getRawStableAccessibility(typeAlias->getFormalAccess()); diff --git a/test/api-digester/source-stability.swift.expected b/test/api-digester/source-stability.swift.expected index a013e70e6ba..bca9f109aec 100644 --- a/test/api-digester/source-stability.swift.expected +++ b/test/api-digester/source-stability.swift.expected @@ -1,8 +1,4 @@ -/* DictionaryIndex => Dictionary.Index, - * SetIndex => Set.Index - * - * Note: The old names are still available via generic typealiases, - * however swift-api-digester doesn't pick that up yet. */ +/* FIXME: Bogus */ TypeAlias Dictionary.Index has been removed TypeAlias Set.Index has been removed Struct DictionaryIndex has been removed @@ -17,27 +13,176 @@ Protocol MutableIndexable has been removed (deprecated) Protocol RandomAccessIndexable has been removed (deprecated) Protocol RangeReplaceableIndexable has been removed (deprecated) -/* More DictionaryIndex / SetIndex */ +/* FIXME: Bogus */ Var Dictionary.endIndex has declared type change from DictionaryIndex to Dictionary.Index Var Dictionary.startIndex has declared type change from DictionaryIndex to Dictionary.Index Var Set.endIndex has declared type change from SetIndex to Set.Index Var Set.startIndex has declared type change from SetIndex to Set.Index +Constructor BidirectionalSlice.init(base:bounds:) has 2nd parameter type change from Range to Range +Constructor MutableBidirectionalSlice.init(base:bounds:) has 2nd parameter type change from Range to Range +Constructor MutableRandomAccessSlice.init(base:bounds:) has 2nd parameter type change from Range to Range +Constructor MutableRangeReplaceableBidirectionalSlice.init(base:bounds:) has 2nd parameter type change from Range to Range +Constructor MutableRangeReplaceableRandomAccessSlice.init(base:bounds:) has 2nd parameter type change from Range to Range +Constructor MutableRangeReplaceableSlice.init(base:bounds:) has 2nd parameter type change from Range to Range +Constructor MutableSlice.init(base:bounds:) has 2nd parameter type change from Range to Range +Constructor RandomAccessSlice.init(base:bounds:) has 2nd parameter type change from Range to Range +Constructor RangeReplaceableBidirectionalSlice.init(base:bounds:) has 2nd parameter type change from Range to Range +Constructor RangeReplaceableRandomAccessSlice.init(base:bounds:) has 2nd parameter type change from Range to Range +Constructor RangeReplaceableSlice.init(base:bounds:) has 2nd parameter type change from Range to Range +Constructor Slice.init(base:bounds:) has 2nd parameter type change from Range to Range +Func BidirectionalSlice.distance(from:to:) has return type change from Base.IndexDistance to BidirectionalSlice.IndexDistance +Func BidirectionalSlice.index(_:offsetBy:) has return type change from Base.Index to BidirectionalSlice.Index +Func BidirectionalSlice.index(_:offsetBy:limitedBy:) has return type change from Base.Index? to BidirectionalSlice.Index? +Func BidirectionalSlice.index(after:) has return type change from Base.Index to BidirectionalSlice.Index +Func BidirectionalSlice.index(before:) has return type change from Base.Index to BidirectionalSlice.Index +Func CountableClosedRange.distance(from:to:) has return type change from Bound.Stride to CountableClosedRange.IndexDistance +Func CountableClosedRange.index(_:offsetBy:) has return type change from ClosedRangeIndex to CountableClosedRange.Index +Func CountableClosedRange.index(after:) has return type change from ClosedRangeIndex to CountableClosedRange.Index +Func CountableClosedRange.index(before:) has return type change from ClosedRangeIndex to CountableClosedRange.Index +Func CountableRange.distance(from:to:) has return type change from Bound.Stride to CountableRange.IndexDistance +Func CountableRange.index(_:offsetBy:) has 2nd parameter type change from Bound.Stride to CountableRange.IndexDistance +Func DefaultBidirectionalIndices.index(after:) has return type change from Elements.Index to DefaultBidirectionalIndices.Index +Func DefaultBidirectionalIndices.index(before:) has return type change from Elements.Index to DefaultBidirectionalIndices.Index +Func DefaultIndices.index(after:) has return type change from Elements.Index to DefaultIndices.Index +Func DefaultRandomAccessIndices.index(after:) has return type change from Elements.Index to DefaultRandomAccessIndices.Index +Func DefaultRandomAccessIndices.index(before:) has return type change from Elements.Index to DefaultRandomAccessIndices.Index Func Dictionary.index(after:) has return type change from DictionaryIndex to Dictionary.Index Func Dictionary.index(forKey:) has return type change from DictionaryIndex? to Dictionary.Index? -Func Dictionary.remove(at:) has 1st parameter type change from DictionaryIndex to Dictionary.Index - -/* False positives due to archetype -> interface type change */ +Func Dictionary.popFirst() has return type change from (key: Key, value: Value)? to Dictionary.Element? +Func Dictionary.remove(at:) has return type change from (key: Key, value: Value) to Dictionary.Element +Func EnumeratedIterator.next() has return type change from (offset: Int, element: Base.Element)? to EnumeratedIterator.Element? +Func FlattenBidirectionalCollection.index(after:) has return type change from FlattenBidirectionalCollectionIndex to FlattenBidirectionalCollection.Index +Func FlattenBidirectionalCollection.index(before:) has return type change from FlattenBidirectionalCollectionIndex to FlattenBidirectionalCollection.Index +Func FlattenCollection.index(after:) has return type change from FlattenCollectionIndex to FlattenCollection.Index +Func LazyBidirectionalCollection.distance(from:to:) has 1st parameter type change from Base.Index to LazyBidirectionalCollection.Index +Func LazyBidirectionalCollection.index(_:offsetBy:) has return type change from Base.Index to LazyBidirectionalCollection.Index +Func LazyBidirectionalCollection.index(_:offsetBy:limitedBy:) has return type change from Base.Index? to LazyBidirectionalCollection.Index? +Func LazyCollection.distance(from:to:) has 1st parameter type change from Base.Index to LazyCollection.Index +Func LazyCollection.index(_:offsetBy:) has return type change from Base.Index to LazyCollection.Index +Func LazyCollection.index(_:offsetBy:limitedBy:) has return type change from Base.Index? to LazyCollection.Index? +Func LazyFilterBidirectionalCollection.index(after:) has return type change from LazyFilterIndex to LazyFilterBidirectionalCollection.Index +Func LazyFilterBidirectionalCollection.index(before:) has return type change from LazyFilterIndex to LazyFilterBidirectionalCollection.Index +Func LazyFilterCollection.index(after:) has return type change from LazyFilterIndex to LazyFilterCollection.Index +Func LazyMapBidirectionalCollection.distance(from:to:) has 1st parameter type change from Base.Index to LazyMapBidirectionalCollection.Index +Func LazyMapBidirectionalCollection.index(_:offsetBy:) has return type change from Base.Index to LazyMapBidirectionalCollection.Index +Func LazyMapBidirectionalCollection.index(_:offsetBy:limitedBy:) has return type change from Base.Index? to LazyMapBidirectionalCollection.Index? +Func LazyMapBidirectionalCollection.index(after:) has return type change from Base.Index to LazyMapBidirectionalCollection.Index +Func LazyMapBidirectionalCollection.index(before:) has return type change from Base.Index to LazyMapBidirectionalCollection.Index +Func LazyMapCollection.distance(from:to:) has 1st parameter type change from Base.Index to LazyMapCollection.Index +Func LazyMapCollection.index(_:offsetBy:) has return type change from Base.Index to LazyMapCollection.Index +Func LazyMapCollection.index(_:offsetBy:limitedBy:) has return type change from Base.Index? to LazyMapCollection.Index? +Func LazyMapCollection.index(after:) has return type change from Base.Index to LazyMapCollection.Index +Func LazyMapRandomAccessCollection.distance(from:to:) has 1st parameter type change from Base.Index to LazyMapRandomAccessCollection.Index +Func LazyMapRandomAccessCollection.index(_:offsetBy:) has return type change from Base.Index to LazyMapRandomAccessCollection.Index +Func LazyMapRandomAccessCollection.index(_:offsetBy:limitedBy:) has return type change from Base.Index? to LazyMapRandomAccessCollection.Index? +Func LazyMapRandomAccessCollection.index(after:) has return type change from Base.Index to LazyMapRandomAccessCollection.Index +Func LazyMapRandomAccessCollection.index(before:) has return type change from Base.Index to LazyMapRandomAccessCollection.Index +Func LazyRandomAccessCollection.distance(from:to:) has 1st parameter type change from Base.Index to LazyRandomAccessCollection.Index +Func LazyRandomAccessCollection.index(_:offsetBy:) has return type change from Base.Index to LazyRandomAccessCollection.Index +Func LazyRandomAccessCollection.index(_:offsetBy:limitedBy:) has return type change from Base.Index? to LazyRandomAccessCollection.Index? +Func MutableBidirectionalSlice.distance(from:to:) has return type change from Base.IndexDistance to MutableBidirectionalSlice.IndexDistance +Func MutableBidirectionalSlice.index(_:offsetBy:) has return type change from Base.Index to MutableBidirectionalSlice.Index +Func MutableBidirectionalSlice.index(_:offsetBy:limitedBy:) has return type change from Base.Index? to MutableBidirectionalSlice.Index? +Func MutableBidirectionalSlice.index(after:) has return type change from Base.Index to MutableBidirectionalSlice.Index +Func MutableBidirectionalSlice.index(before:) has return type change from Base.Index to MutableBidirectionalSlice.Index +Func MutableRandomAccessSlice.distance(from:to:) has return type change from Base.IndexDistance to MutableRandomAccessSlice.IndexDistance +Func MutableRandomAccessSlice.index(_:offsetBy:) has return type change from Base.Index to MutableRandomAccessSlice.Index +Func MutableRandomAccessSlice.index(_:offsetBy:limitedBy:) has return type change from Base.Index? to MutableRandomAccessSlice.Index? +Func MutableRandomAccessSlice.index(after:) has return type change from Base.Index to MutableRandomAccessSlice.Index +Func MutableRandomAccessSlice.index(before:) has return type change from Base.Index to MutableRandomAccessSlice.Index +Func MutableRangeReplaceableBidirectionalSlice.distance(from:to:) has return type change from Base.IndexDistance to MutableRangeReplaceableBidirectionalSlice.IndexDistance +Func MutableRangeReplaceableBidirectionalSlice.index(_:offsetBy:) has return type change from Base.Index to MutableRangeReplaceableBidirectionalSlice.Index +Func MutableRangeReplaceableBidirectionalSlice.index(_:offsetBy:limitedBy:) has return type change from Base.Index? to MutableRangeReplaceableBidirectionalSlice.Index? +Func MutableRangeReplaceableBidirectionalSlice.index(after:) has return type change from Base.Index to MutableRangeReplaceableBidirectionalSlice.Index +Func MutableRangeReplaceableBidirectionalSlice.index(before:) has return type change from Base.Index to MutableRangeReplaceableBidirectionalSlice.Index +Func MutableRangeReplaceableBidirectionalSlice.insert(_:at:) has 2nd parameter type change from Base.Index to MutableRangeReplaceableBidirectionalSlice.Index +Func MutableRangeReplaceableBidirectionalSlice.insert(contentsOf:at:) has 2nd parameter type change from Base.Index to MutableRangeReplaceableBidirectionalSlice.Index +Func MutableRangeReplaceableBidirectionalSlice.remove(at:) has 1st parameter type change from Base.Index to MutableRangeReplaceableBidirectionalSlice.Index +Func MutableRangeReplaceableBidirectionalSlice.removeSubrange(_:) has 1st parameter type change from Range to Range +Func MutableRangeReplaceableBidirectionalSlice.replaceSubrange(_:with:) has 1st parameter type change from Range to Range +Func MutableRangeReplaceableRandomAccessSlice.distance(from:to:) has return type change from Base.IndexDistance to MutableRangeReplaceableRandomAccessSlice.IndexDistance +Func MutableRangeReplaceableRandomAccessSlice.index(_:offsetBy:) has return type change from Base.Index to MutableRangeReplaceableRandomAccessSlice.Index +Func MutableRangeReplaceableRandomAccessSlice.index(_:offsetBy:limitedBy:) has return type change from Base.Index? to MutableRangeReplaceableRandomAccessSlice.Index? +Func MutableRangeReplaceableRandomAccessSlice.index(after:) has return type change from Base.Index to MutableRangeReplaceableRandomAccessSlice.Index +Func MutableRangeReplaceableRandomAccessSlice.index(before:) has return type change from Base.Index to MutableRangeReplaceableRandomAccessSlice.Index +Func MutableRangeReplaceableRandomAccessSlice.insert(_:at:) has 2nd parameter type change from Base.Index to MutableRangeReplaceableRandomAccessSlice.Index +Func MutableRangeReplaceableRandomAccessSlice.insert(contentsOf:at:) has 2nd parameter type change from Base.Index to MutableRangeReplaceableRandomAccessSlice.Index +Func MutableRangeReplaceableRandomAccessSlice.remove(at:) has 1st parameter type change from Base.Index to MutableRangeReplaceableRandomAccessSlice.Index +Func MutableRangeReplaceableRandomAccessSlice.removeSubrange(_:) has 1st parameter type change from Range to Range +Func MutableRangeReplaceableRandomAccessSlice.replaceSubrange(_:with:) has 1st parameter type change from Range to Range +Func MutableRangeReplaceableSlice.distance(from:to:) has return type change from Base.IndexDistance to MutableRangeReplaceableSlice.IndexDistance +Func MutableRangeReplaceableSlice.index(_:offsetBy:) has return type change from Base.Index to MutableRangeReplaceableSlice.Index +Func MutableRangeReplaceableSlice.index(_:offsetBy:limitedBy:) has return type change from Base.Index? to MutableRangeReplaceableSlice.Index? +Func MutableRangeReplaceableSlice.index(after:) has return type change from Base.Index to MutableRangeReplaceableSlice.Index +Func MutableRangeReplaceableSlice.insert(_:at:) has 2nd parameter type change from Base.Index to MutableRangeReplaceableSlice.Index +Func MutableRangeReplaceableSlice.insert(contentsOf:at:) has 2nd parameter type change from Base.Index to MutableRangeReplaceableSlice.Index +Func MutableRangeReplaceableSlice.remove(at:) has 1st parameter type change from Base.Index to MutableRangeReplaceableSlice.Index +Func MutableRangeReplaceableSlice.removeSubrange(_:) has 1st parameter type change from Range to Range +Func MutableRangeReplaceableSlice.replaceSubrange(_:with:) has 1st parameter type change from Range to Range +Func MutableSlice.distance(from:to:) has return type change from Base.IndexDistance to MutableSlice.IndexDistance +Func MutableSlice.index(_:offsetBy:) has return type change from Base.Index to MutableSlice.Index +Func MutableSlice.index(_:offsetBy:limitedBy:) has return type change from Base.Index? to MutableSlice.Index? +Func MutableSlice.index(after:) has return type change from Base.Index to MutableSlice.Index Func OptionSet.insert(_:) has return type change from (inserted: Bool, memberAfterInsert: Self) to (inserted: Bool, memberAfterInsert: Self.Element) Func OptionSet.remove(_:) has return type change from Self? to Self.Element? Func OptionSet.update(with:) has return type change from Self? to Self.Element? Func RandomAccessCollection.distance(from:to:) has return type change from Self.IndexDistance to Self.Index.Stride Func RandomAccessCollection.index(_:offsetBy:) has 2nd parameter type change from Self.IndexDistance to Self.Index.Stride - -/* More DictionaryIndex / SetIndex */ +Func RandomAccessSlice.distance(from:to:) has return type change from Base.IndexDistance to RandomAccessSlice.IndexDistance +Func RandomAccessSlice.index(_:offsetBy:) has return type change from Base.Index to RandomAccessSlice.Index +Func RandomAccessSlice.index(_:offsetBy:limitedBy:) has return type change from Base.Index? to RandomAccessSlice.Index? +Func RandomAccessSlice.index(after:) has return type change from Base.Index to RandomAccessSlice.Index +Func RandomAccessSlice.index(before:) has return type change from Base.Index to RandomAccessSlice.Index +Func RangeReplaceableBidirectionalSlice.distance(from:to:) has return type change from Base.IndexDistance to RangeReplaceableBidirectionalSlice.IndexDistance +Func RangeReplaceableBidirectionalSlice.index(_:offsetBy:) has return type change from Base.Index to RangeReplaceableBidirectionalSlice.Index +Func RangeReplaceableBidirectionalSlice.index(_:offsetBy:limitedBy:) has return type change from Base.Index? to RangeReplaceableBidirectionalSlice.Index? +Func RangeReplaceableBidirectionalSlice.index(after:) has return type change from Base.Index to RangeReplaceableBidirectionalSlice.Index +Func RangeReplaceableBidirectionalSlice.index(before:) has return type change from Base.Index to RangeReplaceableBidirectionalSlice.Index +Func RangeReplaceableBidirectionalSlice.insert(_:at:) has 2nd parameter type change from Base.Index to RangeReplaceableBidirectionalSlice.Index +Func RangeReplaceableBidirectionalSlice.insert(contentsOf:at:) has 2nd parameter type change from Base.Index to RangeReplaceableBidirectionalSlice.Index +Func RangeReplaceableBidirectionalSlice.remove(at:) has 1st parameter type change from Base.Index to RangeReplaceableBidirectionalSlice.Index +Func RangeReplaceableBidirectionalSlice.removeSubrange(_:) has 1st parameter type change from Range to Range +Func RangeReplaceableBidirectionalSlice.replaceSubrange(_:with:) has 1st parameter type change from Range to Range +Func RangeReplaceableRandomAccessSlice.distance(from:to:) has return type change from Base.IndexDistance to RangeReplaceableRandomAccessSlice.IndexDistance +Func RangeReplaceableRandomAccessSlice.index(_:offsetBy:) has return type change from Base.Index to RangeReplaceableRandomAccessSlice.Index +Func RangeReplaceableRandomAccessSlice.index(_:offsetBy:limitedBy:) has return type change from Base.Index? to RangeReplaceableRandomAccessSlice.Index? +Func RangeReplaceableRandomAccessSlice.index(after:) has return type change from Base.Index to RangeReplaceableRandomAccessSlice.Index +Func RangeReplaceableRandomAccessSlice.index(before:) has return type change from Base.Index to RangeReplaceableRandomAccessSlice.Index +Func RangeReplaceableRandomAccessSlice.insert(_:at:) has 2nd parameter type change from Base.Index to RangeReplaceableRandomAccessSlice.Index +Func RangeReplaceableRandomAccessSlice.insert(contentsOf:at:) has 2nd parameter type change from Base.Index to RangeReplaceableRandomAccessSlice.Index +Func RangeReplaceableRandomAccessSlice.remove(at:) has 1st parameter type change from Base.Index to RangeReplaceableRandomAccessSlice.Index +Func RangeReplaceableRandomAccessSlice.removeSubrange(_:) has 1st parameter type change from Range to Range +Func RangeReplaceableRandomAccessSlice.replaceSubrange(_:with:) has 1st parameter type change from Range to Range +Func RangeReplaceableSlice.distance(from:to:) has return type change from Base.IndexDistance to RangeReplaceableSlice.IndexDistance +Func RangeReplaceableSlice.index(_:offsetBy:) has return type change from Base.Index to RangeReplaceableSlice.Index +Func RangeReplaceableSlice.index(_:offsetBy:limitedBy:) has return type change from Base.Index? to RangeReplaceableSlice.Index? +Func RangeReplaceableSlice.index(after:) has return type change from Base.Index to RangeReplaceableSlice.Index +Func RangeReplaceableSlice.insert(_:at:) has 2nd parameter type change from Base.Index to RangeReplaceableSlice.Index +Func RangeReplaceableSlice.insert(contentsOf:at:) has 2nd parameter type change from Base.Index to RangeReplaceableSlice.Index +Func RangeReplaceableSlice.remove(at:) has 1st parameter type change from Base.Index to RangeReplaceableSlice.Index +Func RangeReplaceableSlice.removeSubrange(_:) has 1st parameter type change from Range to Range +Func RangeReplaceableSlice.replaceSubrange(_:with:) has 1st parameter type change from Range to Range +Func ReversedCollection.distance(from:to:) has return type change from Base.IndexDistance to ReversedCollection.IndexDistance +Func ReversedCollection.index(_:offsetBy:) has return type change from ReversedIndex to ReversedCollection.Index +Func ReversedCollection.index(_:offsetBy:limitedBy:) has return type change from ReversedIndex? to ReversedCollection.Index? +Func ReversedCollection.index(after:) has return type change from ReversedIndex to ReversedCollection.Index +Func ReversedCollection.index(before:) has return type change from ReversedIndex to ReversedCollection.Index +Func ReversedRandomAccessCollection.distance(from:to:) has return type change from Base.IndexDistance to ReversedRandomAccessCollection.IndexDistance +Func ReversedRandomAccessCollection.index(_:offsetBy:) has return type change from ReversedRandomAccessIndex to ReversedRandomAccessCollection.Index +Func ReversedRandomAccessCollection.index(_:offsetBy:limitedBy:) has return type change from ReversedRandomAccessIndex? to ReversedRandomAccessCollection.Index? +Func ReversedRandomAccessCollection.index(after:) has return type change from ReversedRandomAccessIndex to ReversedRandomAccessCollection.Index +Func ReversedRandomAccessCollection.index(before:) has return type change from ReversedRandomAccessIndex to ReversedRandomAccessCollection.Index Func Set.index(after:) has return type change from SetIndex to Set.Index Func Set.index(of:) has return type change from SetIndex? to Set.Index? Func Set.remove(at:) has 1st parameter type change from SetIndex to Set.Index +Func Slice.distance(from:to:) has return type change from Base.IndexDistance to Slice.IndexDistance +Func Slice.index(_:offsetBy:) has return type change from Base.Index to Slice.Index +Func Slice.index(_:offsetBy:limitedBy:) has return type change from Base.Index? to Slice.Index? +Func Slice.index(after:) has return type change from Base.Index to Slice.Index /* Function type change */ Func UnsafePointer.withMemoryRebound(to:capacity:_:) has 3rd parameter type change from (UnsafeMutablePointer) throws -> Result to (UnsafePointer) throws -> Result +/* FIXME: Bogus */ +Func Zip2Iterator.next() has return type change from (Iterator1.Element, Iterator2.Element)? to Zip2Iterator.Element? +Func Zip2Sequence.makeIterator() has return type change from Zip2Iterator to Zip2Sequence.Iterator diff --git a/test/decl/typealias/generic.swift b/test/decl/typealias/generic.swift index 8ccdb9fa0b3..7186c1e5c7d 100644 --- a/test/decl/typealias/generic.swift +++ b/test/decl/typealias/generic.swift @@ -123,7 +123,7 @@ func f(a : MyTypeWithHashable) { class GenericClass { typealias TA = MyType typealias TAI = MyType - + func testCapture(s: S, t: T) -> TA { return TA(a: t, b: s) } @@ -213,11 +213,61 @@ func takesSugaredType1(m: ConcreteClass.TA) { let _ = ConcreteStruct.O(123) let _ = ConcreteStruct.O(123) +let _: ConcreteStruct.O = ConcreteStruct.O(123) +let _: ConcreteStruct.O = ConcreteStruct.O(123) + +let _: ConcreteStruct.O = ConcreteStruct.O(123) +let _: ConcreteStruct.O = ConcreteStruct.O(123) + // Qualified lookup of generic typealiases nested inside generic contexts -// FIXME: Something is wrong with SpecializeExpr here -let _ = GenericClass.TA(a: 4.0, b: 1) // expected-error {{'Int' is not convertible to 'Float'}} -let _ = GenericClass.TA(a: 1, b: 4.0) // expected-error {{'Int' is not convertible to 'Float'}} +let _ = GenericClass.TA(a: 4.0, b: 1) // FIXME +let _ = GenericClass.TA(a: 1, b: 4.0) + +let _ = GenericClass.TA(a: 4.0, b: 1) // expected-error {{cannot invoke value of type 'MyType.Type' with argument list '(a: Double, b: Int)'}} +let _ = GenericClass.TA(a: 1, b: 4.0) + +let _ = GenericClass.TA(a: 4.0, b: 1) // expected-error {{'Int' is not convertible to 'Float'}} +let _ = GenericClass.TA(a: 1, b: 4.0) // FIXME // expected-error {{'Int' is not convertible to 'Float'}} + +// FIXME: Crashes +#if false +let _: GenericClass.TA = GenericClass.TA(a: 4.0, b: 1) +let _: GenericClass.TA = GenericClass.TA(a: 1, b: 4.0) + +let _: GenericClass.TA = GenericClass.TA(a: 4.0, b: 1) +let _: GenericClass.TA = GenericClass.TA(a: 1, b: 4.0) + +let _: GenericClass.TA = GenericClass.TA(a: 4.0, b: 1) +let _: GenericClass.TA = GenericClass.TA(a: 1, b: 4.0) + +let _: GenericClass.TA = GenericClass.TA(a: 4.0, b: 1) +let _: GenericClass.TA = GenericClass.TA(a: 1, b: 4.0) +#endif + +let _: GenericClass.TA = GenericClass.TA(a: 4.0, b: 1) // expected-error {{cannot invoke value of type 'MyType<_, _>.Type' with argument list '(a: Double, b: Int)'}} +let _: GenericClass.TA = GenericClass.TA(a: 1, b: 4.0) + +let _: GenericClass.TA = GenericClass.TA(a: 4.0, b: 1) // expected-error {{cannot invoke value of type 'MyType.Type' with argument list '(a: Double, b: Int)'}} +let _: GenericClass.TA = GenericClass.TA(a: 1, b: 4.0) // FIXME // expected-error {{cannot invoke value of type 'MyType.Type' with argument list '(a: Int, b: Double)'}} + +let _: GenericClass.TA = GenericClass.TA(a: 4.0, b: 1) // expected-error {{cannot invoke value of type 'MyType.Type' with argument list '(a: Double, b: Int)'}} +let _: GenericClass.TA = GenericClass.TA(a: 1, b: 4.0) + +let _: GenericClass.TA = GenericClass.TA(a: 4.0, b: 1) // expected-error {{'Int' is not convertible to 'Float'}} +let _: GenericClass.TA = GenericClass.TA(a: 1, b: 4.0) // FIXME // expected-error {{'Int' is not convertible to 'Float'}} + +let _: GenericClass.TA = GenericClass.TA(a: 4.0, b: 1) // expected-error {{cannot invoke value of type 'MyType<_, _>.Type' with argument list '(a: Double, b: Int)'}} +let _: GenericClass.TA = GenericClass.TA(a: 1, b: 4.0) + +let _: GenericClass.TA = GenericClass.TA(a: 4.0, b: 1) // expected-error {{cannot invoke value of type 'MyType.Type' with argument list '(a: Double, b: Int)'}} +let _: GenericClass.TA = GenericClass.TA(a: 1, b: 4.0) // FIXME // expected-error {{cannot invoke value of type 'MyType.Type' with argument list '(a: Int, b: Double)'}} + +let _: GenericClass.TA = GenericClass.TA(a: 4.0, b: 1) // expected-error {{cannot invoke value of type 'MyType.Type' with argument list '(a: Double, b: Int)'}} +let _: GenericClass.TA = GenericClass.TA(a: 1, b: 4.0) + +let _: GenericClass.TA = GenericClass.TA(a: 4.0, b: 1) // expected-error {{'Int' is not convertible to 'Float'}} +let _: GenericClass.TA = GenericClass.TA(a: 1, b: 4.0) // FIXME // expected-error {{'Int' is not convertible to 'Float'}} func takesUnsugaredType2(m: MyType) {} func takesSugaredType2(m: GenericClass.TA) { diff --git a/test/expr/capture/generic_params.swift b/test/expr/capture/generic_params.swift index 54fc8f94735..8066c256903 100644 --- a/test/expr/capture/generic_params.swift +++ b/test/expr/capture/generic_params.swift @@ -26,9 +26,9 @@ func outerGeneric(t: T, x: AnyObject) { // Make sure we look through typealiases typealias TT = (a: T, b: T) - // CHECK: func_decl "localFunction(tt:)" interface type=' (tt: (a: T, b: T)) -> ()' {{.*}} captures=( ) + // CHECK: func_decl "localFunction(tt:)" interface type=' (tt: TT) -> ()' {{.*}} captures=( ) func localFunction(tt: TT) {} - // CHECK: closure_expr type='(TT) -> ()' {{.*}} captures=( ) + // CHECK: closure_expr type='((a: T, b: T)) -> ()' {{.*}} captures=( ) let _: (TT) -> () = { _ in } } diff --git a/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp b/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp index 2d9a08e7753..f3bebbaf18b 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp +++ b/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp @@ -477,11 +477,11 @@ static void reportRelated(ASTContext &Ctx, } else if (auto *TAD = dyn_cast(D)) { - // If underlying type exists, report the inheritance and conformance of the - // underlying type. - auto Ty = TAD->getUnderlyingType(); - if (Ty) { - if (auto NM = Ty->getCanonicalType()->getAnyNominal()) { + if (TAD->hasInterfaceType()) { + // If underlying type exists, report the inheritance and conformance of the + // underlying type. + auto Ty = TAD->getDeclaredInterfaceType(); + if (auto NM = Ty->getAnyNominal()) { passInherits(NM->getInherited(), Consumer); passConforms(NM->getSatisfiedProtocolRequirements(/*Sorted=*/true), Consumer); diff --git a/tools/swift-api-digester/swift-api-digester.cpp b/tools/swift-api-digester/swift-api-digester.cpp index 9474446f1f9..fb6b6d669d9 100644 --- a/tools/swift-api-digester/swift-api-digester.cpp +++ b/tools/swift-api-digester/swift-api-digester.cpp @@ -1241,7 +1241,7 @@ static SDKNode *constructVarNode(SDKContext &Ctx, ValueDecl *VD) { static SDKNode *constructTypeAliasNode(SDKContext &Ctx,TypeAliasDecl *TAD) { auto Alias = SDKNodeInitInfo(Ctx, TAD).createSDKNode(SDKNodeKind::TypeAlias); - Alias->addChild(constructTypeNode(Ctx, TAD->getUnderlyingType())); + Alias->addChild(constructTypeNode(Ctx, TAD->getUnderlyingTypeLoc().getType())); return Alias; } diff --git a/tools/swift-ide-test/ModuleAPIDiff.cpp b/tools/swift-ide-test/ModuleAPIDiff.cpp index 1d32a55899c..947ed5595af 100644 --- a/tools/swift-ide-test/ModuleAPIDiff.cpp +++ b/tools/swift-ide-test/ModuleAPIDiff.cpp @@ -832,7 +832,7 @@ public: void visitTypeAliasDecl(TypeAliasDecl *TAD) { auto ResultTD = std::make_shared(); ResultTD->Name = convertToIdentifier(TAD->getName()); - ResultTD->Type = convertToTypeName(TAD->getUnderlyingType()); + ResultTD->Type = convertToTypeName(TAD->getUnderlyingTypeLoc().getType()); // FIXME // ResultTD->Attributes = ?; Result.Typealiases.emplace_back(std::move(ResultTD)); diff --git a/tools/swift-ide-test/swift-ide-test.cpp b/tools/swift-ide-test/swift-ide-test.cpp index 8c388cf55e8..1ee6c460dc1 100644 --- a/tools/swift-ide-test/swift-ide-test.cpp +++ b/tools/swift-ide-test/swift-ide-test.cpp @@ -1943,8 +1943,8 @@ static int doPrintDecls(const CompilerInvocation &InitInvok, if (auto typeDecl = dyn_cast(result.getValueDecl())) { if (auto typeAliasDecl = dyn_cast(typeDecl)) { - TypeDecl *origTypeDecl = typeAliasDecl->getUnderlyingType() - ->getNominalOrBoundGenericNominal(); + TypeDecl *origTypeDecl = typeAliasDecl->getDeclaredInterfaceType() + ->getAnyNominal(); if (origTypeDecl) { origTypeDecl->print(*Printer, Options); typeDecl = origTypeDecl; diff --git a/validation-test/compiler_crashers/28573-type-hasarchetype-archetype-in-interface-type.swift b/validation-test/compiler_crashers_fixed/28573-type-hasarchetype-archetype-in-interface-type.swift similarity index 87% rename from validation-test/compiler_crashers/28573-type-hasarchetype-archetype-in-interface-type.swift rename to validation-test/compiler_crashers_fixed/28573-type-hasarchetype-archetype-in-interface-type.swift index 706a11dccaf..c30acb88dac 100644 --- a/validation-test/compiler_crashers/28573-type-hasarchetype-archetype-in-interface-type.swift +++ b/validation-test/compiler_crashers_fixed/28573-type-hasarchetype-archetype-in-interface-type.swift @@ -5,7 +5,7 @@ // See https://swift.org/LICENSE.txt for license information // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// RUN: not --crash %target-swift-frontend %s -emit-ir +// RUN: not %target-swift-frontend %s -emit-ir // REQUIRES: asserts typealias B:T guard let d:B