-
-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[shader-ast] Allow type inference of defn with arbitrary number of arguments #440
Open
sylee957
wants to merge
2
commits into
thi-ng:develop
Choose a base branch
from
sylee957:shader-ast/variadic
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import type { Fn, Fn0, Fn2, Fn3, Fn4, Fn5, Fn6, Fn7, Fn8 } from "@thi.ng/api"; | ||
import type { FnCall, Sym, Term } from "./nodes.js"; | ||
import type { SymOpts } from "./syms.js"; | ||
import type { Type } from "./types.js"; | ||
|
@@ -7,40 +6,39 @@ export type ScopeBody = (Term<any> | null | undefined)[]; | |
|
||
export type Arg<A extends Type> = A | [A, string?, SymOpts?]; | ||
|
||
export type Arg1<A extends Type> = [Arg<A>]; | ||
|
||
export type Arg2<A extends Type, B extends Type> = [Arg<A>, Arg<B>]; | ||
|
||
export type Arg3<A extends Type, B extends Type, C extends Type> = [ | ||
Arg<A>, | ||
Arg<B>, | ||
Arg<C> | ||
]; | ||
|
||
/** @deprecated */ | ||
export type Arg1<A extends Type> = VariadicArgs<[A]>; | ||
/** @deprecated */ | ||
export type Arg2<A extends Type, B extends Type> = VariadicArgs<[A, B]>; | ||
/** @deprecated */ | ||
export type Arg3<A extends Type, B extends Type, C extends Type> = VariadicArgs< | ||
[A, B, C] | ||
>; | ||
/** @deprecated */ | ||
export type Arg4< | ||
A extends Type, | ||
B extends Type, | ||
C extends Type, | ||
D extends Type | ||
> = [Arg<A>, Arg<B>, Arg<C>, Arg<D>]; | ||
|
||
> = VariadicArgs<[A, B, C, D]>; | ||
/** @deprecated */ | ||
export type Arg5< | ||
A extends Type, | ||
B extends Type, | ||
C extends Type, | ||
D extends Type, | ||
E extends Type | ||
> = [Arg<A>, Arg<B>, Arg<C>, Arg<D>, Arg<E>]; | ||
|
||
> = VariadicArgs<[A, B, C, D, E]>; | ||
/** @deprecated */ | ||
export type Arg6< | ||
A extends Type, | ||
B extends Type, | ||
C extends Type, | ||
D extends Type, | ||
E extends Type, | ||
F extends Type | ||
> = [Arg<A>, Arg<B>, Arg<C>, Arg<D>, Arg<E>, Arg<F>]; | ||
|
||
> = VariadicArgs<[A, B, C, D, E, F]>; | ||
/** @deprecated */ | ||
export type Arg7< | ||
A extends Type, | ||
B extends Type, | ||
|
@@ -49,8 +47,8 @@ export type Arg7< | |
E extends Type, | ||
F extends Type, | ||
G extends Type | ||
> = [Arg<A>, Arg<B>, Arg<C>, Arg<D>, Arg<E>, Arg<F>, Arg<G>]; | ||
|
||
> = VariadicArgs<[A, B, C, D, E, F, G]>; | ||
/** @deprecated */ | ||
export type Arg8< | ||
A extends Type, | ||
B extends Type, | ||
|
@@ -60,49 +58,43 @@ export type Arg8< | |
F extends Type, | ||
G extends Type, | ||
H extends Type | ||
> = [Arg<A>, Arg<B>, Arg<C>, Arg<D>, Arg<E>, Arg<F>, Arg<G>, Arg<H>]; | ||
|
||
export type FnBody0 = Fn0<ScopeBody>; | ||
|
||
export type FnBody1<A extends Type> = Fn<Sym<A>, ScopeBody>; | ||
|
||
export type FnBody2<A extends Type, B extends Type> = Fn2< | ||
Sym<A>, | ||
Sym<B>, | ||
ScopeBody | ||
>; | ||
|
||
export type FnBody3<A extends Type, B extends Type, C extends Type> = Fn3< | ||
Sym<A>, | ||
Sym<B>, | ||
Sym<C>, | ||
ScopeBody | ||
>; | ||
> = VariadicArgs<[A, B, C, D, E, F, G, H]>; | ||
|
||
export type FnBody0 = VariadicFnBody<[]>; | ||
export type FnBody1<A extends Type> = VariadicFnBody<[A]>; | ||
/** @deprecated */ | ||
export type FnBody2<A extends Type, B extends Type> = VariadicFnBody<[A, B]>; | ||
/** @deprecated */ | ||
export type FnBody3< | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 2 locations. Consider refactoring. |
||
A extends Type, | ||
B extends Type, | ||
C extends Type | ||
> = VariadicFnBody<[A, B, C]>; | ||
/** @deprecated */ | ||
export type FnBody4< | ||
A extends Type, | ||
B extends Type, | ||
C extends Type, | ||
D extends Type | ||
> = Fn4<Sym<A>, Sym<B>, Sym<C>, Sym<D>, ScopeBody>; | ||
|
||
> = VariadicFnBody<[A, B, C, D]>; | ||
/** @deprecated */ | ||
export type FnBody5< | ||
A extends Type, | ||
B extends Type, | ||
C extends Type, | ||
D extends Type, | ||
E extends Type | ||
> = Fn5<Sym<A>, Sym<B>, Sym<C>, Sym<D>, Sym<E>, ScopeBody>; | ||
|
||
> = VariadicFnBody<[A, B, C, D, E]>; | ||
/** @deprecated */ | ||
export type FnBody6< | ||
A extends Type, | ||
B extends Type, | ||
C extends Type, | ||
D extends Type, | ||
E extends Type, | ||
F extends Type | ||
> = Fn6<Sym<A>, Sym<B>, Sym<C>, Sym<D>, Sym<E>, Sym<F>, ScopeBody>; | ||
|
||
> = VariadicFnBody<[A, B, C, D, E, F]>; | ||
/** @deprecated */ | ||
export type FnBody7< | ||
A extends Type, | ||
B extends Type, | ||
|
@@ -111,8 +103,8 @@ export type FnBody7< | |
E extends Type, | ||
F extends Type, | ||
G extends Type | ||
> = Fn7<Sym<A>, Sym<B>, Sym<C>, Sym<D>, Sym<E>, Sym<F>, Sym<G>, ScopeBody>; | ||
|
||
> = VariadicFnBody<[A, B, C, D, E, F, G]>; | ||
/** @deprecated */ | ||
export type FnBody8< | ||
A extends Type, | ||
B extends Type, | ||
|
@@ -122,52 +114,43 @@ export type FnBody8< | |
F extends Type, | ||
G extends Type, | ||
H extends Type | ||
> = Fn8< | ||
Sym<A>, | ||
Sym<B>, | ||
Sym<C>, | ||
Sym<D>, | ||
Sym<E>, | ||
Sym<F>, | ||
Sym<G>, | ||
Sym<H>, | ||
ScopeBody | ||
>; | ||
|
||
export type Func0<T extends Type> = Fn0<FnCall<T>>; | ||
|
||
export type Func1<A extends Type, T extends Type> = Fn<Term<A>, FnCall<T>>; | ||
|
||
export type Func2<A extends Type, B extends Type, T extends Type> = Fn2< | ||
Term<A>, | ||
Term<B>, | ||
FnCall<T> | ||
>; | ||
> = VariadicFnBody<[A, B, C, D, E, F, G, H]>; | ||
|
||
/** @deprecated */ | ||
export type Func0<T extends Type> = VariadicFunc<[], T>; | ||
/** @deprecated */ | ||
export type Func1<A extends Type, T extends Type> = VariadicFunc<[A], T>; | ||
/** @deprecated */ | ||
export type Func2< | ||
A extends Type, | ||
B extends Type, | ||
T extends Type | ||
> = VariadicFunc<[A, B], T>; | ||
/** @deprecated */ | ||
export type Func3< | ||
A extends Type, | ||
B extends Type, | ||
C extends Type, | ||
T extends Type | ||
> = Fn3<Term<A>, Term<B>, Term<C>, FnCall<T>>; | ||
|
||
> = VariadicFunc<[A, B, C], T>; | ||
/** @deprecated */ | ||
export type Func4< | ||
A extends Type, | ||
B extends Type, | ||
C extends Type, | ||
D extends Type, | ||
T extends Type | ||
> = Fn4<Term<A>, Term<B>, Term<C>, Term<D>, FnCall<T>>; | ||
|
||
> = VariadicFunc<[A, B, C, D], T>; | ||
/** @deprecated */ | ||
export type Func5< | ||
A extends Type, | ||
B extends Type, | ||
C extends Type, | ||
D extends Type, | ||
E extends Type, | ||
T extends Type | ||
> = Fn5<Term<A>, Term<B>, Term<C>, Term<D>, Term<E>, FnCall<T>>; | ||
|
||
> = VariadicFunc<[A, B, C, D, E], T>; | ||
/** @deprecated */ | ||
export type Func6< | ||
A extends Type, | ||
B extends Type, | ||
|
@@ -176,8 +159,8 @@ export type Func6< | |
E extends Type, | ||
F extends Type, | ||
T extends Type | ||
> = Fn6<Term<A>, Term<B>, Term<C>, Term<D>, Term<E>, Term<F>, FnCall<T>>; | ||
|
||
> = VariadicFunc<[A, B, C, D, E, F], T>; | ||
/** @deprecated */ | ||
export type Func7< | ||
A extends Type, | ||
B extends Type, | ||
|
@@ -187,17 +170,8 @@ export type Func7< | |
F extends Type, | ||
G extends Type, | ||
T extends Type | ||
> = Fn7< | ||
Term<A>, | ||
Term<B>, | ||
Term<C>, | ||
Term<D>, | ||
Term<E>, | ||
Term<F>, | ||
Term<G>, | ||
FnCall<T> | ||
>; | ||
|
||
> = VariadicFunc<[A, B, C, D, E, F, G], T>; | ||
/** @deprecated */ | ||
export type Func8< | ||
A extends Type, | ||
B extends Type, | ||
|
@@ -208,14 +182,25 @@ export type Func8< | |
G extends Type, | ||
H extends Type, | ||
T extends Type | ||
> = Fn8< | ||
Term<A>, | ||
Term<B>, | ||
Term<C>, | ||
Term<D>, | ||
Term<E>, | ||
Term<F>, | ||
Term<G>, | ||
Term<H>, | ||
> = VariadicFunc<[A, B, C, D, E, F, G, H], T>; | ||
|
||
export type VariadicFunc<Xs extends Type[], T extends Type> = VariadicFn< | ||
VariadicTerms<Xs>, | ||
FnCall<T> | ||
>; | ||
export type VariadicFnBody<Xs extends Type[]> = VariadicFn< | ||
VariadicSyms<Xs>, | ||
ScopeBody | ||
>; | ||
type VariadicFn<Xs extends unknown[], Y> = (...xs: Xs) => Y; | ||
export type VariadicArgs<Xs extends Type[]> = { | ||
[i in keyof Xs]: Arg<Xs[i]>; | ||
}; | ||
export type VariadicSyms<Xs extends Type[]> = { | ||
[i in keyof Xs]: Sym<Xs[i]>; | ||
}; | ||
export type VariadicTerms<Xs extends Type[]> = { | ||
[i in keyof Xs]: Term<Xs[i]>; | ||
}; | ||
type TypeOfArg<X> = X extends Arg<infer A> ? A : never; | ||
export type VariadicTypeOfArg<Xs extends unknown[]> = { [i in keyof Xs]: TypeOfArg<Xs[i]> }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.