Lower UDRE to TypeValue if it references a value generic

This commit is contained in:
Alejandro Alonso
2024-08-01 10:22:43 -07:00
parent 7eb93b877a
commit 0df42e9841
16 changed files with 112 additions and 82 deletions

View File

@@ -1385,8 +1385,47 @@ public:
return E->getKind() == ExprKind::Type;
}
};
class TypeValueExpr : public Expr {
TypeLoc paramTypeLoc;
public:
/// Create a \c TypeValueExpr from an underlying parameter \c TypeRepr.
TypeValueExpr(TypeRepr *paramRepr) :
Expr(ExprKind::TypeValue, /*implicit*/ false), paramTypeLoc(paramRepr) {}
/// Create a \c TypeValueExpr for a given \c TypeDecl at the specified
/// location.
///
/// The given location must be valid. If it is not, you must use
/// \c TypeExpr::createImplicitForDecl instead.
static TypeValueExpr *createForDecl(DeclNameLoc Loc, TypeDecl *D,
DeclContext *DC);
TypeRepr *getParamTypeRepr() const {
return paramTypeLoc.getTypeRepr();
}
/// Retrieves the corresponding parameter type of the value referenced by this
/// expression.
ArchetypeType *getParamType() const {
return paramTypeLoc.getType()->castTo<ArchetypeType>();
}
/// Sets the corresponding parameter type of the value referenced by this
/// expression.
void setParamType(Type paramType) {
paramTypeLoc.setType(paramType);
}
SourceRange getSourceRange() const {
return paramTypeLoc.getSourceRange();
}
static bool classof(const Expr *E) {
return E->getKind() == ExprKind::TypeValue;
}
};
/// A reference to another initializer from within a constructor body,
/// either to a delegating initializer or to a super.init invocation.
@@ -3531,18 +3570,6 @@ public:
}
};
/// The implicit conversion from a variable generic metatype to its underlying
/// value type.
class TypeValueExpr : public ImplicitConversionExpr {
public:
TypeValueExpr(Expr *subExpr, Type ty)
: ImplicitConversionExpr(ExprKind::TypeValue, subExpr, ty) {}
static bool classof(const Expr *E) {
return E->getKind() == ExprKind::TypeValue;
}
};
/// Extracts the isolation of a dynamically isolated function value.
class ExtractFunctionIsolationExpr : public Expr {
/// The function value expression from which to extract the

View File

@@ -191,8 +191,7 @@ ABSTRACT_EXPR(ImplicitConversion, Expr)
EXPR(LinearFunctionExtractOriginal, ImplicitConversionExpr)
EXPR(LinearToDifferentiableFunction, ImplicitConversionExpr)
EXPR(ActorIsolationErasure, ImplicitConversionExpr)
EXPR(TypeValue, ImplicitConversionExpr)
EXPR_RANGE(ImplicitConversion, Load, TypeValue)
EXPR_RANGE(ImplicitConversion, Load, ActorIsolationErasure)
ABSTRACT_EXPR(ExplicitCast, Expr)
ABSTRACT_EXPR(CheckedCast, ExplicitCastExpr)
EXPR(ForcedCheckedCast, CheckedCastExpr)
@@ -218,8 +217,9 @@ UNCHECKED_EXPR(OneWay, Expr)
EXPR(Tap, Expr)
UNCHECKED_EXPR(TypeJoin, Expr)
EXPR(MacroExpansion, Expr)
EXPR(TypeValue, Expr)
// Don't forget to update the LAST_EXPR below when adding a new Expr here.
LAST_EXPR(MacroExpansion)
LAST_EXPR(TypeValue)
#undef EXPR_RANGE
#undef LITERAL_EXPR