Skip to content

[Strings] string.eq #4781

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

Merged
merged 6 commits into from
Jul 8, 2022
Merged

[Strings] string.eq #4781

merged 6 commits into from
Jul 8, 2022

Conversation

kripken
Copy link
Member

@kripken kripken commented Jul 8, 2022

I considered maybe making this a shared class with RefEq. They are quite similar. But the internal opcode would need to be something like "compare references" versus "compare data", which seems slightly awkward. Overall the amount of boilerplate per new class is fairly small now, so I lean towards that.

@kripken kripken requested review from tlively and aheejin July 8, 2022 16:02
Copy link
Member

@tlively tlively 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 comments

src/ir/cost.h Outdated
@@ -684,6 +684,10 @@ struct CostAnalyzer : public OverriddenVisitor<CostAnalyzer, CostType> {
CostType visitStringConcat(StringConcat* curr) {
return 10 + visit(curr->left) + visit(curr->right);
}
CostType visitStringEq(StringEq* curr) {
// This assumes strings are interned in the engine.
Copy link
Member

Choose a reason for hiding this comment

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

I would be surprised if all strings were interned! This seems like it should be modeled as being very expensive since it's cost is unbounded.

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 think the VM will intern them if they are used enough, at least in some cases, but I don't really know. JS string implementations are quite flexible. I guess we shouldn't strongly assume anything here, but like with concat, I don't think this can be a problem in general - there is no equivalent code that would be compared to this.

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 adjusted it to 3 (in between 1 and 6 for interned and not), and added a comment.

@kripken kripken merged commit 75d059a into main Jul 8, 2022
@kripken kripken deleted the string.eq branch July 8, 2022 18:42
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