Skip to content

Commit a703f22

Browse files
authored
Merge pull request #71823 from gottesmm/strong_transferring
[region-isolation] Improve errors around strong transferring and wordsmith main error
2 parents 41add6d + b157368 commit a703f22

18 files changed

+1477
-594
lines changed

include/swift/AST/DiagnosticsSIL.def

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

973973
ERROR(regionbasedisolation_named_transfer_yields_race, none,
974-
"transferring non-Sendable value %0 could yield races with later accesses",
974+
"transferring %0 may cause a race",
975975
(Identifier))
976+
ERROR(regionbasedisolation_stronglytransfer_assignment_yields_race_name, none,
977+
"assigning %0 to transferring parameter %1 may cause a race",
978+
(Identifier, Identifier))
979+
NOTE(regionbasedisolation_stronglytransfer_taskisolated_assign_note, none,
980+
"%0 is a task isolated value that is assigned into transferring parameter %1. Transferred uses of %1 may race with caller uses of %0",
981+
(Identifier, Identifier))
982+
976983
NOTE(regionbasedisolation_named_info_transfer_yields_race, none,
977984
"%0 is transferred from %1 caller to %2 callee. Later uses in caller could race with potential uses in callee",
978985
(Identifier, ActorIsolation, ActorIsolation))
986+
NOTE(regionbasedisolation_transfer_non_transferrable_named_note, none,
987+
"transferring %1 %0 to %2 callee could cause races between %2 and %1 uses",
988+
(Identifier, ActorIsolation, ActorIsolation))
979989
NOTE(regionbasedisolation_named_info_isolated_capture, none,
980990
"%1 value %0 is captured by %2 closure. Later local uses could race",
981991
(Identifier, ActorIsolation, ActorIsolation))

include/swift/SILOptimizer/Utils/VariableNameUtils.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef SWIFT_SILOPTIMIZER_UTILS_VARIABLENAMEUTILS_H
1818
#define SWIFT_SILOPTIMIZER_UTILS_VARIABLENAMEUTILS_H
1919

20+
#include "swift/Basic/OptionSet.h"
2021
#include "swift/SIL/ApplySite.h"
2122
#include "swift/SIL/DebugUtils.h"
2223
#include "swift/SIL/MemAccessUtils.h"
@@ -26,6 +27,19 @@
2627
namespace swift {
2728

2829
class VariableNameInferrer {
30+
public:
31+
enum class Flag {
32+
/// If set then we should look through get and set accessors and infer their
33+
/// name from self.
34+
///
35+
/// DISCUSSION: This may not be the correct semantics for all name inference
36+
/// since we may want to consider computed properties to be tied to self.
37+
InferSelfThroughAllAccessors = 0x1,
38+
};
39+
40+
using Options = OptionSet<Flag>;
41+
42+
private:
2943
/// The stacklist that we use to process from use->
3044
StackList<PointerUnion<SILInstruction *, SILValue>> variableNamePath;
3145

@@ -37,10 +51,21 @@ class VariableNameInferrer {
3751
/// The final string we computed.
3852
SmallString<64> &resultingString;
3953

54+
/// Options that control how we do our walk.
55+
///
56+
/// Example: In certain cases we may want to impute self as a name for
57+
/// computed getters/setters and in other cases we may not want to.
58+
Options options;
59+
4060
public:
4161
VariableNameInferrer(SILFunction *fn, SmallString<64> &resultingString)
4262
: variableNamePath(fn), resultingString(resultingString) {}
4363

64+
VariableNameInferrer(SILFunction *fn, Options options,
65+
SmallString<64> &resultingString)
66+
: variableNamePath(fn), resultingString(resultingString),
67+
options(options) {}
68+
4469
/// Attempts to infer a name from just uses of \p searchValue.
4570
///
4671
/// Returns true if we found a name.
@@ -100,11 +125,16 @@ class VariableNameInferrer {
100125

101126
private:
102127
void drainVariableNamePath();
128+
void popSingleVariableName();
103129

104130
/// Finds the SILValue that either provides the direct debug information or
105131
/// that has a debug_value user that provides the name of the value.
106132
SILValue findDebugInfoProvidingValue(SILValue searchValue);
107133

134+
/// Do not call this directly. Used just to improve logging for
135+
/// findDebugInfoProvidingValue.
136+
SILValue findDebugInfoProvidingValueHelper(SILValue searchValue);
137+
108138
/// Given an initialized once allocation inst without a ValueDecl or a
109139
/// DebugVariable provided name, attempt to find a root value from its
110140
/// initialization.

0 commit comments

Comments
 (0)