Skip to content

[DoNotMerge] Test TF-1232 fix. #30845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/swift/AST/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,11 @@ class ModuleDecl : public DeclContext, public TypeDecl {
declaredCrossImports;

std::unique_ptr<SourceLookupCache> Cache;

public:
SourceLookupCache &getSourceLookupCache() const;

private:
/// Tracks the file that will generate the module's entry point, either
/// because it contains a class marked with \@UIApplicationMain
/// or \@NSApplicationMain, or because it is a script file.
Expand Down
8 changes: 1 addition & 7 deletions include/swift/AST/SourceFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,7 @@ class SourceFile final : public FileUnit {
public:
/// Appends the given declaration to the end of the top-level decls list. Do
/// not add any additional uses of this function.
void addTopLevelDecl(Decl *d) {
// Force decl parsing if we haven't already.
(void)getTopLevelDecls();
Decls->push_back(d);
}
void addTopLevelDecl(Decl *d);

/// Prepends a declaration to the top-level decls list.
///
Expand Down Expand Up @@ -394,8 +390,6 @@ class SourceFile final : public FileUnit {
void cacheVisibleDecls(SmallVectorImpl<ValueDecl *> &&globals) const;
const SmallVectorImpl<ValueDecl *> &getCachedVisibleDecls() const;

void addVisibleDecl(ValueDecl *decl);

virtual void lookupValue(DeclName name, NLKind lookupKind,
SmallVectorImpl<ValueDecl*> &result) const override;

Expand Down
21 changes: 18 additions & 3 deletions lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ class swift::SourceLookupCache {
}
};

public:
ValueDeclMap TopLevelValues;

private:
ValueDeclMap ClassMembers;
bool MemberCachePopulated = false;

Expand Down Expand Up @@ -216,6 +219,8 @@ class swift::SourceLookupCache {
DeclName name,
SmallVectorImpl<ValueDecl*> &results);

void addTopLevelDecl(ValueDecl *decl);

SmallVector<ValueDecl *, 0> AllVisibleValues;
};
SourceLookupCache &SourceFile::getCache() const {
Expand Down Expand Up @@ -322,6 +327,10 @@ SourceLookupCache::SourceLookupCache(const ModuleDecl &M) {
}
}

void SourceLookupCache::addTopLevelDecl(ValueDecl *decl) {
TopLevelValues.add(decl);
}

void SourceLookupCache::lookupValue(DeclName Name, NLKind LookupKind,
SmallVectorImpl<ValueDecl*> &Result) {
auto I = TopLevelValues.find(Name);
Expand Down Expand Up @@ -2232,9 +2241,15 @@ SourceFile::getCachedVisibleDecls() const {
return getCache().AllVisibleValues;
}

void SourceFile::addVisibleDecl(ValueDecl *decl) {
Decls->push_back(decl);
getCache().AllVisibleValues.push_back(decl);
void SourceFile::addTopLevelDecl(Decl *d) {
// Force decl parsing if we haven't already.
(void)getTopLevelDecls();
Decls->push_back(d);
// Update caches.
if (auto *valueDecl = dyn_cast<ValueDecl>(d)) {
getCache().TopLevelValues.add(valueDecl);
getParentModule()->getSourceLookupCache().TopLevelValues.add(valueDecl);
}
}

static void performAutoImport(
Expand Down
4 changes: 2 additions & 2 deletions lib/SILOptimizer/Utils/Differentiation/LinearMapInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ EnumDecl *LinearMapInfo::createBranchingTraceDecl(
computeAccessLevel(branchingTraceDecl, original->getEffectiveSymbolLinkage());
branchingTraceDecl->getInterfaceType();
assert(branchingTraceDecl->hasInterfaceType());
file.addVisibleDecl(branchingTraceDecl);
file.addTopLevelDecl(branchingTraceDecl);
// Add basic block enum cases.
for (auto *predBB : originalBB->getPredecessorBlocks()) {
auto bbId = "bb" + std::to_string(predBB->getDebugID());
Expand Down Expand Up @@ -233,7 +233,7 @@ LinearMapInfo::createLinearMapStruct(SILBasicBlock *originalBB,
computeAccessLevel(linearMapStruct, original->getEffectiveSymbolLinkage());
linearMapStruct->getInterfaceType();
assert(linearMapStruct->hasInterfaceType());
file.addVisibleDecl(linearMapStruct);
file.addTopLevelDecl(linearMapStruct);
return linearMapStruct;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: not %target-build-swift -g %s
// RUN: %target-build-swift -g %s
// REQUIRES: asserts

// TF-1232: IRGenDebugInfo crash due to lack of proper mangling for
Expand Down