@@ -94,7 +94,7 @@ TypeDecl *ASTBuilder::createTypeDecl(NodePointer node) {
9494 if (proto == nullptr )
9595 return nullptr ;
9696
97- auto name = Ctx. getIdentifier (node->getChild (1 )->getText ());
97+ auto name = getIdentifier (node->getChild (1 )->getText ());
9898 return proto->getAssociatedType (name);
9999 }
100100
@@ -110,10 +110,9 @@ ASTBuilder::createBuiltinType(StringRef builtinName,
110110
111111 StringRef strippedName =
112112 builtinName.drop_front (BUILTIN_TYPE_NAME_PREFIX.size ());
113- Ctx.TheBuiltinModule ->lookupValue (Ctx.getIdentifier (strippedName),
114- NLKind::QualifiedLookup,
115- decls);
116-
113+ Ctx.TheBuiltinModule ->lookupValue (getIdentifier (strippedName),
114+ NLKind::QualifiedLookup, decls);
115+
117116 if (decls.size () == 1 && isa<TypeDecl>(decls[0 ]))
118117 return cast<TypeDecl>(decls[0 ])->getDeclaredInterfaceType ();
119118 }
@@ -348,7 +347,7 @@ Type ASTBuilder::createTupleType(ArrayRef<Type> eltTypes, ArrayRef<StringRef> la
348347 for (unsigned i : indices (eltTypes)) {
349348 Identifier label;
350349 if (!labels[i].empty ())
351- label = Ctx. getIdentifier (labels[i]);
350+ label = getIdentifier (labels[i]);
352351 elements.emplace_back (eltTypes[i], label);
353352 }
354353
@@ -408,7 +407,7 @@ Type ASTBuilder::createFunctionType(
408407 if (!type->isMaterializable ())
409408 return Type ();
410409
411- auto label = Ctx. getIdentifier (param.getLabel ());
410+ auto label = getIdentifier (param.getLabel ());
412411 auto flags = param.getFlags ();
413412 auto ownership =
414413 ParamDecl::getParameterSpecifierForValueOwnership (asValueOwnership (flags.getOwnership ()));
@@ -884,7 +883,7 @@ Type ASTBuilder::createGenericTypeParameterType(unsigned depth,
884883
885884Type ASTBuilder::createDependentMemberType (StringRef member,
886885 Type base) {
887- auto identifier = Ctx. getIdentifier (member);
886+ auto identifier = getIdentifier (member);
888887
889888 if (auto *archetype = base->getAs <ArchetypeType>()) {
890889 if (Type memberType = archetype->getNestedTypeByName (identifier))
@@ -901,7 +900,7 @@ Type ASTBuilder::createDependentMemberType(StringRef member,
901900Type ASTBuilder::createDependentMemberType (StringRef member,
902901 Type base,
903902 ProtocolDecl *protocol) {
904- auto identifier = Ctx. getIdentifier (member);
903+ auto identifier = getIdentifier (member);
905904
906905 if (auto *archetype = base->getAs <ArchetypeType>()) {
907906 if (auto assocType = protocol->getAssociatedType (identifier))
@@ -1141,7 +1140,7 @@ ASTBuilder::getAcceptableTypeDeclCandidate(ValueDecl *decl,
11411140
11421141DeclContext *ASTBuilder::getNotionalDC () {
11431142 if (!NotionalDC) {
1144- NotionalDC = ModuleDecl::createEmpty (Ctx. getIdentifier (" .RemoteAST" ), Ctx);
1143+ NotionalDC = ModuleDecl::createEmpty (getIdentifier (" .RemoteAST" ), Ctx);
11451144 NotionalDC = new (Ctx) TopLevelCodeDecl (NotionalDC);
11461145 }
11471146 return NotionalDC;
@@ -1314,7 +1313,7 @@ ASTBuilder::findDeclContext(NodePointer node) {
13141313 Demangle::Node::Kind::PrivateDeclName) {
13151314 name = declNameNode->getChild (1 )->getText ();
13161315 privateDiscriminator =
1317- Ctx. getIdentifier (declNameNode->getChild (0 )->getText ());
1316+ getIdentifier (declNameNode->getChild (0 )->getText ());
13181317
13191318 } else if (declNameNode->getKind () ==
13201319 Demangle::Node::Kind::RelatedEntityDeclName) {
@@ -1342,14 +1341,14 @@ ASTBuilder::findDeclContext(NodePointer node) {
13421341 return nullptr ;
13431342
13441343 for (auto *module : potentialModules)
1345- if (auto typeDecl = findTypeDecl (module , Ctx. getIdentifier (name),
1344+ if (auto typeDecl = findTypeDecl (module , getIdentifier (name),
13461345 privateDiscriminator, node->getKind ()))
13471346 return typeDecl;
13481347 return nullptr ;
13491348 }
13501349
13511350 if (auto *dc = findDeclContext (child))
1352- if (auto typeDecl = findTypeDecl (dc, Ctx. getIdentifier (name),
1351+ if (auto typeDecl = findTypeDecl (dc, getIdentifier (name),
13531352 privateDiscriminator, node->getKind ()))
13541353 return typeDecl;
13551354
@@ -1548,7 +1547,7 @@ GenericTypeDecl *ASTBuilder::findForeignTypeDecl(StringRef name,
15481547 found);
15491548 break ;
15501549 }
1551- importer->lookupValue (Ctx. getIdentifier (name), consumer);
1550+ importer->lookupValue (getIdentifier (name), consumer);
15521551 if (consumer.Result )
15531552 consumer.Result = getAcceptableTypeDeclCandidate (consumer.Result , kind);
15541553 break ;
@@ -1558,3 +1557,28 @@ GenericTypeDecl *ASTBuilder::findForeignTypeDecl(StringRef name,
15581557
15591558 return consumer.Result ;
15601559}
1560+
1561+ Identifier ASTBuilder::getIdentifier (StringRef name) {
1562+ if (name.size () > 1 && name.front () == ' `' && name.back () == ' `' ) {
1563+ // Raw identifiers have backticks affixed before mangling. We need to
1564+ // remove those before creating the Identifier for the AST, which doesn't
1565+ // encode the backticks.
1566+ std::string fixedName;
1567+ for (size_t i = 1 ; i < name.size () - 1 ; ++i) {
1568+ unsigned char ch = name[i];
1569+ // Raw identifiers have the space (U+0020) replaced with a non-breaking
1570+ // space (U+00A0, UTF-8: 0xC2 0xA0) in their mangling so that parts of
1571+ // the runtime that use space as a delimiter remain compatible with
1572+ // these identifiers. Flip it back.
1573+ if (ch == 0xc2 && i < name.size () - 2 &&
1574+ (unsigned char )name[i + 1 ] == 0xa0 ) {
1575+ fixedName.push_back (' ' );
1576+ ++i;
1577+ } else {
1578+ fixedName.push_back (ch);
1579+ }
1580+ }
1581+ return Ctx.getIdentifier (fixedName);
1582+ }
1583+ return Ctx.getIdentifier (name);
1584+ }
0 commit comments