Skip to content

Commit 1983431

Browse files
committed
[ConstraintSystem] Make it so re-labeling fix holds correct labels as trailing objects
1 parent 8f9631b commit 1983431

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

lib/Sema/CSFix.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,17 @@ MarkExplicitlyEscaping::create(ConstraintSystem &cs, ConstraintLocator *locator,
113113
}
114114

115115
bool RelabelArguments::diagnose(Expr *root, const Solution &solution) const {
116-
LabelingFailure failure(solution, getLocator(), CorrectLabels);
116+
LabelingFailure failure(solution, getLocator(), getLabels());
117117
return failure.diagnose();
118118
}
119119

120120
RelabelArguments *
121121
RelabelArguments::create(ConstraintSystem &cs,
122122
llvm::ArrayRef<Identifier> correctLabels,
123123
ConstraintLocator *locator) {
124-
return new (cs.getAllocator()) RelabelArguments(correctLabels, locator);
124+
unsigned size = totalSizeToAlloc<Identifier>(correctLabels.size());
125+
void *mem = cs.getAllocator().Allocate(size, alignof(RelabelArguments));
126+
return new (mem) RelabelArguments(correctLabels, locator);
125127
}
126128

127129
bool MissingConformance::diagnose(Expr *root, const Solution &solution) const {

lib/Sema/CSFix.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "swift/AST/Type.h"
2424
#include "llvm/ADT/ArrayRef.h"
2525
#include "llvm/ADT/SmallVector.h"
26+
#include "llvm/Support/TrailingObjects.h"
2627

2728
namespace llvm {
2829
class raw_ostream;
@@ -198,15 +199,26 @@ class MarkExplicitlyEscaping final : public ConstraintFix {
198199

199200
/// Arguments have labeling failures - missing/extraneous or incorrect
200201
/// labels attached to the, fix it by suggesting proper labels.
201-
class RelabelArguments final : public ConstraintFix {
202-
llvm::SmallVector<Identifier, 4> CorrectLabels;
202+
class RelabelArguments final
203+
: public ConstraintFix,
204+
private llvm::TrailingObjects<RelabelArguments, Identifier> {
205+
friend TrailingObjects;
206+
207+
unsigned NumLabels;
203208

204209
RelabelArguments(llvm::ArrayRef<Identifier> correctLabels,
205210
ConstraintLocator *locator)
206211
: ConstraintFix(FixKind::RelabelArguments, locator),
207-
CorrectLabels(correctLabels.begin(), correctLabels.end()) {}
212+
NumLabels(correctLabels.size()) {
213+
std::uninitialized_copy(correctLabels.begin(), correctLabels.end(),
214+
getLabelsBuffer().begin());
215+
}
208216

209217
public:
218+
ArrayRef<Identifier> getLabels() const {
219+
return {getTrailingObjects<Identifier>(), NumLabels};
220+
}
221+
210222
bool diagnose(Expr *root, const Solution &solution) const override;
211223
void print(llvm::raw_ostream &Out) const override {
212224
Out << "[fix: re-label argument(s)]";
@@ -215,6 +227,11 @@ class RelabelArguments final : public ConstraintFix {
215227
static RelabelArguments *create(ConstraintSystem &cs,
216228
llvm::ArrayRef<Identifier> correctLabels,
217229
ConstraintLocator *locator);
230+
231+
private:
232+
MutableArrayRef<Identifier> getLabelsBuffer() {
233+
return {getTrailingObjects<Identifier>(), NumLabels};
234+
}
218235
};
219236

220237
/// Add a new conformance to the type to satisfy a requirement.

0 commit comments

Comments
 (0)