Skip to content

[PlaygroundTransform] Add experimental feature PlaygroundExtendedCallbacks to pass more info in callbacks #67215

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 2 commits into from
Jul 18, 2023

Conversation

abertelrud
Copy link
Contributor

Summary

Adds the experimental feature PlaygroundExtendedCallbacks which (when -playground is also passed) causes the playground transform to use alternate forms of the result-value, scope-entry, and scope-exit callbacks that include the module name and file path of the source file.

Rationale

The previous callbacks included integers for the module number and file number, but this was cumbersome to use because it required the caller to create source symbols with magical names formed from the module name and file path that the playground transform knew how to look up.

The extended callbacks in the experimental feature instead pass these strings as string literals. This is an experimental feature because of the need to measure the performance impact, and because of the need to provide an option to control which set of callbacks to use so that existing clients of the playground transform can opt into it when ready. It's also likely that we'll want to pass more information in the extended callbacks, such as an indication of the kind of result is being logged (e.g. a loop iteration variable vs a return statement vs a variable assignment). So this should be considered the first of a series of experimental improvements that will then be pitched as an actual, non-experimental v2.0 of the playground transform callback API. Because of the nature of how the playground transform is used, it's much easier to iterate on the functionality in the form of an experimental feature rather than using only desktop debug builds of the Swift compiler.

Changes

  • define a new experimental feature called PlaygroundExtendedCallbacks
  • modify the playground transform step in sema to pass the module name and file name literals when the experimental feature is set
  • add a unit test for the extended callbacks

There is no change in behaviour of the playground transform when PlaygroundExtendedCallbacks is not enabled.

rdar://109911742

@abertelrud
Copy link
Contributor Author

@swift-ci please test

@abertelrud
Copy link
Contributor Author

@swift-ci please test windows platform

@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test

@abertelrud abertelrud requested a review from cwakamo July 13, 2023 23:25
@abertelrud
Copy link
Contributor Author

@cwakamo I think you may have looked at this code in the past. Do you have any concern about adding this experimental flag and callback?

@abertelrud
Copy link
Contributor Author

@xedin I think you reviewed the previous playground transform PR... do you have any concerns?


// Use #sourceLocation if it exists.
SourceLoc sl = SR.Start;
auto *vf = Context.SourceMgr.getVirtualFile(sl);
Copy link
Member

Choose a reason for hiding this comment

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

SourceManager has an operation getDisplayNameForLoc that is used for printing the name in other compiler outputs. Would you prefer to use that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion @DougGregor! In this case, what we'd want to pass to the callback is the actual path through which the file can later be opened — the phrase "display name" suggests that this function might not always return a literal path, but from the implementation, it looks as if it does. Ideally we'd want the same path that is emitted in .dia files — from the code, it looks as if that's indeed using getDisplayNameForLoc — is that correct?

Copy link
Member

Choose a reason for hiding this comment

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

I believe that's correct

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the advice. It looks good as far as I can tell. I'll update the PR.

bshank612 and others added 2 commits July 17, 2023 13:23
…ore information in `-playground` callbacks

Adds the experimental feature `PlaygroundExtendedCallbacks` which (when `-playground` is also passed) causes the playground transform to use alternate forms of the result-value, scope-entry, and scope-exit callbacks that include the module name and file path of the source file.

The previous callbacks included integers for the module number and file number, but this was cumbersome to use because it required the caller to create source symbols with magical names formed from the module name and file path that the playground transform knew how to look up.

The extended callbacks in the experimental feature instead pass these strings as string literals. This is an experimental feature because of the need to measure the performance impact, and because of the need to provide an option to control which set of callbacks to use so that existing clients of the playground transform can opt into it when ready. It's also likely that we'll want to pass more information in the extended callbacks, such as an indication of the kind of result is being logged (e.g. a loop iteration variable vs a return statement vs a variable assignment). So this should be considered the first of a series of experimental improvements that will then be pitched as an actual, non-experimental v2.0 of the playground transform callback API. Because of the nature of how the playground transform is used, it's much easier to iterate on the functionality in the form of an experimental feature rather than using only desktop debug builds of the Swift compiler.

Changes:
- define a new experimental feature called `PlaygroundExtendedCallbacks`
- modify the playground transform step in sema to pass the module name and file name literals when the experimental feature is set
- add a unit test for the extended callbacks

There is no change in behaviour when `PlaygroundExtendedCallbacks` is not enabled.

rdar://109911742
@abertelrud abertelrud force-pushed the eng/anders/playground-transform-extended-callbacks branch from 7e4073a to ac1c1dc Compare July 17, 2023 20:25
@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test

@abertelrud
Copy link
Contributor Author

Linux failure looks unrelated. Trying again.

@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test linux

1 similar comment
@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test linux

@abertelrud abertelrud merged commit d6e0ca3 into main Jul 18, 2023
@abertelrud abertelrud deleted the eng/anders/playground-transform-extended-callbacks branch July 18, 2023 18:55
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