summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-04-03 11:47:19 -0700
committerGitHub <noreply@github.com>2024-04-03 11:47:19 -0700
commita36983536c5557c713720a13c82398ba1a6c14af (patch)
treec462b4abc5ce5042cf03f09b885dfabf086823b6 /docs
parentf8e038f58ebaade84a42ad63282fe28891c027e3 (diff)
Delete out-of-date notes from user guide. (#3877)
We support partial generic parameter inference today.
Diffstat (limited to 'docs')
-rw-r--r--docs/user-guide/06-interfaces-generics.md24
1 files changed, 1 insertions, 23 deletions
diff --git a/docs/user-guide/06-interfaces-generics.md b/docs/user-guide/06-interfaces-generics.md
index 5b3e89566..9de38e6e3 100644
--- a/docs/user-guide/06-interfaces-generics.md
+++ b/docs/user-guide/06-interfaces-generics.md
@@ -68,28 +68,6 @@ int b = myGenericMethod(obj); // OK, automatic type deduction
You may explicitly specify the concrete type to used for the generic type argument, by providing the types in angular brackets after the method name, or leave it to the compiler to automatically deduce the type from the argument list.
-> #### Note ####
-> Slang currently does not support partial type argument list deduction.
-> For example if you have a generic method that accepts two type arguments:
-> ```
-> void g<T:IFoo, U:IBar>(T a, U b) {...}
-> ```
-> You may either call this method with no explicit type arguments:
-> ```
-> MyType a, b;
-> g(a, b);
-> ```
-> Or with explicit arguments for both generic type parameters:
-> ```
-> g<MyType, MyType>(a,b);
-> ```
-> If you only provide first type argument, Slang will generate an error:
-> ```
-> g<MyType>(a,b); // error, does not work today.
-> ```
-> We plan to support such use in a future version.
-
-
Note that it is important to associate a generic type parameter with a type constraint. In the above example, although the definition of `myGenericMethod` is agnostic of the concrete type `T` will stand for, knowing that `T` conforms to `IFoo` allows the compiler to type-check and pre-compile `myGenericMethod` without needing to substitute `T` with any concrete types first. Similar to languages like C#, Rust, Swift and Java, leaving out the type constraint declaration on type parameter `T` will result in a compile error at the line calling `arg.myMethod` since the compiler cannot verify that `arg` has a member named `myMethod` without any knowledge on `T`. This is a major difference of Slang's generics compared to _templates_ in C++.
While C++ templates are a powerful language mechanism, Slang has followed the path of many other modern programming languages to adopt the more structural and restricted generics feature instead. This enables the Slang compiler to perform type checking early to give more readable error messages, and to speed-up compilation by reusing a lot of work for different instantiations of `myGenericMethod`.
@@ -797,4 +775,4 @@ void test()
{
let rs = f(float3(4), float3(5)); // rs = float3(9,9,9)
}
-``` \ No newline at end of file
+```