Skip to content

Commit 57a92b1

Browse files
author
marcrasi
authored
Merge pull request #25110 from apple/tensorflow-merge
merge 'swift-DEVELOPMENT-SNAPSHOT-2019-05-26-a' into 'tensorflow'
2 parents c187300 + 0b7c7bb commit 57a92b1

File tree

171 files changed

+5212
-2520
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+5212
-2520
lines changed

benchmark/scripts/compare_perf_tests.py

Lines changed: 48 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -547,15 +547,6 @@ def __init__(self, comparator, changes_only,
547547
self.changes_only = changes_only
548548
self.single_table = single_table
549549

550-
MARKDOWN_DETAIL = """
551-
<details {3}>
552-
<summary>{0} ({1})</summary>
553-
{2}
554-
</details>
555-
"""
556-
GIT_DETAIL = """
557-
{0} ({1}): {2}"""
558-
559550
PERFORMANCE_TEST_RESULT_HEADER = ('TEST', 'MIN', 'MAX', 'MEAN', 'MAX_RSS')
560551
RESULT_COMPARISON_HEADER = ('TEST', 'OLD', 'NEW', 'DELTA', 'RATIO')
561552

@@ -589,16 +580,26 @@ def values(result):
589580
def markdown(self):
590581
"""Report results of benchmark comparisons in Markdown format."""
591582
return self._formatted_text(
592-
ROW='{0} | {1} | {2} | {3} | {4} \n',
593-
HEADER_SEPARATOR='---',
594-
DETAIL=self.MARKDOWN_DETAIL)
583+
label_formatter=lambda s: ('**' + s + '**'),
584+
COLUMN_SEPARATOR=' | ',
585+
DELIMITER_ROW=([':---'] + ['---:'] * 4),
586+
SEPARATOR='&nbsp; | | | | \n',
587+
SECTION="""
588+
<details {3}>
589+
<summary>{0} ({1})</summary>
590+
{2}
591+
</details>
592+
""")
595593

596594
def git(self):
597595
"""Report results of benchmark comparisons in 'git' format."""
598596
return self._formatted_text(
599-
ROW='{0} {1} {2} {3} {4} \n',
600-
HEADER_SEPARATOR=' ',
601-
DETAIL=self.GIT_DETAIL)
597+
label_formatter=lambda s: s.upper(),
598+
COLUMN_SEPARATOR=' ',
599+
DELIMITER_ROW=None,
600+
SEPARATOR='\n',
601+
SECTION="""
602+
{0} ({1}): \n{2}""")
602603

603604
def _column_widths(self):
604605
changed = self.comparator.decreased + self.comparator.increased
@@ -614,53 +615,49 @@ def _column_widths(self):
614615
]
615616

616617
def max_widths(maximum, widths):
617-
return tuple(map(max, zip(maximum, widths)))
618+
return map(max, zip(maximum, widths))
618619

619-
return reduce(max_widths, widths, tuple([0] * 5))
620+
return reduce(max_widths, widths, [0] * 5)
620621

621-
def _formatted_text(self, ROW, HEADER_SEPARATOR, DETAIL):
622+
def _formatted_text(self, label_formatter, COLUMN_SEPARATOR,
623+
DELIMITER_ROW, SEPARATOR, SECTION):
622624
widths = self._column_widths()
623625
self.header_printed = False
624626

625627
def justify_columns(contents):
626-
return tuple([c.ljust(w) for w, c in zip(widths, contents)])
628+
return [c.ljust(w) for w, c in zip(widths, contents)]
627629

628630
def row(contents):
629-
return ROW.format(*justify_columns(contents))
630-
631-
def header(header):
632-
return '\n' + row(header) + row(tuple([HEADER_SEPARATOR] * 5))
633-
634-
def format_columns(r, strong):
635-
return (r if not strong else
636-
r[:-1] + ('**{0}**'.format(r[-1]), ))
631+
return ('' if not contents else
632+
COLUMN_SEPARATOR.join(justify_columns(contents)) + '\n')
633+
634+
def header(title, column_labels):
635+
labels = (column_labels if not self.single_table else
636+
map(label_formatter, (title, ) + column_labels[1:]))
637+
h = (('' if not self.header_printed else SEPARATOR) +
638+
row(labels) +
639+
(row(DELIMITER_ROW) if not self.header_printed else ''))
640+
if self.single_table and not self.header_printed:
641+
self.header_printed = True
642+
return h
643+
644+
def format_columns(r, is_strong):
645+
return (r if not is_strong else
646+
r[:-1] + ('**' + r[-1] + '**', ))
637647

