Skip to content
This repository was archived by the owner on Oct 17, 2021. It is now read-only.

Make tfjs-layers compatible with the closure compiler #442

Merged
merged 16 commits into from
Jan 31, 2019
Merged

Conversation

dsmilkov
Copy link
Contributor

@dsmilkov dsmilkov commented Jan 30, 2019

  • Add /** @nocollapse */ on static properties to tell closure not to remove them.
  • Prepend declare in front of interfaces and types that are external (used in json deserialization/serialization) so closure doesn't rename their properties.
  • Instead of object literals, explicitly assign each field separately to a config object and mark it as serialization.ConfigDict so closure doesn't rename its properties.

Similar changes in tfjs-core: tensorflow/tfjs-core#1521


This change is Reviewable

@caisq caisq requested review from davidsoergel and caisq January 31, 2019 15:02
@caisq
Copy link
Contributor

caisq commented Jan 31, 2019

cc @ericdnielsen , @bileschi , @davidsoergel as an FYI.

Copy link
Contributor Author

@dsmilkov dsmilkov left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @caisq, @davidsoergel, and @nsthorat)


src/engine/container.ts, line 775 at r1 (raw file):

    const theConfig = this.getConfig();
    const modelConfig: serialization.ConfigDict = {};
    modelConfig.className = this.getClassName();

FYI, this is a known issue with Closure. You can't do object literals even if you immediately assign them to a variable that is marked as being an external interface, such as ConfigDict. You have to assign each field individually.

@caisq
Copy link
Contributor

caisq commented Jan 31, 2019

@dsmilkov Thank you for spending the time and effort in making the code compile with closure.

Is there a way to ensure that going forward, people making changes in tfjs-layers will not break the closure compiler?

Copy link
Member

@davidsoergel davidsoergel left a comment

Choose a reason for hiding this comment

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

Reviewed 24 of 24 files at r1.
Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @caisq, @davidsoergel, and @nsthorat)


src/engine/container.ts, line 775 at r1 (raw file):

Previously, dsmilkov (Daniel Smilkov) wrote…

FYI, this is a known issue with Closure. You can't do object literals even if you immediately assign them to a variable that is marked as being an external interface, such as ConfigDict. You have to assign each field individually.

There are tons of object literals in our tests. I guess it's OK there?

@dsmilkov
Copy link
Contributor Author

So an idea is to setup a weekly cron job to sync layers and test compilation with closure by executing a few pre-trained models (most of these problems only show up on run-time when code is compiled with aggressive closure rewriting rules).

We don't sync existing tests at all.

@dsmilkov dsmilkov merged commit d90401e into master Jan 31, 2019
@dsmilkov dsmilkov deleted the google3 branch January 31, 2019 15:29
dsmilkov added a commit to tensorflow/tfjs-core that referenced this pull request Jan 31, 2019
- Add `/** @nocollapse */` on static properties to tell closure not to remove them.
- Prepend `declare` in front of interfaces and types that are external (used in json deserialization/serialization) so closure doesn't rename its properties.
- Fix issues where the promise was unused.

Similar changes in tfjs-layers: tensorflow/tfjs-layers#442
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants