Skip to content

[DNM] [Builder transform] Give generated pattern bindings proper source locations #29325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions lib/Sema/BuilderTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,8 @@ class BuilderClosureRewriter
/// Declare the given temporary variable, adding the appropriate
/// entries to the elements of a brace stmt.
void declareTemporaryVariable(VarDecl *temporaryVar,
std::vector<ASTNode> &elements) {
std::vector<ASTNode> &elements,
Expr *initExpr = nullptr) {
if (!temporaryVar)
return;

Expand All @@ -739,7 +740,9 @@ class BuilderClosureRewriter
auto pattern = new (ctx) NamedPattern(temporaryVar,/*implicit=*/true);
pattern->setType(temporaryVar->getType());

auto pbd = PatternBindingDecl::createImplicit(ctx, StaticSpellingKind::None, pattern, nullptr, dc);
auto pbd = PatternBindingDecl::create(
ctx, SourceLoc(), StaticSpellingKind::None, temporaryVar->getLoc(),
pattern, SourceLoc(), initExpr, dc);
elements.push_back(temporaryVar);
elements.push_back(pbd);
}
Expand Down Expand Up @@ -789,13 +792,7 @@ class BuilderClosureRewriter

// Form a new pattern binding to bind the temporary variable to the
// transformed expression.
auto pattern = new (ctx) NamedPattern(
recorded.temporaryVar, /*implicit=*/true);
pattern->setType(recorded.temporaryVar->getType());
newElements.push_back(recorded.temporaryVar);

auto pbd = PatternBindingDecl::createImplicit(ctx, StaticSpellingKind::None, pattern, finalExpr, dc);
newElements.push_back(pbd);
declareTemporaryVariable(recorded.temporaryVar, newElements, finalExpr);
continue;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,8 @@ struct AppliedBuilderTransform {
};

/// A mapping from expressions whose values are captured by the builder
/// to information about the temporary variable capturing the
/// to information about the temporary variable capturing that value
/// for use later.
llvm::DenseMap<Expr *, RecordedExpr> capturedExprs;

/// A mapping from statements to a pair containing the implicit variable
Expand Down