Commit Graph
144 Commits
Author SHA1 Message Date
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
Geoff Romer d71f5b1784 Express stack updates using return values. (#747)
This enables the interpreter logic to express its intent more directly, especially in the common cases, and enables us to get rid of ValAction. It's also a step toward simplifying and encapsulating `state->stack`.
2021-08-19 13:35:47 -07:00
Jon MeowandGeoff Romer 0619b4ce6a Provide a BisonWrap for default construction (#761)
Co-authored-by: Geoff Romer <gromer@google.com>
2021-08-19 12:31:25 -07:00
Jon Meow 367f9e4e94 Rename struct to class per #651 (#765) 2021-08-19 12:15:20 -07:00
Jon Meow 47325be112 Switch interpreter Stacks to Ptr (#763)
This also eliminates the ctad wrapper for Stack: I think the leaning is to remove it. It felt worth keeping the constructor because constructing with a single element is a common use-case.

Adds a single-argument constructor for Scope because the `std::list<std::string>()` is common, and eliding it is consistent with what we've done for things like tuples.

I was considering a vector constructor due to the double-Push on line 1139, but thought the Push() semantics may mean that it's better not to provide.
2021-08-19 11:34:03 -07:00
Jon Meow 925c60b669 Change Declaration passing to use Ptr (#758) 2021-08-19 11:33:32 -07:00
Jon Meow 50cfda0e1c Split Stack and Dictionary, moving ListNode into Dictionary (#757)
I think Stack used to use ListNode, but you'd previously removed that dependency. This finalizes the split, and merges ListNode so that we don't accidentally accrue more dependencies. In part I think we'll eventually want to change how Dictionary is set up.
2021-08-18 14:05:14 -07:00
Geoff RomerandJon Meow 7138ee400f Support complex type patterns in bindings. (#759)
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-08-18 13:40:17 -07:00
Geoff Romer 2295658697 More detailed traces for type checking (#760) 2021-08-18 12:34:16 -07:00
Jon MeowandGeoff Romer c6ebe0db67 Add Ptr and RawNew for migration (#751)
Co-authored-by: Geoff Romer <gromer@google.com>
2021-08-17 13:37:29 -07:00
Jon Meow 1eeaa208f2 Move paren_contents under ast and restrict syntax BUILD visibility (#756)
Trying to straighten out the BUILD graph; the dependency of ast pieces on paren_contents makes me think this is the right direction.
2021-08-17 12:52:53 -07:00
Jon Meow a6655b320c Clean up Declaration/TypeCheck dependency (#753)
Looks more like a mistake/legacy than deliberate
2021-08-16 16:38:09 -07:00
Jon Meow 9a9ccd8b7d Exclude tab in string literals (#734)
Noticed this while working on #732, seemed easiest to split changes though.
2021-08-12 09:53:04 -07:00
Jon Meow d3c7ca3131 Remove FunctionDefinition's default constructor (#735)
This opens up a path for switching `int line_num` to a `Location loc`, which I want to do for tracking filenames of code. But I don't think we should have a default constructor on `Location` to avoid mistakes, and switching FunctionDefinition to an arena alloc seems more consistent anyways.
2021-08-12 09:52:32 -07:00
Jon MeowandGeoff Romer 250ce4ab00 Add string parsing and a print builtin (#721)
It was in my mind to add String in order to support libraries in `package`.  `print` is added in order to have a String go to stdout. I've tried to do `print` in a way that won't be too hard to add other printable types, but it's probably also somewhat optional here -- that is, if desired, I could remove it. But it was a lot easier to doublecheck `\n` behavior with it, and I suspect it'll be helpful in other tests if it supports more value types.

On the side, this also fixes dereferencing in Pattern/Expression Print() calls, which I was noticing printing pointers instead of values. This may be another argument for moving away from passing pointers, since this seems to be a difficult-to-catch error.

Co-authored-by: Geoff Romer <gromer@google.com>
2021-08-11 13:14:05 -07:00
Jon Meow d5564280ab Switch Statement to use inheritance+cast (#718) 2021-08-10 13:10:05 -07:00
Jon MeowandGeoff Romer dbcd6ad20d Switch Expression to use inheritance+cast (#712)
Co-authored-by: Geoff Romer <gromer@google.com>
2021-08-06 15:43:25 -07:00
Jon Meow 4e0307efbc Switch Member to use inheritance+cast (#713) 2021-08-06 15:27:31 -07:00
Jon Meow 6164cdfd6d Verify that provision/omission of return types matches (#717)
This is finishing #678
2021-08-06 15:18:39 -07:00
Jon Meow 4b2346cfcd Switch Action to use inheritance+cast (#711) 2021-08-06 15:14:29 -07:00
Jon Meow c1148caf7d Switch Declaration to use inheritance+cast (#714) 2021-08-06 14:57:44 -07:00
Jon MeowandGeoff Romer 642addfe48 Fix caching and correctness of --update_goldens (#709)
- `PATH` is a caching issue, as commented.
- `exec.map` is a correctness issue, the reference to `test` was incorrect on threading so it wasn't updating all tests.

Co-authored-by: Geoff Romer <gromer@google.com>
2021-08-06 13:16:43 -07:00
Jon Meow 2e9e4f4cb3 Migrate remaining exits to FATAL_*_ERROR calls (#704)
Adds FATAL for things that are most likely programming errors in executable_semantics.
2021-08-06 13:06:25 -07:00
Jon Meow 5749413b28 Add TupleValue::Empty for the common empty tuple case (#708) 2021-08-06 10:06:35 -07:00
Jon Meow f7d8b7f2e2 Add Dump to Pattern (#715) 2021-08-06 10:05:00 -07:00
Jon MeowandGeoff Romer 2620ba066d Move Int parsing to i32 for #543 (#700)
Note this doesn't support other sizes or types, it just errors on them.

Co-authored-by: Geoff Romer <gromer@google.com>
2021-08-05 09:34:12 -07:00
Jon Meow 7e91fbc276 Switch Value to use the inherit/cast model (#703) 2021-08-05 08:34:08 -07:00
Geoff Romer de91afcf25 Rename ::yy::parser to ::Carbon::Parser. (#697)
Not only is this more consistent with our style rules, it lets us omit a lot of noisy qualifiers in parser.ypp
2021-08-03 12:09:42 -07:00
Jon Meow 0ca914a17a Remove outdated bison comment (#695) 2021-08-02 18:26:27 -07:00
Jon Meow 6ae9cc3cf8 Add support for return; (#678)
This creates a ReturnExpression. A separate change should enforce that an implicit return of `()` is only allowed in functions that have an implicit return type of `()`, and I think the structure taken here should ease that.
2021-08-02 16:30:08 -07:00
Jon Meow 9829f188b7 Move all new's to global_arena, and remove ASAN disabling (#690)
Note this changes identifiers from char* to string to avoid malloc.

Fixes #580
2021-08-02 11:08:22 -07:00
jonmeow 91512e90e7 Fix tests affected by pattern change 2021-07-30 17:49:37 -07:00
Jon Meow f2db4e2e9f Fix tests.py paths and use pre-commit to guard against lost tests (#689)
- In pre-commit-config, add a run of `--update_list`. I'm doing this because I noticed (on running tests.py) that we'd lost track of a few tests.
- In tests.py, the paths affect bison output where the path to the file is mentioned. This shift should make `--update_goldens` more reliable.
2021-07-30 17:04:49 -07:00
Geoff RomerandJon Meow 6ac3adfa53 Factor out a Pattern sum type from Expression (#685)
`Pattern` is intended to pilot some changes I would like to apply to all our sum types:
- The alternatives are expressed as derived classes rather than members of a `std::variant`.
- The alternatives are classes in the [style guide sense](https://google.github.io/styleguide/cppguide.html#Structs_vs._Classes), meaning they can have invariants, but can't have public data members.
- Creating an object is expressed using a constructor rather than a factory function.
- Accessing an alternative is expressed as a cast (using LLVM's RTTI system) rather than `std::get` or a `Get` method.

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-07-30 12:24:12 -07:00
Jon Meow b08f6bb0f1 Add a global arena to start cleaning up ASAN errors (#687) 2021-07-30 10:56:53 -07:00
Geoff Romer a8f56797b8 Add Dump methods to printable types. (#681) 2021-07-29 14:17:35 -07:00
Jon Meow a930717202 Require braces on control flow statements (#683)
This implements #623
2021-07-28 10:55:14 -07:00
Jon MeowandChandler Carruth f0af3cb795 Switch from llvm::errs()+exit() to FATAL_USER_ERROR() stream-based handling. (#670)
This is intended to:

- Standardize use of line_num (and highlight where no line_num is available).
- Standardize indications of runtime/compilation errors.
- Make it incrementally easier to write new errors.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2021-07-28 10:47:33 -07:00
Geoff Romer fb0c0b63bf Fix match bug when no case matches (#677) 2021-07-27 11:14:10 -07:00
Jon MeowandGeoff Romer 165651c75c Add script to automate mass test updates (#674)
Trying to simplify the process of updating golden output, and ensuring that we aren't missing any tests. With this script, it should be roughly "Add the .carbon file, then run tests.py --update_all"

Co-authored-by: Geoff Romer <gromer@google.com>
2021-07-26 14:57:00 -07:00
Geoff Romer d4ed6b1083 Enable some additional warnings. (#675) 2021-07-26 11:42:38 -07:00
Jeremy G. Siek a1c164f598 added a test for definition-side checking with expected failure (#673) 2021-07-23 11:42:07 -04:00
Jon Meow edbc3f7716 Use llvm::ListSeparator for simpler separators (#671)
I was looking for something like this, I think it's a straightforward simplification for code. Internally, it handles skipping the separator on the first print.

See the bottom of: https://llvm.org/doxygen/StringExtras_8h_source.html
2021-07-23 08:39:58 -07:00
Jon Meow f35cda7a99 Move ASAN_OPTIONS to executable_semantics, local to the leak. (#672) 2021-07-23 08:37:59 -07:00
Jeremy G. SiekandJon Meow 864b3bde02 Generic functions, first baby step (#658)
* generic functions: progress on parser and AST

* finished first baby step

* revisions based on reviews

* Update executable_semantics/interpreter/interpreter.cpp

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>

* Symbol => VariableType

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-07-22 15:16:56 -04:00
Jon Meow 034f3600e3 Add a FatalUserError macro to help print user-caused errors. (#668) 2021-07-21 12:38:56 -07:00
Jon Meow f3cbfc04c6 Move tracing_flag into a common directory (#669)
Intended to combine well with #668, so neither is alone.
2021-07-21 09:57:54 -07:00
Geoff Romer 08a2d44570 Simplify the API and implementation of Stack (#667) 2021-07-20 14:27:41 -07:00
Jon Meow 8fccecadeb Refactor output to be more streaming-focused. (#666)
- Switch code to llvm::raw_ostream as part of standardizing output forms.
    - Preferring llvm::raw_ostream over std::ostream because other tooling code should be expected to rely on llvm more closely, and an overall preference towards library consistency.
    - There are a couple spots in syntax/ that still use std streams, but I'd prefer to take a separate PR to see how best to address those.
    - std::boolalpha doesn't work with llvm, so I've implemented equivalent in a couple places (not enough that it felt like worth making a helper function).
- Implement Print(ostream) as consistently as we can, as an instance member.
    - This facilitates the use of the common/ostream.h template to provide operators.
    - Preferring this approach so that Print is easily accessible via gdb, per suggestion on #executable-semantics.
- Switch code currently calling `type->Print(ostream)` to instead do `ostream << *type`.
- Remove the unused `PrintTypeEnv`, nothing used it and the declaration didn't match the definition.
2021-07-20 13:16:48 -07:00
Jon Meow 368fc0063c Handle invalid chars better, and do small cleanups around error output. (#657)
This adds a test for invalid characters (that would've failed before, because the printed char isn't escaped). Not sure if there's a good way to test the PrintDiagnostic code, as it appears to occur on bison parser errors, which I'm just not sure how to trigger.
2021-07-20 12:04:45 -07:00