Rework computation of local discriminators for named entities.

Local discriminators for named entities are currently being set by the
parser, so entities not created by the parser (e.g., that come from
synthesized code) don't get local discriminators. Moreover, there is
no checking to ensure that every named local entity gets a local
discriminator, so some entities would incorrectly get a local
discriminator of 0.

Assign local discriminators as part of setting closure discriminators,
in response to a request asking for the local discriminator, so the
parser does not need to track this information, and all local
declarations---including synthesized ones---get local discriminators.
And add checking to make sure that every entity that needs a local
discriminator gets assigned one.

There are a few interesting cases in here:
* There was a potential mangling collision with local property
wrappers because their generated variables weren't getting local
discriminators
* $interpolation variables introduced for string interpolation weren't
getting local discriminators, they were just wrong.
* "Local rename" when dealing with captures like `[x]` was dependent on
the new delcaration of `x` *not* getting a local discriminator. There
are funny cases involving nesting where it would do the wrong thing.
This commit is contained in:
Doug Gregor
2022-12-21 13:24:46 -08:00
parent 77527c9e41
commit 9e61b01ec1
13 changed files with 230 additions and 50 deletions

View File

@@ -22,6 +22,7 @@
#include "swift/AST/ParseRequests.h"
#include "swift/AST/PrettyStackTrace.h"
#include "swift/AST/SourceFile.h"
#include "swift/AST/TypeCheckRequests.h"
#include "swift/Basic/Defer.h"
#include "swift/Basic/SourceManager.h"
#include "swift/Parse/Lexer.h"
@@ -149,6 +150,10 @@ void Parser::performIDEInspectionSecondPassImpl(
DeclContext *DC = info.ParentContext;
// Forget about the fact that we may have already computed local
// discriminators.
Context.evaluator.clearCachedOutput(LocalDiscriminatorsRequest{DC});
switch (info.Kind) {
case IDEInspectionDelayedDeclKind::TopLevelCodeDecl: {
// Re-enter the top-level code decl context.