From 4aac22da6ae902eca1e7750f4e5b83ba238b5874 Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Tue, 27 Aug 2024 16:47:05 -0400 Subject: Add ability to specialize generic references to functions, types and more (#4909) * More reflection API features. + Lookup methods and members (by string) on types + Fix issue with looking up non-static members through the scope operator '::' + `GenericReflection`: Cast a decl to generic to access unspecialized generic parameter names and constraints + `GenericReflection`: Use `getGenericContainer()` from function, variable or type to access the 'nearest' generic parent along with specialization info + `GenericReflection::getConcreteType` and `GenericReflection::getConcreteIntVal`: to get the concrete type of a param in the context of the reflection object + `GenericReflection::getOuterGenericContainer` to go up one level and get the outer generic declarations (if there are more than one enclosing generic scopes) + `DeclReflection::getParent`: go to parent declaration. + Change `VariableReflection` to be a `DeclRef` rather than a decl (allows us to return properly substituted types for methods, members, and more) * Fix Falcor issue * Initial namespace reflection support * FIx issue with specializing witness tables * Add API method for specializing parameters of a generic decl * Add ability to specialize generic references to functions, types and more This PR adds the following end-points: - `specializeGeneric()` method that can be called on a generic reflection to substitute arguments for generic type and value parameters. It returns another generic reflection, but this time with the appropriate substitution. - `applySpecializations()` method to then copy these specializations onto an existing type or function reflection. - `isSubType()` to check if a type is a subtype of another type (useful to check if a type is differentiable by checking `IDifferentiable`) This PR also: - Adds `DeclReflection::Kind::Namespace` so that namespace containers are correctly reflected when walking the decl-tree. the name can be obtained through `getName()` but there's no need to cast to a namespace (since there's nothing else we can do with a namespace decl) - Fixes an issue with name-based lookups that fail if a type or function is referenced without specializations. Its helpful to be able to form a reference to a function with default substitutions, so that we can we can specialize it later (either directly, or via argument types). * Update slang.h * Fix up naming * Update slang-compiler.h * Update slang-reflection-api.cpp * Update slang.cpp * Update slang.cpp * Update slang.cpp * Use `checkGenericAppWithCheckedArgs` to do specialization * Update slang-reflection-api.cpp * Update slang-check-decl.cpp --- source/slang/slang-syntax.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source/slang/slang-syntax.h') diff --git a/source/slang/slang-syntax.h b/source/slang/slang-syntax.h index cd8f426ea..ba7909aae 100644 --- a/source/slang/slang-syntax.h +++ b/source/slang/slang-syntax.h @@ -180,6 +180,13 @@ namespace Slang List getDefaultSubstitutionArgs(ASTBuilder* astBuilder, SemanticsVisitor* semantics, GenericDecl* genericDecl); + SubstitutionSet makeSubstitutionFromIncompleteSet( + ASTBuilder* astBuilder, + SemanticsVisitor* semantics, + DeclRef genericDeclRef, + Dictionary paramArgMap, + DiagnosticSink* sink); + Val::OperandView findInnerMostGenericArgs(SubstitutionSet subst); ParameterDirection getParameterDirection(VarDeclBase* varDecl); -- cgit v1.2.3