Skip to content

Do not hardcode ReferenceStorage as a built-in type#14204

Closed
HertzDevil wants to merge 1 commit intocrystal-lang:masterfrom
HertzDevil:bug/reference-storage-definition
Closed

Do not hardcode ReferenceStorage as a built-in type#14204
HertzDevil wants to merge 1 commit intocrystal-lang:masterfrom
HertzDevil:bug/reference-storage-definition

Conversation

@HertzDevil
Copy link
Contributor

Fixes #14194. Checked with make clean crystal && git checkout 1.9.0 && bin/crystal spec spec/std/int_spec.cr. (Even earlier versions would still fail due to an LLVM intrinsic name mismatch regarding opaque pointers, unrelated to this feature.)

@HertzDevil HertzDevil added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic kind:regression Something that used to correctly work but no longer works labels Jan 10, 2024
Comment on lines +525 to +534
when @program.primitive_annotation
# there isn't a PrimitiveAnnotation type yet, so we validate right here
if ann.args.size != 1
ann.raise "expected Primitive annotation to have one argument"
end

arg = ann.args.first
unless arg.is_a?(SymbolLiteral)
arg.raise "expected Primitive argument to be a symbol literal"
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Is this an integral part of this patch? It looks like a tangential issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this would probably prevent us from "exploiting" @[Primitive] in other places in a backward-compatible manner

# than `instance_sizeof(T)` bytes, such as `String` and `Log::Metadata`.
@[Experimental("This type's API is still under development. Join the discussion about custom reference allocation at [#13481](https://github.com/crystal-lang/crystal/issues/13481).")]
struct ReferenceStorage(T)
@[Primitive(:reference_storage_type)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Use camel case for primitive types, equivalent to type names.

Suggested change
@[Primitive(:reference_storage_type)]
@[Primitive(:ReferenceStorageType)]

This is a minor thing. Either spelling should work because it's backed by Enum.parse. But I think this makes a bit more sense for type names.

case annotation_type
when @program.primitive_annotation
arg = ann.args.first.as(SymbolLiteral)
unless special_type = PrimitiveType.parse?(arg.value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick(style): I found it hard to recognize that this line assigns to special_type. I was looking for an assignment and didn't see this at first because it starts with an unless.
I'd suggest to split this into two lines to improve readability.

Suggested change
unless special_type = PrimitiveType.parse?(arg.value)
special_type = PrimitiveType.parse?(arg.value)
unless special_type

A trailing unless would also be possible.

if node.splat_index
node.raise "BUG: Expected reference_storage_type to have no splat parameter"
end
type = GenericReferenceStorageType.new @program, scope, name, @program.value, type_vars
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chore: Can we also validate node.struct? == true and node.abstract? == false?
abstract class ReferenceStorage(T) should be invalid.

@HertzDevil
Copy link
Contributor Author

Superseded by #14270

@HertzDevil HertzDevil closed this Jan 29, 2024
@HertzDevil HertzDevil deleted the bug/reference-storage-definition branch January 29, 2024 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:bug A bug in the code. Does not apply to documentation, specs, etc. kind:regression Something that used to correctly work but no longer works topic:compiler:semantic

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crystal 1.11.0 cannot build older Crystal stdlib

2 participants