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
Type::Tiny::Enum - change ::XS encoding to quote strings #59
Conversation
This along with a corresponding change over in the p5-type-tiny-xs repo is one proposed fix to the Enum encoding issues. Also could fix 133141 by just adding another character to the "can't xsify" regex (along with the existing hyphen) or put something together where the interface between Type::Tiny and Type::Tiny::XS isn't via strings |
Codecov Report
@@ Coverage Diff @@
## master #59 +/- ##
==========================================
- Coverage 88.80% 88.57% -0.24%
==========================================
Files 36 36
Lines 3583 3597 +14
Branches 984 991 +7
==========================================
+ Hits 3182 3186 +4
- Misses 62 64 +2
- Partials 339 347 +8
Continue to review full report at Codecov.
|
I admire your commitment to sticking with the established API, but feel like at this point it might be easier to just do: my $xsub = Type::Tiny::XS::_parameterize_Enum_for( $opts{unique_values} ); Yes, |
Hmmm, I’m pretty sure that would allow a Type::Tiny only change. I can take a stab at that.
…Sent from my iPhone
On Aug 12, 2020, at 3:34 AM, Toby Inkster ***@***.***> wrote:
I admire your commitment to sticking with the established API, but feel like at this point it might be easier to just do:
my $xsub = Type::Tiny::XS::_parameterize_Enum_for( $opts{unique_values} );
Yes, _parameterize_Enum_for isn't part of Type::Tiny::XS's officially supported API, but meh, Type::Tiny and Type::Tiny::XS can be friends with benefits.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Yea, that's a pretty involved change too that might trigger changing the interface to Type::Tiny::XS entirely. For Tuple[Enum[...]] to inline, we need to register the callback with Type::Tiny::XS (so that Type::Tiny::XS::is_known works) and it still needs to return something parse-able by Type::Parser (so we'll still want the B::perlstring encoding). The first part specifically means we'd probably also have to drag the AUTO::TC%d named subname logic into Type::Tiny::Enum for the inline_check to work out AND also attempt to register the sub to Type::Tiny::XS::_know. This is all assuming the intent here is not require changes in both Type::Tiny and Type::Tiny::XS for this. Another option I could pursue is not renaming the encoding to EnumQ[], leaving it Enum[] (now with perlstring encoding) and then add some lame check for " in the contents to understand if Type::Tiny::XS is being called from a old Type::Tiny or new Type::Tiny. I'm pretty sure that would work out, but might unintentionally break someone using " in a string in an old Type::Tiny Enum (although that would have exploded on that person if they then tried to wrap that Enum in a Tuple[] and triggered the Type::Parser error). |
Hmm, if Type::Tiny::XS encounters Meanwhile Type::Tiny::Enum can do a version check on Type::Tiny::XS and pass the strings quoted if it's version 0.020+. If it's older Type::Tiny::XS, bail out from using XS if the strings don't all match |
That sounds reasonable to me and pretty sure it'll work. I'll update the pull request in a bit. |
52d88cd
to
4fb6c20
Compare
Here we go (along with the Type::Tiny::XS pull request which I've updated too). Pretty much what you suggested, version-check Type::Tiny::XS, if we can use the new encoding, otherwise use the old one (but avoid it for these broken space-including strings). This makes the assumption that the version of ::XS that includes the fix will be 0.020. |
475d5d6
to
aa0d2d4
Compare
If we have something like Enum[qw(a b)] we would communicate with Type::Tiny::XS via a string like: 'Enum[a, b]' We've already been hitting issues with this (see perl rt #129729) on hyphens but now also hitting it on spaces (see perl rt #133141). This commit changes the encoding for enums for Type::Tiny::XS to: 'Enum["a", "b"]' Since we use B::perlstring() to encode this, we should also handle any arbitrary string. When we're on an old Type::Tiny::XS though, we'll continue to use the old encoding, we'll just avoid stringification for even more things.
aa0d2d4
to
9072674
Compare
This appears to be passing all tests now (with old Type::Tiny::XS and new Type::Tiny::XS [manually patched to 0.020 since the version check in here for the new API is 0.020+]). Was able to distinkt-dist it as well. |
Built a local Type-Tiny-1.010004 and Type-Tiny-XS-v0.020 and have confirmed that this gets at least the first half of our internal testsuite at ziprecruiter through the Type::Tiny upgrade. 🎉 |
Released Type::Tiny::XS 0.020. Going to wait a day or so for CPAN testers to do their stuff with that before releasing a new Type::Tiny, though I don't anticipate any problems with it. |
… version 1.010004 1.010004 2020-08-18 [ Bug Fixes ] - Fix XSifying Enum[] where the strings contain certain non-word characters. Andrew Ruder++ <tobyink/p5-type-tiny-xs#12> <tobyink/p5-type-tiny#59> - Type::Params compile_named using both the head and named_to_list options would cause compilation error. Fixes RT#132419. Hauke D++ Sandor Patocs++ <https://rt.cpan.org/Ticket/Display.html?id=132419> - Workaround RT#121957 by avoiding attempting to XSify Enum type (NEWS truncated at 15 lines)
1.010006 2020-09-04 [ Bug Fixes ] - Eliminate recusion warnings when Type::Parser needs to parse complex types. Fixes RT#121957. Diab Jerius++ <https://rt.cpan.org/Ticket/Display.html?id=121957> [ Other ] - Better handling of coercions for pre-declared types in Type::Library. The type objects created before the type was properly defined will now lazily attempt to find coercions from the properly defined type once it becomes available. 1.010005 2020-08-26 - Improvements to $AvoidCallbacks support for Type::Tiny::{Class,Role,Duck,Enum,Union,Intersection}, and LaxNum, Ref, RegexpRef, FileHandle, Object, Overload, and Tied types from Types::Standard. 1.010004 2020-08-18 [ Bug Fixes ] - Fix XSifying Enum[] where the strings contain certain non-word characters. Andrew Ruder++ <tobyink/p5-type-tiny-xs#12> <tobyink/p5-type-tiny#59> - Type::Params compile_named using both the head and named_to_list options would cause compilation error. Fixes RT#132419. Hauke D++ Sandor Patocs++ <https://rt.cpan.org/Ticket/Display.html?id=132419> - Workaround RT#121957 by avoiding attempting to XSify Enum type constraints with more than 50 possible strings. Fixes RT#121957. Diab Jerius++ <https://rt.cpan.org/Ticket/Display.html?id=121957> [ Documentation ] - Link to HTTPS version of Type::Tiny web page. 1.010003 2020-08-08 The Crazy 88 [ Bug Fixes ] - ClassName type constraint should treat empty @isa as if no @isa were defined, like Type::Tiny::XS. Fixes RT#132583. Szymon Nieznański++ <https://rt.cpan.org/Ticket/Display.html?id=132583> - Fix for Type::Tiny->can called as a class method. Meredith Howard++ <tobyink/p5-type-tiny#57> - Fix predeclared types in Type::Library. Meredith Howard++ <tobyink/p5-type-tiny#58> [ Documentation ] - Document some edge cases for Types::Standard Int. <https://rt.cpan.org/Ticket/Display.html?id=132754>
If we have something like Enum[qw(a b)] we would communicate with
Type::Tiny::XS via a string like:
'Enum[a, b]'
We've already been hitting issues with this (see perl rt #129729) on hyphens
but now also hitting it on spaces (see perl rt #133141). This commit
changes the encoding for enums for Type::Tiny::XS to:
'EnumQ["a", "b"]'
Since we use B::perlstring() to encode this, we should also handle any
arbitrary string.
Why change Enum -> EnumQ? We've introduced a weird API change,
Type::Tiny::XS < 0.20 won't know how to parse an Enum[] with quoted
strings, but if we pass it an EnumQ[] it'll just silently move past
it (and not be able to optimize it). Then we can release a
Type::Tiny::XS that supports EnumQ and get all the SPEED back.