Skip to content

Commit 6974448

Browse files
committed
Sema: Fold TypeAliasDecl::computeType() into validateDecl()
1 parent 797a797 commit 6974448

File tree

8 files changed

+13
-35
lines changed

8 files changed

+13
-35
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2985,9 +2985,6 @@ class TypeAliasDecl : public GenericTypeDecl {
29852985
/// Retrieve a sugared interface type containing the structure of the interface
29862986
/// type before any semantic validation has occured.
29872987
Type getStructuralType() const;
2988-
2989-
/// Set the interface type of this typealias declaration from the underlying type.
2990-
void computeType();
29912988

29922989
bool isCompatibilityAlias() const {
29932990
return Bits.TypeAliasDecl.IsCompatibilityAlias;

lib/AST/Decl.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3546,25 +3546,6 @@ SourceRange TypeAliasDecl::getSourceRange() const {
35463546
return { TypeAliasLoc, getNameLoc() };
35473547
}
35483548

3549-
void TypeAliasDecl::computeType() {
3550-
assert(!hasInterfaceType());
3551-
3552-
// Set the interface type of this declaration.
3553-
ASTContext &ctx = getASTContext();
3554-
3555-
auto genericSig = getGenericSignature();
3556-
SubstitutionMap subs;
3557-
if (genericSig)
3558-
subs = genericSig->getIdentitySubstitutionMap();
3559-
3560-
Type parent;
3561-
auto parentDC = getDeclContext();
3562-
if (parentDC->isTypeContext())
3563-
parent = parentDC->getSelfInterfaceType();
3564-
auto sugaredType = TypeAliasType::get(this, parent, subs, getUnderlyingType());
3565-
setInterfaceType(MetatypeType::get(sugaredType, ctx));
3566-
}
3567-
35683549
Type TypeAliasDecl::getUnderlyingType() const {
35693550
auto &ctx = getASTContext();
35703551
return evaluateOrDefault(ctx.evaluator,

lib/AST/Module.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ void BuiltinUnit::LookupCache::lookupValue(
103103
const_cast<BuiltinUnit*>(&M));
104104
TAD->setUnderlyingType(Ty);
105105
TAD->setAccess(AccessLevel::Public);
106-
TAD->computeType();
107106
Entry = TAD;
108107
}
109108
}

lib/ClangImporter/ImportDecl.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,6 @@ static void addSynthesizedTypealias(NominalTypeDecl *nominal, Identifier name,
14811481
typealias->setUnderlyingType(underlyingType);
14821482
typealias->setAccess(AccessLevel::Public);
14831483
typealias->setImplicit();
1484-
typealias->computeType();
14851484

14861485
nominal->addMember(typealias);
14871486
}
@@ -2542,7 +2541,6 @@ namespace {
25422541
/*genericparams*/nullptr, DC);
25432542
typealias->setUnderlyingType(
25442543
underlying->getDeclaredInterfaceType());
2545-
typealias->computeType();
25462544

25472545
Impl.SpecialTypedefNames[Decl->getCanonicalDecl()] =
25482546
MappedTypeNameKind::DefineAndUse;
@@ -2562,7 +2560,6 @@ namespace {
25622560
/*genericparams*/nullptr, DC);
25632561
typealias->setUnderlyingType(
25642562
Impl.SwiftContext.getAnyObjectType());
2565-
typealias->computeType();
25662563

25672564
Impl.SpecialTypedefNames[Decl->getCanonicalDecl()] =
25682565
MappedTypeNameKind::DefineAndUse;
@@ -2630,7 +2627,6 @@ namespace {
26302627
Loc,
26312628
/*genericparams*/nullptr, DC);
26322629
Result->setUnderlyingType(SwiftType);
2633-
Result->computeType();
26342630

26352631
// Make Objective-C's 'id' unavailable.
26362632
if (Impl.SwiftContext.LangOpts.EnableObjCInterop && isObjCId(Decl)) {
@@ -2920,7 +2916,6 @@ namespace {
29202916
C.Id_ErrorType, loc,
29212917
/*genericparams=*/nullptr, enumDecl);
29222918
alias->setUnderlyingType(errorWrapper->getDeclaredInterfaceType());
2923-
alias->computeType();
29242919
enumDecl->addMember(alias);
29252920

29262921
// Add the 'Code' enum to the error wrapper.
@@ -4001,7 +3996,6 @@ namespace {
40013996
Loc,
40023997
/*genericparams*/nullptr, DC);
40033998
Result->setUnderlyingType(SwiftTypeDecl->getDeclaredInterfaceType());
4004-
Result->computeType();
40053999

40064000
return Result;
40074001
}
@@ -5128,7 +5122,6 @@ namespace {
51285122
}
51295123

51305124
typealias->setUnderlyingType(typeDecl->getDeclaredInterfaceType());
5131-
typealias->computeType();
51325125
return typealias;
51335126
}
51345127

@@ -5363,7 +5356,6 @@ Decl *SwiftDeclConverter::importCompatibilityTypeAlias(
53635356
}
53645357

53655358
alias->setUnderlyingType(typeDecl->getDeclaredInterfaceType());
5366-
alias->computeType();
53675359

53685360
// Record that this is the official version of this declaration.
53695361
Impl.ImportedDecls[{decl->getCanonicalDecl(), getVersion()}] = alias;

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
733733
NoLoc, NoLoc, IGM.Context.getIdentifier(ArchetypeName), NoLoc,
734734
/*genericparams*/ nullptr, IGM.Context.TheBuiltinModule);
735735
Entry->setUnderlyingType(IGM.Context.TheRawPointerType);
736-
Entry->computeType();
737736
return Entry;
738737
}
739738

lib/Sema/TypeCheckDecl.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4164,7 +4164,19 @@ void TypeChecker::validateDecl(ValueDecl *D) {
41644164

41654165
case DeclKind::TypeAlias: {
41664166
auto typeAlias = cast<TypeAliasDecl>(D);
4167-
typeAlias->computeType();
4167+
4168+
auto genericSig = typeAlias->getGenericSignature();
4169+
SubstitutionMap subs;
4170+
if (genericSig)
4171+
subs = genericSig->getIdentitySubstitutionMap();
4172+
4173+
Type parent;
4174+
auto parentDC = typeAlias->getDeclContext();
4175+
if (parentDC->isTypeContext())
4176+
parent = parentDC->getSelfInterfaceType();
4177+
auto sugaredType = TypeAliasType::get(typeAlias, parent, subs,
4178+
typeAlias->getUnderlyingType());
4179+
typeAlias->setInterfaceType(MetatypeType::get(sugaredType, Context));
41684180
break;
41694181
}
41704182

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2471,7 +2471,6 @@ void ConformanceChecker::recordTypeWitness(AssociatedTypeDecl *assocType,
24712471
/*genericparams*/nullptr,
24722472
DC);
24732473
aliasDecl->setUnderlyingType(type);
2474-
aliasDecl->computeType();
24752474

24762475
aliasDecl->setImplicit();
24772476
if (type->hasError())

lib/Serialization/Deserialization.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2295,7 +2295,6 @@ class swift::DeclDeserializer {
22952295

22962296
auto underlying = MF.getType(underlyingTypeID);
22972297
alias->setUnderlyingType(underlying);
2298-
alias->computeType();
22992298

23002299
if (auto accessLevel = getActualAccessLevel(rawAccessLevel))
23012300
alias->setAccess(*accessLevel);

0 commit comments

Comments
 (0)