GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — initial revision of reachability checks by vladima · Pull Request #4788 · microsoft/TypeScript

Conversation

@vladima

@vladima Vladimir Matveev (vladima) commented Sep 14, 2015

Copy link
Copy Markdown
Contributor

this PR supersedes #1287.
Checking unreachable code in the compiler uncovered 2 bugs, both of the same origin:

function foo() {
    return bar; // at this point x cannot be used yet because of TDZ
    let x: number; 
    function bar() {
        if (!x) x = 0;
        return ++x;
    }
}

Currently reachability checks are placed in binder but ultimately I'd like to be separate actions that are executed on the same pass - split walking and processing logic

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vladima
initial revision of reachability checks in binder
b62ef0d
@msftclas Microsoft Contribution License Agreements (msftclas) added the cla-not-required label Sep 14, 2015
@vladima Vladimir Matveev (vladima) mentioned this pull request Sep 14, 2015
Simple control flow analysis #1287
Closed
@basarat

Basarat Ali Syed (basarat) commented Sep 14, 2015

Copy link
Copy Markdown
Contributor

fancy 😎

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

DanielRosenwasser
DanielRosenwasser reviewed Sep 15, 2015
View reviewed changes
Comment thread src/compiler/binder.ts Outdated

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Sep 15, 2015

Copy link
Copy Markdown
Member

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.

Space after switch

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Vladimir Matveev (vladima) added 2 commits September 15, 2015 10:36
@vladima
addressed PR feedback
beb1aa3
@vladima
merge with master
9aeb0f8
yuit
yuit reviewed Sep 16, 2015
View reviewed changes
Comment thread src/compiler/binder.ts Outdated

@yuit Yui (yuit) Sep 16, 2015

Copy link
Copy Markdown
Contributor

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.

use the parameter name 'node' instead

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vladima Vladimir Matveev (vladima) Sep 16, 2015

Copy link
Copy Markdown
Contributor Author

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.

ok

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@adidahiya Adi Dahiya (adidahiya) mentioned this pull request Sep 16, 2015
deprecate no-unreachable once implemented in TS compiler palantir/tslint#661
Closed
Vladimir Matveev (vladima) added 2 commits September 16, 2015 12:43
@vladima
addressed PR feedback
682c14c
@vladima
merge with master
69321a0
yuit
yuit reviewed Sep 16, 2015
View reviewed changes
Comment thread src/compiler/binder.ts Outdated

@yuit Yui (yuit) Sep 16, 2015

Copy link
Copy Markdown
Contributor

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 don't understand reachability of switch-statement. Why being exhaustive prevent post switch to be reachable?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vladima Vladimir Matveev (vladima) Sep 17, 2015

Copy link
Copy Markdown
Contributor Author

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.

discussed offline

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@yuit Yui (yuit) Sep 17, 2015

Copy link
Copy Markdown
Contributor

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.

🍪 🍰

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vladima
merge with master
4711f0e
@jbondc

Jon (jbondc) commented Sep 22, 2015

Copy link
Copy Markdown
Contributor

🍺 is it enabled by default? impact on performance?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vladima

Vladimir Matveev (vladima) commented Oct 14, 2015

Copy link
Copy Markdown
Contributor Author

Anders Hejlsberg (@ahejlsberg) I've addressed your comments, can you please take another look to see if everything looks good from your perspective?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Vladimir Matveev (vladima) added 2 commits October 16, 2015 13:13
@vladima
Merge branch 'master' into reachabilityChecks
7b12617
@vladima
Merge branch 'master' into reachabilityChecks
f9eaed7
@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Oct 20, 2015

Copy link
Copy Markdown
Member

Vladimir Matveev (@vladima) noImplicitReturns doesn't seem to catch the following function:

function foo(x: number) {
    if (x < 0) return 42;

}
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vladima

Vladimir Matveev (vladima) commented Oct 20, 2015

Copy link
Copy Markdown
Contributor Author

Daniel Rosenwasser (@DanielRosenwasser) noImplicitReturns is enabled if return type is specified

function foo(x: number): number {
    if (x < 0) return 42;

}
v2m@v2m-ThinkPad-W520:~/sources/TypeScript$ node built/local/tsc.js test.ts --noImplicitReturns
test.ts(1,26): error TS7030: Not all code paths return a value.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Oct 20, 2015

Copy link
Copy Markdown
Member

Vladimir Matveev (@vladima) yes, I wasn't sure if that was intentional or not. I think that's a little too subtle. I would assume you are more likely to forget a type annotation as you are an explicit return, and the switch is "no implicit returns".

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vladima

Vladimir Matveev (vladima) commented Oct 20, 2015

Copy link
Copy Markdown
Contributor Author

