diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-04-11 16:18:29 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-04-11 16:18:29 -0700 |
| commit | baf194e7456ba4568dcf11249896af35b3ce18cc (patch) | |
| tree | f75e20db450100d41bfa9c384a8bab0fdc28a749 /source/slang/parameter-binding.cpp | |
| parent | 6322983fa4dc84ef1e9dd8fad54d4c1580436e67 (diff) | |
Introduce an IR-level type system (#481)
* Introduce an IR-level type system
Up to this point, the Slang IR has used the front-end type system to represent types in the IR.
As a result (but ultimately more importantly) the IR representation of generics and specialization has used AST-level concepts embedded in the IR.
For example, to express the specialization of `vector<T,N>` to a concrete type `float` for `T`, we needed an IR operation that could represent the specialization, with operands that somehow represented the type argument `float`.
The whole thing was very complicated.
The big idea of this change is to introduce a new representation in which types in the IR are just ordinary instructions, so that using them as operands makes sense. The hierarchy of IR types closely mirrors the AST-side hierarchy for now, and that will probably be something we should maintain going forward.
In order to make these changes work, though, I also had to do major overhauls of things like the way substitutions are performed, how we check interface conformances, the way lookup through interface types is done, etc. etc. This is a big change, and unfortunately any attempt to summarize it in the commit message wouldn't do it justice.
* Fix 64-bit build warning
* Fix up some clang warnings/errors
Diffstat (limited to 'source/slang/parameter-binding.cpp')
| -rw-r--r-- | source/slang/parameter-binding.cpp | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp index 572235280..4378cb06b 100644 --- a/source/slang/parameter-binding.cpp +++ b/source/slang/parameter-binding.cpp @@ -548,23 +548,72 @@ static bool validateGenericSubstitutionsMatch( return true; } +static bool validateThisTypeSubstitutionsMatch( + ParameterBindingContext* /*context*/, + ThisTypeSubstitution* /*left*/, + ThisTypeSubstitution* /*right*/, + StructuralTypeMatchStack* /*stack*/) +{ + // TODO: actual checking. + return true; +} + static bool validateSpecializationsMatch( ParameterBindingContext* context, SubstitutionSet left, SubstitutionSet right, StructuralTypeMatchStack* stack) { - if(!validateGenericSubstitutionsMatch( - context, - left.genericSubstitutions, - right.genericSubstitutions, - stack)) + auto ll = left.substitutions; + auto rr = right.substitutions; + for(;;) { + // Skip any global generic substitutions. + if(auto leftGlobalGeneric = ll.As<GlobalGenericParamSubstitution>()) + { + ll = leftGlobalGeneric->outer; + continue; + } + if(auto rightGlobalGeneric = rr.As<GlobalGenericParamSubstitution>()) + { + rr = rightGlobalGeneric->outer; + continue; + } + + // If either ran out, then we expect both to have run out. + if(!ll || !rr) + return !ll && !rr; + + auto leftSubst = ll; + auto rightSubst = rr; + + ll = ll->outer; + rr = rr->outer; + + if(auto leftGeneric = leftSubst.As<GenericSubstitution>()) + { + if(auto rightGeneric = rightSubst.As<GenericSubstitution>()) + { + if(validateGenericSubstitutionsMatch(context, leftGeneric, rightGeneric, stack)) + { + continue; + } + } + } + else if(auto leftThisType = leftSubst.As<ThisTypeSubstitution>()) + { + if(auto rightThisType = rightSubst.As<ThisTypeSubstitution>()) + { + if(validateThisTypeSubstitutionsMatch(context, leftThisType, rightThisType, stack)) + { + continue; + } + } + } + return false; } - // TODO: anything else to match? - return true; } |
