Skip to content

[CS] Move getUnopenedTypeOfReference out of TypeChecker #30359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ Type ConstraintSystem::getUnopenedTypeOfReference(VarDecl *value, Type baseType,
DeclContext *UseDC,
const DeclRefExpr *base,
bool wantInterfaceType) {
return TypeChecker::getUnopenedTypeOfReference(
return ConstraintSystem::getUnopenedTypeOfReference(
value, baseType, UseDC,
[&](VarDecl *var) -> Type {
if (Type type = getTypeIfAvailable(var))
Expand All @@ -940,7 +940,7 @@ Type ConstraintSystem::getUnopenedTypeOfReference(VarDecl *value, Type baseType,
base, wantInterfaceType);
}

Type TypeChecker::getUnopenedTypeOfReference(
Type ConstraintSystem::getUnopenedTypeOfReference(
VarDecl *value, Type baseType, DeclContext *UseDC,
llvm::function_ref<Type(VarDecl *)> getType, const DeclRefExpr *base,
bool wantInterfaceType) {
Expand Down Expand Up @@ -1405,9 +1405,9 @@ ConstraintSystem::getTypeOfMemberReference(
->castTo<AnyFunctionType>()->getParams();
refType = FunctionType::get(indices, elementTy);
} else {
refType = TypeChecker::getUnopenedTypeOfReference(
cast<VarDecl>(value), baseTy, useDC, base,
/*wantInterfaceType=*/true);
refType =
getUnopenedTypeOfReference(cast<VarDecl>(value), baseTy, useDC, base,
/*wantInterfaceType=*/true);
}

auto selfTy = outerDC->getSelfInterfaceType();
Expand Down
19 changes: 19 additions & 0 deletions lib/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -3260,6 +3260,25 @@ class ConstraintSystem {
const DeclRefExpr *base = nullptr,
bool wantInterfaceType = false);

/// Return the type-of-reference of the given value.
///
/// \param baseType if non-null, return the type of a member reference to
/// this value when the base has the given type
///
/// \param UseDC The context of the access. Some variables have different
/// types depending on where they are used.
///
/// \param base The optional base expression of this value reference
///
/// \param wantInterfaceType Whether we want the interface type, if available.
///
/// \param getType Optional callback to extract a type for given declaration.
static Type
getUnopenedTypeOfReference(VarDecl *value, Type baseType, DeclContext *UseDC,
llvm::function_ref<Type(VarDecl *)> getType,
const DeclRefExpr *base = nullptr,
bool wantInterfaceType = false);

/// Retrieve the type of a reference to the given value declaration,
/// as a member with a base of the given type.
///
Expand Down
6 changes: 5 additions & 1 deletion lib/Sema/TypeCheckExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "swift/AST/SourceFile.h"
#include "swift/AST/TypeCheckRequests.h"
#include "swift/Parse/Lexer.h"
#include "ConstraintSystem.h"

using namespace swift;

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -591,7 +593,9 @@ bool TypeChecker::requireArrayLiteralIntrinsics(ASTContext &ctx,

Expr *TypeChecker::buildCheckedRefExpr(VarDecl *value, DeclContext *UseDC,
DeclNameLoc loc, bool Implicit) {
auto type = TypeChecker::getUnopenedTypeOfReference(value, Type(), UseDC);
auto type = constraints::ConstraintSystem::getUnopenedTypeOfReference(
value, Type(), UseDC,
[&](VarDecl *var) -> Type { return value->getType(); });
auto semantics = value->getAccessSemanticsFromContext(UseDC,
/*isAccessOnSelf*/false);
return new (value->getASTContext())
Expand Down
43 changes: 0 additions & 43 deletions lib/Sema/TypeChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -989,49 +989,6 @@ class TypeChecker final {
static bool contextualizeInitializer(Initializer *DC, Expr *init);
static void contextualizeTopLevelCode(TopLevelCodeDecl *TLCD);

/// Return the type-of-reference of the given value.
///
/// \param baseType if non-null, return the type of a member reference to
/// this value when the base has the given type
///
/// \param UseDC The context of the access. Some variables have different
/// types depending on where they are used.
///
/// \param base The optional base expression of this value reference
///
/// \param wantInterfaceType Whether we want the interface type, if available.
///
/// \param getType Optional callback to extract a type for given declaration.
static Type
getUnopenedTypeOfReference(VarDecl *value, Type baseType, DeclContext *UseDC,
llvm::function_ref<Type(VarDecl *)> getType,
const DeclRefExpr *base = nullptr,
bool wantInterfaceType = false);

/// Return the type-of-reference of the given value.
///
/// \param baseType if non-null, return the type of a member reference to
/// this value when the base has the given type
///
/// \param UseDC The context of the access. Some variables have different
/// types depending on where they are used.
///
/// \param base The optional base expression of this value reference
///
/// \param wantInterfaceType Whether we want the interface type, if available.
static Type getUnopenedTypeOfReference(VarDecl *value, Type baseType,
DeclContext *UseDC,
const DeclRefExpr *base = nullptr,
bool wantInterfaceType = false) {
return getUnopenedTypeOfReference(
value, baseType, UseDC,
[&](VarDecl *var) -> Type {
return wantInterfaceType ? value->getInterfaceType()
: value->getType();
},
base, wantInterfaceType);
}

/// Retrieve the default type for the given protocol.
///
/// Some protocols, particularly those that correspond to literals, have
Expand Down