Skip to content

Commit

Permalink
cleanup code & comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ArielG-NV authored and kaizhangNV committed Sep 18, 2024
1 parent be77233 commit eeb6e8b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion source/slang/slang-ast-decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
2 changes: 1 addition & 1 deletion source/slang/slang-ast-modifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions source/slang/slang-check-conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ namespace Slang
return true;
}

//
bool isSameSimpleExprType(Type* type1, Type* type2)
{
if (as<BasicExpressionType>(type1) && as<BasicExpressionType>(type2)) return true;
Expand Down Expand Up @@ -111,8 +110,8 @@ namespace Slang
if (toType->equals(fromExpr->type))
return true;

// `vector<T,N>` and `vector<T,U>` may not be copyable, but, we have no choice in this senario but to assume coerce logic
// can resolve such situations
// `vector<T,N>` and `vector<T,U>` 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;

Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<T> tmp = {MyStructBase<U>(), 1}; // assume 'U' is unresolved at this point in time but equal to T
// MyStruct<T> tmp = {MyStructBase<U>(), 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))
{
Expand Down
9 changes: 4 additions & 5 deletions source/slang/slang-check-decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,7 @@ namespace Slang
addModifier(ctor, m_astBuilder->create<SynthesizedModifier>());
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<IntrinsicTypeModifier>())
if(intrinsicType->irOp == kIROp_TorchTensorType)
addModifier(ctor, m_astBuilder->create<CudaHostAttribute>());
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<FuncDecl>();
Expand Down Expand Up @@ -8136,6 +8134,7 @@ namespace Slang
//

auto structDeclType = DeclRefType::create(m_astBuilder, structDecl);

// Collect ctor info
struct DeclAndCtorInfo
{
Expand Down
8 changes: 4 additions & 4 deletions source/slang/slang-ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit eeb6e8b

Please sign in to comment.