Skip to content

Commit efbfaac

Browse files
authored
Merge pull request #35773 from slavapestov/gsb-optimizations
GSB: Optimize PotentialArchetype::getDependentType()
2 parents 337372b + df3c879 commit efbfaac

File tree

5 files changed

+102
-192
lines changed

5 files changed

+102
-192
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,8 +1042,6 @@ ERROR(expected_else_after_guard,PointsToFirstBadToken,
10421042
"expected 'else' after 'guard' condition", ())
10431043
ERROR(expected_lbrace_after_guard,PointsToFirstBadToken,
10441044
"expected '{' after 'guard' else", ())
1045-
ERROR(bound_var_guard_body,none,
1046-
"variable declared in 'guard' condition is not usable in its body", ())
10471045

10481046
// While Statement
10491047
ERROR(expected_condition_while,PointsToFirstBadToken,

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 17 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ class GenericSignatureBuilder {
160160
/// Describes a component within the graph of same-type constraints within
161161
/// the equivalence class that is held together by derived constraints.
162162
struct DerivedSameTypeComponent {
163-
/// The potential archetype that acts as the anchor for this component.
164-
UnresolvedType anchor;
163+
/// The type that acts as the anchor for this component.
164+
Type type;
165165

166166
/// The (best) requirement source within the component that makes the
167167
/// potential archetypes in this component equivalent to the concrete
@@ -1477,31 +1477,17 @@ struct GenericSignatureBuilder::Constraint {
14771477
};
14781478

14791479
class GenericSignatureBuilder::PotentialArchetype {
1480-
/// The parent of this potential archetype (for a nested type) or the
1481-
/// ASTContext in which the potential archetype resides.
1482-
llvm::PointerUnion<PotentialArchetype*, ASTContext*> parentOrContext;
1483-
1484-
/// The identifier describing this particular archetype.
1485-
///
1486-
/// \c parentOrBuilder determines whether we have a nested type vs. a root.
1487-
union PAIdentifier {
1488-
/// The associated type for a resolved nested type.
1489-
AssociatedTypeDecl *assocType;
1490-
1491-
/// The generic parameter key for a root.
1492-
GenericParamKey genericParam;
1493-
1494-
PAIdentifier(AssociatedTypeDecl *assocType) : assocType(assocType) {}
1495-
1496-
PAIdentifier(GenericParamKey genericParam) : genericParam(genericParam) { }
1497-
} identifier;
1480+
/// The parent of this potential archetype, for a nested type.
1481+
PotentialArchetype* parent;
14981482

14991483
/// The representative of the equivalence class of potential archetypes
15001484
/// to which this potential archetype belongs, or (for the representative)
15011485
/// the equivalence class itself.
15021486
mutable llvm::PointerUnion<PotentialArchetype *, EquivalenceClass *>
15031487
representativeOrEquivClass;
15041488

1489+
mutable CanType depType;
1490+
15051491
/// A stored nested type.
15061492
struct StoredNestedType {
15071493
/// The potential archetypes describing this nested type, all of which
@@ -1539,7 +1525,7 @@ class GenericSignatureBuilder::PotentialArchetype {
15391525
PotentialArchetype(PotentialArchetype *parent, AssociatedTypeDecl *assocType);
15401526

15411527
/// Construct a new potential archetype for a generic parameter.
1542-
PotentialArchetype(ASTContext &ctx, GenericParamKey genericParam);
1528+
explicit PotentialArchetype(GenericTypeParamType *genericParam);
15431529

15441530
public:
15451531
/// Retrieve the representative for this archetype, performing
@@ -1558,42 +1544,17 @@ class GenericSignatureBuilder::PotentialArchetype {
15581544
/// Retrieve the parent of this potential archetype, which will be non-null
15591545
/// when this potential archetype is an associated type.
15601546
PotentialArchetype *getParent() const {
1561-
return parentOrContext.dyn_cast<PotentialArchetype *>();
1547+
return parent;
15621548
}
15631549

15641550
/// Retrieve the type declaration to which this nested type was resolved.
15651551
AssociatedTypeDecl *getResolvedType() const {
1566-
assert(getParent() && "Not an associated type");
1567-
return identifier.assocType;
1552+
return cast<DependentMemberType>(depType)->getAssocType();
15681553
}
15691554

15701555
/// Determine whether this is a generic parameter.
15711556
bool isGenericParam() const {
1572-
return parentOrContext.is<ASTContext *>();
1573-
}
1574-
1575-
/// Retrieve the generic parameter key for a potential archetype that
1576-
/// represents this potential archetype.
1577-
///
1578-
/// \pre \c isGenericParam()
1579-
GenericParamKey getGenericParamKey() const {
1580-
assert(isGenericParam() && "Not a generic parameter");
1581-
return identifier.genericParam;
1582-
}
1583-
1584-
/// Retrieve the generic parameter key for the generic parameter at the
1585-
/// root of this potential archetype.
1586-
GenericParamKey getRootGenericParamKey() const {
1587-
if (auto parent = getParent())
1588-
return parent->getRootGenericParamKey();
1589-
1590-
return getGenericParamKey();
1591-
}
1592-
1593-
/// Retrieve the name of a nested potential archetype.
1594-
Identifier getNestedName() const {
1595-
assert(getParent() && "Not a nested type");
1596-
return identifier.assocType->getName();
1557+
return parent == nullptr;
15971558
}
15981559

15991560
/// Retrieve the set of nested types.
@@ -1643,12 +1604,18 @@ class GenericSignatureBuilder::PotentialArchetype {
16431604
AssociatedTypeDecl *assocType,
16441605
ArchetypeResolutionKind kind);
16451606

1607+
/// Retrieve the dependent type that describes this potential
1608+
/// archetype.
1609+
CanType getDependentType() const {
1610+
return depType;
1611+
}
1612+
16461613
/// Retrieve the dependent type that describes this potential
16471614
/// archetype.
16481615
///
16491616
/// \param genericParams The set of generic parameters to use in the resulting
16501617
/// dependent type.
1651-
Type getDependentType(TypeArrayView<GenericTypeParamType> genericParams)const;
1618+
Type getDependentType(TypeArrayView<GenericTypeParamType> genericParams) const;
16521619

16531620
/// True if the potential archetype has been bound by a concrete type
16541621
/// constraint.
@@ -1659,9 +1626,6 @@ class GenericSignatureBuilder::PotentialArchetype {
16591626
return false;
16601627
}
16611628

1662-
/// Retrieve the AST context in which this potential archetype resides.
1663-
ASTContext &getASTContext() const;
1664-
16651629
SWIFT_DEBUG_DUMP;
16661630

16671631
void dump(llvm::raw_ostream &Out, SourceManager *SrcMgr,

include/swift/AST/Types.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5659,8 +5659,7 @@ class DependentMemberType : public TypeBase {
56595659
}
56605660
};
56615661
BEGIN_CAN_TYPE_WRAPPER(DependentMemberType, Type)
5662-
static CanDependentMemberType get(CanType base, AssociatedTypeDecl *assocType,
5663-
const ASTContext &C) {
5662+
static CanDependentMemberType get(CanType base, AssociatedTypeDecl *assocType) {
56645663
return CanDependentMemberType(DependentMemberType::get(base, assocType));
56655664
}
56665665

0 commit comments

Comments
 (0)