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

[webkit] Add nullability to (generated and manual) bindings #15028

Merged
merged 16 commits into from
Jun 17, 2022

Conversation

tj-devel709
Copy link
Contributor

This PR aims to bring nullability changes to WebKit.
Following the steps here:

  1. I am adding nullable enable to all manual files that are not "API_SOURCES" in src/frameworks.sources and making the required nullability changes
  2. Changing all throw new ArgumentNullException ("object")); to ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (object)); for size saving optimization as well to mark that this framework contains nullability changes
  3. Changing any == null or != null to is null and is not null

@tj-devel709 tj-devel709 added the not-notes-worthy Ignore for release notes label May 13, 2022
@tj-devel709 tj-devel709 added this to the Future milestone May 13, 2022
@tj-devel709 tj-devel709 requested a review from chamons as a code owner May 13, 2022 17:39
@@ -24,23 +26,25 @@ internal class IndexedContainerEnumerator<T> : IEnumerator<T> {

public T Current {
get {
return _container [_index];
return _container! [_index];
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Highlighting this !. The return type cannot be made nullable since it is implementing an interface with that method signature but it is also a getter that is not an indexer so I thought this may be the best option

Copy link
Member

Choose a reason for hiding this comment

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

what about using:

if (_container is null) {
    return default (T);
} else {
    return _container [_index]
}

Copy link
Member

Choose a reason for hiding this comment

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

Might make more sense to throw an ObjectDisposedException.

Copy link
Member

Choose a reason for hiding this comment

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

@rolfbjarne good one, that exception should also be a good idea for my other comment.

return ++_index < _container.Count;
}

public void Reset () {
_index = -1;
}

IIndexedContainer<T> _container;
IIndexedContainer<T>? _container;
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed, if the only constructor takes a non-nullable container value and assigns it to this field?

Copy link
Contributor Author

@tj-devel709 tj-devel709 May 16, 2022

Choose a reason for hiding this comment

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

@rolfbjarne I added this, because the Dispose method assigns null to _container

Copy link
Member

Choose a reason for hiding this comment

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

@rolfbjarne we need a way to init that. The compiler is complaining because the default value of a IIndexedContainer is null. We could probably make the _container a private Init property with the type and remove the need of ? and remove all the Dipose code. Should make things nicer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rolfbjarne @mandel-macaque Should I do this?

Copy link
Member

Choose a reason for hiding this comment

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

@tj-devel709 yes, keep this since nulling it the field in the Dispose method might be important

@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.

@@ -24,23 +26,25 @@ internal class IndexedContainerEnumerator<T> : IEnumerator<T> {

public T Current {
get {
return _container [_index];
return _container! [_index];
}
Copy link
Member

Choose a reason for hiding this comment

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

what about using:

if (_container is null) {
    return default (T);
} else {
    return _container [_index]
}

Comment on lines 38 to 39
if (_container is null)
return false;
Copy link
Member

Choose a reason for hiding this comment

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

This is not correct. MoveNext can throw and throws and exception, please read https://docs.microsoft.com/en-us/dotnet/api/system.collections.ienumerator.movenext?view=net-6.0

Returning false has a meaning:

true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.

That means that you are telling the user of the API that everything was ok and that you reached the end, that is not the case. We should throw an InvalidOperationException.

Copy link
Member

Choose a reason for hiding this comment

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

_container can only be null if the object has been disposed, so an ObjectDisposedException sounds natural

return ++_index < _container.Count;
}

public void Reset () {
_index = -1;
}

IIndexedContainer<T> _container;
IIndexedContainer<T>? _container;
Copy link
Member

Choose a reason for hiding this comment

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

@rolfbjarne we need a way to init that. The compiler is complaining because the default value of a IIndexedContainer is null. We could probably make the _container a private Init property with the type and remove the need of ? and remove all the Dipose code. Should make things nicer.

@@ -24,23 +26,25 @@ internal class IndexedContainerEnumerator<T> : IEnumerator<T> {

public T Current {
get {
return _container [_index];
return _container! [_index];
}
Copy link
Member

Choose a reason for hiding this comment

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

Might make more sense to throw an ObjectDisposedException.

@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
Copy link
Collaborator

✅ API diff for current PR / commit

Legacy Xamarin (No breaking changes)
.NET (No breaking changes)

❗ API diff vs stable (Breaking changes)

Legacy Xamarin (No breaking changes)
.NET (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • iOS: vsdrops gist (No breaking changes)
  • tvOS: vsdrops gist (No breaking changes)
  • MacCatalyst: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • macOS: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • Microsoft.iOS vs Microsoft.MacCatalyst: vsdrops gist
Legacy Xamarin (stable) vs .NET

ℹ️ Generator diff

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

Pipeline on Agent
Hash: a4cb95361848bf57bb46e597e091c77bf93d1e16 [PR build]

@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
Copy link
Collaborator

🔥 Unable to find the contents for the comment: D:\a\1\s\change-detection\results\gh-comment.md does not exist :fire

Pipeline on Agent
Hash: 0bef34c6bec150b6509253f35168f005a58659fc [PR build]

@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
Copy link
Collaborator

✅ API diff for current PR / commit

Legacy Xamarin (No breaking changes)
  • iOS (no change detected)
  • tvOS (no change detected)
  • watchOS (no change detected)
  • macOS (no change detected)
NET (empty diffs)
  • iOS: (empty diff detected)
  • tvOS: (empty diff detected)
  • MacCatalyst: (empty diff detected)
  • macOS: (empty diff detected)

✅ API diff vs stable

Legacy Xamarin (No breaking changes)
.NET (No breaking changes)
Legacy Xamarin (stable) vs .NET

✅ Generator diff

Generator diff is empty

Pipeline on Agent
Hash: 9440e6c58cbc1269b2a0c41e177b40daf0a9ea8d [PR build]

@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
Copy link
Collaborator

💻 [PR Build] Tests on macOS Mac Catalina (10.15) passed 💻

All tests on macOS Mac Catalina (10.15) passed.

Pipeline on Agent
Hash: b0a178ec277fb507695cf8792878590abe48f744 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

📚 [PR Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent XAMBOT-1042.Monterey'
Hash: b0a178ec277fb507695cf8792878590abe48f744 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

Legacy Xamarin (No breaking changes)
  • iOS (no change detected)
  • tvOS (no change detected)
  • watchOS (no change detected)
  • macOS (no change detected)
NET (empty diffs)
  • iOS: (empty diff detected)
  • tvOS: (empty diff detected)
  • MacCatalyst: (empty diff detected)
  • macOS: (empty diff detected)

✅ API diff vs stable

Legacy Xamarin (No breaking changes)
.NET (No breaking changes)
Legacy Xamarin (stable) vs .NET

✅ Generator diff

Generator diff is empty

Pipeline on Agent
Hash: b0a178ec277fb507695cf8792878590abe48f744 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS M1 - Mac Big Sur (11.5) passed 💻

All tests on macOS M1 - Mac Big Sur (11.5) passed.

Pipeline on Agent
Hash: b0a178ec277fb507695cf8792878590abe48f744 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

❌ [CI Build] Tests failed on VSTS: simulator tests iOS ❌

Tests failed on VSTS: simulator tests iOS.

Test results

1 tests failed, 147 tests passed.

Failed tests

  • interdependent-binding-projects/watchOS 32-bits - simulator/Debug: Crashed

Pipeline on Agent XAMBOT-1044.Monterey'
Merge b0a178e into 3e6fdd8

@tj-devel709
Copy link
Contributor Author

Unrelated Test Failure: https://github.com/xamarin/maccore/issues/2558

@tj-devel709 tj-devel709 merged commit 893cd77 into xamarin:main Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not-notes-worthy Ignore for release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants