Skip to content

Commit e1901fd

Browse files
authored
Replace explicit 'delete' calls with std::unique_ptr in AST (#19366)
1 parent eb450ee commit e1901fd

File tree

4 files changed

+7
-16
lines changed

4 files changed

+7
-16
lines changed

include/swift/AST/Module.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -890,8 +890,6 @@ class SourceFile final : public FileUnit {
890890

891891
friend ASTContext;
892892
friend Impl;
893-
894-
~SourceFile();
895893
public:
896894
/// The list of top-level declarations in the source file.
897895
std::vector<Decl*> Decls;
@@ -1164,7 +1162,7 @@ class SourceFile final : public FileUnit {
11641162
/// If not None, the underlying vector should contain tokens of this source file.
11651163
Optional<std::vector<Token>> AllCorrectedTokens;
11661164

1167-
SourceFileSyntaxInfo &SyntaxInfo;
1165+
std::unique_ptr<SourceFileSyntaxInfo> SyntaxInfo;
11681166
};
11691167

11701168

include/swift/AST/TypeCheckerDebugConsumer.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ class StderrTypeCheckerDebugConsumer : public TypeCheckerDebugConsumer {
3737

3838
/// \brief A base class for a custom consumer of type checker debug output.
3939
class CapturingTypeCheckerDebugConsumer : public TypeCheckerDebugConsumer {
40-
raw_ostream *Log;
40+
std::unique_ptr<raw_ostream> Log;
4141

4242
public:
4343
CapturingTypeCheckerDebugConsumer();
44-
~CapturingTypeCheckerDebugConsumer();
4544

4645
raw_ostream &getStream() override {
4746
return *Log;

lib/AST/ASTContext.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4306,10 +4306,6 @@ CapturingTypeCheckerDebugConsumer::CapturingTypeCheckerDebugConsumer()
43064306
Log->SetUnbuffered();
43074307
}
43084308

4309-
CapturingTypeCheckerDebugConsumer::~CapturingTypeCheckerDebugConsumer() {
4310-
delete Log;
4311-
}
4312-
43134309
void SubstitutionMap::Storage::Profile(
43144310
llvm::FoldingSetNodeID &id,
43154311
GenericSignature *genericSig,

lib/AST/Module.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -774,16 +774,16 @@ struct SourceFile::SourceFileSyntaxInfo {
774774
};
775775

776776
bool SourceFile::hasSyntaxRoot() const {
777-
return SyntaxInfo.SyntaxRoot.hasValue();
777+
return SyntaxInfo->SyntaxRoot.hasValue();
778778
}
779779

780780
syntax::SourceFileSyntax SourceFile::getSyntaxRoot() const {
781781
assert(hasSyntaxRoot() && "no syntax root is set.");
782-
return *SyntaxInfo.SyntaxRoot;
782+
return *SyntaxInfo->SyntaxRoot;
783783
}
784784

785785
void SourceFile::setSyntaxRoot(syntax::SourceFileSyntax &&Root) {
786-
SyntaxInfo.SyntaxRoot.emplace(Root);
786+
SyntaxInfo->SyntaxRoot.emplace(Root);
787787
}
788788

789789
template<typename OP_DECL>
@@ -1431,7 +1431,7 @@ SourceFile::SourceFile(ModuleDecl &M, SourceFileKind K,
14311431
bool KeepParsedTokens, bool BuildSyntaxTree)
14321432
: FileUnit(FileUnitKind::Source, M),
14331433
BufferID(bufferID ? *bufferID : -1),
1434-
Kind(K), SyntaxInfo(*new SourceFileSyntaxInfo(BuildSyntaxTree)) {
1434+
Kind(K), SyntaxInfo(new SourceFileSyntaxInfo(BuildSyntaxTree)) {
14351435
M.getASTContext().addDestructorCleanup(*this);
14361436
performAutoImport(*this, ModImpKind);
14371437

@@ -1445,8 +1445,6 @@ SourceFile::SourceFile(ModuleDecl &M, SourceFileKind K,
14451445
}
14461446
}
14471447

1448-
SourceFile::~SourceFile() { delete &SyntaxInfo; }
1449-
14501448
std::vector<Token> &SourceFile::getTokenVector() {
14511449
assert(shouldCollectToken() && "Disabled");
14521450
return *AllCorrectedTokens;
@@ -1475,7 +1473,7 @@ bool SourceFile::shouldBuildSyntaxTree() const {
14751473
case SourceFileKind::Library:
14761474
case SourceFileKind::Main:
14771475
case SourceFileKind::Interface:
1478-
return SyntaxInfo.Enable;
1476+
return SyntaxInfo->Enable;
14791477
case SourceFileKind::REPL:
14801478
case SourceFileKind::SIL:
14811479
return false;

0 commit comments

Comments
 (0)