Skip to content

Multiple relations on single parameter#166

Merged
jkoritzinsky merged 1 commit into
SharpGenTools:masterfrom
andrew-boyarshin:attack_of_the_clones
May 13, 2020
Merged

Multiple relations on single parameter#166
jkoritzinsky merged 1 commit into
SharpGenTools:masterfrom
andrew-boyarshin:attack_of_the_clones

Conversation

@andrew-boyarshin

@andrew-boyarshin andrew-boyarshin commented Apr 30, 2020

Copy link
Copy Markdown
Contributor

Example: IUIAnimationInterpolator2::SetInitialValueAndVelocity, cDimension there is a length for both initialValue and initialVelocity), e.g. length(initialValue),length(initialVelocity).

  • Use IList<MarshallableRelation> to store all relations on a parameter
  • Reimplement RelationParser to be a proper language parser using Roslyn
  • Drop IHasRelatedMarshallable interface
  • Prevent crash when relation specifies parameter name, which is absent on the method. Print helpful message instead.
  • Drop workaround for SDK issue, since the fix made its way to daily build. Affected Microsoft.NET.Sdk versions - only 5.0 previews up to 5.0.100-preview.5.20230.9 (first version to contain the fix).
  • Add advanced test log message assertion facilities
  • Fix MarshalledElementFactoryTests.ParameterWithStructSizeRelationLogsError testing the wrong thing

@andrew-boyarshin

andrew-boyarshin commented Apr 30, 2020

Copy link
Copy Markdown
Contributor Author

After sending this PR, I've started writing tests. While everything I've tested on works correctly, I'm worried about const relation. Before this PR (when there was only one relation) it was simple: everything between the first and last bracket is the value to be stored for later use. Now, I've implemented custom language (there is even support for string literals, not pushed to remote for now), and it still doesn't guarantee that some complex const expression wouldn't confuse the parser. I have an idea how to solve the problem: reuse Roslyn. Wrap passed string in new[] { ... }, call ParseExpression and traverse C# syntax tree that is guaranteed to be completely correct.

* Use IList to store all relations on a parameter
* Reimplement RelationParser to be a proper language parser based on Roslyn
* Drop IHasRelatedMarshallable interface
* Prevent crash when relation specifies parameter name, which is absent on the method. Print helpful message instead.
@andrew-boyarshin

andrew-boyarshin commented May 1, 2020

Copy link
Copy Markdown
Contributor Author

@jkoritzinsky this PR is ready to be reviewed.

@andrew-boyarshin

andrew-boyarshin commented May 1, 2020

Copy link
Copy Markdown
Contributor Author

Note, that this PR enables new syntax: Length, Const and StructSize instead of the older variants. Older variants are still supported via string replacement, but that's obviously non-ideal. If const or struct-size occur in substring of relation arguments, they will be replaced too, but warning will be emitted (the least I can do).
The new syntax should be documented, but I would like to postpone the changes to the docs till later PRs (I expect more to come, the next one will be about value type marshalling and/or MSBuild SDK targets file refactoring).

Relatively unrelated question:
After some work on SharpGen, is the targets split (made in #20) necessary anymore? There is no more CodeGenApp. I think about batching these targets and tasks. That will remove mandatory serialization & deserialization (+ I/O) of large XML files on every build. This is also a blocker for moving from CastXML, potential Source Generators and Function Pointers proposal adoption.

@jkoritzinsky

Copy link
Copy Markdown
Member

Some of the tasks (the ones that discover which C++ files are inputs and which C# files are outputs) definitely need to stay separate. The rest of them could probably merge together. My goal with the separation was to enable generation to work incrementally, but the design of the config files breaks that.

@andrew-boyarshin

andrew-boyarshin commented May 1, 2020

Copy link
Copy Markdown
Contributor Author

@jkoritzinsky yep, I agree the tasks that compute inputs/outputs must stay separate.

My goal with the separation was to enable generation to work incrementally, but the design of the config files breaks that.

Could you please elaborate on that? I mean, I think it's because the config files specify inputs (source headers) MSBuild is not aware of, but I haven't given it much thought. What do you think is the cause of SharpGen regenerating everything almost on every build?

Meanwhile (waiting on this PR to be reviewed and merged), I'm having a look at #144. The patch there is insufficient (even SdkTests are failing, and for a good reason), I'm working on a better solution. upd: better solution implemented on my draft PR.

@jkoritzinsky

Copy link
Copy Markdown
Member

There are a few MSBuild tasks that the targets files use to enable discovering all of the input headers into SharpGenTools so that we re-run generation when only the native headers are changed and not require extraneous edits to the mapping files.

@andrew-boyarshin

andrew-boyarshin commented May 8, 2020

Copy link
Copy Markdown
Contributor Author

@jkoritzinsky it still doesn't explain why SharpGen 1.2 sometimes regenerates bindings for no good reason (observed numerous times, but I couldn't grab binlog since I was using Rider IDE). Meanwhile, I'm finishing my rework of SharpGen targets for v2:

  1. Single task for running SharpGen, greatly simplified targets file
  2. All outputs are now static. This means, among other things, that 5 generated .cs files contain code for all namespaces/config files, no subfolders for generated files.
  3. Well-defined up-to-date checks behavior (with extensive documentation based on actual MSBuild sources)
  4. Fixed missed regeneration when using undocumented <file /> config file inclusion method
  5. Reimplemented documentation providers extensibility point from scratch to use Roslyn approach (like the one used for Analyzers/Source Generators, but based on implementing the interface instead of being marked with an attribute)
  6. Reimplemented MSDN doc provider (MSDN retired, Microsoft Docs are used now), added tests
  7. Dropped support for alternative SharpGen.Runtime assemblies, but improved WellKnownType overriding to compensate for that

This will take a couple more days, then I'll push it to draft PR branch. I hope this PR will be reviewed & merged by that time.

@jkoritzinsky

Copy link
Copy Markdown
Member

Rider’s usage of MSBuild is particularly poor since they try to do shortcuts. I wouldn’t be amazed if they broke things.

I’ll try to review this over the weekend so we can get it merged in.

@andrew-boyarshin

andrew-boyarshin commented May 13, 2020

Copy link
Copy Markdown
Contributor Author

Just a friendly reminder and an update on the following PRs.

  1. Now there are only 3 tasks (SharpPatch, SharpGen and a new SharpGen-related task for a new property cache), solid target up-to-date checks behavior
  2. All unit tests are now in a single project (fixes dotCover not showing the results properly in Rider and reduces test logger code duplication)
  3. Extensions don't work now (extension assembly dependencies fail to load). This so obviously should work that I don't know why it doesn't, I feel like it's either a bug in AssemblyLoadContext, or myself, probably the latter. I'll fix that, of course, but today was a disappointing day.
  4. SharpGenTools.Sdk is now an actual MSBuild SDK, removes the need to remember to specify PrivateAssets attribute on a PackageReference
  5. SharpGen.Runtime is now implicitly referenced (always correct matching version)
  6. Filed/hit some NuGet and MSBuild issues. Nothing critical, but one issue was somewhat annoying.

@jkoritzinsky jkoritzinsky merged commit 96c8144 into SharpGenTools:master May 13, 2020
@jkoritzinsky

Copy link
Copy Markdown
Member

That work sounds fantastic! I’ve merged this PR in in the meantime so we can keep moving forward.

@andrew-boyarshin andrew-boyarshin deleted the attack_of_the_clones branch May 28, 2020 04:34
@andrew-boyarshin andrew-boyarshin added this to the 2.0 milestone Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants