@@ -675,7 +675,7 @@ static bool parseDeclSILOptional(
675675 UseStackForPackMetadata_t *useStackForPackMetadata,
676676 bool *hasUnsafeNonEscapableResult, IsExactSelfClass_t *isExactSelfClass,
677677 SILFunction **dynamicallyReplacedFunction,
678- Identifier *objCReplacementFor,
678+ SILFunction **usedAdHocRequirementWitness, Identifier *objCReplacementFor,
679679 SILFunction::Purpose *specialPurpose, Inline_t *inlineStrategy,
680680 OptimizationMode *optimizationMode, PerformanceConstraints *perfConstraints,
681681 bool *isPerformanceConstraint,
@@ -825,6 +825,26 @@ static bool parseDeclSILOptional(
825825 *dynamicallyReplacedFunction = Func;
826826 SP.P .consumeToken (tok::string_literal);
827827
828+ SP.P .parseToken (tok::r_square, diag::expected_in_attribute_list);
829+ continue ;
830+ } else if (usedAdHocRequirementWitness && SP.P .Tok .getText () == " ref_adhoc_requirement_witness" ) {
831+ SP.P .consumeToken (tok::identifier);
832+ if (SP.P .Tok .getKind () != tok::string_literal) {
833+ SP.P .diagnose (SP.P .Tok , diag::expected_in_attribute_list);
834+ return true ;
835+ }
836+ // Drop the double quotes.
837+ StringRef witnessFunc = SP.P .Tok .getText ().drop_front ().drop_back ();
838+ SILFunction *Func = M.lookUpFunction (witnessFunc.str ());
839+ if (!Func) {
840+ Identifier Id = SP.P .Context .getIdentifier (witnessFunc);
841+ SP.P .diagnose (SP.P .Tok , diag::sil_adhoc_requirement_witness_func_not_found,
842+ Id);
843+ return true ;
844+ }
845+ *usedAdHocRequirementWitness = Func;
846+ SP.P .consumeToken (tok::string_literal);
847+
828848 SP.P .parseToken (tok::r_square, diag::expected_in_attribute_list);
829849 continue ;
830850 } else if (objCReplacementFor &&
@@ -7062,6 +7082,7 @@ bool SILParserState::parseDeclSIL(Parser &P) {
70627082 ValueDecl *ClangDecl = nullptr ;
70637083 EffectsKind MRK = EffectsKind::Unspecified;
70647084 SILFunction *DynamicallyReplacedFunction = nullptr ;
7085+ SILFunction *AdHocWitnessFunction = nullptr ;
70657086 Identifier objCReplacementFor;
70667087 if (parseSILLinkage (FnLinkage, P) ||
70677088 parseDeclSILOptional (
@@ -7070,7 +7091,7 @@ bool SILParserState::parseDeclSIL(Parser &P) {
70707091 &isRuntimeAccessible, &forceEnableLexicalLifetimes,
70717092 &useStackForPackMetadata, &hasUnsafeNonEscapableResult,
70727093 &isExactSelfClass, &DynamicallyReplacedFunction,
7073- &objCReplacementFor, &specialPurpose,
7094+ &AdHocWitnessFunction, & objCReplacementFor, &specialPurpose,
70747095 &inlineStrategy, &optimizationMode, &perfConstr,
70757096 &isPerformanceConstraint, &markedAsUsed,
70767097 §ion, nullptr , &isWeakImported, &needStackProtection,
@@ -7116,6 +7137,8 @@ bool SILParserState::parseDeclSIL(Parser &P) {
71167137 FunctionState.F ->setIsExactSelfClass (isExactSelfClass);
71177138 FunctionState.F ->setDynamicallyReplacedFunction (
71187139 DynamicallyReplacedFunction);
7140+ FunctionState.F ->setReferencedAdHocRequirementWitnessFunction (
7141+ AdHocWitnessFunction);
71197142 if (!objCReplacementFor.empty ())
71207143 FunctionState.F ->setObjCReplacement (objCReplacementFor);
71217144 FunctionState.F ->setSpecialPurpose (specialPurpose);
@@ -7325,7 +7348,7 @@ bool SILParserState::parseSILGlobal(Parser &P) {
73257348 nullptr , nullptr , nullptr , nullptr , nullptr , nullptr ,
73267349 nullptr , nullptr , nullptr , nullptr , nullptr , nullptr ,
73277350 nullptr ,
7328- nullptr , nullptr , nullptr , nullptr , &isLet,
7351+ nullptr , nullptr , nullptr , nullptr , nullptr , &isLet,
73297352 nullptr , nullptr , nullptr , nullptr , nullptr , nullptr ,
73307353 nullptr , nullptr , State, M) ||
73317354 P.parseToken (tok::at_sign, diag::expected_sil_value_name) ||
@@ -7379,7 +7402,7 @@ bool SILParserState::parseSILProperty(Parser &P) {
73797402 nullptr , nullptr , nullptr , nullptr , nullptr , nullptr ,
73807403 nullptr , nullptr , nullptr , nullptr , nullptr , nullptr ,
73817404 nullptr , nullptr , nullptr , nullptr , nullptr , nullptr ,
7382- nullptr , nullptr , SP, M))
7405+ nullptr , nullptr , nullptr , SP, M))
73837406 return true ;
73847407
73857408 ValueDecl *VD;
@@ -7449,7 +7472,7 @@ bool SILParserState::parseSILVTable(Parser &P) {
74497472 nullptr , nullptr , nullptr , nullptr , nullptr , nullptr ,
74507473 nullptr , nullptr , nullptr , nullptr , nullptr , nullptr ,
74517474 nullptr , nullptr , nullptr , nullptr , nullptr , nullptr ,
7452- nullptr , nullptr , VTableState, M))
7475+ nullptr , nullptr , nullptr , VTableState, M))
74537476 return true ;
74547477
74557478
@@ -7572,7 +7595,7 @@ bool SILParserState::parseSILMoveOnlyDeinit(Parser &parser) {
75727595 nullptr , nullptr , nullptr , nullptr , nullptr , nullptr ,
75737596 nullptr , nullptr , nullptr , nullptr , nullptr , nullptr ,
75747597 nullptr , nullptr , nullptr , nullptr , nullptr , nullptr ,
7575- nullptr , nullptr , moveOnlyDeinitTableState, M))
7598+ nullptr , nullptr , nullptr , moveOnlyDeinitTableState, M))
75767599 return true ;
75777600
75787601 // Parse the class name.
@@ -8059,7 +8082,7 @@ bool SILParserState::parseSILWitnessTable(Parser &P) {
80598082 nullptr , nullptr , nullptr , nullptr , nullptr , nullptr ,
80608083 nullptr , nullptr , nullptr , nullptr , nullptr , nullptr ,
80618084 nullptr , nullptr , nullptr , nullptr , nullptr , nullptr ,
8062- nullptr , nullptr , WitnessState, M))
8085+ nullptr , nullptr , nullptr , WitnessState, M))
80638086 return true ;
80648087
80658088 // Parse the protocol conformance.
0 commit comments