Skip to content

Commit b2a5fbd

Browse files
committed
Sema: Shave another 8 bytes off of Constraint
1 parent ada6f77 commit b2a5fbd

File tree

3 files changed

+72
-83
lines changed

3 files changed

+72
-83
lines changed

include/swift/Sema/Constraint.h

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ class Constraint final : public llvm::ilist_node<Constraint>,
336336
private llvm::TrailingObjects<Constraint,
337337
TypeVariableType *,
338338
ConstraintFix *,
339+
DeclContext *,
339340
ContextualTypeInfo,
340341
OverloadChoice> {
341342
friend TrailingObjects;
@@ -354,6 +355,9 @@ class Constraint final : public llvm::ilist_node<Constraint>,
354355
/// Whether we have a tail-allocated fix.
355356
unsigned HasFix : 1;
356357

358+
/// Whether we have a tail-allocated DeclContext.
359+
unsigned HasDeclContext : 1;
360+
357361
/// Whether the \c Restriction field is valid.
358362
unsigned HasRestriction : 1;
359363

@@ -392,7 +396,7 @@ class Constraint final : public llvm::ilist_node<Constraint>,
392396
/// node is unused.
393397
unsigned isDiscarded : 1;
394398

395-
// 23 bits remaining
399+
// 22 bits remaining
396400

397401
union {
398402
struct {
@@ -425,20 +429,14 @@ class Constraint final : public llvm::ilist_node<Constraint>,
425429
/// Used for ValueWitness constraints.
426430
ValueDecl *Ref;
427431
} Member;
428-
429-
/// The DC in which the use appears.
430-
DeclContext *UseDC;
431432
} Member;
432433

433434
/// The set of constraints for a disjunction.
434435
ArrayRef<Constraint *> Nested;
435436

436437
struct {
437-
/// The first type
438+
/// The first type.
438439
Type First;
439-
440-
/// The DC in which the use appears.
441-
DeclContext *UseDC;
442440
} Overload;
443441

444442
struct {
@@ -454,8 +452,6 @@ class Constraint final : public llvm::ilist_node<Constraint>,
454452
/// The type being called, primarily a function type, but could
455453
/// be a metatype, a tuple or a nominal type.
456454
Type Callee;
457-
/// The declaration context in which the application appears.
458-
DeclContext *UseDC;
459455
} Apply;
460456
};
461457

@@ -531,6 +527,10 @@ class Constraint final : public llvm::ilist_node<Constraint>,
531527
return HasFix ? 1 : 0;
532528
}
533529

530+
size_t numTrailingObjects(OverloadToken<DeclContext *>) const {
531+
return HasDeclContext ? 1 : 0;
532+
}
533+
534534
size_t numTrailingObjects(OverloadToken<ContextualTypeInfo>) const {
535535
return Kind == ConstraintKind::SyntacticElement ? 1 : 0;
536536
}
@@ -876,20 +876,6 @@ class Constraint final : public llvm::ilist_node<Constraint>,
876876
return *getTrailingObjects<OverloadChoice>();
877877
}
878878

879-
/// Retrieve the DC in which the overload was used.
880-
DeclContext *getOverloadUseDC() const {
881-
assert(Kind == ConstraintKind::BindOverload);
882-
return Overload.UseDC;
883-
}
884-
885-
/// Retrieve the DC in which the member was used.
886-
DeclContext *getMemberUseDC() const {
887-
assert(Kind == ConstraintKind::ValueMember ||
888-
Kind == ConstraintKind::UnresolvedValueMember ||
889-
Kind == ConstraintKind::ValueWitness);
890-
return Member.UseDC;
891-
}
892-
893879
FunctionType *getAppliedFunctionType() const {
894880
assert(Kind == ConstraintKind::ApplicableFunction);
895881
return Apply.AppliedFn;
@@ -900,11 +886,6 @@ class Constraint final : public llvm::ilist_node<Constraint>,
900886
return Apply.Callee;
901887
}
902888

903-
DeclContext *getApplicationDC() const {
904-
assert(Kind == ConstraintKind::ApplicableFunction);
905-
return Apply.UseDC;
906-
}
907-
908889
ASTNode getSyntacticElement() const {
909890
assert(Kind == ConstraintKind::SyntacticElement);
910891
return SyntacticElement.Element;
@@ -920,6 +901,12 @@ class Constraint final : public llvm::ilist_node<Constraint>,
920901
return isDiscarded;
921902
}
922903

904+
/// Retrieve the DC in which the overload was used.
905+
DeclContext *getDeclContext() const {
906+
assert(HasDeclContext);
907+
return *getTrailingObjects<DeclContext *>();
908+
}
909+
923910
/// For an applicable function constraint, retrieve the trailing closure
924911
/// matching rule.
925912
std::optional<TrailingClosureMatching> getTrailingClosureMatching() const;

lib/Sema/CSSimplify.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13089,7 +13089,7 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
1308913089
// Determine the type that this choice will have.
1309013090
Type choiceType = getEffectiveOverloadType(
1309113091
constraint->getLocator(), choice, /*allowMembers=*/true,
13092-
constraint->getOverloadUseDC());
13092+
constraint->getDeclContext());
1309313093
if (!choiceType) {
1309413094
hasUnhandledConstraints = true;
1309513095
return true;
@@ -16335,7 +16335,7 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
1633516335
return simplifyApplicableFnConstraint(
1633616336
constraint.getAppliedFunctionType(), constraint.getCalleeType(),
1633716337
constraint.getTrailingClosureMatching(),
16338-
constraint.getApplicationDC(), /*flags=*/std::nullopt,
16338+
constraint.getDeclContext(), /*flags=*/std::nullopt,
1633916339
constraint.getLocator());
1634016340

1634116341
case ConstraintKind::DynamicCallableApplicableFunction:
@@ -16382,7 +16382,7 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
1638216382

1638316383
resolveOverload(constraint.getLocator(), constraint.getFirstType(),
1638416384
constraint.getOverloadChoice(),
16385-
constraint.getOverloadUseDC());
16385+
constraint.getDeclContext());
1638616386
return SolutionKind::Solved;
1638716387

1638816388
case ConstraintKind::SubclassOf:
@@ -16429,7 +16429,7 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
1642916429
case ConstraintKind::UnresolvedValueMember:
1643016430
return simplifyMemberConstraint(
1643116431
constraint.getKind(), constraint.getFirstType(), constraint.getMember(),
16432-
constraint.getSecondType(), constraint.getMemberUseDC(),
16432+
constraint.getSecondType(), constraint.getDeclContext(),
1643316433
constraint.getFunctionRefInfo(),
1643416434
/*outerAlternatives=*/{},
1643516435
/*flags*/ std::nullopt, constraint.getLocator());
@@ -16438,7 +16438,7 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
1643816438
return simplifyValueWitnessConstraint(
1643916439
constraint.getKind(), constraint.getFirstType(),
1644016440
constraint.getRequirement(), constraint.getSecondType(),
16441-
constraint.getMemberUseDC(), constraint.getFunctionRefInfo(),
16441+
constraint.getDeclContext(), constraint.getFunctionRefInfo(),
1644216442
/*flags*/ std::nullopt, constraint.getLocator());
1644316443

1644416444
case ConstraintKind::Defaultable:

0 commit comments

Comments
 (0)