-
Notifications
You must be signed in to change notification settings - Fork 182
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
Example of baked data crate with macros #2992
Conversation
It works across crate boundaries if I change the super-absolute imports like |
@@ -77,6 +78,7 @@ lto = true | |||
[profile.release-opt-size] | |||
inherits = "release" | |||
opt-level = "s" | |||
debug = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(reminder to remove this line)
type DataStruct = | ||
<icu_provider::hello_world::HelloWorldV1Marker as icu_provider::DataMarker>::Yokeable; | ||
static KEYS: &[&str] = &["bn", "en", "en-US", "ja", "ru"]; | ||
static BN: DataStruct = $crate::baked::core_helloworld_v1::data_core_helloworld_v1_bn!(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, but it will be hard to generate because you're using the absolute path of where this will be included, e.g. it has to be included at $crate::baked
. If we can't find a way to use relative addressing for the data file (either using mod
or include
), we should inline the data to step around this problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path is relative to the globaldata
crate, which is under our control. We may need to tell databake-datagen what that path is, but this is totally an internal thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be useful if the logic we add here is also usable by datagen clients, not only for this crate.
include!("ru.data.rs"); | ||
|
||
#[macro_export] | ||
macro_rules! impl_core_helloworld_v1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the plan for AnyProvider
? Having one macro per key doesn't work, the keys should be arguments (plural) to the macro.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should "just work"
struct LocalBakedProvider;
impl_core_helloworld_v1!(LocalBakedProvider);
impl_decimal_symbols_v1!(LocalBakedProvider);
impl_any_provider!(LocalBakedProvider, [
icu_provider::hello_world::HelloWorldV1Marker,
icu_decimal::provider::SymbolsV1Marker,
]);
@@ -0,0 +1,10 @@ | |||
#[macro_export] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrapping each data expression in a macro is a lot of cognitive overhead, and probably also compile time overhead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cognitive overhead is being moved from the call site (people need to learn how data providers work) to an internal crate (that only us and power users will see).
pub fn try_new(locale: &DataLocale) -> Result<Self, DataError> { | ||
struct LocalBakedProvider; | ||
use crate as icu_provider; | ||
globaldata::impl_core_helloworld_v1!(LocalBakedProvider); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An open question is how to enable vertical fallback. An easy way, which is probably fine, is
let provider = globaldata::with_vertical_fallback!(LocalBakedProvider);
and the macro has two versions: one that is a no-op, and one that is enabled with the globaldata/fallback
feature that actually enables the fallback
See #2945