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

Missing playground results for init/deinit in a class wrapped in a struct #77498

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

abertelrud
Copy link
Contributor

@abertelrud abertelrud commented Nov 8, 2024

When a decl that has init or deinit is nested inside another type, those init or deinit implementations aren't playground-transformed.

Details

The reason is that the playground transform uses an ASTWalker to get to the top-level structure, but then once it’s inside a type, it does directly nested transformDecl() calls. And that inner check was for too narrow of a type.

The problem in this case was that the dyn_cast<FuncDecl>(D) was too narrow and didn’t include constructors/destructors. We want dyn_cast<AbstractFunctionDecl>(D).

Future work

It's unfortunate that the playground transform reaches decls in two different ways (using an ASTWalker to get to the top-level decls but then using directly nested calls below). This seems to be worth resolving at some point (perhaps by using the ASTWalker for the whole traversal?), but that’s a larger change, and so this is worth addressing with a safer short-term fix.

Also, there are still missing results with accessors that are associated with properties in nested types. The fix for that will follow in a separate PR with its own unit test. Edit: The follow-on fix is here: #77530

Changes

  • change a dyn_cast<FuncDecl> to a dyn_cast<AbstractFunctionDecl> in PlaygroundTransform.cpp
  • add a unit test nested init and deinit (this test also tests the unnested case)

rdar://137316110

@abertelrud abertelrud requested review from chrismiles and etcwilde and removed request for xedin, slavapestov and hborla November 8, 2024 22:50
@abertelrud abertelrud self-assigned this Nov 8, 2024
…class wrapped in a struct)

The problem here is when wrapping a type that has constructors and destructors inside another type.

The reason is that the playground transform uses an `ASTWalker` to get to the top-level structure, but then once it’s inside a type, it does directly nested transformDecl() calls.  And that inner check was for too narrow of a type.

The problem in this case was that the `dyn_cast<FuncDecl>(D)` was too narrow and didn’t include constructors/destructors.  We want `dyn_cast<AbstractFunctionDecl>(D)`.

We should probably resolve this duality (using an `ASTWalker` to get to the top-level decls but then using directly nested calls below) at some point, but that’s a larger change, and so this is worth addressing with a safer short-term fix.

Changes:
- change a `dyn_cast<FuncDecl>` to a `dyn_cast<AbstractFunctionDecl>` in PlaygroundTransform.cpp
- add a unit test nested init and deinit (this test also tests the unnested case)

rdar://137316110
@abertelrud abertelrud force-pushed the eng/anders/137316110-nested-init-playground-results branch from 34c18ec to 3db28c8 Compare November 8, 2024 22:53
@abertelrud
Copy link
Contributor Author

abertelrud commented Nov 8, 2024

I hdd accidentally included some temporary cherry-picks of @chrismiles's now-landed branch, so this latest update removed them. This is now ready for review.

@abertelrud abertelrud requested a review from xedin November 8, 2024 22:54
@abertelrud abertelrud changed the title [Playground] Missing playground results for init and deinit in a class wrapped in a struct) Missing playground results for init/deinit in a class wrapped in a struct Nov 8, 2024
@abertelrud
Copy link
Contributor Author

@swift-ci Please smoke test

@abertelrud
Copy link
Contributor Author

Adding @hborla and @slavapestov who are also listed as code owners in a second PR I'm opening for the same source file (they were not in this list when I opened this PR, IIRC).

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.

2 participants