Skip to content

Commit bb886a6

Browse files
committed
Sema: Store a SubstitutionMap instead of a ConcreteDeclRef in AbstractFunction
1 parent 3ce2e04 commit bb886a6

File tree

1 file changed

+21
-31
lines changed

1 file changed

+21
-31
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -207,39 +207,35 @@ class AbstractFunction {
207207
unsigned TheKind : 2;
208208
unsigned ParamCount : 2;
209209
FunctionRethrowingKind RethrowingKind;
210-
ConcreteDeclRef declRef;
210+
SubstitutionMap Substitutions;
211211

212212
public:
213-
explicit AbstractFunction(Kind kind, Expr *fn, ConcreteDeclRef declRef)
213+
explicit AbstractFunction(Kind kind, Expr *fn)
214214
: TheKind(kind),
215215
ParamCount(1),
216-
RethrowingKind(FunctionRethrowingKind::None),
217-
declRef(declRef) {
216+
RethrowingKind(FunctionRethrowingKind::None) {
218217
TheExpr = fn;
219218
}
220219

221-
explicit AbstractFunction(AbstractFunctionDecl *fn, ConcreteDeclRef declRef)
220+
explicit AbstractFunction(AbstractFunctionDecl *fn, SubstitutionMap subs)
222221
: TheKind(Kind::Function),
223222
ParamCount(fn->getNumCurryLevels()),
224223
RethrowingKind(fn->getRethrowingKind()),
225-
declRef(declRef) {
224+
Substitutions(subs) {
226225
TheFunction = fn;
227226
}
228227

229-
explicit AbstractFunction(AbstractClosureExpr *closure,
230-
ConcreteDeclRef declRef)
228+
explicit AbstractFunction(AbstractClosureExpr *closure)
231229
: TheKind(Kind::Closure),
232230
ParamCount(1),
233-
RethrowingKind(FunctionRethrowingKind::None),
234-
declRef(declRef) {
231+
RethrowingKind(FunctionRethrowingKind::None) {
235232
TheClosure = closure;
236233
}
237234

238-
explicit AbstractFunction(ParamDecl *parameter, ConcreteDeclRef declRef)
235+
explicit AbstractFunction(ParamDecl *parameter)
239236
: TheKind(Kind::Parameter),
240237
ParamCount(1),
241-
RethrowingKind(FunctionRethrowingKind::None),
242-
declRef(declRef) {
238+
RethrowingKind(FunctionRethrowingKind::None) {
243239
TheParameter = parameter;
244240
}
245241

@@ -300,29 +296,22 @@ class AbstractFunction {
300296
return TheExpr;
301297
}
302298

303-
ConcreteDeclRef getDeclRef() {
304-
return declRef;
299+
SubstitutionMap getSubstitutions() const {
300+
return Substitutions;
305301
}
306302

307303
static AbstractFunction decomposeApply(ApplyExpr *apply,
308304
SmallVectorImpl<Expr*> &args) {
309305
Expr *fn;
310-
ConcreteDeclRef declRef;
311306
do {
312307
args.push_back(apply->getArg());
313-
auto applyFn = apply->getFn();
314-
if (!declRef) {
315-
if (auto DRE = dyn_cast<DeclRefExpr>(applyFn)) {
316-
declRef = DRE->getDeclRef();
317-
}
318-
}
319-
fn = applyFn->getValueProvidingExpr();
308+
fn = apply->getFn()->getValueProvidingExpr();
320309
} while ((apply = dyn_cast<ApplyExpr>(fn)));
321310

322-
return decomposeFunction(fn, declRef);
311+
return decomposeFunction(fn);
323312
}
324313

325-
static AbstractFunction decomposeFunction(Expr *fn, ConcreteDeclRef declRef = ConcreteDeclRef()) {
314+
static AbstractFunction decomposeFunction(Expr *fn) {
326315
assert(fn->getValueProvidingExpr() == fn);
327316

328317
while (true) {
@@ -353,25 +342,26 @@ class AbstractFunction {
353342

354343
// Constructor delegation.
355344
if (auto otherCtorDeclRef = dyn_cast<OtherConstructorDeclRefExpr>(fn)) {
356-
return AbstractFunction(otherCtorDeclRef->getDecl(), declRef);
345+
return AbstractFunction(otherCtorDeclRef->getDecl(),
346+
otherCtorDeclRef->getDeclRef().getSubstitutions());
357347
}
358348

359349
// Normal function references.
360350
if (auto DRE = dyn_cast<DeclRefExpr>(fn)) {
361351
ValueDecl *decl = DRE->getDecl();
362352
if (auto fn = dyn_cast<AbstractFunctionDecl>(decl)) {
363-
return AbstractFunction(fn, declRef);
353+
return AbstractFunction(fn, DRE->getDeclRef().getSubstitutions());
364354
} else if (auto param = dyn_cast<ParamDecl>(decl)) {
365-
return AbstractFunction(param, declRef);
355+
return AbstractFunction(param);
366356
}
367357

368358
// Closures.
369359
} else if (auto closure = dyn_cast<AbstractClosureExpr>(fn)) {
370-
return AbstractFunction(closure, declRef);
360+
return AbstractFunction(closure);
371361
}
372362

373363
// Everything else is opaque.
374-
return AbstractFunction(Kind::Opaque, fn, declRef);
364+
return AbstractFunction(Kind::Opaque, fn);
375365
}
376366
};
377367

@@ -688,7 +678,7 @@ class ApplyClassifier {
688678
}
689679

690680
if (fnRef.getRethrowingKind() == FunctionRethrowingKind::ByConformance) {
691-
auto substitutions = fnRef.getDeclRef().getSubstitutions();
681+
auto substitutions = fnRef.getSubstitutions();
692682
bool classifiedAsThrows = false;
693683
for (auto conformanceRef : substitutions.getConformances()) {
694684
if (conformanceRef.classifyAsThrows()) {

0 commit comments

Comments
 (0)