From 332f60c19336252d907b83882aa70665ca93a9d2 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Fri, 12 May 2023 04:33:21 +0800 Subject: MVP for higher order functions (#2849) * MVP for higher order functions * Add shader subgroup partitioned glsl intrinsics * Implement parsing and checking for tuple types Currently there is no way to do anything useful with them from the source language however * neaten * Correct precedence of function type parsing * neaten * higher order function tests * function types of any arity * Inference for higher order functions * Add second test for unsynchronized params * regenerate vs projects * dx11 -> dx12 for saturated cooperations tests * Disable saturated cooperation tests on vulkan They fail on release builds in CI, not essential for the higher order function work however * remove saturated-cooperation tests * Remove unnecessary assert and clarify control flow in AddDeclRefOverloadCandidates * Add Tuple type name mangling * Use functype keyword to introduce function types * Add more inference tests for hof --------- Co-authored-by: Yong He --- source/slang/slang-ast-builder.h | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'source/slang/slang-ast-builder.h') diff --git a/source/slang/slang-ast-builder.h b/source/slang/slang-ast-builder.h index c39293914..1ef56894b 100644 --- a/source/slang/slang-ast-builder.h +++ b/source/slang/slang-ast-builder.h @@ -151,6 +151,25 @@ public: /// no need for additional state. Dictionary m_cachedNodes; + template + static void addOrAppendToNodeList(ShortList&) + {} + + template + static void addOrAppendToNodeList(ShortList& list, T t, Ts... ts) + { + list.add(t); + addOrAppendToNodeList(list, ts...); + } + + template + static void addOrAppendToNodeList(ShortList& list, const List& l, Ts... ts ) + { + for(auto t : l) + list.add(t); + addOrAppendToNodeList(list, ts...); + } + public: // For compile time check to see if thing being constructed is an AST type @@ -174,11 +193,11 @@ public: } template - T* create(TArgs... args) + T* create(TArgs&&... args) { auto alloced = m_arena.allocate(sizeof(T)); memset(alloced, 0, sizeof(T)); - return _initAndAdd(new (alloced) T(args...)); + return _initAndAdd(new (alloced) T(std::forward(args)...)); } template @@ -187,7 +206,7 @@ public: SLANG_COMPILE_TIME_ASSERT(IsValidType::Value); NodeDesc desc; desc.type = T::kType; - addToList(desc.operands, args...); + addOrAppendToNodeList(desc.operands, args...); return (T*)_getOrCreateImpl(desc, [&]() { return create(args...); @@ -210,7 +229,7 @@ public: SLANG_COMPILE_TIME_ASSERT(IsValidType::Value); NodeDesc desc; desc.type = T::kType; - addToList(desc.operands, args...); + addOrAppendToNodeList(desc.operands, args...); return (T*)_getOrCreateImpl(desc, [&]() { return create(); @@ -367,6 +386,10 @@ public: Val* getSNormModifierVal(); Val* getNoDiffModifierVal(); + Type* getTupleType(List& types); + + Type* getFuncType(List parameters, Type* result); + TypeType* getTypeType(Type* type); /// Helpers to get type info from the SharedASTBuilder -- cgit v1.2.3