Skip to content

Commit 68a5343

Browse files
authored
Merge pull request swiftlang#32109 from compnerd/behold-the-future
Python 2/3 compat: gyb, gyb_sourcekit_support, gyb_syntax_support, li…
2 parents 532e7f4 + 23f2d34 commit 68a5343

22 files changed

+83
-76
lines changed

stdlib/public/core/FloatingPointTypes.swift.gyb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import SwiftShims
1414

1515
%{
16+
from __future__ import division
1617
from SwiftIntTypes import all_integer_types
1718
from SwiftFloatingPointTypes import all_floating_point_types
1819

@@ -981,7 +982,7 @@ extension ${Self}: Hashable {
981982
%elif bits == 64:
982983
return Hasher._hash(seed: seed, v.bitPattern)
983984
%elif bits < 64:
984-
return Hasher._hash(seed: seed, bytes: UInt64(v.bitPattern), count: ${bits/8})
985+
return Hasher._hash(seed: seed, bytes: UInt64(v.bitPattern), count: ${bits//8})
985986
%else:
986987
#error("Unimplemented")
987988
%end

stdlib/public/core/IntegerTypes.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
# Utility code for later in this template
1515
#
1616

17+
from __future__ import division
1718
from SwiftIntTypes import all_integer_types, int_max_bits, should_define_truncating_bit_pattern_init
1819
from SwiftFloatingPointTypes import getFtoIBounds
1920

20-
from string import maketrans, capitalize
2121
from itertools import chain
2222

2323
# Number of bits in the Builtin.Word type
@@ -1658,7 +1658,7 @@ extension ${Self}: Hashable {
16581658
return Hasher._hash(
16591659
seed: seed,
16601660
bytes: UInt64(truncatingIfNeeded: ${U}${Self}(_value)),
1661-
count: ${bits / 8})
1661+
count: ${bits // 8})
16621662
% end
16631663
}
16641664
}

stdlib/public/core/SIMDVectorTypes.swift.gyb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
%{
14+
from __future__ import division
1415
from SwiftIntTypes import all_integer_types
1516
word_bits = int(CMAKE_SIZEOF_VOID_P) * 8
1617
storagescalarCounts = [2,4,8,16,32,64]
@@ -90,17 +91,17 @@ public struct SIMD${n}<Scalar>: SIMD where Scalar: SIMDScalar {
9091
% if n >= 4:
9192
/// Creates a new vector from two half-length vectors.
9293
@_transparent
93-
public init(lowHalf: SIMD${n/2}<Scalar>, highHalf: SIMD${n/2}<Scalar>) {
94+
public init(lowHalf: SIMD${n//2}<Scalar>, highHalf: SIMD${n//2}<Scalar>) {
9495
self.init()
9596
self.lowHalf = lowHalf
9697
self.highHalf = highHalf
9798
}
9899

99-
% for (half,indx) in [('low','i'), ('high',str(n/2)+'+i'), ('even','2*i'), ('odd','2*i+1')]:
100+
% for (half,indx) in [('low','i'), ('high',str(n//2)+'+i'), ('even','2*i'), ('odd','2*i+1')]:
100101
/// A half-length vector made up of the ${half} elements of the vector.
101-
public var ${half}Half: SIMD${n/2}<Scalar> {
102+
public var ${half}Half: SIMD${n//2}<Scalar> {
102103
@inlinable get {
103-
var result = SIMD${n/2}<Scalar>()
104+
var result = SIMD${n//2}<Scalar>()
104105
for i in result.indices { result[i] = self[${indx}] }
105106
return result
106107
}
@@ -159,7 +160,7 @@ extension SIMD${n}: CustomDebugStringConvertible {
159160
public var debugDescription: String {
160161
return "SIMD${n}<\(Scalar.self)>(${', '.join(map(lambda c:
161162
'\\(self['+ str(c) + '])',
162-
xrange(n)))})"
163+
range(n)))})"
163164
}
164165
}
165166

@@ -212,7 +213,7 @@ extension ${Self}: SIMDScalar {
212213
public typealias SIMDMaskScalar = ${Mask}
213214

214215
% for n in storagescalarCounts:
215-
% bytes = n * self_type.bits / 8
216+
% bytes = n * self_type.bits // 8
216217
/// Storage for a vector of ${spelledNumbers[n]} integers.
217218
@frozen
218219
@_alignment(${bytes if bytes <= 16 else 16})
@@ -260,7 +261,7 @@ extension ${Self} : SIMDScalar {
260261
public typealias SIMDMaskScalar = Int${bits}
261262

262263
% for n in storagescalarCounts:
263-
% bytes = n * bits / 8
264+
% bytes = n * bits // 8
264265
/// Storage for a vector of ${spelledNumbers[n]} floating-point values.
265266
@frozen
266267
@_alignment(${bytes if bytes <= 16 else 16})

stdlib/public/core/Tuple.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public func >=(lhs: (), rhs: ()) -> Bool {
111111
% equatableTypeParams = ", ".join(["{}: Equatable".format(c) for c in typeParams])
112112

113113
% originalTuple = "(\"a\", {})".format(", ".join(map(str, range(1, arity))))
114-
% greaterTuple = "(\"a\", {})".format(", ".join(map(str, range(1, arity - 1) + [arity])))
114+
% greaterTuple = "(\"a\", {})".format(", ".join(map(str, list(range(1, arity - 1)) + [arity])))
115115

116116
/// Returns a Boolean value indicating whether the corresponding components of
117117
/// two tuples are equal.

utils/gyb_sourcekit_support/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
# utils/gyb_sourcekit_support/ directory as a module.
1515
#
1616
# ----------------------------------------------------------------------------
17-
from UIDs import UID_KEYS
18-
from UIDs import UID_KINDS
19-
from UIDs import UID_REQUESTS
17+
from .UIDs import UID_KEYS
18+
from .UIDs import UID_KINDS
19+
from .UIDs import UID_REQUESTS
2020

2121

2222
def check_uid_duplication():

utils/gyb_syntax_support/AttributeNodes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from Child import Child
2-
from Node import Node # noqa: I201
1+
from .Child import Child
2+
from .Node import Node # noqa: I201
33

44
ATTRIBUTE_NODES = [
55
# token-list -> token? token-list?

utils/gyb_syntax_support/AvailabilityNodes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from Child import Child
2-
from Node import Node # noqa: I201
1+
from .Child import Child
2+
from .Node import Node # noqa: I201
33

44
AVAILABILITY_NODES = [
55
# availability-spec-list -> availability-entry availability-spec-list?

utils/gyb_syntax_support/Child.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# flake8: noqa I201
2-
from Classification import classification_by_name
3-
from Token import SYNTAX_TOKEN_MAP
4-
from kinds import SYNTAX_BASE_KINDS, kind_to_type, lowercase_first_word
2+
from .Classification import classification_by_name
3+
from .Token import SYNTAX_TOKEN_MAP
4+
from .kinds import SYNTAX_BASE_KINDS, kind_to_type, lowercase_first_word
55

66

77
class Child(object):

utils/gyb_syntax_support/Classification.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from Node import error
2-
from kinds import lowercase_first_word # noqa: I201
1+
from .Node import error
2+
from .kinds import lowercase_first_word # noqa: I201
33

44

55
class SyntaxClassification(object):

utils/gyb_syntax_support/CommonNodes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from Child import Child
2-
from Node import Node # noqa: I201
1+
from .Child import Child
2+
from .Node import Node # noqa: I201
33

44
COMMON_NODES = [
55
Node('Decl', kind='Syntax'),

0 commit comments

Comments
 (0)