Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions cmake/SlangTarget.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,10 @@ function(slang_add_target dir type)
#
# Link and include from dependencies
#
target_link_libraries(${target} PRIVATE ${ARG_LINK_WITH_PRIVATE})
target_link_libraries(
${target}
PRIVATE $<BUILD_LOCAL_INTERFACE:${ARG_LINK_WITH_PRIVATE}>
)
target_link_libraries(${target} PUBLIC ${ARG_LINK_WITH_PUBLIC})

if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
Expand Down Expand Up @@ -448,14 +451,16 @@ function(slang_add_target dir type)
get_filename_component(inc_abs ${inc} ABSOLUTE)
target_include_directories(
${target}
PUBLIC "$<BUILD_INTERFACE:${inc_abs}>"
PUBLIC
"$<BUILD_INTERFACE:${inc_abs}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
endforeach()
foreach(inc ${ARG_INCLUDE_DIRECTORIES_PRIVATE})
get_filename_component(inc_abs ${inc} ABSOLUTE)
target_include_directories(
${target}
PRIVATE "$<BUILD_INTERFACE:${inc_abs}>"
PRIVATE "$<BUILD_LOCAL_INTERFACE:${inc_abs}>"
)
endforeach()

Expand Down
24 changes: 22 additions & 2 deletions source/slang/slang-check-decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7811,7 +7811,7 @@ void SemanticsDeclBasesVisitor::visitStructDecl(StructDecl* decl)
{
getSink()->diagnose(
inheritanceDecl,
Diagnostics::baseOfStructMustBeStructOrInterface,
Diagnostics::baseOfStructMustBeInterface,
decl,
baseType);
continue;
Expand All @@ -7823,6 +7823,26 @@ void SemanticsDeclBasesVisitor::visitStructDecl(StructDecl* decl)
}
else if (auto baseStructDeclRef = baseDeclRef.as<StructDecl>())
{
if (!isFromCoreModule(decl))
{
// In Slang 2026, we no longer allow structs to inherit from other structs.
if (isSlang2026OrLater(this))
{
getSink()->diagnose(
inheritanceDecl,
Diagnostics::baseOfStructMustBeInterface,
decl,
baseType);
}
else
{
// For legacy langauge versions, we still allow struct inheritance to avoid
// breaking existing code, but we will emit a warning to inform the user
// that this feature is unstable and may be removed in the future.
getSink()->diagnose(inheritanceDecl, Diagnostics::inheritanceUnstable);
}
}

// To simplify the task of reading and maintaining code,
// we require that when a `struct` inherits from another
// `struct`, the base `struct` is the first item in
Expand All @@ -7845,7 +7865,7 @@ void SemanticsDeclBasesVisitor::visitStructDecl(StructDecl* decl)
{
getSink()->diagnose(
inheritanceDecl,
Diagnostics::baseOfStructMustBeStructOrInterface,
Diagnostics::baseOfStructMustBeInterface,
decl,
baseType);
continue;
Expand Down
11 changes: 8 additions & 3 deletions source/slang/slang-diagnostic-defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1662,8 +1662,8 @@ DIAGNOSTIC(
DIAGNOSTIC(
30811,
Error,
baseOfStructMustBeStructOrInterface,
"struct '$0' cannot inherit from type '$1' that is neither a struct nor an interface")
baseOfStructMustBeInterface,
"struct '$0' cannot inherit from non-interface type '$1'")
DIAGNOSTIC(
30812,
Error,
Expand All @@ -1681,7 +1681,12 @@ DIAGNOSTIC(
baseOfClassMustBeClassOrInterface,
"class '$0' cannot inherit from type '$1' that is neither a class nor an interface")
DIAGNOSTIC(30815, Error, circularityInExtension, "circular extension is not allowed.")

DIAGNOSTIC(
30816,
Warning,
inheritanceUnstable,
"support for inheritance is unstable and will be removed in future language versions, consider "
"using composition instead.")
DIAGNOSTIC(
30820,
Error,
Expand Down
13 changes: 13 additions & 0 deletions tests/diagnostics/inheritance-1.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK):

// Tests that we will diagnose a warning on struct inheritance being unstable
// before Slang 2026.

#lang 2025

struct Base {}

//CHECK: ([[# @LINE+1]]): warning 30816:
struct Derived : Base {}

struct Base1 {}
10 changes: 10 additions & 0 deletions tests/diagnostics/inheritance-2.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK):

// Tests that we will diagnose an error on struct inheritance in language 2026 or later.

#lang 2026

struct Base {}

//CHECK: ([[# @LINE+1]]): error 30811:
struct Derived : Base {}
2 changes: 0 additions & 2 deletions tests/expected-failure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ tests/language-feature/saturated-cooperation/fuse.slang (vk)
tests/bugs/byte-address-buffer-interlocked-add-f32.slang (vk)
tests/ir/loop-unroll-0.slang.1 (vk)
tests/hlsl-intrinsic/texture/float-atomics.slang (vk)
tests/hlsl/cbuffer-float3-offsets-aligned.slang.2 (vk)
tests/hlsl/cbuffer-float3-offsets-unaligned.slang.2 (vk)
2 changes: 2 additions & 0 deletions tests/hlsl-intrinsic/size-of/align-of.slang
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer

#pragma warning(disable:30816)

RWStructuredBuffer<int> outputBuffer;

enum Enum : int8_t
Expand Down
1 change: 1 addition & 0 deletions tests/hlsl-intrinsic/size-of/size-of.slang
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma warning(disable:30816)

//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
Expand Down
4 changes: 2 additions & 2 deletions tests/hlsl/cbuffer-float3-offsets-aligned.slang
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//TEST:SIMPLE(filecheck=SPIRV): -target spirv -profile cs_6_2 -entry computeMain -line-directive-mode none -fvk-use-dx-layout
//TEST:SIMPLE(filecheck=SPIRV): -target spirv -emit-spirv-directly -profile cs_6_2 -entry computeMain -line-directive-mode none -fvk-use-dx-layout
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-slang -compute -dx12 -use-dxil -profile cs_6_2 -Xslang... -Xdxc -fvk-use-dx-layout -Xdxc -enable-16bit-types -X. -output-using-type
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-slang -compute -vk -profile cs_6_2 -Xslang... -fvk-use-dx-layout -X. -output-using-type
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-slang -compute -vk -profile cs_6_2 -emit-spirv-directly -Xslang... -fvk-use-dx-layout -X. -output-using-type
//TEST:REFLECTION(filecheck=REFLECT):-stage compute -entry computeMain -target spirv -profile cs_6_2 -no-codegen -line-directive-mode none -fvk-use-dx-layout

//TEST_INPUT:ubuffer(stride=4, count=17):out,name=outputBuffer
Expand Down
4 changes: 2 additions & 2 deletions tests/hlsl/cbuffer-float3-offsets-unaligned.slang
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//TEST:SIMPLE(filecheck=SPIRV): -target spirv -profile cs_6_2 -entry computeMain -line-directive-mode none -fvk-use-dx-layout
//TEST:SIMPLE(filecheck=SPIRV): -target spirv -emit-spirv-directly -profile cs_6_2 -entry computeMain -line-directive-mode none -fvk-use-dx-layout
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-slang -compute -dx12 -use-dxil -Xslang... -Xdxc -fvk-use-dx-layout -Xdxc -enable-16bit-types -X. -output-using-type
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-slang -compute -vk -Xslang... -fvk-use-dx-layout -X. -output-using-type
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-slang -compute -vk -emit-spirv-directly -Xslang... -fvk-use-dx-layout -X. -output-using-type
//TEST:REFLECTION(filecheck=REFLECT):-stage compute -entry computeMain -target spirv -profile cs_6_2 -no-codegen -line-directive-mode none -fvk-use-dx-layout

// dxc: -T cs_6_2 -E computeMain -spirv -fvk-use-dx-layout -enable-16bit-types
Expand Down
2 changes: 2 additions & 0 deletions tests/initializer-list/struct-inherit.slang
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-cpu -compute -entry computeMain
//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-dx12 -use-dxil -compute -entry computeMain

#pragma warning(disable:30816)

//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
RWStructuredBuffer<int> outputBuffer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// an empty initializer list) is still possible
// when using `struct` inheritance.

#pragma warning(disable:30816)

struct Base
{
int a = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

// Test that a `struct` type can use an inherited
// member to satisfy an interface requirement.
#pragma warning(disable:30816)

interface ITweak
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//TEST_IGNORE_FILE:
// struct-inheritance-imported.slang

#pragma warning(disable:30816)
public struct Base
{
public int a;
Expand Down
2 changes: 2 additions & 0 deletions tests/language-feature/inheritance/struct-inheritance.slang
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Test that we can define a `struct` type
// that inherits from another `struct`.

#pragma warning(disable:30816)

struct Base
{
int a;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER):-shaderobj -vk
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER):-shaderobj

#pragma warning(disable:30816)


struct Base<let ND:int>
{
int a = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//TEST:SIMPLE(filecheck=CHECK): -target hlsl -stage compute -entry computeMain
RWStructuredBuffer<int> outputBuffer;

#pragma warning(disable:30816)

//CHECK: error 30851

struct DefaultStructNoInit_base
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-cpu -compute -entry computeMain
//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-dx12 -use-dxil -compute -entry computeMain

#pragma warning(disable:30816)


//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
RWStructuredBuffer<int> outputBuffer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-cpu -compute -entry computeMain
//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-dx12 -use-dxil -compute -entry computeMain

#pragma warning(disable:30816)


//TEST_INPUT:ubuffer(data=[0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<int> outputBuffer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-cpu -compute -entry computeMain
//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-dx12 -use-dxil -compute -entry computeMain

#pragma warning(disable:30816)


//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
RWStructuredBuffer<int> outputBuffer;

Expand Down
Loading