Skip to content

Eagerly emit getters at Onone. #75847

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

Merged
merged 1 commit into from
Aug 14, 2024

Conversation

augusto2112
Copy link
Contributor

Force SILGen to also eagerly emit getters when compiling at Onone. The reason for this is that getters (even not user-written ones, generated by result builders) can, and are often called by users debugging swift programs, and should be available for that reason.

rdar://133329303

@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

@@ -387,6 +387,12 @@ bool SILDeclRef::hasUserWrittenCode() const {
llvm_unreachable("Unhandled case in switch!");
}

bool SILDeclRef::isGetter() const {
if (auto *accessor = dyn_cast_or_null<AccessorDecl>(getFuncDecl()))
return accessor->isGetter();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this also going to be true for getters of ClangImporter-synthesized properties? We probably don't want to emit all of those.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@slavapestov are those ObjC properties that are imported into Swift? Couldn't they also be accessed in the debugger?

Copy link
Contributor

Choose a reason for hiding this comment

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

When evaluating an objective-C method call, the compiler generates the right thunks with shared linkage. That's why we don't want to force emission of those symbols if they're not needed. So perhaps the mayDelay computation needs to check the SIL linkage.

// Implicit decls may be delayed if they can't be used externally.
auto linkage = constant.getLinkage(ForDefinition);
bool mayDelay = !constant.hasUserWrittenCode() &&
bool mayDelay = !isOnoneGetter && !constant.hasUserWrittenCode() &&
Copy link
Contributor

@slavapestov slavapestov Aug 12, 2024

Choose a reason for hiding this comment

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

Maybe hasUserWrittenCode() should also return true for property wrappers? I see code coverage uses that flag too so the behavior should be consistent here.

Copy link
Contributor Author

@augusto2112 augusto2112 Aug 12, 2024

Choose a reason for hiding this comment

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

I thought about that too, since @hamishknight wrote it maybe they can chime in if that'd be appropriate or not. Maybe any getter whose storage is not implicit should be classified as user-written

Copy link
Contributor

Choose a reason for hiding this comment

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

The intention behind hasUserWrittenCode was "does this decl contain any executable code that appears in a source file?", which is needed for code coverage since we don't want to emit coverage maps for anything that won't have any source regions. It's also used here because that check is also what we need for "do we need to emit this for SILOptimizer diagnostics?". It seems like we need a different check here for the debugger which is more "can this decl be referenced from user-written code?". I wonder if we can leverage the isSynthesized Decl flag for that, IIRC that's effectively what it models for implicit decls.

Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, should this behavior also be limited to cases where we're emitting debug info?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Out of curiosity, should this behavior also be limited to cases where we're emitting debug info?

We usually avoid debug info interfering with code generation.

Force SILGen to also eagerly emit getters when compiling at Onone.
The reason for this is that getters (even not user-written ones,
generated by result builders) can, and are often called by users
debugging swift programs, and should be available for that reason.

rdar://133329303
@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

@augusto2112 augusto2112 merged commit 00cac25 into swiftlang:main Aug 14, 2024
3 checks passed
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