-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[stdlib] Fix allow immutable UnsafePointer
and adjust .unsafe_ptr()
methods
#3734
base: nightly
Are you sure you want to change the base?
[stdlib] Fix allow immutable UnsafePointer
and adjust .unsafe_ptr()
methods
#3734
Conversation
Signed-off-by: martinvuyk <martin.vuyklop@gmail.com>
Signed-off-by: martinvuyk <martin.vuyklop@gmail.com>
Signed-off-by: martinvuyk <martin.vuyklop@gmail.com>
Signed-off-by: martinvuyk <martin.vuyklop@gmail.com>
Signed-off-by: martinvuyk <martin.vuyklop@gmail.com>
Signed-off-by: martinvuyk <martin.vuyklop@gmail.com>
Signed-off-by: martinvuyk <martin.vuyklop@gmail.com>
Signed-off-by: martinvuyk <martin.vuyklop@gmail.com>
@JoeLoser All the tests are passing but the packaging of |
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.
This is so exciting to see coming together! I appreciate you tackling this! 🎉
@@ -290,6 +290,12 @@ struct _lit_mut_cast[ | |||
] | |||
|
|||
|
|||
struct _is_mutable_origin[ |
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.
Question Can you help me understand why this is needed? You should be able to directly access the is_mutable
from the call sites without any issues.
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.
Not on type signatures where all you have is __origin_of()
and you want to extract the mutability of that:
@staticmethod
@always_inline("nodebug")
fn address_of(
ref [_, address_space._value.value]arg: type
) -> UnsafePointer[
type,
address_space,
is_mutable = _is_mutable_origin[__origin_of(arg)].result,
origin = __origin_of(arg),
] as result:
"""Gets the address of the argument.
Args:
arg: The value to get the address of.
Returns:
An UnsafePointer which contains the address of the argument.
"""
return __type_of(result)(
__mlir_op.`lit.ref.to_pointer`(__get_mvalue_as_litref(arg))
)
Though if there is a cleaner way to extract an attribute from __origin_of()
I'm all ears
Signed-off-by: martinvuyk <martin.vuyklop@gmail.com>
…ble-unsafepointer
@@ -624,6 +628,7 @@ struct UnsafePointer[ | |||
offset: The offset to store to. | |||
val: The value to store. | |||
""" | |||
constrained[is_mutable, _must_be_mut_err]() |
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.
Can we turn these into conditional conformance?
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.
Theoretically the compiler won't even let you mutate the origin. I added them for convenience so that users get a clear error message. Conditional Conformance doesn't give you that, only a cryptic error that some parameters can't be inferred.
Fix allow immutable
UnsafePointer
and adjust.unsafe_ptr()
methods. Fixes MSTDL-956