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

Add some docs to stblib Symbol #7336

Merged
merged 9 commits into from
Mar 17, 2025
Merged

Conversation

jderochervlk
Copy link
Contributor

This adds a .resi file for Stdlib_Symbol with documentation for most of the common uses for Symbols. I added a description and toString to the bindings.

A good chunk of what Symbols are used for aren't really applicable or possible with ReScript, such as the static properties. I'm not sure if there is value in including those bindings in the stdlib, but for now I just omitted documentation.

Copy link
Contributor

@tsnobip tsnobip left a comment

Choose a reason for hiding this comment

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

thanks for your PR! I think you have to add Stdlib_Symbol.cmti/resi to packages/artifacts.txt to make the tests pass.

While you're there, I'd also convert the documentations to docstring tests, that'd make it even more useful!

Comment on lines 51 to 52
Console.log(Symbol.keyFor(globalSym))
// Expected output: "sym1"
Copy link
Contributor

Choose a reason for hiding this comment

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

Make those a test instead of just documenting it, it'd be even more useful!

Suggested change
Console.log(Symbol.keyFor(globalSym))
// Expected output: "sym1"
Symbol.keyFor(globalSym)->assetEqual("sym1")

@jderochervlk jderochervlk requested a review from tsnobip March 14, 2025 15:30
Copy link
Contributor

@tsnobip tsnobip left a comment

Choose a reason for hiding this comment

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

two typos to fix and we should be good to go :)

## Examples

```rescript
Symbol.make("sym1")->assetEqual("sym1")
Copy link
Contributor

Choose a reason for hiding this comment

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

my bad it's assertEqual

Suggested change
Symbol.make("sym1")->assetEqual("sym1")
Symbol.make("sym1")->assertEqual("sym1")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

## Examples

```rescript
Symbol.getFor("sym1")->assetEqual(Symbol.getFor("sym1"))
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

```
*/
@val
external getFor: string => t = "Symbol.for"
Copy link
Contributor

Choose a reason for hiding this comment

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

you also forgot to update the interface file, and while we're there, I'd also use @scope for these bindings, which is cleaner IMO:

Suggested change
external getFor: string => t = "Symbol.for"
@scope("Symbol")
external getFor: string => option<t> = "for"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@tsnobip
Copy link
Contributor

tsnobip commented Mar 14, 2025

@jderochervlk tests fail, did you try to run them locally?

make lib
make tests

@jderochervlk
Copy link
Contributor Author

make tests

I'm trying to get things to run locally, but the setup docs seem to leave me in a place where things don't work.

➜  rescript git:(symbol) make lib      
cargo build --manifest-path rewatch/Cargo.toml
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s
cp rewatch/target/debug/rewatch rewatch
./scripts/copyExes.js -rewatch
dune build
./scripts/copyExes.js -compiler           
./scripts/buildRuntime.sh
Cleaning... 941 files.
>>>> Start compiling
Dependency Finished
rescript: [678/678] Belt.cmj
>>>> Finish compiling 1030 mseconds
./scripts/prebuilt.js
Version check: package.json: 12.0 vs ABI: 12.0
➜  rescript git:(symbol) make tests    
make: Nothing to be done for 'tests'.
➜  rescript git:(symbol) 

@jderochervlk jderochervlk requested a review from tsnobip March 14, 2025 16:31
@tsnobip
Copy link
Contributor

tsnobip commented Mar 14, 2025

make tests

I'm trying to get things to run locally, but the setup docs seem to leave me in a place where things don't work.

➜  rescript git:(symbol) make lib      
cargo build --manifest-path rewatch/Cargo.toml
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s
cp rewatch/target/debug/rewatch rewatch
./scripts/copyExes.js -rewatch
dune build
./scripts/copyExes.js -compiler           
./scripts/buildRuntime.sh
Cleaning... 941 files.
>>>> Start compiling
Dependency Finished
rescript: [678/678] Belt.cmj
>>>> Finish compiling 1030 mseconds
./scripts/prebuilt.js
Version check: package.json: 12.0 vs ABI: 12.0
➜  rescript git:(symbol) make tests    
make: Nothing to be done for 'tests'.
➜  rescript git:(symbol) 

sorry @jderochervlk I meant

make test

@jderochervlk
Copy link
Contributor Author

sorry @jderochervlk I meant

make test

I'm getting a permissions issue.

➜  rescript git:(symbol) make test
cargo build --manifest-path rewatch/Cargo.toml
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.07s
cp rewatch/target/debug/rewatch rewatch
./scripts/copyExes.js -rewatch
dune build
./scripts/copyExes.js -compiler           
./scripts/buildRuntime.sh
Cleaning... 941 files.
>>>> Start compiling
Dependency Finished
rescript: [678/678] Belt.cmj
>>>> Finish compiling 1538 mseconds
./scripts/prebuilt.js
Version check: package.json: 12.0 vs ABI: 12.0
node scripts/test.js -all
Checking OCaml code formatting...
✅ OCaml code formatting ok.             
Checking ReScript code formatting...
✅ ReScript code formatting ok.
Biome format check

> rescript@12.0.0-alpha.10 checkFormat
> biome format --changed --no-errors-on-unmatched .

sh: 1: biome: Permission denied
node:internal/errors:865
  const err = new Error(message);
              ^

Error: Command failed: bash scripts/format_check.sh
    at checkExecSyncError (node:child_process:890:11)
    at Object.execSync (node:child_process:962:15)
    at runTests (/home/josh/Dev/rescript/scripts/test.js:48:8)
    at Object.<anonymous> (/home/josh/Dev/rescript/scripts/test.js:186:1)
    at Module._compile (node:internal/modules/cjs/loader:1364:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
    at Module.load (node:internal/modules/cjs/loader:1203:32)
    at Module._load (node:internal/modules/cjs/loader:1019:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12) {
  status: 126,
  signal: null,
  output: [ null, null, null ],
  pid: 25486,
  stdout: null,
  stderr: null
}

Node.js v18.20.7
make: *** [Makefile:33: test] Error 1

@tsnobip
Copy link
Contributor

tsnobip commented Mar 14, 2025

@jderochervlk try deleting node_modules and install again.

@jderochervlk
Copy link
Contributor Author

@jderochervlk try deleting node_modules and install again.

Weird, that did the trick, thanks!

@jderochervlk
Copy link
Contributor Author

Tests are now passing locally.

Copy link
Contributor

@tsnobip tsnobip left a comment

Choose a reason for hiding this comment

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

Looks good to me now :)

@tsnobip tsnobip merged commit 67b3870 into rescript-lang:master Mar 17, 2025
20 checks passed
@jderochervlk jderochervlk deleted the symbol branch March 17, 2025 14:52
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.

2 participants