@@ -367,10 +367,34 @@ static void writeDeclCommentTable(
367
367
return StringRef (Mem, String.size ());
368
368
}
369
369
370
+ bool shouldSerializeDoc (Decl *D) {
371
+ if (auto *VD = dyn_cast<ValueDecl>(D)) {
372
+ // Skip the decl if it's not visible to clients. The use of
373
+ // getEffectiveAccess is unusual here; we want to take the testability
374
+ // state into account and emit documentation if and only if they are
375
+ // visible to clients (which means public ordinarily, but
376
+ // public+internal when testing enabled).
377
+ if (VD->getEffectiveAccess () < swift::AccessLevel::Public)
378
+ return false ;
379
+ }
380
+
381
+ // When building the stdlib we intend to serialize unusual comments.
382
+ // This situation is represented by GroupContext.isEnable(). In that
383
+ // case, we perform more serialization to keep track of source order.
384
+ if (GroupContext.isEnable ())
385
+ return true ;
386
+
387
+ // Skip the decl if it cannot have a comment.
388
+ if (!D->canHaveComment ())
389
+ return false ;
390
+
391
+ // Skip the decl if it does not have a comment.
392
+ if (D->getRawComment ().Comments .empty ())
393
+ return false ;
394
+ return true ;
395
+ }
396
+
370
397
void writeDocForExtensionDecl (ExtensionDecl *ED) {
371
- RawComment Raw = ED->getRawComment ();
372
- if (Raw.Comments .empty () && !GroupContext.isEnable ())
373
- return ;
374
398
// Compute USR.
375
399
{
376
400
USRBuffer.clear ();
@@ -379,12 +403,14 @@ static void writeDeclCommentTable(
379
403
return ;
380
404
}
381
405
generator.insert (copyString (USRBuffer.str ()),
382
- { ED->getBriefComment (), Raw ,
406
+ { ED->getBriefComment (), ED-> getRawComment () ,
383
407
GroupContext.getGroupSequence (ED),
384
408
SourceOrder++ });
385
409
}
386
410
387
411
bool walkToDeclPre (Decl *D) override {
412
+ if (!shouldSerializeDoc (D))
413
+ return true ;
388
414
if (auto *ED = dyn_cast<ExtensionDecl>(D)) {
389
415
writeDocForExtensionDecl (ED);
390
416
return true ;
@@ -394,29 +420,6 @@ static void writeDeclCommentTable(
394
420
if (!VD)
395
421
return true ;
396
422
397
- RawComment Raw = VD->getRawComment ();
398
- // When building the stdlib we intend to serialize unusual comments.
399
- // This situation is represented by GroupContext.isEnable(). In that
400
- // case, we perform fewer serialization checks.
401
- if (!GroupContext.isEnable ()) {
402
- // Skip the decl if it cannot have a comment.
403
- if (!VD->canHaveComment ()) {
404
- return true ;
405
- }
406
-
407
- // Skip the decl if it does not have a comment.
408
- if (Raw.Comments .empty ())
409
- return true ;
410
-
411
- // Skip the decl if it's not visible to clients. The use of
412
- // getEffectiveAccess is unusual here; we want to take the testability
413
- // state into account and emit documentation if and only if they are
414
- // visible to clients (which means public ordinarily, but
415
- // public+internal when testing enabled).
416
- if (VD->getEffectiveAccess () < swift::AccessLevel::Public)
417
- return true ;
418
- }
419
-
420
423
// Compute USR.
421
424
{
422
425
USRBuffer.clear ();
@@ -426,7 +429,7 @@ static void writeDeclCommentTable(
426
429
}
427
430
428
431
generator.insert (copyString (USRBuffer.str ()),
429
- { VD->getBriefComment (), Raw ,
432
+ { VD->getBriefComment (), D-> getRawComment () ,
430
433
GroupContext.getGroupSequence (VD),
431
434
SourceOrder++ });
432
435
return true ;
0 commit comments