Only refer to LLVM symbol table in calls to Symbol#to_s
#15486
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.
The compiler places the string contents of all symbols defined in the source code into a special
:symbol_table
LLVM global variable in the main LLVM module:Every LLVM module, without exception, also declares it:
Since the total number of symbols is part of the variable type, adding or removing any symbol invalidates all object files in the Crystal cache, even though only
Symbol#to_s
, or rather@[Primitive(:symbol_to_s)]
, has access to this variable.This PR removes this declaration except where the primitive accesses it. Changes to the symbol table will only affect LLVM modules that call
Symbol#to_s
(the primitive body itself is inlined). Building an empty file, replacing it withx = :abcde
, then rebuilding the same file will now give:(
Crystal
is also invalidated because the return type ofCrystal.main
is nowSymbol
instead ofNil
; appendingnil
to the file makes this module reusable.)Note that it is still possible to invalidate large portions of the cache from the addition or removal of symbols, because their indices are allocated sequentially, and inlined on every use. Something like #15485 but for
Symbol
values would solve that.