Skip to content

Commit c4dbc53

Browse files
Wendy Yufacebook-github-bot
authored andcommitted
Fix AttrResolutionContext lifetimes
Summary: AttrResolutionContext trait should have a lifetime because objects that implement it should live as long as the `Module` and `Heap` inside AttrResolutionContext. Reviewed By: stepancheg Differential Revision: D39348188 fbshipit-source-id: 185633ae4781fc7a34374bf785ab053a3658c5c0
1 parent 9076b59 commit c4dbc53

File tree

13 files changed

+97
-97
lines changed

13 files changed

+97
-97
lines changed

buck2_build_api/src/analysis/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ struct RuleAnalysisAttrResolutionContext<'v> {
113113
query_results: HashMap<String, Arc<AnalysisQueryResult>>,
114114
}
115115

116-
impl<'v> AttrResolutionContext for RuleAnalysisAttrResolutionContext<'v> {
117-
fn starlark_module(&self) -> &Module {
116+
impl<'v> AttrResolutionContext<'v> for RuleAnalysisAttrResolutionContext<'v> {
117+
fn starlark_module(&self) -> &'v Module {
118118
self.module
119119
}
120120

buck2_build_api/src/attrs/resolve/attr_literal.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ impl UnconfiguredAttrLiteralExt for AttrLiteral<CoercedAttr> {
9696
}
9797

9898
pub(crate) trait ConfiguredAttrLiteralExt {
99-
fn resolve_single<'v>(&self, ctx: &'v dyn AttrResolutionContext) -> anyhow::Result<Value<'v>>;
99+
fn resolve_single<'v>(&self, ctx: &dyn AttrResolutionContext<'v>) -> anyhow::Result<Value<'v>>;
100100

101-
fn resolve<'v>(&self, ctx: &'v dyn AttrResolutionContext) -> anyhow::Result<Vec<Value<'v>>>;
101+
fn resolve<'v>(&self, ctx: &dyn AttrResolutionContext<'v>) -> anyhow::Result<Vec<Value<'v>>>;
102102

103103
fn starlark_type(&self) -> anyhow::Result<&'static str>;
104104

@@ -107,7 +107,7 @@ pub(crate) trait ConfiguredAttrLiteralExt {
107107
}
108108

109109
impl ConfiguredAttrLiteralExt for AttrLiteral<ConfiguredAttr> {
110-
fn resolve_single<'v>(&self, ctx: &'v dyn AttrResolutionContext) -> anyhow::Result<Value<'v>> {
110+
fn resolve_single<'v>(&self, ctx: &dyn AttrResolutionContext<'v>) -> anyhow::Result<Value<'v>> {
111111
match self {
112112
AttrLiteral::Bool(v) => Ok(Value::new_bool(*v)),
113113
AttrLiteral::Int(v) => Ok(Value::new_int(*v)),
@@ -157,7 +157,7 @@ impl ConfiguredAttrLiteralExt for AttrLiteral<ConfiguredAttr> {
157157
}
158158
}
159159

160-
fn resolve<'v>(&self, ctx: &'v dyn AttrResolutionContext) -> anyhow::Result<Vec<Value<'v>>> {
160+
fn resolve<'v>(&self, ctx: &dyn AttrResolutionContext<'v>) -> anyhow::Result<Vec<Value<'v>>> {
161161
match self {
162162
// SourceLabel is special since it is the only type that can be expand to many
163163
AttrLiteral::SourceLabel(src) => SourceAttrType::resolve_label(ctx, src),

buck2_build_api/src/attrs/resolve/attr_type/arg/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ impl CommandLineBuilder for SpaceSeparatedCommandLineBuilder<'_> {
6767
}
6868

6969
pub(crate) trait ConfiguredStringWithMacrosExt {
70-
fn resolve<'v>(&self, ctx: &'v dyn AttrResolutionContext) -> anyhow::Result<Value<'v>>;
70+
fn resolve<'v>(&self, ctx: &dyn AttrResolutionContext<'v>) -> anyhow::Result<Value<'v>>;
7171
}
7272

7373
impl ConfiguredStringWithMacrosExt for ConfiguredStringWithMacros {
74-
fn resolve<'v>(&self, ctx: &'v dyn AttrResolutionContext) -> anyhow::Result<Value<'v>> {
74+
fn resolve<'v>(&self, ctx: &dyn AttrResolutionContext<'v>) -> anyhow::Result<Value<'v>> {
7575
ResolvedStringWithMacros::resolved(self, ctx)
7676
}
7777
}

