Skip to content

Commit 398884c

Browse files
committed
Fixes to make the compiler build. (Note: tests are likely to fail.)
1 parent d93a9c0 commit 398884c

16 files changed

+55
-51
lines changed

include/swift/Parse/Parser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ class Parser {
16491649
ParserResult<Expr> parseExprUnquote();
16501650
ParserResult<Expr> parseExprCallSuffix(ParserResult<Expr> fn,
16511651
bool isExprBasic);
1652-
ParserResult<Expr> parseExprPoundAssert();
1652+
ParserResult<Expr> parseExprCollection();
16531653
ParsedSyntaxResult<ParsedExprSyntax> parseExprCollectionSyntax();
16541654
ParsedSyntaxResult<ParsedExprSyntax>
16551655
parseExprArraySyntax(ParsedTokenSyntax &&LSquare, SourceLoc LSquareLoc,
@@ -1658,6 +1658,7 @@ class Parser {
16581658
parseExprDictionarySyntax(ParsedTokenSyntax &&LSquare, SourceLoc LSquareLoc,
16591659
ParsedSyntaxResult<ParsedExprSyntax> &&firstExpr);
16601660

1661+
ParserResult<Expr> parseExprPoundAssert();
16611662
ParserResult<Expr> parseExprPoundUnknown(SourceLoc LSquareLoc);
16621663
ParsedSyntaxResult<ParsedExprSyntax>
16631664
parseExprPoundUnknownSyntax(Optional<ParsedTokenSyntax> &&LSquare,

lib/AST/AutoDiff.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ autodiff::getLoweredParameterIndices(IndexSubset *indices,
151151
paramLoweredSizes.push_back(paramLoweredSize);
152152
totalLoweredSize += paramLoweredSize;
153153
};
154-
for (auto *curryLevel : reversed(curryLevels))
154+
for (auto *curryLevel : llvm::reverse(curryLevels))
155155
for (auto &param : curryLevel->getParams())
156156
addLoweredParamInfo(param.getPlainType());
157157

@@ -183,7 +183,7 @@ void autodiff::getSubsetParameterTypes(IndexSubset *subset,
183183

184184
SmallVector<unsigned, 2> curryLevelParameterIndexOffsets(curryLevels.size());
185185
unsigned currentOffset = 0;
186-
for (unsigned curryLevelIndex : reversed(indices(curryLevels))) {
186+
for (unsigned curryLevelIndex : llvm::reverse(indices(curryLevels))) {
187187
curryLevelParameterIndexOffsets[curryLevelIndex] = currentOffset;
188188
currentOffset += curryLevels[curryLevelIndex]->getNumParams();
189189
}

lib/AST/Type.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4680,7 +4680,7 @@ AnyFunctionType *AnyFunctionType::getAutoDiffDerivativeFunctionType(
46804680
// Wrap the derivative function type in additional curry levels.
46814681
auto curryLevelsWithoutLast =
46824682
ArrayRef<AnyFunctionType *>(curryLevels).drop_back(1);
4683-
for (auto pair : enumerate(reversed(curryLevelsWithoutLast))) {
4683+
for (auto pair : enumerate(llvm::reverse(curryLevelsWithoutLast))) {
46844684
unsigned i = pair.index();
46854685
AnyFunctionType *curryLevel = pair.value();
46864686
derivativeFunction = makeFunctionType(
@@ -4719,7 +4719,7 @@ AnyFunctionType::getAutoDiffOriginalFunctionType() {
47194719
// Wrap the derivative function type in additional curry levels.
47204720
auto curryLevelsWithoutLast =
47214721
ArrayRef<AnyFunctionType *>(curryLevels).drop_back(1);
4722-
for (auto pair : enumerate(reversed(curryLevelsWithoutLast))) {
4722+
for (auto pair : enumerate(llvm::reverse(curryLevelsWithoutLast))) {
47234723
unsigned i = pair.index();
47244724
AnyFunctionType *curryLevel = pair.value();
47254725
originalType = makeFunctionType(

lib/SILGen/SILGenPoly.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3655,7 +3655,7 @@ SILGenFunction::getThunkedAutoDiffLinearMap(
36553655
CleanupLocation::get(loc), NotForUnwind);
36563656

36573657
// Deallocate local allocations.
3658-
for (auto *alloc : reversed(localAllocations))
3658+
for (auto *alloc : llvm::reverse(localAllocations))
36593659
thunkSGF.B.createDeallocStack(loc, alloc);
36603660

36613661
// Create return.

lib/SILOptimizer/Mandatory/Differentiation.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ class LinearMapInfo {
580580
branchingTraceDecl->setGenericSignature(genericSig);
581581
computeAccessLevel(branchingTraceDecl,
582582
original->getEffectiveSymbolLinkage());
583-
branchingTraceDecl->computeType();
583+
// branchingTraceDecl->computeType(); // TODO(saeta): FIX ME!
584584
assert(branchingTraceDecl->hasInterfaceType());
585585
file.addVisibleDecl(branchingTraceDecl);
586586
// Add basic block enum cases.
@@ -591,9 +591,9 @@ class LinearMapInfo {
591591
auto linearMapStructTy =
592592
linearMapStruct->getDeclaredInterfaceType()->getCanonicalType();
593593
// Create dummy declaration representing enum case parameter.
594-
auto *decl = new (astCtx)
595-
ParamDecl(ParamDecl::Specifier::Default, loc, loc, Identifier(), loc,
596-
Identifier(), moduleDecl);
594+
auto *decl = new (astCtx) ParamDecl(loc, loc, Identifier(), loc,
595+
Identifier(), moduleDecl);
596+
decl->setSpecifier(ParamDecl::Specifier::Default);
597597
if (linearMapStructTy->hasArchetype())
598598
decl->setInterfaceType(linearMapStructTy->mapTypeOutOfContext());
599599
else
@@ -604,7 +604,7 @@ class LinearMapInfo {
604604
/*IdentifierLoc*/ loc, DeclName(astCtx.getIdentifier(bbId)),
605605
paramList, loc, /*RawValueExpr*/ nullptr, branchingTraceDecl);
606606
enumEltDecl->setImplicit();
607-
enumEltDecl->computeType();
607+
// enumEltDecl->computeType(); // TODO(saeta): FIX ME!
608608
auto *enumCaseDecl = EnumCaseDecl::create(
609609
/*CaseLoc*/ loc, {enumEltDecl}, branchingTraceDecl);
610610
enumCaseDecl->setImplicit();
@@ -659,7 +659,7 @@ class LinearMapInfo {
659659
linearMapStruct->setGenericSignature(genericSig);
660660
computeAccessLevel(
661661
linearMapStruct, original->getEffectiveSymbolLinkage());
662-
linearMapStruct->computeType();
662+
// linearMapStruct->computeType(); // TODO(saeta): FIX ME!
663663
assert(linearMapStruct->hasInterfaceType());
664664
file.addVisibleDecl(linearMapStruct);
665665
return linearMapStruct;
@@ -2017,7 +2017,7 @@ void DifferentiableActivityInfo::analyze(DominanceInfo *di,
20172017
// Propagate usefulness through the function in post-dominance order.
20182018
PostDominanceOrder postDomOrder(&*function.findReturnBB(), pdi);
20192019
while (auto *bb = postDomOrder.getNext()) {
2020-
for (auto &inst : reversed(*bb)) {
2020+
for (auto &inst : llvm::reverse(*bb)) {
20212021
for (auto i : indices(outputValues)) {
20222022
// Handle indirect results in `apply`.
20232023
if (auto *ai = dyn_cast<ApplyInst>(&inst)) {
@@ -3239,7 +3239,7 @@ static SILFunction *getOrCreateReabstractionThunk(SILOptFunctionBuilder &fb,
32393239
auto retVal = joinElements(results, builder, loc);
32403240

32413241
// Deallocate local allocations.
3242-
for (auto *alloc : reversed(localAllocations))
3242+
for (auto *alloc : llvm::reverse(localAllocations))
32433243
builder.createDeallocStack(loc, alloc);
32443244

32453245
// Create return.
@@ -6610,15 +6610,15 @@ class PullbackEmitter final : public SILInstructionVisitor<PullbackEmitter> {
66106610
auto &s = getADDebugStream()
66116611
<< "Original bb" + std::to_string(bb->getDebugID())
66126612
<< ": To differentiate or not to differentiate?\n";
6613-
for (auto &inst : reversed(*bb)) {
6613+
for (auto &inst : llvm::reverse(*bb)) {
66146614
s << (getPullbackInfo().shouldDifferentiateInstruction(&inst)
66156615
? "[∂] " : "[ ] ")
66166616
<< inst;
66176617
}
66186618
});
66196619

66206620
// Visit each instruction in reverse order.
6621-
for (auto &inst : reversed(*bb)) {
6621+
for (auto &inst : llvm::reverse(*bb)) {
66226622
if (!getPullbackInfo().shouldDifferentiateInstruction(&inst))
66236623
continue;
66246624
// Differentiate instruction.
@@ -6981,7 +6981,7 @@ class PullbackEmitter final : public SILInstructionVisitor<PullbackEmitter> {
69816981
}
69826982
}
69836983
// Destroy and deallocate pullback indirect results.
6984-
for (auto *alloc : reversed(pullbackIndirectResults)) {
6984+
for (auto *alloc : llvm::reverse(pullbackIndirectResults)) {
69856985
builder.emitDestroyAddrAndFold(loc, alloc);
69866986
builder.createDeallocStack(loc, alloc);
69876987
}
@@ -8312,7 +8312,7 @@ ADContext::getOrCreateSubsetParametersThunkForLinearMap(
83128312
// If differential thunk, deallocate local allocations and directly return
83138313
// `apply` result.
83148314
if (kind == AutoDiffDerivativeFunctionKind::JVP) {
8315-
for (auto *alloc : reversed(localAllocations))
8315+
for (auto *alloc : llvm::reverse(localAllocations))
83168316
builder.createDeallocStack(loc, alloc);
83178317
builder.createReturn(loc, ai);
83188318
return {thunk, interfaceSubs};
@@ -8345,7 +8345,7 @@ ADContext::getOrCreateSubsetParametersThunkForLinearMap(
83458345
}
83468346
}
83478347
// Deallocate local allocations and return final direct result.
8348-
for (auto *alloc : reversed(localAllocations))
8348+
for (auto *alloc : llvm::reverse(localAllocations))
83498349
builder.createDeallocStack(loc, alloc);
83508350
auto result = joinElements(results, builder, loc);
83518351
builder.createReturn(loc, result);
@@ -8693,7 +8693,7 @@ SILValue ADContext::promoteToDifferentiableFunction(
86938693
derivativeFns.push_back(derivativeFn);
86948694
}
86958695
// Deallocate temporary buffers used for creating derivative functions.
8696-
for (auto *buf : reversed(newBuffersToDealloc))
8696+
for (auto *buf : llvm::reverse(newBuffersToDealloc))
86978697
builder.createDeallocStack(loc, buf);
86988698

86998699
auto origFnCopy = builder.emitCopyValueOperation(loc, origFnOperand);

lib/SILOptimizer/Mandatory/Differentiation.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ void createEntryArguments(SILFunction *f) {
100100
// Create a dummy parameter declaration.
101101
// Necessary to prevent crash during argument explosion optimization.
102102
auto loc = f->getLocation().getSourceLoc();
103-
auto *decl = new (ctx)
104-
ParamDecl(ParamDecl::Specifier::Default, loc, loc, Identifier(), loc,
105-
Identifier(), moduleDecl);
103+
auto *decl = new (ctx) ParamDecl(loc, loc, Identifier(), loc,
104+
Identifier(), moduleDecl);
105+
decl->setSpecifier(ParamDecl::Specifier::Default);
106106
decl->setType(type.getASTType());
107107
entry->createFunctionArgument(type, decl);
108108
};

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5918,7 +5918,7 @@ maybeDiagnoseUnsupportedDifferentiableConversion(ConstraintSystem &cs,
59185918
diag::invalid_differentiable_function_conversion_expr,
59195919
isToTypeLinear);
59205920
if (paramDecl->getType()->is<AnyFunctionType>()) {
5921-
auto *typeRepr = paramDecl->getTypeLoc().getTypeRepr();
5921+
auto *typeRepr = paramDecl->getTypeRepr();
59225922
while (auto *attributed = dyn_cast<AttributedTypeRepr>(typeRepr))
59235923
typeRepr = attributed->getTypeRepr();
59245924
std::string attributeString = "@differentiable";
@@ -5929,7 +5929,7 @@ maybeDiagnoseUnsupportedDifferentiableConversion(ConstraintSystem &cs,
59295929
tc.diagnose(paramDecl->getLoc(),
59305930
diag::invalid_differentiable_function_conversion_parameter,
59315931
attributeString)
5932-
.highlight(paramDecl->getTypeLoc().getSourceRange())
5932+
.highlight(paramDecl->getTypeRepr()->getSourceRange())
59335933
.fixItInsert(paramListLoc, attributeString + " ");
59345934
}
59355935
return;

lib/Sema/DerivedConformanceDifferentiable.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,9 @@ static ValueDecl *deriveDifferentiable_method(
326326
auto &C = derived.TC.Context;
327327
auto *parentDC = derived.getConformanceContext();
328328

329-
auto *param =
330-
new (C) ParamDecl(ParamDecl::Specifier::Default, SourceLoc(), SourceLoc(),
331-
argumentName, SourceLoc(), parameterName, parentDC);
329+
auto *param = new (C) ParamDecl(SourceLoc(), SourceLoc(), argumentName,
330+
SourceLoc(), parameterName, parentDC);
331+
param->setSpecifier(ParamDecl::Specifier::Default);
332332
param->setInterfaceType(parameterType);
333333
ParameterList *params = ParameterList::create(C, {param});
334334

@@ -699,7 +699,6 @@ static void addAssociatedTypeAliasDecl(Identifier name,
699699
aliasDecl->setGenericSignature(sourceDC->getGenericSignatureOfContext());
700700
cast<IterableDeclContext>(sourceDC->getAsDecl())->addMember(aliasDecl);
701701
aliasDecl->copyFormalAccessFrom(nominal, /*sourceIsParentContext*/ true);
702-
aliasDecl->computeType();
703702
TC.validateDecl(aliasDecl);
704703
C.addSynthesizedDecl(aliasDecl);
705704
};
@@ -845,7 +844,6 @@ deriveDifferentiable_TangentVectorStruct(DerivedConformance &derived) {
845844
aliasDecl->setUnderlyingType(selfType);
846845
aliasDecl->setImplicit();
847846
aliasDecl->copyFormalAccessFrom(nominal, /*sourceIsParentContext*/ true);
848-
aliasDecl->computeType();
849847
TC.validateDecl(aliasDecl);
850848
derived.addMembersToConformanceContext({aliasDecl});
851849
C.addSynthesizedDecl(aliasDecl);

lib/Sema/DerivedConformanceElementaryFunctions.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,9 @@ ElementaryFunction op) {
253253
// Create parameter declaration with the given name and type.
254254
auto createParamDecl = [&](StringRef name, Type type) -> ParamDecl * {
255255
auto *param = new (C)
256-
ParamDecl(ParamDecl::Specifier::Default, SourceLoc(), SourceLoc(),
257-
Identifier(), SourceLoc(), C.getIdentifier(name), parentDC);
256+
ParamDecl(SourceLoc(), SourceLoc(), Identifier(), SourceLoc(),
257+
C.getIdentifier(name), parentDC);
258+
param->setSpecifier(ParamDecl::Specifier::Default);
258259
param->setInterfaceType(type);
259260
return param;
260261
};

lib/Sema/DerivedConformanceRingMathProtocols.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,9 @@ static ValueDecl *deriveMathOperator(DerivedConformance &derived,
228228
// Create parameter declaration with the given name and type.
229229
auto createParamDecl = [&](StringRef name, Type type) -> ParamDecl * {
230230
auto *param = new (C)
231-
ParamDecl(ParamDecl::Specifier::Default, SourceLoc(), SourceLoc(),
232-
Identifier(), SourceLoc(), C.getIdentifier(name), parentDC);
231+
ParamDecl(SourceLoc(), SourceLoc(), Identifier(), SourceLoc(),
232+
C.getIdentifier(name), parentDC);
233+
param->setSpecifier(ParamDecl::Specifier::Default);
233234
param->setInterfaceType(type);
234235
return param;
235236
};

lib/Sema/DerivedConformanceTensorArrayProtocol.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ deriveBodyTensorArrayProtocol_unpackTensorHandles(
149149
// If conformance reference is concrete, then use concrete witness
150150
// declaration for the operator.
151151
if (confRef->isConcrete())
152-
memberMethodDecl = confRef->getConcrete()->getWitnessDecl(methodReq);
152+
memberMethodDecl = confRef->getConcrete()->
153+
getWitnessDecl(methodReq);
153154
assert(memberMethodDecl && "Member method declaration must exist");
154155
auto memberMethodDRE = new (C) DeclRefExpr(
155156
memberMethodDecl, DeclNameLoc(), /*Implicit*/ true);
@@ -227,8 +228,9 @@ static ValueDecl *deriveTensorArrayProtocol_method(
227228
auto parentDC = derived.getConformanceContext();
228229

229230
auto *param =
230-
new (C) ParamDecl(ParamDecl::Specifier::Default, SourceLoc(), SourceLoc(),
231-
argumentName, SourceLoc(), parameterName, parentDC);
231+
new (C) ParamDecl(SourceLoc(), SourceLoc(), argumentName, SourceLoc(),
232+
parameterName, parentDC);
233+
param->setSpecifier(ParamDecl::Specifier::Default);
232234
param->setInterfaceType(parameterType);
233235
ParameterList *params = ParameterList::create(C, {param});
234236

@@ -621,15 +623,15 @@ static ValueDecl
621623
C.getOptionalDecl(), Type(), {baseAddressType});
622624
Type intType = C.getIntDecl()->getDeclaredType();
623625

624-
auto *param1 = new (C) ParamDecl(
625-
ParamDecl::Specifier::Default, SourceLoc(), SourceLoc(),
626+
auto *param1 = new (C) ParamDecl(SourceLoc(), SourceLoc(),
626627
C.getIdentifier("_owning"), SourceLoc(), C.getIdentifier("tensorHandles"),
627628
parentDC);
629+
param1->setSpecifier(ParamDecl::Specifier::Default);
628630
param1->setInterfaceType(addressType);
629-
auto *param2 = new (C) ParamDecl(
630-
ParamDecl::Specifier::Default, SourceLoc(), SourceLoc(),
631+
auto *param2 = new (C) ParamDecl(SourceLoc(), SourceLoc(),
631632
C.getIdentifier("count"), SourceLoc(), C.getIdentifier("count"),
632633
parentDC);
634+
param2->setSpecifier(ParamDecl::Specifier::Default);
633635
param2->setInterfaceType(intType);
634636
ParameterList *params = ParameterList::create(C, {param1, param2});
635637

lib/Sema/DerivedConformanceTensorGroup.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,9 @@ static ValueDecl *deriveTensorGroup_constructor(
323323
auto parentDC = derived.getConformanceContext();
324324

325325
auto *param =
326-
new (C) ParamDecl(ParamDecl::Specifier::Default, SourceLoc(), SourceLoc(),
327-
argumentName, SourceLoc(), parameterName, parentDC);
326+
new (C) ParamDecl(SourceLoc(), SourceLoc(), argumentName, SourceLoc(),
327+
parameterName, parentDC);
328+
param->setSpecifier(ParamDecl::Specifier::Default);
328329
param->setInterfaceType(parameterType);
329330
ParameterList *params = ParameterList::create(C, {param});
330331

lib/Sema/DerivedConformanceVectorProtocol.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,9 @@ static ValueDecl *deriveVectorProtocol_method(
214214
auto parentDC = derived.getConformanceContext();
215215

216216
auto *param =
217-
new (C) ParamDecl(ParamDecl::Specifier::Default, SourceLoc(), SourceLoc(),
218-
argumentLabel, SourceLoc(), parameterName, parentDC);
217+
new (C) ParamDecl(SourceLoc(), SourceLoc(), argumentLabel, SourceLoc(),
218+
parameterName, parentDC);
219+
param->setSpecifier(ParamDecl::Specifier::Default);
219220
param->setInterfaceType(parameterType);
220221
ParameterList *params = ParameterList::create(C, {param});
221222

lib/Sema/DerivedConformances.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,10 +544,9 @@ DerivedConformance::declareDerivedPropertySetter(VarDecl *property,
544544
auto parentDC = property->getDeclContext();
545545

546546
auto propertyInterfaceType = property->getInterfaceType();
547-
auto propertyParam = new (C)
548-
ParamDecl(ParamDecl::Specifier::Default, SourceLoc(), SourceLoc(),
549-
Identifier(), property->getLoc(), C.getIdentifier("newValue"),
550-
parentDC);
547+
auto propertyParam = new (C) ParamDecl(SourceLoc(), SourceLoc(), Identifier(),
548+
property->getLoc(), C.getIdentifier("newValue"), parentDC);
549+
propertyParam->setSpecifier(ParamDecl::Specifier::Default);
551550
propertyParam->setInterfaceType(propertyInterfaceType);
552551

553552
ParameterList *params = ParameterList::create(C, propertyParam);

lib/Sema/QuoteTransform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Breadcrumbs {
3939
void pop() { locs.pop_back(); }
4040

4141
SourceLoc getLoc() {
42-
for (auto loc : reversed(locs)) {
42+
for (auto loc : llvm::reverse(locs)) {
4343
if (loc.isValid()) {
4444
return loc.Start;
4545
}

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4286,7 +4286,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
42864286
AFD->computeType();
42874287
// SWIFT_ENABLE_TENSORFLOW
42884288
// TODO(TF-789): Find proper way to type-check `@differentiable` attributes.
4289-
checkDeclDifferentiableAttributes(CD);
4289+
checkDeclDifferentiableAttributes(AFD);
42904290
// SWIFT_ENABLE_TENSORFLOW END
42914291
break;
42924292
}

0 commit comments

Comments
 (0)