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

Migrate let to const for constants #1253

Open
hackwaly opened this issue Nov 26, 2024 · 5 comments
Open

Migrate let to const for constants #1253

hackwaly opened this issue Nov 26, 2024 · 5 comments
Assignees

Comments

@hackwaly
Copy link
Contributor

No description provided.

@hackwaly hackwaly added the good first issue Good for newcomers label Nov 26, 2024
@Lampese Lampese self-assigned this Nov 29, 2024
@Lampese
Copy link
Collaborator

Lampese commented Nov 29, 2024

Sometimes we may have a need to use a FixedArray as a constant, but it is not allowed now. What should we do about it.

// not allowed
const GDOUBLE_POW5_INV_SPLIT2 : FixedArray[UInt64] = [
  1, 2305843009213693952, 5955668970331000884, 1784059615882449851, 8982663654677661702,
  1380349269358112757, 7286864317269821294, 2135987035920910082, 7005857020398200553,
  1652639921975621497, 17965325103354776697, 1278668206209430417, 8928596168509315048,
  1978643211784836272, 10075671573058298858, 1530901034580419511, 597001226353042382,
  1184477304306571148, 1527430471115325346, 1832889850782397517, 12533209867169019542,
  1418129833677084982, 5577825024675947042, 2194449627517475473, 11006974540203867551,
  1697873161311732311, 10313493231639821582, 1313665730009899186, 12701016819766672773,
  2032799256770390445,
]

@Lampese
Copy link
Collaborator

Lampese commented Nov 29, 2024

The following behavior is also not allowed, but I believe that compile time calculations can be performed on the output of pure functions

pub const NOT_A_NUMBER : Double = 0x7FF8000000000001L.reinterpret_as_double()

@peter-jerry-ye
Copy link
Collaborator

Sometimes we may have a need to use a FixedArray as a constant, but it is not allowed now. What should we do about it.

// not allowed
const GDOUBLE_POW5_INV_SPLIT2 : FixedArray[UInt64] = [
]

This should be allowed as this is defined in https://github.com/WebAssembly/gc/blob/main/proposals/gc/MVP.md#constant-expressions @Guest0x0 @Yu-zh ?

@Yu-zh
Copy link
Collaborator

Yu-zh commented Dec 4, 2024

Sometimes we may have a need to use a FixedArray as a constant, but it is not allowed now.

We should introduce a new primitive type like ReadOnlyFixedArray in the compiler for this.

This should be allowed as this is defined in https://github.com/WebAssembly/gc/blob/main/proposals/gc/MVP.md#constant-expressions @Guest0x0 @Yu-zh ?

This is not relevant. Constant expressions in Wasm is used for initialization of globals. It has no indication on the mutability of the data.

@Lampese
Copy link
Collaborator

Lampese commented Dec 5, 2024

The following behavior is also not allowed, but I believe that compile time calculations can be performed on the output of pure functions

pub const NOT_A_NUMBER : Double = 0x7FF8000000000001L.reinterpret_as_double()

I thought about it again, and it may be quite demanding to achieve such a situation, but I don't know if anyone has any effective solutions?

Another small issue is that we have many pub constants that may not be capitalized, but now our constants require capitalization, which may result in a large number of API migrations. Should we bear this cost?

cc @peter-jerry-ye @Yu-zh @hackwaly

@hackwaly hackwaly removed the good first issue Good for newcomers label Dec 11, 2024
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

No branches or pull requests

4 participants