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: d63ebf8209a0
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: 78a7220e0420
Choose a head ref
  • 2 commits
  • 89 files changed
  • 1 contributor

Commits on Jul 22, 2016

  1. Compiler: replace Dependencies with Array(ASTNode)

    Its memory savings and time speedups are not significant,
    and it also makes the codebase larger.
    Ary Borenszweig committed Jul 22, 2016
    Copy the full SHA
    5c57213 View commit details
  2. Compiler: more refactors.

    - Moved FileNode to semantic directory
    - "infer type" is now "semantic" (because it's more than just inferring types)
    Ary Borenszweig committed Jul 22, 2016
    Copy the full SHA
    78a7220 View commit details
Showing with 293 additions and 484 deletions.
  1. +1 −1 spec/compiler/codegen/alias_spec.cr
  2. +1 −4 spec/compiler/codegen/const_spec.cr
  3. +1 −1 spec/compiler/codegen/yield_with_scope_spec.cr
  4. +2 −2 spec/compiler/crystal/types_spec.cr
  5. +11 −11 spec/compiler/{type_inference → semantic}/abstract_def_spec.cr
  6. +1 −1 spec/compiler/{type_inference → semantic}/alias_spec.cr
  7. +1 −1 spec/compiler/{type_inference → semantic}/array_spec.cr
  8. +2 −2 spec/compiler/{type_inference → semantic}/block_spec.cr
  9. +1 −1 spec/compiler/{type_inference → semantic}/c_enum_spec.cr
  10. +2 −2 spec/compiler/{type_inference → semantic}/c_struct_spec.cr
  11. +1 −1 spec/compiler/{type_inference → semantic}/c_type_spec.cr
  12. +1 −1 spec/compiler/{type_inference → semantic}/c_union_spec.cr
  13. +1 −1 spec/compiler/{type_inference → semantic}/cast_spec.cr
  14. +6 −6 spec/compiler/{type_inference → semantic}/class_spec.cr
  15. +1 −1 spec/compiler/{type_inference → semantic}/class_var_spec.cr
  16. 0 spec/compiler/{type_inference → semantic}/cleanup_spec.cr
  17. +1 −1 spec/compiler/{type_inference → semantic}/closure_spec.cr
  18. +3 −3 spec/compiler/{type_inference → semantic}/const_spec.cr
  19. +1 −1 spec/compiler/{type_inference → semantic}/def_overload_spec.cr
  20. +4 −4 spec/compiler/{type_inference → semantic}/def_spec.cr
  21. +2 −2 spec/compiler/{type_inference → semantic}/did_you_mean_spec.cr
  22. +25 −25 spec/compiler/{type_inference → semantic}/doc_spec.cr
  23. +1 −1 spec/compiler/{type_inference → semantic}/double_splat_spec.cr
  24. +2 −2 spec/compiler/{type_inference → semantic}/enum_spec.cr
  25. +1 −1 spec/compiler/{type_inference → semantic}/exception_spec.cr
  26. +1 −1 spec/compiler/{type_inference → semantic}/external_internal_spec.cr
  27. +2 −25 spec/compiler/{type_inference → semantic}/generic_class_spec.cr
  28. +2 −2 spec/compiler/{type_inference → semantic}/global_spec.cr
  29. +2 −4 spec/compiler/{type_inference → semantic}/hooks_spec.cr
  30. +1 −1 spec/compiler/{type_inference → semantic}/if_spec.cr
  31. +2 −2 spec/compiler/{type_inference → semantic}/initialize_spec.cr
  32. +2 −2 spec/compiler/{type_inference → semantic}/instance_var_spec.cr
  33. +4 −4 spec/compiler/{type_inference → semantic}/is_a_spec.cr
  34. +5 −5 spec/compiler/{type_inference → semantic}/lib_spec.cr
  35. +2 −2 spec/compiler/{type_inference → semantic}/macro_spec.cr
  36. +1 −1 spec/compiler/{type_inference → semantic}/method_missing_spec.cr
  37. +1 −1 spec/compiler/{type_inference → semantic}/module_spec.cr
  38. +1 −1 spec/compiler/{type_inference → semantic}/named_args_spec.cr
  39. +1 −1 spec/compiler/{type_inference → semantic}/named_tuple_spec.cr
  40. +1 −1 spec/compiler/{type_inference → semantic}/new_spec.cr
  41. +1 −1 spec/compiler/{type_inference → semantic}/nil_spec.cr
  42. +1 −1 spec/compiler/{type_inference → semantic}/nilable_cast_spec.cr
  43. +1 −1 spec/compiler/{type_inference → semantic}/nilable_instance_var_spec.cr
  44. +1 −1 spec/compiler/{type_inference → semantic}/no_return_spec.cr
  45. +1 −1 spec/compiler/{type_inference → semantic}/not_spec.cr
  46. +1 −1 spec/compiler/{type_inference → semantic}/pointer_spec.cr
  47. +1 −1 spec/compiler/{type_inference → semantic}/previous_def_spec.cr
  48. +1 −1 spec/compiler/{type_inference → semantic}/primitives_spec.cr
  49. +1 −1 spec/compiler/{type_inference → semantic}/private_def_spec.cr
  50. +2 −2 spec/compiler/{type_inference → semantic}/proc_spec.cr
  51. +2 −2 spec/compiler/{type_inference → semantic}/reflection_spec.cr
  52. +2 −2 spec/compiler/{type_inference → semantic}/responds_to_spec.cr
  53. +3 −3 spec/compiler/{type_inference → semantic}/restrictions_spec.cr
  54. +1 −1 spec/compiler/{type_inference → semantic}/return_spec.cr
  55. +1 −1 spec/compiler/{type_inference → semantic}/special_vars_spec.cr
  56. +1 −1 spec/compiler/{type_inference → semantic}/splat_spec.cr
  57. +1 −1 spec/compiler/{type_inference → semantic}/ssa_spec.cr
  58. +1 −1 spec/compiler/{type_inference → semantic}/static_array_spec.cr
  59. +1 −1 spec/compiler/{type_inference → semantic}/struct_spec.cr
  60. +2 −2 spec/compiler/{type_inference → semantic}/super_spec.cr
  61. +1 −1 spec/compiler/{type_inference → semantic}/tuple_spec.cr
  62. +1 −1 spec/compiler/{type_inference → semantic}/uninitialized_spec.cr
  63. +1 −1 spec/compiler/{type_inference → semantic}/union_spec.cr
  64. +3 −3 spec/compiler/{type_inference → semantic}/var_spec.cr
  65. +1 −1 spec/compiler/{type_inference → semantic}/virtual_metaclass_spec.cr
  66. +5 −5 spec/compiler/{type_inference → semantic}/virtual_spec.cr
  67. 0 spec/compiler/{type_inference → semantic}/visibility_modifiers_spec.cr
  68. +1 −1 spec/compiler/{type_inference → semantic}/while_spec.cr
  69. +4 −4 spec/compiler/{type_inference → semantic}/yield_with_scope_spec.cr
  70. +0 −39 spec/compiler/type_inference/dependencies_spec.cr
  71. +13 −13 spec/spec_helper.cr
  72. +2 −2 src/compiler/crystal/codegen/codegen.cr
  73. +3 −3 src/compiler/crystal/command.cr
  74. +1 −1 src/compiler/crystal/command/docs.cr
  75. +5 −5 src/compiler/crystal/compiler.cr
  76. +21 −35 src/compiler/crystal/{semantic/type_inference.cr → semantic.cr}
  77. +54 −17 src/compiler/crystal/semantic/ast.cr
  78. +20 −0 src/compiler/crystal/semantic/base_type_visitor.cr
  79. +0 −106 src/compiler/crystal/semantic/dependencies.cr
  80. +1 −1 src/compiler/crystal/semantic/filters.cr
  81. +1 −2 src/compiler/crystal/semantic/fix_empty_types.cr
  82. +2 −2 src/compiler/crystal/semantic/main_visitor.cr
  83. +13 −0 src/compiler/crystal/semantic/to_s.cr
  84. +7 −10 src/compiler/crystal/semantic/top_level_visitor.cr
  85. +5 −0 src/compiler/crystal/semantic/transformer.cr
  86. +1 −12 src/compiler/crystal/semantic/type_merge.cr
  87. +0 −46 src/compiler/crystal/syntax/ast.cr
  88. +0 −13 src/compiler/crystal/syntax/to_s.cr
  89. +0 −5 src/compiler/crystal/syntax/transformer.cr
2 changes: 1 addition & 1 deletion spec/compiler/codegen/alias_spec.cr
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ describe "Code gen: alias" do
end

it "doesn't break with alias for link attributes" do
result = infer_type(%(
result = semantic(%(
alias Foo = Int32
module B
5 changes: 1 addition & 4 deletions spec/compiler/codegen/const_spec.cr
Original file line number Diff line number Diff line change
@@ -204,10 +204,7 @@ describe "Codegen: const" do
").to_i.should eq(3)
end

# Constants are actually initialized before main code, so this should
# probably give an error. Since this code is very unlikely to happen,
# we'll fix it later.
pending "works with const initialized after global variable" do
it "works with const initialized after global variable" do
run(%(
$a = 1
COCO = $a
2 changes: 1 addition & 1 deletion spec/compiler/codegen/yield_with_scope_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../../spec_helper"

describe "Type inference: yield with scope" do
describe "Semantic: yield with scope" do
it "uses scope in global method" do
run("
require \"prelude\"
4 changes: 2 additions & 2 deletions spec/compiler/crystal/types_spec.cr
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ end

describe "types to_s of" do
it "does for type contained in generic class" do
result = infer_type(%(
result = semantic(%(
class Bar(T)
class Foo
end
@@ -18,7 +18,7 @@ describe "types to_s of" do
end

it "does for type contained in generic module" do
result = infer_type(%(
result = semantic(%(
module Bar(T)
class Foo
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../../spec_helper"

describe "Type inference: abstract def" do
describe "Semantic: abstract def" do
it "errors if using abstract def on subclass" do
assert_error %(
abstract class Foo
@@ -183,7 +183,7 @@ describe "Type inference: abstract def" do
end

it "doesn't error if abstract method is implemented by subclass" do
infer_type %(
semantic %(
abstract class Foo
abstract def foo
end
@@ -196,7 +196,7 @@ describe "Type inference: abstract def" do
end

it "doesn't error if abstract method with args is implemented by subclass" do
infer_type %(
semantic %(
abstract class Foo
abstract def foo(x, y)
end
@@ -209,7 +209,7 @@ describe "Type inference: abstract def" do
end

it "doesn't error if abstract method with args is implemented by subclass (restriction -> no restriction)" do
infer_type %(
semantic %(
abstract class Foo
abstract def foo(x, y : Int32)
end
@@ -222,7 +222,7 @@ describe "Type inference: abstract def" do
end

it "doesn't error if abstract method with args is implemented by subclass (don't check subclasses)" do
infer_type %(
semantic %(
abstract class Foo
abstract def foo
end
@@ -253,7 +253,7 @@ describe "Type inference: abstract def" do
end

it "doesn't error if abstract method is implemented by subclass via module inclusion" do
infer_type %(
semantic %(
abstract class Foo
abstract def foo
end
@@ -283,7 +283,7 @@ describe "Type inference: abstract def" do
end

it "doesn't error if abstract method is implemented by including class" do
infer_type %(
semantic %(
module Foo
abstract def foo
end
@@ -298,7 +298,7 @@ describe "Type inference: abstract def" do
end

it "doesn't error if abstract method is not implemented by including module" do
infer_type %(
semantic %(
module Foo
abstract def foo
end
@@ -324,7 +324,7 @@ describe "Type inference: abstract def" do
end

it "doesn't error if abstract method with args is implemented by subclass (with one default arg)" do
infer_type %(
semantic %(
abstract class Foo
abstract def foo(x)
end
@@ -337,7 +337,7 @@ describe "Type inference: abstract def" do
end

it "doesn't error if implements with parent class" do
infer_type %(
semantic %(
class Parent; end
class Child < Parent; end
@@ -353,7 +353,7 @@ describe "Type inference: abstract def" do
end

it "doesn't error if implements with parent module" do
infer_type %(
semantic %(
module Moo
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../../spec_helper"

describe "type inference: alias" do
describe "Semantic: alias" do
it "resolves alias type" do
assert_type("
alias Alias = Int32
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../../spec_helper"

describe "Type inference: array" do
describe "Semantic: array" do
it "types array literal of int" do
assert_type("require \"prelude\"; [1, 2, 3]") { array_of(int32) }
end
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ describe "Block inference" do
x = 1
end
").as(Expressions)
result = infer_type input
result = semantic input
input.last.as(Call).block.not_nil!.body.type.should eq(result.program.int32)
end

@@ -32,7 +32,7 @@ describe "Block inference" do
1
end
").as(Expressions)
result = infer_type input
result = semantic input
mod = result.program
input.last.as(Call).block.not_nil!.args[0].type.should eq(mod.int32)
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../../spec_helper"

describe "Type inference: c enum" do
describe "Semantic: c enum" do
it "types enum value" do
assert_type("lib LibFoo; enum Bar; X, Y, Z = 10, W; end; end; LibFoo::Bar::X") { types["LibFoo"].types["Bar"] }
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../../spec_helper"

describe "Type inference: struct" do
describe "Semantic: struct" do
it "types struct" do
result = assert_type("lib LibFoo; struct Bar; x : Int32; y : Float64; end; end; LibFoo::Bar") { types["LibFoo"].types["Bar"].metaclass }
mod = result.program
@@ -247,7 +247,7 @@ describe "Type inference: struct" do
end

it "marks as packed" do
result = infer_type(%(
result = semantic(%(
lib LibFoo
@[Packed]
struct Struct
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../../spec_helper"

describe "Type inference: type" do
describe "Semantic: type" do
it "can call methods of original type" do
assert_type("
lib Lib
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../../spec_helper"

describe "Type inference: c union" do
describe "Semantic: c union" do
it "types c union" do
result = assert_type("lib LibFoo; union Bar; x : Int32; y : Float64; end; end; LibFoo::Bar") { types["LibFoo"].types["Bar"].metaclass }
mod = result.program
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../../spec_helper"

describe "Type inference: cast" do
describe "Semantic: cast" do
it "casts to same type is ok" do
assert_type("1 as Int32 ") { int32 }
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../../spec_helper"

describe "Type inference: class" do
describe "Semantic: class" do
it "types Const#allocate" do
assert_type("class Foo; end; Foo.allocate") { types["Foo"].as(NonGenericClassType) }
end
@@ -67,7 +67,7 @@ describe "Type inference: class" do
g.set 2.5
g
"
result = infer_type input
result = semantic input
mod, node = result.program, result.node.as(Expressions)
foo = mod.types["Foo"].as(GenericClassType)

@@ -98,7 +98,7 @@ describe "Type inference: class" do
g.set 2.5
g.get
").as(Expressions)
result = infer_type input
result = semantic input
mod, node = result.program, result.node.as(Expressions)

node[3].type.should eq(mod.nilable(mod.int32))
@@ -121,7 +121,7 @@ describe "Type inference: class" do
n.add
n
").as(Expressions)
result = infer_type input
result = semantic input
mod, input = result.program, result.node.as(Expressions)
node = mod.types["Node"].as(NonGenericClassType)

@@ -241,7 +241,7 @@ describe "Type inference: class" do
Foo::Bar.new(1)
").as(Expressions)
result = infer_type nodes
result = semantic nodes
mod = result.program
type = nodes.last.type.as(GenericClassInstanceType)
type.type_vars["T"].type.should eq(mod.int32)
@@ -348,7 +348,7 @@ describe "Type inference: class" do
class Foo::Bar
end
")
result = infer_type input
result = semantic input
mod = result.program
mod.types["Foo"].types["Bar"].as(NonGenericClassType)
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../../spec_helper"

describe "Type inference: class var" do
describe "Semantic: class var" do
it "declares class variable" do
assert_error %(
class Foo
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../../spec_helper"

describe "Type inference: closure" do
describe "Semantic: closure" do
it "gives error when doing yield inside proc literal" do
assert_error "-> { yield }", "can't use `yield` outside a method"
end
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require "../../spec_helper"

describe "Type inference: const" do
describe "Semantic: const" do
it "types a constant" do
input = parse("A = 1").as(Assign)
result = infer_type input
result = semantic input
mod = result.program
input.target.type?.should be_nil # Don't type value until needed
end
@@ -164,7 +164,7 @@ describe "Type inference: const" do

["nil", "true", "1", "'a'", %("foo"), "+ 1", "- 2", "~ 2", "1 + 2", "1 + Z"].each do |node|
it "doesn't errors if constant depends on another one defined later through method, but constant is simple (#{node})" do
infer_type(%(
semantic(%(
Z = 10
struct Int32
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../../spec_helper"

describe "Type inference: def overload" do
describe "Semantic: def overload" do
it "types a call with overload" do
assert_type("def foo; 1; end; def foo(x); 2.5; end; foo") { int32 }
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../../spec_helper"

describe "Type inference: def" do
describe "Semantic: def" do
it "types a call with an int" do
assert_type("def foo; 1; end; foo") { int32 }
end
@@ -19,7 +19,7 @@ describe "Type inference: def" do

it "types a call with an argument" do
input = parse "def foo(x); x; end; foo 1; foo 2.3"
result = infer_type input
result = semantic input
mod, input = result.program, result.node.as(Expressions)

input[1].type.should eq(mod.int32)
@@ -32,7 +32,7 @@ describe "Type inference: def" do

it "assigns def owner" do
input = parse "struct Int; def foo; 2.5; end; end; 1.foo"
result = infer_type input
result = semantic input
mod, input = result.program, result.node.as(Expressions)
input.last.as(Call).target_def.owner.should eq(mod.int32)
end
@@ -101,7 +101,7 @@ describe "Type inference: def" do
foo
)
result = infer_type input
result = semantic input
mod, input = result.program, result.node.as(Expressions)

call = input.last.as(Call)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../../spec_helper"

describe "Type inference: did you mean" do
describe "Semantic: did you mean" do
it "says did you mean for one mistake in short word in instance method" do
assert_error "
class Foo
@@ -111,7 +111,7 @@ describe "Type inference: did you mean" do
Foo.new.a
)
begin
infer_type nodes
semantic nodes
fail "TypeException wasn't raised"
rescue ex : Crystal::TypeException
ex.to_s.includes?("did you mean").should be_false
Loading