buck2_build_api/src/attrs/resolve/attr_type/arg/value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl ResolvedStringWithMacros {
280280

281281
pub(crate) fn resolved<'v>(
282282
configured_macros: &ConfiguredStringWithMacros,
283-
ctx: &'v dyn AttrResolutionContext,
283+
ctx: &dyn AttrResolutionContext<'v>,
284284
) -> anyhow::Result<Value<'v>> {
285285
let resolved_parts = match configured_macros {
286286
ConfiguredStringWithMacros::StringPart(s) => {

buck2_build_api/src/attrs/resolve/attr_type/configuration_dep.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::attrs::resolve::ctx::AttrResolutionContext;
1515

1616
pub(crate) trait ConfigurationDepAttrTypeExt {
1717
fn resolve_single<'v>(
18-
ctx: &'v dyn AttrResolutionContext,
18+
ctx: &dyn AttrResolutionContext<'v>,
1919
label: &TargetLabel,
2020
) -> anyhow::Result<Value<'v>> {
2121
Ok(ctx.heap().alloc(label.to_string()))

buck2_build_api/src/attrs/resolve/attr_type/dep.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ pub(crate) trait DepAttrTypeExt {
4545
) -> Value<'v>;
4646

4747
fn resolve_single_impl<'v>(
48-
ctx: &'v dyn AttrResolutionContext,
48+
ctx: &dyn AttrResolutionContext<'v>,
4949
target: &ConfiguredProvidersLabel,
5050
required_providers: &Option<Arc<ProviderIdSet>>,
5151
) -> anyhow::Result<Value<'v>>;
5252

5353
fn resolve_single<'v>(
54-
ctx: &'v dyn AttrResolutionContext,
54+
ctx: &dyn AttrResolutionContext<'v>,
5555
dep_attr: &DepAttr<ConfiguredProvidersLabel>,
5656
) -> anyhow::Result<Value<'v>>;
5757
}
@@ -87,7 +87,7 @@ impl DepAttrTypeExt for DepAttrType {
8787
}
8888

8989
fn resolve_single_impl<'v>(
90-
ctx: &'v dyn AttrResolutionContext,
90+
ctx: &dyn AttrResolutionContext<'v>,
9191
target: &ConfiguredProvidersLabel,
9292
required_providers: &Option<Arc<ProviderIdSet>>,
9393
) -> anyhow::Result<Value<'v>> {
@@ -101,7 +101,7 @@ impl DepAttrTypeExt for DepAttrType {
101101
}
102102

103103
fn resolve_single<'v>(
104-
ctx: &'v dyn AttrResolutionContext,
104+
ctx: &dyn AttrResolutionContext<'v>,
105105
dep_attr: &DepAttr<ConfiguredProvidersLabel>,
106106
) -> anyhow::Result<Value<'v>> {
107107
Self::resolve_single_impl(ctx, &dep_attr.label, &dep_attr.attr_type.required_providers)
@@ -110,7 +110,7 @@ impl DepAttrTypeExt for DepAttrType {
110110

111111
pub(crate) trait ExplicitConfiguredDepAttrTypeExt {
112112
fn resolve_single<'v>(
113-
ctx: &'v dyn AttrResolutionContext,
113+
ctx: &dyn AttrResolutionContext<'v>,
114114
dep_attr: &ConfiguredExplicitConfiguredDep,
115115
) -> anyhow::Result<Value<'v>> {
116116
DepAttrType::resolve_single_impl(

buck2_build_api/src/attrs/resolve/attr_type/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ impl ConfiguredQueryAttrBaseExt for QueryAttrBase<ConfiguredAttr> {
3434
}
3535

3636
pub(crate) trait ConfiguredQueryAttrExt {
37-
fn resolve<'v>(&self, ctx: &'v dyn AttrResolutionContext) -> anyhow::Result<Value<'v>>;
37+
fn resolve<'v>(&self, ctx: &dyn AttrResolutionContext<'v>) -> anyhow::Result<Value<'v>>;
3838
}
3939

4040
impl ConfiguredQueryAttrExt for QueryAttr<ConfiguredAttr> {
41-
fn resolve<'v>(&self, ctx: &'v dyn AttrResolutionContext) -> anyhow::Result<Value<'v>> {
41+
fn resolve<'v>(&self, ctx: &dyn AttrResolutionContext<'v>) -> anyhow::Result<Value<'v>> {
4242
let query_results = self.query.resolve(ctx)?;
4343
let mut dependencies = Vec::new();
4444

buck2_build_api/src/attrs/resolve/attr_type/source.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ enum SourceLabelResolutionError {
2424
}
2525

