Skip to content

Add [nonatomic] attribute to all SIL reference counting instructions. #2067

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
Apr 7, 2016

Conversation

swiftix
Copy link
Contributor

@swiftix swiftix commented Apr 5, 2016

What's in this pull request?

Add [nonatomic] attribute to all SIL reference counting instructions.

Support serialization/deserialization, printing and parsing of this attribute.
Update all affected places to explicitly use the new attribute.

THIS IS WORK IN PROGRESS. DO NOT MERGE YET.

Resolved bug number: (SR-249)


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

Triggering Swift CI

The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:

Smoke Testing

Platform Comment
All supported platforms @swift-ci Please smoke test
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
OS X platform @swift-ci Please test OS X platform
Linux platform @swift-ci Please test Linux platform

Note: Only members of the Apple organization can trigger swift-ci.

@swiftix
Copy link
Contributor Author

swiftix commented Apr 5, 2016

@swift-ci Please smoke test Linux platform

@swiftix
Copy link
Contributor Author

swiftix commented Apr 5, 2016

@swift-ci Please smoke test Linux platform

1 similar comment
@swiftix
Copy link
Contributor Author

swiftix commented Apr 5, 2016

@swift-ci Please smoke test Linux platform

@swiftix
Copy link
Contributor Author

swiftix commented Apr 5, 2016

@jckarter Joe, do you mind taking a look?

This PR contains a lot of almost mechanical changes and boiler plate code to introduce the new [nonatomic] attribute for all reference counting SIL instructions. This includes:

  • serialization/deserialization of SIL with this attribute
  • parsing and printing SIL with this attribute
  • Updating all constructors/builders to take an explicit parameter to set this attribute and updating all the relevant call sites to pass this parameter
  • propagating the nonatomic flag from a SIL instruction through the IRGen internals down to the places, where the actual reference counting runtime function is picked based on this flag.

@rjmccall
Copy link
Contributor

rjmccall commented Apr 5, 2016

Please make the isAtomic flag an enum class : bool instead of a bare bool, either in IRGen.h or somewhere in AST/SIL.

Do you really need to pass this to the in-memory operations? You're not doing anything in SIL that would allow IRGen to ever use anything except atomic refcounting for them.

@swiftix
Copy link
Contributor Author

swiftix commented Apr 5, 2016

@rjmccall

Please make the isAtomic flag an enum class : bool instead of a bare bool, either in IRGen.h or somewhere in AST/SIL.

Sure. Good point!

Do you really need to pass this to the in-memory operations? You're not doing anything in SIL that would allow IRGen to ever use anything except atomic refcounting for them.

I'm not sure I understand your question. Can you elaborate?

My overall plan is that there will be a SIL optimization pass which marks some of SIL refcounting instructions as nonatomic. IRGen then needs to lower them properly.

So far, I added this "isAtomic" flag to some APIs in a couple of IRGen base classes. As a result a bunch of classes derived from those had to be adjusted as well to add this additional parameter to their corresponding derived functions.

Do you mean that I changed too many classes in IRGen and some of those changes could be avoided, because they are not necessary?

@rjmccall
Copy link
Contributor

rjmccall commented Apr 6, 2016

I mean that you've changed the SIL ref-counting operations (retain, release, etc.), but not the SIL memory access operations (load, store, copy_addr, destroy_addr); and yet you've added the isAtomic flag to all the IRGen load/store operations.

@swiftix
Copy link
Contributor Author

swiftix commented Apr 6, 2016

Based on @rjmccall's comment, I introduced a enum class Atomicity : bool, which is now used instead of a simple bool flag. This is definitely safer than using a boolean.

In the next update, I'm going to address the comment about the in-memory operations.

@swiftix
Copy link
Contributor Author

swiftix commented Apr 6, 2016

@swift-ci Please smoke test Linux platform

@jckarter
Copy link
Contributor

jckarter commented Apr 6, 2016

Looks good.

@swiftix
Copy link
Contributor Author

swiftix commented Apr 7, 2016

@rjmccall I removed the atomicity flag from destroy and loadAsCopy methods.

But

  • LoadableTypeInfo::copy is used by visitRetainValueInst in IRGenSIL.cpp
  • LoadableTypeInfo::consume is used by visitReleaseValueInst in IRGenSIL.cpp

So, I guess consume and copy methods still need this atomicity parameter, or?

@swiftix
Copy link
Contributor Author

swiftix commented Apr 7, 2016

@swift-ci Please smoke test Linux platform

@rjmccall
Copy link
Contributor

rjmccall commented Apr 7, 2016

That makes sense to me.

@swiftix
Copy link
Contributor Author

swiftix commented Apr 7, 2016

@rjmccall OK. Thank for reviewing this PR, John! I'll test and merge.

Properly lower reference counting SIL instructions with nonatomic attribute as invocations of corresponding non-atomic reference counting runtime functions.
@swiftix
Copy link
Contributor Author

swiftix commented Apr 7, 2016

@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