@@ -6830,7 +6830,8 @@ bool SILParserTUState::parseSILDifferentiabilityWitness(Parser &P) {
6830
6830
Scope S (&P, ScopeKind::TopLevel);
6831
6831
Scope Body (&P, ScopeKind::FunctionBody);
6832
6832
6833
- auto parseFunctionNameAndType = [&](SILFunction *&fn) -> bool {
6833
+ // Parse a SIL function name.
6834
+ auto parseFunctionName = [&](SILFunction *&fn) -> bool {
6834
6835
Identifier name;
6835
6836
SILType ty;
6836
6837
SourceLoc fnNameLoc = P.Tok .getLoc ();
@@ -6852,13 +6853,13 @@ bool SILParserTUState::parseSILDifferentiabilityWitness(Parser &P) {
6852
6853
State.TUState .PotentialZombieFns .insert (fn);
6853
6854
return false ;
6854
6855
};
6855
-
6856
- SourceLoc lastLoc = P.getEndOfPreviousLoc ();
6857
-
6856
+ // Parse original function name.
6858
6857
SILFunction *originalFn;
6859
- if (parseFunctionNameAndType (originalFn))
6858
+ if (parseFunctionName (originalFn))
6860
6859
return true ;
6861
6860
6861
+ SourceLoc lastLoc = P.getEndOfPreviousLoc ();
6862
+ // Parse an index subset, prefaced with the given label.
6862
6863
auto parseAutoDiffIndexSubset =
6863
6864
[&](StringRef label, AutoDiffIndexSubset *& paramIndexSubset) -> bool {
6864
6865
if (P.parseSpecificIdentifier (
@@ -6895,15 +6896,17 @@ bool SILParserTUState::parseSILDifferentiabilityWitness(Parser &P) {
6895
6896
P.Context , maxIndexRef ? *maxIndexRef + 1 : 0 , paramIndices);
6896
6897
return false ;
6897
6898
};
6899
+ // Parse parameter and result indices.
6898
6900
AutoDiffIndexSubset *parameterIndices = nullptr ;
6899
6901
AutoDiffIndexSubset *resultIndices = nullptr ;
6900
6902
if (parseAutoDiffIndexSubset (" parameters" , parameterIndices))
6901
6903
return true ;
6902
6904
if (parseAutoDiffIndexSubset (" results" , resultIndices))
6903
6905
return true ;
6904
6906
6907
+ // Parse a trailing 'where' clause (optional).
6908
+ // This represents derivative generic signature requirements.
6905
6909
GenericSignature *derivativeGenSig = nullptr ;
6906
- // Parse a trailing 'where' clause if any.
6907
6910
if (P.Tok .is (tok::kw_where)) {
6908
6911
SourceLoc whereLoc;
6909
6912
SmallVector<RequirementRepr, 4 > requirementReprs;
@@ -6925,34 +6928,36 @@ bool SILParserTUState::parseSILDifferentiabilityWitness(Parser &P) {
6925
6928
nullptr );
6926
6929
}
6927
6930
6931
+ // Parse differentiability witness body.
6928
6932
SILFunction *jvp = nullptr ;
6929
6933
SILFunction *vjp = nullptr ;
6930
6934
if (P.Tok .is (tok::l_brace)) {
6931
- SourceLoc LBraceLoc = P.Tok .getLoc ();
6935
+ // Parse '{'.
6936
+ SourceLoc lBraceLoc = P.Tok .getLoc ();
6932
6937
P.consumeToken (tok::l_brace);
6933
-
6938
+ // Parse JVP (optional).
6934
6939
if (P.Tok .is (tok::identifier) && P.Tok .getText () == " jvp" ) {
6935
6940
P.consumeToken (tok::identifier);
6936
6941
if (P.parseToken (tok::colon, diag::sil_diff_witness_expected_keyword,
6937
6942
" :" ))
6938
6943
return true ;
6939
6944
Scope Body (&P, ScopeKind::FunctionBody);
6940
- if (parseFunctionNameAndType (jvp))
6945
+ if (parseFunctionName (jvp))
6941
6946
return true ;
6942
6947
}
6943
-
6948
+ // Parse VJP (optional).
6944
6949
if (P.Tok .is (tok::identifier) && P.Tok .getText () == " vjp" ) {
6945
6950
P.consumeToken (tok::identifier);
6946
6951
if (P.parseToken (tok::colon, diag::sil_diff_witness_expected_keyword,
6947
6952
" :" ))
6948
6953
return true ;
6949
6954
Scope Body (&P, ScopeKind::FunctionBody);
6950
- if (parseFunctionNameAndType (vjp))
6955
+ if (parseFunctionName (vjp))
6951
6956
return true ;
6952
6957
}
6953
-
6958
+ // Parse '}'.
6954
6959
if (P.parseMatchingToken (tok::r_brace, lastLoc, diag::expected_sil_rbrace,
6955
- LBraceLoc ))
6960
+ lBraceLoc ))
6956
6961
return true ;
6957
6962
}
6958
6963
0 commit comments