You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One common complaint I see about the keyword-generics-innitiative is that the syntax can be quite verbose. The core idea I have is to essentially treat all unmarked keyword functions as maybe keyword. A solution I've been exploring in my head looks something like this:
/// Not awaiting or otherwise using the future for this function/// would result in a warningasyncfnfoo_async(){}/// Can optionally be called in any context and can optionally be awaited/// Notice that all regular functions would fall into this category/// Hopefully no need for additional syntax here?fnfoo_maybe_async(){// Perhaps #[cfg(async)] makes more sense than `if ?async`if ?async{// Do some async stuff}else{// Do some sync stuff}}
Awaiting a function which doesn't contain an `?async' block/section would result in a warning. Conversely, not awaiting a function which does contain an async block/section while inside an async context would also emit a warning. I imagine this style of implementation should be fully backwards compatible.
Perhaps there's something I'm missing here, but declaring a function signature like
?asyncfnmaybe_async_foo(){}
or
#[maybe(async)]fnmaybe_async_bar(){}
seems superfluous.
Currently, the compiler can tell if a const fn is valid. So it would seem to me that it should also be able to validate if calling unmarked (maybe const) functions from within a const function is valid. I'll give an example:
This example would compile because the compiler could check that bar_maybe_const has a valid const implementation
/// Notice we are marking explicitly as constconstfnfoo_const() -> usize{bar_maybe_const()}/// Notice we are leaving unmarked (maybe const)fnbar_maybe_const() -> usize{if ?const{return1}else{do_something_at_runtime()}}
This example would error because the compiler could check that bar_maybe_const has no valid const implementation
/// Notice we are marking explicitly as constconstfnfoo_const() -> usize{bar_maybe_const()}/// Notice we are leaving unmarked (maybe const)fnbar_maybe_const() -> usize{// we don't provide a valid const implementationdo_something_at_runtime() <-- Error:fn do_something_at_runtime is not const
}
This is just something that's been spinning in my head for a while and there's a good chance I'm not seeing the whole picture here. But I'd love to get your thoughts/opinions on this.
The text was updated successfully, but these errors were encountered:
My first impression is that this is an API nightmare, since defaulting to maybe means now everything that doesn't want to be maybe has to be explicitly marked.
Like, you've just moved the verbosity somewhere else, and effectively required it to be used more often.
Oh, that makes more sense, although this would be unprecedented in the language, at least for regular functions, since the reason why they require annotations is purely for API documentation purposes and not because they can't infer them.
I can definitely see the argument of doing this for closures, though. Although I'm not exactly sure how useful maybe-async closures are in general.
One common complaint I see about the
keyword-generics-innitiative
is that the syntax can be quite verbose. The core idea I have is to essentially treat all unmarked keyword functions asmaybe keyword
. A solution I've been exploring in my head looks something like this:Awaiting a function which doesn't contain an `?async' block/section would result in a warning. Conversely, not awaiting a function which does contain an async block/section while inside an async context would also emit a warning. I imagine this style of implementation should be fully backwards compatible.
Perhaps there's something I'm missing here, but declaring a function signature like
or
seems superfluous.
Currently, the compiler can tell if a
const
fn is valid. So it would seem to me that it should also be able to validate if calling unmarked (maybe const) functions from within a const function is valid. I'll give an example:This example would compile because the compiler could check that
bar_maybe_const
has a valid const implementationThis example would error because the compiler could check that
bar_maybe_const
has no valid const implementationThis is just something that's been spinning in my head for a while and there's a good chance I'm not seeing the whole picture here. But I'd love to get your thoughts/opinions on this.
The text was updated successfully, but these errors were encountered: