diff options
| author | Yong He <yonghe@outlook.com> | 2020-08-21 01:10:45 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-21 01:10:45 -0700 |
| commit | a8bc5983eae60ca37e853041e989a654c1247876 (patch) | |
| tree | 330cae10c2c24ba14ca726b61c576d9f362f5b8e /source/slang/slang-check-conformance.cpp | |
| parent | 11748a75e66c2bd3fa7ef7635fd35363465f599c (diff) | |
Allow calling a generic function with an existential value (dynamic dispatch) (#1508)
* Allow calling a generic function with an existential value (dynamic dispatch).
* Fixes per review comments.
* Clean up implementation by having `openExistential` return `ExtractExistentialType` instead of a DeclRef to the interface with a `ThisTypeSubstitution`.
* More cleanups
Co-authored-by: Tim Foley <tfoleyNV@users.noreply.github.com>
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-check-conformance.cpp')
| -rw-r--r-- | source/slang/slang-check-conformance.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/source/slang/slang-check-conformance.cpp b/source/slang/slang-check-conformance.cpp index 4dcfb3065..e1904dc71 100644 --- a/source/slang/slang-check-conformance.cpp +++ b/source/slang/slang-check-conformance.cpp @@ -268,6 +268,30 @@ namespace Slang } } } + else if (auto extractExistentialType = as<ExtractExistentialType>(subType)) + { + // An ExtractExistentialType from an existential value of type I + // is a subtype of I. + // We need to check and make sure the interface type of the `ExtractExistentialType` + // is equal to `superType`. + auto interfaceDeclRef = extractExistentialType->interfaceDeclRef; + auto thisTypeSubst = findThisTypeSubstitution(interfaceDeclRef.substitutions.substitutions, interfaceDeclRef.getDecl()); + SLANG_ASSERT(thisTypeSubst && thisTypeSubst == interfaceDeclRef.substitutions.substitutions); + // The interfaceDeclRef in `extractExistentialType` contains a `ThisTypeSubstitution` + // to allow member lookup to return correct substituted types. Here we just need + // to know if that interface is the same as the superType, so we need to exclude + // the `ThisTypeSubstitution` from comparison. + interfaceDeclRef.substitutions.substitutions = thisTypeSubst->outer; + if (interfaceDeclRef.equals(superTypeDeclRef)) + { + if (outWitness) + { + *outWitness = thisTypeSubst->witness; + } + return true; + } + return false; + } else if(auto taggedUnionType = as<TaggedUnionType>(subType)) { // A tagged union type conforms to an interface if all of |
