Skip to content

Commit ebb9f86

Browse files
committed
[ConstraintSystem] NFC: Remove obsolete Fix struct
Also clean up `ConstraintSystem` interface from the storage supporing `Fix` such as missing types, decl names, conformances etc.
1 parent e631a37 commit ebb9f86

File tree

3 files changed

+0
-162
lines changed

3 files changed

+0
-162
lines changed

lib/Sema/Constraint.cpp

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -471,89 +471,6 @@ StringRef swift::constraints::getName(ConversionRestrictionKind kind) {
471471
llvm_unreachable("bad conversion restriction kind");
472472
}
473473

474-
Fix Fix::getForcedDowncast(ConstraintSystem &cs, Type toType) {
475-
unsigned index = cs.FixedTypes.size();
476-
cs.FixedTypes.push_back(toType);
477-
return Fix(FixKind::ForceDowncast, index);
478-
}
479-
480-
Fix Fix::getUnwrapOptionalBase(ConstraintSystem &cs, DeclName memberName) {
481-
unsigned index = cs.FixedDeclNames.size();
482-
cs.FixedDeclNames.push_back(memberName);
483-
return Fix(FixKind::UnwrapOptionalBase, index);
484-
}
485-
486-
Fix Fix::fixArgumentLabels(ConstraintSystem &cs,
487-
ArrayRef<Identifier> newLabels) {
488-
unsigned index = cs.FixedArgLabels.size();
489-
cs.FixedArgLabels.push_back(newLabels);
490-
return Fix(FixKind::RelabelArguments, index);
491-
}
492-
493-
Type Fix::getTypeArgument(ConstraintSystem &cs) const {
494-
assert(getKind() == FixKind::ForceDowncast);
495-
return cs.FixedTypes[Data];
496-
}
497-
498-
/// If this fix has a name argument, retrieve it.
499-
DeclName Fix::getDeclNameArgument(ConstraintSystem &cs) const {
500-
assert(getKind() == FixKind::UnwrapOptionalBase);
501-
return cs.FixedDeclNames[Data];
502-
}
503-
504-
ArrayRef<Identifier> Fix::getArgumentLabels(ConstraintSystem &cs) const {
505-
assert(getKind() == FixKind::RelabelArguments);
506-
return cs.FixedArgLabels[Data];
507-
}
508-
509-
/// If this fix has optional result info, retrieve it.
510-
bool Fix::isUnwrapOptionalBaseByOptionalChaining(ConstraintSystem &cs) const {
511-
assert(getKind() == FixKind::UnwrapOptionalBase);
512-
513-
// Assumes that these fixes are always created in pairs, with the first
514-
// created non-optional and the second with an added optional.
515-
return (Data % 2) == 1;
516-
}
517-
518-
StringRef Fix::getName(FixKind kind) {
519-
switch (kind) {
520-
case FixKind::ForceOptional:
521-
return "fix: force optional";
522-
case FixKind::UnwrapOptionalBase:
523-
case FixKind::UnwrapOptionalBaseWithOptionalResult:
524-
return "fix: unwrap optional base of member lookup";
525-
case FixKind::ForceDowncast:
526-
return "fix: force downcast";
527-
case FixKind::AddressOf:
528-
return "fix: add address-of";
529-
case FixKind::CoerceToCheckedCast:
530-
return "fix: as to as!";
531-
case FixKind::ExplicitlyEscaping:
532-
return "fix: add @escaping";
533-
case FixKind::RelabelArguments:
534-
return "fix: re-label argument(s)";
535-
case FixKind::AddConformance:
536-
return "fix: add missing protocol conformance";
537-
}
538-
539-
llvm_unreachable("Unhandled FixKind in switch.");
540-
}
541-
542-
void Fix::print(llvm::raw_ostream &Out, ConstraintSystem *cs) const {
543-
Out << '[' << getName(getKind());
544-
545-
if (getKind() == FixKind::ForceDowncast && cs) {
546-
Out << " as! ";
547-
Out << getTypeArgument(*cs).getString();
548-
}
549-
Out << ']';
550-
}
551-
552-
void Fix::dump(ConstraintSystem *cs) const {
553-
print(llvm::errs(), cs);
554-
llvm::errs() << "\n";
555-
}
556-
557474
/// Recursively gather the set of type variables referenced by this constraint.
558475
static void
559476
gatherReferencedTypeVars(Constraint *constraint,

lib/Sema/Constraint.h

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -226,64 +226,6 @@ enum RememberChoice_t : bool {
226226
RememberChoice = true
227227
};
228228

229-
/// Describes a fix that can be applied to a constraint before visiting it.
230-
class Fix {
231-
FixKind Kind;
232-
uint16_t Data;
233-
234-
Fix(FixKind kind, uint16_t data) : Kind(kind), Data(data){ }
235-
236-
uint16_t getData() const { return Data; }
237-
238-
friend class Constraint;
239-
240-
public:
241-
Fix(FixKind kind) : Kind(kind), Data(0) {
242-
assert(kind != FixKind::ForceDowncast && "Use getForceDowncast()");
243-
assert(kind != FixKind::UnwrapOptionalBase &&
244-
"Use getUnwrapOptionalBase()");
245-
}
246-
247-
/// Produce a new fix that performs a forced downcast to the given type.
248-
static Fix getForcedDowncast(ConstraintSystem &cs, Type toType);
249-
250-
/// Produce a new fix that unwraps an optional base for an access to a member
251-
/// with the given name.
252-
static Fix getUnwrapOptionalBase(ConstraintSystem &cs, DeclName memberName);
253-
254-
/// Produce a new fix that re-labels existing arguments so they much
255-
/// what parameters expect.
256-
static Fix fixArgumentLabels(ConstraintSystem &cs,
257-
ArrayRef<Identifier> newLabels);
258-
259-
/// Retrieve the kind of fix.
260-
FixKind getKind() const { return Kind; }
261-
262-
/// If this fix has a type argument, retrieve it.
263-
Type getTypeArgument(ConstraintSystem &cs) const;
264-
265-
/// If this fix has a name argument, retrieve it.
266-
DeclName getDeclNameArgument(ConstraintSystem &cs) const;
267-
268-
/// If this fix is an argument re-labeling, retrieve new labels.
269-
ArrayRef<Identifier> getArgumentLabels(ConstraintSystem &cs) const;
270-
271-
/// If this fix has optional result info, retrieve it.
272-
bool isUnwrapOptionalBaseByOptionalChaining(ConstraintSystem &cs) const;
273-
274-
/// Return a string representation of a fix.
275-
static llvm::StringRef getName(FixKind kind);
276-
277-
void print(llvm::raw_ostream &Out, ConstraintSystem *cs) const;
278-
279-
LLVM_ATTRIBUTE_DEPRECATED(void dump(ConstraintSystem *cs) const
280-
LLVM_ATTRIBUTE_USED,
281-
"only for use within the debugger");
282-
283-
bool operator==(Fix const &b) { return Kind == b.Kind && Data == b.Data; }
284-
};
285-
286-
287229
/// \brief A constraint between two type variables.
288230
class Constraint final : public llvm::ilist_node<Constraint>,
289231
private llvm::TrailingObjects<Constraint, TypeVariableType *> {

lib/Sema/ConstraintSystem.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,21 +1010,6 @@ class ConstraintSystem {
10101010
/// The set of fixes applied to make the solution work.
10111011
llvm::SmallVector<ConstraintFix *, 4> Fixes;
10121012

1013-
/// Types used in fixes.
1014-
std::vector<Type> FixedTypes;
1015-
1016-
/// Declaration names used in fixes.
1017-
std::vector<DeclName> FixedDeclNames;
1018-
1019-
/// Argument labels fixed by the constraint solver.
1020-
SmallVector<std::vector<Identifier>, 4> FixedArgLabels;
1021-
1022-
/// Conformances which solver "fixed" to help with
1023-
/// diagnosing problems related to generic requirements.
1024-
llvm::SmallDenseMap<std::pair<Expr *, unsigned>,
1025-
std::pair<TypeBase *, ProtocolDecl *>>
1026-
MissingConformances;
1027-
10281013
/// \brief The set of remembered disjunction choices used to reach
10291014
/// the current constraint system.
10301015
SmallVector<std::pair<ConstraintLocator*, unsigned>, 32>
@@ -1522,12 +1507,6 @@ class ConstraintSystem {
15221507
/// able to emit an error message, or false if none of the fixits worked out.
15231508
bool applySolutionFixes(Expr *E, const Solution &solution);
15241509

1525-
/// \brief Apply the specified Fix to this solution, producing a fix-it hint
1526-
/// diagnostic for it and returning true. If the fix-it hint turned out to be
1527-
/// bogus, this returns false and doesn't emit anything.
1528-
bool applySolutionFix(Expr *expr, const Solution &solution,
1529-
std::pair<Fix, ConstraintLocator *> &fix);
1530-
15311510
/// \brief If there is more than one viable solution,
15321511
/// attempt to pick the best solution and remove all of the rest.
15331512
///

0 commit comments

Comments
 (0)