Skip to content

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Jan 24, 2019

SourceKit document structure request used to crash if if there's initializer with single named parameter with @IBAction attribute.

This used to happen because ConstructorDecl::isObjCZeroParameterWithLongSelector() requires
interface type of the parameter but the constructor doesn't have it at this stage.

This PR fixes that by not vending ObjC name for constructor or destructors.

rdar://problem/47426948

@rintaro
Copy link
Member Author

rintaro commented Jan 24, 2019

@swift-ci Please smoke test

lib/AST/Decl.cpp Outdated
if (params->get(0)->hasInterfaceType()) {
return params->get(0)->getInterfaceType()->isVoid();
} else if (auto tyR = params->get(0)->getTypeLoc().getTypeRepr()) {
// Fallback to textual check. This can happen when getting ObjC selector
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer it if instead you did

if (auto *resolver = getASTContext().getLazyResolver())
  resolver->resolveDeclSignature(this);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. But we want to avoid to resolve anything because "document structure" request should be purely syntactic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there really a resolver ? If there is a resolver it seems like a mistake to me because we don't need any kind of typechecking for syntactic requests so we shouldn't create a resolver.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed there's no resolver at this point.

// RUN: %sourcekitd-test -req=structure %s -- %s | %FileCheck %s

class C {
@IBAction init(foo: Void) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the bug also happens with @objc; you don't need @IBAction

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't happen with @objc because ObjC selector name is only resolved for @IBAction. https://github.com/apple/swift/blob/ff0d764ec922a5d69c2466499120fea0afe1c854/tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp#L1275-L1277

@rintaro
Copy link
Member Author

rintaro commented Jan 24, 2019

Another idea is not to vend ObjC selector name for @IBAction init as it's invalid anyway. Although that fixes the crasher, it only hides the actual problem. @slavapestov @akyrtzi what do you think?

@slavapestov
Copy link
Contributor

I think you'll find a lot of AST operations don't work if there's no resolver, and we haven't really tested that possibility much. Maybe SourceKit should always ensure there's a type checker present?

@akyrtzi
Copy link
Contributor

akyrtzi commented Jan 26, 2019

Maybe SourceKit should always ensure there's a type checker present?

As Rintaro mentioned earlier this is for syntactic-only functionality, so we explicitly don't want to invoke typechecking.
We understand that it's not fully accurate to get the ObjC selector without typechecking but the people that take advantage of this functionality are aware and are in favor of this being a syntactic-only determination, even if it means it's not fully accurate for all cases.

@slavapestov
Copy link
Contributor

slavapestov commented Jan 26, 2019

@akyrtzi what benefit to you derive from there not being any type checking? As work on the request evaluator progresses the distinction between 'type checking' and not will blur. Eventually we hope to get rid of the global TypeChecker object altogether. If you go down the road of not having a TypeChecker, you will get this long tail of crashes to fix for no apparent benefit.

What I'm really saying is that issuing AST queries without a TypeChecker configured is no longer a supported use-case for the compiler infrastructure and we would like it to be impossible in the future.

@akyrtzi
Copy link
Contributor

akyrtzi commented Jan 26, 2019

The benefits of syntactic-only functionality are almost instantaneous performance and robust functionality that does not depend on needing to get correct build settings, needing swift module files to have been generated, needing clang modules to build correctly with the right search paths, etc. There is a concrete benefit that I'm not sure when and if we can approximate with the evaluator but hopefully we can come close.

In any case, I discussed with Rintaro and since this is a specific code-path only for @IBActions, we'll go with what Rintaro suggested earlier which is to avoid calling this for constructor decls.

@slavapestov
Copy link
Contributor

In this case you're fixing a crash, so I'm not really buying the robustness argument. The compiler has much better test coverage in 'type checker is present' mode than this special SourceKit behavior.

@rintaro rintaro force-pushed the sourcekit-rdar47426948 branch from 106d19e to 5646499 Compare January 26, 2019 01:10
…torName()

SourceKit document structure request used to crash if if there's inititalizer
with single named parameter with `@IBAction` attribute.

This used to happen because
ConstructorDecl::isObjCZeroParameterWithLongSelector() requires
interface type of the parameter but the constructor doesn't have it at
this stage.

This change fixes that by not vending ObjC name for
constructor or destructors.

rdar://problem/47426948
@akyrtzi
Copy link
Contributor

akyrtzi commented Jan 26, 2019

With 'robustness' I'm not referring to crashers, I'm referring to the fragility of multiple systems interacting with each other and things breaking down easily if one piece goes wrong (like "swift module needs to be present, which needs the clang module to get built, which needs correct search paths from the build system to find the headers, which provided a headermap that ended up finding the wrong header", etc..)

Compared to that, the syntactic functionality only depends on handling the contents of a single swift file and nothing else.

@rintaro rintaro force-pushed the sourcekit-rdar47426948 branch from 5646499 to 606b551 Compare January 26, 2019 01:11
@rintaro rintaro changed the title [AST] Fix a crash in AbstractFunctionDecl::getObjCSelector() [SourceKit] Fix a crash in SwiftDocumentStructureWalker::getObjCSelectorName() Jan 26, 2019
@rintaro
Copy link
Member Author

rintaro commented Jan 26, 2019

@swift-ci Please smoke test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants