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

Add support for Time.utc and Time.local #2410

Merged
merged 7 commits into from
Feb 5, 2023
Merged

Add support for Time.utc and Time.local #2410

merged 7 commits into from
Feb 5, 2023

Conversation

b-n
Copy link
Member

@b-n b-n commented Feb 4, 2023

This makes progress towards #2223, however it does not yet close it. Breaking this work down to more atomic changes.

Notes:

  • The new exclusions on the spec runner is due to needing to add even more support in parsing time Args. I believe MRI 3.x added support for the text values "jan|feb|..." etc
  • changes to the math class is due to TryConvertMut supporting two targets from &[Value] so the compiler now needs hinting
  • I've left the 10 arg impl empty for now as a step towards Time.utc. This should be easily addable later, but happy to do it here too.

Some design thoughts:

  • I think the checking of the individual arguments should be handled within the TryConvertMut block, instead of in the accessor functions. I originally did it this way because I naively thought I could to_int all the things, but apparently not (month param + sec taking fractional params)
  • If I did the above, I could make it just return a big tuple of the values (although this might be harder since Time.new supports a zone parameter from the looks of it)
  • I have tried to leave the coercion of the args into Value::value in the mruby.rs file - since this feels more consistent with other implementations. That way, I can always say that trampoiline expects a RubyValue. However this limits the implementation a bit - e.g. right now we're doing some args length checking after coercion to RubyValues, where as I believe those checks should be done much earlier. Specificallly, I think it would be nicer if the new time Args was being generated directly from mruby.rs and being passed through. I'll comment in the code where I think this is applicable.

Misc note:

  • Parts of this PR were commited/created in New Zealand. So Artichoke has now added and additional timezone of contribution 😅)

@b-n b-n self-assigned this Feb 4, 2023
@b-n b-n added C-enhancement Category: New feature or request. A-ruby-core Area: Ruby Core types. B-mruby Backend: Implementation of artichoke-core using mruby. labels Feb 4, 2023
These specs rely on Time.utc and Time.local. Previously, they were
marked as NotImplemented, and thus the tests would continue to "pass"
(it was more a false positive).

inspect/to_s - Now requrie a Time.new method which isn't supported
dst?/isdst - some issues to resolve
getgm/getlocal - Requires parsing months as strings etc
Copy link
Member

@lopopolo lopopolo left a comment

Choose a reason for hiding this comment

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

This looks pretty awesome. I left some comments as I went through commit by commit.

I'll take another pass at the PR as a whole.

assert_eq!(
err.message().as_bstr(),
b"wrong number of arguments (given 0, expected 1..8)"
.as_slice()
Copy link
Member

Choose a reason for hiding this comment

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

bstr 1.2 has impls for [u8; N] so this as_slice isn't necessary anymore!

artichoke-backend/src/extn/core/time/args.rs Outdated Show resolved Hide resolved
artichoke-backend/src/extn/core/time/args.rs Outdated Show resolved Hide resolved
artichoke-backend/src/extn/core/time/args.rs Outdated Show resolved Hide resolved
artichoke-backend/src/extn/core/time/args.rs Outdated Show resolved Hide resolved
artichoke-backend/src/extn/core/time/trampoline.rs Outdated Show resolved Hide resolved
artichoke-backend/src/extn/core/time/args.rs Outdated Show resolved Hide resolved
artichoke-backend/src/extn/core/time/args.rs Outdated Show resolved Hide resolved
}
Ok(result)
10 => todo!(),
_ => unreachable!(),
Copy link
Member

Choose a reason for hiding this comment

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

is rustc not smart enough to see that this match is exhaustive. 😢 if that's the case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hah indeed. It's maybe just one level of abstraction too far for it to know that args.len() and the index on the iterator are the same thing I guess 🤷

artichoke-backend/src/extn/core/time/mruby.rs Outdated Show resolved Hide resolved
Copy link
Member

@lopopolo lopopolo left a comment

Choose a reason for hiding this comment

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

I have no concerns with the approach you've taken @b-n. It looks readable and well structured. The Args type keeps all the parsing local and easy to reason about, especially for these TODOs you've called out about supporting some of the polymorphic parameters.

Most of my comments are nits, not to do with the logic itself.

@b-n b-n requested a review from lopopolo February 5, 2023 09:57
Copy link
Member

@lopopolo lopopolo left a comment

Choose a reason for hiding this comment

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

Looks great.

@b-n b-n merged commit 63ce0ff into trunk Feb 5, 2023
@b-n b-n deleted the b-n/time-args branch February 5, 2023 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ruby-core Area: Ruby Core types. B-mruby Backend: Implementation of artichoke-core using mruby. C-enhancement Category: New feature or request.
Development

Successfully merging this pull request may close these issues.

None yet

2 participants