Skip to content

Commit dfbd379

Browse files
committed
Add module organization suggestion doc
Suggest one method to keep slang modules organized in the file system.
1 parent 3c096a7 commit dfbd379

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

docs/assets/moduletree.png

73.6 KB
Loading

docs/user-guide/04-modules-and-access-control.md

+31-4
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@ It is only valid for the user code to `import m`. Attempting to `import helper`
120120
Multiple `import`s of the same module from different input files will only cause the module to be loaded once (there is no need for "include guards" or `#pragma once`).
121121
Note that preprocessor definitions in the current file will not affect the compilation of `import`ed code, and the preprocessor definitions in the imported code is not visible to the current file.
122122

123-
> #### Note ####
124-
> Future versions of the Slang system will support loading of modules from pre-compiled binaries instead of source code.
125-
> The same `import` keyword will continue to work in that case.
126-
127123
## Access Control
128124

129125
Slang supports access control modifiers: `public`, `internal` and `private`. The module boundary plays an important role in access control.
@@ -195,6 +191,37 @@ The Slang compiler enforces the following rules regarding access control:
195191
- Type definitions themselves cannot be `private`, for example, `private struct S {}` is not valid code.
196192
- `interface` requirements cannot be `private`.
197193

194+
## Organizing Systems of Modules
195+
196+
Slang does not seek to impose any specific organization of modules. However, there are some conventions that have emerged as being useful.
197+
198+
### Module Organization Suggestions
199+
200+
- Top-level modules are those that are `import`ed by user code.
201+
- The implementation details of the module are placed in the lower levels of the tree.
202+
203+
This has the benefit that it is easy for a user to distinguish the public API from the implementation details.
204+
205+
### Module Organization Example
206+
207+
![Module organization tree diagram](assets/moduletree.png)
208+
209+
The above diagram shows a module organization example.
210+
211+
Top-level modules such as `utils` are those that are directly `import`ed by user code. The implementation details of the module are placed in the lower levels of the tree.
212+
213+
In this example, the `utils.slang` module needn't contain anything more than a module declaration and a list of included sub-modules, with optional `import` statement(s) to pull in any external dependencies, e.g.
214+
215+
```
216+
module utils;
217+
import slangpy;
218+
219+
__include "utils/accumlator.slang";
220+
__include "utils/tonemap.slang";
221+
__include "utils/fill.slang";
222+
```
223+
224+
Here, all the symbols defined in `accumlator.slang`, `tonemap.slang`, and `fill.slang` are visible to the user of the `utils` module, and these helper modules do not need to clutter the top-level file hierarchy.
198225

199226
## Legacy Modules
200227

0 commit comments

Comments
 (0)