tint: Clean up legacy type cruft

Fix TODOs dating back to when types were an AST / SEM hybrid concept.
Bring the `arch.md` to reflect how things work today.

Bug: tint:724
Change-Id: I6bf4174158cf490f2839aeed78164b66e3410f27
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/96141
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton
2022-07-15 17:16:49 +00:00
committed by Dawn LUCI CQ
parent 68335f88c3
commit 8b0ceea0b1
2 changed files with 68 additions and 59 deletions

View File

@@ -37,10 +37,9 @@ class Info {
/// Resolves to the return type of the Get() method given the desired sementic
/// type and AST type.
template <typename SEM, typename AST_OR_TYPE>
using GetResultType = std::conditional_t<std::is_same<SEM, InferFromAST>::value,
SemanticNodeTypeFor<AST_OR_TYPE>,
SEM>;
template <typename SEM, typename AST>
using GetResultType =
std::conditional_t<std::is_same<SEM, InferFromAST>::value, SemanticNodeTypeFor<AST>, SEM>;
/// Constructor
Info();
@@ -56,36 +55,36 @@ class Info {
/// @return this Program
Info& operator=(Info&& rhs);
/// Get looks up the semantic information for the AST or type node `node`.
/// @param node the AST or type node
/// Get looks up the semantic information for the AST node `node`.
/// @param ast_node the AST node
/// @returns a pointer to the semantic node if found, otherwise nullptr
template <typename SEM = InferFromAST,
typename AST_OR_TYPE = CastableBase,
typename RESULT = GetResultType<SEM, AST_OR_TYPE>>
const RESULT* Get(const AST_OR_TYPE* node) const {
auto it = map_.find(node);
typename AST = CastableBase,
typename RESULT = GetResultType<SEM, AST>>
const RESULT* Get(const AST* ast_node) const {
auto it = map_.find(ast_node);
if (it == map_.end()) {
return nullptr;
}
return As<RESULT>(it->second);
}
/// Add registers the semantic node `sem_node` for the AST or type node `node`.
/// @param node the AST or type node
/// Add registers the semantic node `sem_node` for the AST node `node`.
/// @param ast_node the AST node
/// @param sem_node the semantic node
template <typename AST_OR_TYPE>
void Add(const AST_OR_TYPE* node, const SemanticNodeTypeFor<AST_OR_TYPE>* sem_node) {
template <typename AST>
void Add(const AST* ast_node, const SemanticNodeTypeFor<AST>* sem_node) {
// Check there's no semantic info already existing for the node
TINT_ASSERT(Semantic, Get(node) == nullptr);
map_.emplace(node, sem_node);
TINT_ASSERT(Semantic, Get(ast_node) == nullptr);
map_.emplace(ast_node, sem_node);
}
/// Replace replaces any existing semantic node `sem_node` for the AST or type node `node`.
/// @param node the AST or type node
/// Replace replaces any existing semantic node `sem_node` for the AST node `node`.
/// @param ast_node the AST node
/// @param sem_node the new semantic node
template <typename AST_OR_TYPE>
void Replace(const AST_OR_TYPE* node, const SemanticNodeTypeFor<AST_OR_TYPE>* sem_node) {
map_[node] = sem_node;
template <typename AST>
void Replace(const AST* ast_node, const SemanticNodeTypeFor<AST>* sem_node) {
map_[ast_node] = sem_node;
}
/// Wrap returns a new Info created with the contents of `inner`.
@@ -110,9 +109,8 @@ class Info {
const sem::Module* Module() const { return module_; }
private:
// TODO(crbug.com/tint/724): Once finished, this map should be:
// std::unordered_map<const ast::Node*, const sem::Node*>
std::unordered_map<const CastableBase*, const CastableBase*> map_;
// The map of AST node to semantic node
std::unordered_map<const ast::Node*, const sem::Node*> map_;
// The semantic module
sem::Module* module_ = nullptr;
};