Skip to content

Commit 5457290

Browse files
committed
Eliminate "may have storage" hack in PatternBindingEntryRequest.
Remove an early iteration of cycle-breaking in `PatternBindingEntryRequest` that has been subsumed by the lazy computation of `AbstractStorageDecl::hasStorage()`. We can now directly use `hasStorage()` here.
1 parent 1209ef8 commit 5457290

File tree

1 file changed

+1
-36
lines changed

1 file changed

+1
-36
lines changed

lib/Sema/TypeCheckStorage.cpp

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -350,41 +350,6 @@ InitAccessorPropertiesRequest::evaluate(Evaluator &evaluator,
350350
return decl->getASTContext().AllocateCopy(results);
351351
}
352352

353-
/// Check whether the pattern may have storage.
354-
///
355-
/// This query is careful not to trigger accessor macro expansion, which
356-
/// creates a cycle. It conservatively assumes that all accessor macros
357-
/// produce computed properties, which is... incorrect.
358-
///
359-
/// The query also avoids triggering a `StorageImplInfoRequest` for patterns
360-
/// involved in a ProtocolDecl, because we know they can never contain storage.
361-
/// For background, vars of noncopyable type have their OpaqueReadOwnership
362-
/// determined by the type of the var decl, but that type hasn't always been
363-
/// determined when this query is made.
364-
static bool mayHaveStorage(Pattern *pattern) {
365-
// Check whether there are any accessor macros, or it's a protocol member.
366-
bool hasAccessorMacros = false;
367-
bool inProtocolDecl = false;
368-
pattern->forEachVariable([&](VarDecl *VD) {
369-
if (isa<ProtocolDecl>(VD->getDeclContext()))
370-
inProtocolDecl = true;
371-
372-
VD->forEachAttachedMacro(MacroRole::Accessor,
373-
[&](CustomAttr *customAttr, MacroDecl *macro) {
374-
hasAccessorMacros = true;
375-
});
376-
});
377-
378-
if (hasAccessorMacros)
379-
return false;
380-
381-
// protocol members can never contain storage; avoid triggering request.
382-
if (inProtocolDecl)
383-
return false;
384-
385-
return pattern->hasStorage();
386-
}
387-
388353
/// Validate the \c entryNumber'th entry in \c binding.
389354
const PatternBindingEntry *PatternBindingEntryRequest::evaluate(
390355
Evaluator &eval, PatternBindingDecl *binding, unsigned entryNumber,
@@ -485,7 +450,7 @@ const PatternBindingEntry *PatternBindingEntryRequest::evaluate(
485450
// default-initializable. If so, do it.
486451
if (!pbe.isInitialized() &&
487452
binding->isDefaultInitializable(entryNumber) &&
488-
mayHaveStorage(pattern)) {
453+
pattern->hasStorage()) {
489454
if (auto defaultInit = TypeChecker::buildDefaultInitializer(patternType)) {
490455
// If we got a default initializer, install it and re-type-check it
491456
// to make sure it is properly coerced to the pattern type.

0 commit comments

Comments
 (0)