@@ -46,7 +46,7 @@ std::string inline getKindName<swift::TypeRepr, swift::TypeReprKind>(swift::Type
4646
4747} // namespace detail
4848
49- // The main reponsibilities of the SwiftDispatcher are as follows:
49+ // The main responsibilities of the SwiftDispatcher are as follows:
5050// * redirect specific AST node emission to a corresponding visitor (statements, expressions, etc.)
5151// * storing TRAP labels for emitted AST nodes (in the TrapLabelStore) to avoid re-emission
5252// Since SwiftDispatcher sees all the AST nodes, it also attaches a location to every 'locatable'
@@ -72,19 +72,28 @@ class SwiftDispatcher {
7272 }
7373
7474 private:
75+ // types to be supported by assignNewLabel/fetchLabel need to be listed here
76+ using Store = TrapLabelStore<swift::Decl,
77+ swift::Stmt,
78+ swift::Expr,
79+ swift::Pattern,
80+ swift::TypeRepr,
81+ swift::TypeBase>;
82+
7583 // This method gives a TRAP label for already emitted AST node.
7684 // If the AST node was not emitted yet, then the emission is dispatched to a corresponding
7785 // visitor (see `visit(T *)` methods below).
7886 template <typename E>
79- TrapLabel<ToTag<E> > fetchLabel (E* e) {
87+ TrapLabelOf<E > fetchLabel (E* e) {
8088 // this is required so we avoid any recursive loop: a `fetchLabel` during the visit of `e` might
8189 // end up calling `fetchLabel` on `e` itself, so we want the visit of `e` to call `fetchLabel`
82- // only after having called `assignNewLabel` on `e`
83- assert (!waitingForNewLabel && " fetchLabel called before assignNewLabel" );
90+ // only after having called `assignNewLabel` on `e`.
91+ assert (holds_alternative<std::monostate>(waitingForNewLabel) &&
92+ " fetchLabel called before assignNewLabel" );
8493 if (auto l = store.get (e)) {
8594 return *l;
8695 }
87- waitingForNewLabel = getCanonicalPointer (e) ;
96+ waitingForNewLabel = e ;
8897 visit (e);
8998 if (auto l = store.get (e)) {
9099 if constexpr (!std::is_base_of_v<swift::TypeBase, E>) {
@@ -100,12 +109,12 @@ class SwiftDispatcher {
100109 // it actually gets emitted to handle recursive cases such as recursive calls, or recursive type
101110 // declarations
102111 template <typename E>
103- TrapLabel<ToTag<E> > assignNewLabel (E* e) {
104- assert (waitingForNewLabel == getCanonicalPointer (e) && " assignNewLabel called on wrong entity" );
105- auto label = getLabel<ToTag <E>>();
112+ TrapLabelOf<E > assignNewLabel (E* e) {
113+ assert (waitingForNewLabel == Store::Handle{e} && " assignNewLabel called on wrong entity" );
114+ auto label = getLabel<TrapTagOf <E>>();
106115 trap.assignStar (label);
107116 store.insert (e, label);
108- waitingForNewLabel = nullptr ;
117+ waitingForNewLabel = std::monostate{} ;
109118 return label;
110119 }
111120
@@ -167,8 +176,8 @@ class SwiftDispatcher {
167176 const swift::SourceManager& sourceManager;
168177 TrapArena& arena;
169178 TrapOutput& trap;
170- TrapLabelStore store;
171- const void * waitingForNewLabel{nullptr };
179+ Store store;
180+ Store::Handle waitingForNewLabel{std::monostate{} };
172181};
173182
174183} // namespace codeql
0 commit comments