Skip to content
Merged
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
3 changes: 2 additions & 1 deletion stdlib/public/core/FloatingPointTypes.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import SwiftShims

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

Expand Down Expand Up @@ -981,7 +982,7 @@ extension ${Self}: Hashable {
%elif bits == 64:
return Hasher._hash(seed: seed, v.bitPattern)
%elif bits < 64:
return Hasher._hash(seed: seed, bytes: UInt64(v.bitPattern), count: ${bits/8})
return Hasher._hash(seed: seed, bytes: UInt64(v.bitPattern), count: ${bits//8})
%else:
#error("Unimplemented")
%end
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/IntegerTypes.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
# Utility code for later in this template
#

from __future__ import division
from SwiftIntTypes import all_integer_types, int_max_bits, should_define_truncating_bit_pattern_init
from SwiftFloatingPointTypes import getFtoIBounds

from string import maketrans, capitalize
from itertools import chain

# Number of bits in the Builtin.Word type
Expand Down Expand Up @@ -1658,7 +1658,7 @@ extension ${Self}: Hashable {
return Hasher._hash(
seed: seed,
bytes: UInt64(truncatingIfNeeded: ${U}${Self}(_value)),
count: ${bits / 8})
count: ${bits // 8})
% end
}
}
Expand Down
15 changes: 8 additions & 7 deletions stdlib/public/core/SIMDVectorTypes.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

%{
from __future__ import division
from SwiftIntTypes import all_integer_types
word_bits = int(CMAKE_SIZEOF_VOID_P) * 8
storagescalarCounts = [2,4,8,16,32,64]
Expand Down Expand Up @@ -90,17 +91,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 +160,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 @@ -212,7 +213,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 @@ -260,7 +261,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
2 changes: 1 addition & 1 deletion utils/gyb_syntax_support/Node.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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
29 changes: 15 additions & 14 deletions utils/gyb_syntax_support/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
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 . import Token

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
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 .Trivia import TRIVIAS # noqa: I201
from .TypeNodes import TYPE_NODES # noqa: I201


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

def _make_line_map(target_filename, stream=None):
"""
>>> from StringIO import StringIO
>>> try:
... from StringIO import StringIO # py2
... except ModuleNotFoundError:
... from io import StringIO # py3
>>> _make_line_map('box',
... StringIO('''// ###sourceLocation(file: "foo.bar", line: 3)
... line 2
Expand Down Expand Up @@ -101,7 +104,7 @@ def map_line_to_source_file(target_filename, target_line_num):
>>> # manually handle closing and deleting this file to allow us to open
>>> # the file by its name across all platforms.
>>> t = NamedTemporaryFile(delete=False)
>>> t.write('''line 1
>>> _ = t.write(b'''line 1
... line 2
... // ###sourceLocation(file: "foo.bar", line: 20)
... line 4
Expand Down Expand Up @@ -151,7 +154,7 @@ def map_line_from_source_file(source_filename, source_line_num,
>>> # manually handle closing and deleting this file to allow us to open
>>> # the file by its name across all platforms.
>>> t = NamedTemporaryFile(delete=False)
>>> t.write('''line 1
>>> _ = t.write(b'''line 1
... line 2
... // ###sourceLocation(file: "foo.bar", line: 20)
... line 4
Expand Down Expand Up @@ -237,7 +240,7 @@ def run():
>>> # manually handle closing and deleting this file to allow us to open
>>> # the file by its name across all platforms.
>>> target1 = NamedTemporaryFile(delete=False)
>>> target1.write('''line 1
>>> _ = target1.write(b'''line 1
... line 2
... // ###sourceLocation(file: "foo.bar", line: 20)
... line 4
Expand All @@ -252,7 +255,7 @@ def run():
>>> # manually handle closing and deleting this file to allow us to open
>>> # the file by its name across all platforms.
>>> target2 = NamedTemporaryFile(delete=False)
>>> target2.write('''// ###sourceLocation(file: "foo.bar", line: 7)
>>> _ = target2.write(b'''// ###sourceLocation(file: "foo.bar", line: 7)
... line 2
... line 3
... // ###sourceLocation(file: "fox.box", line: 11)
Expand All @@ -269,21 +272,21 @@ def run():
>>> # the file by its name across all platforms.
>>> raw_output = NamedTemporaryFile(delete=False)
>>> target1_name, target2_name = target1.name, target2.name
>>> raw_output.write('''A
... %(target1_name)s:2:111: error one
>>> _ = raw_output.write('''A
... {target1_name}:2:111: error one
... B
... %(target1_name)s:4:222: error two
... {target1_name}:4:222: error two
... C
... %(target1_name)s:8:333: error three
... {target1_name}:8:333: error three
... D
... glitch in file %(target2_name)s:1 assert one
... glitch in file {target2_name}:1 assert one
... E
... glitch in file %(target2_name)s, line 2 assert two
... glitch at %(target2_name)s, line 3 assert three
... glitch at %(target2_name)s:4 assert four
... glitch in [%(target2_name)s, line 5 assert five
... glitch in [%(target2_name)s:22 assert six
... ''' % locals())
... glitch in file {target2_name}, line 2 assert two
... glitch at {target2_name}, line 3 assert three
... glitch at {target2_name}:4 assert four
... glitch in [{target2_name}, line 5 assert five
... glitch in [{target2_name}:22 assert six
... '''.format(**locals()).encode('utf-8'))
>>> raw_output.flush()

Run this tool on the two targets, using a portable version of Unix 'cat' to
Expand Down Expand Up @@ -330,7 +333,7 @@ def run():
>>> # manually handle closing and deleting this file to allow us to open
>>> # the file by its name across all platforms.
>>> long_output = NamedTemporaryFile(delete=False)
>>> long_output.write('''
>>> _ = long_output.write(b'''
... // ###sourceLocation(file: "/public/core/Map.swift.gyb", line: 1)
... // ###sourceLocation(file: "/public/core/Map.swift.gyb", line: 1)
... //===--- Map.swift.gyb - Lazily map over a Sequence -----------*- swif
Expand Down Expand Up @@ -649,7 +652,8 @@ def run():
>>> long_output.flush()
>>> long_output_result = subprocess.check_output([sys.executable,
... __file__, long_output.name, '--',
... 'echo', long_output.name + ':112:27: error:']).rstrip()
... 'echo', long_output.name + ':112:27: error:'
... ]).rstrip().decode('ascii')
>>> print(long_output_result)
/public/core/Map.swift.gyb:117:27: error:
>>> target1.close()
Expand Down