-
Notifications
You must be signed in to change notification settings - Fork 786
[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
[Strings] string.eq #4781
Conversation
There was a problem hiding this 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Co-authored-by: Thomas Lively <[email protected]>
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.