Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a8c5b84
Add a Set differential matrix and per-operation Set shapes
claude Nov 23, 2026
e8de537
Fill a core Set's table directly in Set.new, merge and the set operators
claude Nov 23, 2026
aaa9f83
Compile the blocks of eval'd text only after 1000 runs
claude Nov 23, 2026
c9c171d
Provide erb/escape: ERB::Escape.html_escape in C#
claude Nov 23, 2026
22468d6
Bind calls on per-object singleton classes without a rule each
claude Nov 23, 2026
9e29c85
Give light-scope call sites precompiled dispatchers for Ruby methods
claude Nov 23, 2026
8903a91
Merge perf/setx (round thirty-three)
claude Nov 23, 2026
e08dc55
Merge perf/erbr (round thirty-three)
claude Nov 23, 2026
ce1ac3a
Merge perf/ostr (round thirty-three)
claude Nov 23, 2026
4e349c7
Merge perf/pwalk (round thirty-three)
claude Nov 23, 2026
5f9f11e
Box an attribute writer's typed argument with the shared boxes
claude Nov 23, 2026
aae3098
Record round thirty-three in the ledger
claude Nov 23, 2026
592c75a
Convert html_escape's argument as rb_check_funcall does; box a writer…
claude Nov 23, 2026
66e5dec
Keep the prism trees of evaluated strings (EvalAstCache)
claude Nov 23, 2026
ec0f1c9
Parse ASCII-only Date._strptime in C#
claude Nov 23, 2026
39fd30b
Let a shared rule's test take in a new class version that resolves th…
claude Nov 23, 2026
7a2d25f
Make Data.new, Data#with, Data readers and Array#sum's plain fold che…
claude Nov 23, 2026
1587bcd
Merge perf/time2 (round thirty-four)
claude Nov 23, 2026
ef88aec
Merge perf/inv2 (round thirty-four)
claude Nov 23, 2026
acc9f9f
Merge perf/erb2 (round thirty-four)
claude Nov 23, 2026
77f841b
Merge perf/ostr2 (round thirty-four)
claude Nov 23, 2026
7289271
Let an attribute reader read a hidden instance variable in Debug builds
claude Nov 23, 2026
08d5cd5
Record round thirty-four in the ledger
claude Nov 24, 2026
8968cff
Add an Integer and a Rational exactly in Array#sum, as MRI does
claude Nov 24, 2026
148c15e
Make Data.new directly only while Data#initialize is the prelude's
claude Nov 24, 2026
5f4d562
Convert Date._strptime's arguments as MRI does, and compare matrix ro…
claude Nov 24, 2026
e72a4b8
Look #to_s up again after a respond_to? in ERB::Escape.html_escape
claude Nov 24, 2026
ea696b3
Keep one-off singleton methods out of the shared-rule table, and prob…
claude Nov 24, 2026
01daccc
Make two rows of sdef-matrix's section 11 test what they name
claude Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions Src/Libraries/Builtins/KernelOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1955,6 +1955,149 @@ public static object GetHiddenInstanceVariable(RubyContext/*!*/ context, object
return value;
}

/// <summary>
/// Data.new (ruby4.rb) for the usual call: when the class's initialize is Data#initialize itself and the
/// arguments are a value for every member, positionally or as keywords named by their Symbols, the new
/// frozen instance, made the way Data#initialize would have made it; null for anything else - an
/// initialize of the class's own, missing, unknown or String keys, the wrong count - which the caller
/// then does the long way, through initialize. MRI's rb_class_new_instance_pass_kw allocates without
/// calling #allocate and rb_data_initialize_m freezes without calling #freeze, as this does.
/// </summary>
[RubyMethod("__ir_data_new__", RubyMethodAttributes.PrivateInstance)]
public static object DataNew(RubyContext/*!*/ context, object self, [NotNull]RubyClass/*!*/ dataClass,
[NotNull]RubyArray/*!*/ args, [NotNull]Hash/*!*/ kwargs) {
var cls = self as RubyClass;
DataLayout layout;
if (cls == null || (layout = GetDataLayout(context, cls, dataClass)) == null) {
return null;
}
var members = layout.Members;
int n = members.Length;
var values = new object[n];
if (args.Count != 0) {
if (kwargs.Count != 0 || args.Count != n) {
return null;
}
for (int i = 0; i < n; i++) {
values[i] = args[i];
}
} else {
if (kwargs.Count != n) {
return null;
}
for (int i = 0; i < n; i++) {
if (!kwargs.TryGetValue(members[i], out values[i])) {
return null;
}
}
}
return NewData(context, cls, layout, values);
}

/// <summary>
/// Data#with (ruby4.rb) for the usual call: keywords that are all members named by their Symbols, on an
/// instance whose class's initialize is Data#initialize. The copy MRI's rb_data_with makes by passing
/// to_h merged with the keywords to initialize, made directly; null for anything else.
/// </summary>
[RubyMethod("__ir_data_with__", RubyMethodAttributes.PrivateInstance)]
public static object DataWith(RubyContext/*!*/ context, object self, [NotNull]RubyClass/*!*/ dataClass, [NotNull]Hash/*!*/ kwargs) {
var cls = context.GetClassOf(self).GetNonSingletonClass();
var layout = GetDataLayout(context, cls, dataClass);
if (layout == null) {
return null;
}
var members = layout.Members;
int n = members.Length;
var values = new object[n];
int found = 0;
for (int i = 0; i < n; i++) {
if (kwargs.TryGetValue(members[i], out values[i])) {
found++;
} else {
context.TryGetInstanceVariable(self, layout.Variables[i], out values[i]);
}
}
return found == kwargs.Count ? NewData(context, cls, layout, values) : null;
}

