Skip to content

Commit afcd1fb

Browse files
authored
Merge pull request #73150 from gottesmm/release/6.0-region-iso
[6.0][region-isolation] Cherry-pick recent work
2 parents 5b0f7f7 + 241fca5 commit afcd1fb

36 files changed

+3035
-1147
lines changed

docs/DebuggingTheCompiler.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ benefit of all Swift developers.
4949
- [Manually symbolication using LLDB](#manually-symbolication-using-lldb)
5050
- [Viewing allocation history, references, and page-level info](#viewing-allocation-history-references-and-page-level-info)
5151
- [Printing memory contents](#printing-memory-contents)
52+
- [Windows Error Codes](#windows-error-codes)
5253
- [Debugging LLDB failures](#debugging-lldb-failures)
5354
- ["Types" Log](#types-log)
5455
- ["Expression" Log](#expression-log)
@@ -1058,6 +1059,36 @@ The following specifiers are available:
10581059
* w - word (32-bit value)
10591060
* g - giant word (64-bit value)
10601061

1062+
## Windows Error Codes
1063+
1064+
When debugging programs on Windows, sometimes one will run into an error message with a mysterious error code. E.x.:
1065+
1066+
```
1067+
note: command had no output on stdout or stderr
1068+
error: command failed with exit status: 0xc0000135
1069+
```
1070+
1071+
These on windows are called HRESULT values. In the case above, the HRESULT is telling me that a DLL was not found. I discovered this
1072+
by running the Microsoft provided [System Error Code Lookup Tool](https://learn.microsoft.com/en-us/windows/win32/debug/system-error-code-lookup-tool). After running
1073+
this tool with the relevant error code on a windows machine, I got back the following result:
1074+
1075+
```
1076+
# for hex 0xc0000135 / decimal -1073741515
1077+
STATUS_DLL_NOT_FOUND ntstatus.h
1078+
# The code execution cannot proceed because %hs was not
1079+
# found. Reinstalling the program may fix this problem.
1080+
# as an HRESULT: Severity: FAILURE (1), FACILITY_NULL (0x0), Code 0x135
1081+
# for hex 0x135 / decimal 309
1082+
ERROR_NOTIFICATION_GUID_ALREADY_DEFINED winerror.h
1083+
# The specified file already has a notification GUID
1084+
# associated with it.
1085+
```
1086+
1087+
Some relevant Microsoft documentation:
1088+
1089+
* https://learn.microsoft.com/en-us/windows/win32/seccrypto/common-hresult-values
1090+
* https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/0642cb2f-2075-4469-918c-4441e69c548a
1091+
* https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-
10611092

10621093
# Debugging LLDB failures
10631094

include/swift/AST/DiagnosticsSIL.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ NOTE(regionbasedisolation_isolated_since_in_same_region_basename, none,
971971
//
972972

973973
ERROR(regionbasedisolation_named_transfer_yields_race, none,
974-
"transferring %0 may cause a race",
974+
"transferring %0 may cause a data race",
975975
(Identifier))
976976

977977
NOTE(regionbasedisolation_named_info_transfer_yields_race, none,

include/swift/SIL/SILType.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,8 +911,16 @@ class SILType {
911911

912912
bool isMarkedAsImmortal() const;
913913

914+
/// Returns true if this type is an actor type. Returns false if this is any
915+
/// other type. This includes distributed actors. To check for distributed
916+
/// actors and actors, use isAnyActor().
914917
bool isActor() const { return getASTType()->isActorType(); }
915918

919+
bool isDistributedActor() const { return getASTType()->isDistributedActor(); }
920+
921+
/// Returns true if this type is an actor or a distributed actor.
922+
bool isAnyActor() const { return getASTType()->isAnyActorType(); }
923+
916924
/// Returns true if this function conforms to the Sendable protocol.
917925
bool isSendable(SILFunction *fn) const;
918926

include/swift/SILOptimizer/Analysis/RegionAnalysis.h

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class RegionAnalysisFunctionInfo;
2828
namespace regionanalysisimpl {
2929

3030
using TransferringOperandSetFactory = Partition::TransferringOperandSetFactory;
31-
using TrackableValueID = PartitionPrimitives::Element;
31+
using Element = PartitionPrimitives::Element;
3232
using Region = PartitionPrimitives::Region;
3333

3434
/// Check if the passed in type is NonSendable.
@@ -88,9 +88,13 @@ class BlockPartitionState {
8888

8989
TransferringOperandSetFactory &ptrSetFactory;
9090

91+
TransferringOperandToStateMap &transferringOpToStateMap;
92+
9193
BlockPartitionState(SILBasicBlock *basicBlock,
9294
PartitionOpTranslator &translator,
93-
TransferringOperandSetFactory &ptrSetFactory);
95+
TransferringOperandSetFactory &ptrSetFactory,
96+
IsolationHistory::Factory &isolationHistoryFactory,
97+
TransferringOperandToStateMap &transferringOpToStateMap);
9498

9599
public:
96100
bool getLiveness() const { return isLive; }
@@ -171,7 +175,7 @@ class regionanalysisimpl::TrackableValueState {
171175

172176
SILIsolationInfo getIsolationRegionInfo() const { return regionInfo; }
173177

174-
TrackableValueID getID() const { return TrackableValueID(id); }
178+
Element getID() const { return Element(id); }
175179

176180
void addFlag(TrackableValueFlag flag) { flagSet |= flag; }
177181

@@ -182,7 +186,7 @@ class regionanalysisimpl::TrackableValueState {
182186
<< "][is_no_alias: " << (isNoAlias() ? "yes" : "no")
183187
<< "][is_sendable: " << (isSendable() ? "yes" : "no")
184188
<< "][region_value_kind: ";
185-
getIsolationRegionInfo().print(os);
189+
getIsolationRegionInfo().printForDiagnostics(os);
186190
os << "].";
187191
}
188192

@@ -272,9 +276,7 @@ class regionanalysisimpl::TrackableValue {
272276
return valueState.getIsolationRegionInfo();
273277
}
274278

275-
TrackableValueID getID() const {
276-
return TrackableValueID(valueState.getID());
277-
}
279+
Element getID() const { return Element(valueState.getID()); }
278280

279281
/// Return the representative value of this equivalence class of values.
280282
RepresentativeValue getRepresentative() const { return representativeValue; }
@@ -285,6 +287,11 @@ class regionanalysisimpl::TrackableValue {
285287
/// parameter.
286288
bool isTransferringParameter() const;
287289

290+
void printIsolationInfo(SmallString<64> &outString) const {
291+
llvm::raw_svector_ostream os(outString);
292+
getIsolationRegionInfo().printForDiagnostics(os);
293+
}
294+
288295
void print(llvm::raw_ostream &os) const {
289296
os << "TrackableValue. State: ";
290297
valueState.print(os);
@@ -311,7 +318,6 @@ class RegionAnalysisValueMap {
311318
using Region = PartitionPrimitives::Region;
312319
using TrackableValue = regionanalysisimpl::TrackableValue;
313320
using TrackableValueState = regionanalysisimpl::TrackableValueState;
314-
using TrackableValueID = Element;
315321
using RepresentativeValue = regionanalysisimpl::RepresentativeValue;
316322

317323
private:
@@ -365,14 +371,14 @@ class RegionAnalysisValueMap {
365371
SILInstruction *introducingInst) const;
366372

367373
private:
368-
std::optional<TrackableValue> getValueForId(TrackableValueID id) const;
374+
std::optional<TrackableValue> getValueForId(Element id) const;
369375
std::optional<TrackableValue> tryToTrackValue(SILValue value) const;
370376
TrackableValue
371377
getActorIntroducingRepresentative(SILInstruction *introducingInst,
372378
SILIsolationInfo isolation) const;
373379
bool mergeIsolationRegionInfo(SILValue value, SILIsolationInfo isolation);
374380
bool valueHasID(SILValue value, bool dumpIfHasNoID = false);
375-
TrackableValueID lookupValueID(SILValue value);
381+
Element lookupValueID(SILValue value);
376382
};
377383

378384
class RegionAnalysisFunctionInfo {
@@ -394,6 +400,10 @@ class RegionAnalysisFunctionInfo {
394400

395401
TransferringOperandSetFactory ptrSetFactory;
396402

403+
IsolationHistory::Factory isolationHistoryFactory;
404+
405+
TransferringOperandToStateMap transferringOpToStateMap;
406+
397407
// We make this optional to prevent an issue that we have seen on windows when
398408
// capturing a field in a closure that is used to initialize a different
399409
// field.
@@ -489,6 +499,16 @@ class RegionAnalysisFunctionInfo {
489499
return valueMap;
490500
}
491501

502+
IsolationHistory::Factory &getIsolationHistoryFactory() {
503+
assert(supportedFunction && "Unsupported Function?!");
504+
return isolationHistoryFactory;
505+
}
506+
507+
TransferringOperandToStateMap &getTransferringOpToStateMap() {
508+
assert(supportedFunction && "Unsupported Function?!");
509+
return transferringOpToStateMap;
510+
}
511+
492512
bool isClosureCaptured(SILValue value, Operand *op);
493513

494514
static SILValue getUnderlyingTrackedValue(SILValue value);

0 commit comments

Comments
 (0)