mojo
mojo copied to clipboard
[mojo-stdlib] Added fn to normalize index calculation
Fixes #2251
@JoeLoser @soraros I am facing this issue right now after rebasing with nightly.
❯ ./stdlib/scripts/run-tests.sh
Creating build directory for building the stdlib running the tests in.
Packaging up the Standard Library.
Included from /Users/kaushalphulgirkar/Documents/Projects/mojo/stdlib/src/collections/__init__.mojo:1:
/Users/kaushalphulgirkar/Documents/Projects/mojo/stdlib/src/collections/list.mojo:573:39: error: invalid initialization: could not deduce parameter 'type' of parent struct 'Reference'
var normalized_idx = Reference(self)._normalize_index(i)
~~~~~~~~~^~~~~~
/Users/kaushalphulgirkar/Documents/Projects/mojo/stdlib/src/__init__.mojo:1:1: note: struct declared here
# ===----------------------------------------------------------------------=== #
^
Included from /Users/kaushalphulgirkar/Documents/Projects/mojo/stdlib/src/memory/__init__.mojo:1:
/Users/kaushalphulgirkar/Documents/Projects/mojo/stdlib/src/memory/reference.mojo:222:8: note: function declared here
fn __init__(inout self, value: Self._mlir_type):
^
mojo: error: failed to parse the provided Mojo source module
Not able to figure how to exactly fix this. Any suggestions? Did we change the Reference initializations?
Hi @StandinKP, indeed you are right :) there was a change with how Reference works right now, see https://github.com/modularml/mojo/commit/0fe4cb7c9610d0c9623f5b0becd2d9af94835b7c
I think that in your case, you don't need to do Reference(self)
since self
is already a reference. The error message from the compiler is not very clear. Let's hope it will get better in the future!
Makes sense. Thanks @gabrieldemarmiesse
@gabrieldemarmiesse if I use self[]._normalize_index(i) it gives a very nasty error and crashes all the test suite trying to figure out this but if you have any idea let me know Thanks
@soraros can you provide some guidance here? Thanks
@StandinKP I think we should merge https://github.com/modularml/mojo/pull/2677 first and then you can open one pull request per method to change. This will ensure the easy changes will be merged to nightly quickly and the harder changes (I know there are some out of bounds bugs in the tests that you will hit) can be merged afterwards. What do you think?
Closing as this is now implemented at https://github.com/modularml/mojo/blob/3cfdd29453d1bddd6d6dbde5fd13c3cf64eff825/stdlib/src/collections/_index_normalization.mojo#L48. Thanks for pushing on this @StandinKP and @gabrieldemarmiesse!