Why PathId holds a reference to its owner SymbolTable? #3228
hs-apotell
started this conversation in
General
Replies: 1 comment
-
@hzeller @alaindargelas I am about to create additional PRs that are on top of the one that was submitted last week. @hzeller raised some concerns/questions about my design decision to have a SymbolTable reference in PathId. The new PR are compiled based on this design and so would like to confirm whether, if any, changes are needed to the existing design before I make more changes. It will be easier to make those changes now before I add more code on top of it. Please take a moment to review the design decision and raise any concerns/questions that you might have. Let the conversation flow. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
For reference, this was discussed briefly in few various contexts -
Proposed: SymbolTable can hold reference to owning SymbolTable.
Pros:
Cons:
The proposed strategy was implemented in PathId. For SymbolId, it was merely a way to ease its use but for PathId, in some context, it is a necessity. May be the term PathId isn't appropriate but the need for it is justified.
PathId is intended to always hold an absolute path i.e. rooted path and FileSystem is intended to be extended in client application to add features that are either application specific or just doesn't belong in Surelog for any number of reasons. In some cases, it comes down to licensing issues as well because of third party libraries that might be involved in extending the functionality. All transactions between Surelog and extended FileSystem are using PathId. The API is much cleaner if that doesn't involve having to deal with SymbolTable as well.
Yes, the client application doesn't and it doesn't have to. FileSystem is a singleton and it is intended to be accessed by all threads in the system. The API doesn't know the context in which a particular API is being called. The caller does and yes, the SymbolTable can be passed as an additional argument to the API. That's an additional argument to every API call in the FileSystem.
SymbolTable themselves aren't thread-safe. I did try to introduce a version to make it thread-safe but it was deemed inappropriate within the overall design (each preprocessor and compiler has its own SymbolTable). FileSystem itself doesn't have its own SymbolTable. But potentially could but this implementation will have to be thread-safe because FileSystem itself is a singleton, used across any number of threads. In the current implementation, only a handful of APIs are deemed necessary to be thread-safe. With FileSystem owning its own SymbolTable, all APIs will need to be thread-safe.
Plus, FileSystem is intended to be extended in client application. Do we really want to force clients to implement a thread-safe FileSystem API? I hold my reservations on that.
There might be a better design for PathId or may be PathId itself shouldn't be called PathId.
I am open to suggestions/discussions and making the change itself.
P.S. Please take a moment to review the attached FileSystem implementation. This is complete implementation and should help decide the direction of where this discussion goes.
FileSystem.h.txt
FileSystem.cpp.txt
Beta Was this translation helpful? Give feedback.
All reactions