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

Support Playgrounds in any Swift file #3

Open
jerrymarino opened this issue Jun 21, 2017 · 0 comments
Open

Support Playgrounds in any Swift file #3

jerrymarino opened this issue Jun 21, 2017 · 0 comments

Comments

@jerrymarino
Copy link
Owner

It should be possible to compile and execute a playground for every Swift file.

A few important use cases come to mind that can leverage this:

  • Simple programs which are executable: a program where logic is in a main.swift.

  • Unit testing. Playgrounds are super applicable to unit testing, since it allows the user to see program state within a test case. This is easier to work with than the existing approach people have adpoted: copying all of the code they want to play with into a playground file.

I think this is a good addition and would make Swift development more interactive overall.

Caveats

Many Swift files don't contain don't contain code that executes, so for a large subset of files, this isn't 100% useful. For example, MyModel.swift is just a class definition.

Alternatives Considered

Copy all of the code in question into a playground.

Implementation

At the compiler level, we are just performing a transform that inserts the playground logging code in a module. I think this pass should work for any file. In my initial testing, it seems to work fine on some sample code.

Pass 1 will use compile_commands.json to get a base a compiler invocation and augment it to include the playground bits.

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

No branches or pull requests

1 participant