Skip to content

fix(core): remove duplicated EMPTY_ARRAY constant#40587

Closed
cexbrayat wants to merge 0 commit intoangular:masterfrom
cexbrayat:fix/duplicate-empty-symbol
Closed

fix(core): remove duplicated EMPTY_ARRAY constant#40587
cexbrayat wants to merge 0 commit intoangular:masterfrom
cexbrayat:fix/duplicate-empty-symbol

Conversation

@cexbrayat
Copy link
Member

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

The codebase currently contains several EMPTY_ARRAY constants,
and they can end up in the bundle of an application.
A recent commit 6fbe219 tipped us off
as it introduced several noop occurrences in the golden symbol files.

What is the new behavior?

After investigating with @petebacondarwin,
we decided to remove the duplicated symbols.

This probably shaves only a few bytes,
but this commit removes the duplicated functions,
by always using the one in core/src/utils/empty.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@google-cla google-cla bot added the cla: yes label Jan 27, 2021
@pullapprove pullapprove bot requested a review from atscott January 27, 2021 07:53
@cexbrayat cexbrayat force-pushed the fix/duplicate-empty-symbol branch 2 times, most recently from ae19b74 to 83dd9d2 Compare January 27, 2021 08:23
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Smashing! Thanks @cexbrayat

@petebacondarwin petebacondarwin added action: review The PR is still awaiting reviews from at least one requested reviewer area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release labels Jan 27, 2021
@ngbot ngbot bot added this to the Backlog milestone Jan 27, 2021
Copy link
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

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

Nice

Copy link
Member

Choose a reason for hiding this comment

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

Are we sure we don't mind that some EMPTY_ARRAYs will not be frozen in dev mode any more?

Copy link
Member Author

Choose a reason for hiding this comment

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

No worries: it now uses EMPTY_ARRAY from util/empty.ts which does exactly the same (see https://github.com/angular/angular/blob/a6971ba89adc253bfa4260036ee4a1e0bd76159f/packages/core/src/util/empty.ts)

Copy link
Member

Choose a reason for hiding this comment

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

Right. Then, are we sure we don't mind that some EMPTY_ARRAYs will now be frozen in dev mode? 😁

Copy link
Member Author

Choose a reason for hiding this comment

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

Ha! That's a tougher question to answer 😃. I think it should be fine but do you see an area where it might be problematic?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would have thought that freezing in dev-mode is what we want. And possibly not bothering to freeze in prod mode.
The general idea being that we would catch errors that try to modify the object during testing in dev mode.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. OOC: is one of the test suites running with ngDevMode enabled?

Copy link
Member

Choose a reason for hiding this comment

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

My concern was more with operations that don't throw errors. For example, a = []; Object.freeze(a); a[0] = 'v'; will silently fail.

But looking at the code, there doesn't seem to be a place were EMPTY_ARRAY is modified. Ideally we should type it as ReadonlyArray, but this is out of scope for this PR 😃

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I always thought that a frozen object/array would throw an error in that case. TIL!

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Ah, nice! That's more reassuring 😃

@gkalpak gkalpak added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews action: review The PR is still awaiting reviews from at least one requested reviewer labels Jan 27, 2021
@JoostK
Copy link
Member

JoostK commented Jan 27, 2021

This happens to address #28229 :-D

@jessicajaniuk
Copy link
Contributor

Presubmit

@jessicajaniuk jessicajaniuk added action: merge The PR is ready for merge by the caretaker and removed action: merge The PR is ready for merge by the caretaker labels Jan 27, 2021
mhevery pushed a commit that referenced this pull request Jan 28, 2021
The codebase currently contains several `EMPTY_ARRAY` constants,
and they can end up in the bundle of an application.
A recent commit 6fbe219 tipped us off
as it introduced several `noop` occurrences in the golden symbol files.
After investigating with @petebacondarwin,
we decided to remove the duplicated symbols.

This probably shaves only a few bytes,
but this commit removes the duplicated functions,
by always using the one in `core/src/utils/empty`.

PR Close #40587
mhevery pushed a commit that referenced this pull request Jan 28, 2021
The codebase currently contains several `EMPTY_ARRAY` constants,
and they can end up in the bundle of an application.
A recent commit 6fbe219 tipped us off
as it introduced several `noop` occurrences in the golden symbol files.
After investigating with @petebacondarwin,
we decided to remove the duplicated symbols.

This probably shaves only a few bytes,
but this commit removes the duplicated functions,
by always using the one in `core/src/utils/empty`.

PR Close #40587
@mhevery mhevery closed this in 34aa9c3 Jan 28, 2021
@mhevery mhevery reopened this Jan 28, 2021
@mhevery
Copy link
Contributor

mhevery commented Jan 28, 2021

This change breaks //cloud/console/web/appengine/versions:karma_skip_snapshots_chrome-linux reverting

mhevery added a commit that referenced this pull request Jan 28, 2021
mhevery added a commit that referenced this pull request Jan 28, 2021
mhevery added a commit that referenced this pull request Jan 28, 2021
@mhevery
Copy link
Contributor

mhevery commented Jan 28, 2021

Do not merge this PR until http://b/178744068 is resolved. (Has been resolved 2/1/2021)

@mhevery
Copy link
Contributor

mhevery commented Feb 1, 2021

presubmit

@alan-agius4 alan-agius4 added the action: presubmit The PR is in need of a google3 presubmit label Feb 22, 2021
@AndrewKushnir AndrewKushnir force-pushed the fix/duplicate-empty-symbol branch from 83dd9d2 to 6c05c80 Compare February 25, 2021 05:01
@AndrewKushnir
Copy link
Contributor

@cexbrayat I've tried rebasing this PR using our tooling, but it detected that the original commit was already merged (and reverted later), so the rebase resulted in an empty branch :(

I can restore actual changes using previously merged commits, but I'd like to ask if you're ok re-creating this PR, so that the change is submitted under your name.

Note: I've also started a new presubmit and we'll use these results for the newly created PR.

Please let me know if you can help with re-creating this PR or you want me to handle this.

Thank you.

@cexbrayat
Copy link
Member Author

@AndrewKushnir Sure, I opened #40991 let me know if that's OK.

Thanks for your help Andrew

@cexbrayat cexbrayat deleted the fix/duplicate-empty-symbol branch February 25, 2021 10:16
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker action: presubmit The PR is in need of a google3 presubmit area: core Issues related to the framework runtime cla: yes target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EMPTY_ARRAY used for identity checks, but multiple are declared in core

9 participants