From a2d90fb275962da84611160f8ddd74d934a68dbd Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 4 Aug 2023 15:47:39 -0700 Subject: Redesign `DeclRef` and systematic `Val` deduplication (#3049) * Redesign DeclRef + Deduplicate Val. * Update project files * Fix warning. * Fix. * Fix. * Remove `Val::_equalsImplOverride`. * Rmove `Val::_getHashCodeOverride`. * Remove `semanticVisitor` param from `resolve`. * Cleanups. --------- Co-authored-by: Yong He --- source/slang/slang-ast-natural-layout.cpp | 46 ++++++++----------------------- 1 file changed, 12 insertions(+), 34 deletions(-) (limited to 'source/slang/slang-ast-natural-layout.cpp') diff --git a/source/slang/slang-ast-natural-layout.cpp b/source/slang/slang-ast-natural-layout.cpp index 1789c5cea..4a4ef37fb 100644 --- a/source/slang/slang-ast-natural-layout.cpp +++ b/source/slang/slang-ast-natural-layout.cpp @@ -70,9 +70,9 @@ Count ASTNaturalLayoutContext::_getCount(IntVal* intVal) { if (auto constIntVal = as(intVal)) { - if (constIntVal->value >= 0) + if (constIntVal->getValue() >= 0) { - return Count(constIntVal->value); + return Count(constIntVal->getValue()); } } @@ -115,9 +115,9 @@ NaturalSize ASTNaturalLayoutContext::_calcSizeImpl(Type* type) { if (VectorExpressionType* vecType = as(type)) { - const Count elementCount = _getCount(vecType->elementCount); + const Count elementCount = _getCount(vecType->getElementCount()); return (elementCount > 0) ? - calcSize(vecType->elementType) * elementCount : + calcSize(vecType->getElementType()) * elementCount : NaturalSize::makeInvalid(); } else if (auto matType = as(type)) @@ -130,7 +130,7 @@ NaturalSize ASTNaturalLayoutContext::_calcSizeImpl(Type* type) } else if (auto basicType = as(type)) { - return NaturalSize::makeFromBaseType(basicType->baseType); + return NaturalSize::makeFromBaseType(basicType->getBaseType()); } else if (as(type) || as(type)) { @@ -146,7 +146,7 @@ NaturalSize ASTNaturalLayoutContext::_calcSizeImpl(Type* type) } else if (auto namedType = as(type)) { - return calcSize(namedType->innerType); + return calcSize(namedType->getCanonicalType()); } else if (const auto tupleType = as(type)) { @@ -154,9 +154,9 @@ NaturalSize ASTNaturalLayoutContext::_calcSizeImpl(Type* type) NaturalSize size = NaturalSize::makeEmpty(); // Accumulate over all the member types - for (auto cur : tupleType->memberTypes) + for (auto cur = 0; cur < tupleType->getMemberCount(); cur++) { - const auto curSize = calcSize(cur); + const auto curSize = calcSize(tupleType->getMember(cur)); if (!curSize) { return NaturalSize::makeInvalid(); @@ -166,36 +166,14 @@ NaturalSize ASTNaturalLayoutContext::_calcSizeImpl(Type* type) return size; } - else if (const auto taggedUnion = as(type)) - { - NaturalSize size = NaturalSize::makeInvalid(); - - for( auto caseType : taggedUnion->caseTypes ) - { - const NaturalSize caseSize = calcSize(caseType); - if (!caseSize) - { - return NaturalSize::makeInvalid(); - } - size = NaturalSize::calcUnion(size, caseSize); - } - - // After we've computed the size required to hold all the - // case types, we will allocate space for the tag field. - - // Currently we assume uint32_t on all targets - size.append(NaturalSize::makeFromBaseType(BaseType::UInt)); - - return size; - } else if( auto declRefType = as(type) ) { - if (const auto enumDeclRef = declRefType->declRef.as()) + if (const auto enumDeclRef = declRefType->getDeclRef().as()) { Type* tagType = getTagType(m_astBuilder, enumDeclRef); return calcSize(tagType); } - else if(const auto structDeclRef = declRefType->declRef.as()) + else if(const auto structDeclRef = declRefType->getDeclRef().as()) { // Poison the cache whilst we construct m_typeToSize.add(type, NaturalSize::makeInvalid()); @@ -208,7 +186,7 @@ NaturalSize ASTNaturalLayoutContext::_calcSizeImpl(Type* type) // Look for a struct type that it inherits from if (auto inheritedDeclRef = as(inherited->base.type)) { - if (auto parentDecl = inheritedDeclRef->declRef.as()) + if (auto parentDecl = inheritedDeclRef->getDeclRef().as()) { // We can only inherit from one thing size = calcSize(inherited->base.type); @@ -237,7 +215,7 @@ NaturalSize ASTNaturalLayoutContext::_calcSizeImpl(Type* type) return size; } - else if (const auto typeDef = declRefType->declRef.as()) + else if (const auto typeDef = declRefType->getDeclRef().as()) { return calcSize(typeDef.getDecl()->type); } -- cgit v1.2.3