Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Allow table.copy between tables with different index types#58

Merged
sbc100 merged 2 commits intomainfrom
mixed_copy
May 24, 2024
Merged

Allow table.copy between tables with different index types#58
sbc100 merged 2 commits intomainfrom
mixed_copy

Conversation

@sbc100
Copy link
Member

@sbc100 sbc100 commented May 24, 2024

See #7 See #6

@sbc100 sbc100 changed the title Allow table.copy between tables with different index types. NFC Allow table.copy between tables with different index types May 24, 2024
Copy link
Member

@rossberg rossberg left a comment

Choose a reason for hiding this comment

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

LGTM modulo comment

| ExternGlobalType gt1, ExternGlobalType gt2 -> match_global_type gt1 gt2
| _, _ -> false

let min_index_type it1 it2 =
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this function is needed, you ought to be able to just use OCaml's polymorphic min function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting. That does seem to work.

I though I32IndexType and I64IndexType were just essentially enum values that make up the index_type type. How does ocaml know how to compile them in functions like min?

Copy link
Member

Choose a reason for hiding this comment

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

OCaml uses a uniform representation, so can have a single polymorphic implementation for an operator like <= that works for arbitrary values. Though here the operand type is monomorphic and compiled to int, so the compiler probably specialises that to an int comparison after inlining min.

Copy link
Member Author

Choose a reason for hiding this comment

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

But I don't see I32IndexType and I64IndexType defined as integer constants anywhere. I must be missing something obvious here.. Is ocaml simply assigned numbers to them like an enum in C?

Copy link
Member

Choose a reason for hiding this comment

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

It compiles them to numbers in order of appearance. But unlike in C that's just an implementation detail and not observable, only their order is.

@sbc100 sbc100 merged commit b99ab2d into main May 24, 2024
@sbc100 sbc100 deleted the mixed_copy branch May 24, 2024 18:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants