summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-impl.h
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-05-29 18:01:11 -0700
committerGitHub <noreply@github.com>2024-05-29 18:01:11 -0700
commitefdbb954c57b89362e390f955d45f90e59d66878 (patch)
tree7b47d6e52d2de666af99f66a2fd3a5dc387ca5cc /source/slang/slang-check-impl.h
parent83f176ba8a3bae5533470aed6a90663653f894b8 (diff)
Improve compile time performance. (#3857)
* Handle type check cache update on extensions more gracefully. * Correctness fix. * Cache implcit cast overload resolution results. * Fix. * More optimizations. * Cache implicit default ctor resolution. * Disable redundancy removal. * Fix. * Fix test. * Fix. * Correctness fix. * Fix. * Fix, * Fix test. * Small tweak.
Diffstat (limited to 'source/slang/slang-check-impl.h')
-rw-r--r--source/slang/slang-check-impl.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/source/slang/slang-check-impl.h b/source/slang/slang-check-impl.h
index 569e27e7c..1bb450a6a 100644
--- a/source/slang/slang-check-impl.h
+++ b/source/slang/slang-check-impl.h
@@ -549,6 +549,45 @@ namespace Slang
FacetList facets;
};
+ /// Cached information about how to convert between two types.
+ struct ImplicitCastMethod
+ {
+ OverloadCandidate conversionFuncOverloadCandidate;
+ ConversionCost cost = kConversionCost_Impossible;
+ bool isAmbiguous = false;
+ };
+
+ struct ImplicitCastMethodKey
+ {
+ Type* fromType; // nullptr means default construct.
+ bool isLValue;
+ Type* toType;
+ uint64_t constantVal;
+ bool isConstant;
+ HashCode getHashCode() const
+ {
+ return combineHash(Slang::getHashCode(fromType), Slang::getHashCode(toType), Slang::getHashCode(constantVal), (HashCode32)isConstant, (HashCode32)isLValue);
+ }
+ bool operator == (const ImplicitCastMethodKey& other) const
+ {
+ return fromType == other.fromType && toType == other.toType && isConstant == other.isConstant && constantVal == other.constantVal && isLValue == other.isLValue;
+ }
+ ImplicitCastMethodKey() = default;
+ ImplicitCastMethodKey(QualType fromType, Type* toType, Expr* fromExpr)
+ : fromType(fromType)
+ , toType(toType)
+ , constantVal(0)
+ , isConstant(false)
+ , isLValue(fromType.isLeftValue)
+ {
+ if (auto constInt = as<IntegerLiteralExpr>(fromExpr))
+ {
+ constantVal = constInt->value;
+ isConstant = true;
+ }
+ }
+ };
+
/// Shared state for a semantics-checking session.
struct SharedSemanticsContext
{
@@ -657,6 +696,14 @@ namespace Slang
auto pair = TypePair{ sub, sup };
m_mapTypePairToSubtypeWitness[pair] = outWitness;
}
+ ImplicitCastMethod* tryGetImplicitCastMethod(ImplicitCastMethodKey key)
+ {
+ return m_mapTypePairToImplicitCastMethod.tryGetValue(key);
+ }
+ void cacheImplicitCastMethod(ImplicitCastMethodKey key, ImplicitCastMethod candidate)
+ {
+ m_mapTypePairToImplicitCastMethod[key] = candidate;
+ }
private:
/// Mapping from type declarations to the known extensiosn that apply to them
@@ -776,6 +823,7 @@ namespace Slang
Dictionary<Type*, InheritanceInfo> m_mapTypeToInheritanceInfo;
Dictionary<DeclRef<Decl>, InheritanceInfo> m_mapDeclRefToInheritanceInfo;
Dictionary<TypePair, SubtypeWitness*> m_mapTypePairToSubtypeWitness;
+ Dictionary<ImplicitCastMethodKey, ImplicitCastMethod> m_mapTypePairToImplicitCastMethod;
};
/// Local/scoped state of the semantic-checking system