Commit Graph
205 Commits
Author SHA1 Message Date
Geoff Romer bb28d37eed Drop support for named tuple fields (#886)
Rationale: Based on the status of #478 and #505, Carbon won't have this feature for a while, and it will be simpler not to support it on spec in the meantime.
2021-10-15 13:19:57 -07:00
Jon MeowandGeoff Romer 9007bfcb88 Run clang-tidy on the interpreter directory (#885)
`// NOLINT` is added on type aliases in stack.h and dictionary.h to allow lower_snake_case naming -- this didn't feel like a check worth disabling in spite of false positives.

Co-authored-by: Geoff Romer <gromer@google.com>
2021-10-15 08:54:53 -07:00
Jon Meow 924259986a Switch static_type to return Expression& (#887) 2021-10-14 14:31:06 -07:00
Jon Meow 52096e4299 Apply clang-tidy fixes to the common dir (#884) 2021-10-14 13:39:05 -07:00
Jon Meow 55ecb62ce5 Refactor Expression accessor/mutator style (#883) 2021-10-13 16:56:27 -07:00
Geoff RomerandJon Meow c2140c6cb9 Check exhaustiveness of function-ending match statements (#882)
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-10-13 16:04:43 -07:00
Geoff Romer 652bee6d99 Add static types to AST. (#879) 2021-10-13 15:42:04 -07:00
Geoff RomerandJon Meow bc5a42211b Support struct implicit conversions in type-checking (#870)
I should emphasize that I am **completely cheating** here. This PR does not add support for actually _performing_  implicit conversions at run time, because the AST doesn't yet contain the necessary type information. At run time, code like `var p: Point = {.x = 1, .y = 2};` directly initializes the name `p` with the _struct_ value `{.x = 1, .y = 2}`; no object of type `Point` is actually created. I'm only getting away with this because we don't yet have any tests that can tell the difference.

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-10-12 10:27:20 -07:00
Geoff Romer a99d882223 Perform type-checking in place (#867) 2021-10-11 16:37:39 -07:00
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
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
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
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
Geoff Romer 52b09f099b Avoid dereferencing a disengaged optional (#865) 2021-10-01 19:23:46 -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 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
Geoff Romer 46775ac2b2 Invoke lit with -sv. (#844) 2021-09-22 12:06:48 -07:00
Jon Meow 15434320e6 Add README entry for lit test setup (#840) 2021-09-21 10:33:20 -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 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
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
Jon Meow 90f04700e2 Remove global_arena (#814)
With this, only main.cpp instantiates an arena. Maybe we'll want to split that up more later (e.g., so that the runtime interpreter uses its own arena), but given the intent to have type-checking update the AST, I thought this was a reasonable approach for now in order to avoid ownership complexities.

Fixes #769
2021-09-09 11:00:57 -07:00
Geoff Romer 0521890dbc Clarify the copy semantics of continuations (#816) 2021-09-08 11:36:16 -07:00
Jon Meow 5e3a1cbdb8 Make ReifyType use the input location (#817)
Fixes #379
2021-09-08 10:32:22 -07:00
Geoff RomerandJon Meow 33dd9a873d Debugging quality-of-life improvements (#810)
* Debugging quality-of-life improvements

- Use std::abort for `CHECK`/`FATAL` failures, which acts as a debugger breakpoint as well as automatically printing a stack trace.
- Re-enable printing continuations in `--trace` mode.
- Log the source location of each step in `--trace` mode.

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-09-08 09:25:16 -07:00
Geoff Romer f931a8cead Replace all lists with vectors (#815) 2021-09-07 09:20:10 -07:00
Jon MeowandGeoff Romer 820081b8c1 Add table sorting functionality (#796)
Also apply it to the list of tokens. This way there's no need for "sort order" comments.

This was a side-effect of me trying to merge in api/impl/library/package, and thinking "why am I doing this manually?"



Co-authored-by: Geoff Romer <gromer@google.com>
2021-09-02 17:28:37 -07:00
Jon Meow a03536a196 Add syntax for package and library (#792)
Doesn't add much logic, only takes advantage of parser structure for the ordering enforcement.

Note import_nonexistent tests should probably fail, but writing import tests needs a chain of functionality, and I figured I'd just start adding some to validate the syntax (not adding existent imports because that'd require multi-file structure).
2021-09-02 16:01:15 -07:00
Jon Meow 0980df65cd Remove RawNew from Arena #807 2021-09-02 16:00:49 -07:00
Jon MeowandGeoff Romer 0601f5620b Switch Value to Ptr (#799)
Co-authored-by: Geoff Romer <gromer@google.com>
2021-09-01 15:59:56 -07:00
Jon Meow 31b4f1e7ac Move ExecProgram to interpreter/ (#802)
Seems to make sense since it's the only interpreter/ dependency in syntax/ right now, so this feels like untangling deps.

Fixes #371
2021-09-01 15:22:10 -07:00
Jon Meow b1ded63f2c Switch Dictionary to Ptr (#801) 2021-09-01 15:20:20 -07:00
Jon Meow 5f8b231322 Switch Clause to Ptr (#800)
This is consistent with other lists, doesn't seem to benefit from being a Ptr.
2021-09-01 15:19:58 -07:00
Jon MeowandGeoff Romer 9f67c4b9a8 Run clang-format on parser.ypp and lexer.lpp (#738)
Co-authored-by: Geoff Romer <gromer@google.com>
2021-08-31 12:41:08 -07:00
Jon Meow 973759f0ff Add parser.output to outs (#795)
Fixes #416
2021-08-31 10:46:42 -07:00
Geoff Romer 3058fb99aa Clean up ManualTransition for match statements. (#773) 2021-08-30 16:47:26 -07:00