Skip to content

Commit fe89798

Browse files
committed
Fix compiler errors.
1 parent e6ef70a commit fe89798

18 files changed

+52
-105
lines changed

cmake/modules/SwiftSource.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ function(_compile_swift_files
347347
endif()
348348

349349
if (NOT SWIFTFILE_IS_STDLIB_CORE)
350-
list(APPEND swift_module_flags
351-
"-Xfrontend" "-experimental-skip-non-inlinable-function-bodies")
350+
# list(APPEND swift_module_flags
351+
# "-Xfrontend" "-experimental-skip-non-inlinable-function-bodies")
352352
endif()
353353

354354
# If we have extra regexp flags, check if we match any of the regexps. If so

include/swift/AST/AutoDiff.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ class ParsedAutoDiffParameter {
144144
SourceLoc Loc;
145145
Kind Kind;
146146
union Value {
147-
struct { Identifier Name; }; // Named
148-
struct { unsigned Index; }; // Ordered
149-
struct {}; // Self
147+
Identifier Name; // Named
148+
unsigned Index; // Ordered
149+
// Self
150150
Value(Identifier name) : Name(name) {}
151151
Value(unsigned index) : Index(index) {}
152152
Value() {}

lib/Parse/ParseDecl.cpp

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,9 +1231,8 @@ static bool parseBaseTypeForQualifiedDeclName(Parser &P, TypeRepr *&baseType) {
12311231
if (!P.canParseTypeQualifierForDeclName())
12321232
return false;
12331233

1234-
SourceLoc loc = P.Tok.getLoc();
12351234
auto result = P.parseTypeIdentifier(/*isParsingQualifiedDeclName*/ true);
1236-
if (!result.isSuccess())
1235+
if (result.isNull())
12371236
return true;
12381237

12391238
// Consume the period.
@@ -1242,9 +1241,7 @@ static bool parseBaseTypeForQualifiedDeclName(Parser &P, TypeRepr *&baseType) {
12421241
else if (P.startsWithSymbol(P.Tok, '.'))
12431242
P.consumeStartingCharacterOfCurrentToken(tok::period);
12441243

1245-
P.SyntaxContext->addSyntax(result.get());
1246-
auto node = P.SyntaxContext->topNode<TypeSyntax>();
1247-
baseType = P.Generator.generate(node, loc);
1244+
baseType = result.getPtrOrNull();
12481245
return false;
12491246
}
12501247

@@ -2609,57 +2606,47 @@ bool Parser::parseTypeAttribute(TypeAttributes &Attributes, SourceLoc AtLoc,
26092606
StringRef witnessMethodProtocol;
26102607

26112608
// SWIFT_ENABLE_TENSORFLOW
2609+
bool linear = false;
26122610
if (attr == TAK_differentiable) {
26132611
// Check if there is a 'linear' argument.
26142612
// If next tokens are not `'(' identifier`, break early.
26152613
if (Tok.is(tok::l_paren) && peekToken().is(tok::identifier)) {
2616-
26172614
Parser::BacktrackingScope backtrack(*this);
2618-
SourceLoc lParenLoc = Tok.getLoc();
2619-
auto lParen = consumeTokenSyntax(tok::l_paren);
2615+
consumeToken(tok::l_paren);
26202616

26212617
// Determine if we have '@differentiable(linear) (T) -> U'
26222618
// or '@differentiable (linear) -> U'.
2623-
if (Tok.getText() == "linear") {
2624-
auto linearIdentifier = consumeTokenSyntax(tok::identifier);
2625-
if (Tok.is(tok::r_paren) &&
2626-
peekToken().isAny(tok::l_paren, tok::at_sign, tok::identifier)) {
2619+
if (Tok.getText() == "linear" && consumeIf(tok::identifier)) {
2620+
if (Tok.is(tok::r_paren) && peekToken().is(tok::l_paren)) {
26272621
// It is being used as an attribute argument, so cancel backtrack
26282622
// as function is linear differentiable.
2623+
linear = true;
26292624
backtrack.cancelBacktrack();
2630-
builder.useLeftParen(std::move(lParen));
2631-
builder.useArgument(std::move(linearIdentifier));
2632-
SourceLoc rParenLoc;
2633-
auto rParen = parseMatchingTokenSyntax(
2634-
tok::r_paren, diag::differentiable_attribute_expected_rparen, lParenLoc);
2635-
if (rParen.isError())
2636-
return true;
2637-
builder.useRightParen(rParen.get());
2625+
consumeToken(tok::r_paren);
26382626
} else if (Tok.is(tok::l_paren)) {
26392627
// Handle invalid '@differentiable(linear (T) -> U'
2640-
diagnose(Tok, diag::differentiable_attribute_expected_rparen);
2628+
if (!justChecking)
2629+
diagnose(Tok,
2630+
diag::differentiable_attribute_expected_rparen);
26412631
backtrack.cancelBacktrack();
2642-
builder.useLeftParen(std::move(lParen));
2643-
builder.useArgument(std::move(linearIdentifier));
2644-
return true;
2632+
return false;
26452633
}
26462634
} else if (Tok.is(tok::identifier)) {
26472635
// No 'linear' arg or param type, but now checking if the token is being
26482636
// passed in as an invalid argument to '@differentiable'.
26492637
auto possibleArg = Tok.getText();
26502638
auto t = Tok; // get ref to the argument for clearer diagnostics.
2651-
auto argIdentifier = consumeTokenSyntax(tok::identifier);
2639+
consumeToken(tok::identifier);
26522640
// Check if there is an invalid argument getting passed into
26532641
// '@differentiable'.
26542642
if (Tok.is(tok::r_paren) && peekToken().is(tok::l_paren)) {
26552643
// Handling '@differentiable(wrong) (...'.
2656-
diagnose(t, diag::unexpected_argument_differentiable, possibleArg);
2657-
auto rParen = consumeTokenSyntax(tok::r_paren);
2644+
if (!justChecking)
2645+
diagnose(t, diag::unexpected_argument_differentiable,
2646+
possibleArg);
2647+
consumeToken(tok::r_paren);
26582648
backtrack.cancelBacktrack();
2659-
builder.useLeftParen(std::move(lParen));
2660-
builder.useArgument(std::move(argIdentifier));
2661-
builder.useRightParen(std::move(rParen));
2662-
return true;
2649+
return false;
26632650
}
26642651
}
26652652
}
@@ -2849,8 +2836,14 @@ bool Parser::parseTypeAttribute(TypeAttributes &Attributes, SourceLoc AtLoc,
28492836
Attributes.setOpaqueReturnTypeOf(mangling, index);
28502837
break;
28512838
}
2839+
// SWIFT_ENABLE_TENSORFLOW
2840+
// @differentiable(...) attribute.
2841+
case TAK_differentiable:
2842+
Attributes.linear = linear;
2843+
break;
28522844
}
28532845

2846+
28542847
Attributes.setAttr(attr, AtLoc);
28552848
return false;
28562849
}

lib/Parse/ParseType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ bool Parser::canParseTypeQualifierForDeclName() {
624624
// SWIFT_ENABLE_TENSORFLOW: Added `isParsingQualifiedDeclName` flag.
625625
ParserResult<TypeRepr> Parser::parseTypeIdentifier(bool isParsingQualifiedDeclName) {
626626
if (isParsingQualifiedDeclName && !canParseTypeQualifierForDeclName())
627-
return makeParsedError<TypeRepr>();
627+
return makeParserError();
628628

629629
// SWIFT_ENABLE_TENSORFLOW: Condition body intentionally not indented, to
630630
// reduce merge conflicts.

lib/SILOptimizer/Mandatory/Differentiation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class PostOrderPostDominanceOrder {
8989
};
9090

9191
/// Creates arguments in the entry block based on the function type.
92-
void createEntryArguments(SILFunction *f) {
92+
inline void createEntryArguments(SILFunction *f) {
9393
auto *entry = f->getEntryBlock();
9494
auto conv = f->getConventions();
9595
auto &ctx = f->getASTContext();
@@ -103,7 +103,7 @@ void createEntryArguments(SILFunction *f) {
103103
auto *decl = new (ctx) ParamDecl(loc, loc, Identifier(), loc,
104104
Identifier(), moduleDecl);
105105
decl->setSpecifier(ParamDecl::Specifier::Default);
106-
decl->setType(type.getASTType());
106+
// decl->setType(type.getASTType());
107107
entry->createFunctionArgument(type, decl);
108108
};
109109
for (auto indResTy : conv.getIndirectSILResultTypes())

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7119,7 +7119,7 @@ ConstraintSystem::simplifyApplicableFnConstraint(
71197119
// Record the call method overload set.
71207120
SmallVector<OverloadChoice, 4> choices;
71217121
for (auto candidate : callMethods) {
7122-
TC.validateDecl(candidate);
7122+
(void)candidate->getInterfaceType();
71237123
if (candidate->isInvalid()) continue;
71247124
choices.push_back(
71257125
OverloadChoice(type2, candidate, FunctionRefKind::SingleApply));

lib/Sema/DerivedConformanceDifferentiable.cpp

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ getStoredPropertiesForDifferentiation(NominalTypeDecl *nominal,
5959
continue;
6060
if (vd->isLet())
6161
continue;
62-
if (!vd->hasInterfaceType())
63-
C.getLazyResolver()->resolveDeclSignature(vd);
64-
if (!vd->hasInterfaceType())
62+
if (vd->getInterfaceType()->hasError())
6563
continue;
6664
auto varType = DC->mapTypeIntoContext(vd->getValueInterfaceType());
6765
if (!TypeChecker::conformsToProtocol(varType, diffableProto, nominal,
@@ -90,8 +88,6 @@ static StructDecl *convertToStructDecl(ValueDecl *v) {
9088
static Type getTangentVectorType(VarDecl *decl, DeclContext *DC) {
9189
auto &C = decl->getASTContext();
9290
auto *diffableProto = C.getProtocol(KnownProtocolKind::Differentiable);
93-
if (!decl->hasInterfaceType())
94-
C.getLazyResolver()->resolveDeclSignature(decl);
9591
auto varType = DC->mapTypeIntoContext(decl->getValueInterfaceType());
9692
auto conf = TypeChecker::conformsToProtocol(varType, diffableProto, DC,
9793
None);
@@ -126,7 +122,6 @@ bool DerivedConformance::canDeriveDifferentiable(NominalTypeDecl *nominal,
126122
if (!isa<StructDecl>(nominal) && !isa<ClassDecl>(nominal))
127123
return false;
128124
auto &C = nominal->getASTContext();
129-
auto *lazyResolver = C.getLazyResolver();
130125
auto *diffableProto = C.getProtocol(KnownProtocolKind::Differentiable);
131126
auto *addArithProto = C.getProtocol(KnownProtocolKind::AdditiveArithmetic);
132127

@@ -186,9 +181,7 @@ bool DerivedConformance::canDeriveDifferentiable(NominalTypeDecl *nominal,
186181
SmallVector<VarDecl *, 16> diffProperties;
187182
getStoredPropertiesForDifferentiation(nominal, DC, diffProperties);
188183
return llvm::all_of(diffProperties, [&](VarDecl *v) {
189-
if (!v->hasInterfaceType())
190-
lazyResolver->resolveDeclSignature(v);
191-
if (!v->hasInterfaceType())
184+
if (v->getInterfaceType()->hasError())
192185
return false;
193186
auto varType = DC->mapTypeIntoContext(v->getValueInterfaceType());
194187
return (bool)TypeChecker::conformsToProtocol(varType, diffableProto, DC,
@@ -204,17 +197,14 @@ bool DerivedConformance::canDeriveEuclideanDifferentiable(
204197
if (!canDeriveDifferentiable(nominal, DC))
205198
return false;
206199
auto &C = nominal->getASTContext();
207-
auto *lazyResolver = C.getLazyResolver();
208200
auto *eucDiffProto =
209201
C.getProtocol(KnownProtocolKind::EuclideanDifferentiable);
210202
// Return true if all differentiation stored properties conform to
211203
// `AdditiveArithmetic` and their `TangentVector` equals themselves.
212204
SmallVector<VarDecl *, 16> diffProperties;
213205
getStoredPropertiesForDifferentiation(nominal, DC, diffProperties);
214206
return llvm::all_of(diffProperties, [&](VarDecl *member) {
215-
if (!member->hasInterfaceType())
216-
lazyResolver->resolveDeclSignature(member);
217-
if (!member->hasInterfaceType())
207+
if (member->getInterfaceType()->hasError())
218208
return false;
219209
auto varType = DC->mapTypeIntoContext(member->getValueInterfaceType());
220210
return (bool)TypeChecker::conformsToProtocol(
@@ -344,7 +334,6 @@ static ValueDecl *deriveDifferentiable_method(
344334
funcDecl->setBodySynthesizer(bodySynthesizer.Fn, bodySynthesizer.Context);
345335

346336
funcDecl->setGenericSignature(parentDC->getGenericSignatureOfContext());
347-
funcDecl->computeType();
348337
funcDecl->copyFormalAccessFrom(nominal, /*sourceIsParentContext*/ true);
349338

350339
derived.addMembersToConformanceContext({funcDecl});
@@ -600,7 +589,7 @@ getOrSynthesizeTangentVectorStruct(DerivedConformance &derived, Identifier id) {
600589
auto memberAssocContextualType =
601590
parentDC->mapTypeIntoContext(memberAssocInterfaceType);
602591
newMember->setInterfaceType(memberAssocInterfaceType);
603-
newMember->setType(memberAssocContextualType);
592+
// newMember->setType(memberAssocContextualType);
604593
Pattern *memberPattern =
605594
new (C) NamedPattern(newMember, /*implicit*/ true);
606595
memberPattern->setType(memberAssocContextualType);
@@ -624,9 +613,7 @@ getOrSynthesizeTangentVectorStruct(DerivedConformance &derived, Identifier id) {
624613
// call to the getter.
625614
if (member->getEffectiveAccess() > AccessLevel::Internal &&
626615
!member->getAttrs().hasAttribute<DifferentiableAttr>()) {
627-
if (!member->getSynthesizedAccessor(AccessorKind::Get)
628-
->hasInterfaceType())
629-
TC.resolveDeclSignature(member->getAccessor(AccessorKind::Get));
616+
(void)member->getAccessor(AccessorKind::Get)->getInterfaceType();
630617
// If member or its getter already has a `@differentiable` attribute,
631618
// continue.
632619
if (member->getAttrs().hasAttribute<DifferentiableAttr>() ||
@@ -699,7 +686,6 @@ static void addAssociatedTypeAliasDecl(Identifier name,
699686
aliasDecl->setGenericSignature(sourceDC->getGenericSignatureOfContext());
700687
cast<IterableDeclContext>(sourceDC->getAsDecl())->addMember(aliasDecl);
701688
aliasDecl->copyFormalAccessFrom(nominal, /*sourceIsParentContext*/ true);
702-
TC.validateDecl(aliasDecl);
703689
C.addSynthesizedDecl(aliasDecl);
704690
};
705691

@@ -716,9 +702,7 @@ static void checkAndDiagnoseImplicitNoDerivative(TypeChecker &TC,
716702
bool nominalCanDeriveAdditiveArithmetic =
717703
DerivedConformance::canDeriveAdditiveArithmetic(nominal, DC);
718704
for (auto *vd : nominal->getStoredProperties()) {
719-
if (!vd->hasInterfaceType())
720-
TC.resolveDeclSignature(vd);
721-
if (!vd->hasInterfaceType())
705+
if (vd->getInterfaceType()->hasError())
722706
continue;
723707
auto varType = DC->mapTypeIntoContext(vd->getValueInterfaceType());
724708
if (vd->getAttrs().hasAttribute<NoDerivativeAttr>())
@@ -773,7 +757,6 @@ getOrSynthesizeTangentVectorStructType(DerivedConformance &derived) {
773757
// Add `TangentVector` typealias for `TangentVector` struct.
774758
addAssociatedTypeAliasDecl(C.Id_TangentVector,
775759
tangentStruct, tangentStruct, TC);
776-
TC.validateDecl(tangentStruct);
777760

778761
// Sanity checks for synthesized struct.
779762
assert(DerivedConformance::canDeriveAdditiveArithmetic(tangentStruct,
@@ -844,7 +827,6 @@ deriveDifferentiable_TangentVectorStruct(DerivedConformance &derived) {
844827
aliasDecl->setUnderlyingType(selfType);
845828
aliasDecl->setImplicit();
846829
aliasDecl->copyFormalAccessFrom(nominal, /*sourceIsParentContext*/ true);
847-
TC.validateDecl(aliasDecl);
848830
derived.addMembersToConformanceContext({aliasDecl});
849831
C.addSynthesizedDecl(aliasDecl);
850832
return selfType;

lib/Sema/DerivedConformanceElementaryFunctions.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ bool DerivedConformance::canDeriveElementaryFunctions(NominalTypeDecl *nominal,
129129
auto &C = nominal->getASTContext();
130130
auto *mathProto = C.getProtocol(KnownProtocolKind::ElementaryFunctions);
131131
return llvm::all_of(structDecl->getStoredProperties(), [&](VarDecl *v) {
132-
if (!v->hasInterfaceType())
133-
C.getLazyResolver()->resolveDeclSignature(v);
134-
if (!v->hasInterfaceType())
132+
if (v->getInterfaceType()->hasError())
135133
return false;
136134
auto varType = DC->mapTypeIntoContext(v->getValueInterfaceType());
137135
return (bool)TypeChecker::conformsToProtocol(varType, mathProto, DC, None);
@@ -302,7 +300,6 @@ ElementaryFunction op) {
302300
#undef ELEMENTARY_FUNCTION
303301
}
304302
operatorDecl->setGenericSignature(parentDC->getGenericSignatureOfContext());
305-
operatorDecl->computeType();
306303
operatorDecl->copyFormalAccessFrom(nominal, /*sourceIsParentContext*/ true);
307304

308305
derived.addMembersToConformanceContext({operatorDecl});

lib/Sema/DerivedConformanceRingMathProtocols.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ static bool canDeriveRingProtocol(KnownProtocolKind knownProtoKind,
113113
auto &C = nominal->getASTContext();
114114
auto *proto = C.getProtocol(knownProtoKind);
115115
return llvm::all_of(structDecl->getStoredProperties(), [&](VarDecl *v) {
116-
if (!v->hasInterfaceType())
117-
C.getLazyResolver()->resolveDeclSignature(v);
118-
if (!v->hasInterfaceType())
116+
if (v->getInterfaceType()->hasError())
119117
return false;
120118
auto varType = DC->mapTypeIntoContext(v->getValueInterfaceType());
121119
return (bool)TypeChecker::conformsToProtocol(varType, proto, DC, None);
@@ -255,7 +253,6 @@ static ValueDecl *deriveMathOperator(DerivedConformance &derived,
255253
};
256254
operatorDecl->setBodySynthesizer(bodySynthesizer, (void *) op);
257255
operatorDecl->setGenericSignature(parentDC->getGenericSignatureOfContext());
258-
operatorDecl->computeType();
259256
operatorDecl->copyFormalAccessFrom(nominal, /*sourceIsParentContext*/ true);
260257

261258
derived.addMembersToConformanceContext({operatorDecl});

lib/Sema/DerivedConformanceTensorArrayProtocol.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ bool DerivedConformance::canDeriveTensorArrayProtocol(NominalTypeDecl *nominal,
4141
auto &C = nominal->getASTContext();
4242
auto *tensorGroupProto = C.getProtocol(KnownProtocolKind::TensorGroup);
4343
return llvm::all_of(structDecl->getStoredProperties(), [&](VarDecl *v) {
44-
if (!v->hasInterfaceType())
45-
C.getLazyResolver()->resolveDeclSignature(v);
46-
if (!v->hasInterfaceType())
44+
if (v->getInterfaceType()->hasError())
4745
return false;
4846
auto varType = DC->mapTypeIntoContext(v->getValueInterfaceType());
4947
return (bool)TypeChecker::conformsToProtocol(varType, tensorGroupProto, DC,
@@ -244,7 +242,6 @@ static ValueDecl *deriveTensorArrayProtocol_method(
244242
funcDecl->setBodySynthesizer(bodySynthesizer.Fn, bodySynthesizer.Context);
245243

246244
funcDecl->setGenericSignature(parentDC->getGenericSignatureOfContext());
247-
funcDecl->computeType();
248245
funcDecl->copyFormalAccessFrom(nominal, /*sourceIsParentContext*/ true);
249246

250247
derived.addMembersToConformanceContext({funcDecl});
@@ -645,7 +642,6 @@ static ValueDecl
645642
initDecl->setBodySynthesizer(deriveBodyTensorArrayProtocol_init, nullptr);
646643

647644
initDecl->setGenericSignature(parentDC->getGenericSignatureOfContext());
648-
initDecl->computeType(AnyFunctionType::ExtInfo().withThrows(false));
649645
initDecl->copyFormalAccessFrom(nominal, /*sourceIsParentContext*/ true);
650646

651647
derived.addMembersToConformanceContext({initDecl});

lib/Sema/DerivedConformanceTensorGroup.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ bool DerivedConformance::canDeriveTensorGroup(NominalTypeDecl *nominal,
4141
auto &C = nominal->getASTContext();
4242
auto *tensorGroupProto = C.getProtocol(KnownProtocolKind::TensorGroup);
4343
return llvm::all_of(structDecl->getStoredProperties(), [&](VarDecl *v) {
44-
if (!v->hasInterfaceType())
45-
C.getLazyResolver()->resolveDeclSignature(v);
46-
if (!v->hasInterfaceType())
44+
if (v->getInterfaceType()->hasError())
4745
return false;
4846
auto varType = DC->mapTypeIntoContext(v->getValueInterfaceType());
4947
return (bool)TypeChecker::conformsToProtocol(varType, tensorGroupProto, DC,
@@ -339,7 +337,6 @@ static ValueDecl *deriveTensorGroup_constructor(
339337
initDecl->setBodySynthesizer(bodySynthesizer.Fn, bodySynthesizer.Context);
340338

341339
initDecl->setGenericSignature(parentDC->getGenericSignatureOfContext());
342-
initDecl->computeType(AnyFunctionType::ExtInfo().withThrows(false));
343340
initDecl->copyFormalAccessFrom(nominal, /*sourceIsParentContext*/ true);
344341

345342
derived.addMembersToConformanceContext({initDecl});

0 commit comments

Comments
 (0)