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

Deprecating M_PI and a few other constants in favor of better API #6764

Merged
merged 2 commits into from
Jan 13, 2017

Conversation

moiseev
Copy link
Contributor

@moiseev moiseev commented Jan 12, 2017

Deprecating M_PI, M_PI_2, M_PI_4, M_SQRT2, M_SQRT1_2.
Sugesting using Double.pi or even just .pi to allow type be inferred
and avoid a type-cast.

Fixes: rdar://problem/26602190

Deprecating `M_PI`, `M_PI_2`, `M_PI_4`, `M_SQRT2`, `M_SQRT1_2`.
Sugesting using `Double.pi` or even just `.pi` to allow type be inferred
and avoid a type-cast.

Fixes: <rdar://problem/26602190>
public let M_PI_4 = Double.pi / 4

@available(swift, deprecated: 3.0, message: "Please use '2.squareRoot()'.")
public let M_SQRT2 = 2.0.squareRoot()
Copy link
Contributor

Choose a reason for hiding this comment

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

Will LLVM constant-fold this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah! Good question. It does not. /cc @stephentyrone

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also /cc @swiftix and @shajrawi. Maybe it's not too hard to constant fold it in SIL?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm somewhat surprised that LLVM doesn't manage to constant-fold it. We should figure out why not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's not LLVM's fault, but Swift's. According to Roman we don't currently lower sqrt into an llvm intrinsic, so LLVM has no chances.

Copy link
Contributor

@jckarter jckarter Jan 13, 2017

Choose a reason for hiding this comment

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

LLVM can constant-fold the C sqrt, not only llvm.sqrt, can't it? Does squareRoot boil down to a call to sqrt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Digging into it, I originally had a static inline wrapper around C sqrt. However, that ran into https://bugs.swift.org/browse/SR-2089, so it had to be replaced with a non-inline stub [some history here: https://github.com//pull/3454]. We should be able to fix that now that 2089 is addressed, which should also let us constant fold these, I think.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll prep a pull request with sqrt inlined again and see where we are.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stephentyrone Please mention me on the PR when it's ready.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah... nevermind. Reading email from the bottom. Found it already =)

@moiseev
Copy link
Contributor Author

moiseev commented Jan 12, 2017

@swift-ci Please test

@stephentyrone
Copy link
Contributor

As to the practical matter of this pull, what you have for the .pi constants LGTM.

@moiseev
Copy link
Contributor Author

moiseev commented Jan 13, 2017

For the record: I filed rdar://problem/30003973 and rdar://problem/30004033 to track the rest of the work.

@moiseev moiseev merged commit 0d0dc79 into swiftlang:master Jan 13, 2017
@moiseev moiseev deleted the pi branch January 13, 2017 00:36
@lattner
Copy link
Contributor

lattner commented Jan 13, 2017

Yay, thanks!

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.

5 participants