Skip to content

Commit

Permalink
Restore original values for CR flags
Browse files Browse the repository at this point in the history
These values are originally from CRuby, and now hardcoded as part
of the Prism parser, so they must continue to have the same values
or it will break codranges coming out of Prism.

This also makes the value check a hard check rather than an assert
since that will help ensure they do not accidentally get changed.
  • Loading branch information
headius committed Apr 1, 2024
1 parent d8f1d82 commit 44d10c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ObjectFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ public interface ObjectFlags {
int INCLUDED_INTO_REFINEMENT = registry.newFlag(RubyModule.class);
int TEMPORARY_NAME = registry.newFlag(RubyModule.class);

// order is important here; CR_7BIT_f needs to be 16 and CR_VALID_F needs to be 32 to match values in Prism parser
int FSTRING = registry.newFlag(RubyString.class);
int CR_7BIT_F = registry.newFlag(RubyString.class);
int CR_VALID_F = registry.newFlag(RubyString.class);
int FSTRING = registry.newFlag(RubyString.class);

int MATCH_BUSY = registry.newFlag(RubyMatchData.class);

Expand Down
11 changes: 6 additions & 5 deletions core/src/main/java/org/jruby/util/StringSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ public final class StringSupport {
public static final int CR_VALID_F = ObjectFlags.CR_VALID_F;
public static final int CR_UNKNOWN = 0;

// We hardcode these so they can be used in a switch below. The assert verifies they match FlagRegistry's value.
public static final int CR_7BIT = 8;
public static final int CR_VALID = 16;
// We hardcode these so they can be used in a switch.
// These values also must continue to match the same values in the Prism parser so we perform a hard check.
public static final int CR_7BIT = 16;
public static final int CR_VALID = 32;
static {
assert CR_7BIT == CR_7BIT_F : "CR_7BIT = " + CR_7BIT + " but should be " + CR_7BIT_F;
assert CR_VALID == CR_VALID_F : "CR_VALID = " + CR_VALID + " but should be " + CR_VALID_F;
if (CR_7BIT != CR_7BIT_F) throw new RuntimeException("BUG: CR_7BIT_F = " + CR_7BIT_F + " but should be " + CR_7BIT);
if (CR_VALID != CR_VALID_F) throw new RuntimeException("BUG: CR_VALID_F = " + CR_VALID_F + " but should be " + CR_VALID);
}

public static final int CR_BROKEN = CR_7BIT | CR_VALID;
Expand Down

0 comments on commit 44d10c6

Please sign in to comment.