2626
pub(crate) trait SourceAttrTypeExt {
27-
fn resolve_single_file<'v>(ctx: &'v dyn AttrResolutionContext, path: &BuckPath) -> Value<'v> {
27+
fn resolve_single_file<'v>(ctx: &dyn AttrResolutionContext<'v>, path: &BuckPath) -> Value<'v> {
2828
ctx.heap().alloc(StarlarkArtifact::new(
2929
SourceArtifact::new(path.clone()).into(),
3030
))
3131
}
3232

3333
fn resolve_label<'v>(
34-
ctx: &'v dyn AttrResolutionContext,
34+
ctx: &dyn AttrResolutionContext<'v>,
3535
label: &ConfiguredProvidersLabel,
3636
) -> anyhow::Result<Vec<Value<'v>>> {
3737
let dep = ctx.get_dep(label)?;
@@ -47,7 +47,7 @@ pub(crate) trait SourceAttrTypeExt {
4747
}
4848

4949
fn resolve_single_label<'v>(
50-
ctx: &'v dyn AttrResolutionContext,
50+
ctx: &dyn AttrResolutionContext<'v>,
5151
value: &ConfiguredProvidersLabel,
5252
) -> anyhow::Result<Value<'v>> {
5353
let mut resolved = Self::resolve_label(ctx, value)?;

buck2_build_api/src/attrs/resolve/attr_type/split_transition_dep.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ use crate::attrs::resolve::ctx::AttrResolutionContext;
2020

2121
pub(crate) trait SplitTransitionDepAttrTypeExt {
2222
fn resolve_single<'v>(
23-
ctx: &'v dyn AttrResolutionContext,
23+
ctx: &dyn AttrResolutionContext<'v>,
2424
deps: &ConfiguredSplitTransitionDep,
2525
) -> anyhow::Result<Value<'v>>;
2626
}
2727

2828
impl SplitTransitionDepAttrTypeExt for SplitTransitionDepAttrType {
2929
fn resolve_single<'v>(
30-
ctx: &'v dyn AttrResolutionContext,
30+
ctx: &dyn AttrResolutionContext<'v>,
3131
deps: &ConfiguredSplitTransitionDep,
3232
) -> anyhow::Result<Value<'v>> {
3333
let mut res = SmallMap::with_capacity(deps.deps.len());

buck2_build_api/src/attrs/resolve/configured_attr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use crate::attrs::resolve::attr_literal::ConfiguredAttrLiteralExt;
1515
use crate::attrs::resolve::ctx::AttrResolutionContext;
1616

1717
pub trait ConfiguredAttrExt {
18-
fn resolve<'v>(&self, ctx: &'v dyn AttrResolutionContext) -> anyhow::Result<Vec<Value<'v>>>;
18+
fn resolve<'v>(&self, ctx: &dyn AttrResolutionContext<'v>) -> anyhow::Result<Vec<Value<'v>>>;
1919

20-
fn resolve_single<'v>(&self, ctx: &'v dyn AttrResolutionContext) -> anyhow::Result<Value<'v>>;
20+
fn resolve_single<'v>(&self, ctx: &dyn AttrResolutionContext<'v>) -> anyhow::Result<Value<'v>>;
2121

2222
fn starlark_type(&self) -> anyhow::Result<&'static str>;
2323

@@ -31,13 +31,13 @@ impl ConfiguredAttrExt for ConfiguredAttr {
3131
/// an inappropriate number of elements is returned. e.g. `attrs.list()` might
3232
/// accept and merge multiple returned values from `attrs.source()`, but
3333
/// `attrs.optional()` might only accept a single value, and fail otherwise.
34-
fn resolve<'v>(&self, ctx: &'v dyn AttrResolutionContext) -> anyhow::Result<Vec<Value<'v>>> {
34+
fn resolve<'v>(&self, ctx: &dyn AttrResolutionContext<'v>) -> anyhow::Result<Vec<Value<'v>>> {
3535
self.0.resolve(ctx)
3636
}
3737

3838
/// Resolving a single value is common, so `resolve_single` will validate
3939
/// this function's output, and return a single value or an error.
40-
fn resolve_single<'v>(&self, ctx: &'v dyn AttrResolutionContext) -> anyhow::Result<Value<'v>> {
40+
fn resolve_single<'v>(&self, ctx: &dyn AttrResolutionContext<'v>) -> anyhow::Result<Value<'v>> {
4141
self.0.resolve_single(ctx)
4242
}
4343

0 commit comments

Comments
 (0)