Skip to content

Conversation

swiftix
Copy link
Contributor

@swiftix swiftix commented Jun 5, 2017

Move the error reporting slow-path into a separate function, which is not inlined or specialized.
This reduced the stdlib code size by almost 1%.

@swiftix
Copy link
Contributor Author

swiftix commented Jun 5, 2017

@swift-ci please smoke test

@swiftix swiftix requested a review from itaiferber June 5, 2017 23:02
@swiftix
Copy link
Contributor Author

swiftix commented Jun 5, 2017

@itaiferber Itai, do you mind having a look? I just re-factored the slow path. No semantic changes are intended.

Copy link
Contributor

@itaiferber itaiferber left a comment

Choose a reason for hiding this comment

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

Thanks for putting this together! 😄 I think we can make this even simpler, though.

However: given that this error production is never inlined, what's the tradeoff here we'll be making in terms of size for speed? Is there any sort of noticeable slowdown because we're not inlining?

I also have to admit, I'm not familiar with the @_semantics being applied here. What do they optimize for?

@_semantics("optimize.sil.specialize.generic.never")
@_semantics("optimize.sil.specialize.generic.partial.never")
@inline(never)
internal func decodeError<T: Decodable>(_ type: T.Type, forKey key: Key) throws -> T {
Copy link
Contributor

@itaiferber itaiferber Jun 5, 2017

Choose a reason for hiding this comment

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

What's the point of this throwing the error instead of just returning a new error?
Can't this just be internal func _errorInDecoding(_ type: T.Type, forKey key: Key) -> DecodingError { ... }?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! I just tried to be as similar as possible to the original code.

@_semantics("optimize.sil.specialize.generic.never")
@_semantics("optimize.sil.specialize.generic.partial.never")
@inline(never)
internal func decodeError<T: Decodable>(_ type: T.Type) throws -> T {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here. Why pretend to return a T when we can just return the error?

@swiftix
Copy link
Contributor Author

swiftix commented Jun 5, 2017

@itaiferber We are not inlining the slow path now. So, we pay a price of a generic function call. But since it is a slow path, it doesn't matter.

The @_semantics are used to prevent the generic specializer from (partially) specializing the generic code for concrete types, because this would result in the code bloat in the object file.

…e size

Move the error reporting slow-path into a separate function, which is not inlined or specialized.
This reduced the stdlib code size by almost 1%.
@swiftix swiftix force-pushed the inliner-improvements2 branch from 8605699 to 890c2d5 Compare June 5, 2017 23:28
@swiftix
Copy link
Contributor Author

swiftix commented Jun 5, 2017

@itaiferber I address your review comments. Looks better now?

@swiftix
Copy link
Contributor Author

swiftix commented Jun 6, 2017

@swift-ci please smoke test

1 similar comment
@swiftix
Copy link
Contributor Author

swiftix commented Jun 6, 2017

@swift-ci please smoke test

@swiftix
Copy link
Contributor Author

swiftix commented Jun 6, 2017

@itaiferber Let me know if it is OK to merge or if you have any further improvements suggestions.

@itaiferber
Copy link
Contributor

LGTM but I'd like to be sure with a full test, if you don't mind.

@itaiferber
Copy link
Contributor

@swift-ci Please test and merge

@swiftix swiftix merged commit ff1e770 into swiftlang:master Jun 6, 2017
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