summaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-10-06 17:21:37 -0700
committerGitHub <noreply@github.com>2025-10-07 00:21:37 +0000
commit6af3381f47e3c22e1657c0e0064fa466e8bde0f6 (patch)
treebe187939b58bd6196fb0b2e5824d5d60f312b6b3 /docs
parentf4449d9376f0a5c32274fd812d135f3595159bae (diff)
Use symbol alias instead of wrapper synthesis to implement link-time types. (#8603)
This change achieves link-time type resolution with a different mechanism. For `extern struct Foo : IFoo = FooImpl;`, instead of synthesizing a wrapper type `Foo` that has a `FooImpl inner` field and dispatches all interface method calls to `inner.method()`, this PR completely removes this synthesis step, and instead just lower such `extern`/`export` types as `IRSymbolAlias` instructions that is just a reference to the type being wrapped. Then we extend the linker logic to clone the referenced symbol instead of the SymbolAlias insts itself during linking. By doing so, we greatly simply the logic need to support link-time types, and achieves higher robustness by not having to deal with many AST synthesis scenarios. Closes #8554. --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'docs')
-rw-r--r--docs/user-guide/10-link-time-specialization.md24
-rw-r--r--docs/user-guide/toc.html1
2 files changed, 3 insertions, 22 deletions
diff --git a/docs/user-guide/10-link-time-specialization.md b/docs/user-guide/10-link-time-specialization.md
index 516fd19b5..e5bc97930 100644
--- a/docs/user-guide/10-link-time-specialization.md
+++ b/docs/user-guide/10-link-time-specialization.md
@@ -163,16 +163,9 @@ import common;
export struct Sampler : ISampler = FooSampler;
```
-The `=` syntax is a syntactic sugar that expands to the following code:
-
-```csharp
-export struct Sampler : ISampler
-{
- FooSampler inner;
- int getSampleCount() { return inner.getSampleCount(); }
- float sample(int index) { return inner.sample(index); }
-}
-```
+The `=` syntax defines a typealias that allows `Sampler` to resolve to `FooSampler` at link-time.
+Note that both the name and type conformance clauses must match exactly between an `export` and an `extern` declaration
+for link-time types to resolve correctly. Link-time types can also be generic, and may conform to generic interfaces.
When all these three modules are linked, we will produce a specialized shader that uses the `FooSampler`.
@@ -196,17 +189,6 @@ void main(uint tid : SV_DispatchThreadID)
}
```
-## Restrictions
-
-Unlike preprocessors, link-time constants and types can only be used in places where shader parameter layout cannot be
-affected. This means that link-time constants and types are subject to the following restrictions:
-- Link-time constants cannot be used to define array sizes.
-- Link-time types are considered "incomplete" types. A struct or array type that has incomplete typed element is also an incomplete type.
- Incomplete types cannot be used as `ConstantBuffer` or `ParameterBlock` element type, and cannot be used directly as the type of
- a uniform variable.
-
-However it is allowed to use incomplete types as the element type of `StructuredBuffer` or `GLSLStorageBuffer`.
-
## Using Precompiling Modules with the API
In addition to using `slangc` for precompiling Slang modules, the `IModule` class provides a method to serialize itself to disk:
diff --git a/docs/user-guide/toc.html b/docs/user-guide/toc.html
index b32ad71da..89ddf34d9 100644
--- a/docs/user-guide/toc.html
+++ b/docs/user-guide/toc.html
@@ -148,7 +148,6 @@
<li data-link="link-time-specialization#link-time-constants"><span>Link-time Constants</span></li>
<li data-link="link-time-specialization#link-time-types"><span>Link-time Types</span></li>
<li data-link="link-time-specialization#providing-default-settings"><span>Providing Default Settings</span></li>
-<li data-link="link-time-specialization#restrictions"><span>Restrictions</span></li>
<li data-link="link-time-specialization#using-precompiling-modules-with-the-api"><span>Using Precompiling Modules with the API</span></li>
<li data-link="link-time-specialization#additional-remarks"><span>Additional Remarks</span></li>
</ul>