@@ -2287,6 +2287,7 @@ class PatternBindingEntry {
22872287 // Flags::Checked.
22882288 friend class PatternBindingEntryRequest ;
22892289 friend class PatternBindingCheckedAndContextualizedInitRequest ;
2290+ friend class PatternBindingCaptureInfoRequest ;
22902291
22912292 bool isFullyValidated () const {
22922293 return InitContextAndFlags.getInt ().contains (
@@ -2435,8 +2436,20 @@ class PatternBindingEntry {
24352436 // / from the source range.
24362437 SourceRange getSourceRange (bool omitAccessors = false ) const ;
24372438
2438- CaptureInfo getCaptureInfo () const { return Captures; }
2439- void setCaptureInfo (CaptureInfo captures) { Captures = captures; }
2439+ // / Retrieve the computed capture info, or \c nullopt if it hasn't been
2440+ // / computed yet.
2441+ std::optional<CaptureInfo> getCachedCaptureInfo () const {
2442+ if (!Captures.hasBeenComputed ())
2443+ return std::nullopt ;
2444+
2445+ return Captures;
2446+ }
2447+
2448+ void setCaptureInfo (CaptureInfo captures) {
2449+ ASSERT (!Captures.hasBeenComputed ());
2450+ ASSERT (captures.hasBeenComputed ());
2451+ Captures = captures;
2452+ }
24402453
24412454private:
24422455 SourceLoc getLastAccessorEndLoc () const ;
@@ -2460,6 +2473,7 @@ class PatternBindingDecl final : public Decl,
24602473 friend class Decl ;
24612474 friend class PatternBindingEntryRequest ;
24622475 friend class PatternBindingCheckedAndContextualizedInitRequest ;
2476+ friend class PatternBindingCaptureInfoRequest ;
24632477
24642478 SourceLoc StaticLoc; // /< Location of the 'static/class' keyword, if present.
24652479 SourceLoc VarLoc; // /< Location of the 'var' keyword.
@@ -2639,13 +2653,9 @@ class PatternBindingDecl final : public Decl,
26392653 getMutablePatternList ()[i].setInitContext (init);
26402654 }
26412655
2642- CaptureInfo getCaptureInfo (unsigned i) const {
2643- return getPatternList ()[i].getCaptureInfo ();
2644- }
2645-
2646- void setCaptureInfo (unsigned i, CaptureInfo captures) {
2647- getMutablePatternList ()[i].setCaptureInfo (captures);
2648- }
2656+ // / Retrieve the capture info for the initializer at the given index,
2657+ // / computing if needed.
2658+ CaptureInfo getCaptureInfo (unsigned i) const ;
26492659
26502660 // / Given that this PBD is the parent pattern for the specified VarDecl,
26512661 // / return the entry of the VarDecl in our PatternList. For example, in:
0 commit comments