-
Notifications
You must be signed in to change notification settings - Fork 173
Apply common project properties to LlvmBinding project #931
Apply common project properties to LlvmBinding project #931
Conversation
|
Thanks @AndreyTretyak for the great contribution! Regarding the StyleCop suggestion for changing the header, that is indeed left intentionally to indicate the project these files were originally copied from. But all the rest of the style clean up sounds excellent. For the missing types, this is most likely because they have been intentionally removed as part of adapting the code to our use, but not all doc comment references were removed, and I agree that can be fixed in a later pass through the code. I should have time to review this over the next day or two, and will ping you if I have any questions or concerns. |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
It should be possible to have a different StyleCop configuration for the LlvmBindings project that specifies the right copyright header. |
swernli
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lot's here, but it looks good! Just a couple minor comments that you can either address now or can be cleaned up later. Thanks again!
src/QsCompiler/LlvmBindings/LLVMSharpExtensions/LLVMValueRefExtensions.cs
Show resolved
Hide resolved
|
Awesome! Thanks, @AndreyTretyak for the great contribution! |
Nice idea. I've tested it and it works and even it even located some wrong headers but raises some additional questions (ex. config override, common props changes, and header in delay sign), so I would prefer to submit it as a follow-up to simplify the discussion. |
|
@swernli thank you for the review, I can imagine it was not easy. |
|
@AndreyTretyak Sounds good to me. I set up the auto-merge, so assuming the latest merge from main and build succeeds it should go in. Thanks again! |
|
/azp list |
|
Commenter does not have sufficient privileges for PR 931 in repo microsoft/qsharp-compiler |
|
/azp run |
|
Commenter does not have sufficient privileges for PR 931 in repo microsoft/qsharp-compiler |
@swernli I think I need your help triggering the last validation pipeline |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
|
@swernli @SamarSha I'm sorry for pinging you again. Could it be related to this PR somehow? |
|
It does appear to have been an intermittent failure, since it passed on rerun, but it's not one I've seen before, so I'll keep an eye out in case it crops up again. |
PR for the issue #922
I'm sorry in advance for the PR size. I should've stopped earlier :)
Most of the changes are automatic, I'll try to describe the most important parts here.
I also understand that it's a risky change to take from an external contributor, so feel free to decline.
StyleCop
Most of the changes are about adjusting whitespaces, reordering
using's, addingthis.and dots in comments, and reordering constructors (the most annoying part). Most of the changes that I consider safe are here f3589a6 and here 2bc853fCases where I actually had to change code:
GlobalCopyAllMetadata, so now they start with an upper case letter. It might be a problem since the method is public, an alternative could be just suppressing warning. Commit with the change 84f83e0BitcodeModulehas two fields that StyleCop really doesn't like.IsDisposedis a public field that basically allows anybody to set it totrue, that looked wrong so I replaced it with property (public getter and private setter), but there might be a reason for it to be how it is.ModuleHandleis an internal property with a mutable struct as type, so I've replaces it with a private field and internal property that returns value by ref. It should provide the same behavior, excluding recursion.Commit with the change 84f83e0
Nullablity
The majority of the changes are about marking return type as nullable, so they should be only beneficial.
Most of them are here be2128a
But the are some risky changes where I've decided to change behavior:
ValueAttributeDictionary.TryGetValuebecause innetstandard2.1dictionary interface didn't have proper parameter attribute, suppression could be removed after project target changed tonet5.0or higher. It might cause incorrect nullable marking if the type used via the interface in projects targetingnetcoreapp3.1or lower, but that also the case for any dictionary.Value.FromHandle<T>andTypeRef.FromHandle<T>, both of them usedasfor casting so could returnnullin case of the wrong type, but judging from methods usage null was not expected, so I assumed it's that replacing it with direct cast might be more appropriate. In addition to thatTypeRef.FromHandle<T>(LLVMTypeRef typeRef)was returningnullif input struct isdefault, so I've removed the check, so it would fail withArrgumentException("Handle is null"). I understand it's very controversial decisions and behavior change, an alternative would mean marking a big chunk of the project with nullability markers and checks. That's definitely possible, but I've wanted to check with you first that it would be a proper thing to do here. Commit ea47021public class Value { internal static T FromHandle<T>(LLVMValueRef valueRef) where T : Value { var context = valueRef.GetContext(); - return context.GetValueFor(valueRef) as T; + return (T)context.GetValueFor(valueRef); } } internal class TypeRef { internal static T FromHandle<T>(LLVMTypeRef typeRef) where T : class, ITypeRef { - if( typeRef == default ) - { - return default; - } var ctx = GetContextFor(typeRef); - return ctx.GetTypeFor(typeRef) as T; + return (T)ctx.GetTypeFor(typeRef); } }Future improvements
crefof documentation comments (CS1574) currently suppressed. I'm not sure where they lost during refactoring, were never accessible, or just require a proper namespace. Probably the easiest fix would be replacingcrefwith regular text if nobody knows how to reference them.AssemblyCommon.propsfile could be done by putting import intoDirectory.Build.propsin the root of the repo, then each new project would automatically use it without the need to modify the project (you can also add a way of disabling it if needed). More info https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2019