Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
09bf4cb
[NFC] Fixing some stdlib unused warnings
LucianoPAlmeida Feb 20, 2022
bf820c5
[CSDiagnostics] Look through l-value conversions when mismatch is in …
xedin Feb 22, 2022
034c4bd
[Sema] Attempt diagnose generic arg ambiguity if all solutions produc…
LucianoPAlmeida Feb 22, 2022
0f67926
[move-function-value] Make sure that we propagate the debug scope fro…
gottesmm Feb 23, 2022
e766b44
Revert "Revert "[SSADestroyHoisting] Split destroy from copy.""
nate-chandler Feb 23, 2022
ac7e28a
[alloc-stack-hoisting] Handle alloc_stack [move] correctly.
gottesmm Feb 18, 2022
90893b9
AST: Types are immutable so there's no reason for TypeBase::findUnres…
slavapestov Feb 19, 2022
a3ab5f4
RequirementMachine: Remove no-longer used DebugFlags::Merge
slavapestov Feb 19, 2022
e326c01
RequirementMachine: Write some comments
slavapestov Feb 18, 2022
ae1ef6d
RequirementMachine: Eliminate RequirementMachine::initWithAbstractReq…
slavapestov Feb 19, 2022
d36aecc
Diag: Make 'could_not_use_member_on_existential' less assertive
AnthonyLatsis Feb 16, 2022
f239dbc
[SE-309] CSDiag: Add a fix-it that replaces an existential parameter …
AnthonyLatsis Feb 4, 2022
88dc3ad
Sema: Fix interface type computation for observer parameters
AnthonyLatsis Feb 19, 2022
2342712
[NFC] Reorganize a few SE-309 test cases with opaque result types
AnthonyLatsis Feb 22, 2022
dd8d5b8
Merge pull request #41521 from gottesmm/pr-7a4df70e3efbb5bb8a409952b2…
gottesmm Feb 23, 2022
350d039
Merge pull request #41523 from gottesmm/alloc-stack-hoisting-fix
gottesmm Feb 23, 2022
ddc2065
Merge pull request #41198 from AnthonyLatsis/se-309-fixit
AnthonyLatsis Feb 23, 2022
4bef7bf
Merge pull request #41506 from LucianoPAlmeida/SR-15843-generic-ambig…
LucianoPAlmeida Feb 23, 2022
1218d7f
Merge pull request #41489 from LucianoPAlmeida/minor-nfc-warnings
LucianoPAlmeida Feb 23, 2022
8e071f7
Merge pull request #41522 from apple/revert-41518-revert-41497-lexica…
nate-chandler Feb 23, 2022
0220728
[Gardening] Tweaked verifier wording.
nate-chandler Feb 23, 2022
039eb10
Mark stdlib/Assert-debugPrecondition-off.swift as REQUIRES: executabl…
mikeash Feb 23, 2022
c22649e
Merge pull request #41504 from xedin/rdar-84580119
xedin Feb 23, 2022
f6b2e2e
Fix invalid warning for enum cases named self (#41520)
keith Feb 23, 2022
efa055c
Merge pull request #41524 from slavapestov/rqm-tiny-cleanup-and-comments
slavapestov Feb 23, 2022
61cc49e
Merge pull request #41528 from mikeash/fix-Assert-debugPrecondition-o…
mikeash Feb 23, 2022
a9a512d
Merge pull request #41527 from nate-chandler/gardening/verifier-wording
nate-chandler Feb 23, 2022
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
4 changes: 2 additions & 2 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ ERROR(could_not_use_instance_member_on_type,none,
"%select{| instance of nested}3 type %0",
(Type, DeclNameRef, Type, bool))
ERROR(could_not_use_member_on_existential,none,
"member %1 cannot be used on value of protocol type %0; use a generic"
" constraint instead",
"member %1 cannot be used on value of protocol type %0; consider using a"
" generic constraint instead",
(Type, DeclNameRef))
FIXIT(replace_with_type,"%0",(Type))
FIXIT(insert_type_qualification,"%0.",(Type))
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
///
/// "Unresolved" dependent member types have no known associated type,
/// and are only used transiently in the type checker.
const DependentMemberType *findUnresolvedDependentMemberType();
DependentMemberType *findUnresolvedDependentMemberType();

/// Return the root generic parameter of this type parameter type.
GenericTypeParamType *getRootGenericParam();
Expand Down
30 changes: 30 additions & 0 deletions include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -1963,6 +1963,22 @@ class AllocStackInst final
/// any point of the program.
bool wasMoved = false;

/// Set to true if this AllocStack has var info that a pass purposely
/// invalidated.
///
/// NOTE:
///
/// 1. We don't print this state. It is just a way to invalidate the debug
/// info. When we parse back in whatever we printed, we will parse it without
/// debug var info since none will be printed.
///
/// 2. Since we do not serialize debug info today, we do not need to serialize
/// this state.
///
/// TODO: If we begin serializing debug info, we will need to begin
/// serializing this!
bool hasInvalidatedVarInfo = false;

AllocStackInst(SILDebugLocation Loc, SILType elementType,
ArrayRef<SILValue> TypeDependentOperands, SILFunction &F,
Optional<SILDebugVariable> Var, bool hasDynamicLifetime,
Expand Down Expand Up @@ -2019,6 +2035,12 @@ class AllocStackInst final

/// Return the debug variable information attached to this instruction.
Optional<SILDebugVariable> getVarInfo() const {
// If we used to have debug info attached but our debug info is now
// invalidated, just bail.
if (hasInvalidatedVarInfo) {
return None;
}

Optional<SILType> AuxVarType;
Optional<SILLocation> VarDeclLoc;
const SILDebugScope *VarDeclScope = nullptr;
Expand All @@ -2039,6 +2061,14 @@ class AllocStackInst final
VarDeclScope, DIExprElements);
}

bool isVarInfoInvalidated() const { return hasInvalidatedVarInfo; }

/// Invalidate the debug info in an alloc_stack. This is useful in cases where
/// we one is merging alloc_stack and wants to split the debug info on an
/// alloc_stack into a separate debug_value instruction from the merged
/// alloc_stack.
void invalidateVarInfo() { hasInvalidatedVarInfo = true; }

bool isLet() const {
if (auto varInfo = getVarInfo())
return varInfo->isLet();
Expand Down
27 changes: 12 additions & 15 deletions lib/AST/RequirementMachine/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,42 @@ enum class DebugFlags : unsigned {
/// Print debug output when adding rules.
Add = (1<<1),

/// Print debug output when merging associated types.
Merge = (1<<2),

/// Print debug output from the Knuth-Bendix algorithm.
Completion = (1<<3),
Completion = (1<<2),

/// Print debug output from property map construction.
PropertyMap = (1<<4),
PropertyMap = (1<<3),

/// Print debug output when unifying concrete types in the property map.
ConcreteUnification = (1<<5),
ConcreteUnification = (1<<4),

/// Print debug output when concretizing nested types in the property map.
ConcretizeNestedTypes = (1<<6),
ConcretizeNestedTypes = (1<<5),

/// Print debug output when inferring conditional requirements in the
/// property map.
ConditionalRequirements = (1<<7),
ConditionalRequirements = (1<<6),

/// Print debug output from the homotopy reduction algorithm.
HomotopyReduction = (1<<8),
HomotopyReduction = (1<<7),

/// Print more detailed debug output from the homotopy reduction algorithm.
HomotopyReductionDetail = (1<<9),
HomotopyReductionDetail = (1<<8),

/// Print debug output from the minimal conformances algorithm.
MinimalConformances = (1<<10),
MinimalConformances = (1<<9),

/// Print debug output from the protocol dependency graph.
ProtocolDependencies = (1<<11),
ProtocolDependencies = (1<<10),

/// Print debug output from generic signature minimization.
Minimization = (1<<12),
Minimization = (1<<11),

/// Print redundant rules and their replacement paths.
RedundantRules = (1<<13),
RedundantRules = (1<<12),

/// Print more detail about redundant rules.
RedundantRulesDetail = (1<<14)
RedundantRulesDetail = (1<<13)
};

using DebugOptions = OptionSet<DebugFlags>;
Expand Down
75 changes: 24 additions & 51 deletions lib/AST/RequirementMachine/RequirementMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,46 @@ RequirementMachine::RequirementMachine(RewriteContext &ctx)

RequirementMachine::~RequirementMachine() {}

static void checkCompletionResult(const RequirementMachine &machine,
CompletionResult result) {
/// Checks the result of a completion in a context where we can't diagnose
/// failure, either when building a rewrite system from an existing
/// minimal signature (which should have been checked when it was
/// minimized) or from AbstractGenericSignatureRequest (where failure
/// is fatal).
void RequirementMachine::checkCompletionResult(CompletionResult result) const {
switch (result) {
case CompletionResult::Success:
break;

case CompletionResult::MaxRuleCount:
llvm::errs() << "Rewrite system exceeded maximum rule count\n";
machine.dump(llvm::errs());
dump(llvm::errs());
abort();

case CompletionResult::MaxRuleLength:
llvm::errs() << "Rewrite system exceeded rule length limit\n";
machine.dump(llvm::errs());
dump(llvm::errs());
abort();

case CompletionResult::MaxConcreteNesting:
llvm::errs() << "Rewrite system exceeded concrete type nesting depth limit\n";
machine.dump(llvm::errs());
dump(llvm::errs());
abort();
}
}

/// Build a requirement machine for the requirements of a generic signature.
///
/// In this mode, minimization is not going to be performed, so rewrite loops
/// are not recorded.
///
/// This must only be called exactly once, before any other operations are
/// performed on this requirement machine.
///
/// Used by ASTContext::getOrCreateRequirementMachine().
///
/// Asserts if completion fails within the configured number of steps.
void RequirementMachine::initWithGenericSignature(CanGenericSignature sig) {
/// Returns failure if completion fails within the configured number of steps.
std::pair<CompletionResult, unsigned>
RequirementMachine::initWithGenericSignature(CanGenericSignature sig) {
Sig = sig;
Params.append(sig.getGenericParams().begin(),
sig.getGenericParams().end());
Expand All @@ -92,17 +100,21 @@ void RequirementMachine::initWithGenericSignature(CanGenericSignature sig) {
std::move(builder.RequirementRules));

auto result = computeCompletion(RewriteSystem::DisallowInvalidRequirements);
checkCompletionResult(*this, result.first);

if (Dump) {
llvm::dbgs() << "}\n";
}

return result;
}

/// Build a requirement machine for the structural requirements of a set
/// of protocols, which are understood to form a strongly-connected component
/// (SCC) of the protocol dependency graph.
///
/// In this mode, minimization will be performed, so rewrite loops are recorded
/// during completion.
///
/// This must only be called exactly once, before any other operations are
/// performed on this requirement machine.
///
Expand Down Expand Up @@ -138,55 +150,16 @@ RequirementMachine::initWithProtocols(ArrayRef<const ProtocolDecl *> protos) {
return result;
}

/// Build a requirement machine from a set of generic parameters and
/// (possibly non-canonical or non-minimal) abstract requirements.
///
/// This must only be called exactly once, before any other operations are
/// performed on this requirement machine.
///
/// Used by AbstractGenericSignatureRequest.
///
/// Asserts if completion fails within the configured number of steps.
void RequirementMachine::initWithAbstractRequirements(
ArrayRef<GenericTypeParamType *> genericParams,
ArrayRef<Requirement> requirements) {
Params.append(genericParams.begin(), genericParams.end());

FrontendStatsTracer tracer(Stats, "build-rewrite-system");

if (Dump) {
llvm::dbgs() << "Adding generic parameters:";
for (auto *paramTy : genericParams)
llvm::dbgs() << " " << Type(paramTy);
llvm::dbgs() << "\n";
}

// Collect the top-level requirements, and all transtively-referenced
// protocol requirement signatures.
RuleBuilder builder(Context, System.getProtocolMap());
builder.addRequirements(requirements);

// Add the initial set of rewrite rules to the rewrite system.
System.initialize(/*recordLoops=*/true,
/*protos=*/ArrayRef<const ProtocolDecl *>(),
std::move(builder.PermanentRules),
std::move(builder.RequirementRules));

auto result = computeCompletion(RewriteSystem::AllowInvalidRequirements);
checkCompletionResult(*this, result.first);

if (Dump) {
llvm::dbgs() << "}\n";
}
}

/// Build a requirement machine from a set of generic parameters and
/// structural requirements.
///
/// In this mode, minimization will be performed, so rewrite loops are recorded
/// during completion.
///
/// This must only be called exactly once, before any other operations are
/// performed on this requirement machine.
///
/// Used by InferredGenericSignatureRequest.
/// Used by AbstractGenericSignatureRequest and InferredGenericSignatureRequest.
///
/// Returns failure if completion fails within the configured number of steps.
std::pair<CompletionResult, unsigned>
Expand Down
10 changes: 6 additions & 4 deletions lib/AST/RequirementMachine/RequirementMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ class RequirementMachine final {
RequirementMachine &operator=(const RequirementMachine &) = delete;
RequirementMachine &operator=(RequirementMachine &&) = delete;

void initWithGenericSignature(CanGenericSignature sig);
void checkCompletionResult(CompletionResult result) const;

std::pair<CompletionResult, unsigned>
initWithGenericSignature(CanGenericSignature sig);

std::pair<CompletionResult, unsigned>
initWithProtocols(ArrayRef<const ProtocolDecl *> protos);
void initWithAbstractRequirements(
ArrayRef<GenericTypeParamType *> genericParams,
ArrayRef<Requirement> requirements);

std::pair<CompletionResult, unsigned>
initWithWrittenRequirements(
ArrayRef<GenericTypeParamType *> genericParams,
Expand Down
21 changes: 14 additions & 7 deletions lib/AST/RequirementMachine/RequirementMachineRequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,9 @@ AbstractGenericSignatureRequestRQM::evaluate(
return GenericSignatureWithError(result, /*hadError=*/false);
}

SmallVector<Requirement, 4> requirements(
baseSignature.getRequirements().begin(),
baseSignature.getRequirements().end());
SmallVector<StructuralRequirement, 4> requirements;
for (auto req : baseSignature.getRequirements())
requirements.push_back({req, SourceLoc(), /*wasInferred=*/false});

// We need to create this errors vector to pass to
// desugarRequirement, but this request should never
Expand All @@ -492,14 +492,20 @@ AbstractGenericSignatureRequestRQM::evaluate(
// Desugaring converts these kinds of requirements into "proper"
// requirements where the subject type is always a type parameter,
// which is what the RuleBuilder expects.
for (auto req : addedRequirements)
desugarRequirement(req, requirements, errors);
for (auto req : addedRequirements) {
SmallVector<Requirement, 2> reqs;
desugarRequirement(req, reqs, errors);
for (auto req : reqs)
requirements.push_back({req, SourceLoc(), /*wasInferred=*/false});
}

// Heap-allocate the requirement machine to save stack space.
std::unique_ptr<RequirementMachine> machine(new RequirementMachine(
ctx.getRewriteContext()));

machine->initWithAbstractRequirements(genericParams, requirements);
auto status =
machine->initWithWrittenRequirements(genericParams, requirements);
machine->checkCompletionResult(status.first);

auto minimalRequirements =
machine->computeMinimalGenericSignatureRequirements();
Expand Down Expand Up @@ -611,7 +617,8 @@ InferredGenericSignatureRequestRQM::evaluate(
std::unique_ptr<RequirementMachine> machine(new RequirementMachine(
ctx.getRewriteContext()));

auto status = machine->initWithWrittenRequirements(genericParams, requirements);
auto status =
machine->initWithWrittenRequirements(genericParams, requirements);
if (status.first != CompletionResult::Success) {
ctx.Diags.diagnose(loc,
diag::requirement_machine_completion_failed,
Expand Down
5 changes: 3 additions & 2 deletions lib/AST/RequirementMachine/RewriteContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ static DebugOptions parseDebugFlags(StringRef debugFlags) {
auto flag = llvm::StringSwitch<Optional<DebugFlags>>(flagStr)
.Case("simplify", DebugFlags::Simplify)
.Case("add", DebugFlags::Add)
.Case("merge", DebugFlags::Merge)
.Case("completion", DebugFlags::Completion)
.Case("property-map", DebugFlags::PropertyMap)
.Case("concrete-unification", DebugFlags::ConcreteUnification)
Expand Down Expand Up @@ -134,7 +133,9 @@ RequirementMachine *RewriteContext::getRequirementMachine(

// This might re-entrantly invalidate 'machine', which is a reference
// into Protos.
newMachine->initWithGenericSignature(sig);
auto status = newMachine->initWithGenericSignature(sig);
newMachine->checkCompletionResult(status.first);

return newMachine;
}

Expand Down
Loading