From ecf85df6eee3da76ef54b14e4ab083f22da89e46 Mon Sep 17 00:00:00 2001 From: Yong He Date: Sun, 18 Aug 2024 21:57:24 -0700 Subject: Variadic Generics Part 2: IR lowering and specialization. (#4849) * Variadic Generics Part 2: IR lowering and specialization. * Update design doc status. * Update design doc. * Resolve review comments. --- source/slang/slang-ast-builder.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-ast-builder.cpp') diff --git a/source/slang/slang-ast-builder.cpp b/source/slang/slang-ast-builder.cpp index faf15470f..3a2b2933d 100644 --- a/source/slang/slang-ast-builder.cpp +++ b/source/slang/slang-ast-builder.cpp @@ -525,7 +525,19 @@ FuncType* ASTBuilder::getFuncType(ArrayView parameters, Type* result, Typ TupleType* ASTBuilder::getTupleType(List& types) { - return getOrCreate(types.getArrayView()); + // The canonical form of a tuple type is always a DeclRefType(GenAppDeclRef(TupleDecl, ConcreteTypePack(types...))). + // If `types` is already a single ConcreteTypePack, then we can use that directly. + if (types.getCount() == 1) + { + if (isTypePack(types[0])) + { + return as(getSpecializedBuiltinType(types[0], "TupleType")); + } + } + + // Otherwise, we need to create a ConcreteTypePack to hold the types. + auto typePack = getTypePack(types.getArrayView()); + return as(getSpecializedBuiltinType(typePack, "TupleType")); } TypeType* ASTBuilder::getTypeType(Type* type) -- cgit v1.2.3