@@ -2287,6 +2287,7 @@ class PatternBindingEntry {
2287
2287
// Flags::Checked.
2288
2288
friend class PatternBindingEntryRequest ;
2289
2289
friend class PatternBindingCheckedAndContextualizedInitRequest ;
2290
+ friend class PatternBindingCaptureInfoRequest ;
2290
2291
2291
2292
bool isFullyValidated () const {
2292
2293
return InitContextAndFlags.getInt ().contains (
@@ -2435,8 +2436,20 @@ class PatternBindingEntry {
2435
2436
// / from the source range.
2436
2437
SourceRange getSourceRange (bool omitAccessors = false ) const ;
2437
2438
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
+ }
2440
2453
2441
2454
private:
2442
2455
SourceLoc getLastAccessorEndLoc () const ;
@@ -2460,6 +2473,7 @@ class PatternBindingDecl final : public Decl,
2460
2473
friend class Decl ;
2461
2474
friend class PatternBindingEntryRequest ;
2462
2475
friend class PatternBindingCheckedAndContextualizedInitRequest ;
2476
+ friend class PatternBindingCaptureInfoRequest ;
2463
2477
2464
2478
SourceLoc StaticLoc; // /< Location of the 'static/class' keyword, if present.
2465
2479
SourceLoc VarLoc; // /< Location of the 'var' keyword.
@@ -2639,13 +2653,9 @@ class PatternBindingDecl final : public Decl,
2639
2653
getMutablePatternList ()[i].setInitContext (init);
2640
2654
}
2641
2655
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 ;
2649
2659
2650
2660
// / Given that this PBD is the parent pattern for the specified VarDecl,
2651
2661
// / return the entry of the VarDecl in our PatternList. For example, in:
0 commit comments