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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃彈 Rewrite and enable type-checking on src/core target #33921

Merged
merged 13 commits into from
Apr 21, 2021

Conversation

rcebulko
Copy link
Contributor

@rcebulko rcebulko commented Apr 20, 2021

Related to #33631
Example usage: amp check-types --targets=src-core; amp check-types --warning_level=verbose

Currently, type-checking the entire source tree fails with various errors and warnings. It pulls in almost every source file in the repo, then trims it down based on what's required by the binary. This makes sense for compilation, but isn't necessary for type-checking.

This PR allows for type-checking a specific directory--in this case, src/core. Externs belonging to src/core are defined there, rather than in build-system/amp.externs.js which has grown to be huge (~1100 lines last I checked). By default, amp check-types doesn't run at all on targets with a warning_level=QUIET, since that effectively does nothing but take time. The only enabled target is src/core for now, but this will be steadily expanded.

/cc @ampproject/wg-performance

@rcebulko rcebulko marked this pull request as ready for review April 20, 2021 20:54
@amp-owners-bot
Copy link

Hey @rsimha! These files were changed:

build-system/compile/compile.js

Hey @jridgewell! These files were changed:

src/core/assert.js
src/core/error-message-helpers.js
src/core/error.extern.js
src/core/shame.extern.js
src/core/types/object.extern.js
src/core/window.extern.js

*/
const TYPE_CHECK_TARGETS = {
'src': {
entryPoints: [
Copy link
Member

@samouri samouri Apr 21, 2021

Choose a reason for hiding this comment

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

Would it make more sense to use our bundle definitions as our typecheck targets instead of recreating a somewhat similar map? The primary entrypoints are in bundles.config.js and the extensions are in bundles.config.extensions.js.

In the short-term, I see how that would be difficult for enforcing src/core files, but in the long terms it seems more maintainable (and hopefully less code!).

It would also enable us to check-types for binaries in isolation (just one extension, or just v0.js, etc.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The short answer to this is: I don't know. To some degree, that would seem to make sense. When the whole repo is passing, we can enable the type--checking CC flag by default, and that will just get added into the dist process. But that's a bit "messier" to get working, as opposed to locking down type-safety one directory at a time. If we build this up so the whole repo is type-checked successfully, would there be any added value in type-checking the binaries themselves? (I'm guessing yes, but am not certain)

Copy link
Member

Choose a reason for hiding this comment

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

Partial typechecking will not be valuable once everything is fixed up. The question is until we get there, what is more valuable? Fixing directory by directory where we have to code each in a one-off way? Or Binary by binary? I don't have that strong of an opinion since I figured adding in one-off directories is not that much work

Copy link
Contributor Author

@rcebulko rcebulko Apr 21, 2021

Choose a reason for hiding this comment

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

I get the sense that in practice, locking down one directory at a time (and including the check in CI) will make it easiest to take multiple bites at the apple and get the whole repo compliant, whereas we have to get a whole binary compliant to enable it during CI and for most of the binaries that entails most of src

@rcebulko rcebulko merged commit df20a6f into ampproject:main Apr 21, 2021
@rcebulko rcebulko deleted the core-types branch April 21, 2021 22:31
rochapablo pushed a commit to rochapablo/amphtml that referenced this pull request Aug 30, 2021
* add compile options to not add anything unspecified

* Rewrite check-types task to support checking individual targets

* Update conformance allowlist for string helpers now in core

* Define extern types for existing core files

* Update core files to pass type-checking

* %s/object.externs.js/object.extern.js/

* Remove duplicate externs defined in core

* Opt-out failing targets from type-checking; let flag override

* Clean up extern list code

* Lint fixes

* destructure

* typo

* comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants