Comments (7)
Tentative Plan:
- For an initialization list of a struct to be legal, it must match up to a constructor.
- We will only auto-gen a constructor with a parameter-list that is 1:1 to visible struct members. We cannot generate a ctor if a private member is part of a struct and uninitialized. We cannot generate a ctor if a internal member is part of a struct and uninitialized and we are not inside the original def'ed module scope. This calling rule is effectively inheriting the smallest scope visible member as the visibility of the __init {private,internal,public}.
- We (for now) only allow initializing all visible variables at once.
- We won't auto-gen constructors if an already valid constructor exists. We will use the valid constructor instead.
- init-lists may call user-defined constructors
- We will demote a default ctor to
internal
ifinternal
variables are being init'd. - initializer lists ignore all varDecl init expressions.
Examples:
- assume
struct S
{
private int m1;
public int m2;
}
S test()
{
S s = {1,2};
return s;
}
This will error, there are more init list elements than public variables
- assume
struct S
{
private int m1;
public int m2;
__init(int in1, int in2)
{
m1 = in1;
m2 = in2
}
}
S test()
{
S s = {1,2};
return s;
}
This will work, user made constructor has priority
- assume
struct S
{
public int m1;
public int m2;
}
S test()
{
S s = {1,2};
return s;
}
This will work, 2 public int members, 2 elements inside the parameter-list
- assume
struct S
{
private int m1;
public int m2;
private int m3;
public int m4;
}
S test()
{
S s = {1,2};
return s;
}
This will error, we cannot create an implicit ctor from an initializer-list when uninitialized private variables are inside a struct.
- assume
struct S
{
private int m1;
public int m2;
private int m3;
public int m4;
__init(int in1, int in2)
{
m1 = in1;
m2 = in2;
}
}
S test()
{
S s = {1, 1};
return s;
}
This will work, user made constructor has priority
- assume
struct S
{
private int m1 = 0;
public int m2;
private int m3 = 1;
public int m4;
}
S test()
{
S s = {1,2};
return s;
}
This will work, we can create an implicit ctor from an initializer-list when all private variables are initialized inside a struct.
- assume
// myFile_1.slang
struct S
{
internal int m1 = 0;
public int m2;
}
...
S s = {1,2}; // works from the same module.
S s = {1}; // does not work from the same module
// myFile_2.slang
S s = {1,2}; // does not work if called from a different module because m1 is internal (not visible).
S s = {1}; // does work since only m2 is visible and m1 is default initialized.
- assume
struct S
{
private int m1 = 0;
public int m2;
private int m3 = 1;
public int m4;
}
S test()
{
S s = {1};
return s;
}
???
from slang.
We should make 6 an error, because private members must have an explicit initializer for implicit generation of ctor. If we have uninitialized private members, do not generate a ctor, or generate a ctor that will result an error message if it is ever called.
from slang.
updated 👍 (also changed the example numbers to make more sense)
from slang.
Just want to add that
struct S
{
private int m1 = 0;
public int m2;
}
S s = {1}; // works.
from slang.
struct S
{
internal int m1;
public int m2;
}
S s = {1,2}; // works from the same module.
S s = {1,2}; // does not work if called from a different module, because ctor is not visible.
from slang.
I have a question about when an initializer-list is a partial-completion to the public/internal member list:
struct S
{
private int m1 = 0;
public int m2;
private int m3 = 1;
public int m4;
}
S test()
{
S s = {1};
return s;
}
This would error since no user-ctor && not 1:1 for each public member? Or not error and allow partial init?
from slang.
I think we just don't allow this for now.
from slang.
Related Issues (20)
- Create the breakdown profiling of slang HOT 2
- AD Cleanup: Use a temporary accumulation inst such as `IRAccumulate` instead of explicitly loading, adding and storing differential values in reverse mode HOT 1
- Implement metrics tracking for GitHub engagement
- Document the existing auto-diff type system, semantic checking and AST synthesis methods
- Return ptr of new Object out of Slang DLL HOT 5
- Stage the CTS cases known failure for now. HOT 1
- Fix CTS tests failures.
- Breakdown the runtime cost of Slang backend passes.
- constexpr doesn't work as expected when used on a function HOT 3
- Design documentation for DXIL linking of shader-modules
- Pointer example on User Guide doesn't work HOT 5
- Incorrect inlining of generic initializers HOT 1
- Throw an error when using `[[vk::binding]]` on global shader parameters
- Wrong matrix operations in Metal? HOT 6
- How to import modules :) HOT 1
- support for opengl HOT 3
- Investigate why the compiler warning level 4 is not working as expected HOT 2
- Shader reflection API issues HOT 1
- Update documentation for compilation API with profile information for new targets.
- Print warning when unsigned and signed integer types used for binary operators
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slang.