-
Notifications
You must be signed in to change notification settings - Fork 67
Dart 3.0 class modifiers #476
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
Comments
I'll go for option 1. We could bump FFIgen to 8.0.0 so that we can still release legacy versions on 7.x. However, that would mean that users need to opt in by explicitly upgrading FFIgen. @leafpetersen is bumping the SDK constraint to 3.0 and adding class modifiers considered a breaking change? Should it we be major version bumping FFIgen? |
Bumping the SDK constraint should be fine - the new version will only get picked up by people on 3.0 sdks. Note though that code generators have some additional complexity:
As for whether adding cc @natebosch @devoncarew @jakemac53 who might have additional advice and opinions about how we want to manage the roll out of class modifiers in dart owned packages and code generators. |
I think it is sensible to only support generating the new language version, and asking folks who need backwards compatibility to stay on an older version of I think projects should see analysis errors if we are generating code with If the code wouldn't have supported subclasses in a meaningful way before and we can reasonably assume there are no (or very very few) examples in the wild of |
Packages have a dev dependency on FFIgen.
I'm also leaning in to this considering the above user flows.
It's not a breaking change, we already have custom error messages pre 3.0 that prevent
The packages using FFIgen, if they export the generated code in their public API, can indeed publish their package without a major version bump. Adding
We have considered this, but not done it (yet). Thanks for helping me think through this! 🚀 |
This current taken approach of an instant flip is untenable at least for google3. It means that we will have to flip the language version for everyone and import third_party ffigen atomically. Among who knows how many other things that will want to be atomic. This also means that any updates of third_party ffigen in google3 are blocked until the flip. Instead, generating different code based on the target language version would be very very nice. built_value already went for this approach and it's great |
Actually a very easy option would be to undo this change and instead just add This works (and I confirmed that it does) because ffi is part of the SDK and SDK pretends that class modifiers aren't there if used from files pinned to an older language version. |
I believe we do not run any ffigen as part of build steps yet. So currently it's a manual run by users to run ffigen. Or is FFIgen already integrated in build steps? @TzviPM
That only holds true if FFIgen is run automatically.
FFIgen currently does not try to parse the the parent project package_config/pubspec, but conceivably we could do so. (With a fallback that if you run it in a vaccuum and there is no pubspec it just assumes newest version of Dart.)
2.16 likely, as that's the lower bound currently on the last stable release. However, wouldn't this prevent users from having their whole project in 3.0 mode? I guess |
Also, looking for a pubspec to see if we're in 3.0 or not will likely not work in g3 where language versions are defined in a different way? This PR doesn't show how the language version of the surrounding project is obtained. Any suggestions on how to do that reliably? |
In g3 I see both kinds of usages - checked in and auto generated. So there is at least 1 place where this is integrated into the build, haven't checked how many places there are that use this.
Yes, in g3 we are not looking at pubspec. But somehow built_value figures out the language version anyway. I don't know how it is done - neither in g3, nor normally. Anyway I realized that for g3 we will have a way forward: I'll have to proceed with adding |
Ah but I think I have a pointer towards the answer. |
That still means
Which will most likely block @TzviPM's work. An alternative to detecting the language version from a pubspec is to declare the target language version in |
let's not guide the entire ecosystem based on my work in google3. That said, I imagine a configurable version would be good to maintain at least for a short period of time for others as well. I'm fine with making dart 3 the default, as long as we can opt out for some period of time. Opting out in the config is no issue for us, because we auto-generate that config in google3. I'll gather some additional context from @oprypin and update this issue. We don't currently support using ffigen automatically, but I am hoping to support that use case by EOM, so this might block my work depending on the timelines of dart 3, etc. |
Does ffigen import any user code in its generated files, or is it all fixed dependencies? If the latter, we could also consider adding |
Apologies, I must have made a mistake in my observations. ffigen is not used at build time anywhere in google3 (yet?), so indeed it's only checked-in files, which of course cannot affect a roll of third_party ffigen. So maybe we don't have a problem after all. These are many possible ways of going forward:
But in google3 I think we're not blocked either way. |
This is done as a patch in google3 now, so I believe we can close this. |
When code opts into Dart 3.0, we need to add class modifiers.
All subtypes of
Struct
,Union
,Opaque
, andAbiSpecificInteger
need to becomefinal class
instead of class.If the code is being generated for pre-3.0, we need to generate
class
, becausefinal class
is not accepted by the parser.This means we have two options:
dart:ffi
features anyway.)I'm not sure of option 2 is worth it though. For example
VarArgs
only exists in 3.0 and we will add that as well when Dart 3.0 is out.The text was updated successfully, but these errors were encountered: