Skip to content

Updated files to work with Python 3 #26296

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions stdlib/public/core/FloatingPointTypes.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import SwiftShims

%{
from SwiftIntTypes import all_integer_types
from SwiftFloatingPointTypes import all_floating_point_types
import SwiftIntTypes
import SwiftFloatingPointTypes

#
# Utility code for later in this template
Expand All @@ -27,7 +27,7 @@ word_bits = int(CMAKE_SIZEOF_VOID_P) * 8
builtinIntLiteralBits = 2048
}%

% for self_type in all_floating_point_types():
% for self_type in SwiftFloatingPointTypes.all_floating_point_types():
%{
Self = self_type.stdlib_name
bits = self_type.bits
Expand Down Expand Up @@ -1042,7 +1042,7 @@ extension ${Self} {
}
}

% for src_type in all_floating_point_types():
% for src_type in SwiftFloatingPointTypes.all_floating_point_types():
% srcBits = src_type.bits
% That = src_type.stdlib_name

Expand Down
11 changes: 5 additions & 6 deletions stdlib/public/core/IntegerTypes.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
# Utility code for later in this template
#

from SwiftIntTypes import all_integer_types, int_max_bits, should_define_truncating_bit_pattern_init
from SwiftFloatingPointTypes import getFtoIBounds
import SwiftIntTypes
import SwiftFloatingPointTypes
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn’t need these changes back in January. Are you sure they are needed?