currently implemented behavior is aligned with our existing approach to report errors on missing return or throw only if user explicitly opted in (by using return type annotation). However I do see how it might be subtle especially now it is kind of double opt-in (first via command line switch and second - by explicitly specifying return type) - this behavior can always be adjusted

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vladima
merge with master
f96980d
@alexeagle

Alex Eagle (alexeagle) commented Oct 22, 2015

Copy link
Copy Markdown
Contributor

This is fantastic! We love preventing bugs.

I'm curious if the team has discussed how to classify which static analysis will be included in the compiler, vs. what would be in something like tslint.
Our experience at Google is that optional tooling is underused and much less effective. (we're writing a paper on it which I hope to share soon - cc Eddie Aftandilian (@eaftan)).
As a trivial example, we found a handful of occurrences of a bug like:

if (condition);
  throw new IllegalState();

in Google's code, and this is very easily prevented by disallowing "empty" if statements with no then/else blocks.

Do you imagine adding many more compilerOptions like the new --noImplicitReturns added in this PR?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vladima
make binder singleton, inline bindWithReachabilityChecks
2779352
@vladima

Vladimir Matveev (vladima) commented Oct 22, 2015

Copy link
Copy Markdown
Contributor Author

Anders Hejlsberg (@ahejlsberg) can you please check if your time measurements got better with last commit?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ahejlsberg
ahejlsberg reviewed Oct 22, 2015
View reviewed changes
Comment thread src/compiler/binder.ts Outdated

@ahejlsberg Anders Hejlsberg (ahejlsberg) Oct 22, 2015

Copy link
Copy Markdown
Member

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.

Since we don't remove Debug.assert calls in retail code, this will always perform expensive number-to-string and string allocation/concatenation operations.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vladima Vladimir Matveev (vladima) Oct 22, 2015

Copy link
Copy Markdown
Contributor Author

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.

makes sense, will fix it

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ahejlsberg

Anders Hejlsberg (ahejlsberg) commented Oct 22, 2015

Copy link
Copy Markdown
Member

Vladimir Matveev (@vladima) Just ran my RWC Monaco tests. With the latest changes we're now consistently a little bit faster than 1.6 even with reachability checks. Good stuff.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Vladimir Matveev (vladima) added 3 commits October 22, 2015 09:50
@vladima
defer allocation of error message text in binder
7d09f26
@vladima
merge with master
d2a11b5
@vladima
merge with master
3f11c0b
@ahejlsberg

Anders Hejlsberg (ahejlsberg) commented Nov 2, 2015

Copy link
Copy Markdown
Member

👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Vladimir Matveev (vladima) added a commit that referenced this pull request Nov 2, 2015
@vladima
Merge pull request #4788 from Microsoft/reachabilityChecks
fb15e9c
initial revision of reachability checks
@vladima
Vladimir Matveev (vladima) merged commit fb15e9c into master Nov 2, 2015
@vladima
Vladimir Matveev (vladima) deleted the reachabilityChecks branch November 2, 2015 22:55
Marcus (mjohnsonengr) added a commit to mjohnsonengr/atom-typescript that referenced this pull request Nov 15, 2015
@mjohnsonengr
Added new tsconfig validation for options introduced in microsoft/Typ…
9b043c7
…eScript#4788 (reachability checks)
@mjohnsonengr Marcus (mjohnsonengr) mentioned this pull request Nov 15, 2015
Support new tsconfig options for reachability checks TypeStrong/atom-typescript#725
Merged
@vladima Vladimir Matveev (vladima) mentioned this pull request Nov 25, 2015
Show bind errors in js files #5785
Closed
@mhegazy Mohamed Hegazy (mhegazy) mentioned this pull request Dec 9, 2015
Compiler warnings / errors for common automatic semi-colon insertion (ASI) issues #2575
Closed
@glen-84

Glen (glen-84) commented Jan 18, 2016

Copy link
Copy Markdown

What about the tsconfig.json schema? Shouldn't it be updated?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy Mohamed Hegazy (mhegazy) mentioned this pull request Feb 22, 2016
Suggestion: Control flow analysis #2854
Closed
2 tasks
@aluanhaddad Aluan Haddad (aluanhaddad) mentioned this pull request Jun 5, 2016
New rule: ensure that all code paths return a value palantir/tslint#580
Closed
@roymiloh Roy Miloh (roymiloh) mentioned this pull request Nov 21, 2016
remove unreachable code rule wix-incubator/tslint-config-wix#1
Merged
@ashishsc Ashish Chandwani (ashishsc) mentioned this pull request Mar 27, 2017
Convert index.js to TypeScript evancohen/sonus#35
Open
@microsoft Microsoft (microsoft) locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

11 participants

@vladima @basarat @jbondc @DanielRosenwasser @alexeagle @ahejlsberg @glen-84 @yuit @CyrusNajmabadi @JsonFreeman @msftclas
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.