Skip to content

Commit d80b1d3

Browse files
Backout SE-0246 (#26809)
* Revert "Add availability information to the new Math function protocols (#24187)" This reverts commit d2f6959. * Revert "SE-0246: Protocols and static functions (#23824)" This reverts commit 57a4553. * Expected abi changes.
1 parent 8cb3284 commit d80b1d3

14 files changed

+437
-875
lines changed

stdlib/public/Darwin/CoreGraphics/CGFloat.swift.gyb

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -509,66 +509,6 @@ public func %=(lhs: inout CGFloat, rhs: CGFloat) {
509509
fatalError("%= is not available.")
510510
}
511511

512-
//===----------------------------------------------------------------------===//
513-
// Real conformance
514-
//===----------------------------------------------------------------------===//
515-
516-
%from SwiftMathFunctions import *
517-
518-
extension CGFloat: ElementaryFunctions {
519-
% for func in ElementaryFunctions + RealFunctions:
520-
521-
@_alwaysEmitIntoClient
522-
public static func ${func.decl('CGFloat')} {
523-
return CGFloat(NativeType.${func.swiftName}(${func.params("", ".native")}))
524-
}
525-
% end
526-
527-
@_alwaysEmitIntoClient
528-
public static func pow(_ x: CGFloat, _ y: CGFloat) -> CGFloat {
529-
guard x >= 0 else { return .nan }
530-
return CGFloat(NativeType.pow(x.native, y.native))
531-
}
532-
533-
@_alwaysEmitIntoClient
534-
public static func pow(_ x: CGFloat, _ n: Int) -> CGFloat {
535-
// TODO: this implementation isn't quite right for n so large that
536-
// the conversion to `CGFloat` rounds. We could also consider using
537-
// a multiply-chain implementation for small `n`; this would be faster
538-
// for static `n`, but less accurate on platforms with a good `pow`
539-
// implementation.
540-
return CGFloat(NativeType.pow(x.native, n))
541-
}
542-
543-
@_alwaysEmitIntoClient
544-
public static func root(_ x: CGFloat, _ n: Int) -> CGFloat {
545-
guard x >= 0 || n % 2 != 0 else { return .nan }
546-
// TODO: this implementation isn't quite right for n so large that
547-
// the conversion to `CGFloat` rounds.
548-
return CGFloat(NativeType.root(x.native, n))
549-
}
550-
551-
@_alwaysEmitIntoClient
552-
public static func atan2(y: CGFloat, x: CGFloat) -> CGFloat {
553-
return CGFloat(NativeType.atan2(y: y.native, x: x.native))
554-
}
555-
556-
@_alwaysEmitIntoClient
557-
public static func logGamma(_ x: CGFloat) -> CGFloat {
558-
return CGFloat(NativeType.logGamma(x.native))
559-
}
560-
561-
@_alwaysEmitIntoClient
562-
public static func signGamma(_ x: CGFloat) -> FloatingPointSign {
563-
if x >= 0 { return .plus }
564-
let trunc = x.rounded(.towardZero)
565-
if x == trunc { return .plus }
566-
let halfTrunc = trunc/2
567-
if halfTrunc == halfTrunc.rounded(.towardZero) { return .minus }
568-
return .plus
569-
}
570-
}
571-
572512
//===----------------------------------------------------------------------===//
573513
// tgmath
574514
//===----------------------------------------------------------------------===//
@@ -589,18 +529,10 @@ BinaryFunctions = [
589529
}%
590530

591531
%for ufunc in UnaryFunctions:
592-
% if ufunc in ['rint','nearbyint']:
593-
@available(swift, deprecated: 5.1, message: "Swift does not model dynamic rounding modes, use x.rounded(.toNearestOrEven) instead.")
594-
@_transparent
595-
public func ${ufunc}(_ x: CGFloat) -> CGFloat {
596-
return x.rounded(.toNearestOrEven)
597-
}
598-
% else:
599532
@_transparent
600533
public func ${ufunc}(_ x: CGFloat) -> CGFloat {
601534
return CGFloat(${ufunc}(x.native))
602535
}
603-
% end
604536

605537
%end
606538

stdlib/public/Platform/tgmath.swift.gyb

Lines changed: 61 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,44 @@ UnaryFunctions = [
155155
'acos', 'asin', 'atan', 'tan',
156156
'acosh', 'asinh', 'atanh', 'cosh', 'sinh', 'tanh',
157157
'expm1',
158-
'log1p',
159-
'erf', 'erfc',
158+
'log1p', 'logb',
159+
'cbrt', 'erf', 'erfc', 'tgamma',
160160
]
161161

162162
# These functions have a corresponding LLVM intrinsic
163+
# We call this intrinsic via the Builtin method so keep this list in
164+
# sync with core/BuiltinMath.swift.gyb
163165
UnaryIntrinsicFunctions = [
164-
'cos', 'sin', 'exp', 'exp2', 'log', 'log10', 'log2', 'nearbyint', 'rint'
166+
'cos', 'sin',
167+
'exp', 'exp2',
168+
'log', 'log10', 'log2',
169+
'nearbyint', 'rint',
165170
]
166171

172+
# (T, T) -> T
173+
BinaryFunctions = [
174+
'atan2', 'hypot', 'pow',
175+
'copysign', 'nextafter', 'fdim', 'fmax', 'fmin'
176+
]
177+
178+
# These functions have special implementations.
179+
OtherFunctions = [
180+
'scalbn', 'lgamma', 'remquo', 'nan', 'jn', 'yn'
181+
]
182+
183+
# These functions are imported correctly as-is.
184+
OkayFunctions = ['j0', 'j1', 'y0', 'y1']
185+
186+
# These functions are not supported for various reasons.
187+
UnhandledFunctions = [
188+
'math_errhandling', 'scalbln',
189+
'lrint', 'lround', 'llrint', 'llround', 'nexttoward',
190+
'isgreater', 'isgreaterequal', 'isless', 'islessequal',
191+
'islessgreater', 'isunordered', '__exp10',
192+
'__sincos', '__cospi', '__sinpi', '__tanpi', '__sincospi'
193+
]
194+
195+
167196
def AllFloatTypes():
168197
for bits in allFloatBits:
169198
yield floatName(bits), cFloatName(bits), cFuncSuffix(bits)
@@ -197,117 +226,60 @@ def TypedBinaryFunctions():
197226
% end
198227
@_transparent
199228
public func ${ufunc}(_ x: ${T}) -> ${T} {
200-
return ${T}.${ufunc}(x)
229+
return ${T}(${ufunc}${f}(${CT}(x)))
201230
}
202231
% if T == 'Float80':
203232
#endif
204233
% end
205234

206235
% end
207-
@_transparent
208-
public func cbrt(_ x: Float) -> Float {
209-
return Float.root(x, 3)
210-
}
211-
212-
@available(swift, deprecated: 5.1, message: "Use `x.exponent` or `floor(log2(x))`.")
213-
@_transparent
214-
public func logb(_ x: Float) -> Float {
215-
return Float.log2(x).rounded(.down)
216-
}
217-
218-
@_transparent
219-
public func tgamma(_ x: Float) -> Float {
220-
return Float.gamma(x)
221-
}
222-
223-
#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android))
224-
@_transparent
225-
public func cbrt(_ x: Float80) -> Float80 {
226-
return Float80.root(x, 3)
227-
}
228-
229-
@available(swift, deprecated: 5.1, message: "Use `x.exponent` or `floor(log2(x))`.")
230-
@_transparent
231-
public func logb(_ x: Float80) -> Float80 {
232-
return Float80.log2(x).rounded(.down)
233-
}
234-
235-
@_transparent
236-
public func tgamma(_ x: Float80) -> Float80 {
237-
return Float80.gamma(x)
238-
}
239-
#endif
240236

237+
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
241238
// Unary intrinsic functions
242239
// Note these have a corresponding LLVM intrinsic
243240
% for T, ufunc in TypedUnaryIntrinsicFunctions():
244241
% if T == 'Float80':
245242
#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android))
246243
% end
247-
% if ufunc[-3:] != 'int':
248244
@_transparent
249245
public func ${ufunc}(_ x: ${T}) -> ${T} {
250-
return ${T}.${ufunc}(x)
246+
return _${ufunc}(x)
251247
}
252-
% else:
253-
@available(swift, deprecated: 5.1, message: "Swift does not model dynamic rounding modes, use x.rounded(.toNearestOrEven) instead.")
248+
% if T == 'Float80':
249+
#endif
250+
% end
251+
252+
% end
253+
#else
254+
// FIXME: As of now, we cannot declare 64-bit (Double/CDouble) overlays here.
255+
// Since CoreFoundation also exports libc functions, they will conflict with
256+
// Swift overlays when building Foundation. For now, just like normal
257+
// UnaryFunctions, we define overlays only for OverlayFloatTypes.
258+
% for ufunc in UnaryIntrinsicFunctions:
259+
% for T, CT, f in OverlayFloatTypes():
260+
% if T == 'Float80':
261+
#if (arch(i386) || arch(x86_64)) && !os(Windows)
262+
% end
254263
@_transparent
255264
public func ${ufunc}(_ x: ${T}) -> ${T} {
256-
return x.rounded(.toNearestOrEven)
265+
return ${T}(${ufunc}${f}(${CT}(x)))
257266
}
258-
% end
259-
% if T == 'Float80':
267+
% if T == 'Float80':
260268
#endif
269+
% end
261270
% end
262-
263271
% end
272+
#endif
264273

265274
// Binary functions
266-
% for T, CT, f in OverlayFloatTypes():
275+
276+
% for T, CT, f, bfunc in TypedBinaryFunctions():
267277
% if T == 'Float80':
268278
#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android))
269279
% end
270280
@_transparent
271-
public func atan2(_ y: ${T}, _ x: ${T}) -> ${T} {
272-
return ${T}.atan2(y: y, x: x)
273-
}
274-
275-
@_transparent
276-
public func hypot(_ x: ${T}, _ y: ${T}) -> ${T} {
277-
return ${T}.hypot(x, y)
278-
}
279-
280-
@_transparent
281-
public func pow(_ x: ${T}, _ y: ${T}) -> ${T} {
282-
return ${T}.pow(x, y)
283-
}
284-
285-
@_transparent
286-
public func copysign(_ x: ${T}, _ y: ${T}) -> ${T} {
287-
return ${T}(signOf: y, magnitudeOf: x)
288-
}
289-
290-
@_transparent
291-
public func fdim(_ x: ${T}, _ y: ${T}) -> ${T} {
292-
return ${T}(fdim${f}(${CT}(x), ${CT}(y)))
293-
}
294-
295-
@available(swift, deprecated: 5.1, message: "Use the .nextUp and .nextDown properties.")
296-
@_transparent
297-
public func nextafter(_ x: ${T}, _ y: ${T}) -> ${T} {
298-
return y > x ? x.nextUp : (y < x ? x.nextDown : y)
299-
}
300-
301-
@available(swift, deprecated: 5.1, message: "Use ${T}.minimum( ) or Swift.min( )")
302-
@_transparent
303-
public func fmin(_ x: ${T}, _ y: ${T}) -> ${T} {
304-
return .minimum(x, y)
305-
}
306-
307-
@available(swift, deprecated: 5.1, message: "Use ${T}.maximum( ) or Swift.max( )")
308-
@_transparent
309-
public func fmax(_ x: ${T}, _ y: ${T}) -> ${T} {
310-
return .maximum(x, y)
281+
public func ${bfunc}(_ lhs: ${T}, _ rhs: ${T}) -> ${T} {
282+
return ${T}(${bfunc}${f}(${CT}(lhs), ${CT}(rhs)))
311283
}
312284
% if T == 'Float80':
313285
#endif
@@ -325,7 +297,9 @@ public func fmax(_ x: ${T}, _ y: ${T}) -> ${T} {
325297
% end
326298
@_transparent
327299
public func lgamma(_ x: ${T}) -> (${T}, Int) {
328-
return (${T}.logGamma(x), ${T}.signGamma(x) == .plus ? 1 : -1)
300+
var sign = Int32(0)
301+
let value = lgamma${f}_r(${CT}(x), &sign)
302+
return (${T}(value), Int(sign))
329303
}
330304
#endif
331305

0 commit comments

Comments
 (0)