Skip to content

Commit fa4435f

Browse files
authored
Making checked-c-convert into a library (#837)
This large change adds support for existential struct types to Checked C. These can be used to replace uses of void pointers in callbacks, abstract data types, and closures. There is a corresponding commit of tests for existential types to the Checked C repo. This changes adds IR support, parsing support, semantic checking/typechecking support, and code generation support. Serialization/deserialization support still needs to be implemented. There are also a number of cleanups to do, which are documented in GitHub issues. There are three parts to the change: - Support for existential types. - The pack operation. - The unpack operation, which is done as a declaration with an initializer. Merged on behalf of Machiry Aravind Kumar (@Machiry)
1 parent a8ffb13 commit fa4435f

File tree

131 files changed

+871
-10310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+871
-10310
lines changed

clang-tools-extra/clangd/CConvertCommands.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CLANGD_CCONVERTCOMMANDS_H
1414

1515
#include "Protocol.h"
16-
#include "cconvert/CConvInteractive.h"
16+
#include "clang/CConv/CConv.h"
1717

1818
namespace clang {
1919
namespace clangd {

clang-tools-extra/clangd/CConvertDiagnostics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include <set>
1616
#include "Diagnostics.h"
17-
#include "cconvert/CConvInteractive.h"
17+
#include "clang/CConv/CConv.h"
1818

1919
namespace clang {
2020
namespace clangd {

clang-tools-extra/clangd/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ add_clang_library(cconvClangDaemon
210210
refactor/Tweak.cpp
211211

212212
LINK_LIBS
213+
CConv
213214
clangAST
214215
clangASTMatchers
215216
clangBasic
@@ -254,7 +255,6 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
254255
# FIXME: Make fuzzer not use linux-specific APIs, build it everywhere.
255256
add_subdirectory(fuzzer)
256257
endif()
257-
add_subdirectory(cconvert)
258258
add_subdirectory(tool)
259259
add_subdirectory(indexer)
260260
add_subdirectory(index/dex/dexp)

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,13 @@ void ClangdLSPServer::ccConvResultsReady(std::string FileName,
548548
this->onDiagnosticsReady(FileName, Diagnostics);
549549
}
550550

551-
void ClangdLSPServer::sendCConvMessage(std::string msg) {\
551+
void ClangdLSPServer::sendCConvMessage(std::string MsgStr) {
552552
// Send message as info to the client.
553553
notify("window/showMessage",
554554
llvm::json::Object{
555555
// Info message.
556556
{"type", 3},
557-
{"message", std::move(msg)},
557+
{"message", std::move(MsgStr)},
558558
});
559559
}
560560
#endif

clang-tools-extra/clangd/ClangdLSPServer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "Protocol.h"
1919
#include "Transport.h"
2020
#ifdef INTERACTIVECCCONV
21-
#include "cconvert/CConvInteractive.h"
21+
#include "clang/CConv/CConv.h"
2222
#endif
2323
#include "clang/Tooling/Core/Replacement.h"
2424
#include "llvm/ADT/Optional.h"
@@ -64,7 +64,7 @@ class ClangdLSPServer : private DiagnosticsConsumer {
6464

6565
#ifdef INTERACTIVECCCONV
6666
void ccConvResultsReady(std::string FileName, bool ClearDiags = false) override;
67-
void sendCConvMessage(std::string msg) override;
67+
void sendCConvMessage(std::string MsgStr) override;
6868
#endif
6969

7070
private:

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "refactor/Rename.h"
2525
#include "refactor/Tweak.h"
2626
#ifdef INTERACTIVECCCONV
27-
#include "cconvert/CConvInteractive.h"
27+
#include "clang/CConv/CConv.h"
2828
#include "CConvertCommands.h"
2929
#endif
3030
#include "clang/Format/Format.h"
@@ -170,34 +170,36 @@ void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents,
170170
}
171171

172172
#ifdef INTERACTIVECCCONV
173-
void ClangdServer::reportCConvDiagsForAllFiles(DisjointSet &ccInfo,
173+
void ClangdServer::reportCConvDiagsForAllFiles(DisjointSet &CcInfo,
174174
CConvLSPCallBack *ConvCB) {
175175
// Update the diag information for all the valid files.
176-
for (auto &srcFileDiags : CConvDiagInfo.GetAllFilesDiagnostics()) {
177-
ConvCB->ccConvResultsReady(srcFileDiags.first);
176+
for (auto &SrcFileDiags : CConvDiagInfo.GetAllFilesDiagnostics()) {
177+
ConvCB->ccConvResultsReady(SrcFileDiags.first);
178178
}
179179
}
180180

181-
void ClangdServer::clearCConvDiagsForAllFiles(DisjointSet &ccInfo,
181+
void ClangdServer::clearCConvDiagsForAllFiles(DisjointSet &CcInfo,
182182
CConvLSPCallBack *ConvCB) {
183-
for (auto &srcFileDiags : CConvDiagInfo.GetAllFilesDiagnostics()) {
183+
for (auto &SrcFileDiags : CConvDiagInfo.GetAllFilesDiagnostics()) {
184184
// Clear diags for all files.
185-
ConvCB->ccConvResultsReady(srcFileDiags.first, true);
185+
ConvCB->ccConvResultsReady(SrcFileDiags.first, true);
186186
}
187187
}
188188

189-
void ClangdServer::cconvCollectAndBuildInitialConstraints(CConvLSPCallBack *ConvCB) {
189+
void
190+
ClangdServer::cconvCollectAndBuildInitialConstraints(CConvLSPCallBack *ConvCB) {
190191
auto Task = [=]() {
191192
CConvDiagInfo.ClearAllDiags();
192193
ConvCB->sendCConvMessage("Running CConv for first time.");
193194
CConvInter.BuildInitialConstraints();
195+
CConvInter.SolveConstraints();
194196
ConvCB->sendCConvMessage("Finished running CConv.");
195197
log("CConv: Built initial constraints successfully.\n");
196-
auto &ccInterfaceInfo = CConvInter.GetWILDPtrsInfo();
198+
auto &WildPtrsInfo = CConvInter.GetWILDPtrsInfo();
197199
log("CConv: Got WILD Ptrs Info.\n");
198-
CConvDiagInfo.PopulateDiagsFromDisjointSet(ccInterfaceInfo);
200+
CConvDiagInfo.PopulateDiagsFromDisjointSet(WildPtrsInfo);
199201
log("CConv: Populated Diags from Disjoint Sets.\n");
200-
reportCConvDiagsForAllFiles(ccInterfaceInfo, ConvCB);
202+
reportCConvDiagsForAllFiles(WildPtrsInfo, ConvCB);
201203
ConvCB->sendCConvMessage("CConv: Finished updating problems.");
202204
log("CConv: Updated the diag information.\n");
203205
};
@@ -207,37 +209,40 @@ void ClangdServer::cconvCollectAndBuildInitialConstraints(CConvLSPCallBack *Conv
207209
void ClangdServer::executeCConvCommand(ExecuteCommandParams Params,
208210
CConvLSPCallBack *ConvCB) {
209211
auto Task = [this, Params, ConvCB]() {
210-
std::string replyMessage;
211-
auto &wildPtrInfo = CConvInter.GetWILDPtrsInfo();
212-
auto &ptrSourceMap = wildPtrInfo.PtrSourceMap;
213-
if (ptrSourceMap.find(Params.ccConvertManualFix->ptrID) != ptrSourceMap.end()) {
214-
std::string ptrFileName = ptrSourceMap[Params.ccConvertManualFix->ptrID]->getFileName();
215-
log("CConv: File of the pointer {0}\n", ptrFileName);
216-
clearCConvDiagsForAllFiles(wildPtrInfo, ConvCB);
212+
std::string RplMsg;
213+
auto &WildPtrsInfo = CConvInter.GetWILDPtrsInfo();
214+
auto &PtrSourceMap = WildPtrsInfo.PtrSourceMap;
215+
if (PtrSourceMap.find(Params.ccConvertManualFix->ptrID) !=
216+
PtrSourceMap.end()) {
217+
std::string PtrFileName =
218+
PtrSourceMap[Params.ccConvertManualFix->ptrID]->getFileName();
219+
log("CConv: File of the pointer {0}\n", PtrFileName);
220+
clearCConvDiagsForAllFiles(WildPtrsInfo, ConvCB);
217221
ConvCB->sendCConvMessage("CConv modifying constraints.");
218-
ExecuteCCCommand(Params, replyMessage, CConvInter);
222+
ExecuteCCCommand(Params, RplMsg, CConvInter);
219223
this->CConvDiagInfo.ClearAllDiags();
220-
auto &ccInterfaceInfo = wildPtrInfo;
221-
ConvCB->sendCConvMessage("CConv Updating new issues after editing constraints.");
222-
this->CConvDiagInfo.PopulateDiagsFromDisjointSet(ccInterfaceInfo);
224+
ConvCB->sendCConvMessage("CConv Updating new issues "
225+
"after editing constraints.");
226+
this->CConvDiagInfo.PopulateDiagsFromDisjointSet(WildPtrsInfo);
223227
log("CConv calling call-back\n");
224228
// ConvCB->ccConvResultsReady(ptrFileName);
225229
ConvCB->sendCConvMessage("CConv Updated new issues.");
226-
reportCConvDiagsForAllFiles(ccInterfaceInfo, ConvCB);
230+
reportCConvDiagsForAllFiles(WildPtrsInfo, ConvCB);
227231
} else {
228232
ConvCB->sendCConvMessage("CConv contraint key already removed.");
229233
}
230234
};
231235
WorkScheduler.run("Applying on demand ptr modifications", Task);
232236
}
233237

234-
void ClangdServer::cconvCloseDocument(std::string file) {
238+
void ClangdServer::cconvCloseDocument(std::string FileName) {
235239
auto Task = [=]() {
236-
log("CConv: Trying to write back file: {0}\n", file);
237-
if (CConvInter.WriteConvertedFileToDisk(file)) {
238-
log("CConv: Finished writing back file: {0}\n", file);
240+
log("CConv: Trying to write back file: {0}\n", FileName);
241+
if (CConvInter.WriteConvertedFileToDisk(FileName)) {
242+
log("CConv: Finished writing back file: {0}\n", FileName);
239243
} else {
240-
log("CConv: File not included during constraint solving phase. Rewriting failed: {0}\n", file);
244+
log("CConv: File not included during constraint solving phase. "
245+
"Rewriting failed: {0}\n", FileName);
241246
}
242247
};
243248
WorkScheduler.run("CConv: Writing back file.", Task);

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ class DiagnosticsConsumer {
6363
#ifdef INTERACTIVECCCONV
6464
class CConvLSPCallBack {
6565
public:
66-
virtual void ccConvResultsReady(std::string targetFileName, bool clearDiags = false) = 0;
67-
virtual void sendCConvMessage(std::string msg) = 0;
66+
virtual void ccConvResultsReady(std::string FileName,
67+
bool ClearDiags = false) = 0;
68+
virtual void sendCConvMessage(std::string MsgStr) = 0;
6869
};
6970
#endif
7071

@@ -316,7 +317,7 @@ class ClangdServer {
316317

317318
CConvertDiagnostics CConvDiagInfo;
318319

319-
void cconvCloseDocument(std::string file);
320+
void cconvCloseDocument(std::string FileName);
320321
#endif
321322

322323
private:
@@ -327,8 +328,8 @@ class ClangdServer {
327328
ArrayRef<tooling::Range> Ranges);
328329

329330
#ifdef INTERACTIVECCCONV
330-
void reportCConvDiagsForAllFiles(DisjointSet &ccInfo, CConvLSPCallBack *ConvCB);
331-
void clearCConvDiagsForAllFiles(DisjointSet &ccInfo, CConvLSPCallBack *ConvCB);
331+
void reportCConvDiagsForAllFiles(DisjointSet &CcInfo, CConvLSPCallBack *ConvCB);
332+
void clearCConvDiagsForAllFiles(DisjointSet &CcInfo, CConvLSPCallBack *ConvCB);
332333
#endif
333334

334335
const FileSystemProvider &FSProvider;

0 commit comments

Comments
 (0)