Skip to content

[region-isolation] Improve errors around strong transferring and wordsmith main error #71823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion include/swift/AST/DiagnosticsSIL.def
Original file line number Diff line number Diff line change
Expand Up @@ -971,11 +971,21 @@ NOTE(regionbasedisolation_isolated_since_in_same_region_basename, none,
//

ERROR(regionbasedisolation_named_transfer_yields_race, none,
"transferring non-Sendable value %0 could yield races with later accesses",
"transferring %0 may cause a race",
(Identifier))
ERROR(regionbasedisolation_stronglytransfer_assignment_yields_race_name, none,
"assigning %0 to transferring parameter %1 may cause a race",
(Identifier, Identifier))
NOTE(regionbasedisolation_stronglytransfer_taskisolated_assign_note, none,
"%0 is a task isolated value that is assigned into transferring parameter %1. Transferred uses of %1 may race with caller uses of %0",
(Identifier, Identifier))

NOTE(regionbasedisolation_named_info_transfer_yields_race, none,
"%0 is transferred from %1 caller to %2 callee. Later uses in caller could race with potential uses in callee",
(Identifier, ActorIsolation, ActorIsolation))
NOTE(regionbasedisolation_transfer_non_transferrable_named_note, none,
"transferring %1 %0 to %2 callee could cause races between %2 and %1 uses",
(Identifier, ActorIsolation, ActorIsolation))
NOTE(regionbasedisolation_named_info_isolated_capture, none,
"%1 value %0 is captured by %2 closure. Later local uses could race",
(Identifier, ActorIsolation, ActorIsolation))
Expand Down
30 changes: 30 additions & 0 deletions include/swift/SILOptimizer/Utils/VariableNameUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef SWIFT_SILOPTIMIZER_UTILS_VARIABLENAMEUTILS_H
#define SWIFT_SILOPTIMIZER_UTILS_VARIABLENAMEUTILS_H

#include "swift/Basic/OptionSet.h"
#include "swift/SIL/ApplySite.h"
#include "swift/SIL/DebugUtils.h"
#include "swift/SIL/MemAccessUtils.h"
Expand All @@ -26,6 +27,19 @@
namespace swift {

class VariableNameInferrer {
public:
enum class Flag {
/// If set then we should look through get and set accessors and infer their
/// name from self.
///
/// DISCUSSION: This may not be the correct semantics for all name inference
/// since we may want to consider computed properties to be tied to self.
InferSelfThroughAllAccessors = 0x1,
};

using Options = OptionSet<Flag>;

private:
/// The stacklist that we use to process from use->
StackList<PointerUnion<SILInstruction *, SILValue>> variableNamePath;

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

/// Options that control how we do our walk.
///
/// Example: In certain cases we may want to impute self as a name for
/// computed getters/setters and in other cases we may not want to.
Options options;

public:
VariableNameInferrer(SILFunction *fn, SmallString<64> &resultingString)
: variableNamePath(fn), resultingString(resultingString) {}

VariableNameInferrer(SILFunction *fn, Options options,
SmallString<64> &resultingString)
: variableNamePath(fn), resultingString(resultingString),
options(options) {}

/// Attempts to infer a name from just uses of \p searchValue.
///
/// Returns true if we found a name.
Expand Down Expand Up @@ -100,11 +125,16 @@ class VariableNameInferrer {

private:
void drainVariableNamePath();
void popSingleVariableName();

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

/// Do not call this directly. Used just to improve logging for
/// findDebugInfoProvidingValue.
SILValue findDebugInfoProvidingValueHelper(SILValue searchValue);

/// Given an initialized once allocation inst without a ValueDecl or a
/// DebugVariable provided name, attempt to find a root value from its
/// initialization.
Expand Down
Loading