From baf194e7456ba4568dcf11249896af35b3ce18cc Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Wed, 11 Apr 2018 16:18:29 -0700 Subject: 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` 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 --- source/slang/parameter-binding.cpp | 63 +++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 7 deletions(-) (limited to 'source/slang/parameter-binding.cpp') 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()) + { + ll = leftGlobalGeneric->outer; + continue; + } + if(auto rightGlobalGeneric = rr.As()) + { + 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()) + { + if(auto rightGeneric = rightSubst.As()) + { + if(validateGenericSubstitutionsMatch(context, leftGeneric, rightGeneric, stack)) + { + continue; + } + } + } + else if(auto leftThisType = leftSubst.As()) + { + if(auto rightThisType = rightSubst.As()) + { + if(validateThisTypeSubstitutionsMatch(context, leftThisType, rightThisType, stack)) + { + continue; + } + } + } + return false; } - // TODO: anything else to match? - return true; } -- cgit v1.2.3