Skip to content

Commit

Permalink
Revert "Add ReferenceStorage for manual allocation of references (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Jan 10, 2024
1 parent bd43c5f commit 9d52e30
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 132 deletions.
40 changes: 0 additions & 40 deletions spec/compiler/semantic/reference_storage_spec.cr

This file was deleted.

4 changes: 3 additions & 1 deletion spec/primitives/reference_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ describe "Primitives: reference" do
end

it "works when address is on the stack" do
foo_buffer = uninitialized ReferenceStorage(Foo)
# suitably aligned, sufficient storage for type ID + i64 + ptr
# TODO: use `ReferenceStorage` instead
foo_buffer = uninitialized UInt64[3]
foo = Foo.pre_initialize(pointerof(foo_buffer))
pointerof(foo_buffer).as(typeof(Foo.crystal_instance_type_id)*).value.should eq(Foo.crystal_instance_type_id)
foo.str.should eq("abc")
Expand Down
4 changes: 0 additions & 4 deletions src/compiler/crystal/codegen/llvm_typer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,6 @@ module Crystal
llvm_type(type.remove_alias, wants_size)
end

private def create_llvm_type(type : ReferenceStorageType, wants_size)
llvm_struct_type(type.reference_type, wants_size)
end

private def create_llvm_type(type : NonGenericModuleType | GenericClassType, wants_size)
# This can only be reached if the module or generic class don't have implementors
@llvm_context.int1
Expand Down
6 changes: 1 addition & 5 deletions src/compiler/crystal/program.cr
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,6 @@ module Crystal
types["Struct"] = struct_t = @struct_t = NonGenericClassType.new self, self, "Struct", value
abstract_value_type(struct_t)

types["ReferenceStorage"] = @reference_storage = reference_storage = GenericReferenceStorageType.new self, self, "ReferenceStorage", value, ["T"]
reference_storage.declare_instance_var("@type_id", int32)
reference_storage.can_be_stored = false

types["Enumerable"] = @enumerable = GenericModuleType.new self, self, "Enumerable", ["T"]
types["Indexable"] = @indexable = GenericModuleType.new self, self, "Indexable", ["T"]

Expand Down Expand Up @@ -497,7 +493,7 @@ module Crystal

{% for name in %w(object no_return value number reference void nil bool char int int8 int16 int32 int64 int128
uint8 uint16 uint32 uint64 uint128 float float32 float64 string symbol pointer enumerable indexable
array static_array reference_storage exception tuple named_tuple proc union enum range regex crystal
array static_array exception tuple named_tuple proc union enum range regex crystal
packed_annotation thread_local_annotation no_inline_annotation
always_inline_annotation naked_annotation returns_twice_annotation
raises_annotation primitive_annotation call_convention_annotation
Expand Down
28 changes: 1 addition & 27 deletions src/compiler/crystal/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ module Crystal
def allows_instance_vars?
case self
when program.object, program.value, program.struct,
program.reference, program.class_type, program.reference_storage,
program.reference, program.class_type,
program.number, program.int, program.float,
program.tuple, program.named_tuple,
program.pointer, program.static_array,
Expand Down Expand Up @@ -2642,32 +2642,6 @@ module Crystal
end
end

# The non-instantiated ReferenceStorage(T) type.
class GenericReferenceStorageType < GenericClassType
@struct = true

def new_generic_instance(program, generic_type, type_vars)
t = type_vars["T"].type

unless t.is_a?(TypeParameter) || (t.class? && !t.struct?)
raise TypeException.new "Can't instantiate ReferenceStorage(T) with T = #{t} (T must be a reference type)"
end

ReferenceStorageType.new program, t
end
end

class ReferenceStorageType < GenericClassInstanceType
getter reference_type : Type

def initialize(program, @reference_type)
t_var = Var.new("T", @reference_type)
t_var.bind_to t_var

super(program, program.reference_storage, program.struct, {"T" => t_var} of String => ASTNode)
end
end

# A lib type, like `lib LibC`.
class LibType < ModuleType
getter link_annotations : Array(LinkAnnotation)?
Expand Down
1 change: 0 additions & 1 deletion src/prelude.cr
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ require "raise"
require "random"
require "range"
require "reference"
require "reference_storage"
require "regex"
require "set"
{% unless flag?(:wasm32) %}
Expand Down
54 changes: 0 additions & 54 deletions src/reference_storage.cr

This file was deleted.

0 comments on commit 9d52e30

Please sign in to comment.