Skip to content

Commit 08cf1de

Browse files
author
Max Moiseev
committed
[WIP] fixing some of the integer related test failures
1 parent 530e97e commit 08cf1de

File tree

7 files changed

+34
-60
lines changed

7 files changed

+34
-60
lines changed

stdlib/public/core/CTypes.swift

-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ func _memcpy(
205205
let dest = destination._rawValue
206206
let src = src._rawValue
207207
let size = UInt64(size)._value
208-
let zero: Int32 = 0
209208
Builtin.int_memcpy_RawPointer_RawPointer_Int64(
210209
dest, src, size,
211210
/*alignment:*/ Int32()._value,
@@ -224,7 +223,6 @@ func _memmove(
224223
let dest = destination._rawValue
225224
let src = src._rawValue
226225
let size = UInt64(size)._value
227-
let zero: Int32 = 0
228226
Builtin.int_memmove_RawPointer_RawPointer_Int64(
229227
dest, src, size,
230228
/*alignment:*/ Int32()._value,

stdlib/public/core/Integers.swift.gyb

+9-8
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,7 @@ extension ${Protocol} {
10081008
% for x in binaryArithmetic[Protocol]:
10091009
% callLabel = x.firstArg + ': ' if not x.firstArg == '_' else ''
10101010
${operationComment(x.operator)}
1011+
@_transparent
10111012
public func ${x.name}(${x.firstArg} rhs: Self) -> Self {
10121013
var lhs = self
10131014
lhs.${x.mutatingName}(${callLabel}rhs)
@@ -2049,7 +2050,7 @@ extension FixedWidthInteger {
20492050
public mutating func ${x.mutatingName}(${x.firstArg} other: Self) {
20502051
let (result, overflow) = self.${x.name}WithOverflow(${callLabel}other)
20512052
// FIXME(integers): uncomment the check
2052-
//_precondition(overflow != .none, "Overflow in ${x.mutatingName}")
2053+
_precondition(overflow != .none, "Overflow in ${x.mutatingName}")
20532054
self = result
20542055
}
20552056

@@ -2178,19 +2179,19 @@ extension UnsignedInteger where Self : FixedWidthInteger {
21782179
@_transparent
21792180
public init<T : BinaryInteger>(_ source: T) {
21802181
// FIXME(integers): uncomment checks
2181-
//_precondition(source >= 0,
2182-
//"Negative value is not representable")
2183-
//let requiredBits = source.minimumSignedRepresentationBitWidth - 1
2184-
//_precondition(requiredBits <= Self.bitWidth,
2185-
//"Not enough bits to represent an unsigned value")
2182+
_precondition(source >= 0,
2183+
"negative value is not representable")
2184+
let requiredBits = source.minimumSignedRepresentationBitWidth - 1
2185+
_precondition(requiredBits <= Self.bitWidth,
2186+
"Not enough bits to represent an unsigned value")
21862187
self.init(extendingOrTruncating: source)
21872188
}
21882189

21892190
@_transparent
21902191
public init?<T : BinaryInteger>(exactly source: T) {
21912192
// FIXME(integers): uncomment the check
2192-
//_precondition(source >= 0,
2193-
//"Negative value is not representable")
2193+
_precondition(source >= 0,
2194+
"Negative value is not representable")
21942195
let requiredBits = source.minimumSignedRepresentationBitWidth - 1
21952196
if requiredBits > Self.bitWidth {
21962197
return nil

test/Constraints/closures.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func someGeneric19997471<T>(_ x: T) {
261261
func f20371273() {
262262
let x: [Int] = [1, 2, 3, 4]
263263
let y: UInt = 4
264-
x.filter { $0 == y } // expected-error {{binary operator '==' cannot be applied to operands of type 'Int' and 'UInt'}}
264+
_ = x.filter { $0 == y } // expected-error {{binary operator '==' cannot be applied to operands of type 'Int' and 'UInt'}}
265265
// expected-note @-1 {{overloads for '==' exist with these partially matching parameter lists: (UInt, UInt), (Int, Int)}}
266266
}
267267

test/expr/expressions.swift

+4-23
Original file line numberDiff line numberDiff line change
@@ -754,12 +754,12 @@ func testOptionalTypeParsing(_ a : AnyObject) -> String {
754754
func testParenExprInTheWay() {
755755
let x = 42
756756

757-
if x & 4.0 {} // expected-error {{binary operator '&' cannot be applied to operands of type 'Int' and 'Double'}} expected-note {{expected an argument list of type '(Int, Int)'}}
757+
if x & 4.0 {} // expected-error {{binary operator '&' cannot be applied to operands of type 'Int' and 'Double'}} expected-note {{expected an argument list of type '(Self, Self)'}}
758758

759-
if (x & 4.0) {} // expected-error {{binary operator '&' cannot be applied to operands of type 'Int' and 'Double'}} expected-note {{expected an argument list of type '(Int, Int)'}}
759+
if (x & 4.0) {} // expected-error {{binary operator '&' cannot be applied to operands of type 'Int' and 'Double'}} expected-note {{expected an argument list of type '(Self, Self)'}}
760760

761761
if !(x & 4.0) {} // expected-error {{no '&' candidates produce the expected contextual result type 'Bool'}}
762-
//expected-note @-1 {{overloads for '&' exist with these result types: UInt8, Int8, UInt16, Int16, UInt32, Int32, UInt64, Int64, UInt, Int, T, Self}}
762+
//expected-note @-1 {{produces result of type 'Self'}}
763763

764764

765765
if x & x {} // expected-error {{'Int' is not convertible to 'Bool'}}
@@ -791,7 +791,7 @@ func inoutTests(_ arr: inout Int) {
791791
inoutTests(&x)
792792

793793
// <rdar://problem/17489894> inout not rejected as operand to assignment operator
794-
&x += y // expected-error {{'&' can only appear immediately in a call argument list}}
794+
&x += y // expected-error {{cannot pass immutable value of type 'inout Int' as inout argument}}}
795795

796796
// <rdar://problem/23249098>
797797
func takeAny(_ x: Any) {}
@@ -843,25 +843,6 @@ func r22913570() {
843843
}
844844

845845

846-
// <rdar://problem/23708702> Emit deprecation warnings for ++/-- in Swift 2.2
847-
func swift22_deprecation_increment_decrement() {
848-
var i = 0
849-
var f = 1.0
850-
851-
i++ // expected-error {{'++' is unavailable}} {{4-6= += 1}}
852-
--i // expected-error {{'--' is unavailable}} {{3-5=}} {{6-6= -= 1}}
853-
_ = i++ // expected-error {{'++' is unavailable}}
854-
855-
++f // expected-error {{'++' is unavailable}} {{3-5=}} {{6-6= += 1}}
856-
f-- // expected-error {{'--' is unavailable}} {{4-6= -= 1}}
857-
_ = f-- // expected-error {{'--' is unavailable}} {{none}}
858-
859-
// <rdar://problem/24530312> Swift ++fix-it produces bad code in nested expressions
860-
// This should not get a fixit hint.
861-
var j = 2
862-
i = ++j // expected-error {{'++' is unavailable}} {{none}}
863-
}
864-
865846
// SR-628 mixing lvalues and rvalues in tuple expression
866847
var x = 0
867848
var y = 1

test/stdlib/Renames.swift

-11
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,6 @@ func _Filter<C>(c: LazyFilterCollection<C>) {
179179
}
180180

181181
func _FixedPoint() {
182-
var i: Int = 0
183-
var u: UInt = 0
184-
i++ // expected-error {{'++' is unavailable: it has been removed in Swift 3}} {{4-6= += 1}} {{none}}
185-
++i // expected-error {{'++' is unavailable: it has been removed in Swift 3}} {{3-5=}} {{6-6= += 1}} {{none}}
186-
i-- // expected-error {{'--' is unavailable: it has been removed in Swift 3}} {{4-6= -= 1}} {{none}}
187-
--i // expected-error {{'--' is unavailable: it has been removed in Swift 3}} {{3-5=}} {{6-6= -= 1}} {{none}}
188-
u++ // expected-error {{'++' is unavailable: it has been removed in Swift 3}} {{4-6= += 1}} {{none}}
189-
++u // expected-error {{'++' is unavailable: it has been removed in Swift 3}} {{3-5=}} {{6-6= += 1}} {{none}}
190-
u-- // expected-error {{'--' is unavailable: it has been removed in Swift 3}} {{4-6= -= 1}} {{none}}
191-
--u // expected-error {{'--' is unavailable: it has been removed in Swift 3}} {{3-5=}} {{6-6= -= 1}} {{none}}
192-
193182
func fn1<T: IntegerType>(i: T) {} // expected-error {{'IntegerType' has been renamed to 'FixedWidthInteger'}} {{15-26=FixedWidthInteger}} {{none}}
194183
func fn2<T: SignedIntegerType>(i: T) {} // expected-error {{'SignedIntegerType' has been renamed to 'SignedInteger'}} {{15-32=SignedInteger}} {{none}}
195184
func fn3<T: UnsignedIntegerType>(i: T) {} // expected-error {{'UnsignedIntegerType' has been renamed to 'UnsignedInteger'}} {{15-34=UnsignedInteger}} {{none}}

validation-test/stdlib/FixedPoint.swift.gyb

+10-5
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,9 @@ _UnimplementedError()
292292
// Misc tests that should be expanded to cover all types (FIXME)
293293
//===----------------------------------------------------------------------===//
294294

295-
func testBitwiseOperationsImpl<T : UnsignedInteger>(_: T.Type) {
295+
func testBitwiseOperationsImpl<
296+
T : FixedWidthInteger & UnsignedInteger
297+
>(_: T.Type) {
296298
let x = numericCast(0b11_1010_00) as T
297299
let y = numericCast(0b10_1100_10) as T
298300

@@ -301,7 +303,7 @@ func testBitwiseOperationsImpl<T : UnsignedInteger>(_: T.Type) {
301303
expectEqual(0b01_0110_10, x ^ y)
302304
expectEqual(0b00_0101_11, (~x) & 0xff)
303305

304-
let z = T.allZeros
306+
let z: T = 0
305307
expectEqual(x, x | z)
306308
expectEqual(x, x ^ z)
307309
expectEqual(z, x & z)
@@ -325,9 +327,12 @@ FixedPoint.test("BitwiseOperations/UInt64") {
325327
}
326328

327329
FixedPoint.test("OverflowCheck") {
328-
expectEqual(Int8.addWithOverflow(4, 5), (9, false))
329-
expectEqual(Int8.addWithOverflow(1, 127), (-128, true))
330-
expectEqual(UInt8.multiplyWithOverflow(2,128), (0, true))
330+
expectEqual((partialValue: 9, overflow: .none),
331+
(4 as Int8).addingWithOverflow(5))
332+
expectEqual((partialValue: -128, overflow: .overflow),
333+
(1 as Int8).addingWithOverflow(127))
334+
expectEqual((partialValue: 0, overflow: .overflow),
335+
(2 as UInt8).multipliedWithOverflow(by: 128))
331336
}
332337

333338
FixedPoint.test("String.init") {

validation-test/stdlib/SipHash.swift

+10-10
Original file line numberDiff line numberDiff line change
@@ -214,23 +214,23 @@ func loadUnalignedUInt64LE(
214214
) -> UInt64 {
215215
return
216216
UInt64(p.load(fromByteOffset: 0, as: UInt8.self)) |
217-
(UInt64(p.load(fromByteOffset: 1, as: UInt8.self)) << 8) |
218-
(UInt64(p.load(fromByteOffset: 2, as: UInt8.self)) << 16) |
219-
(UInt64(p.load(fromByteOffset: 3, as: UInt8.self)) << 24) |
220-
(UInt64(p.load(fromByteOffset: 4, as: UInt8.self)) << 32) |
221-
(UInt64(p.load(fromByteOffset: 5, as: UInt8.self)) << 40) |
222-
(UInt64(p.load(fromByteOffset: 6, as: UInt8.self)) << 48) |
223-
(UInt64(p.load(fromByteOffset: 7, as: UInt8.self)) << 56)
217+
(UInt64(p.load(fromByteOffset: 1, as: UInt8.self)) &<< 8 as UInt64) |
218+
(UInt64(p.load(fromByteOffset: 2, as: UInt8.self)) &<< 16 as UInt64) |
219+
(UInt64(p.load(fromByteOffset: 3, as: UInt8.self)) &<< 24 as UInt64) |
220+
(UInt64(p.load(fromByteOffset: 4, as: UInt8.self)) &<< 32 as UInt64) |
221+
(UInt64(p.load(fromByteOffset: 5, as: UInt8.self)) &<< 40 as UInt64) |
222+
(UInt64(p.load(fromByteOffset: 6, as: UInt8.self)) &<< 48 as UInt64) |
223+
(UInt64(p.load(fromByteOffset: 7, as: UInt8.self)) &<< 56 as UInt64)
224224
}
225225

226226
func loadUnalignedUInt32LE(
227227
from p: UnsafeRawPointer
228228
) -> UInt32 {
229229
return
230230
UInt32(p.load(fromByteOffset: 0, as: UInt8.self)) |
231-
(UInt32(p.load(fromByteOffset: 1, as: UInt8.self)) << 8) |
232-
(UInt32(p.load(fromByteOffset: 2, as: UInt8.self)) << 16) |
233-
(UInt32(p.load(fromByteOffset: 3, as: UInt8.self)) << 24)
231+
(UInt32(p.load(fromByteOffset: 1, as: UInt8.self)) &<< 8 as UInt32) |
232+
(UInt32(p.load(fromByteOffset: 2, as: UInt8.self)) &<< 16 as UInt32) |
233+
(UInt32(p.load(fromByteOffset: 3, as: UInt8.self)) &<< 24 as UInt32)
234234
}
235235

236236
func loadUnalignedUIntLE(

0 commit comments

Comments
 (0)