Skip to content

Commit d23082f

Browse files
authored
Merge pull request #30359 from CodaFi/unopened-reference-semantics
[CS] Move getUnopenedTypeOfReference out of TypeChecker
2 parents 94ffe9a + 4e67eec commit d23082f

File tree

4 files changed

+29
-49
lines changed

4 files changed

+29
-49
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ Type ConstraintSystem::getUnopenedTypeOfReference(VarDecl *value, Type baseType,
925925
DeclContext *UseDC,
926926
const DeclRefExpr *base,
927927
bool wantInterfaceType) {
928-
return TypeChecker::getUnopenedTypeOfReference(
928+
return ConstraintSystem::getUnopenedTypeOfReference(
929929
value, baseType, UseDC,
930930
[&](VarDecl *var) -> Type {
931931
if (Type type = getTypeIfAvailable(var))
@@ -940,7 +940,7 @@ Type ConstraintSystem::getUnopenedTypeOfReference(VarDecl *value, Type baseType,
940940
base, wantInterfaceType);
941941
}
942942

943-
Type TypeChecker::getUnopenedTypeOfReference(
943+
Type ConstraintSystem::getUnopenedTypeOfReference(
944944
VarDecl *value, Type baseType, DeclContext *UseDC,
945945
llvm::function_ref<Type(VarDecl *)> getType, const DeclRefExpr *base,
946946
bool wantInterfaceType) {
@@ -1405,9 +1405,9 @@ ConstraintSystem::getTypeOfMemberReference(
14051405
->castTo<AnyFunctionType>()->getParams();
14061406
refType = FunctionType::get(indices, elementTy);
14071407
} else {
1408-
refType = TypeChecker::getUnopenedTypeOfReference(
1409-
cast<VarDecl>(value), baseTy, useDC, base,
1410-
/*wantInterfaceType=*/true);
1408+
refType =
1409+
getUnopenedTypeOfReference(cast<VarDecl>(value), baseTy, useDC, base,
1410+
/*wantInterfaceType=*/true);
14111411
}
14121412

14131413
auto selfTy = outerDC->getSelfInterfaceType();

lib/Sema/ConstraintSystem.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,6 +3260,25 @@ class ConstraintSystem {
32603260
const DeclRefExpr *base = nullptr,
32613261
bool wantInterfaceType = false);
32623262

3263+
/// Return the type-of-reference of the given value.
3264+
///
3265+
/// \param baseType if non-null, return the type of a member reference to
3266+
/// this value when the base has the given type
3267+
///
3268+
/// \param UseDC The context of the access. Some variables have different
3269+
/// types depending on where they are used.
3270+
///
3271+
/// \param base The optional base expression of this value reference
3272+
///
3273+
/// \param wantInterfaceType Whether we want the interface type, if available.
3274+
///
3275+
/// \param getType Optional callback to extract a type for given declaration.
3276+
static Type
3277+
getUnopenedTypeOfReference(VarDecl *value, Type baseType, DeclContext *UseDC,
3278+
llvm::function_ref<Type(VarDecl *)> getType,
3279+
const DeclRefExpr *base = nullptr,
3280+
bool wantInterfaceType = false);
3281+
32633282
/// Retrieve the type of a reference to the given value declaration,
32643283
/// as a member with a base of the given type.
32653284
///

lib/Sema/TypeCheckExpr.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "swift/AST/SourceFile.h"
2424
#include "swift/AST/TypeCheckRequests.h"
2525
#include "swift/Parse/Lexer.h"
26+
#include "ConstraintSystem.h"
27+
2628
using namespace swift;
2729

2830
//===----------------------------------------------------------------------===//
@@ -591,7 +593,9 @@ bool TypeChecker::requireArrayLiteralIntrinsics(ASTContext &ctx,
591593

592594
Expr *TypeChecker::buildCheckedRefExpr(VarDecl *value, DeclContext *UseDC,
593595
DeclNameLoc loc, bool Implicit) {
594-
auto type = TypeChecker::getUnopenedTypeOfReference(value, Type(), UseDC);
596+
auto type = constraints::ConstraintSystem::getUnopenedTypeOfReference(
597+
value, Type(), UseDC,
598+
[&](VarDecl *var) -> Type { return value->getType(); });
595599
auto semantics = value->getAccessSemanticsFromContext(UseDC,
596600
/*isAccessOnSelf*/false);
597601
return new (value->getASTContext())

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -989,49 +989,6 @@ class TypeChecker final {
989989
static bool contextualizeInitializer(Initializer *DC, Expr *init);
990990
static void contextualizeTopLevelCode(TopLevelCodeDecl *TLCD);
991991

992-
/// Return the type-of-reference of the given value.
993-
///
994-
/// \param baseType if non-null, return the type of a member reference to
995-
/// this value when the base has the given type
996-
///
997-
/// \param UseDC The context of the access. Some variables have different
998-
/// types depending on where they are used.
999-
///
1000-
/// \param base The optional base expression of this value reference
1001-
///
1002-
/// \param wantInterfaceType Whether we want the interface type, if available.
1003-
///
1004-
/// \param getType Optional callback to extract a type for given declaration.
1005-
static Type
1006-
getUnopenedTypeOfReference(VarDecl *value, Type baseType, DeclContext *UseDC,
1007-
llvm::function_ref<Type(VarDecl *)> getType,
1008-
const DeclRefExpr *base = nullptr,
1009-
bool wantInterfaceType = false);
1010-
1011-
/// Return the type-of-reference of the given value.
1012-
///
1013-
/// \param baseType if non-null, return the type of a member reference to
1014-
/// this value when the base has the given type
1015-
///
1016-
/// \param UseDC The context of the access. Some variables have different
1017-
/// types depending on where they are used.
1018-
///
1019-
/// \param base The optional base expression of this value reference
1020-
///
1021-
/// \param wantInterfaceType Whether we want the interface type, if available.
1022-
static Type getUnopenedTypeOfReference(VarDecl *value, Type baseType,
1023-
DeclContext *UseDC,
1024-
const DeclRefExpr *base = nullptr,
1025-
bool wantInterfaceType = false) {
1026-
return getUnopenedTypeOfReference(
1027-
value, baseType, UseDC,
1028-
[&](VarDecl *var) -> Type {
1029-
return wantInterfaceType ? value->getInterfaceType()
1030-
: value->getType();
1031-
},
1032-
base, wantInterfaceType);
1033-
}
1034-
1035992
/// Retrieve the default type for the given protocol.
1036993
///
1037994
/// Some protocols, particularly those that correspond to literals, have

0 commit comments

Comments
 (0)