@@ -7857,6 +7857,27 @@ bool SILParserState::parseSILMoveOnlyDeinit(Parser &parser) {
78577857 return false ;
78587858}
78597859
7860+ static ClassDecl *parseClassDecl (Parser &P, SILParser &SP) {
7861+ Identifier DeclName;
7862+ SourceLoc DeclLoc;
7863+ if (SP.parseSILIdentifier (DeclName, DeclLoc, diag::expected_sil_value_name))
7864+ return nullptr ;
7865+
7866+ // Find the protocol decl. The protocol can be imported.
7867+ llvm::PointerUnion<ValueDecl *, ModuleDecl *> Res =
7868+ lookupTopDecl (P, DeclName, /* typeLookup=*/ true );
7869+ assert (Res.is <ValueDecl *>() && " Protocol look-up should return a Decl" );
7870+ ValueDecl *VD = Res.get <ValueDecl *>();
7871+ if (!VD) {
7872+ P.diagnose (DeclLoc, diag::sil_default_override_class_not_found, DeclName);
7873+ return nullptr ;
7874+ }
7875+ auto *decl = dyn_cast<ClassDecl>(VD);
7876+ if (!decl)
7877+ P.diagnose (DeclLoc, diag::sil_default_override_decl_not_class, DeclName);
7878+ return decl;
7879+ }
7880+
78607881static ProtocolDecl *parseProtocolDecl (Parser &P, SILParser &SP) {
78617882 Identifier DeclName;
78627883 SourceLoc DeclLoc;
@@ -8444,6 +8465,100 @@ bool SILParserState::parseSILDefaultWitnessTable(Parser &P) {
84448465 return false ;
84458466}
84468467
8468+ // / Parser a single SIL default override table entry and add it to \p entries.
8469+ // / sil-default-override-entry:
8470+ // / SILDeclRef ':' SILDeclRef ':' @SILFunctionName
8471+ static bool parseSILDefaultOverrideTableEntry (
8472+ Parser &P, SILModule &M, ClassDecl *proto, GenericSignature witnessSig,
8473+ GenericParamList *witnessParams, SILParser &parser,
8474+ std::vector<SILDefaultOverrideTable::Entry> &entries) {
8475+ Identifier EntryKeyword;
8476+ SourceLoc KeywordLoc;
8477+
8478+ SILDeclRef replacement;
8479+ if (parser.parseSILDeclRef (replacement, true ) ||
8480+ P.parseToken (tok::colon, diag::expected_sil_witness_colon))
8481+ return true ;
8482+
8483+ SILDeclRef original;
8484+ if (parser.parseSILDeclRef (original, true ) ||
8485+ P.parseToken (tok::colon, diag::expected_sil_witness_colon))
8486+ return true ;
8487+
8488+ SILFunction *impl = nullptr ;
8489+ Identifier implName;
8490+ SourceLoc implLoc;
8491+ if (P.parseToken (tok::at_sign, diag::expected_sil_function_name) ||
8492+ parser.parseSILIdentifier (implName, implLoc,
8493+ diag::expected_sil_value_name))
8494+ return true ;
8495+
8496+ impl = M.lookUpFunction (implName.str ());
8497+ if (!impl) {
8498+ P.diagnose (implLoc, diag::sil_default_override_func_not_found, implName);
8499+ return true ;
8500+ }
8501+
8502+ entries.push_back (
8503+ SILDefaultOverrideTable::Entry{replacement, original, impl});
8504+
8505+ return false ;
8506+ }
8507+
8508+ // / decl-sil-default-override ::= 'sil_default_override_table'
8509+ // / sil-linkage identifier
8510+ // / decl-sil-default-override-body
8511+ // / decl-sil-default-override-body:
8512+ // / '{' sil-default-override-entry* '}'
8513+ // / sil-default-override-entry:
8514+ // / SILDeclRef ':' SILDeclRef ':' @SILFunctionName
8515+ bool SILParserState::parseSILDefaultOverrideTable (Parser &P) {
8516+ P.consumeToken (tok::kw_sil_default_override_table);
8517+ SILParser OverrideState (P);
8518+
8519+ // Parse the linkage.
8520+ std::optional<SILLinkage> Linkage;
8521+ parseSILLinkage (Linkage, P);
8522+
8523+ // Parse the class.
8524+ ClassDecl *decl = parseClassDecl (P, OverrideState);
8525+ if (!decl)
8526+ return true ;
8527+
8528+ OverrideState.ContextGenericSig = decl->getGenericSignature ();
8529+ OverrideState.ContextGenericParams = decl->getGenericParams ();
8530+
8531+ // Parse the body.
8532+ SourceLoc LBraceLoc = P.Tok .getLoc ();
8533+ P.consumeToken (tok::l_brace);
8534+
8535+ // We need to turn on InSILBody to parse SILDeclRef.
8536+ Lexer::SILBodyRAII Tmp (*P.L );
8537+
8538+ // Parse the entry list.
8539+ std::vector<SILDefaultOverrideTable::Entry> entries;
8540+
8541+ if (P.Tok .isNot (tok::r_brace)) {
8542+ do {
8543+ if (parseSILDefaultOverrideTableEntry (
8544+ P, M, decl, decl->getGenericSignature (), decl->getGenericParams (),
8545+ OverrideState, entries))
8546+ return true ;
8547+ } while (P.Tok .isNot (tok::r_brace) && P.Tok .isNot (tok::eof));
8548+ }
8549+
8550+ SourceLoc RBraceLoc;
8551+ P.parseMatchingToken (tok::r_brace, RBraceLoc, diag::expected_sil_rbrace,
8552+ LBraceLoc);
8553+
8554+ // Default to public linkage.
8555+ if (!Linkage)
8556+ Linkage = SILLinkage::Public;
8557+
8558+ SILDefaultOverrideTable::define (M, *Linkage, decl, entries);
8559+ return false ;
8560+ }
8561+
84478562// / decl-sil-differentiability-witness ::=
84488563// / 'sil_differentiability_witness'
84498564// / ('[' 'serialized' ']')?
0 commit comments