(The change with the // is needed, only the import ones werent't needed)


from string import maketrans, capitalize
from itertools import chain

# Number of bits in the Builtin.Word type
Expand Down Expand Up @@ -1064,7 +1063,7 @@ def unsafeOperationComment(operator):
//===--- Concrete FixedWidthIntegers --------------------------------------===//
//===----------------------------------------------------------------------===//

% for self_type in all_integer_types(word_bits):
% for self_type in SwiftIntTypes.all_integer_types(word_bits):
% bits = self_type.bits
% signed = self_type.is_signed
% BuiltinName = self_type.builtin_name
Expand Down Expand Up @@ -1125,7 +1124,7 @@ public struct ${Self}

% for (FloatType, FloatBits) in [
% ('Float', 32), ('Double', 64), ('Float80', 80)]:
% (lower, upper) = getFtoIBounds(floatBits=FloatBits, intBits=int(bits), signed=signed)
% (lower, upper) = SwiftFloatingPointTypes.getFtoIBounds(floatBits=FloatBits, intBits=int(bits), signed=signed)

% if FloatType == 'Float80':
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
Expand Down Expand Up @@ -1648,7 +1647,7 @@ extension ${Self}: Hashable {
return Hasher._hash(
seed: seed,
bytes: UInt64(truncatingIfNeeded: ${U}${Self}(_value)),
count: ${bits / 8})
count: ${bits // 8})
% end
}
}
Expand Down
18 changes: 9 additions & 9 deletions stdlib/public/core/SIMDVectorTypes.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

%{
from SwiftIntTypes import all_integer_types
import SwiftIntTypes
word_bits = int(CMAKE_SIZEOF_VOID_P) * 8
storagescalarCounts = [2,4,8,16,32,64]
vectorscalarCounts = storagescalarCounts + [3]
Expand Down Expand Up @@ -90,17 +90,17 @@ public struct SIMD${n}<Scalar>: SIMD where Scalar: SIMDScalar {
% if n >= 4:
/// Creates a new vector from two half-length vectors.
@_transparent
public init(lowHalf: SIMD${n/2}<Scalar>, highHalf: SIMD${n/2}<Scalar>) {
public init(lowHalf: SIMD${n//2}<Scalar>, highHalf: SIMD${n//2}<Scalar>) {
self.init()
self.lowHalf = lowHalf
self.highHalf = highHalf
}

% for (half,indx) in [('low','i'), ('high',str(n/2)+'+i'), ('even','2*i'), ('odd','2*i+1')]:
% for (half,indx) in [('low','i'), ('high',str(n//2)+'+i'), ('even','2*i'), ('odd','2*i+1')]:
/// A half-length vector made up of the ${half} elements of the vector.
public var ${half}Half: SIMD${n/2}<Scalar> {
public var ${half}Half: SIMD${n//2}<Scalar> {
@inlinable get {
var result = SIMD${n/2}<Scalar>()
var result = SIMD${n//2}<Scalar>()
for i in result.indices { result[i] = self[${indx}] }
return result
}
Expand Down Expand Up @@ -159,7 +159,7 @@ extension SIMD${n}: CustomDebugStringConvertible {
public var debugDescription: String {
return "SIMD${n}<\(Scalar.self)>(${', '.join(map(lambda c:
'\\(self['+ str(c) + '])',
xrange(n)))})"
range(n)))})"
}
}

Expand Down Expand Up @@ -203,7 +203,7 @@ extension SIMD4 {
}
}

%for self_type in all_integer_types(word_bits):
%for self_type in SwiftIntTypes.all_integer_types(word_bits):
% Self = self_type.stdlib_name
% BuiltinName = self_type.builtin_name
% Mask = Self if self_type.is_signed else self_type.get_opposite_signedness().stdlib_name
Expand All @@ -212,7 +212,7 @@ extension ${Self}: SIMDScalar {
public typealias SIMDMaskScalar = ${Mask}

% for n in storagescalarCounts:
% bytes = n * self_type.bits / 8
% bytes = n * self_type.bits // 8
/// Storage for a vector of ${spelledNumbers[n]} integers.
@frozen
@_alignment(${bytes if bytes <= 16 else 16})
Expand Down Expand Up @@ -257,7 +257,7 @@ extension ${Self}: SIMDScalar {
public typealias SIMDMaskScalar = Int${bits}

% for n in storagescalarCounts:
% bytes = n * bits / 8
% bytes = n * bits // 8
/// Storage for a vector of ${spelledNumbers[n]} floating-point values.
@frozen
@_alignment(${bytes if bytes <= 16 else 16})
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Tuple.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public func >=(lhs: (), rhs: ()) -> Bool {
% equatableTypeParams = ", ".join(["{}: Equatable".format(c) for c in typeParams])

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

/// Returns a Boolean value indicating whether the corresponding components of
/// two tuples are equal.
Expand Down
6 changes: 3 additions & 3 deletions utils/gyb_sourcekit_support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
# utils/gyb_sourcekit_support/ directory as a module.
#
# ----------------------------------------------------------------------------
from UIDs import UID_KEYS
from UIDs import UID_KINDS
from UIDs import UID_REQUESTS
from .UIDs import UID_KEYS
from .UIDs import UID_KINDS
from .UIDs import UID_REQUESTS


def check_uid_duplication():
Expand Down
4 changes: 2 additions & 2 deletions utils/gyb_syntax_support/AttributeNodes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from Child import Child
from Node import Node # noqa: I201
from .Child import Child
from .Node import Node # noqa: I201

ATTRIBUTE_NODES = [
# token-list -> token? token-list?
Expand Down
4 changes: 2 additions & 2 deletions utils/gyb_syntax_support/AvailabilityNodes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from Child import Child
from Node import Node # noqa: I201
from .Child import Child
from .Node import Node # noqa: I201

AVAILABILITY_NODES = [
# availability-spec-list -> availability-entry availability-spec-list?
Expand Down
6 changes: 3 additions & 3 deletions utils/gyb_syntax_support/Child.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# flake8: noqa I201
from Classification import classification_by_name
from Token import SYNTAX_TOKEN_MAP
from kinds import SYNTAX_BASE_KINDS, kind_to_type, lowercase_first_word
from .Classification import classification_by_name
from .Token import SYNTAX_TOKEN_MAP
from .kinds import SYNTAX_BASE_KINDS, kind_to_type, lowercase_first_word


class Child(object):
Expand Down
4 changes: 2 additions & 2 deletions utils/gyb_syntax_support/Classification.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from Node import error
from kinds import lowercase_first_word # noqa: I201
from .Node import error
from .kinds import lowercase_first_word # noqa: I201


class SyntaxClassification(object):
Expand Down
4 changes: 2 additions & 2 deletions utils/gyb_syntax_support/CommonNodes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from Child import Child
from Node import Node # noqa: I201
from .Child import Child
from .Node import Node # noqa: I201

COMMON_NODES = [
Node('Decl', kind='Syntax'),
Expand Down
4 changes: 2 additions & 2 deletions utils/gyb_syntax_support/DeclNodes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# flake8: noqa I201
from Child import Child
from Node import Node
from .Child import Child
from .Node import Node


DECL_NODES = [
Expand Down
4 changes: 2 additions & 2 deletions utils/gyb_syntax_support/ExprNodes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from Child import Child
from Node import Node # noqa: I201
from .Child import Child
from .Node import Node # noqa: I201

EXPR_NODES = [
# An inout expression.
Expand Down
4 changes: 2 additions & 2 deletions utils/gyb_syntax_support/GenericNodes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from Child import Child
from Node import Node # noqa: I201
from .Child import Child
from .Node import Node # noqa: I201

GENERIC_NODES = [
# generic-where-clause -> 'where' requirement-list
Expand Down
3 changes: 1 addition & 2 deletions utils/gyb_syntax_support/Node.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import print_function
import sys # noqa: I201

from kinds import SYNTAX_BASE_KINDS, kind_to_type, lowercase_first_word
from .kinds import SYNTAX_BASE_KINDS, kind_to_type, lowercase_first_word


def error(msg):
Expand Down
2 changes: 1 addition & 1 deletion utils/gyb_syntax_support/NodeSerializationCodes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from Node import error
from .Node import error


SYNTAX_NODE_SERIALIZATION_CODES = {
Expand Down
4 changes: 2 additions & 2 deletions utils/gyb_syntax_support/PatternNodes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from Child import Child
from Node import Node # noqa: I201
from .Child import Child
from .Node import Node # noqa: I201

PATTERN_NODES = [

Expand Down
4 changes: 2 additions & 2 deletions utils/gyb_syntax_support/StmtNodes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from Child import Child
from Node import Node # noqa: I201
from .Child import Child
from .Node import Node # noqa: I201

STMT_NODES = [
# continue-stmt -> 'continue' label? ';'?
Expand Down
6 changes: 3 additions & 3 deletions utils/gyb_syntax_support/Token.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from Classification import classification_by_name
from Node import error # noqa: I201
from kinds import lowercase_first_word # noqa: I201
from .Classification import classification_by_name
from .Node import error # noqa: I201
from .kinds import lowercase_first_word # noqa: I201


class Token(object):
Expand Down
4 changes: 2 additions & 2 deletions utils/gyb_syntax_support/Trivia.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from Node import error
from kinds import lowercase_first_word # noqa: I201
from .Node import error
from .kinds import lowercase_first_word # noqa: I201


class Trivia(object):
Expand Down
4 changes: 2 additions & 2 deletions utils/gyb_syntax_support/TypeNodes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from Child import Child
from Node import Node # noqa: I201
from .Child import Child
from .Node import Node # noqa: I201

TYPE_NODES = [
# simple-type-identifier -> identifier generic-argument-clause?
Expand Down
27 changes: 12 additions & 15 deletions utils/gyb_syntax_support/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import textwrap
from AttributeNodes import ATTRIBUTE_NODES # noqa: I201
from AvailabilityNodes import AVAILABILITY_NODES # noqa: I201
import Classification # noqa: I201
from CommonNodes import COMMON_NODES # noqa: I201
from DeclNodes import DECL_NODES # noqa: I201
from ExprNodes import EXPR_NODES # noqa: I201
from GenericNodes import GENERIC_NODES # noqa: I201

from NodeSerializationCodes import SYNTAX_NODE_SERIALIZATION_CODES, \
from .AttributeNodes import ATTRIBUTE_NODES # noqa: I201
from .AvailabilityNodes import AVAILABILITY_NODES # noqa: I201
from . import Classification # noqa: I201
from .CommonNodes import COMMON_NODES # noqa: I201
from .DeclNodes import DECL_NODES # noqa: I201
from .ExprNodes import EXPR_NODES # noqa: I201
from .GenericNodes import GENERIC_NODES # noqa: I201
from .NodeSerializationCodes import SYNTAX_NODE_SERIALIZATION_CODES, \
get_serialization_code, \
verify_syntax_node_serialization_codes

from PatternNodes import PATTERN_NODES # noqa: I201
from StmtNodes import STMT_NODES # noqa: I201

import Token
from Trivia import TRIVIAS # noqa: I201
from TypeNodes import TYPE_NODES # noqa: I201
from .PatternNodes import PATTERN_NODES # noqa: I201
from .StmtNodes import STMT_NODES # noqa: I201
from . import Token
from .TypeNodes import TYPE_NODES # noqa: I201


# Re-export global constants
Expand Down
8 changes: 4 additions & 4 deletions utils/line-directive
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ line_pattern = re.compile(

def _make_line_map(target_filename, stream=None):
"""
>>> from StringIO import StringIO
>>> from io import StringIO
Copy link
Contributor

Choose a reason for hiding this comment

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

This will not work in Python 2, I'm afraid.

You can see in https://github.com/apple/swift/pull/23038/files#diff-cca357e5f9d41d8ba84f741ccf60fe55R64 how I solved it.

>>> _make_line_map('box',
... StringIO('''// ###sourceLocation(file: "foo.bar", line: 3)
... line 2
Expand Down Expand Up @@ -95,7 +95,7 @@ def fline_map(target_filename):

def map_line_to_source_file(target_filename, target_line_num):
"""
>>> from tempfile import *
>>> from .tempfile import *
>>> # On Windows, the name of a NamedTemporaryFile cannot be used to open
>>> # the file for a second time if delete=True. Therefore, we have to
>>> # manually handle closing and deleting this file to allow us to open
Expand Down Expand Up @@ -145,7 +145,7 @@ def map_line_to_source_file(target_filename, target_line_num):
def map_line_from_source_file(source_filename, source_line_num,
target_filename):
"""
>>> from tempfile import *
>>> from .tempfile import *
>>> # On Windows, the name of a NamedTemporaryFile cannot be used to open
>>> # the file for a second time if delete=True. Therefore, we have to
>>> # manually handle closing and deleting this file to allow us to open
Expand Down Expand Up @@ -231,7 +231,7 @@ def expand_response_files(files):
def run():
"""Simulate a couple of gyb-generated files

>>> from tempfile import *
>>> from .tempfile import *
>>> # On Windows, the name of a NamedTemporaryFile cannot be used to open
>>> # the file for a second time if delete=True. Therefore, we have to
>>> # manually handle closing and deleting this file to allow us to open
Expand Down
2 changes: 1 addition & 1 deletion utils/update-checkout
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import sys

import update_checkout
from update_checkout.update_checkout import update_checkout

# The internal Windows implementation tries to import the current module using
# sys.modules[__name__]. This file (called 'update-checkout') is not a valid
Expand Down
4 changes: 0 additions & 4 deletions utils/update_checkout/__init__.py

This file was deleted.

4 changes: 0 additions & 4 deletions utils/update_checkout/update_checkout/__init__.py

This file was deleted.