Breaks `--trace` into two flags:
- `--parser_debug`, which sets the parser debug level (which I haven't dug into piping with `--trace`, but seemed likely to be troublesome)
- `--trace_file`, which now the type checker and interpreter will use for trace information (note compile errors should use a different channel)
Most of the file edits are just mechanical testdata flag updates: `sed -i 's/--trace/--parser_debug --trace_file=-/' testdata/**/*.carbon`
To explain the output paths:
- parse/compile errors: stderr
- print() calls: stdout
- parser tracing: `--parser_debug` option, stdout (formerly stdout if `--trace`)
- type check/compile tracing: `--trace_file=<file>`, giving `-` uses stdout (formerly stdout if `--trace`)
- return code of executed Carbon code: `--trace_file` if set, stdout if not (formerly stdout always)
* finished fuzzer and added fuzzverter util
* fixed typo
* renamed cmd line params
* fixed libproto_mutator download path
* small fixes
* small fixes
* small fixes
* renamed sample corpus proto
* small fixes
* try building on github with LIBCPP_DEBUG enabled
* temporarily marked proto fuzzer as a manual test
* code review
* use a dedicated proto-fuzzer feature to work around LIBCPP_DEBUG=1 crash in proto code
* code review comments, added README.md
* minor fixes to the text
* Update bazel/cc_toolchains/clang_cc_toolchain_config.bzl
Co-authored-by: Jon Meow <jperkins@google.com>
* use Carbon source representation for "empty Main()" instead of text format proto representation
* fixed typo
* made FuzzerUtil produce the full carbon source (proto converted + Main if needed) to decrease code duplication a bit
* typo
* switched to text proto format per code review
* Update executable_semantics/prelude.h
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/fuzzing/README.md
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/fuzzing/README.md
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/fuzzing/README.md
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/fuzzing/README.md
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/fuzzing/README.md
Co-authored-by: Jon Meow <jperkins@google.com>
* review comments
* removed unnecessary file mode variables
* Update executable_semantics/fuzzing/fuzzverter.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/fuzzing/README.md
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/fuzzing/README.md
Co-authored-by: Jon Meow <jperkins@google.com>
* code review comments
* Update executable_semantics/syntax/BUILD
Co-authored-by: Jon Meow <jperkins@google.com>
* buildifier
Co-authored-by: Jon Meow <jperkins@google.com>
* start of generic classes
* fix regressions
* class functions in interfaces
* access to class function on interface from class parameter
* more stuff working for generic classes
* fixing bugs
* update TypeEqual for generic classes
* fixing bugs and finding new ones
* disable unqualified access to members from other members for now
* minor edits
* bug fixes
* introduce compile_time_value to use in type checker instead of constant_value
* cleanup
* put a CHECK back in
* failure test cases for the new FATAL_COMPILATION_ERROR
* change a runtime FATAL into a FATAL_COMPILATION_ERROR
* Update executable_semantics/ast/declaration.h
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/interpreter/action_stack.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/interpreter/interpreter.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/interpreter/value.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/interpreter/value.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/interpreter/interpreter.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/interpreter/value.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/interpreter/value.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/interpreter/resolve_names.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/interpreter/type_checker.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/interpreter/type_checker.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/interpreter/type_checker.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* responses to reviews
* Update executable_semantics/interpreter/type_checker.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* rename compile_time_value to symbolic_identity
* Update executable_semantics/interpreter/type_checker.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/interpreter/type_checker.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/interpreter/type_checker.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/interpreter/type_checker.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/interpreter/type_checker.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/interpreter/type_checker.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/interpreter/value.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/interpreter/value.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/interpreter/value.cpp
Co-authored-by: Jon Meow <jperkins@google.com>
* more edits from review
* Apply suggestions from code review
Co-authored-by: Geoff Romer <gromer@google.com>
* review responses
* Update executable_semantics/interpreter/interpreter.cpp
Co-authored-by: Geoff Romer <gromer@google.com>
* const impl_scope for TypeCheckChoiceDeclaration
* add some const
Co-authored-by: Jon Meow <jperkins@google.com>
Co-authored-by: Geoff Romer <gromer@google.com>
* initial fuzzer proto
* visibility change
* use newer protocol buffer version which has the defs.bzl bug fixed
* Adjusted fix_cc_deps to work with protobuf external repo
* explicitly load rules_cc to avoid a frozenset bug in the version loaded by protobuf
* use explit deps, use llvm's zlib
* restored cxx settings
* deps change
* Cleaned up WORKSPACE and changed the test to read carbon sources from testdata
* updated comment
* adapted to new ErrorOr return value
* proto buffer 3.19.2 -> 3.19.4
* changed comment
* Apply suggestions from code review
Co-authored-by: Jon Meow <jperkins@google.com>
* Apply suggestions from code review
Co-authored-by: Jon Meow <jperkins@google.com>
* Update executable_semantics/fuzzing/BUILD
Co-authored-by: Jon Meow <jperkins@google.com>
* addressed review comments
* updated Unimplemented error message
* Addressed review comments
* more review comments
* switched to loading protobuf via rules_proto()
* Ignore protobuf headers in fix_cc_deps.py until the script supports alias rules
* renamed repeated proto fields to be plural
* added @zlib to check_non_test_cc_deps
* Update common/fuzzing/BUILD
Co-authored-by: Jon Meow <jperkins@google.com>
* review comments
* set is_omitted_expression for return value
Co-authored-by: Jon Meow <jperkins@google.com>
* Modify parser and AST nodes to include let statement
* Implement let variables
* Remove redundant code in fail_match_choice test
* Add comment for has_value_category()
* Apply suggestions from code review
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
* clang-format changes
* Update comments for new BindingPattern methods
* Implement nested vars in patterns
* Apply suggestions from @geoffromer's code review
Co-authored-by: Geoff Romer <gromer@google.com>
* Implement changes from code review.
* Remove maybe_var_pattern grammar rule
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
Co-authored-by: Geoff Romer <gromer@google.com>
* Fixed a couple simple crashes surfaced by running a structured fuzzer on executable_semantics parse/type-check/execute logic.
* var a: b: auto; -> var a: auto;
In the process, switch to an unambiguous grammar, using the
precedence-climbing method for operator precedence (suitably modified to
handle a partial precedence order) rather than Bison %precedence /
%prec.
* adding methods to the ast
* pre commit stuff?
* implementation of class functions
* implemented methods
* some cleanup
* more cleanup
* add newlines in test programs
* pre-commit fixups
* added include of return_term.h
* a test of a method calling another method
* replacing Member with Declaration
* removing the member.h etc files
* clarify a type annotation
* update uses of FunctionDeclaration
* remove ReturnTarget, no longer needed
* more cleanup
* more cleanup
* yet more cleanup, playing with pre-commit
* did a pre-commit run --all-files
* fixed const issue
* remove comment
* checking dependencies in BUILD files and headers
* pre-commit working now
* refactor NominalClassType to just hold a pointer to the class declaration
* remove Member from rtti
* responding to Geoffreys review
* change field_types to a non-member function
* Naive pointer implementation
* Bug fixes and better pointer tests
* Remove debug print statement
* Implement changes suggested by @geoffromer
Also add a failing test case that tests applying the address-of operator
to an rvalue.
* Initial implementation of block string literals following lexical_conventions/string_literals.md.
Enabled yyinput() in flex to implement parsing.
Added ParseBlockStringLiteral() helper to handler further transformations such as indenting.
Modified formar_grammar to support single-quoted strings to prevent a failure on lexer.lpp.
* Fixed _find_string_end quote parameter type int -> str.
* Update executable_semantics/syntax/BUILD
Co-authored-by: Geoff Romer <gromer@google.com>
* Addressed code review comments - split table-drived test into individual tests, renamed constants to match style guide.
* Addressed code review comments -- using EXPECT_THAT_EXPECTED() in tests, lexer comments and code cleanup.
Co-authored-by: Geoff Romer <gromer@google.com>
This required changing BindingPattern::name() to return `"_"` instead of nullopt when representing a `"_"` binding.
Semi-related drive-by fixes:
- Update BindingPlaceholderValue to expose a NamedEntity instead of a string name, and stop exposing its type.
- Drop the unused SourceLocation parameter of ValueEqual
This enables us to stop treating the return type as a Pattern (which is really isn't), treat return types more consistently with other static types in the typechecker, and drop ReturnTypeContext.
Additional changes:
- Merge TypeCheckFunDef with TypeOfFunDef.
- Handle implicit conversions in `return` statements.
- Require function type literals to have an explicit `->`.
- Move consistency check for omitted returns from TypeChecker to ResolveControlFlow.
This avoids needing to have nearly as many rules here which should
reduce its churn.
I've tested that this reaches the exact same set of transitive
dependencies.
Note, only the last commit here is new.
This starts detecting naming collisions as a consequence of being able to determine when the name is declared twice in a given scope.
Co-authored-by: Geoff Romer <gromer@google.com>
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.
The `__Fn` naming is intended to mirror things like `__Continuation`.
The reason for this path is because it's not clear this is the form we'll want, and I think experimental naming will help reflect that.
This was born out of wanting FunctionDeclaration to explicitly have a Block for a body, and became a bit more of specifying types around. Note this forces exec_program to generate a Block for print()'s body, which is probably more correct as now we can expect a standard FunctionDeclaration AST structure, even for the built-ins.
There is a syntactic change here: a continuation's body is now a Block, not just a Statement. I've added an example disallowed test case. I think this is more reasonable syntax.
Other than that, note that optional_else now generates a valid Block. This has me thinking about whether we can eliminate Sequence, but that seemed well out of scope for this.
Arguably missed in #769
Note, this is reminding me we have more class members to rename for `_`, but I felt it's best to use the new naming instead of adding more to clean up.
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.
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.
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>
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.
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).