mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
* spelling: accessor Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: accommodates Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: argument Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: associated Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: availability Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: available Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: belongs Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: bookkeeping Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: building Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: clazz Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: clonable Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: closure Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: concatenated Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: conformance Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: context Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: conversion Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: correspondence Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: declarations Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: declared Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: defining Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: delayed Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: dependency Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: deployed Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: descendants Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: diagnose Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: diagnostic Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: equitable Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: evaluation Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: exclusivity Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: existence Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: existential Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: explicit Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: expressed Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: for Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: foreign Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: function Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: identifier Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: implicit Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: indices Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: information Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: instance Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: interchangeable Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: interface Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: introduced Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: invalid Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: kind-in Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: least Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: library Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: location Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: namespace Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: necessary Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: nonexistent Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: not Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: number Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: obtains Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: occurs Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: opaque Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: overridden Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: parameter Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: precede Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: preceding Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: property Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: protocol Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: qualified Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: recognized Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: recursively Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: references Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: relaxing Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: represented Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: request Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: requirement Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: requirements Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: retrieve Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: returned Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: satisfied Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: satisfy Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: scanner Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: siblings Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: simplified Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: something Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: source Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: specializations Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: specially Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: statement Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: stripped Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: structure Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: substitution Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: the Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: transform Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: transformed Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: transitively Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: transparent Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: typecheck Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: unknown Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: unlabeled Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: unqualified Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: whether Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: with Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: scanner Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
129 lines
4.8 KiB
C++
129 lines
4.8 KiB
C++
//===--- RuleBuilder.h - Lowering desugared requirements to rules ---------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2021 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_RULEBUILDER_H
|
|
#define SWIFT_RULEBUILDER_H
|
|
|
|
#include "swift/AST/ASTContext.h"
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
#include "llvm/ADT/DenseSet.h"
|
|
#include "llvm/ADT/SmallVector.h"
|
|
#include <vector>
|
|
#include "RewriteContext.h"
|
|
#include "Rule.h"
|
|
#include "Symbol.h"
|
|
#include "Term.h"
|
|
|
|
namespace llvm {
|
|
class raw_ostream;
|
|
}
|
|
|
|
namespace swift {
|
|
|
|
class AssociatedTypeDecl;
|
|
class ProtocolDecl;
|
|
class ProtocolTypeAlias;
|
|
class Requirement;
|
|
|
|
namespace rewriting {
|
|
|
|
/// A utility class for building rewrite rules from the top-level requirements
|
|
/// of a generic signature.
|
|
///
|
|
/// This also collects requirements from the transitive closure of all protocols
|
|
/// appearing on the right hand side of conformance requirements.
|
|
struct RuleBuilder {
|
|
RewriteContext &Context;
|
|
|
|
/// The transitive closure of all protocols appearing on the right hand
|
|
/// side of conformance requirements.
|
|
llvm::DenseSet<const ProtocolDecl *> &ReferencedProtocols;
|
|
|
|
/// A subset of the above in insertion order, consisting of the protocols
|
|
/// whose rules we are going to import.
|
|
///
|
|
/// If this is a rewrite system built from a generic signature, this vector
|
|
/// contains all elements in the above set.
|
|
///
|
|
/// If this is a rewrite system built from a strongly connected component
|
|
/// of the protocol, this vector contains all elements in the above set
|
|
/// except for the protocols belonging to the component representing the
|
|
/// rewrite system itself; those protocols are added directly instead of
|
|
/// being imported.
|
|
std::vector<const ProtocolDecl *> ProtocolsToImport;
|
|
|
|
/// The rules representing a complete rewrite system for the above vector,
|
|
/// pulled in by collectRulesFromReferencedProtocols().
|
|
std::vector<Rule> ImportedRules;
|
|
|
|
/// New rules to add which will be marked 'permanent'. These are rules for
|
|
/// introducing associated types, and relationships between layout,
|
|
/// superclass and concrete type symbols. They are not eliminated by
|
|
/// homotopy reduction, since they are always added when the rewrite system
|
|
/// is built.
|
|
std::vector<std::pair<MutableTerm, MutableTerm>> PermanentRules;
|
|
|
|
/// New rules derived from requirements written by the user, which can be
|
|
/// eliminated by homotopy reduction.
|
|
std::vector<std::tuple<MutableTerm, MutableTerm, Optional<unsigned>>>
|
|
RequirementRules;
|
|
|
|
/// Requirements written in source code. The requirement ID in the above
|
|
/// \c RequirementRules vector is an index into this array.
|
|
std::vector<StructuralRequirement> WrittenRequirements;
|
|
|
|
/// Enables debugging output. Controlled by the -dump-requirement-machine
|
|
/// frontend flag.
|
|
unsigned Dump : 1;
|
|
|
|
/// Used to ensure the initWith*() methods are only called once.
|
|
unsigned Initialized : 1;
|
|
|
|
RuleBuilder(RewriteContext &ctx,
|
|
llvm::DenseSet<const ProtocolDecl *> &referencedProtocols)
|
|
: Context(ctx), ReferencedProtocols(referencedProtocols) {
|
|
Dump = ctx.getASTContext().LangOpts.DumpRequirementMachine;
|
|
Initialized = 0;
|
|
}
|
|
|
|
void initWithGenericSignatureRequirements(ArrayRef<Requirement> requirements);
|
|
void initWithWrittenRequirements(ArrayRef<StructuralRequirement> requirements);
|
|
void initWithProtocolSignatureRequirements(ArrayRef<const ProtocolDecl *> proto);
|
|
void initWithProtocolWrittenRequirements(
|
|
ArrayRef<const ProtocolDecl *> component,
|
|
const llvm::DenseMap<const ProtocolDecl *,
|
|
SmallVector<StructuralRequirement, 4>> protos);
|
|
void initWithConditionalRequirements(ArrayRef<Requirement> requirements,
|
|
ArrayRef<Term> substitutions);
|
|
void addReferencedProtocol(const ProtocolDecl *proto);
|
|
void collectRulesFromReferencedProtocols();
|
|
|
|
private:
|
|
void addPermanentProtocolRules(const ProtocolDecl *proto);
|
|
void addAssociatedType(const AssociatedTypeDecl *type,
|
|
const ProtocolDecl *proto);
|
|
void addRequirement(const Requirement &req,
|
|
const ProtocolDecl *proto,
|
|
Optional<ArrayRef<Term>> substitutions=None,
|
|
Optional<unsigned> requirementID=None);
|
|
void addRequirement(const StructuralRequirement &req,
|
|
const ProtocolDecl *proto);
|
|
void addTypeAlias(const ProtocolTypeAlias &alias,
|
|
const ProtocolDecl *proto);
|
|
};
|
|
|
|
} // end namespace rewriting
|
|
|
|
} // end namespace swift
|
|
|
|
#endif
|