mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Implement canonicalization of Value and Element (#3024)
See arena.h for discussion of what canonicalization means in this context. This is primarily intended to support implementing a memo table of template instantiations to resolve #2951, but could be useful for other purposes as well. Additional changes: - Pass `VTable` constructor parameters by pointer, to avoid the need to define `operator==` and `hash_value` for it. - Clean up the recurring pattern of allocating identical `NamedElement`s on the stack and heap. Instead we always allocate it on the heap and pass it by pointer. - Add `Print()` and `Dump()` to `Bindings` as a debugging convenience. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com> Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
co-authored by
Jon Ross-Perkins
Richard Smith
parent
2c4fff25a8
commit
c93a0e5e42
@@ -8,6 +8,7 @@
|
||||
#include "explorer/ast/impl_binding.h"
|
||||
#include "explorer/ast/pattern.h"
|
||||
#include "explorer/ast/value.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
@@ -41,6 +42,18 @@ auto Bindings::None() -> Nonnull<const Bindings*> {
|
||||
return bindings;
|
||||
}
|
||||
|
||||
void Bindings::Print(llvm::raw_ostream& out) const {
|
||||
out << "{";
|
||||
llvm::ListSeparator sep;
|
||||
for (const auto& [name, value] : args_) {
|
||||
out << sep << *name << " -> " << *value;
|
||||
}
|
||||
for (const auto& [name, value] : witnesses_) {
|
||||
out << sep << *name << " -> " << *value;
|
||||
}
|
||||
out << "}";
|
||||
}
|
||||
|
||||
auto Bindings::SymbolicIdentity(
|
||||
Nonnull<Arena*> arena,
|
||||
llvm::ArrayRef<Nonnull<const GenericBinding*>> bindings)
|
||||
|
||||
Reference in New Issue
Block a user