Skip to content

Commit 019de55

Browse files
author
Eugene Burmako
authored
---
yaml --- r: 340733 b: refs/heads/rxwei-patch-1 c: d545974 h: refs/heads/master i: 340731: 13bb6bf
1 parent e266740 commit 019de55

27 files changed

+619
-255
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-08-18-a: b10b1fce14385faa6d44f6b933e95
10151015
refs/heads/rdar-43033749-fix-batch-mode-no-diags-swift-5.0-branch: a14e64eaad30de89f0f5f0b2a782eed7ecdcb255
10161016
refs/heads/revert-19006-error-bridging-integer-type: 8a9065a3696535305ea53fe9b71f91cbe6702019
10171017
refs/heads/revert-19050-revert-19006-error-bridging-integer-type: ecf752d54b05dd0a20f510f0bfa54a3fec3bcaca
1018-
refs/heads/rxwei-patch-1: fb402ef7bb95edd7b4ea0720210ccba39d3801dc
1018+
refs/heads/rxwei-patch-1: d5459740c357342008c12a9c086cab853714af0d
10191019
refs/heads/shahmishal-patch-1: e58ec0f7488258d42bef51bc3e6d7b3dc74d7b2a
10201020
refs/heads/typelist-existential: 4046359efd541fb5c72d69a92eefc0a784df8f5e
10211021
refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-20-a: 4319ba09e4fb8650ee86061075c74a016b6baab9

branches/rxwei-patch-1/include/swift/AST/Attr.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,10 @@ DECL_ATTR(differentiating, Differentiating,
428428
OnFunc | LongAttribute | AllowMultipleAttributes |
429429
NotSerialized, 90)
430430
SIMPLE_DECL_ATTR(compilerEvaluable, CompilerEvaluable,
431-
OnAccessor | OnFunc | OnConstructor | OnSubscript,
432-
/* Not serialized */ 91)
431+
OnAccessor | OnFunc | OnConstructor | OnSubscript,
432+
/* Not serialized */ 91)
433433
SIMPLE_DECL_ATTR(noDerivative, NoDerivative,
434-
OnVar, 92)
434+
OnVar, 92)
435435

436436
#undef TYPE_ATTR
437437
#undef DECL_ATTR_ALIAS

