summaryrefslogtreecommitdiffstats
path: root/source/slang/diagnostics.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-01-02 10:44:05 -0800
committerGitHub <noreply@github.com>2018-01-02 10:44:05 -0800
commit66f9a7cefe351d7e0a27fa77fbfe5ca93f2d8133 (patch)
tree752942257513c580185bd3e42680d1447ee7716e /source/slang/diagnostics.cpp
parent17369d9a4f26a15393c15a9de4199d2963236c0b (diff)
Bug fix for humane source location computation. (#346)
Fixes #345 A brief refresher: a `SourceLoc` in the Slang implementation is just an integer (more or less an absolute byte index into all of the source compiled so far). We convert that integer to a "humane" source location (a file name and line/column numbers) by finding the file and line that match the integer via binary search. The data structures used for that search are owned by a `SourceManager`. In order to avoid running out of source locations when used in a long-running application (that might reload shaders many times), the implementation creates one `SourceManager` per `CompileRequest`, along with a single shared `SourceManager` that is used for locations in the builtin libraries. The root of the bug here was that some code was using the `SourceManager` for a compile request when it should have been using the one for the builtins. This happened because one source manager was asked to translate a `SourceLoc` into a humane location, which first involves "expanding" that location (figuring out which file it belongs to, and which source manager owns that file), and failed to realize that the expanded location might use a different source manager (either the current one or one of its "parents"). I fixed this by reworking the API so that the mapping from an expanded location to a humane one is no longer a member of a source manager (since the correct source manager can be looked up in the associated expanded location). Hopefully this will prevent this class of error in the future.
Diffstat (limited to 'source/slang/diagnostics.cpp')
-rw-r--r--source/slang/diagnostics.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/source/slang/diagnostics.cpp b/source/slang/diagnostics.cpp
index 18e5f9a4d..4f4a33e60 100644
--- a/source/slang/diagnostics.cpp
+++ b/source/slang/diagnostics.cpp
@@ -155,7 +155,7 @@ static void formatDiagnostic(
auto sourceManager = sink->sourceManager;
auto expandedLoc = sourceManager->expandSourceLoc(diagnostic.loc);
- auto humaneLoc = expandedLoc.sourceManager->getHumaneLoc(expandedLoc);
+ auto humaneLoc = getHumaneLoc(expandedLoc);
sb << humaneLoc.getPath();
sb << "(";