638648
def table(title, results, is_strong=False, is_open=False):
639-
rows = [
640-
row(format_columns(ReportFormatter.values(r), is_strong))
641-
for r in results
642-
]
643-
if not rows:
649+
if not results:
644650
return ''
645-
646-
if self.single_table:
647-
t = ''
648-
if not self.header_printed:
649-
t += header(ReportFormatter.header_for(results[0]))
650-
self.header_printed = True
651-
t += row(('**' + title + '**', '', '', '', ''))
652-
t += ''.join(rows)
653-
return t
654-
655-
return DETAIL.format(
656-
*[
657-
title, len(results),
658-
(header(ReportFormatter.header_for(results[0])) +
659-
''.join(rows)),
660-
('open' if is_open else '')
661-
])
662-
663-
return ''.join([
651+
rows = [row(format_columns(ReportFormatter.values(r), is_strong))
652+
for r in results]
653+
table = (header(title if self.single_table else '',
654+
ReportFormatter.header_for(results[0])) +
655+
''.join(rows))
656+
return (table if self.single_table else
657+
SECTION.format(
658+
title, len(results), table, 'open' if is_open else ''))
659+
660+
return '\n' + ''.join([
664661
table('Regression', self.comparator.decreased, True, True),
665662
table('Improvement', self.comparator.increased, True),
666663
('' if self.changes_only else

benchmark/scripts/run_smoke_bench

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def main():
8888
help='In addition to stdout, write the results into a markdown file')
8989
argparser.add_argument(
9090
'-threshold', type=float,
91-
help='The performance threshold in % which triggers a re-run',
91+
help='The performance threshold in %% which triggers a re-run',
9292
default=5)
9393
argparser.add_argument(
9494
'-num-samples', type=int,

benchmark/scripts/test_compare_perf_tests.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ def test_column_headers(self):
759759
)
760760
self.assert_markdown_contains([
761761
'TEST | OLD | NEW | DELTA | RATIO',
762-
'--- | --- | --- | --- | --- ',
762+
':--- | ---: | ---: | ---: | ---: ',
763763
'TEST | MIN | MAX | MEAN | MAX_RSS'])
764764
self.assert_git_contains([
765765
'TEST OLD NEW DELTA RATIO',
@@ -855,6 +855,36 @@ def test_report_only_changes(self):
855855
self.assertNotIn('No Changes', html)
856856
self.assertNotIn('AngryPhonebook', html)
857857

858+
def test_single_table_report(self):
859+
"""Single table report has inline headers and no elaborate sections."""
860+
self.tc.removed = [] # test handling empty section
861+
rf = ReportFormatter(self.tc, changes_only=True, single_table=True)
862+
markdown = rf.markdown()
863+
self.assertNotIn('<details', markdown) # no sections
864+
self.assertNotIn('\n\n', markdown) # table must not be broken
865+
self.assertNotIn('Removed', markdown)
866+
self.assert_report_contains([
867+
'\n**Regression** ',
868+
'| **OLD**', '| **NEW**', '| **DELTA**', '| **RATIO**',
869+
'\n**Added** ',
870+
'| **MIN**', '| **MAX**', '| **MEAN**', '| **MAX_RSS**'
871+
], markdown)
872+
# Single delimiter row:
873+
self.assertIn('\n:---', markdown) # first column is left aligned
874+
self.assertEqual(markdown.count('| ---:'), 4) # other, right aligned
875+
# Separator before every inline header (new section):
876+
self.assertEqual(markdown.count('&nbsp; | | | | '), 2)
877+
878+
git = rf.git()
879+
self.assertNotIn('): \n', git) # no sections
880+
self.assertNotIn('REMOVED', git)
881+
self.assert_report_contains([
882+
'\nREGRESSION ', ' OLD ', ' NEW ', ' DELTA ', ' RATIO ',
883+
'\n\nADDED ', ' MIN ', ' MAX ', ' MEAN ', ' MAX_RSS '
884+
], git)
885+
# Separator before every inline header (new section):
886+
self.assertEqual(git.count('\n\n'), 2)
887+
858888

859889
class Test_parse_args(unittest.TestCase):
860890
required = ['--old-file', 'old.log', '--new-file', 'new.log']

docs/SIL.rst

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2337,7 +2337,7 @@ assign_by_delegate
23372337
``````````````````
23382338
::
23392339

2340-
sil-instruction ::= 'assign_by_delegate' sil-operand 'to' sil-operand ',' 'init' sil-operand ',' 'set' sil-operand
2340+
sil-instruction ::= 'assign_by_delegate' sil-operand 'to' sil-operand ',' 'init' sil-operand ',' 'set' sil-operand
23412341

23422342
assign_by_delegate %0 : $S to %1 : $*T, init %2 : $F, set %3 : $G
23432343
// $S can be a value or address type
@@ -3053,6 +3053,73 @@ function_ref
30533053

30543054
Creates a reference to a SIL function.
30553055

3056+
dynamic_function_ref
3057+
````````````````````
3058+
::
3059+
3060+
sil-instruction ::= 'dynamic_function_ref' sil-function-name ':' sil-type
3061+
3062+
%1 = dynamic_function_ref @function : $@convention(thin) T -> U
3063+
// $@convention(thin) T -> U must be a thin function type
3064+
// %1 has type $T -> U
3065+
3066+
Creates a reference to a `dynamically_replacable` SIL function. A
3067+
`dynamically_replacable` SIL function can be replaced at runtime.
3068+
3069+
For the following Swift code::
3070+
3071+
dynamic func test_dynamically_replaceable() {}
3072+
3073+
func test_dynamic_call() {
3074+
test_dynamically_replaceable()
3075+
}
3076+
3077+
We will generate::
3078+
3079+
sil [dynamically_replacable] @test_dynamically_replaceable : $@convention(thin) () -> () {
3080+
bb0:
3081+
%0 = tuple ()
3082+
return %0 : $()
3083+
}
3084+
3085+
sil @test_dynamic_call : $@convention(thin) () -> () {
3086+
bb0:
3087+
%0 = dynamic_function_ref @test_dynamically_replaceable : $@convention(thin) () -> ()
3088+
%1 = apply %0() : $@convention(thin) () -> ()
3089+
%2 = tuple ()
3090+
return %2 : $()
3091+
}
3092+
3093+
prev_dynamic_function_ref
3094+
`````````````````````````
3095+
::
3096+
3097+
sil-instruction ::= 'prev_dynamic_function_ref' sil-function-name ':' sil-type
3098+
3099+
%1 = prev_dynamic_function_ref @function : $@convention(thin) T -> U
3100+
// $@convention(thin) T -> U must be a thin function type
3101+
// %1 has type $T -> U
3102+
3103+
Creates a reference to a previous implemenation of a `dynamic_replacement` SIL
3104+
function.
3105+
3106+
For the following Swift code::
3107+
3108+
@_dynamicReplacement(for: test_dynamically_replaceable())
3109+
func test_replacement() {
3110+
test_dynamically_replaceable() // calls previous implementation
3111+
}
3112+
3113+
We will generate::
3114+
3115+
sil [dynamic_replacement_for "test_dynamically_replaceable"] @test_replacement : $@convention(thin) () -> () {
3116+
bb0:
3117+
%0 = prev_dynamic_function_ref @test_replacement : $@convention(thin) () -> ()
3118+
%1 = apply %0() : $@convention(thin) () -> ()
3119+
%2 = tuple ()
3120+
return %2 : $()
3121+
}
3122+
30563123
global_addr
30573124
```````````
30583125

include/swift/AST/ASTContext.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ namespace swift {
5353
class AvailabilityContext;
5454
class BoundGenericType;
5555
class ClangNode;
56+
class ConcreteDeclRef;
5657
class ConstructorDecl;
5758
class Decl;
5859
class DeclContext;
@@ -540,7 +541,20 @@ class ASTContext final {
540541
bool hasArrayLiteralIntrinsics() const;
541542

542543
/// Retrieve the declaration of Swift.Bool.init(_builtinBooleanLiteral:)
543-
ConstructorDecl *getBoolBuiltinInitDecl() const;
544+
ConcreteDeclRef getBoolBuiltinInitDecl() const;
545+
546+
/// Retrieve the witness for init(_builtinIntegerLiteral:).
547+
ConcreteDeclRef getIntBuiltinInitDecl(NominalTypeDecl *intDecl) const;
548+
549+
/// Retrieve the witness for init(_builtinFloatLiteral:).
550+
ConcreteDeclRef getFloatBuiltinInitDecl(NominalTypeDecl *floatDecl) const;
551+
552+
/// Retrieve the witness for (_builtinStringLiteral:utf8CodeUnitCount:isASCII:).
553+
ConcreteDeclRef getStringBuiltinInitDecl(NominalTypeDecl *stringDecl) const;
554+
555+
ConcreteDeclRef getBuiltinInitDecl(NominalTypeDecl *decl,
556+
KnownProtocolKind builtinProtocol,
557+
llvm::function_ref<DeclName (ASTContext &ctx)> initName) const;
544558

545559
/// Retrieve the declaration of Swift.==(Int, Int) -> Bool.
546560
FuncDecl *getEqualIntDecl() const;

include/swift/AST/DiagnosticsParse.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ ERROR(extra_tokens_conditional_compilation_directive,none,
6868
"extra tokens following conditional compilation directive", ())
6969
ERROR(unexpected_rbrace_in_conditional_compilation_block,none,
7070
"unexpected '}' in conditional compilation block", ())
71+
ERROR(unexpected_if_following_else_compilation_directive,none,
72+
"unexpected 'if' keyword following '#else' conditional compilation "
73+
"directive; did you mean '#elseif'?",
74+
())
7175

7276
ERROR(pound_diagnostic_expected_string,none,
7377
"expected string literal in %select{#warning|#error}0 directive",(bool))
@@ -734,6 +738,8 @@ ERROR(expected_type_after_arrow,none,
734738
ERROR(function_type_argument_label,none,
735739
"function types cannot have argument labels; use '_' before %0",
736740
(Identifier))
741+
ERROR(expected_dynamic_func_attr,none,
742+
"expected a dynamically_replaceable function", ())
737743

738744
// Enum Types
739745
ERROR(expected_expr_enum_case_raw_value,PointsToFirstBadToken,

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4114,17 +4114,9 @@ ERROR(borrowed_on_objc_protocol_requirement,none,
41144114
// MARK: dynamic
41154115
//------------------------------------------------------------------------------
41164116

4117-
ERROR(dynamic_not_in_class,none,
4118-
"only members of classes may be dynamic", ())
4119-
ERROR(dynamic_with_nonobjc,none,
4120-
"a declaration cannot be both '@nonobjc' and 'dynamic'",
4121-
())
41224117
ERROR(dynamic_with_transparent,none,
41234118
"a declaration cannot be both '@_tranparent' and 'dynamic'",
41244119
())
4125-
ERROR(dynamic_requires_objc,none,
4126-
"'dynamic' %0 %1 must also be '@objc'",
4127-
(DescriptiveDeclKind, DeclName))
41284120

41294121
//------------------------------------------------------------------------------
41304122
// MARK: @_dynamicReplacement(for:)

include/swift/AST/Expr.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -955,15 +955,25 @@ class TapExpr : public Expr {
955955
class InterpolatedStringLiteralExpr : public LiteralExpr {
956956
/// Points at the beginning quote.
957957
SourceLoc Loc;
958+
/// Points at the ending quote.
959+
/// Needed for the upcoming \c ASTScope subsystem because lookups can be
960+
/// targeted to inside an \c InterpolatedStringLiteralExpr. It would be nicer
961+
/// to use \c EndLoc for this value, but then \c Lexer::getLocForEndOfToken()
962+
/// would not work for \c stringLiteral->getEndLoc().
963+
SourceLoc TrailingQuoteLoc;
958964
TapExpr *AppendingExpr;
959965
Expr *SemanticExpr;
960966

961967
public:
962-
InterpolatedStringLiteralExpr(SourceLoc Loc, unsigned LiteralCapacity,
968+
InterpolatedStringLiteralExpr(SourceLoc Loc,
969+
SourceLoc TrailingQuoteLoc,
970+
unsigned LiteralCapacity,
963971
unsigned InterpolationCount,
964972
TapExpr *AppendingExpr)
965973
: LiteralExpr(ExprKind::InterpolatedStringLiteral, /*Implicit=*/false),
966-
Loc(Loc), AppendingExpr(AppendingExpr), SemanticExpr() {
974+
Loc(Loc),
975+
TrailingQuoteLoc(TrailingQuoteLoc),
976+
AppendingExpr(AppendingExpr), SemanticExpr() {
967977
Bits.InterpolatedStringLiteralExpr.InterpolationCount = InterpolationCount;
968978
Bits.InterpolatedStringLiteralExpr.LiteralCapacity = LiteralCapacity;
969979
}
@@ -1000,6 +1010,11 @@ class InterpolatedStringLiteralExpr : public LiteralExpr {
10001010
// token, so the range should be (Start == End).
10011011
return Loc;
10021012
}
1013+
SourceLoc getTrailingQuoteLoc() const {
1014+
// Except when computing a SourceRange for an ASTScope. Then the range
1015+
// must be (Start - TrainingQuoteLoc).
1016+
return TrailingQuoteLoc;
1017+
}
10031018

10041019
/// Call the \c callback with information about each segment in turn.
10051020
void forEachSegment(ASTContext &Ctx,

include/swift/AST/KnownStdlibTypes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ KNOWN_STDLIB_TYPE_DECL(Float80, NominalTypeDecl, 0)
4848
KNOWN_STDLIB_TYPE_DECL(_MaxBuiltinFloatType, TypeAliasDecl, 0)
4949

5050
KNOWN_STDLIB_TYPE_DECL(String, NominalTypeDecl, 0)
51+
KNOWN_STDLIB_TYPE_DECL(StaticString, NominalTypeDecl, 0)
5152
KNOWN_STDLIB_TYPE_DECL(Substring, NominalTypeDecl, 0)
5253
KNOWN_STDLIB_TYPE_DECL(Array, NominalTypeDecl, 1)
5354
KNOWN_STDLIB_TYPE_DECL(Set, NominalTypeDecl, 1)

0 commit comments

Comments
 (0)