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

refactor: clarify uppercase exotic ident path #6779

Merged
merged 3 commits into from
May 30, 2024

Conversation

cometkim
Copy link
Member

@cometkim cometkim commented May 25, 2024

This could improves perf in theory, but actually a bit slower... IDK why

It is a slightly bit faster, but almost within the margin so... just for cleanup
(context: #6658 (comment))

@cometkim cometkim changed the title refactor: make uppercase exotic ident path clear refactor: clarify uppercase exotic ident path May 25, 2024
@cometkim cometkim force-pushed the perf-printidentlike branch 2 times, most recently from 5214d54 to a3f202c Compare May 26, 2024 13:41
@cometkim cometkim marked this pull request as ready for review May 26, 2024 13:41
@cometkim
Copy link
Member Author

Does it look better to you? @cristianoc

Copy link
Member

@cknitt cknitt left a comment

Choose a reason for hiding this comment

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

LGTM. @IwanKaramazow could you also have a look?

| 'A' .. 'Z' when allowUident -> loop (i + 1)
| 'a' .. 'z' | '_' -> loop (i + 1)
| '-' when allowHyphen -> loop (i + 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this line removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh thanks, I never intended to do this. (but tests are fine?)

Copy link
Member Author

@cometkim cometkim May 26, 2024

Choose a reason for hiding this comment

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

But, it seems we don't actually need this line because the scanner never makes an unwrapped ident with - as the first char I guess

match classifyIdentContent ~allowUident:true txt with
| UppercaseExoticIdent ->
Copy link
Collaborator

Choose a reason for hiding this comment

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

This cases unwraps then re-wraps the ident.
What's the net effect? Just to remove \ ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes it does.

Maybe we can replace it to

      let len = String.length txt in
      Doc.text ((String.sub [@doesNotRaise]) txt 1 (len - 1))

Copy link
Collaborator

@cristianoc cristianoc May 27, 2024

Choose a reason for hiding this comment

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

Either that, or add a comment that that's the effect, is fine.
Just, the current code can be a bit confusing without additional explanation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Btw, I don't know if it is possible, but one could try to classify the ident content already at scanning time, instead of print time.
And any id that is classified to be exotic could be represented internally as "id".
So the printer would need to do no special work.
And uppercase exotic ids would just be exotic ids that happen to start with capital letter -- nothing special.

Copy link
Member Author

Choose a reason for hiding this comment

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

I had tried it within a previous PR to get as much work done from the scanner as possible, but it ultimately failed. I have no other ideas on how to do it while still using the existing parsetree as is. What do you mean "id"? Is there another place to mark it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually never mind, the scanner does not have the context that the printer has, such as when an uppercase identified is allowed.
Good to go for me.

Copy link
Collaborator

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

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

Left a comment about a possible different approach: https://github.com/rescript-lang/rescript-compiler/pull/6779/files#r1615712136

But I don't know if that would work, and is not for this PR anyway.
To me, this is good to go.

@cristianoc
Copy link
Collaborator

There are a few conflicts from the camelCase to snake_case PR. Once resolved, this can be merged.

@cometkim cometkim force-pushed the perf-printidentlike branch from a9a8372 to 636f978 Compare May 28, 2024 22:52
@cometkim cometkim force-pushed the perf-printidentlike branch from 636f978 to b0c6f1e Compare May 29, 2024 20:10
@cknitt
Copy link
Member

cknitt commented May 30, 2024

@cometkim Could you add a CHANGELOG entry?

@cometkim
Copy link
Member Author

for this internal refactor...?

@cknitt
Copy link
Member

cknitt commented May 30, 2024

We do have an "Internal" section in the CHANGELOG.
I agree this is not visible or important to the user.
But maybe we can put something there for the sake of completeness?

@cknitt
Copy link
Member

cknitt commented May 30, 2024

Ok, never mind, I am currently cleaning up the CHANGELOG anyway and adding some missing stuff, will do that myself.

@cknitt cknitt merged commit 551a172 into rescript-lang:master May 30, 2024
19 checks passed
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