Skip to content

Change the compiler ABI of keypaths. #20493

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 5 commits into from
Nov 10, 2018

Conversation

rjmccall
Copy link
Contributor

@rjmccall rjmccall commented Nov 10, 2018

Previously, the stdlib provided:

  • getters for AnyKeyPath and PartialKeyPath, which have remained;

  • a getter for KeyPath, which still exists alongside a new read coroutine; and

  • a pair of owned mutable addressors that provided modify-like behavior for WritableKeyPath and ReferenceWritableKeyPath, which have been replaced with modify coroutines and augmented with dedicated setters.

SILGen then uses the most efficient accessor available for the access it's been asked to do: for example, if it's been asked to produce a borrowed r-value, it uses the read accessor.

Providing a broad spectrum of accessor functions here seems acceptable because the code-size hit is fixed-size: we don't need to generate extra code per storage declaration to support more alternatives for key paths.

Note that this is just the compiler ABI; the implementation is still basically what it was. That means the implementation of the setters and the read accessor is pretty far from optimal. But we can improve the implementation later; we can't improve the ABI.

The coroutine accessors have to be implemented in C++ and used via hand-rolled declarations in SILGen because it's not currently possible to declare independent coroutine accessors in Swift.

Previously, the stdlib provided:

- getters for AnyKeyPath and PartialKeyPath, which have remained;

- a getter for KeyPath, which still exists alongside a new read
  coroutine; and

- a pair of owned mutable addressors that provided modify-like behavior
  for WritableKeyPath and ReferenceWritableKeyPath, which have been
  replaced with modify coroutines and augmented with dedicated setters.

SILGen then uses the most efficient accessor available for the access
it's been asked to do: for example, if it's been asked to produce a
borrowed r-value, it uses the read accessor.

Providing a broad spectrum of accessor functions here seems acceptable
because the code-size hit is fixed-size: we don't need to generate
extra code per storage declaration to support more alternatives for
key paths.

Note that this is just the compiler ABI; the implementation is still
basically what it was.  That means the implementation of the setters
and the read accessor is pretty far from optimal.  But we can improve
the implementation later; we can't improve the ABI.

The coroutine accessors have to be implemented in C++ and used via
hand-rolled declarations in SILGen because it's not currently possible
to declare independent coroutine accessors in Swift.
@rjmccall rjmccall requested a review from jckarter November 10, 2018 07:10
@rjmccall
Copy link
Contributor Author

@swift-ci Please test.

@rjmccall
Copy link
Contributor Author

@swift-ci Please benchmark

@rjmccall
Copy link
Contributor Author

@swift-ci Please test source compatibility.

@swift-ci
Copy link
Contributor

Build comment file:

No performance and code size changes


@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 3e5165d

@rjmccall
Copy link
Contributor Author

Random LLDB failures?

@rjmccall
Copy link
Contributor Author

Source compatibility failures are just due to the introduction of AdditiveArithmetic.

@rjmccall
Copy link
Contributor Author

@swift-ci Please smoke test

@rjmccall rjmccall merged commit 44e0f44 into swiftlang:master Nov 10, 2018
@rjmccall rjmccall deleted the keypath-compiler-abi branch November 10, 2018 19:18
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