Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[pigeon] Fixes bug with mixmatch of nndb and nested types of objc.#2157

Merged
gaaclarke merged 8 commits intoflutter:mainfrom
gaaclarke:nested-crash-objc
Jun 7, 2022
Merged

[pigeon] Fixes bug with mixmatch of nndb and nested types of objc.#2157
gaaclarke merged 8 commits intoflutter:mainfrom
gaaclarke:nested-crash-objc

Conversation

@gaaclarke
Copy link
Member

@gaaclarke gaaclarke commented May 31, 2022

fixes flutter/flutter#104871

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@gaaclarke gaaclarke marked this pull request as ready for review May 31, 2022 21:33
@gaaclarke gaaclarke requested a review from stuartmorgan-g May 31, 2022 21:33
}
return '[$className fromMap:GetNullableObject($dict, @"${field.name}")]';
final String mapExpression = 'GetNullableObject($dict, @"${field.name}")';
return '($mapExpression ? [$className fromMap:$mapExpression] : nil)';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Duplicating evaluation of the whole expression in the common case seems needlessly inefficient. Why not just make fromMap:nil return nil, which is less generated code and more efficient at runtime than this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Changing the contract for functions like that when we don't have support from the compiler has been fraught in the past. I would be better off storing the variable. It requires shifting the dart code around though and generating unique symbols. I'll look into it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you elaborate on the concern here? It's a private method, so we control all calls to it. We call it in exactly two places AFAICT:

  • readValueOfType:, which explicitly returns a nullable value
  • Here, where returning nil is explicitly the behavior we want.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea, it's not so easy to reason about its usage when we are generating code. I've introduced bugs when changing these before. The function can be used in other contexts where it is expected to return a non-null value (ex a nonnull nested object). It's best to avoid it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. I added a nullable variant that can be used in this case (one sec I'll add an integration test too).

Copy link
Collaborator

Choose a reason for hiding this comment

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

The new method should be used to simplify line 925 as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

objc_generator.dart:925? That's the definition of the new method. You talking about somewhere else?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, I was on a phone and confused myself about the context while searching for the other location.

I'm still not clear on why we can't replace https://github.com/flutter/packages/blob/e6d5f869bf8d5c332e30231424c1493b380c5d4a/packages/pigeon/lib/objc_generator.dart#L265 with this (which is the only other use of toMap:). You said "The function can be used in other contexts where it is expected to return a non-null value", but that usage is a function that returns a (nullable id). I don't understand how an explicitly nullable function can be expected to return a non-null value; that means you are expecting a function to behave differently than its explicit documented behavior, which is a recipe for disaster. If there is code that is calling readValueOfType: but requires that it return a non-null value, then the calling code is wrong and we should fix it.

@gaaclarke gaaclarke force-pushed the nested-crash-objc branch from ab02c1f to 60774a7 Compare June 1, 2022 21:10
@gaaclarke gaaclarke requested a review from stuartmorgan-g June 1, 2022 21:12
@gaaclarke
Copy link
Member Author

Ah, looks like I broke some dart tests. One sec.

@gaaclarke gaaclarke force-pushed the nested-crash-objc branch from 60774a7 to f8ac5cf Compare June 1, 2022 21:27
@gaaclarke
Copy link
Member Author

Ah, looks like I broke some dart tests. One sec.

Should be good now.

Copy link
Collaborator

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM with comment nit.

I still don't think we should have the second method at all, vs just changing fromMap:, but we can revisit that later.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should have a comment saying that it's non-nullable to test non-nullable fields nested inside of nullable fields, so someone doesn't "fix" it later.

@gaaclarke gaaclarke force-pushed the nested-crash-objc branch 2 times, most recently from b3b07c9 to a64538a Compare June 7, 2022 00:30
@fluttergithubbot
Copy link

This pull request is not suitable for automatic merging in its current state.

@bitsydarel

This comment was marked as off-topic.

@flutter flutter deleted a comment from fluttergithubbot Jun 7, 2022
@gaaclarke gaaclarke force-pushed the nested-crash-objc branch from 2891733 to 3d515c7 Compare June 7, 2022 20:07
@gaaclarke gaaclarke merged commit 23e2d1a into flutter:main Jun 7, 2022
@gaaclarke
Copy link
Member Author

I'm not sure what happened with github. I merged before the fuchsia_ctl step finished since it takes forever and isn't related. Github however is listing the windows step as not passing, that wasn't the case, it passed here: https://ci.chromium.org/ui/p/flutter/builders/try/Windows%20custom_package_tests%20master%20-%20packages/987/overview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[pigeon] Nullable nested type causes crash in ObjC

4 participants