Features

InfraRuby is a compiler and runtime for statically typed Ruby.

The compiler requires annotations for field types and method signatures, and supports blocks, mixins, primitive types with autoboxing, generic types with bounded wildcards and type argument inference, and local type inference with autocasting.

field types

nullable types

InfraRuby supports nullable types. In type annotations a nullable type is indicated with a question mark (example: java.lang.Object?). The compiler forbids calling methods on a receiver with a nullable type.

local type inference

The compiler infers local variable types. For example, here s is inferred to be a String and n is inferred to be a Integer:

s = "hello"
n = s.size

The compiler infers non-nullable types after null checks. For example, if s is a String?, the method call is permitted after a null check:

unless s.nil?
n = s.size
end

The method call is also permitted if the compiler can infer a non-nullable type from the control flow:

if s.nil?
raise RuntimeError
end
n = s.size

The compiler also infers types after type checks. For example, if o is an Object, the method call is permitted after a type check:

if o.is_a?(String)
n = o.size
end

The compiler infers types across conditional branches. For example, after this code, o is inferred to be a Numeric:

if c
o = 1
else
o = 3.1
end

blocks

InfraRuby supports blocks. A method signature indicates the argument types and return type of a block the method accepts. Here are some examples:

primitive types

boolean literals

true

false

byte literal

0.byte

char literal

0.char

int16 literal

0.i16

int32 literal

0.i32

int64 literal

0.i64

float32 literal

3.1.f32

float64 literal

3.1.f64

The logical operators for the boolean type and the arithmetic operators for the numeric primitive types are compiler intrinsics. The methods #times, #upto and #downto for the int32 type are also compiler intrinsics.