<feed xmlns='http://www.w3.org/2005/Atom'>
<title>slang.git/source/core/slang-string.cpp, branch master</title>
<subtitle>Making it easier to work with shaders</subtitle>
<id>https://git.yummers.dev/slang.git/atom?h=master</id>
<link rel='self' href='https://git.yummers.dev/slang.git/atom?h=master'/>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/'/>
<updated>2025-06-19T00:11:16+00:00</updated>
<entry>
<title>Add support for on-demand AST deserialization (#7482)</title>
<updated>2025-06-19T00:11:16+00:00</updated>
<author>
<name>Theresa Foley</name>
<email>10618364+tangent-vector@users.noreply.github.com</email>
</author>
<published>2025-06-19T00:11:16+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=3ed77615924dc41b8b2f286d4ac646f625cd946c'/>
<id>urn:sha1:3ed77615924dc41b8b2f286d4ac646f625cd946c</id>
<content type='text'>
Note that this change does not actually *enable* on-demand deserialization of ASTs, because doing so is incompatible with the current compiler architecture where we have both an `ASTBuilder` and a `SharedASTBuilder`, and there are important invariants about how all AST nodes related to the core module must be created before those of any module using the core module.

Instead, this change simply adds the *infrastructure* for on-demand deserialization, and ensures that those code paths get used at runtime, but actually "demands" all of the nodes in a given serialized AST immediately as part of the deserialization process.

Important notes about the implementation approach:

* PR #7242 ensured that all of the code accessing the direct member declarations of a `ContainerDecl` went through a small(-ish) set of accessor methods. This change takes advantage of that work by further abstracting the storage of the direct member declarations out in a type, `ContainerDeclDirectMemberDecls`, which makes it easy to add custom serialization logic for just that type.

* The `ContainerDeclDirectMemberDecls` type also stores two pointers (one a `RefPtr` and the other a plain pointer) that are only used in the case where the members of a given `ContainerDecl` are being accessed through on-demand deserialization. This can be queried using the `isUsingOnDemandDeserialization()` method but any code accessing a `ContainerDecl` through the intended public API should never need to care about that detail.

* Many of the accessor methods that were added in PR #7242 now branch on whether `isUsingOnDemandDeserialization()` is set. The normal code path is unchanged, and the implementation logic for the on-demand-deserialization case is largely held in `slang-serialize-ast.cpp`, to keep it close to the definitions of the serialized data structures themselves.

* A few types in the `slang-ast-*.h` headers have had `FIDDLE()` annotations added to them, so that they can be used to synthesize some of the serialization logic that was previously hand-written.

* The `_registerBuiltinDeclsRec()` function (which is used to scan the built-in module ASTs for the various "magic" declarations that the `SharedASTBuilder` needs to know about) was factored a bit to support the way that registration needs to behave differently in the case of loading a serialized module (if we kept using the existing recursive search, then it would force every declaration in the core module to be loaded right away). The new `_collectBuiltinDeclsThatNeedRegistrationRec()` function mirrors the overall traversal pattern to produce a flat list that gets included in the serialized AST module. Note in particular that we no longer call `registerBuiltinDecls()` from within `_readBuiltinModule()`.

* The interface of the `Module` type was slightly expanded so that there is a more complete API for accessing the declarations exported from the module. Previously they could only be queried by their mangled name, but the new API also allows the entire list to be iterated over. The `ensureLookupAcceleratorBuilt()` method factors out the logic for building those data structures for a module. Note that in the case where on-demand deserialization is being used for a module, the `findExportedDeclByMandledName()` query will use serialized data directly, rather than build the lookup accelerators as C++ data structures (this is required if we are to avoid immediately deserializing all of the (exported) declarations in the core module as soon as it is loaded).

* A few methods related to loading serialized modules (e.g., `loadSerializedModule()`) have been updated so that along with a pointer to the serialized `ModuleChunk` (which, for those who aren't aware, is a pointer directly into the serialized bytes of the module file), they receive an `ISlangBlob` that refers to the entire blob holding the serialized data (which the `ModuleChunk` is part of). Passing this pointer down allows code running under these methods to retain a reference-counted pointer to the blob to stop the memory of the serialized module from being released until deserialization has been completed.

* The data types defined in `slang-fossil.h` have been overhauled significantly:

  * The most important change that is relevant to this work is the introduction of the `Fossilized&lt;T&gt;` template, which is used to statically map a "live" C++ type `T` to its binary fossilized representation. The `slang-fossil.h` file provides infrastructure allowing `Fossilized&lt;T&gt;` to be specialized for user-defined types, and also provides the necessary mappings for the core types like strings, arrays, and dictionaries.

  * A key point is that in C++ code, one can take a value of some type `Foo`, serialize it using a `Fossil::SerialWriter`, get a pointer to that serialized data, and then directly cast it to a `Fossilized&lt;Foo&gt;*` and navigate the serialized data directly (without deserializing it back into a `Foo`). For that process to work, any specialization of `Fossilized&lt;T&gt;` must be sure to match the layout that will be produced by the `serialize()` implementation for `T`, when writing to a `Fossil::SerialWriter`.

  * Another key change in the public interface of `slang-fossil.h` is that dynamically-typed traversal of the data used to be handled just with `FossilizedValRef`, but now uses a few different types. The `Fossil::ValRef&lt;T&gt;` and `Fossil::AnyValRef` types are used to capture the use cases that want reference-like behavior (basically a `Fossil::ValRef&lt;T&gt;` can be thought of as sort of like a `T&amp;`), while `Fossil::ValPtr&lt;T&gt;` and `Fossil::AnyValPtr` are used for cases that want pointer like behavior (akin to `T*`).

* Then there are related changes in `slang-serialize-fossil.*`:

  * The implementation of `Fossil::SerialReader` has been changed to use `Fossil::AnyValPtr` in most places where it formerly used `FossilizedValRef`. Using pointers (that can be null) instead of a weird kind of pseudo-reference (that could still be null) to traverse things was making the code harder to follow than it ought to be, in terms of understanding the levels of indirection in various places.

  * Some of the state that was previously in `Fossil::SerialReader` has been split into `Fossil::ReadContext`. This type allows multiple `Fossil::SerialReader`s to be created to read from the same serialized blob(s), while maintaining a persistent mapping from fossilized data pointers to live object pointers. The `ReadContext` also maintains the work list of deferred deserialization actions waiting to be performed, and only flushes that list when the last currently-open `SerialReader` is about to go out of scope.

* In order to support the split of `Fossil::SerialReader` described above (and also to clean up something that didn't quite feel right in the original serialization design) the base serialization framework in `slang-serialize.h` has been tweaked so that a `Serializer` now wraps *two* pointers instead of just one. The first pointer continues to be an implementation of `ISerializerImpl`, which handles the actual reading/writing of data, while the other pointer is an explicit "context" pointer for operations that need additional user-defined context.

* Similar to the changes made to the accessors for direct member declarations in a `ContainerDecl`, the `Module::findExportedDeclByMangledName()` method was updated to conditionally execute a different code path in the case of a module that has been loaded from serialized data.

* Some improvements have been made to the fiddle tool:

  * Most importantly, the error-handling logic around Lua script execution has been cleaned up to better match correct Lua idiom. Native functions exposed to the Lua scripts have been changed to just use `lua_call` instead of `lua_pcall`, so rather than attempt to intercept Lua errors they will just automatically propagate them.

  * All Lua-related errors are caught at the top level, and reported in a way that uses the source location of the fiddle template that was being evaluated when the error was raised. In most cases, a Lua error should be accompanied by a stack trace of the Lua evluation state. The file paths and line numbers given should be accurate, but aren't directly double-clickable in the Visual Studio output panel, because they use a different format (a good future change might be to process the Lua stack trace and rewrite it into a format that is better for our needs).

  * Fixed a subtle bug where having "raw" content (parts of the template that should neither be evaluated nor emitted into the output) that consisted of only whitespace could result in a template being translated to invalid Lua code.

* The bulk of the change is, unsurprisingly, in `slang-serialize-ast.cpp`.

  * This file has been refactored enough to look like a complete rewrite. A lot of work has been put into comments that describe the overall approach being taken, so hopefully it can be understood even by somebody who wasn't familiar with the previous code. Some of these are just plain cleanups, rather than being directly related to on-demand serialization.

  * Where possible, the code for reading and writing types that needed custom serialization has been moved so that the read/write functions are next to one another, making it easier to visually confirm that the serialized representations match on the read and write sides.

  * Where possible, the serialization logic for all types (not just the AST nodes, as was the case before) is being generated via fiddle.

  * Rather than just defining `serialize()` overloads for each of the relevant types, the code now defines `Fossilized&lt;...&gt;` specializations for these types as well, to enable statically-typed in-memory traversal of the serialized data. Note, however, that for the most part the `Fossilized&lt;...&gt;` representation types are *not* being used by the code (really only the `ASTModuleInfo` and `ContainerDeclDirectMemberDeclsInfo` types are traversed directly). This can be considered more as work to prove out the design of the `Fossil&lt;...&gt;` template approach, and it may or may not end up being relevant in the future.

  * The trivial bit of work to enable on-demand deserialization is in `ASTSerialReadContext::handleContainerDeclDirectMemberDecls()` where, rather than recursively reading the contained declarations, the method effectively just grabs the current cursor of the `Fossil::SerialReader` (which is pointed into the fossilized data) and stashes it into the `ContainerDeclDirectMemberDecls`, along with a `RefPtr` to the `ASTSerialReadContext` itself. Those stashed pointers are what enables the accessors on `ContaienrDeclDirectMemberDecls` to look up information on-demand.

  * The more interesting bits of the approach mostly come at the end of the file, where the accessor operations for on-demand deserialization are implemented. Once all the relevant work has been done to write the data structures, and produce `Fossilized&lt;...&gt;` types with the right layout, the work itself may seem almost trivial: a little bit of array iteration, and a little bit of binary-search lookup.

  * As a reminder, all of this infrastructure for on-demand deserialization is now in place and able to be invoked by the rest of the compiler, but declarations are currently all being loaded eagerly. The `SLANG_DISABLE_ON_DEMAND_AST_DESERIALIZATION` macro is being used to enable a small bit of extra logic in `ASTSerialReadContext::_cleanUpASTNode` so that the "cleanup" on a just-deserialized `ContainerDecl` includes eagerly querying its list of direct member declarations, which will cause them to be recursively deserialized.</content>
</entry>
<entry>
<title>Move switch statement bodies to their own lines (#5493)</title>
<updated>2024-11-05T17:47:26+00:00</updated>
<author>
<name>Ellie Hermaszewska</name>
<email>ellieh@nvidia.com</email>
</author>
<published>2024-11-05T17:47:26+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=b118451e301d734e3e783b3acdf871f3f6ea851c'/>
<id>urn:sha1:b118451e301d734e3e783b3acdf871f3f6ea851c</id>
<content type='text'>
* Move switch statement bodies to their own lines

* format

---------

Co-authored-by: Yong He &lt;yonghe@outlook.com&gt;</content>
</entry>
<entry>
<title>format</title>
<updated>2024-10-29T06:49:26+00:00</updated>
<author>
<name>Ellie Hermaszewska</name>
<email>ellieh@nvidia.com</email>
</author>
<published>2024-10-29T06:49:26+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=f65d756bff8d4c5cbc15bd0322a2ae8e6b896a21'/>
<id>urn:sha1:f65d756bff8d4c5cbc15bd0322a2ae8e6b896a21</id>
<content type='text'>
* format

* Minor test fixes

* enable checking cpp format in ci</content>
</entry>
<entry>
<title>Use ankerl/unordered_dense as a hashmap implementation (#3036)</title>
<updated>2023-08-16T00:57:47+00:00</updated>
<author>
<name>Ellie Hermaszewska</name>
<email>ellieh@nvidia.com</email>
</author>
<published>2023-08-16T00:57:47+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=45d9961a6a86d184248ef84f6a07125b0c224f97'/>
<id>urn:sha1:45d9961a6a86d184248ef84f6a07125b0c224f97</id>
<content type='text'>
* Correct namespace for getClockFrequency

* missing const

* Add missing assignment operator

* Remove unused variables

* Return correct modified variable

* Use stable hash code for file system identity

* terse static_assert

* Structured binding for map iteration

* Make (==) and getHashCode const on many structs

* Add ConstIterator for LinkedList

* Replace uses of ItemProxy::getValue with Dictionary::at

* Extract list of loads from gradientsMap before updating it

* Const correctness in type layout

* Add unordered_dense hashmap submodule

* Use wyhash or getHashCode in slang-hash.h

* refactor slang-hash.h

* Use ankerl/unordered_dense as a hashmap implementation

Notable changes:
- The subscript operator returns a reference directly to the value,
  rather than a lazy ItemProxy (pair of dict pointer and key)

slang-profile time (95% over 10 runs):

- Before: 6.3913906 (±0.0746)
- After:  5.9276123 (±0.0964)

* 64 bit hash for strings

So they have the same hash as char buffers with the same contents

* Narrowing warnings for gcc to match msvc

* revert back to c++17

* Correct c++ version for msvc

* Use path to unordered_dense which keeps tests happy

* Do not assign to and read from map in same expression

* Remove redundant map operations in primal-hoist

* Split out stable hash functions into slang-stable-hash.h

* 64 bit hash by default

* regenerate vs projects

* Correct return type from HashSetBase::getCount()

* correct width for call to Dictionary::reserve

* Use stable hash for obfuscated module ids

* Signed int for reserve

* clearer variable naming

* Parameterize Dictionary on hash and equality functors

* Allow heterogenous lookup for Dictionary

* missing const

* Use set over operator[] in some places

* Remove unused function

* s/at/getValue</content>
</entry>
<entry>
<title>Fix most of the disabled warnings on gcc/clang (#2839)</title>
<updated>2023-04-27T04:36:59+00:00</updated>
<author>
<name>Ellie Hermaszewska</name>
<email>ellieh@nvidia.com</email>
</author>
<published>2023-04-27T04:36:59+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=3acbe8145c60f4d1e7a180b4602a94269a489df5'/>
<id>urn:sha1:3acbe8145c60f4d1e7a180b4602a94269a489df5</id>
<content type='text'>
</content>
</entry>
<entry>
<title>StringBuilder to lowerCamel (#2840)</title>
<updated>2023-04-25T16:25:52+00:00</updated>
<author>
<name>jsmall-nvidia</name>
<email>jsmall@nvidia.com</email>
</author>
<published>2023-04-25T16:25:52+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=5abee6a0a30c7c965138ec7286b7f1b21b201731'/>
<id>urn:sha1:5abee6a0a30c7c965138ec7286b7f1b21b201731</id>
<content type='text'>
* #include an absolute path didn't work - because paths were taken to always be relative.

* WIP lowerCamel Dictionary.

* WIP more lowerCamel fixes for Dictionary.

* Add/Remove/Clear

* GetValue/Contains

* Fix tabs in dictionary.
Count -&gt; getCount

* Fix fields with caps.

* Key -&gt; key
Value -&gt; value
Use m_ for members where appropriate.
Use lowerCamel in linked list.

* Some small fixes/improvements to Dictionary.

* Kick CI.

* Small tidy on String.

* Append -&gt; append

* ToString -&gt; toString
ProduceString -&gt; produceString

* Small fixes.

* StringToXXX -&gt; stringToXXX

* Fix typo introduced by Append -&gt; append.

* Made intToAscii do reversal at the end.

---------

Co-authored-by: Yong He &lt;yonghe@outlook.com&gt;</content>
</entry>
<entry>
<title>Fix mismatched malloc/delete[] in toWString (#2758)</title>
<updated>2023-03-30T19:46:27+00:00</updated>
<author>
<name>Ellie Hermaszewska</name>
<email>ellieh@nvidia.com</email>
</author>
<published>2023-03-30T19:46:27+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=72f792858a951821ff266295e018c9472fe02a14'/>
<id>urn:sha1:72f792858a951821ff266295e018c9472fe02a14</id>
<content type='text'>
Co-authored-by: Yong He &lt;yonghe@outlook.com&gt;</content>
</entry>
<entry>
<title>Language server: auto completion of `import` file and directories. (#2312)</title>
<updated>2022-07-01T22:09:24+00:00</updated>
<author>
<name>Yong He</name>
<email>yonghe@outlook.com</email>
</author>
<published>2022-07-01T22:09:24+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=0bf899a5f8110fbea97272bdda03b68b91745e51'/>
<id>urn:sha1:0bf899a5f8110fbea97272bdda03b68b91745e51</id>
<content type='text'>
* Language server: auto completion of `import` file and directories.

* Completion of include path.

* Improvements.

Co-authored-by: Yong He &lt;yhe@nvidia.com&gt;</content>
</entry>
<entry>
<title>Language server fixes and improvements (#2304)</title>
<updated>2022-06-27T22:36:00+00:00</updated>
<author>
<name>Yong He</name>
<email>yonghe@outlook.com</email>
</author>
<published>2022-06-27T22:36:00+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=b7638b8fffe78ade657f361cadc08dffc8c10acf'/>
<id>urn:sha1:b7638b8fffe78ade657f361cadc08dffc8c10acf</id>
<content type='text'>
* Language server: Inlay hints.

* Signature help for base exprs that is not a declref.

* Fix checking of jvp operator.

* Fix.

* Add clang-format based auto formatting.

* Fix clang error.

* Fix clang-format discovery logic.

* Fine tune auto formatting and completion experience.

* Update macos workflow.

* Fixes to configurations.

* Fix parser recovery to trigger completion for index exprs.

* Typo fix.

Co-authored-by: Yong He &lt;yhe@nvidia.com&gt;</content>
</entry>
<entry>
<title>Major language server features. (#2264)</title>
<updated>2022-06-07T21:10:49+00:00</updated>
<author>
<name>Yong He</name>
<email>yonghe@outlook.com</email>
</author>
<published>2022-06-07T21:10:49+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=0c64995ea28febcc7d38e1519da8d93391ce2e7d'/>
<id>urn:sha1:0c64995ea28febcc7d38e1519da8d93391ce2e7d</id>
<content type='text'>
* Major language server features.

* Include slangd in binary release.

* Fix compiler issues.

* Fix compiler error.

* Completion resolve.

* Various improvements.

* Update diagnostic test expected output.

* Bug fix for source locations.

* Adjust diagnostic update frequency.

* Update github actions to store artifacts.

* Fix infinite parser loop.

* Fix parser recovery.

* Fix parser recovery.

* Update test.

* Fix test.

* Disable IR gen for language server.

* Allow commit characters in auto completion.

* Fix lookup for invoke exprs.

* More parser robustness fixes.

* update solution file

Co-authored-by: Yong He &lt;yhe@nvidia.com&gt;</content>
</entry>
</feed>
