Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

tonycoz
Copy link
Contributor

@tonycoz tonycoz commented Oct 28, 2019

No description provided.

@atoomic
Copy link
Member

atoomic commented Oct 28, 2019

this excellent!
maybe once merged we could consider using back the original syntax
s{FEATURE_IS_ENABLED_MASK}{FEATURE_IS_ENABLED}g ?

* Check whether the named feature is enabled.
*/
bool
Perl_feature_is_enabled(pTHX_ const char *const name, STRLEN namelen)
Copy link
Member

@atoomic atoomic Oct 28, 2019

Choose a reason for hiding this comment

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

note that we will also have to remove or adjust feature_is_enabled from Devel::PPPort

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably remove, feature_is_enabled was only used by FEATURE_IS_ENABLED(), which is only intended for use by core or included extensions (PERL_EXT).

@@ -76,6 +76,17 @@ BEGIN
###########################################################################
# More data generated from the above

if (keys %feature > 32) {
die "cop_features only has room for 32 features";
Copy link
Contributor

Choose a reason for hiding this comment

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

What would be the thing to do if we run out of bits? Can we easily turn the field into a U64, or would we make a second one?

Copy link
Contributor

@Leont Leont Oct 28, 2019

Choose a reason for hiding this comment

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

If U64 can be used, it may make sense to reuse cop_hints (it's a U32, but 28 of its bits are currently in use)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplest for working with feature.pm/${^FEATURE_BITS} would probably be a U8 array, but that's difficult to write a SAVEFEATUREBITS() for.

We could make it a pointer as for warnings, but since the feature bits are fixed size and will be present in any cop, the pointer is just overhead.

But for now we have over twice the feature bits as features, so I don't feel much urgency to decide right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If U64 can be used, it may make sense to reuse cop_hints (it's a U32, but 28 of its bits are currently in use)

If we worked through $^H we'd need to require -Duse64bitint to safely update it from feature.pm

Copy link
Contributor

@leonerd leonerd left a comment

Choose a reason for hiding this comment

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

LGTM

@Leont
Copy link
Contributor

Leont commented Oct 28, 2019

${^FEATURE_BITS} should probably be documented in perlvar

Perform only a bit check instead of a much more expensive hash
lookup to test features.

For now I've just added a U32 to the cop structure to store the bits,
if we need more we could either add more bits directly, or make it a
pointer.

We don't have the immediate need for a pointer that warning do since
we don't dynamically add new features during compilation/runtime.

The changes to %^H are retained so that caller() can be used from perl
code to check the features enabled at a given caller's scope.
@haarg
Copy link
Contributor

haarg commented Oct 29, 2019

This currently leaves no way for a user to manually construct a ${^FEATURE_BITS} value. While the bits themselves are internal values, it would still be nice to be able to construct a value based on feature names.

@leonerd
Copy link
Contributor

leonerd commented Oct 29, 2019

@haarg Perhaps this could be solved by feature.pm adding a function?

$bits = feature::make_bitmask(qw( say evalbytes ));

@haarg
Copy link
Contributor

haarg commented Oct 29, 2019

That would make sense to me.

@tonycoz
Copy link
Contributor Author

tonycoz commented Oct 30, 2019

This currently leaves no way for a user to manually construct a ${^FEATURE_BITS} value. While the bits themselves are internal values, it would still be nice to be able to construct a value based on feature names.

Why do they need it?

If they want to enable features they can use feature->(un)import() in the current compilation.

It also risks the feature bits and %^H feature entries getting out of sync.

I'd rather remove ${^FEATURE_BITS} rather than even vaguely suggest it's something users should be touching.

That said, there is a way to get the bits for a given feature set: call feature->import() at runtime with the features you want, and extract the bits.

@leonerd leonerd mentioned this pull request Oct 30, 2019
1 task
@leonerd
Copy link
Contributor

leonerd commented Oct 30, 2019

It remains to be seen whether such a feature would be needed, but it can be added in a small addition to feature.pm later if required. Its absence now shouldn't hold back this particular change, which basically just improves performance to no real detriment in API. I believe it should be merged.

@tonycoz tonycoz merged commit df31f96 into Perl:blead Oct 30, 2019
@tonycoz
Copy link
Contributor Author

tonycoz commented Oct 30, 2019

I've merged this, I may end up removing ${^FEATURE_BITS} (but keeping the optimization)

@Leont
Copy link
Contributor

Leont commented Oct 30, 2019

unicode_strings is now living in both the hints and the features bitsets, this doesn't seem necessary.

@tonycoz
Copy link
Contributor Author

tonycoz commented Nov 3, 2019

unicode_strings is now living in both the hints and the features bitsets, this doesn't seem necessary.

I had a look at this, I don't think it's worth reinstating FEATURE_IS_ENABLED() / Perl_feature_is_enabled() to save this bit. Opinions welcome.

@Leont
Copy link
Contributor

Leont commented Nov 4, 2019

It's not saving a bit that I'm worried about, but more things like "what happens if they're out of sync?". Also, feature.pm now contains special case code for unicode_strings that could be eliminated if that feature no longer uses the hints bitset.

@tonycoz tonycoz deleted the faster-feature branch November 4, 2019 21:40
@tonycoz
Copy link
Contributor Author

tonycoz commented Nov 4, 2019

The out of sync could happen between $^H{feature_unicode} and the bit in PL_hints before this.

Losing sync between $^H{feature_*} and ${^FEATURE_BITS} seems more likely if the user modifies either of those outside of feature.pm, but I see that as a "Doctor, it hurts when I do this" type of issue.

I've considered eliminating the visibility of ${^FEATURE_BITS} and adjusting the magic in Perl_magic_(set|clear)hints() to update cop_features instead, but the perl code is easier to maintain.

@cpansprout
Copy link

There are modules that copy the values of $^H, %^H, and ${^WARNING_BITS} from one lexical scope to another. So for %^H to get out of synch with ${^FEATURE_BITS} is not unlikely to happen.

I think having yet another lexical hints variable is something that should be avoided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants