-
Notifications
You must be signed in to change notification settings - Fork 83
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
Added Cmm_helpers.Scalar_type #3423
base: main
Are you sure you want to change the base?
Conversation
Selection Change CheckThis PR modifies the original selection pass (targeting Mach). |
16f1b23
to
443a81c
Compare
39828c2
to
ae1f27d
Compare
443a81c
to
2f5d60b
Compare
ae1f27d
to
d4a7719
Compare
1d28ccf
to
e856bc9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I'm confident the conversions are correct. Have you checked that this doesn't hurt codegen for static casts? We don't have a good way to test that automatically, but spot-checking a few things seems sufficient.
I noticed that the generated |
Should we e.g. examine the actual generated assembly for a few executables before and after this change? I think probably yes. |
baa577d
to
bb2d88e
Compare
let nativeint = Untagged Integer.nativeint | ||
|
||
let[@inline] untagged = function | ||
| Untagged t -> t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there legitimate uses where we try and untag an already untagged integral type ? That seems like a bug to me at first glance, so unless we have some actual uses cases (and they are correct), we should probably raise a fatal_error here since this may indicate a bug elsewhere ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is so that you can cast to the untagged representation of a type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not for asserting that we know a type is untagged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is so that you can cast to the untagged representation of a type
When do we legitimately need to "cast to the untagged representation of a type" when that type is already untagged ?
Put another way: I'm arguing that this line should read Untagged _ -> assert false
and that this assert should not trigger since untagging something that is already untagged has no clearly defined semantics and actually indicates a bug/error. Can you give a detailed explanation of at least one case where that line of code is effectively used, and why do we need it / why the code is better (or simpler) that way ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I read, the only use of that function is in cast_cast_without_losing_information
, where the actual information that is of interest is the number of bits actually used to store information, so I think it should be better to rearrange the code a bit to not need this function (and instead use a function that returns the actually use-for-information bit-width for instance).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(C.Scalar_type.Integral.untagged kind) |
it's useful b/c you can static_cast or conjugate to untagged kind , and it's just a no-op if the integer is already untagged.
backend/cmm_helpers.ml
Outdated
Misc.fatal_errorf | ||
"static_cast: casting floats to unsigned values is undefined" | ||
| Signed -> | ||
(* we can truncate, but we don't want to promote *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I clarified the comments
Also: there's a CI failure that seems related to this PR: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I wait until you fix the CI failures to review again ?
8a57568
to
5a2037e
Compare
This will be used by a future pr to simplify casting without impacting performance as much
5a2037e
to
8fa9539
Compare
8fa9539
to
6dce5c0
Compare
…ng between integers types of different widths and signedness. This is in preparation for adding unboxed small integer types.
6dce5c0
to
e13ed4b
Compare
Cmm_helpers.Scalar_type
provides utilities for converting between integers types of different widths and signedness. This is in preparation for adding unboxed small integer types.