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

Corrected impl of typeof #396

Merged
merged 1 commit into from
May 21, 2020
Merged

Conversation

JavedNissar
Copy link
Contributor

@JavedNissar JavedNissar commented May 13, 2020

Corrected impl of typeof to follow specification by using relevant
AST node directly instead of using UnaryOp

This Pull Request fixes #359.

It changes the following:

  • Adjusts implementation of TypeOf to use Node::TypeOf instead of Node::UnaryOp

@JavedNissar
Copy link
Contributor Author

Does this code look alright? I ask because I'm encountering the following bizarre compile error and I'm wondering if there's an alternative route I can pursue:

error: internal compiler error: src/librustc/ty/steal.rs:34: attempted to read from stolen value

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:875:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.43.0 (4fb7144ed 2020-04-20) running on x86_64-apple-darwin

note: compiler flags: -C debuginfo=2 -C incremental --crate-type cdylib --crate-type lib

note: some of the compiler flags provided by cargo are hidden

thread '<unnamed>' panicked at 'assertion failed: `(left == right)`
  left: `LLVMing`,
 right: `Codegenning`', <::std::macros::panic macros>:5:6

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.43.0 (4fb7144ed 2020-04-20) running on x86_64-apple-darwin

note: compiler flags: -C debuginfo=2 -C incremental --crate-type cdylib --crate-type lib

note: some of the compiler flags provided by cargo are hidden

error: aborting due to previous error

error: could not compile `Boa`.

@Razican
Copy link
Member

Razican commented May 13, 2020

That is in fact a bug inside the Rust compiler. You should report it, as the error says. You could also try to upgrade to the latest stable version, to see if they solved the issue.

Copy link
Member

@Razican Razican left a comment

Choose a reason for hiding this comment

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

Hi! thanks for the contribution. After some discussion in #359, it seems that it's best if we implement this as a unary expression and remove the Node, then move the exec part to the unary expression execution.

We should also add tests to this.

@Razican Razican added enhancement New feature or request bug Something isn't working parser Issues surrounding the parser labels May 13, 2020
@jasonwilliams
Copy link
Member

jasonwilliams commented May 13, 2020

Hi! thanks for the contribution. After some discussion in #359, it seems that it's best if we implement this as a unary expression and remove the Node, then move the exec part to the unary expression execution.

We should also add tests to this.

Yeah sorry about that its my fault i was under the impression it was a Node expression and not a unary one.

@JavedNissar JavedNissar force-pushed the type-of-correction branch 7 times, most recently from c502fc6 to 08760f2 Compare May 14, 2020 03:48
Copy link
Member

@Razican Razican left a comment

Choose a reason for hiding this comment

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

Very nice indeed! This is almost ready to be merged, just give a look to my comments :)

"object"
}
}
}),
_ => unimplemented!(),
Copy link
Member

Choose a reason for hiding this comment

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

It seems that we already implemented all variants, so this is unreachable :D

Suggested change
_ => unimplemented!(),

boa/src/exec/tests.rs Outdated Show resolved Hide resolved
boa/src/syntax/ast/node.rs Outdated Show resolved Hide resolved
@Razican Razican added this to the v0.8.0 milestone May 14, 2020
@jasonwilliams jasonwilliams modified the milestones: v0.8.0, v0.9.0 May 14, 2020
Copy link
Member

@Razican Razican left a comment

Choose a reason for hiding this comment

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

This is ready to be merged from my side :)

Copy link
Member

@HalidOdat HalidOdat 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 too. Check my comment it's mostly for my understanding.

Comment on lines 426 to 440
UnaryOp::TypeOf => Value::from(match v_a.data() {
ValueData::Undefined => "undefined",
ValueData::Symbol(_) => "symbol",
ValueData::Null => "object",
ValueData::Boolean(_) => "boolean",
ValueData::Rational(_) | ValueData::Integer(_) => "number",
ValueData::String(_) => "string",
ValueData::Object(ref o) => {
if o.deref().borrow().is_callable() {
"function"
} else {
"object"
}
}
}),
Copy link
Member

@HalidOdat HalidOdat May 15, 2020

Choose a reason for hiding this comment

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

Why do we do this here when we can just call value.get_type() which returns a &'static str, it seems like were duplicating code.

Copy link
Member

Choose a reason for hiding this comment

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

I think i mentioned in the original issue that we don't need both jasonwilliams#359 (comment)

Copy link
Member

@HalidOdat HalidOdat left a comment

Choose a reason for hiding this comment

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

I think it's best to keep the get_type function in value and just call it from exec. there are a lot of places were get_type is called.

Copy link
Member

@jasonwilliams jasonwilliams left a comment

Choose a reason for hiding this comment

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

as @HalidOdat said maybe we can just call get_type() from UnaryOf::TypeOf

Copy link
Member

@Razican Razican left a comment

Choose a reason for hiding this comment

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

Hi, it seems it's almost ready, just one test failing. Could you check why? I also added a small comment to see if we can improve testing coverage and documentation for null comparison.

Comment on lines 21 to 29
//Null has to be handled specially because "typeof null" returns object and if we managed
//this without a special case we would compare self and other as if they were actually
//objects which unfortunately fails
if self.is_null() {
return true;
}

Copy link
Member

Choose a reason for hiding this comment

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

Can we add a test for this, and a link to the spec?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't boa/src/builtins/value/tests.rs:58 already a test for this?

Copy link
Member

@Razican Razican May 21, 2020

Choose a reason for hiding this comment

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

Yes! Perfect, thanks :)

@JavedNissar
Copy link
Contributor Author

I'm having difficulty replicating the errors in CI on my local development environments (Windows and Mac OSX). I'm not entirely sure where to proceed from here so I would love to have some suggestions!

@jasonwilliams
Copy link
Member

I'm having difficulty replicating the errors in CI on my local development environments (Windows and Mac OSX). I'm not entirely sure where to proceed from here so I would love to have some suggestions!

Looks like you've found a regression introduced by my "implement this" change

I will look at this.

@JavedNissar
Copy link
Contributor Author

I'm having difficulty replicating the errors in CI on my local development environments (Windows and Mac OSX). I'm not entirely sure where to proceed from here so I would love to have some suggestions!

Looks like you've found a regression introduced by my "implement this" change

I will look at this.

Thanks!

@jasonwilliams
Copy link
Member

jasonwilliams commented May 20, 2020

Lets see if https://github.com/jasonwilliams/boa/pull/407 passes and ill merge that, String wasn't defaulting to empty when being called as const a = String()

The fact that you made a test for this is great as we may not have captured that before.
Once i merged that you will need to rebase

@jasonwilliams
Copy link
Member

Removed Node::TypeOf, implemented UnaryOp::TypeOf, and added tests
Copy link
Member

@HalidOdat HalidOdat left a comment

Choose a reason for hiding this comment

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

This looks perfect! Thanks for the contribution @restitutororbis :)

Copy link
Member

@Razican Razican left a comment

Choose a reason for hiding this comment

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

This is good to go for me as well :)

@Razican Razican merged commit 29abfd6 into boa-dev:master May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request parser Issues surrounding the parser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeOf failing
4 participants