Skip to content

Commit

Permalink
Remove NameLookupFlags::KnownPrivate
Browse files Browse the repository at this point in the history
  • Loading branch information
CodaFi committed Sep 21, 2020
1 parent 259e1a9 commit ee35a4f
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 60 deletions.
3 changes: 1 addition & 2 deletions lib/AST/UnqualifiedLookup.cpp
Expand Up @@ -195,8 +195,7 @@ namespace {
const bool isOriginallyTypeLookup);

Optional<bool> getInitialIsCascadingUse() const {
return options.contains(Flags::KnownPrivate) ? Optional<bool>(false)
: None;
return Optional<bool>(false);
}

void findResultsAndSaveUnavailables(
Expand Down
2 changes: 0 additions & 2 deletions lib/Sema/CSSimplify.cpp
Expand Up @@ -6693,8 +6693,6 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
// Ignore access control so we get candidates that might have been missed
// before.
lookupOptions |= NameLookupFlags::IgnoreAccessControl;
// This is only used for diagnostics, so always use KnownPrivate.
lookupOptions |= NameLookupFlags::KnownPrivate;

auto lookup =
TypeChecker::lookupMember(DC, instanceTy, memberName, lookupOptions);
Expand Down
6 changes: 1 addition & 5 deletions lib/Sema/ConstraintSystem.cpp
Expand Up @@ -247,11 +247,7 @@ LookupResult &ConstraintSystem::lookupMember(Type base, DeclNameRef name) {
if (result) return *result;

// Lookup the member.
NameLookupOptions lookupOptions = defaultMemberLookupOptions;
if (isa<AbstractFunctionDecl>(DC))
lookupOptions |= NameLookupFlags::KnownPrivate;

result = TypeChecker::lookupMember(DC, base, name, lookupOptions);
result = TypeChecker::lookupMember(DC, base, name, defaultMemberLookupOptions);

// If we aren't performing dynamic lookup, we're done.
if (!*result || !base->isAnyObject())
Expand Down
3 changes: 1 addition & 2 deletions lib/Sema/MiscDiagnostics.cpp
Expand Up @@ -3458,8 +3458,7 @@ class ObjCSelectorWalker : public ASTWalker {
auto nominal = method->getDeclContext()->getSelfNominalTypeDecl();
auto result = TypeChecker::lookupMember(
const_cast<DeclContext *>(DC), nominal->getDeclaredInterfaceType(),
DeclNameRef(lookupName),
(defaultMemberLookupOptions | NameLookupFlags::KnownPrivate));
DeclNameRef(lookupName), defaultMemberLookupOptions);

// If we didn't find multiple methods, there is no ambiguity.
if (result.size() < 2) return false;
Expand Down
33 changes: 7 additions & 26 deletions lib/Sema/TypeCheckConstraints.cpp
Expand Up @@ -341,14 +341,11 @@ static bool diagnoseOperatorJuxtaposition(UnresolvedDeclRefExpr *UDRE,

// Perform name lookup for the first and second pieces. If either fail to
// be found, then it isn't a valid split.
NameLookupOptions LookupOptions = defaultUnqualifiedLookupOptions;
// This is only used for diagnostics, so always use KnownPrivate.
LookupOptions |= NameLookupFlags::KnownPrivate;
auto startLookup = TypeChecker::lookupUnqualified(
DC, startName, UDRE->getLoc(), LookupOptions);
DC, startName, UDRE->getLoc(), defaultUnqualifiedLookupOptions);
if (!startLookup) continue;
auto endLookup = TypeChecker::lookupUnqualified(DC, endName, UDRE->getLoc(),
LookupOptions);
defaultUnqualifiedLookupOptions);
if (!endLookup) continue;

// If the overall operator is a binary one, then we're looking at
Expand Down Expand Up @@ -536,9 +533,6 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,

// Perform standard value name lookup.
NameLookupOptions lookupOptions = defaultUnqualifiedLookupOptions;
if (isa<AbstractFunctionDecl>(DC))
lookupOptions |= NameLookupFlags::KnownPrivate;

// TODO: Include all of the possible members to give a solver a
// chance to diagnose name shadowing which requires explicit
// name/module qualifier to access top-level name.
Expand All @@ -562,7 +556,6 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,

// Try ignoring access control.
NameLookupOptions relookupOptions = lookupOptions;
relookupOptions |= NameLookupFlags::KnownPrivate;
relookupOptions |= NameLookupFlags::IgnoreAccessControl;
auto inaccessibleResults =
TypeChecker::lookupUnqualified(DC, Name, Loc, relookupOptions);
Expand Down Expand Up @@ -1424,14 +1417,10 @@ TypeExpr *PreCheckExpression::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) {
// and not a TypeExpr.
if (auto *DRE = dyn_cast<DeclRefExpr>(UDE->getBase())) {
if (auto *TD = dyn_cast<TypeDecl>(DRE->getDecl())) {
auto lookupOptions = defaultMemberLookupOptions;
if (isa<AbstractFunctionDecl>(DC) ||
isa<AbstractClosureExpr>(DC))
lookupOptions |= NameLookupFlags::KnownPrivate;

// See if the type has a member type with this name.
auto Result = TypeChecker::lookupMemberType(
DC, TD->getDeclaredInterfaceType(), Name, lookupOptions);
DC, TD->getDeclaredInterfaceType(), Name,
defaultMemberLookupOptions);

// If there is no nested type with this name, we have a lookup of
// a non-type member, so leave the expression as-is.
Expand Down Expand Up @@ -1484,14 +1473,10 @@ TypeExpr *PreCheckExpression::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) {
const auto BaseTy = resolution.resolveType(InnerTypeRepr);

if (BaseTy->mayHaveMembers()) {
auto lookupOptions = defaultMemberLookupOptions;
if (isa<AbstractFunctionDecl>(DC) ||
isa<AbstractClosureExpr>(DC))
lookupOptions |= NameLookupFlags::KnownPrivate;

// See if there is a member type with this name.
auto Result =
TypeChecker::lookupMemberType(DC, BaseTy, Name, lookupOptions);
TypeChecker::lookupMemberType(DC, BaseTy, Name,
defaultMemberLookupOptions);

// If there is no nested type with this name, we have a lookup of
// a non-type member, so leave the expression as-is.
Expand Down Expand Up @@ -2466,12 +2451,10 @@ bool TypeChecker::typeCheckExprPattern(ExprPattern *EP, DeclContext *DC,
EP->setMatchVar(matchVar);

// Find '~=' operators for the match.
auto lookupOptions = defaultUnqualifiedLookupOptions;
lookupOptions |= NameLookupFlags::KnownPrivate;
auto matchLookup =
lookupUnqualified(DC->getModuleScopeContext(),
DeclNameRef(Context.Id_MatchOperator),
SourceLoc(), lookupOptions);
SourceLoc(), defaultUnqualifiedLookupOptions);
auto &diags = DC->getASTContext().Diags;
if (!matchLookup) {
diags.diagnose(EP->getLoc(), diag::no_match_operator);
Expand Down Expand Up @@ -3884,8 +3867,6 @@ IsCallableNominalTypeRequest::evaluate(Evaluator &evaluator, CanType ty,
DeclContext *dc) const {
auto options = defaultMemberLookupOptions;
options |= NameLookupFlags::IgnoreAccessControl;
if (isa<AbstractFunctionDecl>(dc))
options |= NameLookupFlags::KnownPrivate;

// Look for a callAsFunction method.
auto &ctx = ty->getASTContext();
Expand Down
5 changes: 1 addition & 4 deletions lib/Sema/TypeCheckExpr.cpp
Expand Up @@ -617,13 +617,10 @@ Expr *TypeChecker::buildRefExpr(ArrayRef<ValueDecl *> Decls,
static Type lookupDefaultLiteralType(const DeclContext *dc,
StringRef name) {
auto &ctx = dc->getASTContext();
auto lookupOptions = defaultUnqualifiedLookupOptions;
if (isa<AbstractFunctionDecl>(dc))
lookupOptions |= NameLookupFlags::KnownPrivate;
DeclNameRef nameRef(ctx.getIdentifier(name));
auto lookup = TypeChecker::lookupUnqualified(dc->getModuleScopeContext(),
nameRef, SourceLoc(),
lookupOptions);
defaultUnqualifiedLookupOptions);
TypeDecl *TD = lookup.getSingleTypeResult();
if (!TD)
return Type();
Expand Down
5 changes: 2 additions & 3 deletions lib/Sema/TypeCheckPattern.cpp
Expand Up @@ -119,10 +119,9 @@ lookupUnqualifiedEnumMemberElement(DeclContext *DC, DeclNameRef name,
// FIXME: We should probably pay attention to argument labels someday.
name = name.withoutArgumentLabels();

auto lookupOptions = defaultUnqualifiedLookupOptions;
lookupOptions |= NameLookupFlags::KnownPrivate;
auto lookup =
TypeChecker::lookupUnqualified(DC, name, UseLoc, lookupOptions);
TypeChecker::lookupUnqualified(DC, name, UseLoc,
defaultUnqualifiedLookupOptions);
return filterForEnumElement(DC, UseLoc,
/*unqualifiedLookup=*/true, lookup);
}
Expand Down
10 changes: 3 additions & 7 deletions lib/Sema/TypeCheckProtocol.cpp
Expand Up @@ -1164,12 +1164,9 @@ WitnessChecker::lookupValueWitnesses(ValueDecl *req, bool *ignoringNames) {

if (req->isOperator()) {
// Operator lookup is always global.
auto lookupOptions = defaultUnqualifiedLookupOptions;
if (!DC->isCascadingContextForLookup(false))
lookupOptions |= NameLookupFlags::KnownPrivate;
auto lookup = TypeChecker::lookupUnqualified(DC->getModuleScopeContext(),
reqBaseName, SourceLoc(),
lookupOptions);
defaultUnqualifiedLookupOptions);
for (auto candidate : lookup) {
auto decl = candidate.getValueDecl();
if (swift::isMemberOperator(cast<FuncDecl>(decl), Adoptee)) {
Expand Down Expand Up @@ -1249,10 +1246,9 @@ bool WitnessChecker::findBestWitness(
if (!overlay)
continue;

auto lookupOptions = defaultUnqualifiedLookupOptions;
lookupOptions |= NameLookupFlags::KnownPrivate;
auto lookup = TypeChecker::lookupUnqualified(
overlay, requirement->createNameRef(), SourceLoc(), lookupOptions);
overlay, requirement->createNameRef(), SourceLoc(),
defaultUnqualifiedLookupOptions);
for (auto candidate : lookup)
witnesses.push_back(candidate.getValueDecl());
break;
Expand Down
3 changes: 2 additions & 1 deletion lib/Sema/TypeCheckStmt.cpp
Expand Up @@ -1669,7 +1669,7 @@ static bool checkSuperInit(ConstructorDecl *fromCtor,
if (!superclassCtor || !superclassCtor->isDesignatedInit() ||
superclassCtor == ctor)
continue;

// Found another designated initializer in the superclass. Don't add the
// super.init() call.
return true;
Expand All @@ -1684,6 +1684,7 @@ static bool checkSuperInit(ConstructorDecl *fromCtor,
}
}


return false;
}

Expand Down
4 changes: 0 additions & 4 deletions lib/Sema/TypeCheckType.cpp
Expand Up @@ -1111,7 +1111,6 @@ static Type diagnoseUnknownType(TypeResolution resolution,

// Try ignoring access control.
NameLookupOptions relookupOptions = lookupOptions;
relookupOptions |= NameLookupFlags::KnownPrivate;
relookupOptions |= NameLookupFlags::IgnoreAccessControl;
auto inaccessibleResults =
TypeChecker::lookupUnqualifiedType(dc, comp->getNameRef(),
Expand Down Expand Up @@ -1177,7 +1176,6 @@ static Type diagnoseUnknownType(TypeResolution resolution,

// Try ignoring access control.
NameLookupOptions relookupOptions = lookupOptions;
relookupOptions |= NameLookupFlags::KnownPrivate;
relookupOptions |= NameLookupFlags::IgnoreAccessControl;
auto inaccessibleMembers =
TypeChecker::lookupMemberType(dc, parentType, comp->getNameRef(),
Expand Down Expand Up @@ -1212,8 +1210,6 @@ static Type diagnoseUnknownType(TypeResolution resolution,
// identifier not found as a member type vs. not found at all.
NameLookupOptions memberLookupOptions = lookupOptions;
memberLookupOptions |= NameLookupFlags::IgnoreAccessControl;
memberLookupOptions |= NameLookupFlags::KnownPrivate;

memberLookup = TypeChecker::lookupMember(dc, parentType,
comp->getNameRef(),
memberLookupOptions);
Expand Down
6 changes: 2 additions & 4 deletions lib/Sema/TypeChecker.h
Expand Up @@ -186,14 +186,12 @@ inline TypeCheckExprOptions operator|(TypeCheckExprFlags flag1,

/// Flags that can be used to control name lookup.
enum class NameLookupFlags {
/// Whether we know that this lookup is always a private dependency.
KnownPrivate = 0x01,
/// Whether to ignore access control for this lookup, allowing inaccessible
/// results to be returned.
IgnoreAccessControl = 0x10,
IgnoreAccessControl = 1 << 0,
/// Whether to include results from outside the innermost scope that has a
/// result.
IncludeOuterResults = 0x20,
IncludeOuterResults = 1 << 1,
};

/// A set of options that control name lookup.
Expand Down

0 comments on commit ee35a4f

Please sign in to comment.