Metadata refactor & guidelines - #1107
ThomasHaas wants to merge 6 commits into
Conversation
|
We wanted to discuss some guidelines about the usage of metadata. I will bring up some points/questions (not exhaustive) that we should talk about with tentative answers. (1) Q: Is metadata always optional or can it be mandatory? (2) Q: Should metadata be able to modify the semantics of, e.g., events? (3) Q: Can the presence of metadata affect the tools outcome? (4) Q: How complex can metadata be? (5) Q: Where should metadata classes be located? |
Performance comparisonLinux x64Benchmark detailsMemory model: vmm
Memory model: aarch64
Memory model: power
Total
3 benchmark(s) omitted because both averages were below 5 seconds. macOS ARM64Benchmark detailsMemory model: vmm
Memory model: aarch64
Memory model: power
Total
|
I think |
|
I think there are different possible ways to go about it. We can try with a basic |
…s there. Make Event-specific metadata inner classes of Event.
5efd8d5 to
4ee9f46
Compare
Add SourcePath (unused)
I think the "if its presence can be guaranteed by us, making it mandatory is ok" is a good trade-off.
Agree.
I think the following would fit in this Q. Imagine we would implement support for the
As we already discussed offine, I am in favor of keeping it class-internal as we already did in #1104. BTW, I think we should add this documentation as part of the |
| // If source is a path, we take the last path element | ||
| // if source is not a path, the function will return it as is |
There was a problem hiding this comment.
You mean Path.of(source).getFileName().toString() == source if the path does not exists? If so I would explicitly say so to avoid confusion.
EDIT: it seems Path.of("/").getFileName() would return null
There was a problem hiding this comment.
It's not about path existence but rather path shape: not/a/path/to/a/file would still yield file.
Technically, Path.of() can throw an exception if there are invalid symbols in the path though. I can also revert it back to the old which used explicit substring manipulation, but now that I think about it, the old code expected / as separator which may fail under Windows... I guess we should just use a proper Path.
it seems Path.of("/").getFileName() would return null
Interesting, I expected it to return the empty string.
You just mentioned one in point (3) though. The Given these arguments, I think EDIT: If the location metadata would be a
Sure, but first we need to have some consensus :). I didn't want to put my proposed rules into the text before anyone showed agreement :) |
This is a new one. Given how many CI runs we had without this error, debugging this one is going to be nightmare. I think RA and its reasoning over stratifications might be the most likely culprit here. |
I asked an agent to reproduced and it could not. This plus the fact that I never seen that test fail (not only in this PR history, but any any previous run) suggests the chances to hit it again are extremely low. |
|
I couldn't reproduce it either and it is orthogonal to this PR. However, if you wanna debug it, I don't think you should just run the code until the error occurs but instead check the may/must sets in every run. If the error is due to RA, then maybe there are fluctuations in RA that do not immediately affect the verdict but still show the presence of a bug. Apart from RA, I cannot imagine what else could be wrong. |
|
A few comments about the current state of the metadata following the proposed guidelines:
I also think this pattern is currently allowed and can cause problems We should probably have some guidelines (and maybe even automatic checks that these are followed) about which kind of metadata can be combined. About the guidelines: should we maybe split the matadata into different "sub-types"? Something like
|
| } | ||
| } | ||
|
|
||
| record Generic(Path sourcePath, int lineNumber) implements SourceLocation { |
There was a problem hiding this comment.
Using Path here may cause problems. This metadata is populated using debug information from LLVM/SPIRV. If the file was generated by Windows, but we are running the code now from Linux, the incompatibility between systems will results in something like "null#line"
There was a problem hiding this comment.
I don't understand. The point of Path is that it is OS-agnostic, no? Why would we have issues there?
Is it because the LLVM visitor constructs the path via directory + "/" + file and so the separator is inconsistent (we should use Path.of(directory, file) though)? Even then, / is a valid separator on Windows I think.
There was a problem hiding this comment.
Suppose you are given a *.ll file generated from Windows. The debug information contains C:\projects\demo\test.c.
Dartagnan later parses that LLVM file on Linux:
Path sourcePath = Path.of("C:\\projects\\demo\\test.c");
sourcePath.getFileName();
Because \ is not a path separator on Linux, the result is the entire string C:\projects\demo\test.c instead of test.c.
To be fair, I think we have the same problem on development. Also, since debug information is probably less useful when we are dealing with the compiled code rather than the source, this is not much of a real problem.
There was a problem hiding this comment.
Ok, from Windows to Linux there are problems (the other way around is fine). It does not result in null#line though but rather an overly verbose source location. The same problem does not exist on development because we explicitly use directory + "/" + file which will result in a path like C:\\projects\\demo/test.c with mixed separators. We then do the split on "/" to extract the file name.
I guess we need to add a utility that replaces "\\" by "/" in paths to normalize them.
There was a problem hiding this comment.
Hmm, I think there is a different underlying problem. If the source path was specified as C:\\projects\\demo\\test.c and we verify this on Linux/MacOS, the source path we track should still be the windows path, right? I mean, are we allowed to represent the path differently at all? I wouldn't be so strict about it and allow the path to be tracked as C:/projects/demo/test.c instead, but it certainly is something to consider.
The point of
Yeah, that sucks a bit. For the most part, the metadata is generated within
I don't think this is a real issue to be honest. The frontend should be generating that metadata and it should know not to attach multiple types of source information to the same object. Trying to come up with a fix to a problem that will likely never arise is wasted effort IMO.
I also thought about a more fine-granular distinction, but I'm not sure what distinctions are practically useful and if they are needed yet. I like the provenance category insofar as it captures the fact that the metadata should be preserved through modifications of the annotated object (in particular copies should keep that metadata). Btw. now that I think about it, maybe we should move |
|
I think we should avoid making the framework too rigorous: the guidelines are "soft constraints" and not hard rules. |
|
Btw. we use several tags internally like |
As discussed in #1105, I moved the basic metadata classes to a top-level package.
I made all Event-specific metadata inner classes of
Event.I moved
SourceLocationto the top-level package, seeing that is could (and probably should) be reused for programs (#1105).