Skip to content

Commit 965f962

Browse files
authored
Add module organization suggestion doc (#6509)
* Add module organization suggestion doc Suggest one method to keep slang modules organized in the file system. Closes #4841
1 parent 0634684 commit 965f962

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

docs/assets/moduletree.png

73.6 KB
Loading

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

+33-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,39 @@ 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 File Structure 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+
- The top-level directory contains modules that would be `import`ed by user code.
201+
- The implementation details of the modules are placed in files at 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+
<img src="../assets/moduletree.png" width="300em" alt="Module organization tree diagram"/>
208+
209+
### Module Organization Example
210+
211+
The above diagram shows a module organization example.
212+
213+
Top-level module files such as `utils.slang` 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, organized into similarly named subdirectories for clarity.
214+
215+
Modules like `utils.slang` needn't contain anything more than a module declaration and a list of included files, with optional `import` statement(s) to pull in any external dependencies, e.g.
216+
217+
```
218+
module utils;
219+
import slangpy;
220+
221+
__include "utils/accumlator.slang";
222+
__include "utils/tonemap.slang";
223+
__include "utils/fill.slang";
224+
```
225+
226+
Here, all the public symbols defined in `accumlator.slang`, `tonemap.slang`, and `fill.slang` are visible to the user of the `utils` module, and these constituent helper files do not need to clutter the top-level file hierarchy.
198227

199228
## Legacy Modules
200229

docs/user-guide/toc.html

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<li data-link="modules#defining-a-module"><span>Defining a Module</span></li>
5959
<li data-link="modules#importing-a-module"><span>Importing a Module</span></li>
6060
<li data-link="modules#access-control"><span>Access Control</span></li>
61+
<li data-link="modules#organizing-file-structure-of-modules"><span>Organizing File Structure of Modules</span></li>
6162
<li data-link="modules#legacy-modules"><span>Legacy Modules</span></li>
6263
</ul>
6364
</li>

0 commit comments

Comments
 (0)