Commit Graph
33 Commits
Author SHA1 Message Date
Martim Martinsandmartimartins 31df852738 Remove non-needed Python 2.x inherit from object (#1622)
In Python 3.x it is not necessary to have `object` inheritance in classes, it may be useful to have `object` inheritance in classes if the code has support for Python 3.x, 2.x, but currently the present code does not contain support for python 2.x.

Co-authored-by: martimartins <martim13artins13@gmail.com>
2022-07-23 18:15:29 -07:00
Josh Soref 066b103881 Spelling (#1580)
This PR corrects misspellings identified by the [check-spelling action](https://github.com/marketplace/actions/check-spelling).

The misspellings have been reported at https://github.com/jsoref/carbon-lang/commit/38a1c1640151899fd6da0442a92557f9543b6280#commitcomment-79197316

The action reports that the changes in this PR would make it happy: https://github.com/jsoref/carbon-lang/commit/173c8f9083a68aa61f7cfe94f720f1e5dc7f1ea3

Note: this PR does not include the action. If you're interested in running a spell check on every PR and push, that can be offered separately.

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2022-07-22 16:14:21 -07:00
Jon Meow 20728dbd3a CARBON_ header guards (#1261)
This modifies scripts/check_header_guards.py to add the CARBON_ prefix; everything else is pre-commit.
2022-05-12 17:25:43 -07:00
Jon Meow 107848e30f Switch mypy approach to pre-commit (#1234)
I'm treating my PR to mypy bazel integration as dead in the water. Abandoning that approach, this seems to work reasonably well as a replacement. It's actually a slightly newer version of mypy too -- the bazel integration was stuck on an old version.

Note I don't think we're losing much: we shouldn't be writing too much python.
2022-05-09 09:54:12 -07:00
pk19604014 9ec2a0bb98 Added googletest deps removed in #1215 as the deps are still required in strict headers mode for the googletest.h include (#1218) 2022-04-27 13:25:57 -04:00
Jon MeowandChandler Carruth d3700d5cd0 Changes tests to init LLVM stack tracing (#1215)
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2022-04-26 16:19:51 -07:00
Jon Meow eda43faa5a Note namespace and static recommendations in C++ style guide (#1041) 2022-01-27 11:26:47 -08:00
Jon MeowandGeoff Romer 1b4c81fa69 Add script for generating missing C++ deps (#1012)
Co-authored-by: Geoff Romer <gromer@google.com>
2022-01-07 14:44:40 -08:00
Chandler Carruth 5f67029479 Use upstream GoogleTest and add related test utils. (#876)
This moves over to the vanilla upstream GoogleTest pulled in the more
expected manner with Bazel. It also adds Abseil and Google Benchmark
libraries in the same fashion (there are cross dependencies here).

As part of this, also introduce a dependency check test that can enforce
basic layering of dependencies. For example, this lets us ensure that
non-test Carbon code only depends on LLVM and Clang despite having other
libraries available. There remains some cleanup to improve the way these
dependency tests work, but this at least ensures we don't regress.

I've also provided workarounds to allow both Carbon code and LLVM code
to freely be used with GoogleTest (and other `std::ostream` based
output code). This is done by extending the code in
`//common/ostream.h`. One downside is that it requires opening the
`llvm` namespace and adding an ADL_found overload there. I think on
balance this is still a win and doesn't make me too nervous.

The new version of GoogleTest requires printing more often from matchers
and so I've also added several printing routines to types that
previously didn't require them. Otherwise, most of the updates are just
using the more conventional upstream style of including the headers and
adding `ostream.h` where it is needed.

I did consider moving code over to use `std::ostream` instead of LLVM's
`raw_ostream`, but the advantages of not doing virtual dispatch still
seem significant, and it also seems good to retain access to LLVM's
formatting utilities built around `raw_ostream` given that we can't pull
arbitrary dependencies into Carbon code outside of test code.

All of this was slightly motivated by requests for newer features in
GoogleTest, but much more-so by my desire to have access to Google
Benchmark and Abseil when writing benchmarks. For example, using
Abseil's random number generator seems extremely helpful when generating
inputs for benchmarks. The growing dependencies between these packages
further motivated me to just pull them all in and ensure they worked
well.
2021-11-02 20:14:12 -07:00
Chandler Carruth ec7a670d84 Update the LLVM submodule. (#935)
Among other things, this brings compatibility fixes with upstream
GoogleTest and Windows Bazel build support fixes.
2021-11-02 18:14:58 -07:00
Jon Meow 3351443c8f Switch to a mypy fork that handles imports (#823)
I'm seeing if I can upstream thundergolfer/bazel-mypy-integration#43, but we can also point at my fork for the time being.

This should resolve conflicts with mypy treating imports as non-hermetic, creating inconsistent behavior if packages are/aren't installed locally.
2021-09-13 13:08:54 -07:00
Jon Meow 33daf64329 Remove explicit py_* loads (#781)
Per https://groups.google.com/g/bazel-discuss/c/XNvpWcge4AE/m/aJ-aQzszAwAJ
2021-08-26 09:57:27 -07:00
Jon Meow 8b8715e871 Add mypy hints for migrate_cpp (#784)
(these are minimal, but adding them for completeness)
2021-08-26 09:28:16 -07:00
Jon Meow d7b2c9b580 Remove uses of rules_cc (#776)
Per https://github.com/bazelbuild/rules_cc this still isn't necessary. There's no build-time enforcement, so usage is inconsistent/incorrect. Rather than letting this linger, remove it pending Bazel tooling enforcing it.
2021-08-24 08:55:17 -07:00
Jon Meow c94ff74ea2 Switch to run-clang-tidy for parallelism (#629)
Not sure why this affects include ordering, but it makes execution a _lot_ faster.
2021-07-16 10:48:20 -07:00
Jon Meow 6fa42a7f3c For-range in replacement logic (#631)
This replaces GetAstMatcher with AddMatcher because cxxForRangeStmt is a StatementMatcher. addMatcher has multiple definitions (https://clang.llvm.org/doxygen/classclang_1_1ast__matchers_1_1MatchFinder.html) and so this approach allows using the right addMatcher without writing per-call overloads.

To handle the `var`, I'm considering something like moving VarDecl logic into a VarMatcherBase so that I can just use CXXForRangeStmt's getLoopVariable. The problem is a for-range statement has multiple VarDecls, and getLoopVariable may be the easiest way to identify the real one.
2021-07-12 16:20:44 -07:00
Jon Meow 3082d05f80 Handle var initialization. (#628) 2021-07-09 11:29:38 -07:00
Jon Meow 4f1b2198ff Refactor Matcher code to reduce per-Matcher boilerplate (#615)
This is in part to eliminate the "sm" and "lang_opts" variables that received comment, but also cuts back on the use of auto.
2021-07-08 12:42:24 -07:00
Jon MeowandGeoff Romer e7a1093eb9 Fix fn placement around keywords (#613)
Co-authored-by: Geoff Romer <gromer@google.com>
2021-07-01 09:43:14 -07:00
Jon MeowandChandler Carruth 1071ec52b7 Head further towards reconstructing the type as written. (#612)
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2021-06-30 14:42:37 -07:00
Jon Meow 8e31e46c66 Don't use VarDecl replacements on range for loops. (#604) 2021-06-29 09:41:15 -07:00
Chandler CarruthandJon Meow 1057eda8f7 Fix formatting by removing a comment. (#608)
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-06-28 16:39:28 -07:00
Jon MeowandChandler Carruth 2d95993bd5 Improve handling for let and auto (#599)
Range-based for loops remain messed up -- I'm just disabling the test here and turning a blind eye.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2021-06-28 10:03:17 -07:00
Jon Meow 9bdabda851 Insert fn for void functions (#596) 2021-06-24 10:16:21 -07:00
Jon Meow 2344a52e24 Start handling variable declarations (#571)
TODOs in the test for known issues.

I may switch the approach to getting the variable type (on examination, this isn't working quite as well as I'd thought) but for now I think it's okay. I had an earlier approach though that may work better overall -- I'd been thinking this would work better, but as you can see in the null check for type information, I think I missed a key point.

Anyways, what'd really been vexing me was `int i, j` which I think I handle passably well now. There's obviously room for improvement, but given I've been going at this for a couple days now, I thought it best to checkpoint where I was.

This also includes some related framework changes to fix bumps I was running into. Overall the tool should operate a bit more smoothly with these changes. There are still issues with overlapping replacements, but I think it's primarily with range-based for loops which I just need to take some time to fix.
2021-06-23 10:58:32 -07:00
Chandler CarruthandJon Meow 05261b7fe7 Remove the LLVM bootstrap and use Hombrew installed LLVM-12. (#551)
Now that LLVM 12 has been released we no longer have any need to
bootstrap LLVM to get the desired featureset. LLVM 12 is available
widely, including in Homebrew across multiple platforms and in the
GitHub action runners.

Sadly, the Linux distribution builds of LLVM-12 are largely broken and
not as useful for us. The Homebrew Linux install was also broken
originally, but I've worked extensively with the Homebrew folks to get
the Linux install into a really good shape. It should now work reliably.

There are two primary bugs in Linux LLVM packages that need to be fixed
before we can just use them:

- https://bugs.llvm.org/show_bug.cgi?id=43604
- https://bugs.llvm.org/show_bug.cgi?id=46321

Once those are addressed and point releases with the fixes widely
available we can further simplify things.

Even with the need to use Homebrew installs, using the released LLVM has
the extra advantage of making it easy to properly support Darwin ARM and
I've added that configuration so that I can test things there.

Last but not least, this will significantly shrink our build outputs
which should allow building much more in continuous integration on
GitHub actions without exceeding the action cache size limits. I've even
added several tweaks and adjustments to the compile and build flags to
improve the build performance and reduce the build output size.

Once this is landed and stable, we can consider adding the refactoring
tooling back to our CI.

One of the biggest downsides of this path is that our CI has to download
and install the LLVM toolchain from Homebrew on each run. This is pretty
slow (takes a couple of minutes). But it is a fixed overhead -- it won't
get worse over time. Eventually, we can either look at a much fancier
action configuration to avoid this or hopefully the Debian packages will
get updated and we can move back to those.

The bootstrapping has served us long enough at this point. We can
resurrect it if we ever find a compelling reason for breaking off of the
latest LLVM release as our host toolchain.

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-06-09 10:00:46 -07:00
Jon Meow f180c64454 Change how replacements are filtered (#541)
This replaces the use of `isExpansionInMainFile` with instead taking the list of input files, and only touching them. This doesn't keep `isExpansionInMainFile` because it should be redundant, and as such it'd be easy to forget. Unless it starts being a performance issue, it's probably better to omit.
2021-06-03 16:35:55 -07:00
Jon Meow e619d3d632 Shift migrate script to a workflow class, and file renames to .carbon (#535)
This might need some customization, e.g. `woff2_decompress.impl.carbon` (as a file with a `main`) might be better as `woff2_decompress.carbon`, but I thought at least putting on `.carbon` extensions would help perspectives on files.

This restructures the script to make it easier to access standard info (e.g. cpp_files) without passing everywhere.
2021-06-01 10:15:03 -07:00
Chandler Carruth 4034fa223d Update LLVM (and llvm-bazel). (#550)
This picks up a newer version of LLVM and the LLVM Bazel integration.
The big change here is that we can configure the LLVM targets that are
built, which allows us to dramatically reduce the build costs by
focusing on a couple of CPUs for the time being.

There are a few API updates needed as well.

This also rotates the cache version so we start with a clean Bazel cache
from here. Otherwise we'd potentially pay the cost of carrying around
stale bits of LLVM endlessly.
2021-05-25 15:21:57 -07:00
Jon Meow 29bf305539 Add tests to the cpp_refactoring tool. (#539)
This refactors the main.cpp out into a file structure that should make it easier to add more matchers/tests.
2021-05-17 16:55:50 -07:00
Jon Meow 82f5c4224b Small fixes from #530 (#537) 2021-05-14 13:23:10 -07:00
Jon Meow 6f544494b3 Use AST to start inserting fn (#530) 2021-05-13 14:58:32 -07:00
Jon MeowandMatthew Riley 88a9d244b7 Initial migration framework (#525)
What this does:

- Sets up a `migrate_cpp` tool which currently only runs `clang-tidy`.
  - This is intended to have more transformations in the future.
- Sets up a `migrate_cpp.sh` script.
  - This copies the original woff2 code into a `carbon` directory and runs the `migrate_cpp` tool on it there.
- Adds the initial `carbon` directory of woff2
  - To be clear, this is currently only updated via `clang-tidy`.
  - More transformations should be expected in the future.
- Minor related edits. For example:
  - Adjust pre-commit to skip the `carbon` directory, because it's third-party code and shouldn't be edited in the same way.
  - Adds `@brotli_carbon` as a local repository so that we can "build" outputs.
  - Makes clang-tidy from the bootstrap toolchain accessible for BUILD dependencies, as it's then used for `migrate_cpp`.

What this does not do:

- Any actual transformation of C++ code to Carbon

Co-authored-by: Matthew Riley <mdriley@gmail.com>
2021-05-11 10:13:47 -07:00