Skip to content

Commit c72e3e3

Browse files
committed
Sema: Simplify ConstraintSystem::getUnopenedTypeOfReference()
1 parent d0bb3f7 commit c72e3e3

File tree

2 files changed

+19
-63
lines changed

2 files changed

+19
-63
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4374,39 +4374,6 @@ class ConstraintSystem {
43744374
bool wantInterfaceType = false,
43754375
bool adjustForPreconcurrency = true);
43764376

4377-
/// Return the type-of-reference of the given value.
4378-
///
4379-
/// \param baseType if non-null, return the type of a member reference to
4380-
/// this value when the base has the given type
4381-
///
4382-
/// \param UseDC The context of the access. Some variables have different
4383-
/// types depending on where they are used.
4384-
///
4385-
/// \param locator The locator anchored at this value reference, when
4386-
/// it is a member reference.
4387-
///
4388-
/// \param wantInterfaceType Whether we want the interface type, if available.
4389-
///
4390-
/// \param getType Optional callback to extract a type for given declaration.
4391-
static Type
4392-
getUnopenedTypeOfReference(
4393-
VarDecl *value, Type baseType, DeclContext *UseDC,
4394-
llvm::function_ref<Type(VarDecl *)> getType,
4395-
ConstraintLocator *locator,
4396-
bool wantInterfaceType = false,
4397-
bool adjustForPreconcurrency = true,
4398-
llvm::function_ref<Type(const AbstractClosureExpr *)> getClosureType =
4399-
[](const AbstractClosureExpr *) {
4400-
return Type();
4401-
},
4402-
llvm::function_ref<bool(const ClosureExpr *)> isolatedByPreconcurrency =
4403-
[](const ClosureExpr *closure) {
4404-
return closure->isIsolatedByPreconcurrency();
4405-
},
4406-
llvm::function_ref<bool(Expr *)> isAssignTarget = [](Expr *) {
4407-
return false;
4408-
});
4409-
44104377
/// Given the opened type and a pile of information about a member reference,
44114378
/// determine the reference type of the member reference.
44124379
Type getMemberReferenceTypeFromOpenedType(

lib/Sema/TypeOfReference.cpp

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -503,43 +503,31 @@ Type ConstraintSystem::getUnopenedTypeOfReference(
503503
VarDecl *value, Type baseType, DeclContext *UseDC,
504504
ConstraintLocator *locator, bool wantInterfaceType,
505505
bool adjustForPreconcurrency) {
506-
return ConstraintSystem::getUnopenedTypeOfReference(
507-
value, baseType, UseDC,
508-
[&](VarDecl *var) -> Type {
509-
if (Type type = getTypeIfAvailable(var))
510-
return type;
511-
512-
if (!var->hasInterfaceType()) {
513-
return ErrorType::get(getASTContext());
514-
}
515-
516-
return wantInterfaceType ? var->getInterfaceType() : var->getTypeInContext();
517-
},
518-
locator, wantInterfaceType, adjustForPreconcurrency,
519-
GetClosureType{*this},
520-
ClosureIsolatedByPreconcurrency{*this},
521-
IsInLeftHandSideOfAssignment{*this});
522-
}
506+
Type requestedType;
507+
if (Type type = getTypeIfAvailable(value)) {
508+
requestedType = type;
509+
} else if (!value->hasInterfaceType()) {
510+
requestedType = ErrorType::get(getASTContext());
511+
} else {
512+
requestedType = (wantInterfaceType
513+
? value->getInterfaceType()
514+
: value->getTypeInContext());
515+
}
523516

524-
Type ConstraintSystem::getUnopenedTypeOfReference(
525-
VarDecl *value, Type baseType, DeclContext *UseDC,
526-
llvm::function_ref<Type(VarDecl *)> getType,
527-
ConstraintLocator *locator,
528-
bool wantInterfaceType, bool adjustForPreconcurrency,
529-
llvm::function_ref<Type(const AbstractClosureExpr *)> getClosureType,
530-
llvm::function_ref<bool(const ClosureExpr *)> isolatedByPreconcurrency,
531-
llvm::function_ref<bool(Expr *)> isAssignTarget) {
532-
Type requestedType =
533-
getType(value)->getWithoutSpecifierType()->getReferenceStorageReferent();
517+
requestedType =
518+
requestedType->getWithoutSpecifierType()->getReferenceStorageReferent();
534519

535520
// Strip pack expansion types off of pack references.
536521
if (auto *expansion = requestedType->getAs<PackExpansionType>())
537522
requestedType = expansion->getPatternType();
538523

539524
// Adjust the type for concurrency if requested.
540-
if (adjustForPreconcurrency)
525+
if (adjustForPreconcurrency) {
541526
requestedType = adjustVarTypeForConcurrency(
542-
requestedType, value, UseDC, getClosureType, isolatedByPreconcurrency);
527+
requestedType, value, UseDC,
528+
GetClosureType{*this},
529+
ClosureIsolatedByPreconcurrency{*this});
530+
}
543531

544532
// If we're dealing with contextual types, and we referenced this type from
545533
// a different context, map the type.
@@ -553,7 +541,8 @@ Type ConstraintSystem::getUnopenedTypeOfReference(
553541

554542
// Qualify storage declarations with an lvalue when appropriate.
555543
// Otherwise, they yield rvalues (and the access must be a load).
556-
if (doesStorageProduceLValue(value, baseType, UseDC, isAssignTarget,
544+
if (doesStorageProduceLValue(value, baseType, UseDC,
545+
IsInLeftHandSideOfAssignment{*this},
557546
locator) &&
558547
!requestedType->hasError()) {
559548
return LValueType::get(requestedType);

0 commit comments

Comments
 (0)