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

Implement Nat.length_nat as an external primitive #35

Merged
merged 1 commit into from
Nov 5, 2023

Conversation

vouillon
Copy link
Member

The current implementation of length_nat really depends on the representation of nats.
There is a hack to make it work with Js_of_ocaml, but it is not possible to do the same thing for Wasm_of_ocaml.
Implementing this function as an external primitive would resolve this issue and should not have much of a performance impact.

@xavierleroy
Copy link
Contributor

(Note to Github Actions experts: the CI looks broken.)

Well spotted, thanks for the report. I was surprised that length_nat is defined in the C stubs but not used. I guess that's because the Obj-based implementation is faster when compiled with ocamlopt. But, as you say, it may not have much of a performance impact. Still, what about declaring length_nat as a "noalloc" primitive? This will remove some of the overhead.

(Note to self and other maintainers of Num: many other C primitives in Nat could be declared "noalloc".)

@dra27
Copy link
Member

dra27 commented Oct 26, 2023

(ACK to the CI problem - it's being looked at)

@xavierleroy
Copy link
Contributor

@vouillon : please add a "noalloc" attribute, and then I'll be happy to merge.

@vouillon
Copy link
Member Author

vouillon commented Nov 4, 2023

@xavierleroy I have added the "noalloc" attribute.

@xavierleroy xavierleroy merged commit 80bb9b7 into ocaml:master Nov 5, 2023
2 of 10 checks passed
@xavierleroy
Copy link
Contributor

Thanks! Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants