Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3d9f4709481e
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b5e46dbebf33
Choose a head ref
  • 5 commits
  • 6 files changed
  • 1 contributor

Commits on Jun 16, 2016

  1. Fixed #2839: don't use + in types on semantic phase

    Ary Borenszweig committed Jun 16, 2016

    Verified

    This commit was signed with the committer’s verified signature.
    jhass Jonne Haß
    Copy the full SHA
    3c7aee9 View commit details
  2. Change compile-time version check to starts_with?

    Ary Borenszweig committed Jun 16, 2016
    Copy the full SHA
    ab6b852 View commit details
  3. Merge branch 'release/0.18'

    Ary Borenszweig committed Jun 16, 2016
    Copy the full SHA
    5f95d63 View commit details
  4. Use 0.18.1 version check for tuple and proc to_s

    Ary Borenszweig committed Jun 16, 2016
    Copy the full SHA
    f1a9684 View commit details
  5. Merge branch 'release/0.18'

    Ary Borenszweig committed Jun 16, 2016
    Copy the full SHA
    b5e46db View commit details
63 changes: 63 additions & 0 deletions spec/compiler/codegen/generic_class_spec.cr
Original file line number Diff line number Diff line change
@@ -193,4 +193,67 @@ describe "Code gen: generic class type" do
Hello(MAX_RANGE).t
)).to_u64.should eq(2374623294237463578)
end

it "doesn't use virtual + in type arguments (#2839)" do
run(%(
class Class
def name : String
{{ @type.name.stringify }}
end
end
class Foo
end
class Bar < Foo
end
class Gen(T)
end
Gen(Foo).name
)).to_string.should eq("Gen(Foo)")
end

it "doesn't use virtual + in type arguments for Tuple (#2839)" do
run(%(
class Class
def name : String
{{ @type.name.stringify }}
end
end
class Foo
end
class Bar < Foo
end
class Gen(T)
end
Tuple(Foo).name
)).to_string.should eq("Tuple(Foo)")
end

it "doesn't use virtual + in type arguments for NamedTuple (#2839)" do
run(%(
class Class
def name : String
{{ @type.name.stringify }}
end
end
class Foo
end
class Bar < Foo
end
class Gen(T)
end
NamedTuple(x: Foo).name
)).to_string.should eq("NamedTuple(x: Foo)")
end
end
2 changes: 1 addition & 1 deletion spec/compiler/type_inference/cast_spec.cr
Original file line number Diff line number Diff line change
@@ -243,7 +243,7 @@ describe "Type inference: cast" do
Gen(Foo).new
Gen(Bar).new as Gen(Foo)
), "can't cast Gen(Bar) to Gen(Foo+)"
), "can't cast Gen(Bar) to Gen(Foo)"
end

it "allows casting NoReturn to any type (#2132)" do
8 changes: 4 additions & 4 deletions spec/std/proc_spec.cr
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ describe "Proc" do
str = MemoryIO.new
f = ->(x : Int32) { x.to_f }
f.to_s(str)
{% if Crystal::VERSION == "0.18.0" %}
{% if Crystal::VERSION.starts_with?("0.18.1") %}
str.to_s.should eq("#<Proc(Int32, Float64):0x#{f.pointer.address.to_s(16)}>")
{% else %}
str.to_s.should eq("#<(Int32 -> Float64):0x#{f.pointer.address.to_s(16)}>")
@@ -17,7 +17,7 @@ describe "Proc" do
a = 1.5
f = ->(x : Int32) { x + a }
f.to_s(str)
{% if Crystal::VERSION == "0.18.0" %}
{% if Crystal::VERSION.starts_with?("0.18.1") %}
str.to_s.should eq("#<Proc(Int32, Float64):0x#{f.pointer.address.to_s(16)}:closure>")
{% else %}
str.to_s.should eq("#<(Int32 -> Float64):0x#{f.pointer.address.to_s(16)}:closure>")
@@ -27,7 +27,7 @@ describe "Proc" do
it "does to_s" do
str = MemoryIO.new
f = ->(x : Int32) { x.to_f }
{% if Crystal::VERSION == "0.18.0" %}
{% if Crystal::VERSION.starts_with?("0.18.1") %}
f.to_s.should eq("#<Proc(Int32, Float64):0x#{f.pointer.address.to_s(16)}>")
{% else %}
f.to_s.should eq("#<(Int32 -> Float64):0x#{f.pointer.address.to_s(16)}>")
@@ -38,7 +38,7 @@ describe "Proc" do
str = MemoryIO.new
a = 1.5
f = ->(x : Int32) { x + a }
{% if Crystal::VERSION == "0.18.0" %}
{% if Crystal::VERSION.starts_with?("0.18.1") %}
f.to_s.should eq("#<Proc(Int32, Float64):0x#{f.pointer.address.to_s(16)}:closure>")
{% else %}
f.to_s.should eq("#<(Int32 -> Float64):0x#{f.pointer.address.to_s(16)}:closure>")
2 changes: 1 addition & 1 deletion spec/std/tuple_spec.cr
Original file line number Diff line number Diff line change
@@ -270,7 +270,7 @@ describe "Tuple" do

it "does types" do
tuple = {1, 'a', "hello"}
{% if Crystal::VERSION == "0.18.0" %}
{% if Crystal::VERSION == "0.18.1" %}
tuple.types.to_s.should eq("Tuple(Int32, Char, String)")
{% else %}
tuple.types.to_s.should eq("{Int32, Char, String}")
8 changes: 4 additions & 4 deletions src/compiler/crystal/codegen/types.cr
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ module Crystal
end

def llvm_name(io)
to_s io
to_s_with_options io, codegen: true
end
end

@@ -20,21 +20,21 @@ module Crystal
class AliasType
def llvm_name(io)
io << "alias."
to_s io
to_s_with_options io, codegen: true
end
end

class CStructType
def llvm_name(io)
io << "struct."
to_s io
to_s_with_options io, codegen: true
end
end

class CUnionType
def llvm_name(io)
io << "union."
to_s io
to_s_with_options io, codegen: true
end
end

63 changes: 38 additions & 25 deletions src/compiler/crystal/types.cr
Original file line number Diff line number Diff line change
@@ -503,7 +503,7 @@ module Crystal
to_s_with_options(io)
end

abstract def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true)
abstract def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen = false)
end

# A type that has a name and can be contained inside other types.
@@ -539,7 +539,7 @@ module Crystal
String.build { |io| append_full_name(io) }
end

def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true)
def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen = false)
append_full_name(io)
end
end
@@ -1343,7 +1343,7 @@ module Crystal
true
end

def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true)
def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen = false)
io << "NoReturn"
end
end
@@ -1353,7 +1353,7 @@ module Crystal
true
end

def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true)
def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen = false)
io << "Void"
end
end
@@ -1534,7 +1534,7 @@ module Crystal
end
end

def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true)
def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen = false)
super
if generic_args
io << "("
@@ -1634,7 +1634,7 @@ module Crystal
end
end

def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true)
def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen = false)
super
if generic_args
io << "("
@@ -1762,7 +1762,7 @@ module Crystal
program.after_inference_types << self
end

def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true)
def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen = false)
generic_class.append_full_name(io)
io << "("
i = 0
@@ -1773,10 +1773,13 @@ module Crystal
tuple = type_var.type.as(TupleInstanceType)
tuple.tuple_types.each_with_index do |tuple_type, j|
io << ", " if j > 0
tuple_type.to_s(io)
tuple_type = tuple_type.devirtualize unless codegen
tuple_type.to_s_with_options(io, codegen: codegen)
end
else
type_var.type.to_s_with_options(io, skip_union_parens: true)
type_var_type = type_var.type
type_var_type = type_var_type.devirtualize unless codegen
type_var_type.to_s_with_options(io, skip_union_parens: true, codegen: codegen)
end
else
type_var.to_s(io)
@@ -1964,11 +1967,12 @@ module Crystal
tuple_types.any? { |tuple_type| tuple_type.includes_type?(type) || tuple_type.has_in_type_vars?(type) }
end

def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true)
def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen = false)
io << "Tuple("
@tuple_types.each_with_index do |tuple_type, i|
io << ", " if i > 0
tuple_type.to_s_with_options(io, skip_union_parens: true)
tuple_type = tuple_type.devirtualize unless codegen
tuple_type.to_s_with_options(io, skip_union_parens: true, codegen: codegen)
end
io << ")"
end
@@ -2073,7 +2077,7 @@ module Crystal
true
end

def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true)
def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen = false)
io << "NamedTuple("
@entries.each_with_index do |entry, i|
io << ", " if i > 0
@@ -2083,7 +2087,9 @@ module Crystal
io << entry.name
end
io << ": "
entry.type.to_s_with_options(io, skip_union_parens: true)
entry_type = entry.type
entry_type = entry_type.devirtualize unless codegen
entry_type.to_s_with_options(io, skip_union_parens: true, codegen: codegen)
end
io << ")"
end
@@ -2137,7 +2143,7 @@ module Crystal
end
end

def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true)
def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen = false)
@module.to_s(io)
io << "("
@including_class.to_s(io)
@@ -2219,7 +2225,7 @@ module Crystal
end
end

def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true)
def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen = false)
@extended_class.to_s(io)
io << "("
@extending_class.to_s(io)
@@ -2621,7 +2627,7 @@ module Crystal
instance_type.virtual_type!.metaclass
end

def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true)
def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen = false)
io << @name
end
end
@@ -2662,7 +2668,7 @@ module Crystal
instance_type
end

def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true)
def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen = false)
instance_type.to_s(io)
io << ":Class"
end
@@ -2807,15 +2813,19 @@ module Crystal
self == other_type || union_types.all?(&.implements?(other_type))
end

def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true)
def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen = false)
io << "(" unless skip_union_parens
union_types = @union_types
# Make sure to put Nil at the end
if nil_type_index = @union_types.index(&.nil_type?)
union_types = @union_types.dup
union_types << union_types.delete_at(nil_type_index)
end
names = union_types.join(" | ", io)
union_types.each_with_index do |type, i|
io << " | " if i > 0
type = type.devirtualize unless codegen
type.to_s_with_options(io, codegen: codegen)
end
io << ")" unless skip_union_parens
end

@@ -3076,7 +3086,7 @@ module Crystal
nil
end

def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true)
def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen = false)
base_type.to_s(io)
io << "+"
end
@@ -3149,8 +3159,8 @@ module Crystal
nil
end

def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true)
instance_type.to_s(io)
def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen = false)
instance_type.to_s_with_options(io, codegen: codegen)
io << ":Class"
end
end
@@ -3234,13 +3244,16 @@ module Crystal
super
end

def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true)
def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen = false)
io << "Proc("
arg_types.each_with_index do |type, i|
type.to_s(io)
type = type.devirtualize unless codegen
type.to_s_with_options(io, codegen: codegen)
io << ", "
end
return_type.to_s(io)
return_type = self.return_type
return_type = return_type.devirtualize unless codegen
return_type.to_s_with_options(io, codegen: codegen)
io << ")"
end
end