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

switch == invocation #450

Closed
DartBot opened this issue Nov 15, 2011 · 4 comments
Closed

switch == invocation #450

DartBot opened this issue Nov 15, 2011 · 4 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).

Comments

@DartBot
Copy link

DartBot commented Nov 15, 2011

This issue was originally filed by kresten.kra...@gmail.com


When doing

   switch(v) { case e: ... }

The spec says that it tests v==e,

  the vm does e.operator ==(v)
  the frog compiles it to JS: "switch(v) { case e: ... }"

Neither of which correspond to the spec. Which is right?

Attached test case tests the spec semantics.


Attachment:
SwitchEqualsTest.dart (826 Bytes)

@floitschG
Copy link
Contributor

I'll let Gilad be the final judge on this, but our intention was e == v (i.e. the VM behavior). This gives more predictable behavior and can be optimized more easily.


Added Area-Language, Triaged labels.

@DartBot
Copy link
Author

DartBot commented Nov 15, 2011

This comment was originally written by kresten...@gmail.com


For what it is worth, It seems that v==e would have (potentially) better performance, because the virtual method '==' can be extracted once, and then applied repeatedly without the vtable indirection.

@floitschG
Copy link
Contributor

But the type of e is almost always known at compilation time (in most cases it's a literal).
For example:
switch (v) {
  case 1: ...
  case 2: ...
  case 3: ...
  ...
}

This could be efficiently compiled to a jump-table or a tree after first checking that the input is a number. (In the case of a double a little bit more trickery is necessary).
If the ==operator is invoked on v, then the compiler doesn't have any information and must run through each case.

@gbracha
Copy link
Contributor

gbracha commented Dec 14, 2011

Fixed in spec version 0.07 to match VM behavior, which was desired intent.


Set owner to @gbracha.
Added Done label.

@DartBot DartBot added Type-Defect area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Dec 14, 2011
copybara-service bot pushed a commit that referenced this issue Sep 21, 2022
Changes:
```
> git log --format="%C(auto) %h %s" 32a9450..87e4c68
 https://dart.googlesource.com/markdown.git/+/87e4c68 Bump to 6.0.1 (#462)
 https://dart.googlesource.com/markdown.git/+/37305cf Add deprecated accessors for indicatorForUncheckedCheckBox and indicatorForCheckedCheckBox (#459)
 https://dart.googlesource.com/markdown.git/+/2e5e347 lint cleanup (#456)
 https://dart.googlesource.com/markdown.git/+/a0b5a05 example: small tweak to example – add Dart code (#455)
 https://dart.googlesource.com/markdown.git/+/de32a69 visitText to use textContent getter so subclassing Text class works correctly. (#431)
 https://dart.googlesource.com/markdown.git/+/8247955 Rewrite checkbox(task list) extension (#450)
 https://dart.googlesource.com/markdown.git/+/a602760 Fix crash with mixed checkbox lists (#449)

```

Diff: https://dart.googlesource.com/markdown.git/+/32a94505ded3863b82310b86344a003a19c00341~..87e4c689342d5bbaa84ba2999abf0bff503979be/
Change-Id: I92cf05fe6057e1b3eda8da09fc4eac4f67dd47ab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260441
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Devon Carew <devoncarew@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).
Projects
None yet
Development

No branches or pull requests

4 participants