@@ -127,12 +127,6 @@ bool IsDefaultActorRequest::evaluate(
127127 return true ;
128128}
129129
130- static bool isDeclNotAsAccessibleAsParent (ValueDecl *decl,
131- NominalTypeDecl *parent) {
132- return decl->getFormalAccess () <
133- std::min (parent->getFormalAccess (), AccessLevel::Public);
134- }
135-
136130VarDecl *GlobalActorInstanceRequest::evaluate (
137131 Evaluator &evaluator, NominalTypeDecl *nominal) const {
138132 auto globalActorAttr = nominal->getAttrs ().getAttribute <GlobalActorAttr>();
@@ -147,106 +141,18 @@ VarDecl *GlobalActorInstanceRequest::evaluate(
147141 return nullptr ;
148142 }
149143
150- auto *module = nominal->getParentModule ();
151-
152144 // Global actors have a static property "shared" that provides an actor
153145 // instance. The value must
154146 SmallVector<ValueDecl *, 4 > decls;
155147 nominal->lookupQualified (
156148 nominal, DeclNameRef (ctx.Id_shared ), NL_QualifiedDefault, decls);
157- VarDecl *sharedVar = nullptr ;
158- llvm::TinyPtrVector<VarDecl *> candidates;
159149 for (auto decl : decls) {
160150 auto var = dyn_cast<VarDecl>(decl);
161151 if (!var)
162152 continue ;
163153
164- auto varDC = var->getDeclContext ();
165- if (var->isStatic () &&
166- !isDeclNotAsAccessibleAsParent (var, nominal) &&
167- !(isa<ExtensionDecl>(varDC) &&
168- cast<ExtensionDecl>(varDC)->isConstrainedExtension ()) &&
169- TypeChecker::conformsToProtocol (
170- varDC->mapTypeIntoContext (var->getValueInterfaceType ()),
171- actorProto, module )) {
172- sharedVar = var;
173- break ;
174- }
175-
176- candidates.push_back (var);
177- }
178-
179- // If we found a suitable candidate, we're done.
180- if (sharedVar)
181- return sharedVar;
182-
183- // Complain about the lack of a suitable 'shared' property.
184- {
185- auto primaryDiag = nominal->diagnose (
186- diag::global_actor_missing_shared, nominal->getName ());
187-
188- // If there were no candidates, provide a Fix-It with a prototype.
189- if (candidates.empty () && nominal->getBraces ().Start .isValid ()) {
190- // Figure out the indentation we need.
191- SourceLoc sharedInsertionLoc = Lexer::getLocForEndOfToken (
192- ctx.SourceMgr , nominal->getBraces ().Start );
193-
194- StringRef extraIndent;
195- StringRef currentIndent = Lexer::getIndentationForLine (
196- ctx.SourceMgr , sharedInsertionLoc, &extraIndent);
197- std::string stubIndent = (currentIndent + extraIndent).str ();
198-
199- // From the string to add the declaration.
200- std::string sharedDeclString = " \n " + stubIndent;
201- if (nominal->getFormalAccess () >= AccessLevel::Public)
202- sharedDeclString += " public " ;
203-
204- sharedDeclString += " static let shared = <#actor instance#>" ;
205-
206- primaryDiag.fixItInsert (sharedInsertionLoc, sharedDeclString);
207- }
208- }
209-
210- // Remark about all of the candidates that failed (and why).
211- for (auto candidate : candidates) {
212- if (!candidate->isStatic ()) {
213- candidate->diagnose (diag::global_actor_shared_not_static)
214- .fixItInsert (candidate->getAttributeInsertionLoc (true ), " static " );
215- continue ;
216- }
217-
218- if (isDeclNotAsAccessibleAsParent (candidate, nominal)) {
219- AccessLevel needAccessLevel = std::min (
220- nominal->getFormalAccess (), AccessLevel::Public);
221- auto diag = candidate->diagnose (
222- diag::global_actor_shared_inaccessible,
223- getAccessLevelSpelling (candidate->getFormalAccess ()),
224- getAccessLevelSpelling (needAccessLevel));
225- if (auto attr = candidate->getAttrs ().getAttribute <AccessControlAttr>()) {
226- if (needAccessLevel == AccessLevel::Internal) {
227- diag.fixItRemove (attr->getRange ());
228- } else {
229- diag.fixItReplace (
230- attr->getRange (), getAccessLevelSpelling (needAccessLevel));
231- }
232- } else {
233- diag.fixItInsert (
234- candidate->getAttributeInsertionLoc (true ),
235- getAccessLevelSpelling (needAccessLevel));
236- }
237- continue ;
238- }
239-
240- if (auto ext = dyn_cast<ExtensionDecl>(candidate->getDeclContext ())) {
241- if (ext->isConstrainedExtension ()) {
242- candidate->diagnose (diag::global_actor_shared_constrained_extension);
243- continue ;
244- }
245- }
246-
247- Type varType = candidate->getDeclContext ()->mapTypeIntoContext (
248- candidate->getValueInterfaceType ());
249- candidate->diagnose (diag::global_actor_shared_non_actor_type, varType);
154+ if (var->getDeclContext () == nominal && var->isStatic ())
155+ return var;
250156 }
251157
252158 return nullptr ;
0 commit comments