Skip to content
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

[Rgen] Add support to the syntax factory to generate setters for fields. #21983

Merged
merged 3 commits into from
Jan 16, 2025

Conversation

mandel-macaque
Copy link
Member

@mandel-macaque mandel-macaque commented Jan 15, 2025

This commit has the following important changes to carefully review:

  1. We move to make the method name otpional in the GetConstant and SetConstant. This is done by the CallerMemberName attribute which will add the name automatically to match the caller. This is done at compile time and is equal to nameof. This way we reduce typing and typos.
  2. Added a tuple to return the getter and setter. This way we make sure that when we add support for a new kind of field, that we add both.
  3. For those fields that we cannot set, we return a throw expression. Ideally this will never happen because we will make sure the analyzer stops us from trying to use Set properties on unsupported type.
  4. Added support for casting in the Setter. We are using a lambda factory that captures the type of the property ONLY when is needed, this should be lazy enough.

With this change we should be able to fully generate field properties.

…lds.

This commit has the following important changes to carefully review:

1. We move to make the method name otpional in the GetConstant and
   SetConstat. This is done by the CallerMemberName attribute which will
   add the name automatically to match the caller. This is done at
   compile time and is equal to nameof. This way we reduce typing and
   typos.
2. Added a tuple to return the getter and setter. This way we make sure
   that when we add support for a new kind of field, that we add both.
3. For those fields that we cannot set, we return a throw expression.
   Ideally this will never happen because we will make sure the analyzer
   stops us from trying to use Set properties on unsupported type.
4. Added support for casting in the Setter. We are using a lambda
   factory that captures the type of the property ONLY when is needed,
   this should be lazy enought.

With this change we should be able to fully generate field properties.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (3)

src/rgen/Microsoft.Macios.Generator/Extensions/SpecialTypeExtensions.cs:15

  • [nitpick] The parameter name 'self' is ambiguous. It should be renamed to 'type' or 'specialType'.
public static string? GetKeyword (this SpecialType? self) => self switch {

src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.cs:70

  • Ensure that the behavior of the ThrowException method is covered by tests.
static CompilationUnitSyntax ThrowException (string type, string message)

src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.cs:85

  • Ensure that the behavior of the ThrowNotSupportedException method is covered by tests.
static CompilationUnitSyntax ThrowNotSupportedException (string message)
@mandel-macaque mandel-macaque changed the title [Rgen] Add support to the syntaxt factory to generate setters for fields. [Rgen] Add support to the syntax factory to generate setters for fields. Jan 15, 2025
Copy link
Contributor

⚠️ Your code has been reformatted. ⚠️

If this is not desired, add the actions-disable-autoformat label, and revert the reformatting commit.

If files unrelated to your change were modified, try reverting the reformatting commit + merging with the target branch (and push those changes).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@mandel-macaque mandel-macaque merged commit 7ae40bf into main Jan 16, 2025
36 of 41 checks passed
@mandel-macaque mandel-macaque deleted the dev/mandel/property-setter-dlfcn branch January 16, 2025 12:06
@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 7ae40bf77f815e5eb01c9c08b445c651f4e34ea8 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 7ae40bf77f815e5eb01c9c08b445c651f4e34ea8 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 7ae40bf77f815e5eb01c9c08b445c651f4e34ea8 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build] Windows Integration Tests passed 💻

All Windows Integration Tests passed.

Pipeline on Agent
Hash: 7ae40bf77f815e5eb01c9c08b445c651f4e34ea8 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build] Tests on macOS M1 - Mac Monterey (12) passed 💻

All tests on macOS M1 - Mac Monterey (12) passed.

Pipeline on Agent
Hash: 7ae40bf77f815e5eb01c9c08b445c651f4e34ea8 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build] Tests on macOS M1 - Mac Ventura (13) passed 💻

All tests on macOS M1 - Mac Ventura (13) passed.

Pipeline on Agent
Hash: 7ae40bf77f815e5eb01c9c08b445c651f4e34ea8 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build] Tests on macOS arm64 - Mac Sequoia (15) passed 💻

All tests on macOS arm64 - Mac Sequoia (15) passed.

Pipeline on Agent
Hash: 7ae40bf77f815e5eb01c9c08b445c651f4e34ea8 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

.NET ( No breaking changes )

❗ API diff vs stable (Breaking changes)

.NET ( ❗ Breaking changes ❗ )

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 7ae40bf77f815e5eb01c9c08b445c651f4e34ea8 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build] Tests on macOS X64 - Mac Sonoma (14) passed 💻

All tests on macOS X64 - Mac Sonoma (14) passed.

Pipeline on Agent
Hash: 7ae40bf77f815e5eb01c9c08b445c651f4e34ea8 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🔥 [CI Build] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

1 tests crashed, 0 tests failed, 111 tests passed.

Failures

❌ dotnettests tests (macOS)

🔥 Failed catastrophically on VSTS: test results - dotnettests_macos (no summary found).

Html Report (VSDrops) Download

Successes

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 8 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 9 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 8 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 7ae40bf77f815e5eb01c9c08b445c651f4e34ea8 [PR build]

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.

5 participants