2424namespace swift {
2525
2626class RegionAnalysisFunctionInfo ;
27+ class RegionAnalysisValueMap ;
2728
2829namespace regionanalysisimpl {
2930
@@ -121,9 +122,11 @@ using TrackedValueFlagSet = OptionSet<TrackableValueFlag>;
121122} // namespace regionanalysisimpl
122123
123124class regionanalysisimpl ::TrackableValueState {
125+ friend RegionAnalysisValueMap;
126+
124127 unsigned id;
125128 TrackedValueFlagSet flagSet = {TrackableValueFlag::isMayAlias};
126- SILIsolationInfo regionInfo = SILIsolationInfo::getDisconnected() ;
129+ std::optional< SILIsolationInfo> regionInfo = {} ;
127130
128131public:
129132 TrackableValueState (unsigned newID) : id(newID) {}
@@ -140,20 +143,28 @@ class regionanalysisimpl::TrackableValueState {
140143
141144 bool isNonSendable () const { return !isSendable (); }
142145
146+ SILIsolationInfo getIsolationRegionInfo () const {
147+ if (!regionInfo) {
148+ return SILIsolationInfo::getDisconnected (false );
149+ }
150+
151+ return *regionInfo;
152+ }
153+
143154 SILIsolationInfo::Kind getIsolationRegionInfoKind () const {
144- return regionInfo .getKind ();
155+ return getIsolationRegionInfo () .getKind ();
145156 }
146157
147158 ActorIsolation getActorIsolation () const {
148- return regionInfo .getActorIsolation ();
159+ return getIsolationRegionInfo () .getActorIsolation ();
149160 }
150161
151- void mergeIsolationRegionInfo (SILIsolationInfo newRegionInfo) {
152- regionInfo = regionInfo.merge (newRegionInfo);
162+ void setDisconnectedNonisolatedUnsafe () {
163+ auto oldRegionInfo = getIsolationRegionInfo ();
164+ assert (oldRegionInfo.isDisconnected ());
165+ regionInfo = oldRegionInfo.withUnsafeNonIsolated ();
153166 }
154167
155- SILIsolationInfo getIsolationRegionInfo () const { return regionInfo; }
156-
157168 Element getID () const { return Element (id); }
158169
159170 void addFlag (TrackableValueFlag flag) { flagSet |= flag; }
@@ -165,11 +176,22 @@ class regionanalysisimpl::TrackableValueState {
165176 << " ][is_no_alias: " << (isNoAlias () ? " yes" : " no" )
166177 << " ][is_sendable: " << (isSendable () ? " yes" : " no" )
167178 << " ][region_value_kind: " ;
168- getIsolationRegionInfo ().printForDiagnostics (os);
179+ getIsolationRegionInfo ().printForOneLineLogging (os);
169180 os << " ]." ;
170181 }
171182
172183 SWIFT_DEBUG_DUMP { print (llvm::dbgs ()); }
184+
185+ private:
186+ bool hasIsolationRegionInfo () const { return bool (regionInfo); }
187+
188+ // / Set the isolation region info for this TrackableValueState. Private so it
189+ // / can only be used by RegionAnalysisValueMap::getTrackableValue.
190+ void setIsolationRegionInfo (SILIsolationInfo newRegionInfo) {
191+ assert (!regionInfo.has_value () &&
192+ " Can only call setIsolationRegionInfo once!\n " );
193+ regionInfo = newRegionInfo;
194+ }
173195};
174196
175197// / The representative value of the equivalence class that makes up a tracked
@@ -358,9 +380,17 @@ class RegionAnalysisValueMap {
358380 TrackableValue
359381 getActorIntroducingRepresentative (SILInstruction *introducingInst,
360382 SILIsolationInfo isolation) const ;
361- bool mergeIsolationRegionInfo (SILValue value, SILIsolationInfo isolation);
362383 bool valueHasID (SILValue value, bool dumpIfHasNoID = false );
363384 Element lookupValueID (SILValue value);
385+
386+ // / Initialize a TrackableValue with a SILIsolationInfo that we already know
387+ // / instead of inferring.
388+ // /
389+ // / If we successfully initialize \p value with \p info, returns
390+ // / {TrackableValue(), true}. If we already had a TrackableValue, we return
391+ // / {TrackableValue(), false}.
392+ std::pair<TrackableValue, bool >
393+ initializeTrackableValue (SILValue value, SILIsolationInfo info) const ;
364394};
365395
366396class RegionAnalysisFunctionInfo {
0 commit comments