Skip to content
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 Documentation For Auto-Generated Constructors & Initializer Lists #4988

Merged

Conversation

ArielG-NV
Copy link
Contributor

Fixes: #4903

Add documentation for auto-generated constructors & initializer lists.
The logic behind this PR is on PR #4854.

fixes: shader-slang#4903

Add documentation for auto-generated constructors & Initializer Lists, the logic behind this PR is on shader-slang#4854
@ArielG-NV ArielG-NV added the pr: non-breaking PRs without breaking changes label Sep 3, 2024
int a;
int b = 5;

__init()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment here:
// because the user has explicitly defined a constructor,
// slang will not synthesize more constructors.

int a;
int b = 5;

// Implicitly generate:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Slang will automatically generate an implicit constructor:


2. Auto-generate a 'member-wise constructor' if a conflicting `__init(...)` does not exist, **All members and inherited members have equal visibility**
```c#
struct DontGenerateCtor_Inner
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dontgenerate types here aren't necessary.

};
```

2. Auto-generate a 'member-wise constructor' if a conflicting `__init(...)` does not exist, **All members and inherited members have equal visibility**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if such a constructor isn't explicilty defined by the user

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..., when all members and inherited..

// }
};
```
3. Auto-generate a 'member-wise constructor' if a conflicting `__init(...)` does not exist, **not all members and inherited members have equal visibility**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..., when not all

----------
Initializer List's are an expression of the form `{...}`.

This form is **different** from declaring a new scope
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessary.

* User does not define any non-default constructor
* User only auto-generates 1 member-wise constructor following rules of [Auto-Generated Constructors](###auto-generated-constructors---struct).
> #### What is a C-Style-Struct - Simplified
> * Never defines a custom `__init(...)`, custom `__init()` are allowed.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this sentence.


### Initializer Lists - Struct

Slang has 2 seperate calling style for an Initializer List with `struct`'s:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

" In most scenarios, using an initializer list to create a struct typed value is equivalent to calling the struct's constructor using the elements in the initilaizer list as arguments". For example:
...
"

GenerateCtor1 val[2] = {{ 3 }, { 2 }};
```

2. C-Style-Initializer-List
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"In addition, slang allows provides compatbility support for legacy C-style structs. When the struct type qualifies as a "C-Style" struct, it is allowed to provide less arguments than struct members in an initilaizer list.

A struct is considered a C-style struct if:

  • condition1
  • condition2
  • condition3

For example,

code

".

@csyonghe csyonghe merged commit 65dd3b7 into shader-slang:master Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: non-breaking PRs without breaking changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document rules for initializer lists
2 participants