Merge pull request #13050 from davezarzycki/nfc_enum_class_TypeResolutionFlags
NFC: Use 'enum class' for TypeResolutionFlags
diff --git a/lib/Sema/CSGen.cpp b/lib/Sema/CSGen.cpp
index cdb2410..3ae6484 100644
--- a/lib/Sema/CSGen.cpp
+++ b/lib/Sema/CSGen.cpp
@@ -1329,8 +1329,8 @@
}
Type resolveTypeReferenceInExpression(TypeRepr *rep) {
- TypeResolutionOptions options = TR_AllowUnboundGenerics;
- options |= TR_InExpression;
+ TypeResolutionOptions options = TypeResolutionFlags::AllowUnboundGenerics;
+ options |= TypeResolutionFlags::InExpression;
return CS.TC.resolveType(rep, CS.DC, options);
}
@@ -1553,9 +1553,9 @@
// open type.
auto locator = CS.getConstraintLocator(expr);
for (size_t i = 0, size = specializations.size(); i < size; ++i) {
- if (tc.validateType(specializations[i], CS.DC,
- (TR_InExpression |
- TR_AllowUnboundGenerics)))
+ TypeResolutionOptions options = TypeResolutionFlags::InExpression;
+ options |= TypeResolutionFlags::AllowUnboundGenerics;
+ if (tc.validateType(specializations[i], CS.DC, options))
return Type();
CS.addConstraint(ConstraintKind::Equal,
@@ -2169,7 +2169,7 @@
pattern = pattern->getSemanticsProvidingPattern();
while (auto isp = dyn_cast<IsPattern>(pattern)) {
if (CS.TC.validateType(isp->getCastTypeLoc(), CS.DC,
- TR_InExpression))
+ TypeResolutionFlags::InExpression))
return false;
if (!isp->hasSubPattern()) {
@@ -2189,7 +2189,7 @@
Type exnType = CS.TC.getExceptionType(CS.DC, clause->getCatchLoc());
if (!exnType ||
CS.TC.coercePatternToType(pattern, CS.DC, exnType,
- TR_InExpression)) {
+ TypeResolutionFlags::InExpression)) {
return false;
}
@@ -2500,8 +2500,8 @@
return nullptr;
// Validate the resulting type.
- TypeResolutionOptions options = TR_AllowUnboundGenerics;
- options |= TR_InExpression;
+ TypeResolutionOptions options = TypeResolutionFlags::AllowUnboundGenerics;
+ options |= TypeResolutionFlags::InExpression;
if (tc.validateType(expr->getCastTypeLoc(), CS.DC, options))
return nullptr;
@@ -2523,8 +2523,8 @@
auto &tc = CS.getTypeChecker();
// Validate the resulting type.
- TypeResolutionOptions options = TR_AllowUnboundGenerics;
- options |= TR_InExpression;
+ TypeResolutionOptions options = TypeResolutionFlags::AllowUnboundGenerics;
+ options |= TypeResolutionFlags::InExpression;
if (tc.validateType(expr->getCastTypeLoc(), CS.DC, options))
return nullptr;
@@ -2548,8 +2548,8 @@
return nullptr;
// Validate the resulting type.
- TypeResolutionOptions options = TR_AllowUnboundGenerics;
- options |= TR_InExpression;
+ TypeResolutionOptions options = TypeResolutionFlags::AllowUnboundGenerics;
+ options |= TypeResolutionFlags::InExpression;
if (tc.validateType(expr->getCastTypeLoc(), CS.DC, options))
return nullptr;
@@ -2567,8 +2567,8 @@
Type visitIsExpr(IsExpr *expr) {
// Validate the type.
auto &tc = CS.getTypeChecker();
- TypeResolutionOptions options = TR_AllowUnboundGenerics;
- options |= TR_InExpression;
+ TypeResolutionOptions options = TypeResolutionFlags::AllowUnboundGenerics;
+ options |= TypeResolutionFlags::InExpression;
if (tc.validateType(expr->getCastTypeLoc(), CS.DC, options))
return nullptr;
diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp
index 2a42ea7..14c10af 100644
--- a/lib/Sema/ConstraintSystem.cpp
+++ b/lib/Sema/ConstraintSystem.cpp
@@ -893,7 +893,7 @@
if (auto typeDecl = dyn_cast<TypeDecl>(value)) {
// Resolve the reference to this type declaration in our current context.
auto type = TC.resolveTypeInContext(typeDecl, nullptr, DC,
- TR_InExpression,
+ TypeResolutionFlags::InExpression,
/*isSpecialized=*/false);
// Open the type.
diff --git a/lib/Sema/ITCDecl.cpp b/lib/Sema/ITCDecl.cpp
index fd57db4..1a3012c 100644
--- a/lib/Sema/ITCDecl.cpp
+++ b/lib/Sema/ITCDecl.cpp
@@ -37,9 +37,9 @@
inheritanceClause = typeDecl->getInherited();
if (auto nominal = dyn_cast<NominalTypeDecl>(typeDecl)) {
dc = nominal;
- options |= (TR_GenericSignature |
- TR_InheritanceClause |
- TR_AllowUnavailableProtocol);
+ options |= TypeResolutionFlags::GenericSignature;
+ options |= TypeResolutionFlags::InheritanceClause;
+ options |= TypeResolutionFlags::AllowUnavailableProtocol;
} else {
dc = typeDecl->getDeclContext();
@@ -48,13 +48,13 @@
// signature of the enclosing entity.
if (auto nominal = dyn_cast<NominalTypeDecl>(dc)) {
dc = nominal;
- options |= TR_GenericSignature;
+ options |= TypeResolutionFlags::GenericSignature;
} else if (auto ext = dyn_cast<ExtensionDecl>(dc)) {
dc = ext;
- options |= TR_GenericSignature;
+ options |= TypeResolutionFlags::GenericSignature;
} else if (auto func = dyn_cast<AbstractFunctionDecl>(dc)) {
dc = func;
- options |= TR_GenericSignature;
+ options |= TypeResolutionFlags::GenericSignature;
} else if (!dc->isModuleScopeContext()) {
// Skip the generic parameter's context entirely.
dc = dc->getParent();
@@ -65,9 +65,9 @@
auto ext = decl.get<ExtensionDecl *>();
inheritanceClause = ext->getInherited();
dc = ext;
- options |= (TR_GenericSignature |
- TR_InheritanceClause |
- TR_AllowUnavailableProtocol);
+ options |= TypeResolutionFlags::GenericSignature;
+ options |= TypeResolutionFlags::InheritanceClause;
+ options |= TypeResolutionFlags::AllowUnavailableProtocol;
}
return std::make_tuple(options, dc, inheritanceClause);
@@ -340,9 +340,10 @@
if (auto typeAliasDecl = dyn_cast<TypeAliasDecl>(typeDecl)) {
if (typeAliasDecl->getDeclContext()->isModuleScopeContext() &&
typeAliasDecl->getGenericParams() == nullptr) {
- TypeResolutionOptions options = TR_TypeAliasUnderlyingType;
+ TypeResolutionOptions options =
+ TypeResolutionFlags::TypeAliasUnderlyingType;
if (typeAliasDecl->getFormalAccess() <= AccessLevel::FilePrivate)
- options |= TR_KnownNonCascadingDependency;
+ options |= TypeResolutionFlags::KnownNonCascadingDependency;
// Note: recursion into old type checker is okay when passing in an
// unsatisfied-dependency callback.
diff --git a/lib/Sema/ITCType.cpp b/lib/Sema/ITCType.cpp
index 7033d9f..598fbb6 100644
--- a/lib/Sema/ITCType.cpp
+++ b/lib/Sema/ITCType.cpp
@@ -54,7 +54,7 @@
// If we're only looking to resolve the structure of the type,
// don't walk into generic arguments. They don't affect the
// structure.
- if (Options.contains(TR_ResolveStructure) &&
+ if (Options.contains(TypeResolutionFlags::ResolveStructure) &&
isa<GenericIdentTypeRepr>(ident))
return false;
}
diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp
index 173a587..eeebf92 100644
--- a/lib/Sema/TypeCheckAttr.cpp
+++ b/lib/Sema/TypeCheckAttr.cpp
@@ -1979,8 +1979,7 @@
void AttributeChecker::visitImplementsAttr(ImplementsAttr *attr) {
TypeLoc &ProtoTypeLoc = attr->getProtocolType();
- TypeResolutionOptions options;
- options |= TR_AllowUnboundGenerics;
+ auto options = TypeResolutionFlags::AllowUnboundGenerics;
DeclContext *DC = D->getDeclContext();
Type T = TC.resolveType(ProtoTypeLoc.getTypeRepr(),
diff --git a/lib/Sema/TypeCheckConstraints.cpp b/lib/Sema/TypeCheckConstraints.cpp
index a627797..ab4641d 100644
--- a/lib/Sema/TypeCheckConstraints.cpp
+++ b/lib/Sema/TypeCheckConstraints.cpp
@@ -1009,10 +1009,10 @@
// Validate the parameters.
TypeResolutionOptions options;
- options |= TR_AllowUnspecifiedTypes;
- options |= TR_AllowUnboundGenerics;
- options |= TR_InExpression;
- options |= TR_AllowIUO;
+ options |= TypeResolutionFlags::AllowUnspecifiedTypes;
+ options |= TypeResolutionFlags::AllowUnboundGenerics;
+ options |= TypeResolutionFlags::InExpression;
+ options |= TypeResolutionFlags::AllowIUO;
bool hadParameterError = false;
GenericTypeToArchetypeResolver resolver(closure);
@@ -1030,7 +1030,7 @@
// Validate the result type, if present.
if (closure->hasExplicitResultType() &&
TC.validateType(closure->getExplicitResultTypeLoc(), DC,
- TR_InExpression, &resolver)) {
+ TypeResolutionFlags::InExpression, &resolver)) {
closure->setType(ErrorType::get(TC.Context));
return false;
}
@@ -1112,9 +1112,9 @@
// Resolve the TypeRepr to get the base type for the lookup.
// Disable availability diagnostics here, because the final
// TypeRepr will be resolved again when generating constraints.
- TypeResolutionOptions options = TR_AllowUnboundGenerics;
- options |= TR_InExpression;
- options |= TR_AllowUnavailable;
+ TypeResolutionOptions options = TypeResolutionFlags::AllowUnboundGenerics;
+ options |= TypeResolutionFlags::InExpression;
+ options |= TypeResolutionFlags::AllowUnavailable;
auto BaseTy = TC.resolveType(InnerTypeRepr, DC, options);
if (BaseTy && BaseTy->mayHaveMembers()) {
@@ -2210,11 +2210,10 @@
}
if (resultTy) {
- TypeResolutionOptions options;
- options |= TR_OverrideType;
- options |= TR_InExpression;
+ TypeResolutionOptions options = TypeResolutionFlags::OverrideType;
+ options |= TypeResolutionFlags::InExpression;
if (isa<EditorPlaceholderExpr>(initializer->getSemanticsProvidingExpr())) {
- options |= TR_EditorPlaceholder;
+ options |= TypeResolutionFlags::EditorPlaceholder;
}
// FIXME: initTy should be the same as resultTy; now that typeCheckExpression()
@@ -2433,10 +2432,9 @@
// Apply the solution to the iteration pattern as well.
Pattern *pattern = Stmt->getPattern();
- TypeResolutionOptions options;
- options |= TR_OverrideType;
- options |= TR_EnumerationVariable;
- options |= TR_InExpression;
+ TypeResolutionOptions options = TypeResolutionFlags::OverrideType;
+ options |= TypeResolutionFlags::EnumerationVariable;
+ options |= TypeResolutionFlags::InExpression;
if (tc.coercePatternToType(pattern, cs.DC, InitType, options)) {
return nullptr;
}
@@ -2606,9 +2604,9 @@
// Check the pattern, it allows unspecified types because the pattern can
// provide type information.
- TypeResolutionOptions options = TR_InExpression;
- options |= TR_AllowUnspecifiedTypes;
- options |= TR_AllowUnboundGenerics;
+ TypeResolutionOptions options = TypeResolutionFlags::InExpression;
+ options |= TypeResolutionFlags::AllowUnspecifiedTypes;
+ options |= TypeResolutionFlags::AllowUnboundGenerics;
if (typeCheckPattern(pattern, dc, options)) {
typeCheckPatternFailed();
continue;
diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp
index f37dcf3..3bf3270 100644
--- a/lib/Sema/TypeCheckDecl.cpp
+++ b/lib/Sema/TypeCheckDecl.cpp
@@ -297,27 +297,27 @@
DeclContext *DC;
if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) {
DC = nominal;
- options |= (TR_GenericSignature |
- TR_InheritanceClause |
- TR_AllowUnavailableProtocol);
+ options |= TypeResolutionFlags::GenericSignature;
+ options |= TypeResolutionFlags::InheritanceClause;
+ options |= TypeResolutionFlags::AllowUnavailableProtocol;
} else if (auto ext = dyn_cast<ExtensionDecl>(decl)) {
DC = ext;
- options |= (TR_GenericSignature |
- TR_InheritanceClause |
- TR_AllowUnavailableProtocol);
+ options |= TypeResolutionFlags::GenericSignature;
+ options |= TypeResolutionFlags::InheritanceClause;
+ options |= TypeResolutionFlags::AllowUnavailableProtocol;
} else if (isa<GenericTypeParamDecl>(decl)) {
// For generic parameters, we want name lookup to look at just the
// signature of the enclosing entity.
DC = decl->getDeclContext();
if (auto nominal = dyn_cast<NominalTypeDecl>(DC)) {
DC = nominal;
- options |= TR_GenericSignature;
+ options |= TypeResolutionFlags::GenericSignature;
} else if (auto ext = dyn_cast<ExtensionDecl>(DC)) {
DC = ext;
- options |= TR_GenericSignature;
+ options |= TypeResolutionFlags::GenericSignature;
} else if (auto func = dyn_cast<AbstractFunctionDecl>(DC)) {
DC = func;
- options |= TR_GenericSignature;
+ options |= TypeResolutionFlags::GenericSignature;
} else if (!DC->isModuleScopeContext()) {
// Skip the generic parameter's context entirely.
DC = DC->getParent();
@@ -1117,13 +1117,13 @@
// In particular, it's /not/ correct to check the PBD's DeclContext because
// top-level variables in a script file are accessible from other files,
// even though the PBD is inside a TopLevelCodeDecl.
- TypeResolutionOptions options = TR_InExpression;
+ TypeResolutionOptions options = TypeResolutionFlags::InExpression;
- options |= TR_AllowIUO;
+ options |= TypeResolutionFlags::AllowIUO;
if (binding->getInit(entryNumber)) {
// If we have an initializer, we can also have unknown types.
- options |= TR_AllowUnspecifiedTypes;
- options |= TR_AllowUnboundGenerics;
+ options |= TypeResolutionFlags::AllowUnspecifiedTypes;
+ options |= TypeResolutionFlags::AllowUnboundGenerics;
}
if (tc.typeCheckPattern(pattern, binding->getDeclContext(), options)) {
setBoundVarsTypeError(pattern, tc.Context);
@@ -4284,10 +4284,10 @@
GenericTypeToArchetypeResolver resolver(SD);
bool isInvalid = TC.validateType(SD->getElementTypeLoc(), SD,
- TR_AllowIUO,
+ TypeResolutionFlags::AllowIUO,
&resolver);
TypeResolutionOptions options;
- options |= TR_SubscriptParameters;
+ options |= TypeResolutionFlags::SubscriptParameters;
isInvalid |= TC.typeCheckParameterList(SD->getIndices(), SD,
options,
@@ -4863,9 +4863,9 @@
bool badType = false;
if (!FD->getBodyResultTypeLoc().isNull()) {
- TypeResolutionOptions options = TR_AllowIUO;
+ TypeResolutionOptions options = TypeResolutionFlags::AllowIUO;
if (FD->hasDynamicSelf())
- options |= TR_DynamicSelfResult;
+ options |= TypeResolutionFlags::DynamicSelfResult;
if (TC.validateType(FD->getBodyResultTypeLoc(), FD, options,
&resolver)) {
@@ -6830,7 +6830,7 @@
if (!EED->getArgumentTypeLoc().isNull()) {
if (TC.validateType(EED->getArgumentTypeLoc(), EED->getDeclContext(),
- TR_EnumCase)) {
+ TypeResolutionFlags::EnumCase)) {
EED->setInterfaceType(ErrorType::get(TC.Context));
EED->setInvalid();
return;
@@ -7357,9 +7357,9 @@
/// Validate the underlying type of the given typealias.
static void validateTypealiasType(TypeChecker &tc, TypeAliasDecl *typeAlias) {
- TypeResolutionOptions options = TR_TypeAliasUnderlyingType;
+ TypeResolutionOptions options = TypeResolutionFlags::TypeAliasUnderlyingType;
if (typeAlias->getFormalAccess() <= AccessLevel::FilePrivate)
- options |= TR_KnownNonCascadingDependency;
+ options |= TypeResolutionFlags::KnownNonCascadingDependency;
if (typeAlias->getDeclContext()->isModuleScopeContext() &&
typeAlias->getGenericParams() == nullptr) {
@@ -7842,7 +7842,7 @@
validateAccessControl(typealias);
if (typealias->getFormalAccess() <= AccessLevel::FilePrivate)
- options |= TR_KnownNonCascadingDependency;
+ options |= TypeResolutionFlags::KnownNonCascadingDependency;
if (validateType(typealias->getUnderlyingTypeLoc(),
typealias, options, &resolver)) {
diff --git a/lib/Sema/TypeCheckGeneric.cpp b/lib/Sema/TypeCheckGeneric.cpp
index b09966c..9feb689 100644
--- a/lib/Sema/TypeCheckGeneric.cpp
+++ b/lib/Sema/TypeCheckGeneric.cpp
@@ -262,7 +262,7 @@
isa<AbstractFunctionDecl>(lookupDC) ||
isa<SubscriptDecl>(lookupDC)) &&
"not a proper generic parameter context?");
- options = TR_GenericSignature;
+ options = TypeResolutionFlags::GenericSignature;
}
// First, add the generic parameters to the generic signature builder.
@@ -513,9 +513,9 @@
if (auto fn = dyn_cast<FuncDecl>(func)) {
if (!fn->getBodyResultTypeLoc().isNull()) {
// Check the result type of the function.
- TypeResolutionOptions options = TR_AllowIUO;
+ TypeResolutionOptions options = TypeResolutionFlags::AllowIUO;
if (fn->hasDynamicSelf())
- options |= TR_DynamicSelfResult;
+ options |= TypeResolutionFlags::DynamicSelfResult;
if (tc.validateType(fn->getBodyResultTypeLoc(), fn, options, &resolver)) {
badType = true;
@@ -973,7 +973,7 @@
// Check the element type.
badType |= tc.validateType(subscript->getElementTypeLoc(), subscript,
- TR_AllowIUO, &resolver);
+ TypeResolutionFlags::AllowIUO, &resolver);
// Infer requirements from it.
if (genericParams && builder) {
@@ -988,9 +988,7 @@
// Check the indices.
auto params = subscript->getIndices();
-
- TypeResolutionOptions options;
- options |= TR_SubscriptParameters;
+ TypeResolutionOptions options = TypeResolutionFlags::SubscriptParameters;
badType |= tc.typeCheckParameterList(params, subscript,
options,
diff --git a/lib/Sema/TypeCheckPattern.cpp b/lib/Sema/TypeCheckPattern.cpp
index 8d3e48f..215098f 100644
--- a/lib/Sema/TypeCheckPattern.cpp
+++ b/lib/Sema/TypeCheckPattern.cpp
@@ -430,7 +430,8 @@
auto *repr = IdentTypeRepr::create(TC.Context, components);
// See if the repr resolves to a type.
- Type ty = TC.resolveIdentifierType(DC, repr, TR_AllowUnboundGenerics,
+ Type ty = TC.resolveIdentifierType(DC, repr,
+ TypeResolutionFlags::AllowUnboundGenerics,
/*diagnoseErrors*/false, &resolver,
nullptr);
@@ -549,7 +550,7 @@
auto *prefixRepr = IdentTypeRepr::create(TC.Context, components);
// See first if the entire repr resolves to a type.
Type enumTy = TC.resolveIdentifierType(DC, prefixRepr,
- TR_AllowUnboundGenerics,
+ TypeResolutionFlags::AllowUnboundGenerics,
/*diagnoseErrors*/false, &resolver,
nullptr);
if (!dyn_cast_or_null<EnumDecl>(enumTy->getAnyNominal()))
@@ -709,11 +710,11 @@
// If the element is a variadic parameter, resolve the parameter type as if
// it were in non-parameter position, since we want functions to be
// @escaping in this case.
- auto elementOptions = (options |
- (decl->isVariadic() ? TR_VariadicFunctionInput
- : TR_FunctionInput));
+ auto elementOptions = (options | (decl->isVariadic()
+ ? TypeResolutionFlags::VariadicFunctionInput
+ : TypeResolutionFlags::FunctionInput));
if (!decl->isVariadic())
- elementOptions |= TR_AllowIUO;
+ elementOptions |= TypeResolutionFlags::AllowIUO;
bool hadError = false;
@@ -778,7 +779,7 @@
// as well to get the ParamDecl marked invalid and to get an ErrorType.
if (!type) {
// Closure argument lists are allowed to be missing types.
- if (options & TR_InExpression)
+ if (options & TypeResolutionFlags::InExpression)
continue;
param->setInvalid();
}
@@ -847,8 +848,8 @@
Pattern *subPattern = TP->getSubPattern();
if (coercePatternToType(subPattern, dc, P->getType(),
- options|TR_FromNonInferredPattern, &resolver,
- TP->getTypeLoc()))
+ options|TypeResolutionFlags::FromNonInferredPattern,
+ &resolver, TP->getTypeLoc()))
hadError = true;
else {
TP->setSubPattern(subPattern);
@@ -863,7 +864,7 @@
case PatternKind::Named:
// If we're type checking this pattern in a context that can provide type
// information, then the lack of type information is not an error.
- if (options & TR_AllowUnspecifiedTypes)
+ if (options & TypeResolutionFlags::AllowUnspecifiedTypes)
return false;
diagnose(P->getLoc(), diag::cannot_infer_type_for_pattern);
@@ -884,8 +885,8 @@
// If this is the top level of a function input list, peel off the
// ImmediateFunctionInput marker and install a FunctionInput one instead.
auto elementOptions = withoutContext(options);
- if (options & TR_ImmediateFunctionInput)
- elementOptions |= TR_FunctionInput;
+ if (options & TypeResolutionFlags::ImmediateFunctionInput)
+ elementOptions |= TypeResolutionFlags::FunctionInput;
bool missingType = false;
for (unsigned i = 0, e = tuplePat->getNumElements(); i != e; ++i) {
@@ -907,7 +908,8 @@
P->setType(ErrorType::get(Context));
return true;
}
- if (!missingType && !(options & TR_AllowUnspecifiedTypes)) {
+ if (!missingType && !(options &
+ TypeResolutionFlags::AllowUnspecifiedTypes)) {
P->setType(TupleType::get(typeElts, Context));
}
return false;
@@ -923,7 +925,7 @@
case PatternKind::Bool:
case PatternKind::Expr:
// In a let/else, these always require an initial value to match against.
- if (!(options & TR_AllowUnspecifiedTypes)) {
+ if (!(options & TypeResolutionFlags::AllowUnspecifiedTypes)) {
diagnose(P->getLoc(), diag::refutable_pattern_requires_initializer);
P->setType(ErrorType::get(Context));
return true;
@@ -944,7 +946,7 @@
tyLoc = TypeLoc::withoutLoc(type);
}
- TypeResolutionOptions subOptions = options - TR_EnumPatternPayload;
+ auto subOptions = options - TypeResolutionFlags::EnumPatternPayload;
switch (P->getKind()) {
// For parens and vars, just set the type annotation and propagate inwards.
case PatternKind::Paren: {
@@ -954,7 +956,7 @@
// If this is the payload of an enum, and the type is a single-element
// labeled tuple, treat this as a tuple pattern. It's unlikely that the
// user is interested in binding a variable of type (foo: Int).
- if ((options & TR_EnumPatternPayload)
+ if ((options & TypeResolutionFlags::EnumPatternPayload)
&& !isa<TuplePattern>(semantic)) {
if (auto tupleType = type->getAs<TupleType>()) {
if (tupleType->getNumElements() == 1
@@ -998,7 +1000,7 @@
bool hadError = validateTypedPattern(*this, dc, TP, options, resolver);
if (!hadError) {
if (!type->isEqual(TP->getType()) && !type->hasError()) {
- if (options & TR_OverrideType) {
+ if (options & TypeResolutionFlags::OverrideType) {
TP->setType(type);
} else {
diagnose(P->getLoc(), diag::pattern_type_mismatch_context, type);
@@ -1009,7 +1011,7 @@
Pattern *sub = TP->getSubPattern();
hadError |= coercePatternToType(sub, dc, TP->getType(),
- subOptions | TR_FromNonInferredPattern,
+ subOptions | TypeResolutionFlags::FromNonInferredPattern,
resolver);
if (!hadError) {
TP->setSubPattern(sub);
@@ -1061,9 +1063,9 @@
}
if (shouldRequireType &&
- !(options & TR_FromNonInferredPattern) &&
- !(options & TR_EnumerationVariable) &&
- !(options & TR_EditorPlaceholder)) {
+ !(options & TypeResolutionFlags::FromNonInferredPattern) &&
+ !(options & TypeResolutionFlags::EnumerationVariable) &&
+ !(options & TypeResolutionFlags::EditorPlaceholder)) {
diagnose(NP->getLoc(), diag::type_inferred_to_undesirable_type,
NP->getDecl()->getName(), type, NP->getDecl()->isLet());
diagnose(NP->getLoc(), diag::add_explicit_type_annotation_to_silence);
@@ -1189,7 +1191,8 @@
auto IP = cast<IsPattern>(P);
// Type-check the type parameter.
- if (validateType(IP->getCastTypeLoc(), dc, TR_InExpression))
+ if (validateType(IP->getCastTypeLoc(), dc,
+ TypeResolutionFlags::InExpression))
return true;
auto castType = IP->getCastTypeLoc().getType();
@@ -1268,7 +1271,7 @@
// Coerce the subpattern to the destination type.
if (Pattern *sub = IP->getSubPattern()) {
if (coercePatternToType(sub, dc, IP->getCastTypeLoc().getType(),
- subOptions|TR_FromNonInferredPattern))
+ subOptions|TypeResolutionFlags::FromNonInferredPattern))
return true;
IP->setSubPattern(sub);
}
@@ -1398,8 +1401,9 @@
elt, argType);
else
elementType = TupleType::getEmpty(Context);
- if (coercePatternToType(sub, dc, elementType,
- subOptions|TR_FromNonInferredPattern|TR_EnumPatternPayload,
+ if (coercePatternToType(sub, dc, elementType, subOptions
+ | TypeResolutionFlags::FromNonInferredPattern
+ | TypeResolutionFlags::EnumPatternPayload,
resolver))
return true;
EEP->setSubPattern(sub);
@@ -1427,8 +1431,9 @@
Pattern *sub = TuplePattern::createSimple(Context, SourceLoc(),
elements, SourceLoc(),
/*implicit*/true);
- if (coercePatternToType(sub, dc, elementType,
- subOptions|TR_FromNonInferredPattern|TR_EnumPatternPayload,
+ if (coercePatternToType(sub, dc, elementType, subOptions
+ | TypeResolutionFlags::FromNonInferredPattern
+ | TypeResolutionFlags::EnumPatternPayload,
resolver))
return true;
EEP->setSubPattern(sub);
@@ -1480,8 +1485,9 @@
OP->setElementDecl(elementDecl);
Pattern *sub = OP->getSubPattern();
- if (coercePatternToType(sub, dc, elementType,
- subOptions|TR_FromNonInferredPattern|TR_EnumPatternPayload,
+ if (coercePatternToType(sub, dc, elementType, subOptions
+ | TypeResolutionFlags::FromNonInferredPattern
+ | TypeResolutionFlags::EnumPatternPayload,
resolver))
return true;
OP->setSubPattern(sub);
diff --git a/lib/Sema/TypeCheckStmt.cpp b/lib/Sema/TypeCheckStmt.cpp
index e70f6d6..0f7f6d8 100644
--- a/lib/Sema/TypeCheckStmt.cpp
+++ b/lib/Sema/TypeCheckStmt.cpp
@@ -555,9 +555,9 @@
Stmt *visitForEachStmt(ForEachStmt *S) {
TypeResolutionOptions options;
- options |= TR_AllowUnspecifiedTypes;
- options |= TR_AllowUnboundGenerics;
- options |= TR_InExpression;
+ options |= TypeResolutionFlags::AllowUnspecifiedTypes;
+ options |= TypeResolutionFlags::AllowUnboundGenerics;
+ options |= TypeResolutionFlags::InExpression;
if (auto *P = TC.resolvePattern(S->getPattern(), DC,
/*isStmtCondition*/false)) {
@@ -856,7 +856,7 @@
pattern = newPattern;
// Coerce the pattern to the subject's type.
if (!subjectType || TC.coercePatternToType(pattern, DC, subjectType,
- TR_InExpression)) {
+ TypeResolutionFlags::InExpression)) {
hadError = true;
// If that failed, mark any variables binding pieces of the pattern
@@ -977,7 +977,8 @@
// Coerce the pattern to the exception type.
if (!exnType ||
- coercePatternToType(pattern, DC, exnType, TR_InExpression)) {
+ coercePatternToType(pattern, DC, exnType,
+ TypeResolutionFlags::InExpression)) {
// If that failed, be sure to give the variables error types
// before we type-check the guard. (This will probably kill
// most of the type-checking, but maybe not.)
diff --git a/lib/Sema/TypeCheckType.cpp b/lib/Sema/TypeCheckType.cpp
index 49b4fd8..28d1106 100644
--- a/lib/Sema/TypeCheckType.cpp
+++ b/lib/Sema/TypeCheckType.cpp
@@ -441,7 +441,7 @@
}
// In SIL mode, Optional<T> interprets T as a SIL type.
- if (options.contains(TR_SILType)) {
+ if (options.contains(TypeResolutionFlags::SILType)) {
if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) {
if (nominal->classifyAsOptionalType()) {
// Validate the generic argument.
@@ -459,7 +459,7 @@
}
// Cannot extend a bound generic type.
- if (options.contains(TR_ExtensionBinding)) {
+ if (options.contains(TypeResolutionFlags::ExtensionBinding)) {
diagnose(loc, diag::extension_specialization,
genericDecl->getName())
.highlight(generic->getSourceRange());
@@ -504,12 +504,12 @@
GenericTypeResolver *resolver,
UnsatisfiedDependency *unsatisfiedDependency) {
- options -= TR_SILType;
- options -= TR_ImmediateFunctionInput;
- options -= TR_FunctionInput;
- options -= TR_TypeAliasUnderlyingType;
- options -= TR_AllowUnavailableProtocol;
- options -= TR_AllowIUO;
+ options -= TypeResolutionFlags::SILType;
+ options -= TypeResolutionFlags::ImmediateFunctionInput;
+ options -= TypeResolutionFlags::FunctionInput;
+ options -= TypeResolutionFlags::TypeAliasUnderlyingType;
+ options -= TypeResolutionFlags::AllowUnavailableProtocol;
+ options -= TypeResolutionFlags::AllowIUO;
assert(genericArgs.size() == decl->getGenericParams()->size() &&
"invalid arguments, use applyGenericArguments for diagnostic emitting");
@@ -687,7 +687,7 @@
assert(fromDC && "No declaration context for type resolution?");
// Don't validate nominal type declarations during extension binding.
- if (!options.contains(TR_ExtensionBinding) ||
+ if (!options.contains(TypeResolutionFlags::ExtensionBinding) ||
!isa<NominalTypeDecl>(typeDecl)) {
// If we have a callback to report dependencies, do so.
if (unsatisfiedDependency) {
@@ -715,9 +715,9 @@
generic, resolver);
if (type->is<UnboundGenericType>() && !generic &&
- !options.contains(TR_AllowUnboundGenerics) &&
- !options.contains(TR_TypeAliasUnderlyingType) &&
- !options.contains(TR_ResolveStructure)) {
+ !options.contains(TypeResolutionFlags::AllowUnboundGenerics) &&
+ !options.contains(TypeResolutionFlags::TypeAliasUnderlyingType) &&
+ !options.contains(TypeResolutionFlags::ResolveStructure)) {
diagnoseUnboundGenericType(TC, type, loc);
return ErrorType::get(TC.Context);
}
@@ -728,7 +728,7 @@
loc, cast<AssociatedTypeDecl>(typeDecl));
}
- if (generic && !options.contains(TR_ResolveStructure)) {
+ if (generic && !options.contains(TypeResolutionFlags::ResolveStructure)) {
// Apply the generic arguments to the type.
type = TC.applyGenericArguments(type, typeDecl, loc, fromDC, generic,
options, resolver, unsatisfiedDependency);
@@ -826,7 +826,7 @@
// Try ignoring access control.
DeclContext *lookupDC = dc;
- if (options.contains(TR_GenericSignature))
+ if (options.contains(TypeResolutionFlags::GenericSignature))
lookupDC = dc->getParentForLookup();
NameLookupOptions relookupOptions = lookupOptions;
@@ -1090,7 +1090,7 @@
DeclContext *lookupDC = DC;
// Dynamic 'Self' in the result type of a function body.
- if (options.contains(TR_DynamicSelfResult) &&
+ if (options.contains(TypeResolutionFlags::DynamicSelfResult) &&
comp->getIdentifier() == TC.Context.Id_Self) {
auto func = cast<FuncDecl>(DC);
assert(func->hasDynamicSelf() && "Not marked as having dynamic Self?");
@@ -1106,7 +1106,7 @@
// For lookups within the generic signature, look at the generic
// parameters (only), then move up to the enclosing context.
- if (options.contains(TR_GenericSignature)) {
+ if (options.contains(TypeResolutionFlags::GenericSignature)) {
Type type = resolveGenericSignatureComponent(
TC, DC, comp, options, diagnoseErrors, resolver,
unsatisfiedDependency);
@@ -1114,7 +1114,7 @@
return type;
if (!DC->isCascadingContextForLookup(/*excludeFunctions*/false))
- options |= TR_KnownNonCascadingDependency;
+ options |= TypeResolutionFlags::KnownNonCascadingDependency;
lookupDC = DC->getParentForLookup();
}
@@ -1134,12 +1134,12 @@
// ImplicitlyUnwrappedOptional where it is not allowed, treat it as
// if it was spelled Optional.
if (id == TC.Context.Id_ImplicitlyUnwrappedOptional
- && !options.contains(TR_AllowIUO)
+ && !options.contains(TypeResolutionFlags::AllowIUO)
&& !TC.Context.isSwiftVersionAtLeast(5))
id = TC.Context.Id_Optional;
NameLookupOptions lookupOptions = defaultUnqualifiedLookupOptions;
- if (options.contains(TR_KnownNonCascadingDependency))
+ if (options.contains(TypeResolutionFlags::KnownNonCascadingDependency))
lookupOptions |= NameLookupFlags::KnownPrivate;
auto globals = TC.lookupUnqualifiedType(lookupDC,
id,
@@ -1207,7 +1207,7 @@
// Emit diagnostics related to ImplicitlyUnwrappedOptional.
if (comp->getIdentifier() == TC.Context.Id_ImplicitlyUnwrappedOptional) {
- if (options.contains(TR_AllowIUO)) {
+ if (options.contains(TypeResolutionFlags::AllowIUO)) {
if (isa<GenericIdentTypeRepr>(comp)) {
auto *genericTyR = cast<GenericIdentTypeRepr>(comp);
assert(genericTyR->getGenericArgs().size() == 1);
@@ -1319,7 +1319,7 @@
// Only the last component of the underlying type of a type alias may
// be an unbound generic.
- if (options & TR_TypeAliasUnderlyingType) {
+ if (options & TypeResolutionFlags::TypeAliasUnderlyingType) {
if (parentTy->is<UnboundGenericType>()) {
if (diagnoseErrors)
diagnoseUnboundGenericType(TC, parentTy, parentRange.End);
@@ -1351,9 +1351,9 @@
}
if (memberType->is<UnboundGenericType>() &&
- !options.contains(TR_AllowUnboundGenerics) &&
- !options.contains(TR_TypeAliasUnderlyingType) &&
- !options.contains(TR_ResolveStructure)) {
+ !options.contains(TypeResolutionFlags::AllowUnboundGenerics) &&
+ !options.contains(TypeResolutionFlags::TypeAliasUnderlyingType) &&
+ !options.contains(TypeResolutionFlags::ResolveStructure)) {
diagnoseUnboundGenericType(TC, memberType, comp->getLoc());
return ErrorType::get(TC.Context);
}
@@ -1383,8 +1383,8 @@
// Phase 1: Find and bind the component decl.
// Look for member types with the given name.
- bool isKnownNonCascading = options.contains(TR_KnownNonCascadingDependency);
- if (!isKnownNonCascading && options.contains(TR_InExpression)) {
+ bool isKnownNonCascading = options.contains(TypeResolutionFlags::KnownNonCascadingDependency);
+ if (!isKnownNonCascading && options.contains(TypeResolutionFlags::InExpression)) {
// Expressions cannot affect a function's signature.
isKnownNonCascading = isa<AbstractFunctionDecl>(DC);
}
@@ -1409,9 +1409,9 @@
NameLookupOptions lookupOptions = defaultMemberLookupOptions;
if (isKnownNonCascading)
lookupOptions |= NameLookupFlags::KnownPrivate;
- // FIXME: Lift the restriction for TR_InheritanceClause
- if (options.contains(TR_ExtensionBinding) ||
- options.contains(TR_InheritanceClause))
+ // FIXME: Lift the restriction for TypeResolutionFlags::InheritanceClause
+ if (options.contains(TypeResolutionFlags::ExtensionBinding) ||
+ options.contains(TypeResolutionFlags::InheritanceClause))
lookupOptions -= NameLookupFlags::ProtocolMembers;
LookupTypeResult memberTypes;
if (parentTy->mayHaveMembers())
@@ -1519,8 +1519,8 @@
TypeResolutionOptions options) {
// Remember whether this is a function parameter.
bool isFunctionParam =
- options.contains(TR_FunctionInput) ||
- options.contains(TR_ImmediateFunctionInput);
+ options.contains(TypeResolutionFlags::FunctionInput) ||
+ options.contains(TypeResolutionFlags::ImmediateFunctionInput);
bool defaultNoEscape = isFunctionParam;
@@ -1587,9 +1587,9 @@
// To support this, inside inheritance clauses we allow references to
// protocols that are unavailable in the current type refinement context.
- if (!(options & TR_AllowUnavailable) &&
+ if (!(options & TypeResolutionFlags::AllowUnavailable) &&
diagnoseAvailability(IdType, DC, *this,
- options.contains(TR_AllowUnavailableProtocol))) {
+ options.contains(TypeResolutionFlags::AllowUnavailableProtocol))) {
Components.back()->setInvalid();
return ErrorType::get(Context);
}
@@ -1622,7 +1622,8 @@
type = ErrorType::get(Context);
// Diagnose types that are illegal in SIL.
- } else if (options.contains(TR_SILType) && !type->isLegalSILType()) {
+ } else if (options.contains(TypeResolutionFlags::SILType)
+ && !type->isLegalSILType()) {
diagnose(Loc.getLoc(), diag::illegal_sil_type, type);
Loc.setType(ErrorType::get(Context), true);
return true;
@@ -1755,13 +1756,13 @@
!isa<AttributedTypeRepr>(repr) &&
!isa<FunctionTypeRepr>(repr) &&
!isa<IdentTypeRepr>(repr)) {
- options -= TR_ImmediateFunctionInput;
- options -= TR_FunctionInput;
- options -= TR_TypeAliasUnderlyingType;
+ options -= TypeResolutionFlags::ImmediateFunctionInput;
+ options -= TypeResolutionFlags::FunctionInput;
+ options -= TypeResolutionFlags::TypeAliasUnderlyingType;
}
if (Context.LangOpts.DisableAvailabilityChecking)
- options |= TR_AllowUnavailable;
+ options |= TypeResolutionFlags::AllowUnavailable;
switch (repr->getKind()) {
case TypeReprKind::Error:
@@ -1781,7 +1782,7 @@
UnsatisfiedDependency);
case TypeReprKind::Function: {
- if (!(options & TR_SILType)) {
+ if (!(options & TypeResolutionFlags::SILType)) {
// Default non-escaping for closure parameters
auto result =
resolveASTFunctionType(cast<FunctionTypeRepr>(repr), options);
@@ -1792,7 +1793,7 @@
return resolveSILFunctionType(cast<FunctionTypeRepr>(repr), options);
}
case TypeReprKind::SILBox:
- assert((options & TR_SILType) && "SILBox repr in non-SIL type context?!");
+ assert((options & TypeResolutionFlags::SILType) && "SILBox repr in non-SIL type context?!");
return resolveSILBoxType(cast<SILBoxTypeRepr>(repr), options);
case TypeReprKind::Array:
@@ -1863,10 +1864,10 @@
// Remember whether this is a function parameter.
bool isFunctionParam =
- options.contains(TR_FunctionInput) ||
- options.contains(TR_ImmediateFunctionInput);
+ options.contains(TypeResolutionFlags::FunctionInput) ||
+ options.contains(TypeResolutionFlags::ImmediateFunctionInput);
bool isVariadicFunctionParam =
- options.contains(TR_VariadicFunctionInput);
+ options.contains(TypeResolutionFlags::VariadicFunctionInput);
// The type we're working with, in case we want to build it differently
// based on the attributes we see.
@@ -1891,10 +1892,10 @@
Optional<MetatypeRepresentation> storedRepr;
// The instance type is not a SIL type.
auto instanceOptions = options;
- instanceOptions -= TR_SILType;
- instanceOptions -= TR_ImmediateFunctionInput;
- instanceOptions -= TR_FunctionInput;
- instanceOptions -= TR_TypeAliasUnderlyingType;
+ instanceOptions -= TypeResolutionFlags::SILType;
+ instanceOptions -= TypeResolutionFlags::ImmediateFunctionInput;
+ instanceOptions -= TypeResolutionFlags::FunctionInput;
+ instanceOptions -= TypeResolutionFlags::TypeAliasUnderlyingType;
auto instanceTy = resolveType(base, instanceOptions);
if (!instanceTy || instanceTy->hasError())
@@ -1956,7 +1957,7 @@
// Some function representation attributes are not supported at source level;
// only SIL knows how to handle them. Reject them unless this is a SIL input.
- if (!(options & TR_SILType)) {
+ if (!(options & TypeResolutionFlags::SILType)) {
for (auto silOnlyAttr : {TAK_callee_owned, TAK_callee_guaranteed}) {
checkUnsupportedAttr(silOnlyAttr);
}
@@ -1988,7 +1989,7 @@
attrs.clearAttribute(TAK_autoclosure);
}
// Fall through to diagnose below.
- } else if (hasFunctionAttr && (options & TR_SILType)) {
+ } else if (hasFunctionAttr && (options & TypeResolutionFlags::SILType)) {
SILFunctionType::Representation rep;
TypeRepr *witnessMethodProtocol = nullptr;
@@ -2109,9 +2110,9 @@
}
auto instanceOptions = options;
- instanceOptions -= TR_ImmediateFunctionInput;
- instanceOptions -= TR_FunctionInput;
- instanceOptions -= TR_TypeAliasUnderlyingType;
+ instanceOptions -= TypeResolutionFlags::ImmediateFunctionInput;
+ instanceOptions -= TypeResolutionFlags::FunctionInput;
+ instanceOptions -= TypeResolutionFlags::TypeAliasUnderlyingType;
// If we didn't build the type differently above, we might have
// a typealias pointing at a function type with the @escaping
@@ -2137,7 +2138,7 @@
.fixItRemove(attrRange);
// Try to find a helpful note based on how the type is being used
- if (options.contains(TR_ImmediateOptionalTypeArgument)) {
+ if (options.contains(TypeResolutionFlags::ImmediateOptionalTypeArgument)) {
TC.diagnose(repr->getLoc(), diag::escaping_optional_type_argument);
}
}
@@ -2208,19 +2209,19 @@
}
// In SIL *only*, allow @block_storage to specify a block storage type.
- if ((options & TR_SILType) && attrs.has(TAK_block_storage)) {
+ if ((options & TypeResolutionFlags::SILType) && attrs.has(TAK_block_storage)) {
ty = SILBlockStorageType::get(ty->getCanonicalType());
attrs.clearAttribute(TAK_block_storage);
}
// In SIL *only*, allow @box to specify a box type.
- if ((options & TR_SILType) && attrs.has(TAK_box)) {
+ if ((options & TypeResolutionFlags::SILType) && attrs.has(TAK_box)) {
ty = SILBoxType::get(ty->getCanonicalType());
attrs.clearAttribute(TAK_box);
}
// In SIL *only*, allow @dynamic_self to specify a dynamic Self type.
- if ((options & TR_SILMode) && attrs.has(TAK_dynamic_self)) {
+ if ((options & TypeResolutionFlags::SILMode) && attrs.has(TAK_dynamic_self)) {
ty = rebuildWithDynamicSelf(TC.Context, ty);
attrs.clearAttribute(TAK_dynamic_self);
}
@@ -2236,17 +2237,17 @@
Type TypeResolver::resolveASTFunctionType(FunctionTypeRepr *repr,
TypeResolutionOptions options,
FunctionType::ExtInfo extInfo) {
- options -= TR_ImmediateFunctionInput;
- options -= TR_FunctionInput;
- options -= TR_TypeAliasUnderlyingType;
+ options -= TypeResolutionFlags::ImmediateFunctionInput;
+ options -= TypeResolutionFlags::FunctionInput;
+ options -= TypeResolutionFlags::TypeAliasUnderlyingType;
// FIXME: Until we remove the IUO type from the type system, we
// need to continue to parse IUOs in SIL tests so that we can
// match the types we generate from the importer.
- if (!options.contains(TR_SILMode))
- options -= TR_AllowIUO;
+ if (!options.contains(TypeResolutionFlags::SILMode))
+ options -= TypeResolutionFlags::AllowIUO;
Type inputTy = resolveType(repr->getArgsTypeRepr(),
- options | TR_ImmediateFunctionInput);
+ options | TypeResolutionFlags::ImmediateFunctionInput);
if (!inputTy || inputTy->hasError()) return inputTy;
Type outputTy = resolveType(repr->getResultTypeRepr(), options);
@@ -2415,9 +2416,9 @@
SILFunctionType::ExtInfo extInfo,
ParameterConvention callee,
TypeRepr *witnessMethodProtocol) {
- options -= TR_ImmediateFunctionInput;
- options -= TR_FunctionInput;
- options -= TR_TypeAliasUnderlyingType;
+ options -= TypeResolutionFlags::ImmediateFunctionInput;
+ options -= TypeResolutionFlags::FunctionInput;
+ options -= TypeResolutionFlags::TypeAliasUnderlyingType;
bool hasError = false;
@@ -2454,7 +2455,7 @@
for (auto elt : tuple->getElements()) {
auto param = resolveSILParameter(elt.Type,
- options | TR_ImmediateFunctionInput);
+ options | TypeResolutionFlags::ImmediateFunctionInput);
params.push_back(param);
if (!param.getType()) return nullptr;
@@ -2463,7 +2464,7 @@
}
} else {
SILParameterInfo param = resolveSILParameter(repr->getArgsTypeRepr(),
- options | TR_ImmediateFunctionInput);
+ options | TypeResolutionFlags::ImmediateFunctionInput);
params.push_back(param);
if (!param.getType()) return nullptr;
@@ -2567,14 +2568,16 @@
TypeResolutionOptions options) {
AttributedTypeRepr attrRepr(attrs, repr);
SILParameterInfo paramInfo =
- resolveSILParameter(&attrRepr, options | TR_ImmediateFunctionInput);
+ resolveSILParameter(&attrRepr, options |
+ TypeResolutionFlags::ImmediateFunctionInput);
return SILYieldInfo(paramInfo.getType(), paramInfo.getConvention());
}
SILParameterInfo TypeResolver::resolveSILParameter(
TypeRepr *repr,
TypeResolutionOptions options) {
- assert((options & TR_FunctionInput) | (options & TR_ImmediateFunctionInput) &&
+ assert((options & TypeResolutionFlags::FunctionInput)
+ | (options & TypeResolutionFlags::ImmediateFunctionInput) &&
"Parameters should be marked as inputs");
auto convention = DefaultParameterConvention;
Type type;
@@ -2740,13 +2743,13 @@
Type TypeResolver::resolveSpecifierTypeRepr(SpecifierTypeRepr *repr,
TypeResolutionOptions options) {
// inout is only valid for (non-subscript) function parameters.
- if ((options & TR_SubscriptParameters) ||
- (!(options & TR_FunctionInput) &&
- !(options & TR_ImmediateFunctionInput))) {
+ if ((options & TypeResolutionFlags::SubscriptParameters) ||
+ (!(options & TypeResolutionFlags::FunctionInput) &&
+ !(options & TypeResolutionFlags::ImmediateFunctionInput))) {
decltype(diag::attr_only_on_parameters) diagID;
- if (options & TR_SubscriptParameters) {
+ if (options & TypeResolutionFlags::SubscriptParameters) {
diagID = diag::attr_not_on_subscript_parameters;
- } else if (options & TR_VariadicFunctionInput) {
+ } else if (options & TypeResolutionFlags::VariadicFunctionInput) {
diagID = diag::attr_not_on_variadic_parameters;
} else {
diagID = diag::attr_only_on_parameters;
@@ -2760,9 +2763,9 @@
}
// Anything within the inout isn't a parameter anymore.
- options -= TR_ImmediateFunctionInput;
- options -= TR_FunctionInput;
- options -= TR_TypeAliasUnderlyingType;
+ options -= TypeResolutionFlags::ImmediateFunctionInput;
+ options -= TypeResolutionFlags::FunctionInput;
+ options -= TypeResolutionFlags::TypeAliasUnderlyingType;
Type ty = resolveType(repr->getBase(), options);
if (!ty || ty->hasError()) return ty;
@@ -2826,7 +2829,7 @@
Type TypeResolver::resolveOptionalType(OptionalTypeRepr *repr,
TypeResolutionOptions options) {
auto elementOptions = withoutContext(options, true);
- elementOptions |= TR_ImmediateOptionalTypeArgument;
+ elementOptions |= TypeResolutionFlags::ImmediateOptionalTypeArgument;
// The T in T? is a generic type argument and therefore always an AST type.
// FIXME: diagnose non-materializability of element type!
@@ -2842,7 +2845,7 @@
Type TypeResolver::resolveImplicitlyUnwrappedOptionalType(
ImplicitlyUnwrappedOptionalTypeRepr *repr,
TypeResolutionOptions options) {
- if (!options.contains(TR_AllowIUO)) {
+ if (!options.contains(TypeResolutionFlags::AllowIUO)) {
Diagnostic diag = diag::
implicitly_unwrapped_optional_in_illegal_position_decay_to_optional;
@@ -2854,7 +2857,7 @@
}
auto elementOptions = withoutContext(options, true);
- elementOptions |= TR_ImmediateOptionalTypeArgument;
+ elementOptions |= TypeResolutionFlags::ImmediateOptionalTypeArgument;
// The T in T! is a generic type argument and therefore always an AST type.
// FIXME: diagnose non-materializability of element type!
@@ -2862,7 +2865,7 @@
if (!baseTy || baseTy->hasError()) return baseTy;
Type uncheckedOptionalTy;
- if (!options.contains(TR_AllowIUO))
+ if (!options.contains(TypeResolutionFlags::AllowIUO))
// Treat IUOs in illegal positions as optionals.
uncheckedOptionalTy = TC.getOptionalType(repr->getExclamationLoc(), baseTy);
else
@@ -2877,7 +2880,8 @@
Type TypeResolver::resolveTupleType(TupleTypeRepr *repr,
TypeResolutionOptions options) {
- bool isImmediateFunctionInput = options.contains(TR_ImmediateFunctionInput);
+ bool isImmediateFunctionInput = options.contains(
+ TypeResolutionFlags::ImmediateFunctionInput);
SmallVector<TupleTypeElt, 8> elements;
elements.reserve(repr->getNumElements());
@@ -2889,8 +2893,8 @@
// FIXME: Until we remove the IUO type from the type system, we
// need to continue to parse IUOs in SIL tests so that we can
// match the types we generate from the importer.
- if (!options.contains(TR_SILMode))
- elementOptions -= TR_AllowIUO;
+ if (!options.contains(TypeResolutionFlags::SILMode))
+ elementOptions -= TypeResolutionFlags::AllowIUO;
// If we have a single ParenType, don't clear the context bits; we
// still want to parse the type contained therein as if it were in
@@ -2899,13 +2903,13 @@
// `FunctionInput` so that e.g. ((foo: Int)) -> Int is considered a
// tuple argument rather than a labeled Int argument.
if (isImmediateFunctionInput) {
- elementOptions -= TR_ImmediateFunctionInput;
- elementOptions |= TR_FunctionInput;
+ elementOptions -= TypeResolutionFlags::ImmediateFunctionInput;
+ elementOptions |= TypeResolutionFlags::FunctionInput;
}
} else {
elementOptions = withoutContext(elementOptions, true);
if (isImmediateFunctionInput)
- elementOptions |= TR_FunctionInput;
+ elementOptions |= TypeResolutionFlags::FunctionInput;
}
bool complained = false;
@@ -2937,7 +2941,7 @@
if (repr->hasEllipsis() &&
elements.size() == repr->getEllipsisIndex()) {
thisElementOptions = withoutContext(elementOptions);
- thisElementOptions |= TR_VariadicFunctionInput;
+ thisElementOptions |= TypeResolutionFlags::VariadicFunctionInput;
variadic = true;
}
@@ -2963,8 +2967,8 @@
// or SIL, either.
if (!isImmediateFunctionInput) {
if (elements.size() == 1 && elements[0].hasName()
- && !(options & TR_SILType)
- && !(options & TR_EnumCase)) {
+ && !(options & TypeResolutionFlags::SILType)
+ && !(options & TypeResolutionFlags::EnumCase)) {
if (!complained) {
TC.diagnose(repr->getElementNameLoc(0),
diag::tuple_single_element)
@@ -3158,7 +3162,7 @@
// In SIL mode, a metatype must have a @thin, @thick, or
// @objc_metatype attribute, so metatypes should have been lowered
// in resolveAttributedType.
- if (options & TR_SILType) {
+ if (options & TypeResolutionFlags::SILType) {
TC.diagnose(repr->getStartLoc(), diag::sil_metatype_without_repr);
storedRepr = MetatypeRepresentation::Thick;
}
@@ -3189,7 +3193,7 @@
// In SIL mode, a metatype must have a @thin, @thick, or
// @objc_metatype attribute, so metatypes should have been lowered
// in resolveAttributedType.
- if (options & TR_SILType) {
+ if (options & TypeResolutionFlags::SILType) {
TC.diagnose(repr->getStartLoc(), diag::sil_metatype_without_repr);
storedRepr = MetatypeRepresentation::Thick;
}
diff --git a/lib/Sema/TypeChecker.cpp b/lib/Sema/TypeChecker.cpp
index 18ffe45..cb30575 100644
--- a/lib/Sema/TypeChecker.cpp
+++ b/lib/Sema/TypeChecker.cpp
@@ -306,8 +306,8 @@
// Validate the representation.
// FIXME: Perform some kind of "shallow" validation here?
TypeResolutionOptions options;
- options |= TR_AllowUnboundGenerics;
- options |= TR_ExtensionBinding;
+ options |= TypeResolutionFlags::AllowUnboundGenerics;
+ options |= TypeResolutionFlags::ExtensionBinding;
if (TC.validateType(ED->getExtendedTypeLoc(), dc, options)) {
ED->setInvalid();
return;
@@ -710,13 +710,13 @@
TypeResolutionOptions options;
// Fine to have unbound generic types.
- options |= TR_AllowUnboundGenerics;
+ options |= TypeResolutionFlags::AllowUnboundGenerics;
if (isSILMode) {
- options |= TR_SILMode;
- options |= TR_AllowIUO;
+ options |= TypeResolutionFlags::SILMode;
+ options |= TypeResolutionFlags::AllowIUO;
}
if (isSILType)
- options |= TR_SILType;
+ options |= TypeResolutionFlags::SILType;
GenericTypeToArchetypeResolver contextResolver(GenericEnv);
diff --git a/lib/Sema/TypeChecker.h b/lib/Sema/TypeChecker.h
index ba07222..54c1ef5 100644
--- a/lib/Sema/TypeChecker.h
+++ b/lib/Sema/TypeChecker.h
@@ -451,114 +451,109 @@
/// Flags that describe the context of type checking a pattern or
/// type.
-enum TypeResolutionFlags : unsigned {
+enum class TypeResolutionFlags : unsigned {
/// Whether to allow unspecified types within a pattern.
- TR_AllowUnspecifiedTypes = 0x01,
+ AllowUnspecifiedTypes = 0x01,
/// Whether the given type can override the type of a typed pattern.
- TR_OverrideType = 0x04,
+ OverrideType = 0x04,
/// Whether to allow unbound generic types.
- TR_AllowUnboundGenerics = 0x08,
+ AllowUnboundGenerics = 0x08,
/// Whether we are validating the type for SIL.
- TR_SILType = 0x10,
+ SILType = 0x10,
- /// Whether we are parsing a SIL file. Not the same as TR_SILType,
+ /// Whether we are parsing a SIL file. Not the same as SILType,
/// because the latter is not set if we're parsing an AST type.
- TR_SILMode = 0x20,
+ SILMode = 0x20,
/// Whether we are in the input type of a function, or under one level of
/// tuple type. This is not set for multi-level tuple arguments.
- TR_FunctionInput = 0x40,
+ FunctionInput = 0x40,
/// Whether this is the immediate input type to a function type,
- TR_ImmediateFunctionInput = 0x80,
+ ImmediateFunctionInput = 0x80,
/// Whether this is a variadic function input.
- TR_VariadicFunctionInput = 0x100,
+ VariadicFunctionInput = 0x100,
/// Whether we are in the result type of a function body that is
/// known to produce dynamic Self.
- TR_DynamicSelfResult = 0x200,
+ DynamicSelfResult = 0x200,
/// Whether this is a resolution based on a non-inferred type pattern.
- TR_FromNonInferredPattern = 0x400,
+ FromNonInferredPattern = 0x400,
/// Whether we are the variable type in a for/in statement.
- TR_EnumerationVariable = 0x800,
+ EnumerationVariable = 0x800,
/// Whether we are looking only in the generic signature of the context
/// we're searching, rather than the entire context.
- TR_GenericSignature = 0x1000,
+ GenericSignature = 0x1000,
/// Whether an unavailable protocol can be referenced.
- TR_AllowUnavailableProtocol = 0x2000,
+ AllowUnavailableProtocol = 0x2000,
/// Whether this type is the value carried in an enum case.
- TR_EnumCase = 0x4000,
+ EnumCase = 0x4000,
/// Whether this type is being used in an expression or local declaration.
///
/// This affects what sort of dependencies are recorded when resolving the
/// type.
- TR_InExpression = 0x8000,
+ InExpression = 0x8000,
/// Whether this type resolution is guaranteed not to affect downstream files.
- TR_KnownNonCascadingDependency = 0x10000,
+ KnownNonCascadingDependency = 0x10000,
/// Whether we should allow references to unavailable types.
- TR_AllowUnavailable = 0x20000,
+ AllowUnavailable = 0x20000,
/// Whether this is the payload subpattern of an enum pattern.
- TR_EnumPatternPayload = 0x40000,
+ EnumPatternPayload = 0x40000,
/// Whether we are binding an extension declaration, which limits
/// the lookup.
- TR_ExtensionBinding = 0x80000,
+ ExtensionBinding = 0x80000,
/// Whether we are in the inheritance clause of a nominal type declaration
/// or extension.
- TR_InheritanceClause = 0x100000,
+ InheritanceClause = 0x100000,
/// Whether we should resolve only the structure of the resulting
/// type rather than its complete semantic properties.
- TR_ResolveStructure = 0x200000,
+ ResolveStructure = 0x200000,
/// Whether this is the type of an editor placeholder.
- TR_EditorPlaceholder = 0x400000,
+ EditorPlaceholder = 0x400000,
/// Whether we are in a type argument for an optional
- TR_ImmediateOptionalTypeArgument = 0x800000,
+ ImmediateOptionalTypeArgument = 0x800000,
/// Whether we are checking the underlying type of a typealias.
- TR_TypeAliasUnderlyingType = 0x1000000,
+ TypeAliasUnderlyingType = 0x1000000,
/// Whether we are checking the parameter list of a subscript.
- TR_SubscriptParameters = 0x2000000,
+ SubscriptParameters = 0x2000000,
/// Is it okay to resolve an IUO sigil ("!") here?
- TR_AllowIUO = 0x4000000,
+ AllowIUO = 0x4000000,
};
/// Option set describing how type resolution should work.
typedef OptionSet<TypeResolutionFlags> TypeResolutionOptions;
-inline TypeResolutionOptions operator|(TypeResolutionFlags lhs,
- TypeResolutionFlags rhs) {
- return TypeResolutionOptions(lhs) | rhs;
-}
-
/// Strip the contextual options from the given type resolution options.
static inline TypeResolutionOptions
withoutContext(TypeResolutionOptions options, bool preserveSIL = false) {
- options -= TR_ImmediateFunctionInput;
- options -= TR_FunctionInput;
- options -= TR_VariadicFunctionInput;
- options -= TR_EnumCase;
- options -= TR_ImmediateOptionalTypeArgument;
- options -= TR_AllowIUO;
- if (!preserveSIL) options -= TR_SILType;
+ options -= TypeResolutionFlags::ImmediateFunctionInput;
+ options -= TypeResolutionFlags::FunctionInput;
+ options -= TypeResolutionFlags::VariadicFunctionInput;
+ options -= TypeResolutionFlags::EnumCase;
+ options -= TypeResolutionFlags::ImmediateOptionalTypeArgument;
+ options -= TypeResolutionFlags::AllowIUO;
+ if (!preserveSIL) options -= TypeResolutionFlags::SILType;
return options;
}