@@ -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 ;
0 commit comments