summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-conformance.cpp
diff options
context:
space:
mode:
authorArielG-NV <159081215+ArielG-NV@users.noreply.github.com>2024-06-12 12:46:24 -0400
committerGitHub <noreply@github.com>2024-06-12 09:46:24 -0700
commitb7e824347a5de25cc013af30e43bd405b8b5698f (patch)
tree74f477e883add12978d1586c89814364d8a1f275 /source/slang/slang-check-conformance.cpp
parentccc26c2d22d471ae649bf16f37ed1cd6cfbddd1b (diff)
Add slangc flag to `-zero-initialize` all variables (#3987)
* Default (zero'd) values with `-zero-initialize` flag Adds `-zero-initialize` flag to set values to a __default() expression if they are missing a initExpr. * address review and ensure __default calls ctor + zero's fields. 1. We must keep zero-initialize in SemanticsDeclHeaderVisitor. This is done because else a ctor will be initialized before we can set struct fields to `__default`. 2. IRDefaultCtorDecoration was added to track default ctor's with parent struct. 3. ParentAggTypeModifier was added to track ChildOfStruct->IRType for sharing data such as with functions. This is required to ensure we associate a lowered function with a lowered struct type * Removed decoration to track defaultCtor in favor of field. This was done since decorations are checked for IR objects, storing auxillary info does not work here as a result if usable object. * address some review comments Since `IDefaultInitializable` is taking a considerabley larger amount of time than anticipated I am pushing some of the other fixes requested. I did not remove the "IRStruct storing a default Ctor" hack yet. mostly renamed/adjusted tests to work as intended added test to ensure we don't synthisize a junk `= 0` when not in `zero initialize` mode removed member in favor of sharedContext+dictionary. * a working but incorrect impl * default init without any IR hacks (fully working aside from generic/containored-types) * Finish zero init code 1. IDefaultInitializer interface was added. If conforming, your type may be zero-initialized. To Conform a `__init()` is required 2. `[OnlyAutoInitIfForced]` was added. This attribute states that a default initializer should only be implicitly called if forced by the compiler (`zero-initialize` for example). This allows types which implicitly/explicitly conform to IDefaultInitialize to have optional auto-init behavior (which is Slang's default for user structs) to be disabled. * note about `[OnlyAutoInitIfForced]`. This is required for std-lib to not automatically resolve init-expressions for std-lib, but it has the added benifit of allowing user made structs/classes to control the default behavior of initializing * fix ErrType assumption * testing why dx12 fails local but passes CI * push vector changes to generic test * push syntax adjustment, still figuring out what is wrong with cuda. * remove debug changes & adjust style * fix field-init expressions with structs initializers don't init a static in a ctor. This would be illegal code and wrong code (init list in lower-to-ir) * minor adjustments temporarily while the rest of the issue is discussed * fix * implement IDefaultInitializable * remove a unneeded whitespace change * fix type checking error should be checking if a valid type is `Type`, not `BasicExpressionType` * needs to be DeclRefType, not Type * fix langguage server error * change findinheritance for correctness + cleanup * remove return false verified the issue was `findInheritance` * push attempt at language server fix * still trying to fix inheritance * added extension support, remove redundant code Did not address all review comments yet, want to see if CI also passes my changes * undo a change which caused CI to fail * change logic + DefaultConstructExpr setup code to use defaultConstructExpr when possible to construct a default without overhead of invoke/related also changed code so parent's defaultInitializable propegates to derived member * 1. fix error in `isSubtype` 2. add flag to isSubtype `subtypeInheritanceIsNotFullyResolved` was added since we may not be done the lookup stage but still require `isSubtype` checking to verify usage of inheritance while working with inheritance. In This case we will just skip `ensureLookup` and "caching" (since we don't have a cache invalidation system, nor need) * fix bug in logic + add test to better catch the bug * address comment + isSubTypeOption + wrapper type test, * fix wrong code adjustment I checked on the CI and realized I caused a failure, mistake was made not negating some code * syntax, class naming capital * remove stdlib default initialize changes, replace with `__default()` for init * remove redundant code + fix defaultConstruct emitting previously defaultConstruct emitting was crashing due to having generics unresolved. By not resolving the default construct immediately, everything works. * remove a coment * add test to ensure static variables dont `init` inside a struct's `__init` * fix Ptr members breaking struct use * address review and add -zero-initialize test `-zero-initialize` test was added to be sure debug pointers are not broken with default init values --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-check-conformance.cpp')
-rw-r--r--source/slang/slang-check-conformance.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/source/slang/slang-check-conformance.cpp b/source/slang/slang-check-conformance.cpp
index 59547ef0a..0ff4bfed4 100644
--- a/source/slang/slang-check-conformance.cpp
+++ b/source/slang/slang-check-conformance.cpp
@@ -51,19 +51,26 @@ namespace Slang
SubtypeWitness* SemanticsVisitor::isSubtype(
Type* subType,
- Type* superType)
+ Type* superType,
+ IsSubTypeOptions isSubTypeOptions
+ )
{
SubtypeWitness* result = nullptr;
if (getShared()->tryGetSubtypeWitnessFromCache(subType, superType, result))
return result;
- result = checkAndConstructSubtypeWitness(subType, superType);
+ result = checkAndConstructSubtypeWitness(subType, superType, isSubTypeOptions);
+
+ if(int(isSubTypeOptions) & int(IsSubTypeOptions::NotReadyForLookup))
+ return result;
+
getShared()->cacheSubtypeWitness(subType, superType, result);
return result;
}
SubtypeWitness* SemanticsVisitor::checkAndConstructSubtypeWitness(
Type* subType,
- Type* superType)
+ Type* superType,
+ IsSubTypeOptions isSubTypeOptions)
{
// TODO: The Slang codebase is currently being quite slippery by conflating
// multiple concepts, all under the banner of a "subtype" test:
@@ -105,11 +112,14 @@ namespace Slang
// tangling convertibility into it.
// First, make sure both sub type and super type decl are ready for lookup.
- if (auto subDeclRefType = as<DeclRefType>(subType))
+ if ( !(int(isSubTypeOptions) & int(IsSubTypeOptions::NotReadyForLookup)) )
{
- ensureDecl(subDeclRefType->getDeclRef().getDecl(), DeclCheckState::ReadyForLookup);
+ if (auto subDeclRefType = as<DeclRefType>(subType))
+ {
+ ensureDecl(subDeclRefType->getDeclRef().getDecl(), DeclCheckState::ReadyForLookup);
+ }
}
- if (auto superDeclRefType = as<DeclRefType>(subType))
+ if (auto superDeclRefType = as<DeclRefType>(superType))
{
ensureDecl(superDeclRefType->getDeclRef().getDecl(), DeclCheckState::ReadyForLookup);
}
@@ -189,10 +199,10 @@ namespace Slang
// We therefore simply recursively test both `T <: L`
// and `T <: R`.
//
- auto leftWitness = isSubtype(subType, conjunctionSuperType->getLeft());
+ auto leftWitness = isSubtype(subType, conjunctionSuperType->getLeft(), IsSubTypeOptions::None);
if (!leftWitness) return nullptr;
//
- auto rightWitness = isSubtype(subType, conjunctionSuperType->getRight());
+ auto rightWitness = isSubtype(subType, conjunctionSuperType->getRight(), IsSubTypeOptions::None);
if (!rightWitness) return nullptr;
// If both of the sub-relationships hold, we can construct
@@ -238,7 +248,7 @@ namespace Slang
bool SemanticsVisitor::isTypeDifferentiable(Type* type)
{
- return isSubtype(type, m_astBuilder->getDiffInterfaceType());
+ return isSubtype(type, m_astBuilder->getDiffInterfaceType(), IsSubTypeOptions::None);
}
bool SemanticsVisitor::doesTypeHaveTag(Type* type, TypeTag tag)
@@ -319,7 +329,7 @@ namespace Slang
Type* type,
Type* interfaceType)
{
- return isSubtype(type, interfaceType);
+ return isSubtype(type, interfaceType, IsSubTypeOptions::None);
}
TypeEqualityWitness* SemanticsVisitor::createTypeEqualityWitness(