From 9ec6b91686b651d959fd9ffbec283845bd725dd6 Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Wed, 5 Feb 2025 12:37:03 -0600 Subject: Feature/initialize list side branch (#6058) * SP004: implement initialize list translation to ctor - We synthesize a member-wise constructor for each struct follow the rules described in SP004. - Add logic to translate the initialize list to constructor invoke - Add cuda-host decoration for the synthesized constructor - Remove the default constructor when we have a valid member init constructor - Disable -zero-initialize option, will re-implement it in followup (#6109). - Fix the overload lookup issue When creating invoke expression for ctor, we need to call ResolveInvoke() to find us the best candidates, however the existing lookup logic could find us the base constructor for child struct, we should eliminate this case by providing the LookupOptions::IgnoreInheritance to lookup, this requires us to create a subcontext on SemanticsVisitor to indicate that we only want to use this option on looking the constructor. - Do not implicit initialize a struct that doesn't have explicit default constructor. Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- .../interfaces/anyvalue-size-validation.slang | 2 +- tests/diagnostics/mismatching-types.slang | 9 +++++++- tests/diagnostics/mismatching-types.slang.expected | 21 +++++++++++-------- tests/diagnostics/uninitialized-fields.slang | 4 ++-- tests/diagnostics/variable-redeclaration.slang | 2 +- .../variable-redeclaration.slang.expected | 24 ++++++++++++++++++++++ 6 files changed, 48 insertions(+), 14 deletions(-) (limited to 'tests/diagnostics') diff --git a/tests/diagnostics/interfaces/anyvalue-size-validation.slang b/tests/diagnostics/interfaces/anyvalue-size-validation.slang index f2ed52d0c..ffe968c67 100644 --- a/tests/diagnostics/interfaces/anyvalue-size-validation.slang +++ b/tests/diagnostics/interfaces/anyvalue-size-validation.slang @@ -26,6 +26,6 @@ RWStructuredBuffer output; [numthreads(4, 1, 1)] void main() { - S s = S(); + S s = S(1, 2, 3); output[0] = test(s).a; } diff --git a/tests/diagnostics/mismatching-types.slang b/tests/diagnostics/mismatching-types.slang index 15fc1d0e3..ead1d34ff 100644 --- a/tests/diagnostics/mismatching-types.slang +++ b/tests/diagnostics/mismatching-types.slang @@ -49,19 +49,26 @@ void main(uint3 dispatchThreadID : SV_DispatchThreadID) // expected an expression of type 'GenericOuter', got 'int' a = 0; + // expected an expression of type 'GenericOuter.GenericInner', got 'int' + // explicit conversion from 'int' to 'GenericOuter.GenericInner' is possible a.g = 0; + // expected an expression of type 'GenericOuter.NonGenericInner', got 'int' + // explicit conversion from 'int' to 'GenericOuter.GenericInner' is possible a.ng = 0; // expected an expression of type 'GenericOuter.GenericInner', got 'GenericOuter.GenericInner' a.g = b.g; // expected an expression of type 'GenericOuter.NonGenericInner', got 'GenericOuter.NonGenericInner' a.ng = b.ng; // expected an expression of type 'NonGenericOuter.GenericInner', got 'int' + // explicit conversion from 'int' to 'GenericInner' is possible c.i = 0; // expected an expression of type 'NonGenericOuter.GenericInner', got 'NonGenericOuter.GenericInner' c.i = c.f; + // expected an expression of type 'NonGenericOuter.GenericInner.ReallyNested', got 'int' + // explicit conversion from 'int' to 'GenericInner.ReallyNested' is possible c.i.n = 0; // OK c.i.n.val = 0; @@ -74,4 +81,4 @@ void main(uint3 dispatchThreadID : SV_DispatchThreadID) Texture1D t1 = tex; // expected an expression of type 'Texture2D', got 'Texture1D' Texture2D t2 = tex; -} \ No newline at end of file +} diff --git a/tests/diagnostics/mismatching-types.slang.expected b/tests/diagnostics/mismatching-types.slang.expected index 65a6df32e..a706e30e6 100644 --- a/tests/diagnostics/mismatching-types.slang.expected +++ b/tests/diagnostics/mismatching-types.slang.expected @@ -3,31 +3,34 @@ standard error = { tests/diagnostics/mismatching-types.slang(51): error 30019: expected an expression of type 'GenericOuter', got 'int' a = 0; ^ -tests/diagnostics/mismatching-types.slang(53): error 30019: expected an expression of type 'GenericOuter.GenericInner', got 'int' +tests/diagnostics/mismatching-types.slang(55): error 30019: expected an expression of type 'GenericOuter.GenericInner', got 'int' a.g = 0; ^ -tests/diagnostics/mismatching-types.slang(55): error 30019: expected an expression of type 'GenericOuter.NonGenericInner', got 'int' +tests/diagnostics/mismatching-types.slang(55): note: explicit conversion from 'int' to 'GenericOuter.GenericInner' is possible +tests/diagnostics/mismatching-types.slang(59): error 30019: expected an expression of type 'GenericOuter.NonGenericInner', got 'int' a.ng = 0; ^ -tests/diagnostics/mismatching-types.slang(57): error 30019: expected an expression of type 'GenericOuter.GenericInner', got 'GenericOuter.GenericInner' +tests/diagnostics/mismatching-types.slang(59): note: explicit conversion from 'int' to 'GenericOuter.NonGenericInner' is possible +tests/diagnostics/mismatching-types.slang(61): error 30019: expected an expression of type 'GenericOuter.GenericInner', got 'GenericOuter.GenericInner' a.g = b.g; ^ -tests/diagnostics/mismatching-types.slang(59): error 30019: expected an expression of type 'GenericOuter.NonGenericInner', got 'GenericOuter.NonGenericInner' +tests/diagnostics/mismatching-types.slang(63): error 30019: expected an expression of type 'GenericOuter.NonGenericInner', got 'GenericOuter.NonGenericInner' a.ng = b.ng; ^~ -tests/diagnostics/mismatching-types.slang(61): error 30019: expected an expression of type 'NonGenericOuter.GenericInner', got 'int' +tests/diagnostics/mismatching-types.slang(66): error 30019: expected an expression of type 'NonGenericOuter.GenericInner', got 'int' c.i = 0; ^ -tests/diagnostics/mismatching-types.slang(63): error 30019: expected an expression of type 'NonGenericOuter.GenericInner', got 'NonGenericOuter.GenericInner' +tests/diagnostics/mismatching-types.slang(68): error 30019: expected an expression of type 'NonGenericOuter.GenericInner', got 'NonGenericOuter.GenericInner' c.i = c.f; ^ -tests/diagnostics/mismatching-types.slang(65): error 30019: expected an expression of type 'NonGenericOuter.GenericInner.ReallyNested', got 'int' +tests/diagnostics/mismatching-types.slang(72): error 30019: expected an expression of type 'NonGenericOuter.GenericInner.ReallyNested', got 'int' c.i.n = 0; ^ -tests/diagnostics/mismatching-types.slang(74): error 30019: expected an expression of type 'Texture1D', got 'Texture1D' +tests/diagnostics/mismatching-types.slang(72): note: explicit conversion from 'int' to 'NonGenericOuter.GenericInner.ReallyNested' is possible +tests/diagnostics/mismatching-types.slang(81): error 30019: expected an expression of type 'Texture1D', got 'Texture1D' Texture1D t1 = tex; ^~~ -tests/diagnostics/mismatching-types.slang(76): error 30019: expected an expression of type 'Texture2D', got 'Texture1D' +tests/diagnostics/mismatching-types.slang(83): error 30019: expected an expression of type 'Texture2D', got 'Texture1D' Texture2D t2 = tex; ^~~ } diff --git a/tests/diagnostics/uninitialized-fields.slang b/tests/diagnostics/uninitialized-fields.slang index f3c7b1a36..efa62cc36 100644 --- a/tests/diagnostics/uninitialized-fields.slang +++ b/tests/diagnostics/uninitialized-fields.slang @@ -56,16 +56,16 @@ struct Partial // Warnings here should be a bit different struct Implicit { - //CHK-DAG: warning 41021: default initializer for 'Implicit' will not initialize field 'a' int a; int b = 1; - //CHK-DAG: warning 41021: default initializer for 'Implicit' will not initialize field 'c' int c; int d = 1 + 1; } int using_implicit(int x) { + // no default constructor will be called, because there is no __init() synthesized for `Implicit` + // so no warnings will be reported on members of `Implicit` Implicit impl; impl.a = x; return impl.c; diff --git a/tests/diagnostics/variable-redeclaration.slang b/tests/diagnostics/variable-redeclaration.slang index bbd6a07c0..d238442e8 100644 --- a/tests/diagnostics/variable-redeclaration.slang +++ b/tests/diagnostics/variable-redeclaration.slang @@ -37,7 +37,7 @@ int testLocalShadowing(int x) } // Structure fields - +// Note: more diagnostics will be reported here because of the constructor synthesis struct S { int f; diff --git a/tests/diagnostics/variable-redeclaration.slang.expected b/tests/diagnostics/variable-redeclaration.slang.expected index 1998c13c8..842038180 100644 --- a/tests/diagnostics/variable-redeclaration.slang.expected +++ b/tests/diagnostics/variable-redeclaration.slang.expected @@ -30,6 +30,30 @@ tests/diagnostics/variable-redeclaration.slang(21): error 30200: declaration of tests/diagnostics/variable-redeclaration.slang(20): note: see previous declaration of 'y' int y = x; ^ +tests/diagnostics/variable-redeclaration.slang(41): error 30200: declaration of 'f' conflicts with existing declaration +struct S + ^ +tests/diagnostics/variable-redeclaration.slang(41): note: see previous declaration of 'f' +struct S + ^ +tests/diagnostics/variable-redeclaration.slang(43): error 39999: ambiguous reference to 'f' + int f; + ^ +tests/diagnostics/variable-redeclaration.slang(44): note 39999: candidate: float S.f + float f; + ^ +tests/diagnostics/variable-redeclaration.slang(43): note 39999: candidate: int S.f + int f; + ^ +tests/diagnostics/variable-redeclaration.slang(44): error 39999: ambiguous reference to 'f' + float f; + ^ +tests/diagnostics/variable-redeclaration.slang(44): note 39999: candidate: float S.f + float f; + ^ +tests/diagnostics/variable-redeclaration.slang(43): note 39999: candidate: int S.f + int f; + ^ tests/diagnostics/variable-redeclaration.slang(53): error 39999: ambiguous reference to 'size' return size; ^~~~ -- cgit v1.2.3