Commit Graph
617 Commits
Author SHA1 Message Date
Geoff Romer d177a08e01 Make continuations consistently "shallow" (#874)
Prior to this change, `__await` would make a deep copy of the continuation stack, but shallow-copy the individual stack frames within it. As a result, continuations appeared to have shallow semantics so long as the continuation stack had only a single frame.

This change also removes an obsolete test from the brief period when we intended continuations to have deep-copy semantics, which has been passing basically by accident.
2021-10-11 14:57:09 -07:00
Chandler Carruth 9211c98951 Switch to depend on LLVM 13's Clang. (#877)
The LLVM-13 release is now on Homebrew, so switch to it. This is
important because our CI only installs the latest version currently.

If you hit issues after this, make sure to update your Homebrew install
to get the latest Clang release. You can always directly set `CC` in
your environment to use a specific `clang` compiler.
2021-10-11 09:33:55 -07:00
Geoff Romer 6068d2306b Address feedback from #856 (#864)
* Make tuple/struct fields mutable.
* Avoid ExpectType when we know it will fail.
2021-10-08 16:52:17 -07:00
Richard Smith 93a002a21a Avoid confusing description of "equivalent". (#843) 2021-10-06 11:06:34 -07:00
Richard Smith aec77a6f39 Add a keyword list. (#869)
This list was extracted from currently-approved proposals and
corresponding design documents. This is intended to be a summary of the
status quo, not a change.
2021-10-06 11:05:41 -07:00
Geoff Romer fbf2116d35 Handle line number changes in update_checks.py (#873) 2021-10-05 16:09:03 -07:00
Geoff Romer d5eb9a72f9 Fix shadowing.carbon to test shadowing behavior. (#872) 2021-10-05 16:08:15 -07:00
Geoff Romer 823251efee Clarify code of conduct appeals process (#871)
- Replace obsolete references to the arbiters, and clarify that the appeals process will be available once the leads are separate from the conduct team.
- Document that leads, like conduct team members, will be excluded from discussions/decisions that concern them.
2021-10-05 16:06:00 -07:00
Chandler CarruthandGeoff Romer a2c91eae89 Rework exiting system to have better backtraces. (#863)
Previously, the program exit was triggered by the destructor.
Unfortunately, C++ doesn't make it precisely clear where the destructor
is run, and Clang doesn't generate reliable debug information for that
to give good backtraces. Among other things, when combining separate
cleanup regions in Clang there may be no single canonical location.

Instead, move the ExitingStream system to use an explicit
low-precedence operator overload to flush the output and exit. This
ensures the stream and other actions are completed first but then
immediately exits the program in a way that has a definitive source
location and produces reliable backtraces.

I've tried to add comments and helpers to make this as clear as possible
given that it is a subtle and surprising issue.

Co-authored-by: Geoff Romer <gromer@google.com>
2021-10-05 00:30:43 -07:00
Richard Smith 0539931b76 PR 866: Allow ties in floating literals. (#866) 2021-10-02 11:01:29 -07:00
Chandler Carruth a5cee52239 Fix a typo in the spelling of the libc++ debug macro. (#868)
This should get us actual debugging capabilities.

Also, adopt the better bazel formulation that I forgot to add from
geoffromer's original change.
2021-10-01 20:07:23 -07:00
Geoff Romer 52b09f099b Avoid dereferencing a disengaged optional (#865) 2021-10-01 19:23:46 -07:00
Geoff Romer c37521fdc3 Log C++ file/line number in CHECK and FATAL (#862) 2021-09-30 11:56:19 -07:00
Jon Meow 70797e8bf8 Mass rename SourceLoc and Tag (#860)
This does a mass rename of:

-   `SourceLoc()` -> `source_loc()` for property naming
    - `loc` -> `source_loc_` for underscore+consistency
    - Generally changing function args to `source_loc` for consistency
-   `Tag()` -> `kind()` for property naming and `Kind` parity
    - `tag` -> `kind_` for underscore

Also renames `Pos` and `Results` on `Action`. These are a bit of an exception in that most base classes only have `Tag` and maybe `SourceLoc`, whereas `Action` has a little more. I felt okay having `source_loc()` and `kind()` on the base class where children do `Exp()` and the like, but it felt weird to me to mix it on the same class.

The reason for doing this cross-class in one PR is so that I can do it efficiently with a global replace in the codebase, rather than e.g. changing `Expression` but having to read through compiler errors to determine where it's calling `Expression`'s `Tag` versus a different `Tag`. The end result should be equivalent.
2021-09-29 16:52:12 -07:00
Geoff Romer c4e40aaa86 Add support for struct types, following p0561. (#856) 2021-09-29 16:14:27 -07:00
Jon Meow d157d96338 Migrate Declaration to newer property style, class-ify ClassDefinition (#859) 2021-09-29 14:38:18 -07:00
Jon Meow 25dce9fbcf Change Match clauses from pairs to classes (#858)
Updates style of the Match class at the same time.
2021-09-29 13:36:54 -07:00
Geoff RomerandChandler Carruth bf49f2efed Proposal: Property naming in C++ (#720)
This proposed style change allows C++ classes in the Carbon project to provide methods that are named like variables, so long as they behave like _properties_ of the class. It also requires data member names to have a trailing `_`.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2021-09-28 14:36:43 -07:00
Geoff Romer 532948d9a5 Miscellaneous tuple simplifications (#857)
- Drop unnecessary special-casing of 0-tuples.
- Drop unused constructor.
2021-09-27 12:10:16 -07:00
Jon MeowandGeoff Romer 5aa958345b Implement auto return types, removing => returns (#850)
This implements #826, I think covering everything important there.

Regarding ReturnTypeContext, I broke that out because it started feeling like a significant number of args to be passing around, and I think this makes the association inside type checking clearer.

Co-authored-by: Geoff Romer <gromer@google.com>
2021-09-27 11:17:24 -07:00
Jon Meow 04ab30f231 Make the AST mutable (#849)
The code is pretty intertwined: having the AST be truly mutable means (to me) changing parser.ypp to return non-const values, but then the way things are passed around between objects should be non-const (particularly an issue with lists), which then creates issues with construction of lists in the TypeChecker, which then TypeChecker needs to mostly be non-const.

Due to the difficulties in breaking this apart, whereas I'd previously considering refactoring accessor naming in the same PR, I've largely avoided doing so. The intent is then that this PR focuses mainly on const -> non-const AST behavior.

call_main moves out of interpreter.cpp so that interpreter.cpp can receive a fully const AST.
2021-09-27 10:57:31 -07:00
Jon Meow 721743bc58 Change Alternative to a class (#853)
Revives BisonWrap because this seems a reasonable use of it (avoiding the need to have an std::optional or pointer for Alternative, both of which I thought could be unclear about the intent).
2021-09-27 09:05:22 -07:00
Jon Meow 6ab2bff69c Switch FunctionDefinition to a class (#852)
Splitting out the task from #849
2021-09-27 09:05:04 -07:00
Jon Meow c9b5c2fa1a pre-commit autoupdate (fixes clang-format file bug) (#854) 2021-09-24 17:15:34 -07:00
b9619db402 Numeric literal semantics (#144)
This proposal provides semantics for numeric literals.

* Numeric literals have a type derived from their value, and can be converted to any type that can represent that value.

* Simple operations such as arithmetic that involve only literals also produce values of literal types.

* Literals implicitly convert to types that can represent them.

* The Carbon prelude provides:
    * An arbitrary-precision integer type `BigInt`.
    * A rational number type `Rational(T:! Type)` with constraints on `T` not yet determined.
    * A family of integer literal types, `IntLiteral(N:! BigInt)`.
    * A family of real literal types, `RealLiteral(N:! Rational(BigInt))`.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-09-23 18:48:37 -07:00
3b11b8d2cf Comparison operators (#702)
This proposal introduces the operators `==`, `!=`, `<`, `<=`, `>`, and
`>=` to Carbon.

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
Co-authored-by: Geoff Romer <gromer@google.com>
Co-authored-by: josh11b <josh11b@users.noreply.github.com>
2021-09-23 18:39:54 -07:00
fa4c79c1e9 Function return type inference (#826)
Allow `auto` as a return type for functions. Only support functions with one `return` statement for now (open question).

This explicitly suggests removing the executable semantics `fn name(args) => expression` syntax, and is motivated by reconciling executable semantics with approved Carbon state. [example](https://github.com/carbon-language/carbon-lang/blob/3d1716f6c692a840d8b4b513ddfb8119432a5150/executable_semantics/testdata/fun_named_params.carbon) This aspect is a decision that may be affected by lambda syntax, but we might also choose to keep lambda syntax and function syntax separate -- I don't think there's enough benefit to providing the alternate function syntax right now.

Co-authored-by: Geoff Romer <gromer@google.com>
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2021-09-23 10:09:57 -07:00
Jon Meow 563201a849 Remove proposals/BUILD, moving template.md under scripts (#846)
With #842 there's not as much reason for the BUILD anymore, maybe move the template.md file and get rid of it?
2021-09-23 09:16:19 -07:00
Jon Meow 103808b92a pre-commit autoupdate (#848)
Validated with `pre-commit run -a`
2021-09-23 09:05:41 -07:00
Jon Meow 8396527043 Add pre-commit check to remove trunk links from md files (#847)
Restricting this to just md files because maybe we'll reasonably want such links in source files, but would be fine removing that restriction if you're on board.

e.g., this won't change: https://github.com/carbon-language/carbon-lang/blob/trunk/common/string_helpers.cpp#L85
2021-09-23 09:05:21 -07:00
Richard Smith 45ea240942 Replace proposal list generation script with a link to a github query. (#842)
This aims to avoid merge conflicts when adding new proposals.
2021-09-22 12:25:14 -07:00
Geoff Romer 46775ac2b2 Invoke lit with -sv. (#844) 2021-09-22 12:06:48 -07:00
f63169608e Implicit conversions (#820)
Proposal to support a limited set of implicit conversions.

This would generally permit only implicit conversions that are lossless and semantics-preserving. In particular, this proposal allows:

-   Conversion from an integer type to a wider integer type of the same signedness, and from an unsigned integer type to a wider signed integer type.
-   Conversion from an integer type to a floating-point type that has enough mantissa bits to exactly represent all integers in the source type.
-   Conversion from integer literals to integer and floating-point types that can represent them.
-   Conversion from floating-point literals to floating-point types that can represent them.
-   Conversions required for generics: conversions of values between facet types, and conversions of types between type-of-types, as described in the generics proposals.
-   Conversions required for inheritance: derived-to-base conversions for class pointers and class values.

Other conversions, such as lossy conversions between arithmetic types and conversions between bool and other types are not supported.

Co-authored-by: josh11b <josh11b@users.noreply.github.com>
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
Co-authored-by: Geoff Romer <gromer@google.com>
2021-09-21 15:16:16 -07:00
Jon MeowandGeoff Romer 7beaabc934 Prevent ostream << for pointers to printable types. (#837)
Co-authored-by: Geoff Romer <gromer@google.com>
2021-09-21 10:44:00 -07:00
Jon Meow 15434320e6 Add README entry for lit test setup (#840) 2021-09-21 10:33:20 -07:00
Jon MeowandChandler Carruth c3f4f28ec5 One way principle (#829)
Add a principle that Carbon should only provide one way of doing things

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2021-09-21 09:45:35 -07:00
Jon MeowandChandler Carruth 6d33a80988 api file default public (#752)
Replace library public-like `api` behavior with explicit `private` behavior, mirroring #665 

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2021-09-21 09:33:32 -07:00
Jon Meow b1af08fed0 Rename ptr.h to nonnull.h (#839) 2021-09-20 15:15:30 -07:00
Jon Meow 9edb2459fd Remove BisonWrap, which was a Ptr-specific feature (#836) 2021-09-20 13:51:20 -07:00
Chandler Carruth fbb0aa729b Update LLVM and switch to upstreamed Bazel BUILD. (#838)
Also removes the legacy llvm-bazel submodule that is no longer needed.
2021-09-20 13:15:08 -07:00
Chandler Carruth bc658e6923 Cleanup debug flags and enable libc++ debugging on Linux. (#835)
The big change here is to enable libc++'s debug mode outside of `opt`
builds on Linux where it seems to work well with the Homebrew installed
toolchain. I'm restricting it to Linux as the system libc++ install on
x86 macOS doesn't seem to work. This is based on and subsumes #811.

This also tidies up how `-NDEBUG` is set to include non-codegen compile
actions, and consolidates some optimization flags in a single location.
This part has no functionality change, but would likely invalidate
caches so bundled here where both a) I noticed and b) we already had
a cache invalidation.
2021-09-18 03:57:17 -07:00
Chandler Carruth 89da711a26 Correctly sanitize nonnull pointers. (#834)
Only the special nullability attributes (`_Nonnull`) work correctly
through type aliases like we're using with `Ptr`. But they aren't
strictly UB and so have to be specially enabled in our sanitizer config
in order to usefully catch nullness errors early. Turn on those
sanitizers as well.

Also, now that we are using fully remote build output caching for our
CI and not trying to squeeze under an arbitrary size limit, re-enable
the nice error messages for all the UBSan checks.

Note that this will have a (very) slow CI run as it will have to
recompile ~everything and upload fresh artifacts. But those should then
be effective cache hits going forward.
2021-09-16 23:22:20 -07:00
Jon Meow 56dc4ae375 Rename Ptr<T> to Nonnull<T*> (#832)
Note that ptr.h also includes an enable_if change, to help avoid https://bugs.llvm.org/show_bug.cgi?id=51881
2021-09-16 19:22:57 -07:00
Jon Meow 5e66248db0 Set issue report url (#833)
Defaults to llvm.org, which we definitely don't want
2021-09-16 16:38:26 -07:00
Jon Meow ff319d311a Switch Ptr to a C++ pointer using the nonnull attribute (#831)
The advantage is a C++ pointer is special, and this approach eliminates the Ptr class type that was causing problems in conversions. Attribute suggestion was courtesy of chandlerc. We're sticking with the Ptr name because it's shorter than Nonnull, and we're likely to keep this in lots of places.
2021-09-16 13:05:25 -07:00
Jon Meow 395a331cde Reorganize tests into dirs and rename numbered tests (#825)
There's a small update to update_checks.py to handle the recursive directories. Also, I'm only using one level of nesting in this PR but really no reason we can't do more. I'm just not sure what clustering is best right now.

As a pattern, I'm trying to name all failing tests `fail_*.carbon`.
2021-09-15 16:37:34 -07:00
Richard Smith 0fec34df03 Tiny doc update: var is not an expression. (#812) 2021-09-14 13:17:31 -07:00
Jon Meow 3d1716f6c6 Autoupdate pre-commit-config (#824)
(manually switching from gitlab to github for flake8)
2021-09-13 14:03:24 -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 5047cd6447 Switch executable_semantics to lit/filecheck tests. (#819) 2021-09-09 11:15:41 -07:00