diff --git a/source/slang/slang-ast-decl.h b/source/slang/slang-ast-decl.h index 93f8ad9251..226b2d66f8 100644 --- a/source/slang/slang-ast-decl.h +++ b/source/slang/slang-ast-decl.h @@ -379,7 +379,7 @@ enum class ConstructorTags : int MemberwiseCtorForPublicVisibility = 1 << 1, /// Derived classes will call this ctor if they need a memberwise ctor for public and internal members. - /// This ctor may be equal to 'isMemberwiseCtorForPublicVisibility' + /// A ctor with `MemberwiseCtorForInternalVisibility` may also contain 'isMemberwiseCtorForPublicVisibility' MemberwiseCtorForInternalVisibility = 1 << 2, }; diff --git a/source/slang/slang-ast-modifier.h b/source/slang/slang-ast-modifier.h index ec537d4bf2..d7a46e707d 100644 --- a/source/slang/slang-ast-modifier.h +++ b/source/slang/slang-ast-modifier.h @@ -38,7 +38,7 @@ class ToBeSynthesizedModifier : public Modifier {SLANG_AST_CLASS(ToBeSynthesized // Marks that the definition of a decl is synthesized. class SynthesizedModifier : public Modifier { SLANG_AST_CLASS(SynthesizedModifier) }; -// Marks that the definition of a decl is synthesized. +// Marks that the definition of a decl is our $ZeroInit function. class ZeroInitModifier : public Modifier { SLANG_AST_CLASS(ZeroInitModifier) }; // Marks a synthesized variable as local temporary variable. diff --git a/source/slang/slang-check-conversion.cpp b/source/slang/slang-check-conversion.cpp index 1aadae52a8..c2ff0dd4b4 100644 --- a/source/slang/slang-check-conversion.cpp +++ b/source/slang/slang-check-conversion.cpp @@ -68,7 +68,6 @@ namespace Slang return true; } - // bool isSameSimpleExprType(Type* type1, Type* type2) { if (as(type1) && as(type2)) return true; @@ -111,8 +110,8 @@ namespace Slang if (toType->equals(fromExpr->type)) return true; - // `vector` and `vector` may not be copyable, but, we have no choice in this senario but to assume coerce logic - // can resolve such situations + // `vector` and `vector` may not be equal types, but, we have no choice in this senario but to assume coerce logic + // can resolve such situations, otherwise we need to fail if (isSameSimpleExprType(toType, fromExpr->type)) return true; @@ -329,6 +328,7 @@ namespace Slang { // TODO(tfoley): If we can compute the size of the array statically, // then we want to check that there aren't too many initializers present + auto toElementType = toArrayType->getElementType(); if(!toArrayType->isUnsized()) { @@ -618,7 +618,7 @@ namespace Slang } // c. Create InvokeExpr for our valid ConstructorDecl - // We cannot fail anymore, set ioArgIndex to the 'used up arg count'. + // We cannot fail anymore, set `ioArgIndex` to the 'used up arg count'. if (outToExpr) { ioArgIndex = ioArgIndexCandidate; @@ -646,12 +646,12 @@ namespace Slang // If we have a generic being compared to another generic (with different generic arguments) // coerce logic will fail regardless of if generics are valid together. Example is below: // - // MyStruct tmp = {MyStructBase(), 1}; // assume 'U' is unresolved at this point in time but equal to T + // MyStruct tmp = {MyStructBase(), 1}; // Assume 'U' is unresolved at this point in time but equal to T // // To handle this since this is not verifiable coerce logic: // 1. We need to ensure we don't have any matching constructors - // 2. if '1.' is true we can assign the possibly compatible generics and let generic resolution diagnose - // if something makes zero sense. + // 2. if '1.' is true we can assign the possibly compatible generics and let generic resolution + // diagnose an error down the line if types are in-compatible if (auto toGenericType = _getGenericAppDeclRefType(toType)) { diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 5142ab78fd..5acd302158 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -1866,7 +1866,7 @@ namespace Slang addModifier(ctor, m_astBuilder->create()); ctor->addOption(ConstructorTags::Synthesized); - // kIROp_TorchTensorType must only refer to its own type through Host functions + // kIROp_TorchTensorType can only be used in host-callable functions if(auto intrinsicType = decl->findModifier()) if(intrinsicType->irOp == kIROp_TorchTensorType) addModifier(ctor, m_astBuilder->create()); @@ -1961,8 +1961,6 @@ namespace Slang varDecl->initExpr = constructDefaultInitExprForVar(this, varDecl->type, varDecl); } - auto type = varDecl->getType(); - if (auto initExpr = varDecl->initExpr) { // Disable the short-circuiting for static const variable init expression @@ -2010,12 +2008,12 @@ namespace Slang // and filtering them to ones that are applicable // to our "call site" with zero arguments. // - OverloadResolveContext overloadContext; overloadContext.loc = varDecl->nameAndLoc.loc; overloadContext.mode = OverloadResolveContext::Mode::JustTrying; overloadContext.sourceScope = m_outerScope; + auto type = varDecl->getType(); ImplicitCastMethodKey key = ImplicitCastMethodKey(QualType(), type, nullptr); auto ctorMethod = getShared()->tryGetImplicitCastMethod(key); if (ctorMethod) @@ -2513,7 +2511,6 @@ namespace Slang } } - // Annotate ctor as a memberwise ctor. A non synthisized function may be annotated as a memberwise ctor // if it has a compatible parameter list with a memberwise ctor. void _annotateMemberwiseCtorWithVisibility(ConstructorDecl* ctor, DeclVisibility visibility) @@ -2644,6 +2641,7 @@ namespace Slang // $ZeroInit is a synthisized static-function only used In 2 cases: // 1. if `{}` is used inside a `__init()` // 2. if `{}` is used and a user has a 'synthisized __init()` + // // Use of $ZeroInit is only for functionality of `{}` to avoid hacks. { auto zeroInitFunc = m_astBuilder->create(); @@ -8136,6 +8134,7 @@ namespace Slang // auto structDeclType = DeclRefType::create(m_astBuilder, structDecl); + // Collect ctor info struct DeclAndCtorInfo { diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index b2bc2b27c7..90154538f6 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -3741,11 +3741,11 @@ namespace Slang // Slang generally detects recursive type-uses in IR, // This means that DefaultConstruct may crash unless we // track visited types with `visitedTypes.contains(type)` - // to avoid infinite looping of type-checks + // to avoid infinite looping of type-checks. // - // Slang may be asked to default init a `RWTexture2D`. - // If so, `isResourceType(type)` ensures we don't generate - // garbage/ + // Slang may be asked to default init a `RWTexture2D`, + // if so, adding `isResourceType(type)` ensures we don't + // generate garbage for resource types. if (visitedTypes.contains(type) || isResourceType(type)) return emitUndefined(type); visitedTypes.add(type);