Skip to content

Better mixin generation for gem RBIs - #569

Merged
paracycle merged 12 commits into
mainfrom
uk-at-include-detection
Oct 28, 2021
Merged

Better mixin generation for gem RBIs#569
paracycle merged 12 commits into
mainfrom
uk-at-include-detection

Conversation

@paracycle

Copy link
Copy Markdown
Member

Motivation

We have not had a way of filtering mixins on a constant to generate only the ones that are actually mixed in by the gem we are generating an RBI for. This has been causing issues of attribution and was resulting in Tapioca generating RBIs that would look different in the presence of other gems.

Implementation

The implementation relies on detecting when mixins happen on constants and recording the unique file based backtrace of the mixin location. At RBI mixin generation time, we filter out all mixins on a constant that have no backtrace that has ever touched the gem we are working on.

Tests

Updated existing tests to work well with the new reality.

Co-authored-by: Alexandre Terrasa [email protected]

paracycle and others added 8 commits October 21, 2021 01:08
Mixin tracker tracks all `prepend`, `include` and `extend` calls and
keeps a map of modules and the locations where they were mixed into each
constant.

Co-authored-by: Alexandre Terrasa <[email protected]>
The logic was duplicated for `prepends`, `includes` and `extends`, so we
factored out the common logic to a method.

Co-authored-by: Alexandre Terrasa <[email protected]>
We should generate a mixin in the RBI file only if we can be sure that
the mixin location was coming from a gem file or if we could not track
the mixin location at all.

In all other cases, we can safely drop the mixin, since it should be
generated in the RBI file of the gem that is actually performing the
mixin in the first place.

Co-authored-by: Alexandre Terrasa <[email protected]>
Stop expecting that unrelated mixins should be generated on the core
types we have to reopen them in RBI files.

Co-authored-by: Alexandre Terrasa <[email protected]>
Co-authored-by: Alexandre Terrasa <[email protected]>
Not sure if this is going to work properly

Co-authored-by: Alexandre Terrasa <[email protected]>
Since some code checks or relies on the result of `callers` or
`caller_locations` during a mixin, if we patch mixin methods, we might
get spurious failures.

A safer way is to patch `append_features` to catch `include`s,
`prepend_features` to catch `prepend`s and `extend_object`s to catch
`extend`s.

Co-authored-by: Alan Wu <[email protected]>
@paracycle
paracycle requested review from a team and Morriar October 27, 2021 22:22
Comment thread lib/tapioca/compilers/symbol_table/symbol_generator.rb Outdated
Comment thread lib/tapioca/mixin_tracker.rb
Comment thread lib/tapioca/compilers/symbol_table/symbol_generator.rb Outdated
@paracycle
paracycle merged commit 2a6982e into main Oct 28, 2021
@paracycle
paracycle deleted the uk-at-include-detection branch October 28, 2021 22:05
@Morriar Morriar added the bugfix label Oct 29, 2021
@paracycle paracycle mentioned this pull request Dec 17, 2021
@shopify-shipit
shopify-shipit Bot temporarily deployed to production December 17, 2021 22:05 Inactive
@paracycle paracycle added the backported Backported to stable branch label Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backported Backported to stable branch bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants