Skip to content

[stdlib/private][OSLog] Support expressive, fprintf-style formatting options for integers passed to os log string interpolation. #29518

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 1 commit into from
Feb 8, 2020

Conversation

ravikandhadai
Copy link
Contributor

@ravikandhadai ravikandhadai commented Jan 28, 2020

@milseman This PR adds the IntegerFormatting.swift and StringAlignment.swift features to the new os log overlay, and updates the OSLog test suites to make it compatible with these changes. These files are almost same as what you had made, expect for the following changes:

  1. I have omitted the separator option of IntegerFormatting. This is because, as of now, os log is not supporting custom separators and therefore I did not want the option to be available to os log users. Similarly, I have also omitted Fill character from String.Alignment as os log would not be supporting anything but spaces, as of now.

  2. I have updated the implementation of formatSpecifier function slightly so that it uses only operations supported by the constant evaluator. This mostly involves replacing all string operations with +=.

  3. The formatSpecifier function now takes the privacy specifiers also as a parameter as they also add a flag to the format specifier.

  4. I have made the formatSpecifier function return a String instead of an optional String?. The conditions under which the function returned nil are now turned into precondition failures. This would enable the constant evaluator to report a reason for failure at compile time when those conditions are reached (without having to return an explicit error message).

I have not yet added support for formatting strings. I will create a new PR for that.

@ravikandhadai
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 3c5d62e2c93c86c3bc1533a5ad231711e64666bd

@ravikandhadai
Copy link
Contributor Author

@swift-ci Please smoke test Linux Platform

@ravikandhadai
Copy link
Contributor Author

@swift-ci Please test Linux Platform

@ravikandhadai
Copy link
Contributor Author

ravikandhadai commented Feb 6, 2020

Rebasing on latest master and resolving conflicts.

@ravikandhadai
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Feb 6, 2020

Build failed
Swift Test OS X Platform
Git Sha - 4b70b90d849407b6a03e2c70e817d98a71f5cd77

@ravikandhadai
Copy link
Contributor Author

@swift-ci Please test macOS Platform

@swift-ci
Copy link
Contributor

swift-ci commented Feb 6, 2020

Build failed
Swift Test OS X Platform
Git Sha - 4b70b90d849407b6a03e2c70e817d98a71f5cd77

@ravikandhadai
Copy link
Contributor Author

@swift-ci Please smoke test

@ravikandhadai
Copy link
Contributor Author

@swift-ci Please test macOS Platform

Copy link
Member

@milseman milseman left a comment

Choose a reason for hiding this comment

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

I'd recommend carefully naming a few things, otherwise LGTM

@@ -0,0 +1,317 @@
@frozen
public struct IntegerFormatting: Equatable {
Copy link
Member

Choose a reason for hiding this comment

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

I'd pick a specific name to avoid potential future conflicts or shadowing like OSLogIntegerFormatting

@@ -0,0 +1,67 @@
@frozen
public enum CollectionBound {
Copy link
Member

Choose a reason for hiding this comment

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

I'd pick a specific name to avoid potential future conflicts or shadowing like OSCollectionBound


extension String {
@frozen
public struct Alignment {
Copy link
Member

Choose a reason for hiding this comment

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

I'd pick a specific name to avoid potential future conflicts or shadowing like OSLogStringAlignment, and not have this be in the String namespace

options for integers passed to os log string interpolation.
@ravikandhadai ravikandhadai force-pushed the oslog-string-formatting branch from 4b70b90 to 4f2a55b Compare February 8, 2020 01:39
@ravikandhadai
Copy link
Contributor Author

Pushed a commit that fixes the comments.

@ravikandhadai
Copy link
Contributor Author

@swift-ci Please test and merge

1 similar comment
@ravikandhadai
Copy link
Contributor Author

@swift-ci Please test and merge

@swift-ci swift-ci merged commit eed603d into swiftlang:master Feb 8, 2020
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