Skip to content

Commit d4d9ff6

Browse files
committed
Enable the type checker by default
Signed-off-by: Roberto Raggi <roberto.raggi@gmail.com>
1 parent b654386 commit d4d9ff6

384 files changed

Lines changed: 413 additions & 389 deletions

File tree

Some content is hidden

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

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
for i in src/parser/cxx/*.cc src/lsp/cxx/lsp/*.cc src/frontend/cxx/*.cc; do
3737
echo "Parsing $i"
3838
./build/src/frontend/cxx \
39+
-fno-check \
3940
-I src/parser \
4041
-I src/lsp \
4142
-I build/_deps/utfcpp-src/source \
@@ -52,6 +53,7 @@ jobs:
5253
for i in src/parser/cxx/*.cc src/lsp/cxx/lsp/*.cc src/frontend/cxx/*.cc; do
5354
echo "Parsing $i"
5455
./build/src/frontend/cxx \
56+
-fno-check \
5557
-toolchain linux \
5658
-I src/parser \
5759
-I src/lsp \
@@ -208,6 +210,7 @@ jobs:
208210
for i in src/parser/cxx/*.cc src/lsp/cxx/lsp/*.cc src/frontend/cxx/*.cc; do
209211
echo "Parsing $i"
210212
./build/src/frontend/cxx \
213+
-fno-check \
211214
-toolchain macos \
212215
-I src/parser \
213216
-I src/lsp \

scripts/build-emscripten.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const __dirname = path.dirname(__filename);
99

1010
async function main() {
1111
// configure cmake using the emscripten presets
12-
await $`cmake --preset emscripten`;
12+
await $`cmake --preset emscripten-mlir`;
1313
await $`cmake --build --preset build-emscripten`;
1414

1515
// make sure packages/cxx-frontend/dist/wasm exists

src/frontend/cxx/cxx.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ auto main(int argc, char* argv[]) -> int {
3939
cli.opt_lsp = true;
4040
}
4141

42+
if (cli.opt_fno_check) {
43+
cli.opt_fcheck = false;
44+
cli.opt_fsyntax_only = true;
45+
}
46+
4247
if (!cli.opt_lsp && inputFiles.empty()) {
4348
std::cerr << "cxx: no input files" << std::endl
4449
<< "Usage: cxx [options] file..." << std::endl;

src/frontend/cxx/frontend.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,7 @@ void Frontend::Private::parse() {
524524
}
525525

526526
unit_->parse(ParserConfiguration{
527-
.checkTypes =
528-
cli.opt_fcheck || needsIR() || unit_->language() == LanguageKind::kC,
527+
.checkTypes = cli.opt_fcheck,
529528
.fuzzyTemplateResolution = true,
530529
.allowUnprototypedFunctions = cli.opt_fno_strict_prototypes,
531530
.stopParsingPredicate = [this]() -> bool {

src/js/cxx/api.cc

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
#include <emscripten/val.h>
3333

3434
#include <cstdlib>
35-
#include <format>
36-
#include <iostream>
3735
#include <optional>
3836
#include <sstream>
3937

4038
#ifdef CXX_WITH_MLIR
4139
#include <cxx/mlir/codegen.h>
4240
#include <cxx/mlir/cxx_dialect.h>
41+
#include <cxx/mlir/cxx_dialect_conversions.h>
42+
#include <cxx/wasm32_wasi_toolchain.h>
4343
#include <llvm/Support/raw_os_ostream.h>
4444
#include <mlir/IR/MLIRContext.h>
4545
#endif
@@ -72,6 +72,9 @@ struct WrappedUnit {
7272
std::unique_ptr<DiagnosticsClient> diagnosticsClient;
7373
std::unique_ptr<cxx::TranslationUnit> unit;
7474
val api;
75+
#ifdef CXX_WITH_MLIR
76+
std::unique_ptr<cxx::Toolchain> toolchain_;
77+
#endif
7578

7679
WrappedUnit(std::string source, std::string filename, val api = {})
7780
: api(api) {
@@ -84,6 +87,13 @@ struct WrappedUnit {
8487
}
8588

8689
unit->beginPreprocessing(std::move(source), std::move(filename));
90+
91+
#ifdef CXX_WITH_MLIR
92+
auto tc = std::make_unique<cxx::Wasm32WasiToolchain>(unit->preprocessor());
93+
tc->initMemoryLayout();
94+
tc->addPredefinedMacros();
95+
toolchain_ = std::move(tc);
96+
#endif
8797
}
8898

8999
auto getUnitHandle() const -> std::intptr_t {
@@ -182,20 +192,25 @@ struct WrappedUnit {
182192

183193
unit->endPreprocessing();
184194

185-
unit->parse();
195+
unit->parse(cxx::ParserConfiguration{
196+
.checkTypes = true,
197+
});
186198

187199
co_return val{true};
188200
}
189201

190202
auto emitIR() -> std::string {
191203
#ifdef CXX_WITH_MLIR
192204
mlir::MLIRContext context;
205+
context.disableMultithreading();
193206
context.loadDialect<mlir::cxx::CxxDialect>();
194207

195208
cxx::Codegen codegen(context, unit.get());
196209

197210
auto ir = codegen(unit->ast());
198211

212+
(void)cxx::lowerToMLIR(ir.module);
213+
199214
mlir::OpPrintingFlags flags;
200215
flags.enableDebugInfo(true, true);
201216

@@ -204,9 +219,7 @@ struct WrappedUnit {
204219
ir.module->print(os, flags);
205220
os.flush();
206221

207-
auto code = out.str();
208-
209-
return code;
222+
return out.str();
210223
#else
211224
return {};
212225
#endif

src/mlir/cxx/mlir/codegen.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ auto Codegen::getFileAttr(const std::string& filename)
12041204
return it->second;
12051205
}
12061206

1207-
auto filePath = absolute(std::filesystem::path{filename});
1207+
auto filePath = std::filesystem::path{filename};
12081208

12091209
auto attr = mlir::LLVM::DIFileAttr::get(
12101210
context_, filePath.filename().string(), filePath.parent_path().string());

src/parser/cxx/cli.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ std::vector<CLIOptionDescr> options{
155155
{"-x", "Specify the language from the compiler driver, e.g. c, or c++",
156156
CLIOptionDescrKind::kSeparated},
157157

158-
{"-fcheck", "Enable type checker (WIP)", &CLI::opt_fcheck},
158+
{"-fcheck", "Enable type checker", &CLI::opt_fcheck},
159+
160+
{"-fno-check", "Disable type checker (implies -fsyntax-only)",
161+
&CLI::opt_fno_check},
159162

160163
{"-fsyntax-only", "Check only the syntax", &CLI::opt_fsyntax_only},
161164

src/parser/cxx/cli.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ class CLI {
7070
bool opt_S = false;
7171
bool opt_c = false;
7272
bool opt_fsyntax_only = false;
73-
bool opt_fcheck = false;
73+
bool opt_fcheck = true;
74+
bool opt_fno_check = false;
7475
bool opt_freport_missing_types = false;
7576
bool opt_fno_reflect = false;
7677
bool opt_fno_strict_prototypes = false;

src/parser/cxx/substitution.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ void Substitution::doMake() {
349349
if (!isPackParameter(parameters[i])) continue;
350350
packIndex = i;
351351

352-
// Count trailing non-pack parameters that don't have defaults
352+
// Count trailing non-pack parameters that don't have defaults -
353353
// they need their own arguments, so the pack can't consume those.
354354
int trailingRequired = 0;
355355
for (int j = i + 1; j < paramCount; ++j) {

src/parser/cxx/type_checker.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2256,7 +2256,7 @@ auto TypeChecker::Visitor::check_reinterpret_cast(ExpressionAST*& expression,
22562256
check.unit_->typeTraits().is_enum(sourceType) ||
22572257
check.unit_->typeTraits().is_scoped_enum(sourceType)) &&
22582258
check.unit_->typeTraits().is_pointer(targetType)) {
2259-
// No implicit cast wrapper CastExpressionAST codegen emits IntToPtrOp.
2259+
// No implicit cast wrapper - CastExpressionAST codegen emits IntToPtrOp.
22602260
return true;
22612261
}
22622262

0 commit comments

Comments
 (0)