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.cpp | 75 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) (limited to 'source/slang/slang-ast-type.cpp') diff --git a/source/slang/slang-ast-type.cpp b/source/slang/slang-ast-type.cpp index 27cc7800b..90ed1b8e4 100644 --- a/source/slang/slang-ast-type.cpp +++ b/source/slang/slang-ast-type.cpp @@ -521,8 +521,8 @@ ParameterDirection FuncType::getParamDirection(Index index) void FuncType::_toTextOverride(StringBuilder& out) { - out << toSlice("("); Index paramCount = getParamCount(); + out << toSlice("("); for (Index pp = 0; pp < paramCount; ++pp) { if (pp != 0) @@ -531,7 +531,7 @@ void FuncType::_toTextOverride(StringBuilder& out) } out << getParamType(pp); } - out << toSlice(") -> ") << getResultType(); + out << ") -> " << getResultType(); if (!getErrorType()->equals(getASTBuilder()->getBottomType())) { @@ -634,6 +634,77 @@ HashCode FuncType::_getHashCodeOverride() return hashCode; } +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! TupleType !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +void TupleType::_toTextOverride(StringBuilder& out) +{ + out << toSlice("("); + for (Index pp = 0; pp < memberTypes.getCount(); ++pp) + { + if (pp != 0) + out << toSlice(", "); + out << memberTypes[pp]; + } + out << toSlice(")"); +} + +bool TupleType::_equalsImplOverride(Type * type) +{ + if (const auto other = as(type)) + { + auto paramCount = memberTypes.getCount(); + auto otherParamCount = other->memberTypes.getCount(); + if (paramCount != otherParamCount) + return false; + + for (Index i = 0; i < memberTypes.getCount(); ++i) + { + if(!memberTypes[i]->equals(other->memberTypes[i])) + return false; + } + + return true; + } + return false; +} + +Val* TupleType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff) +{ + int diff = 0; + + // just recurse into the members + List substMemberTypes; + for (auto m : memberTypes) + substMemberTypes.add(as(m->substituteImpl(astBuilder, subst, &diff))); + + // early exit for no change... + if (!diff) + return this; + + (*ioDiff)++; + return astBuilder->create(std::move(substMemberTypes)); +} + +Type* TupleType::_createCanonicalTypeOverride() +{ + // member types + List canMemberTypes; + for (auto m : memberTypes) + { + canMemberTypes.add(m->getCanonicalType()); + } + + return getASTBuilder()->create(std::move(canMemberTypes)); +} + +HashCode TupleType::_getHashCodeOverride() +{ + HashCode hashCode = Slang::getHashCode(kType); + for(auto m : memberTypes) + hashCode = combineHash(hashCode, m->getHashCode()); + return hashCode; +} + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ExtractExistentialType !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! void ExtractExistentialType::_toTextOverride(StringBuilder& out) -- cgit v1.2.3