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

Mark defaultTargetPlatform as constant for non-debug non-web builds. #141105

Merged

Conversation

sstrickl
Copy link
Contributor

@sstrickl sstrickl commented Jan 8, 2024

This PR adds the Dart VM vm:platform-const-if pragma introduced in dart-lang/sdk@57a1168875 to the defaultTargetPlatform property, allowing it to be computed as if it was a constant field in non-debug AOT builds. In particular, this means that platform-specific code executed conditionally based on this property can be tree-shaken in release builds. Note that this PR changes defaultTargetPlatform to only allow overriding via debugDefaultTargetPlatformOverride in debug builds, and makes it so that compilation throws an error if code assigns todebugDefaultTargetPlatformOverride in other build modes.

Related issue: #14233

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 Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • 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.

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Jan 8, 2024
@sstrickl sstrickl force-pushed the platform-const-default-target-platform branch from 9d936af to b65cb3d Compare January 12, 2024 10:33
@sstrickl sstrickl marked this pull request as ready for review January 16, 2024 12:41
@sstrickl
Copy link
Contributor Author

Note that I haven't marked

I added new tests to check the change I am making, or this PR is test-exempt.

above, as I'm not sure what, if any, test would be useful for this.

@sstrickl sstrickl force-pushed the platform-const-default-target-platform branch from a831652 to d4d244b Compare January 18, 2024 09:07
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@Hixie
Copy link
Contributor

Hixie commented Jan 18, 2024

Is vm:platform-const-if documented anywhere?

@Hixie
Copy link
Contributor

Hixie commented Jan 18, 2024

test-exempt: optimization

@mkustermann
Copy link
Member

Is vm:platform-const-if documented anywhere?

All VM related pragmas are documented at runtime/docs/pragmas.md

@Hixie
Copy link
Contributor

Hixie commented Jan 18, 2024

@matanlurey points out (correctly) that it'd be nice to test that in production mode we do throw for setting the debug flag here. do we have a harness for testing things in production mode? if we don't i think this probably doesn't justify the cost of adding one, but if we do, it'd be nice to add this to it.

@sstrickl sstrickl force-pushed the platform-const-default-target-platform branch from 3055ed6 to 4e1c862 Compare January 19, 2024 10:17
@sstrickl
Copy link
Contributor Author

@matanlurey points out (correctly) that it'd be nice to test that in production mode we do throw for setting the debug flag here. do we have a harness for testing things in production mode? if we don't i think this probably doesn't justify the cost of adding one, but if we do, it'd be nice to add this to it.

I'll take a look around and see if I find one, and if I do then add it before merging.

@sstrickl
Copy link
Contributor Author

I didn't find a harness for testing non-debug-only code when I looked around, and from Discord it seems like no one else knows of one either to point me at, so I'm going to ship this as is.

@sstrickl sstrickl merged commit 7ca4b7b into flutter:master Jan 22, 2024
59 of 60 checks passed
@sstrickl sstrickl deleted the platform-const-default-target-platform branch January 22, 2024 13:49
@eliasyishak
Copy link
Contributor

Hi @sstrickl, just an fyi that this PR is causing post submit errors

I'll be investigating some more to see if your PR is causing any issues related to the observed error

auto-submit bot pushed a commit to flutter/packages that referenced this pull request Jan 22, 2024
flutter/flutter@5dea6b9...3ee8ff2

2024-01-22 engine-flutter-autoroll@skia.org Roll Flutter Engine from 40c5e9ce6596 to c49989292fc1 (1 revision) (flutter/flutter#141966)
2024-01-22 engine-flutter-autoroll@skia.org Roll Packages from 129e08c to e4cbf23 (11 revisions) (flutter/flutter#141962)
2024-01-22 sstrickl@google.com Mark defaultTargetPlatform as constant for non-debug non-web builds. (flutter/flutter#141105)
2024-01-22 tessertaha@gmail.com Fix `shape` and `collapsedShape` isn't applied to `ExpansionTile`'s splash ink (flutter/flutter#141777)
2024-01-22 dacoharkes@google.com Reapply "Native assets: roll deps" (#141748) (flutter/flutter#141864)
2024-01-22 engine-flutter-autoroll@skia.org Roll Flutter Engine from 11c585f48b77 to 40c5e9ce6596 (1 revision) (flutter/flutter#141956)
2024-01-22 tessertaha@gmail.com Update `ToggleButtons`, `ExpansionPanel`, and `ExpandIcon` tests for Material 3 (flutter/flutter#141868)
2024-01-22 engine-flutter-autoroll@skia.org Roll Flutter Engine from c485c574fb1d to 11c585f48b77 (1 revision) (flutter/flutter#141952)
2024-01-22 engine-flutter-autoroll@skia.org Roll Flutter Engine from a7b207d5a1fe to c485c574fb1d (1 revision) (flutter/flutter#141951)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC bmparr@google.com,rmistry@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@XilaiZhang XilaiZhang added the cp: beta cherry pick this pull request to beta release candidate branch label Jan 22, 2024
@mkustermann
Copy link
Member

Hi @sstrickl, just an fyi that this PR is causing post submit errors

I'll be investigating some more to see if your PR is causing any issues related to the observed error

@eliasyishak To follow up here, were there any issues we need to be aware of?

@sstrickl
Copy link
Contributor Author

sstrickl commented Feb 5, 2024

Elias reached out to me over chat and it turned out to be a flake after further investigation, hence why no revert happened.

arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
flutter/flutter@5dea6b9...3ee8ff2

2024-01-22 engine-flutter-autoroll@skia.org Roll Flutter Engine from 40c5e9ce6596 to c49989292fc1 (1 revision) (flutter/flutter#141966)
2024-01-22 engine-flutter-autoroll@skia.org Roll Packages from 129e08c to e4cbf23 (11 revisions) (flutter/flutter#141962)
2024-01-22 sstrickl@google.com Mark defaultTargetPlatform as constant for non-debug non-web builds. (flutter/flutter#141105)
2024-01-22 tessertaha@gmail.com Fix `shape` and `collapsedShape` isn't applied to `ExpansionTile`'s splash ink (flutter/flutter#141777)
2024-01-22 dacoharkes@google.com Reapply "Native assets: roll deps" (#141748) (flutter/flutter#141864)
2024-01-22 engine-flutter-autoroll@skia.org Roll Flutter Engine from 11c585f48b77 to 40c5e9ce6596 (1 revision) (flutter/flutter#141956)
2024-01-22 tessertaha@gmail.com Update `ToggleButtons`, `ExpansionPanel`, and `ExpandIcon` tests for Material 3 (flutter/flutter#141868)
2024-01-22 engine-flutter-autoroll@skia.org Roll Flutter Engine from c485c574fb1d to 11c585f48b77 (1 revision) (flutter/flutter#141952)
2024-01-22 engine-flutter-autoroll@skia.org Roll Flutter Engine from a7b207d5a1fe to c485c574fb1d (1 revision) (flutter/flutter#141951)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC bmparr@google.com,rmistry@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cp: beta cherry pick this pull request to beta release candidate branch framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants