Skip to content

Documentation: Remove warning that nonstandard primitive type sizes may reveal LLVM bugs #58262

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PatrickHaecker
Copy link
Contributor

Only primitive types which are a multiple of 8 bits in size can be constructed. Therefore, the documentation should not speculate about possible bugs in other non-reachable cases.

Additionally, it's not clear whether these LLVM bugs still exist now that C allows all integers sizes.

Only primitive types which are a multiple of 8 bits in size can be constructed. Therefore, the documentation should not speculate about possible bugs in other non-reachable cases.

Additionally, it's not clear whether these LLVM bugs still exist now that C allows all integers sizes.
@oscardssmith
Copy link
Member

It would be pretty nice if we could enable support for arbitrary size primitive types. LLVM should be able to do so now that C Rust and Zig all support it.

@PatrickHaecker
Copy link
Contributor Author

PatrickHaecker commented Apr 29, 2025

Yes, this would be nice, but unfortunately out-of-scope for this PR.

Arbitrary bit sized primitives need at least two large changes to be really useful (each worth at least one separate PR):

  • switching all the size logic to not only account bytes, but allow for accounting bits – this is not only a huge change, but might make things slower and/or remove support for very large sizes
  • packing fields closer than what C does, because otherwise padding typically makes all potential space savings void, e.g. a struct consisting of an Int24 and an Int8 results in a 64 bit field with the C memory layout which Julia follows.

I am currently working on two packages which would mostly circumvent these issues. However, I need to clarify whether we'll open-source them.

@inkydragon inkydragon added docs This change adds or pertains to documentation types and dispatch Types, subtyping and method dispatch labels Apr 29, 2025
Copy link
Member

@LilithHafner LilithHafner left a comment

Choose a reason for hiding this comment

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

"Sizes used above" refers to 2 .^ (3:7), so the clause this PR removes isn't about multiples of 8 bits but about sizes that are larger or not powers of 2.

An accurate title for this PR would be "Remove warning that nonstandard primitive type sizes may reveal LLVM bugs"

@PatrickHaecker
Copy link
Contributor Author

Yes, this would be nice, but unfortunately out-of-scope for this PR.

Maybe I was too fast. Supporting arbitrary sized primitives which have a byte-sized sizeof might actually be possible within the scope of this PR (I have not evaluated this). It would mean that there would be no space savings at all and all we would get would be the modular arithmetic.

It would open a can of worms for discussions about how widen should work and whether all the types need to be defined by the user and what to do about signed when only the unsigned type is defined, but at least it would be a step in the direction of implementing them in Base. Would that be seen as useful?

This could make one of the two mentioned packages obsolete in the long run.

@PatrickHaecker PatrickHaecker changed the title Documentation: primitive type needs multiple of 8 bits Documentation: Remove warning that nonstandard primitive type sizes may reveal LLVM bugs Apr 29, 2025
@LilithHafner
Copy link
Member

Is this not already supported?

julia> primitive type T 24 end

julia> sizeof(T)
3

@oscardssmith
Copy link
Member

What we're talking about here is primitive type T 23 end

@@ -301,7 +301,7 @@ 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 and you are likely to experience LLVM bugs with sizes other than those used above.
8 bits are supported.
Copy link
Member

Choose a reason for hiding this comment

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

As @LilithHafner already pointed out, the removed sentence did not refer to the "multiples of 8 bits" but rather to "sizes [...] used above", i.e. "8, 16, 32, 64, 128"

So the question then is: we sure that e.g. 24 or 48 work fine now and there are no LLVM bugs to be encountered? Then removing this sentence makes sense -- but I'd feel better about that if there were some actual tests in the test suite exercising that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BitIntegers.jl's test suite covers 24, 200, 256, 512 and 1024 bits with more than 500 lines of test files.

We are also using non-power-of-two byte sizes in the company I work for and do not have observed a single LLVM bug.

C, Rust and Zig should use the same LLVM code paths.

Proving the absence of bugs is hard. I have the feeling that we treat this differently compared to what we normally do: Normally we assume that LLVM works correctly and we normally do not mention bugs in other software we use. Shouldn't we have proof of bugs if we say so?

Copy link
Member

Choose a reason for hiding this comment

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

I have the feeling that we treat this differently compared to what we normally do

I think this is just an instance of once bitten, twice shy. We know LLVM used to have a bunch of bugs here. That said, given BitIntegers tests, I think this is good to go.

Copy link
Member

@rfourquet rfourquet left a comment

Choose a reason for hiding this comment

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

The deleted comment used to be true, but I'm not aware of current LLVM (or Julia) bugs with these primitive types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants