This repository has been archived by the owner on Nov 4, 2023. It is now read-only.
Optimised GetDecl process for faster semanting across multiple files #86
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I discovered a significant speed-bump in the semanting process: every time a declaration made in file A is used in file B, the compiler rebuilds the entire import hierarchy of file B from scratch and searches every declaration map individually for conflicts.
In practice, this resulted in a near-linear relationship between number of files and semanting time for any given quantity of code.
This modified implementation improves performance by constructing the import hierarchy of file B just once, the first time a declaration is sought outside the file. From this it caches a single map of synonyms (lists of decls with the same identifier).
Subsequently, seeking an external decl requires only a single string map lookup to obtain the appropriate synonym list. In correct code, only one synonym will pass the final accessibility test. If more than one pass, a duplicate identifier error is reported (via the old method, both for simplicity and to sanity-check the behaviour of the new system)
The upshot is a considerable reduction in semanting time on projects with large numbers of source files (from 45 seconds to under 3 seconds in our case).