interfaces, impls, and constrained generics (basics) (#1073)

* interfaces, impls, and constrained generics (basics)

* separate type checking into declare vs. type check, removing redundancy

* external impls

* added impl scopes to handle generics calling generics

* cleanup

* more cleanup

* Update executable_semantics/testdata/interface/external_impl_point_vector.carbon

Co-authored-by: josh11b <josh11b@users.noreply.github.com>

* Update executable_semantics/testdata/interface/generic_call_generic.carbon

Co-authored-by: josh11b <josh11b@users.noreply.github.com>

* Update executable_semantics/testdata/interface/tuple_vector_add_scale.carbon

Co-authored-by: josh11b <josh11b@users.noreply.github.com>

* Update executable_semantics/testdata/interface/vector_point_add_scale.carbon

Co-authored-by: josh11b <josh11b@users.noreply.github.com>

* change ImplementationDeclaration to ImplDeclaration

* remove impl_type_value

* split NamedEntity into two

* changed GetName to be a free function

* adding comments

* more edits to respond to review

* introduce ImplBinding, remove punning on GenericBinding

* new test case and some minor edits

* refactor GetMember and GetField to move impl logic to interpreter

* remove commennt

* change EntityView to ImplBinding in FieldAccess...

* move ImplBinding

* review response

* added example to impl_scope.h

* minor edits

* Update executable_semantics/interpreter/field_path.h

Co-authored-by: Geoff Romer <gromer@google.com>

* Update executable_semantics/interpreter/value.cpp

Co-authored-by: Geoff Romer <gromer@google.com>

* Update executable_semantics/interpreter/interpreter.cpp

Co-authored-by: Geoff Romer <gromer@google.com>

* Update executable_semantics/ast/expression.h

Co-authored-by: Geoff Romer <gromer@google.com>

* Update executable_semantics/ast/expression.h

Co-authored-by: Geoff Romer <gromer@google.com>

* Update executable_semantics/ast/generic_binding.h

Co-authored-by: Geoff Romer <gromer@google.com>

* more edits from review

* review response

* Update executable_semantics/ast/static_scope.h

Co-authored-by: Geoff Romer <gromer@google.com>

* remove ImplType, renamed node_view to value_node

Co-authored-by: josh11b <josh11b@users.noreply.github.com>
Co-authored-by: Geoff Romer <gromer@google.com>
This commit is contained in:
Jeremy G. Siek
2022-03-02 15:58:45 -05:00
committed by GitHub
co-authored by josh11b Geoff Romer
parent 8f6e42d866
commit 7cce1bd124
43 changed files with 1722 additions and 441 deletions
+32 -4
View File
@@ -9,10 +9,13 @@
#include <vector>
#include "common/ostream.h"
#include "executable_semantics/ast/static_scope.h"
#include "llvm/Support/Compiler.h"
namespace Carbon {
class Witness;
// Given some initial Value, a FieldPath identifies a sub-Value within it,
// in much the same way that a file path identifies a file within some
// directory. FieldPaths are relative rather than absolute: the initial
@@ -29,8 +32,33 @@ class FieldPath {
// Constructs an empty FieldPath.
FieldPath() = default;
// A single component of the FieldPath, which is typically the name
// of a field. However, inside a generic, when there is a field
// access on something of a generic type, e.g., `T`, then we also
// need `witness`, a pointer to the witness table containing that field.
class Component {
public:
explicit Component(std::string name) : name_(std::move(name)) {}
Component(std::string name, std::optional<Nonnull<const Witness*>> witness)
: name_(std::move(name)), witness_(witness) {}
auto name() const -> const std::string& { return name_; }
auto witness() const -> std::optional<Nonnull<const Witness*>> {
return witness_;
}
void Print(llvm::raw_ostream& out) const { out << name_; }
private:
std::string name_;
std::optional<Nonnull<const Witness*>> witness_;
};
// Constructs a FieldPath consisting of a single step.
explicit FieldPath(std::string name) : components_({std::move(name)}) {}
explicit FieldPath(std::string name)
: components_({Component(std::move(name))}) {}
explicit FieldPath(const Component& f) : components_({f}) {}
FieldPath(const FieldPath&) = default;
FieldPath(FieldPath&&) = default;
@@ -42,11 +70,11 @@ class FieldPath {
// Appends `name` to the end of *this.
auto Append(std::string name) -> void {
components_.push_back(std::move(name));
components_.push_back(Component(std::move(name)));
}
void Print(llvm::raw_ostream& out) const {
for (const std::string& component : components_) {
for (const Component& component : components_) {
out << "." << component;
}
}
@@ -58,7 +86,7 @@ class FieldPath {
// another Value, so its implementation details are tied to the implementation
// details of Value.
friend class Value;
std::vector<std::string> components_;
std::vector<Component> components_;
};
} // namespace Carbon