Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discourage definition of custom primitive types #35526

Merged
merged 2 commits into from
Apr 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions doc/src/manual/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ of function arguments that are containers of abstract types; see [Performance Ti

## Primitive Types

!!! warning
It is almost always preferable to wrap an existing primitive type in a new
composite type than to define your own primitive type.

This functionality exists to allow Julia to bootstrap the standard primitive
types that LLVM supports. Once they are defined, there is very little reason
to define more.

A primitive type is a concrete type whose data consists of plain old bits. Classic examples of primitive
types are integers and floating-point values. Unlike most languages, Julia lets you declare your
own primitive types, rather than providing only a fixed set of built-in ones. In fact, the standard
Expand Down Expand Up @@ -273,8 +281,9 @@ a name. A primitive type can optionally be declared to be a subtype of some supe
is omitted, then the type defaults to having `Any` as its immediate supertype. The declaration
of [`Bool`](@ref) above therefore means that a boolean value takes eight bits to store, and has
[`Integer`](@ref) as its immediate supertype. Currently, only sizes that are multiples of
8 bits are supported. Therefore, boolean values, although they really need just a single bit,
cannot be declared to be any smaller than eight bits.
8 bits are supported and you are likely to experience LLVM bugs with sizes other than those used above.
Therefore, boolean values, although they really need just a single bit, cannot be declared to be any
smaller than eight bits.

The types [`Bool`](@ref), [`Int8`](@ref) and [`UInt8`](@ref) all have identical representations:
they are eight-bit chunks of memory. Since Julia's type system is nominative, however, they
Expand Down