forked from gopherjs/gopherjs
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rudimentary support for passing type parameters into generic functions.
Instead of generating an independent function instance for every combination of type parameters at compile time we construct generic function instances at runtime using "generic factory functions". Such a factory takes type params as arguments and returns a concrete instance of the function for the given type params (type param values are captured by the returned function as a closure and can be used as necessary). Here is an abbreviated example of how a generic function is compiled and called: ``` // Go: func F[T any](t T) {} f(1) // JS: F = function(T){ return function(t) {}; }; F($Int)(1); ``` This approach minimizes the size of the generated JS source, which is critical for the client-side use case, at the cost of runtime performance. See gopherjs#1013 (comment) for the detailed description. Note that the implementation in this commit is far from complete: - Generic function instances are not cached. - Generic types are not supported. - Declaring types dependent on type parameters doesn't work correctly. - Operators (such as `+`) do not work correctly with generic arguments.
- Loading branch information
1 parent
900dda7
commit 0406604
Showing
4 changed files
with
123 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters