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-type.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'source/slang/slang-ast-type.h') diff --git a/source/slang/slang-ast-type.h b/source/slang/slang-ast-type.h index 67288a59d..7da7ecc88 100644 --- a/source/slang/slang-ast-type.h +++ b/source/slang/slang-ast-type.h @@ -664,6 +664,15 @@ class FuncType : public Type { SLANG_AST_CLASS(FuncType) + // Construct a unary function + FuncType(Type* paramType, Type* resultType, Type* errorType) + : paramTypes{{paramType}}, resultType{resultType}, errorType{errorType} + {} + + FuncType(List parameters, Type* result, Type* error) + : paramTypes(std::move(parameters)), resultType(result), errorType(error) + {} + // TODO: We may want to preserve parameter names // in the list here, just so that we can print // out friendly names when printing a function @@ -689,6 +698,29 @@ class FuncType : public Type HashCode _getHashCodeOverride(); }; +// A tuple is a product of its member types +class TupleType : public Type +{ + SLANG_AST_CLASS(TupleType) + + // Construct a unary tupletion + TupleType(List memberTypes) + : memberTypes(std::move(memberTypes)) + {} + + auto getMemberCount() { return memberTypes.getCount(); } const + auto& getMember(Index i) { return memberTypes[i]; } + + List memberTypes; + + // Overrides should be public so base classes can access + void _toTextOverride(StringBuilder& out); + Type* _createCanonicalTypeOverride(); + Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff); + bool _equalsImplOverride(Type* type); + HashCode _getHashCodeOverride(); +}; + // The "type" of an expression that names a generic declaration. class GenericDeclRefType : public Type { -- cgit v1.2.3