branches/rxwei-patch-1/include/swift/AST/AutoDiff.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,36 @@ enum class DifferentiabilityKind: uint8_t {
3232

3333
class ParsedAutoDiffParameter {
3434
public:
35-
enum class Kind { Named, Self };
35+
enum class Kind { Named, Ordered, Self };
3636

3737
private:
3838
SourceLoc Loc;
3939
Kind Kind;
4040
union Value {
41-
struct { Identifier Name; }; // Index
41+
struct { Identifier Name; }; // Named
42+
struct { unsigned Index; }; // Ordered
4243
struct {}; // Self
4344
Value(Identifier name) : Name(name) {}
45+
Value(unsigned index) : Index(index) {}
4446
Value() {}
4547
} V;
4648

4749
public:
4850
ParsedAutoDiffParameter(SourceLoc loc, enum Kind kind, Value value)
4951
: Loc(loc), Kind(kind), V(value) {}
52+
53+
ParsedAutoDiffParameter(SourceLoc loc, enum Kind kind, unsigned index)
54+
: Loc(loc), Kind(kind), V(index) {}
5055

5156
static ParsedAutoDiffParameter getNamedParameter(SourceLoc loc,
5257
Identifier name) {
5358
return { loc, Kind::Named, name };
5459
}
60+
61+
static ParsedAutoDiffParameter getOrderedParameter(SourceLoc loc,
62+
unsigned index) {
63+
return { loc, Kind::Ordered, index };
64+
}
5565

5666
static ParsedAutoDiffParameter getSelfParameter(SourceLoc loc) {
5767
return { loc, Kind::Self, {} };
@@ -61,6 +71,10 @@ class ParsedAutoDiffParameter {
6171
assert(Kind == Kind::Named);
6272
return V.Name;
6373
}
74+
75+
unsigned getIndex() const {
76+
return V.Index;
77+
}
6478

6579
enum Kind getKind() const {
6680
return Kind;

branches/rxwei-patch-1/include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,8 @@ ERROR(attr_differentiating_expected_label_linear_or_wrt,none,
15161516
ERROR(expected_colon_after_label,PointsToFirstBadToken,
15171517
"expected a colon ':' after '%0'", (StringRef))
15181518
ERROR(diff_params_clause_expected_parameter,PointsToFirstBadToken,
1519-
"expected a parameter, which can be a function parameter name or 'self'",
1519+
"expected a parameter, which can be a function parameter name, "
1520+
"parameter index, or 'self'",
15201521
())
15211522

15221523
// [differentiable ...] (sil-decl attr)

branches/rxwei-patch-1/include/swift/AST/DiagnosticsSIL.def

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,16 +413,16 @@ NOTE(autodiff_external_nondifferentiable_function,none,
413413
"'@differentiable' and that are defined in other files", ())
414414
NOTE(autodiff_nondifferentiable_argument,none,
415415
"cannot differentiate through a non-differentiable argument; do you want "
416-
"to add '.withoutDerivative()'?", ())
416+
"to use 'withoutDerivative(at:)'?", ())
417417
NOTE(autodiff_nondifferentiable_result,none,
418418
"cannot differentiate through a non-differentiable result; do you want to "
419-
"add '.withoutDerivative()'?", ())
419+
"use 'withoutDerivative(at:)'?", ())
420420
NOTE(autodiff_noderivative_stored_property,none,
421421
"cannot differentiate through a '@noDerivative' stored property; do you "
422-
"want to add '.withoutDerivative()'?", ())
422+
"want to use 'withoutDerivative(at:)'?", ())
423423
WARNING(autodiff_nonvaried_result_fixit,none,
424424
"result does not depend on differentiation arguments and will always "
425-
"have a zero derivative; do you want to add '.withoutDerivative()'?",
425+
"have a zero derivative; do you want to use 'withoutDerivative(at:)'?",
426426
())
427427
NOTE(autodiff_enums_unsupported,none,
428428
"differentiating enum values is not yet supported", ())

branches/rxwei-patch-1/include/swift/AST/DiagnosticsSema.def

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,10 +1100,6 @@ NOTE(string_index_not_integer_note,none,
11001100
"consider using an existing high level algorithm, "
11011101
"str.startIndex.advanced(by: n), or a projection like str.utf8", ())
11021102

1103-
// SWIFT_ENABLE_TENSORFLOW
1104-
ERROR(invalid_tensorflow_fn_conversion,none,
1105-
"TensorFlow functions cannot be converted to other function types", ())
1106-
11071103

11081104
ERROR(invalid_c_function_pointer_conversion_expr,none,
11091105
"a C function pointer can only be formed from a reference to a 'func' or "
@@ -1118,6 +1114,12 @@ ERROR(c_function_pointer_from_function_with_context,none,
11181114
"%select{local function|closure}0 that captures "
11191115
"%select{context|generic parameters|dynamic Self type|<<error>}1",
11201116
(bool, unsigned))
1117+
// SWIFT_ENABLE_TENSORFLOW
1118+
ERROR(invalid_differentiable_function_conversion_expr,none,
1119+
"a '@differentiable' function can only be formed from a reference to a "
1120+
"'func' or a literal closure", ())
1121+
NOTE(invalid_differentiable_function_conversion_parameter,none,
1122+
"did you mean to take a '%0' closure?", (StringRef))
11211123
ERROR(invalid_autoclosure_forwarding,none,
11221124
"add () to forward @autoclosure parameter", ())
11231125

@@ -2815,7 +2817,9 @@ ERROR(diff_params_clause_self_instance_method_only,none,
28152817
ERROR(diff_params_clause_self_must_be_first,none,
28162818
"'self' parameter must come first in the parameter list", ())
28172819
ERROR(diff_params_clause_params_not_original_order,none,
2818-
"parameter names must be specified in original order", ())
2820+
"parameters must be specified in original order", ())
2821+
ERROR(diff_params_clause_param_index_out_of_range,none,
2822+
"parameter index is larger than total number of parameters", ())
28192823
ERROR(diff_params_clause_no_inferred_parameters,PointsToFirstBadToken,
28202824
"no differentiation parameters could be inferred; must differentiate "
28212825
"with respect to at least one parameter conforming to 'Differentiable'",

branches/rxwei-patch-1/include/swift/Parse/Parser.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,6 @@ class Parser {
961961
bool parseDifferentiationParametersClause(
962962
SmallVectorImpl<ParsedAutoDiffParameter> &params, StringRef attrName);
963963

964-
/// SWIFT_ENABLE_TENSORFLOW
965964
/// Parse the @differentiating attribute.
966965
ParserResult<DifferentiatingAttr>
967966
parseDifferentiatingAttribute(SourceLoc AtLoc, SourceLoc Loc);

branches/rxwei-patch-1/lib/AST/Attr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,13 @@ static std::string getDifferentiationParametersClauseString(
374374
case ParsedAutoDiffParameter::Kind::Self:
375375
printer << "self";
376376
break;
377+
case ParsedAutoDiffParameter::Kind::Ordered:
378+
auto *paramList = function->getParameters();
379+
assert(param.getIndex() <= paramList->size() &&
380+
"wrt parameter is out of range");
381+
auto *funcParam = paramList->get(param.getIndex());
382+
printer << funcParam->getNameStr();
383+
break;
377384
}
378385
}, [&] { printer << ", "; });
379386
if (parsedParams.size() > 1)

branches/rxwei-patch-1/lib/IRGen/GenDecl.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,16 +1654,13 @@ getIRLinkage(const UniversalLinkageInfo &info, SILLinkage linkage,
16541654
return {llvm::GlobalValue::ExternalLinkage, PublicDefinitionVisibility,
16551655
ExportedStorage};
16561656

1657-
case SILLinkage::PublicNonABI:
1658-
return isDefinition ? RESULT(WeakODR, Hidden, Default)
1659-
: RESULT(External, Hidden, Default);
1660-
16611657
case SILLinkage::Shared:
16621658
case SILLinkage::SharedExternal:
16631659
return isDefinition ? RESULT(LinkOnceODR, Hidden, Default)
16641660
: RESULT(External, Hidden, Default);
16651661

16661662
case SILLinkage::Hidden:
1663+
case SILLinkage::PublicNonABI:
16671664
return RESULT(External, Hidden, Default);
16681665

16691666
case SILLinkage::Private: {

branches/rxwei-patch-1/lib/IRGen/GenFunc.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,22 +1247,8 @@ static llvm::Function *emitPartialApplicationForwarder(IRGenModule &IGM,
12471247
// cast to the result type - it could be substituted.
12481248
if (origConv.getSILResultType().hasTypeParameter()) {
12491249
auto ResType = fwd->getReturnType();
1250-
// SWIFT_ENABLE_TENSORFLOW
1251-
if (auto *structType = dyn_cast<llvm::StructType>(ResType)) {
1252-
// Cast all struct elements to the desired type.
1253-
llvm::Value *castResult = llvm::UndefValue::get(structType);
1254-
for (auto i : range(structType->getStructNumElements())) {
1255-
auto desiredEltTy = structType->getElementType(i);
1256-
auto elt = subIGF.Builder.CreateExtractValue(callResult, {i});
1257-
auto castElt = subIGF.Builder.CreateBitCast(elt, desiredEltTy);
1258-
castResult =
1259-
subIGF.Builder.CreateInsertValue(castResult, castElt, {i});
1260-
}
1261-
callResult = castResult;
1262-
}
1263-
else
1264-
if (ResType != callResult->getType())
1265-
callResult = subIGF.coerceValue(callResult, ResType, subIGF.IGM.DataLayout);
1250+
if (ResType != callResult->getType())
1251+
callResult = subIGF.coerceValue(callResult, ResType, subIGF.IGM.DataLayout);
12661252
}
12671253
subIGF.Builder.CreateRet(callResult);
12681254
}

branches/rxwei-patch-1/lib/Parse/ParseDecl.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,17 @@ bool Parser::parseDifferentiationParametersClause(
892892
paramLoc, paramName));
893893
break;
894894
}
895+
case tok::integer_literal: {
896+
unsigned paramNum;
897+
if (parseUnsignedInteger(
898+
paramNum, paramLoc,
899+
diag::diff_params_clause_expected_parameter))
900+
return true;
901+
902+
params.push_back(ParsedAutoDiffParameter::getOrderedParameter(
903+
paramLoc, paramNum));
904+
break;
905+
}
895906
case tok::kw_self: {
896907
paramLoc = consumeToken(tok::kw_self);
897908
params.push_back(ParsedAutoDiffParameter::getSelfParameter(paramLoc));
@@ -1960,15 +1971,15 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
19601971
break;
19611972
}
19621973

1963-
/// SWIFT_ENABLE_TENSORFLOW
1974+
// SWIFT_ENABLE_TENSORFLOW
19641975
case DAK_Differentiable: {
19651976
auto Attr = parseDifferentiableAttribute(AtLoc, Loc);
19661977
if (Attr.isNonNull())
19671978
Attributes.add(Attr.get());
19681979
break;
19691980
}
19701981

1971-
/// SWIFT_ENABLE_TENSORFLOW
1982+
// SWIFT_ENABLE_TENSORFLOW
19721983
case DAK_Differentiating: {
19731984
auto Attr = parseDifferentiatingAttribute(AtLoc, Loc);
19741985
if (Attr.isNonNull())

0 commit comments

Comments
 (0)