Skip to content
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

Rewrite SimpleDidSetRequest to not require a typechecked body #69215

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 0 additions & 8 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,14 +957,6 @@ Type AbstractFunctionDecl::getThrownInterfaceType() const {

llvm::Optional<Type>
AbstractFunctionDecl::getEffectiveThrownErrorType() const {
// FIXME: Only getters can have thrown error types right now, and DidSet
// has a cyclic reference if we try to get its interface type here. Find a
// better way to express this.
if (auto accessor = dyn_cast<AccessorDecl>(this)) {
if (accessor->getAccessorKind() != AccessorKind::Get)
return llvm::None;
}

Type interfaceType = getInterfaceType();
if (hasImplicitSelfDecl()) {
if (auto fnType = interfaceType->getAs<AnyFunctionType>())
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ void TypeChecker::buildTypeRefinementContextHierarchyDelayed(SourceFile &SF, Abs
if(!RootTRC)
return;

if (AFD->getBodyKind() != AbstractFunctionDecl::BodyKind::Unparsed)
if (AFD->getLoc().isInvalid())
return;

// Parse the function body.
Expand Down
19 changes: 18 additions & 1 deletion lib/Sema/TypeCheckStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3797,6 +3797,9 @@ bool SimpleDidSetRequest::evaluate(Evaluator &evaluator,
virtual PreWalkResult<Expr *> walkToExprPre(Expr *E) override {
if (!E)
return Action::Continue(E);

// If we have an already-resolved reference to the parameter in question,
// we're done.
if (auto DRE = dyn_cast<DeclRefExpr>(E)) {
if (auto decl = DRE->getDecl()) {
if (decl == OldValueParam) {
Expand All @@ -3806,6 +3809,20 @@ bool SimpleDidSetRequest::evaluate(Evaluator &evaluator,
}
}

// If we have an unresolved reference with the same name as the parameter,
// perform name lookup to determine whether it refers to this parameter.
if (auto UDRE = dyn_cast<UnresolvedDeclRefExpr>(E)) {
auto loc = UDRE->getLoc();
auto sf = OldValueParam->getDeclContext()
->getOutermostParentSourceFile();
auto name = UDRE->getName().getFullName();
if (name == OldValueParam->getName() &&
ASTScope::lookupSingleLocalDecl(sf, name, loc) == OldValueParam) {
foundOldValueRef = true;
return Action::Stop();
}
}

return Action::Continue(E);
}

Expand Down Expand Up @@ -3838,7 +3855,7 @@ bool SimpleDidSetRequest::evaluate(Evaluator &evaluator,
// If we find a reference to the implicit 'oldValue' parameter, then it is
// not a "simple" didSet because we need to fetch it.
auto walker = OldValueFinder(param);
if (auto *body = decl->getTypecheckedBody())
if (auto *body = decl->getBody())
body->walk(walker);
auto hasOldValueRef = walker.didFindOldValueRef();
if (!hasOldValueRef) {
Expand Down