-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CursorInfo] Implement a few expression references as solver-based #62478
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
[CursorInfo] Implement a few expression references as solver-based #62478
Conversation
@swift-ci Please SourceKit stress test |
a7772e6
to
352d75f
Compare
@swift-ci Please SourceKit stress test |
Stress tester failure at protocol MyProto {
static func makeInstance() -> Self
}
class Base: MyProto {
static func makeInstance() -> Self {
fatalError()
}
}
class Inherited: Base {
var member: Int
}
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 2):30 %s -- %s
func foo() {
Inherited.makeInstance().member = 2
} The AST-based implementation reported |
Stress tester failure at The AST-based implementation reported |
Stress tester failure at In the AST-based implementation on |
352d75f
to
50bfe6b
Compare
I wouldn't expect any receiver type here, it's statically resolvable. If the old implementation is returning dynamic here I'd say that's a bug.
Is |
50bfe6b
to
7dbddfb
Compare
@swift-ci Please smoke test |
4c74b61
to
3649562
Compare
@swift-ci Please SourceKit stress test |
1 similar comment
@swift-ci Please SourceKit stress test |
@swift-ci Please smoke test |
c60da65
to
255fcfe
Compare
@swift-ci Please smoke test |
This implements cursor info resolving for a few expression types using the constraint system. This allows us to detect ambiguous results – we cannot deliver them yet but that will be done in a follow-up PR.
255fcfe
to
3d4ca87
Compare
@swift-ci Please SourceKit stress test |
@swift-ci Please smoke test |
Running the SourceKit stress tester with verification of solver-based cursor info returned quite a few differences but in all of them, the old AST-based implementation was actually incorrect. So, instead of verifying the results, deliver the results from solver-baesd cursor info and only fall back to AST-based cursor info if the solver-based implementation returned no results. rdar://103369449
3d4ca87
to
b14b470
Compare
@swift-ci Please SourceKit stress test |
@swift-ci Please smoke test |
b14b470
to
fef7bd7
Compare
@swift-ci Please SourceKit stress test |
@swift-ci Please smoke test |
fef7bd7
to
922ec03
Compare
Note to self: The stress tester only found failures in refactoring where previously we didn’t report any cursor, so all of those are improvements. |
@swift-ci Please smoke test |
lib/AST/Decl.cpp
Outdated
if (!classDecl->isActor() && !isa<VarDecl>(D)) { | ||
return StaticSpellingKind::KeywordClass; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re: !isa<VarDecl>(D)
, does this affect class
computed values? e.g.
class C {
class var value: Int { 1 }
}
lib/IDE/Utils.cpp
Outdated
while (auto Identity = dyn_cast<IdentityExpr>(Base)) { | ||
Base = Identity->getSubExpr(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while (auto Identity = dyn_cast<IdentityExpr>(Base)) { | |
Base = Identity->getSubExpr(); | |
} | |
Base = Base->getSemanticsProvidingExpr(); |
lib/IDE/Utils.cpp
Outdated
@@ -962,6 +969,8 @@ void swift::ide::getReceiverType(Expr *Base, | |||
ReceiverTy = MetaT->getInstanceType(); | |||
else if (auto SelfT = ReceiverTy->getAs<DynamicSelfType>()) | |||
ReceiverTy = SelfT->getSelfType(); | |||
else if (auto InoutT = ReceiverTy->getAs<InOutType>()) | |||
ReceiverTy = InoutT->getObjectType(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ReceiverTy = ReceiverTy->getWithoutSpecifierType()
that handles both LValueType
and InOutType
.
Also for MetatypeType
, we might want to consider using ReceiverTy->getMetatypeInstanceType()
922ec03
to
d9ebe09
Compare
@swift-ci Please smoke test |
lib/IDE/Utils.cpp
Outdated
ReceiverTy = SelfT->getSelfType(); | ||
|
||
ReceiverTy->getWithoutSpecifierType(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to remove?
…nd new test cases In these cases the solver-based and AST-based cursor info differed in their results. Fix the AST-based cursor info to return the correct results and add test cases to make sure the solver-based implementation doesn’t regress them.
…if invoked on a symbol from a different module
d9ebe09
to
a9cba54
Compare
@swift-ci Please smoke test |
@swift-ci Please SourceKit stress test |
@swift-ci Please smoke test Windows |
This implements cursor info resolving for a few expression types using the constraint system. This allows us to detect ambiguous results – we cannot deliver them yet but that will be done in a follow-up PR.