* 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>
* 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.
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.
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.
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.
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
Sorry about the big change, this is hard to split. ParenContents is used by both, templated, and expects the same pointer type. While I could duplicate ParenContents with some ExpressionParenContents or PatternParenContents, that seems a little kludgy versus a single large change handling both. The worst of it is that Expression is already pretty sweeping, Pattern is really just incrementally adding.
That said, I believe this includes a couple fixes I found with incorrect use of dyn_cast in typecheck.cpp (checked nullptr at the wrong step in 2 code locations). There's also a missing `*` in member.cpp this caught. I adjust passing of expressions for Return due to nullness (I felt adding another constructor was the best solution).
I add a `.Release()` to BisonWrap due to things like `$3.first` needing some way to work through BIsonWrap. I felt this was better than `operator->`, but feel free to comment if you prefer the other path (`.Release()` conveniently lets me do pair unwrapping, so it felt a better solution).
I do add a TODO to think about better Ptr-to-Ptr cast<> support too, though, as that doesn't work cleanly with LLVM's infra. But so far it seems to only come up in one spot, so I'm not prioritizing it.
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>
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.
`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>
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>
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
- 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.
Also:
- Switch data members, and associated parameters and return types to be values/references rather than pointers, where applicable.
- Move Expression's TagVisitor to anonymous namespace, to avoid name collision.
- Switch to trailing return syntax (per style guide).
Pretty much any names will be awkward, since these types represent cases where an `Expression` is not an expression, and a `Value` is not a value, but we can at least be more explicit about the fact that they represent bindings rather than variable usages.
- `Kind` enumerator names always match the corresponding factory function, accessor, and type names (if any).
- All abbreviations in those names are expanded.
- Those names always have a suffix to disambiguate expressions from values.
`VarTV` is excluded from these changes because there's a pending PR to remove it.
This ensures that the factory functions correspond 1:1 with expression kinds, and MakeOp covers their use cases with minimal syntactic overhead now that it can take initializer list arguments.
The presence or absence of whitespace is used to determine which
operator is in use, following the rules described in #520.
Support for prefix * dereference operator follows #523.
Co-authored-by: Geoff Romer <gromer@google.com>