@@ -985,6 +985,33 @@ void PrintAST::printTypedPattern(const TypedPattern *TP) {
985
985
printTypeLoc (TP->getTypeLoc ());
986
986
}
987
987
988
+ // / Determines if we are required to print the name of a property declaration,
989
+ // / or if we can elide it by printing a '_' instead.
990
+ static bool mustPrintPropertyName (VarDecl *decl, PrintOptions opts) {
991
+ // If we're not allowed to omit the name, we must print it.
992
+ if (!opts.OmitNameOfInaccessibleProperties ) return true ;
993
+
994
+ // If it contributes to the parent's storage, we must print it because clients
995
+ // need to be able to directly access the storage.
996
+ // FIXME: We might be able to avoid printing names for some of these
997
+ // if we serialized references to them using field indices.
998
+ if (contributesToParentTypeStorage (decl)) return true ;
999
+
1000
+ // If it's public or @usableFromInline, we must print the name because it's a
1001
+ // visible entry-point.
1002
+ if (isPublicOrUsableFromInline (decl)) return true ;
1003
+
1004
+ // If it has an initial value, we must print the name because it's used in
1005
+ // the mangled name of the initializer expression generator function.
1006
+ // FIXME: We _could_ figure out a way to generate an entry point
1007
+ // for the initializer expression without revealing the name. We just
1008
+ // don't have a mangling for it.
1009
+ if (decl->hasInitialValue ()) return true ;
1010
+
1011
+ // If none of those are true, we can elide the name of the variable.
1012
+ return false ;
1013
+ }
1014
+
988
1015
void PrintAST::printPattern (const Pattern *pattern) {
989
1016
switch (pattern->getKind ()) {
990
1017
case PatternKind::Any:
@@ -995,16 +1022,13 @@ void PrintAST::printPattern(const Pattern *pattern) {
995
1022
auto named = cast<NamedPattern>(pattern);
996
1023
auto decl = named->getDecl ();
997
1024
recordDeclLoc (decl, [&]{
998
- if (Options.OmitNameOfInaccessibleProperties &&
999
- contributesToParentTypeStorage (decl) &&
1000
- !isPublicOrUsableFromInline (decl) &&
1001
- // FIXME: We need to figure out a way to generate an entry point
1002
- // for the initializer expression without revealing the name.
1003
- !decl->hasInitialValue ())
1004
- Printer << " _" ;
1005
- else
1025
+ // FIXME: This always returns true now, because of the FIXMEs listed in
1026
+ // mustPrintPropertyName.
1027
+ if (mustPrintPropertyName (decl, Options))
1006
1028
Printer.printName (named->getBoundName ());
1007
- });
1029
+ else
1030
+ Printer << " _" ;
1031
+ });
1008
1032
break ;
1009
1033
}
1010
1034
0 commit comments