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

Switch artichoke-backend to use spinoso-time tzrs feature #1956

Merged
merged 28 commits into from
Aug 21, 2022

Conversation

b-n
Copy link
Member

@b-n b-n commented Jul 16, 2022

#1927 Added enough to hopefully make tzrs feature safe for replacement of the chrono feature in arthicoke-backend. This PR achieves to do exactly that

Compatibility

The previous version of Time#at supported only the syntax that mruby did. This PR introduces all options available as at MRI 3.1.2.

Time#succ now uses the same logic as Time#+ which wasn't implemented before.

Time#+ is now implemented, and follows MRI

Time#- changes:

  • The previous version use to just return rhs when subtracting one time from another (this now returns a float as per MRI)
  • Arthimetic with intergers/floats now works

@b-n b-n added A-frontend Area: Frontends for interpreters, like the `ruby` or `irb` binaries. S-wip Status: This pull request is a work in progress. A-ruby-core Area: Ruby Core types. A-performance Area: Performance improvements and optimizations. B-Artichoke Backend: Implementation of artichoke-core using Rust-native backend. C-enhancement Category: New feature or request. and removed A-frontend Area: Frontends for interpreters, like the `ruby` or `irb` binaries. labels Jul 16, 2022
@b-n b-n force-pushed the b-n/time-use-tzrs branch 3 times, most recently from 10acbd4 to 2770c74 Compare July 16, 2022 09:44
@b-n b-n changed the title [WIP] Switch artichoke-backend to use spinoso-time tzrs feature Switch artichoke-backend to use spinoso-time tzrs feature Jul 16, 2022
@b-n b-n removed the S-wip Status: This pull request is a work in progress. label Jul 16, 2022
@b-n b-n requested a review from lopopolo July 16, 2022 19:38
@lopopolo lopopolo added B-mruby Backend: Implementation of artichoke-core using mruby. and removed B-Artichoke Backend: Implementation of artichoke-core using Rust-native backend. labels Jul 18, 2022
@lopopolo
Copy link
Member

Hi @b-n I've seen this but haven't had time to sit down and give a proper review yet. I took a glance and things look like they came together nicely. I hope to get to this sometime this week.

@lopopolo
Copy link
Member

Heads up, despite the crate being named artichoke-backend this change should be tagged B-mruby.

The B- tags refer to the VM implementation. B-Artichoke is a hypothetical pure Rust VM that we'll write in house.

artichoke-backend/src/extn/core/time/mruby.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/trampoline.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/trampoline.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/trampoline.rs Outdated Show resolved Hide resolved
artichoke-backend/src/extn/core/time/trampoline.rs Outdated Show resolved Hide resolved
@b-n
Copy link
Member Author

b-n commented Jul 30, 2022

@lopopolo I'll pick this one up again shortly, sorry for taking a while to get back around to it!

@b-n
Copy link
Member Author

b-n commented Aug 14, 2022

@lopopolo Converting this one back to draft since there's still some reasonably sized changes that I need to check. 3dd1b6b might be pique your interest 😅

@b-n
Copy link
Member Author

b-n commented Aug 14, 2022

Also, do you have a preference on tabled vs. non tabled tests? (below are the same tests)

Table tests:

    #[test]
    fn subsec_millis_tabled() {
        let mut interp = interpreter();

        let table: HashMap<&[u8], (i64, u32)> = HashMap::from([
            (b"-1001".as_slice(), (-2, 999_000_000)),
            (b"-1000".as_slice(), (-2, 0)),
            (b"-999".as_slice(), (-1, 1_000_000)),
            (b"-1".as_slice(), (-1, 999_000_000)),
            (b"0".as_slice(), (0, 0)),
            (b"999".as_slice(), (0, 999_000_000)),
            (b"1000".as_slice(), (1, 0)),
            (b"1001".as_slice(), (1, 1_000_000))
        ]);

        let unit = b":milliseconds";

        for (input, expectation) in table {
            let result = subsec(&mut interp, (Some(input), Some(unit))).unwrap();
            assert_eq!(
                result.to_tuple(),
                expectation,
                "Expected TryConvertMut<(Some({}), Some({})), Result<Subsec>>, to return {} secs, {} nanos",
                input.as_bstr(),
                unit.as_bstr(),
                expectation.0,
                expectation.1
            );
        }
    }

Not so tabled:

    #[test]
    fn subsec_millis() {
        let mut interp = interpreter();

        let result = subsec(&mut interp, (Some(b"-1001"), Some(b":milliseconds"))).unwrap();
        assert_eq!(result.to_tuple(), (-2, -999_000_000));

        let result = subsec(&mut interp, (Some(b"-1000"), Some(b":milliseconds"))).unwrap();
        assert_eq!(result.to_tuple(), (-2, 0));

        let result = subsec(&mut interp, (Some(b"-999"), Some(b":milliseconds"))).unwrap();
        assert_eq!(result.to_tuple(), (-1, 1_000_000));

        let result = subsec(&mut interp, (Some(b"-1"), Some(b":milliseconds"))).unwrap();
        assert_eq!(result.to_tuple(), (-1, 999_000_000));

        let result = subsec(&mut interp, (Some(b"0"), Some(b":milliseconds"))).unwrap();
        assert_eq!(result.to_tuple(), (0, 0));

        let result = subsec(&mut interp, (Some(b"999"), Some(b":milliseconds"))).unwrap();
        assert_eq!(result.to_tuple(), (0, 999_000_000));

        let result = subsec(&mut interp, (Some(b"1000"), Some(b":milliseconds"))).unwrap();
        assert_eq!(result.to_tuple(), (1, 0));

        let result = subsec(&mut interp, (Some(b"1001"), Some(b":milliseconds"))).unwrap();
        assert_eq!(result.to_tuple(), (1, 1_000_000));
    }

@b-n b-n added the S-wip Status: This pull request is a work in progress. label Aug 14, 2022
@lopopolo
Copy link
Member

Also, do you have a preference on tabled vs. non tabled tests? (below are the same tests)

I've been leaning toward table driven tests lately, especially for things like parsers, and have been liking how clean things look. I haven't been using HashMaps for this though, instead preferring an array of tuples, like:

#[test]
fn argument_error_display_from_invalid_subject() {
let test_cases: &[(&[u8], &str)] = &[
(b"\xFF", r#"invalid value for Integer(): "\xFF""#),
("🦀".as_bytes(), r#"invalid value for Integer(): "🦀""#),
// XXX: for UTF-8 strings, "\x00".inspect is "\u0000".
(b"\x00", r#"invalid value for Integer(): "\x00""#),
];
for (input, message) in test_cases.iter().copied() {
let err = ArgumentError::from(input);
let mut buf = String::new();
write!(&mut buf, "{}", err).unwrap();
assert_eq!(&*buf, message, "unexpected value for test case '{input:?}'");
}
}

b-n and others added 26 commits August 21, 2022 13:05
Ruby 3.x supports a lot more than what is expected form 2.7.x. This is
the base for the changes to support ruby 3.x changes at least
subsec could be a Fixnum or a Float. This logic is now handled in the
subsec module.
Co-authored-by: Ryan Lopopolo <rjl@hyperbo.la>
Co-authored-by: Ryan Lopopolo <rjl@hyperbo.la>
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.

All comments resolved and fixups filed as tickets.

Will merge this when the build is green.

@lopopolo lopopolo merged commit 5a133b5 into trunk Aug 21, 2022
@lopopolo lopopolo deleted the b-n/time-use-tzrs branch August 21, 2022 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-performance Area: Performance improvements and optimizations. 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.

2 participants