/// <summary>
/// The end of Data.define (ruby4.rb): stores the member list on the new class, with the names of the hidden
/// instance variables the members' values live in (DataNew and DataWith read them, so that nothing makes
/// the names anew on every call), and defines each member's reader - an attribute reader of that variable,
/// which a call site reads as it reads an attr_reader's, where a define_method block calling
/// __ir_hidden_ivar__ cost a block frame and a new name on every read.
/// </summary>
[RubyMethod("__ir_data_define__", RubyMethodAttributes.PrivateInstance)]
public static void DefineData(RubyContext/*!*/ context, [NotNull]RubyClass/*!*/ self, [NotNull]RubyArray/*!*/ names) {
var members = new RubySymbol[names.Count];
var variables = new string[names.Count];
for (int i = 0; i < variables.Length; i++) {
members[i] = (RubySymbol)names[i];
variables[i] = RubyUtils.GetHiddenInstanceVariableName(members[i].ToString());
}
context.SetInstanceVariable(self, RubyUtils.GetHiddenInstanceVariableName("data_members"), names);
context.SetInstanceVariable(self, DataLayoutName, new DataLayout(members, variables));
for (int i = 0; i < variables.Length; i++) {
string methodName = members[i].ToString();
self.AddMethod(context, methodName, new RubyAttributeReaderInfo(
(RubyMemberFlags)RubyUtils.GetSpecialMethodVisibility(RubyMethodVisibility.Public, methodName), self, variables[i]));
}
}

// A Data class's members and the hidden variables their values are kept in (DefineData).
private sealed class DataLayout {
public readonly RubySymbol/*!*/[]/*!*/ Members;
public readonly string/*!*/[]/*!*/ Variables;

public DataLayout(RubySymbol/*!*/[]/*!*/ members, string/*!*/[]/*!*/ variables) {
Members = members;
Variables = variables;
}
}

// The layout Data.define stored on cls or a class above it, when cls's initialize is Data#initialize - the
// prelude's own, which MarkDataInitializer recorded: a program that reopens Data and defines initialize again
// gets its initialize called, through the prelude's Ruby path.
private static DataLayout GetDataLayout(RubyContext/*!*/ context, RubyClass/*!*/ cls, RubyClass/*!*/ dataClass) {
var initializer = cls.ResolveMethod(Symbols.Initialize, VisibilityContext.AllVisible).Info;
object builtIn;
if (initializer == null || initializer.DeclaringModule != dataClass
|| !context.TryGetInstanceVariable(dataClass, DataInitializerName, out builtIn) || builtIn != (object)initializer) {
return null;
}
for (var c = cls; c != null && c != dataClass; c = c.SuperClass) {
object layout;
if (context.TryGetInstanceVariable(c, DataLayoutName, out layout)) {
return layout as DataLayout;
}
}
return null;
}

private static readonly string DataLayoutName = RubyUtils.GetHiddenInstanceVariableName("data_layout");
private static readonly string DataInitializerName = RubyUtils.GetHiddenInstanceVariableName("data_initializer");

/// <summary>
/// Records Data#initialize as the prelude defines it (ruby4.rb, right after the def), so that DataNew and
/// DataWith make an instance directly only while that is the initialize a Data class has.
/// </summary>
[RubyMethod("__ir_data_initializer__", RubyMethodAttributes.PrivateInstance)]
public static void MarkDataInitializer(RubyContext/*!*/ context, [NotNull]RubyClass/*!*/ self) {
context.SetInstanceVariable(self, DataInitializerName, self.ResolveMethod(Symbols.Initialize, VisibilityContext.AllVisible).Info);
}

private static object NewData(RubyContext/*!*/ context, RubyClass/*!*/ cls, DataLayout/*!*/ layout, object[]/*!*/ values) {
object instance = cls.TryAllocatePlainInstance();
if (instance == null) {
return null;
}
for (int i = 0; i < values.Length; i++) {
context.SetInstanceVariable(instance, layout.Variables[i], values[i]);
}
context.FreezeObject(instance);
return instance;
}

[RubyMethod("__ir_set_hidden_ivar__", RubyMethodAttributes.PrivateInstance)]
public static object SetHiddenInstanceVariable(RubyContext/*!*/ context, object self, [NotNull]RubySymbol/*!*/ name, object value) {
context.SetInstanceVariable(self, RubyUtils.GetHiddenInstanceVariableName(name.ToString()), value);
Expand Down
7 changes: 7 additions & 0 deletions Src/Libraries/Date/Date.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ internal Frac DayFraction {
return CreateCivil(self, year, month, day, ToStart(start));
}

// date/format.rb's _strptime for ASCII-only strings (DateStrptime.cs): a Hash, nil, or false
// when format.rb has to do it.
[RubyMethod("__strptime_ascii", RubyMethodAttributes.PrivateSingleton)]
public static object StrptimeAscii(RubyContext/*!*/ context, RubyClass/*!*/ self, [NotNull]MutableString/*!*/ str, [NotNull]MutableString/*!*/ fmt) {
return DateStrptime.Parse(context, str, fmt);
}

[RubyMethod("civil", RubyMethodAttributes.PublicSingleton)]
public static RubyDate/*!*/ Civil(RubyClass/*!*/ self,
[DefaultProtocol, DefaultParameterValue(-4712)]int year,
Expand Down
Loading
Loading