You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/user-guide/04-modules-and-access-control.md
+31-4
Original file line number
Diff line number
Diff line change
@@ -120,10 +120,6 @@ It is only valid for the user code to `import m`. Attempting to `import helper`
120
120
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`).
121
121
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.
122
122
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
-
127
123
## Access Control
128
124
129
125
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:
195
191
- Type definitions themselves cannot be `private`, for example, `private struct S {}` is not valid code.
196
192
-`interface` requirements cannot be `private`.
197
193
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
+

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.
0 commit comments