-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an overload of CSharpSyntaxTree.Create
that allows to specify checksum algorithm
#62923
Comments
Assigned to @333fred and @CyrusNajmabadi to triage/drive as needed, as area owners for api-syntax. |
@tmat what's the motivation for using a different hashing algorithm? Not criticizing, just curious. |
Need to use the same hash algorithm as specified in the project settings. As explained in #62840, Hot Reload needs to check for a given Document whether or not it matches the compiled code. It does so by comparing the checksum stored in the PDB with the checksum of the Document. The checksum algorithm thus needs to flow through the system. |
Another reason is that it should be possible for users of our API to avoid using SHA1 entirely. Having SHA1 as a default parameter of an API that can't be changed makes that impossible. |
API Review
|
The tree either holds on a SourceText, if it's created directly from SourceText or it creates SourceText lazily if it's created from a syntax node: In the latter case the checksum algorithm is passed from the SyntaxTree to the SourceText being created. Currently ParsedSyntaxTree is only created with hardcoded checksum algorithm. The property is added to SyntaxTree in order to avoid creating the underlying SourceText unnecessarily, only when the checksum algorithm is needed. |
API Review
|
Changes merged in #63832 enabled defining a subclass of CSharpSyntaxTree/VisualBasicSyntaxTree that customizes creation of SourceText. This approach can be used instead of passing checksum algorithm to SyntaxFactory.CreateTree. |
Background and Motivation
The existing API always used
SourceHashAlgorithm.Sha1
but the IDE needs to be able to create parsed syntax trees backed by text with specific checksum algorithm.See #62840 for the change, including usage in the IDE.
Proposed API
In addition, similarly to
SyntaxTree.Encoding
make checksum algorithm available fromSyntaxTree
instance:class SyntaxTree { + public abstract SourceHashAlgorithm ChecksumAlgorithm { get; } }
and add a factory method to
SyntaxFactory
:The text was updated successfully, but these errors were encountered: