-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
add @reflectDecl and @reflectFn builtins #10706
Comments
can this change still preserve the enum tag from |
The Data tagged union in master branch is completely bogus. All decls are Consider: |
Since Some small thoughts:
const decl_type = @TypeOf(@field(T, "..."));
const decl_align = @typeInfo(@TypeOf(&@field(T,"..."))).Pointer.alignment; The only thing missing is reflection for the |
I don't like "Info" in the name. It's redundant. Literally everything in programming is "info". |
fooInfo usually means info about a foo, vs. a foo. It's easier to write fooInfo(foo: Foo) FooInfo {...} than informationAboutThisFoo(foo: Foo) InformationAboutFoo { ... } . Just calling it foo(foo: Foo) Foo { ... } makes no sense and is clearly wrong. Trying to replace "Info" due to a misconception leads to nothing good. (Like renaming TypeInfo to Type--it's not a type and it's not the type of a type, its a struct that contains information about a type.) |
If you use
@typeInfo
on a struct, you get this structure:Declaration looks like this:
name
andis_pub
are cool. ButData
requires doing a lot of semantic analysis to provide this information. However most usages of@typeInfo
do not need access to this information.stage1 solves this problem by making Data lazy. But this is complicated and slow.
This proposal is to remove the
data
field from Declaration, and add a new builtin function to reflect on declarations:@reflectDecl
- given a type which is used as a namespace, and a decl name, provides meta information about the decl. The type returned is:If you then looked at the type and learned that it was a function, you could use
@reflectFunc
to learn information about its function body (not to be confused with its function type which can be learned via@typeInfo(type).Fn
.Related: #10705
The text was updated successfully, but these errors were encountered: