Skip to content

feat(linter): add CFGLintContext for rules with #[use_cfg].#3747

Closed
rzvxa wants to merge 4 commits into06-18-perf_linter_only_generate_cfg_when_we_have_a_rule_which_depends_on_itfrom
06-19-feat_linter_add_cfglintcontext_for_rules_with_use_cfg_
Closed

feat(linter): add CFGLintContext for rules with #[use_cfg].#3747
rzvxa wants to merge 4 commits into06-18-perf_linter_only_generate_cfg_when_we_have_a_rule_which_depends_on_itfrom
06-19-feat_linter_add_cfglintcontext_for_rules_with_use_cfg_

Conversation

@rzvxa
Copy link
Contributor

@rzvxa rzvxa commented Jun 18, 2024

related to this #3744 (comment)

Now only rules declared with the #[use_cfg] attribute would get to use ctx.cfg method otherwise they have to check for cfx.semantic().cfg() to be Some.

If this gets merged we should be able to unwrap the control flow unchecked; Since our current linter runner is getting its context from outside we should check for this not being None before iterating and panicking early on.

@graphite-app
Copy link
Contributor

graphite-app bot commented Jun 18, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

Copy link
Contributor Author

rzvxa commented Jun 18, 2024

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @rzvxa and the rest of your teammates on Graphite Graphite

@codspeed-hq
Copy link

codspeed-hq bot commented Jun 18, 2024

CodSpeed Performance Report

Merging #3747 will degrade performances by 3.42%

Comparing 06-19-feat_linter_add_cfglintcontext_for_rules_with_use_cfg_ (c575a19) with 06-18-perf_linter_only_generate_cfg_when_we_have_a_rule_which_depends_on_it (7ac80eb)

Summary

❌ 1 regressions
✅ 21 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark 06-18-perf_linter_only_generate_cfg_when_we_have_a_rule_which_depends_on_it 06-19-feat_linter_add_cfglintcontext_for_rules_with_use_cfg_ Change
codegen_sourcemap[react.development.js] 2 ms 2.1 ms -3.42%

@rzvxa rzvxa requested a review from overlookmotel June 18, 2024 22:21
@rzvxa
Copy link
Contributor Author

rzvxa commented Jun 18, 2024

@overlookmotel Is there any way to transmute LintContext to CFGLintContext? If we want to do this are we forced to make them #[repr(C)]? Some parts of my current implementation are a bit wanky because of this.
Changed my data structures a little bit and now it is easy to prove it is sound.

@rzvxa rzvxa marked this pull request as ready for review June 18, 2024 22:39
@rzvxa rzvxa marked this pull request as draft June 18, 2024 22:41
@rzvxa rzvxa marked this pull request as ready for review June 19, 2024 01:01
@Boshen Boshen force-pushed the 06-18-perf_linter_only_generate_cfg_when_we_have_a_rule_which_depends_on_it branch from be0dd5b to 7ac80eb Compare June 19, 2024 05:17
@Boshen Boshen force-pushed the 06-19-feat_linter_add_cfglintcontext_for_rules_with_use_cfg_ branch from 0ddedbf to c575a19 Compare June 19, 2024 05:18
severity: Severity,
}

#[derive(Clone)]
Copy link
Member

Choose a reason for hiding this comment

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

I think the transmute between &LintContext/&CFGLintContext and &LintContextData is sound as you've made both structs #[repr(transparent)].

But if someone changed the type defs without understanding this need, it'd lead to UB.

To make this unlikely to happen, I think it needs a comment here at the location of the type definitions explaining what is going on here, the motivation for it, and saying at minimum "It is essential that LintContext and LintContextData have identical memory layouts so that From impls below are sound.".

@Boshen
Copy link
Member

Boshen commented Jun 19, 2024

Closing the stack as too complicated.

@Boshen Boshen closed this Jun 19, 2024
Boshen pushed a commit that referenced this pull request Jun 19, 2024
…g enabled semantic. (#3761)

It has the same spirit as #3747 but with a much simpler approach. I've used the fact that @Boshen mentioned about linter always using CFG so now we assert `semantic.cfg().is_some()` in the `LintContext::new` because of this assertion we can have a `LintContext::cfg` that unwraps unchecked.
Eliminates unnecessary checks in our hot paths.

It has the best of both worlds, No complicated typing yet we still get the CFG as a non-optional value without extra ASM or branching.
rzvxa added a commit that referenced this pull request Jun 19, 2024
…g enabled semantic. (#3761)

It has the same spirit as #3747 but with a much simpler approach. I've used the fact that @Boshen mentioned about linter always using CFG so now we assert `semantic.cfg().is_some()` in the `LintContext::new` because of this assertion we can have a `LintContext::cfg` that unwraps unchecked.
Eliminates unnecessary checks in our hot paths.

It has the best of both worlds, No complicated typing yet we still get the CFG as a non-optional value without extra ASM or branching.
@Boshen Boshen deleted the 06-19-feat_linter_add_cfglintcontext_for_rules_with_use_cfg_ branch June 27, 2024 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants