From ae04e604d43d169bcba7f24c8c23a0fdf4cbb483 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 18 Dec 2024 11:33:55 -0800 Subject: Allow `Optional`, `Tuple` and `bool` to be used in varying input/output. (#5889) * Allow `Optional` and `Tuple` to be used in varying input/output. * Fix. * format code * Fix. * Fix test. * Fix. * enhance test. * Fix. * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang-type-layout.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-type-layout.cpp') diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp index b54f813dd..17f1ae677 100644 --- a/source/slang/slang-type-layout.cpp +++ b/source/slang/slang-type-layout.cpp @@ -4785,10 +4785,18 @@ static TypeLayoutResult _createTypeLayout(TypeLayoutContext& context, Type* type type, rules); } + else if (auto optionalType = as(type)) + { + // OptionalType should be laid out the same way as Tuple. + Array types = + makeArray(optionalType->getValueType(), context.astBuilder->getBoolType()); + auto tupleType = context.astBuilder->getTupleType(types.getView()); + return _createTypeLayout(context, tupleType); + } else if (auto tupleType = as(type)) { // A `Tuple` type is laid out exactly the same way as a `struct` type, - // except that we want have a declref to the field. + // except that we won't have a declref to the field. StructTypeLayoutBuilder typeLayoutBuilder; StructTypeLayoutBuilder pendingDataTypeLayoutBuilder; -- cgit v1.2.3