Skip to content

Commit 027df4b

Browse files
tausbnCopilot
andcommitted
Unified: Use isolated interpolation contexts
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 94785174-d02b-4b65-993a-7d74a834d3db
1 parent e6d51de commit 027df4b

1 file changed

Lines changed: 11 additions & 24 deletions

File tree

  • unified/extractor/src/languages/swift

‎unified/extractor/src/languages/swift/swift.rs‎

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use codeql_extractor::extractor::desugaring;
2-
use yeast::{ConcreteDesugarer, DesugaringConfig, Rule, tree};
2+
use yeast::{tree, ConcreteDesugarer, DesugaringConfig, Rule};
33

44
/// User context propagated from outer rules down to the inner rules that
55
/// emit the corresponding output declarations, so that each emitted node
@@ -51,10 +51,9 @@ impl SwiftContext {
5151
/// Called before recursively translating a body / initializer
5252
/// slot. Most rules mutate `ctx` in place — the framework invokes
5353
/// each rule with a private clone of the user context, so
54-
/// mutations are discarded on rule exit anyway. Rules that need
55-
/// the outer context intact *after* the reset-and-translate (see
56-
/// e.g. the `property_binding` willSet/didSet rule) wrap the
57-
/// mutation in `ctx.scoped(...)` instead.
54+
/// mutations are discarded on rule exit anyway. Output-template
55+
/// interpolations additionally restore the context after evaluation,
56+
/// preventing mutations from leaking into sibling fields.
5857
fn reset(&mut self) {
5958
*self = SwiftContext::default();
6059
}
@@ -371,17 +370,13 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
371370
let mut result = Vec::new();
372371
if let Some(val) = val {
373372
// Stored property with observers: the initializer is not part
374-
// of the binding, so translate it in a reset scope.
375-
let val = ctx.scoped(|ctx| {
376-
ctx.reset();
377-
ctx.translate(val)
378-
});
373+
// of the binding, so translate it in a reset interpolation.
379374
result.push(tree!(
380375
(variable_declaration
381376
modifier: {ctx.outer_modifiers.clone()}
382377
pattern: (identifier #{name})
383378
type: {ty}
384-
value: {val})
379+
value: {ctx.reset(); val})
385380
));
386381
}
387382
for acc in accessors.into_iter() {
@@ -736,19 +731,11 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
736731
trailingClosure: _? @trailing
737732
additionalTrailingClosures: _* @additional)
738733
=>
739-
expr {
740-
// Always translate the callee in non-pattern context.
741-
let callee = ctx.scoped(|ctx| {
742-
ctx.in_pattern = false;
743-
ctx.translate(rawCallee)
744-
});
745-
tree!((call_expr
746-
callee: {callee}
747-
argument: {args}
748-
argument: {trailing.map(|trailing| tree!((argument value: {trailing})))}
749-
argument: {additional}
750-
))
751-
}
734+
(call_expr
735+
callee: {ctx.in_pattern = false; rawCallee}
736+
argument: {args}
737+
argument: {trailing.map(|trailing| tree!((argument value: {trailing})))}
738+
argument: {additional})
752739
),
753740
// A call or enum-case pattern argument.
754741
rule!(

0 commit comments

Comments
 (0)