Skip to content

Commit dd6422c

Browse files
Merge remote-tracking branch 'apple/main' into katei/merge-main-2023-01-05
2 parents 1b1439b + b205a9c commit dd6422c

File tree

133 files changed

+3203
-1322
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+3203
-1322
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ComputeSideEffects.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ private struct CollectedEffects {
9898
addDestroyEffects(of: inst.operands[0].value)
9999

100100
case let da as DestroyAddrInst:
101+
// A destroy_addr also involves a read from the address. It's equivalent to a `%x = load [take]` and `destroy_value %x`.
102+
addEffects(.read, to: da.operand)
103+
// Conceptually, it's also a write, because the stored value is not available anymore after the destroy
104+
addEffects(.write, to: da.operand)
105+
101106
addDestroyEffects(of: da.operand)
102107

103108
case let copy as CopyAddrInst:
@@ -108,12 +113,16 @@ private struct CollectedEffects {
108113
addEffects(.copy, to: copy.source)
109114
}
110115
if !copy.isInitializationOfDest {
116+
// Like for destroy_addr, the destroy also involves a read.
117+
addEffects(.read, to: copy.destination)
111118
addDestroyEffects(of: copy.destination)
112119
}
113120

114121
case let store as StoreInst:
115122
addEffects(.write, to: store.destination)
116123
if store.destinationOwnership == .assign {
124+
// Like for destroy_addr, the destroy also involves a read.
125+
addEffects(.read, to: store.destination)
117126
addDestroyEffects(of: store.destination)
118127
}
119128

@@ -433,7 +442,8 @@ private struct ArgumentEscapingWalker : ValueDefUseWalker, AddressDefUseWalker {
433442
return .continueWalk
434443

435444
// Warning: all instruction listed here, must also be handled in `CollectedEffects.addInstructionEffects`
436-
case is StoreInst, is StoreWeakInst, is StoreUnownedInst, is ApplySite, is DestroyAddrInst:
445+
case is StoreInst, is StoreWeakInst, is StoreUnownedInst, is ApplySite, is DestroyAddrInst,
446+
is DebugValueInst:
437447
return .continueWalk
438448

439449
default:

SwiftCompilerSources/Sources/Optimizer/Utilities/EscapeUtils.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,10 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
810810
switch effect.kind {
811811
case .escapingToReturn(let toPath, let exclusive):
812812
if exclusive && path.projectionPath.matches(pattern: toPath) {
813-
let arg = apply.arguments[effect.argumentIndex]
813+
guard let callerArgIdx = apply.callerArgIndex(calleeArgIndex: effect.argumentIndex) else {
814+
return .abortWalk
815+
}
816+
let arg = apply.arguments[callerArgIdx]
814817

815818
let p = Path(projectionPath: effect.pathPattern, followStores: path.followStores, knownType: nil)
816819
if walkUp(addressOrValue: arg, path: p) == .abortWalk {

docs/Lexicon.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Apple term for "the person assigned to watch CI this week".
100100

101101
## canonical SIL
102102

103-
SIL after the
103+
[SIL](#sil) after the
104104
[mandatory passes](#mandatory-passes--mandatory-optimizations) have run.
105105
This can be used as input to IRGen to generate LLVM IR or object files.
106106

@@ -179,7 +179,7 @@ The other half is provided by corresponding
179179
## DI (definite initialization / definitive initialization)
180180

181181
The feature that no uninitialized variables, constants, or properties will
182-
be read by a program, or the analysis pass that operates on SIL to
182+
be read by a program, or the analysis pass that operates on [SIL](#sil) to
183183
guarantee this. This was
184184
[discussed on Apple's Swift blog](https://developer.apple.com/swift/blog/?id=28).
185185

@@ -284,6 +284,8 @@ perform structural modification, e.x.:
284284
2. `case let x:`.
285285
3. `case (_, _):`.
286286

287+
Contrast with [refutable pattern](#refutable-pattern)
288+
287289
## IR
288290

289291
1. "intermediate representation": a generic term for a format representing
@@ -327,7 +329,7 @@ The module for the file or files currently being compiled.
327329

328330
## mandatory passes / mandatory optimizations
329331

330-
Transformations over SIL that run immediately after SIL generation. Once
332+
Transformations over [SIL](#sil) that run immediately after SIL generation. Once
331333
all mandatory passes have run (and if no errors are found), the SIL is
332334
considered [canonical](#canonical-SIL).
333335

@@ -359,7 +361,7 @@ Has *many* uses in the Swift world. We may want to rename some of them.
359361
2. A compilation unit; that is, source files that are compiled together.
360362
These files may contain cross-references. Represented as "the main
361363
module" (a specific ModuleDecl).
362-
3. (as "SIL module") A container for SIL to be compiled together, along
364+
3. (as "[SIL](#sil) module") A container for SIL to be compiled together, along
363365
with various context for the compilation.
364366
4. (as "LLVM module") A collection of LLVM IR to be compiled together.
365367
Always created in an LLVMContext.
@@ -491,7 +493,7 @@ on that system.
491493

492494
## raw SIL
493495

494-
SIL just after being generated, not yet in a form that can be used for
496+
[SIL](#sil) just after being generated, not yet in a form that can be used for
495497
IR generation.
496498
See [mandatory passes](#mandatory-passes--mandatory-optimizations).
497499

@@ -540,6 +542,8 @@ A pattern that may not always match. These include patterns such as:
540542
2. Enum case check: e.g. `case .none:`.
541543
3. Expr pattern: e.g. `case foo():`.
542544

545+
Contrast with [irrefutable pattern](#irrefutable-pattern)
546+
543547
## resilient
544548

545549
Describes a type or function where making certain changes will not break
@@ -656,7 +660,7 @@ The value or type that satisfies a protocol requirement.
656660

657661
## witness table
658662

659-
The SIL (and runtime) representation of a [conformance](#conformance); essentially a
663+
The [SIL](#sil) (and runtime) representation of a [conformance](#conformance); essentially a
660664
[vtable](#vtable-virtual-dispatch-table) but for a protocol instead of
661665
a class.
662666

include/swift/ABI/Metadata.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4740,7 +4740,7 @@ using AccessibleFunctionRecord = TargetAccessibleFunctionRecord<InProcess>;
47404740
/// that relates a type attribute is attached to a generator function.
47414741
template <typename Runtime>
47424742
struct TargetRuntimeDiscoverableAttributeEntry {
4743-
ConstTargetMetadataPointer<Runtime, TargetMetadata> Type;
4743+
RelativeDirectPointer<const char, /*nullable*/ false> Type;
47444744
RelativeDirectPointer<TargetAccessibleFunctionRecord<Runtime>> Generator;
47454745
};
47464746

@@ -4759,7 +4759,10 @@ class RuntimeDiscoverableAttributeRecord
47594759
uint32_t flags;
47604760

47614761
/// The nominal type that describes the attribute.
4762-
TargetSignedContextPointer<Runtime, TargetTypeContextDescriptor> Attribute;
4762+
TargetRelativeIndirectablePointer<Runtime,
4763+
TargetTypeContextDescriptor<Runtime>,
4764+
/*nullable*/ false>
4765+
Attribute;
47634766

47644767
/// The number of types this attribute is associated with.
47654768
uint32_t numEntries;

include/swift/AST/ASTContext.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -991,18 +991,20 @@ class ASTContext final {
991991

992992
/// Retrieve the module dependencies for the module with the given name.
993993
///
994-
/// \param isUnderlyingClangModule When true, only look for a Clang module
995-
/// with the given name, ignoring any Swift modules.
996-
Optional<ModuleDependencyInfo> getModuleDependencies(
994+
Optional<const ModuleDependencyInfo*> getModuleDependencies(
997995
StringRef moduleName,
998-
bool isUnderlyingClangModule,
999996
ModuleDependenciesCache &cache,
1000997
InterfaceSubContextDelegate &delegate,
1001-
bool cacheOnly = false,
1002998
llvm::Optional<std::pair<std::string, swift::ModuleDependencyKind>> dependencyOf = None);
1003999

1000+
/// Retrieve the module dependencies for the Clang module with the given name.
1001+
Optional<const ModuleDependencyInfo*> getClangModuleDependencies(
1002+
StringRef moduleName,
1003+
ModuleDependenciesCache &cache,
1004+
InterfaceSubContextDelegate &delegate);
1005+
10041006
/// Retrieve the module dependencies for the Swift module with the given name.
1005-
Optional<ModuleDependencyInfo> getSwiftModuleDependencies(
1007+
Optional<const ModuleDependencyInfo*> getSwiftModuleDependencies(
10061008
StringRef moduleName,
10071009
ModuleDependenciesCache &cache,
10081010
InterfaceSubContextDelegate &delegate);

include/swift/AST/ConstTypeInfo.h

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2022 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -102,16 +102,6 @@ class BuilderValue : public CompileTimeValue {
102102
std::vector<CompileTimeValue> Members;
103103
};
104104

105-
/// A dictionary literal value representation
106-
class DictionaryValue : public CompileTimeValue {
107-
public:
108-
DictionaryValue() : CompileTimeValue(ValueKind::Dictionary) {}
109-
110-
static bool classof(const CompileTimeValue *T) {
111-
return T->getKind() == ValueKind::Dictionary;
112-
}
113-
};
114-
115105
struct TupleElement {
116106
Optional<std::string> Label;
117107
swift::Type Type;
@@ -151,6 +141,24 @@ class ArrayValue : public CompileTimeValue {
151141
std::vector<std::shared_ptr<CompileTimeValue>> Elements;
152142
};
153143

144+
/// A dictionary literal value representation
145+
class DictionaryValue : public CompileTimeValue {
146+
public:
147+
DictionaryValue(std::vector<std::shared_ptr<TupleValue>> elements)
148+
: CompileTimeValue(ValueKind::Dictionary), Elements(elements) {}
149+
150+
static bool classof(const CompileTimeValue *T) {
151+
return T->getKind() == ValueKind::Dictionary;
152+
}
153+
154+
std::vector<std::shared_ptr<TupleValue>> getElements() const {
155+
return Elements;
156+
}
157+
158+
private:
159+
std::vector<std::shared_ptr<TupleValue>> Elements;
160+
};
161+
154162
/// A representation of an arbitrary value that does not fall under
155163
/// any of the above categories.
156164
class RuntimeValue : public CompileTimeValue {

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ ERROR(error_stdlib_module_name,none,
180180
"module name \"%0\" is reserved for the standard library"
181181
"%select{|; use -module-name flag to specify an alternate name}1",
182182
(StringRef, bool))
183+
ERROR(error_bad_package_name,none,
184+
"package name \"%0\" is not a valid identifier",
185+
(StringRef))
186+
ERROR(error_stdlib_package_name,none,
187+
"package name \"%0\" is reserved for the standard library",
188+
(StringRef))
183189
ERROR(error_stdlib_not_found,Fatal,
184190
"unable to load standard library for target '%0'", (StringRef))
185191
ERROR(error_module_alias_invalid_format,none,

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2035,10 +2035,12 @@ NOTE(objc_generic_extension_using_type_parameter_here,none,
20352035
"generic parameter used here", ())
20362036
NOTE(objc_generic_extension_using_type_parameter_try_objc,none,
20372037
"add '@objc' to allow uses of 'self' within the function body", ())
2038+
ERROR(unsupported_existential_extension,none,
2039+
"extension of existential type %0 is not supported", (Type))
20382040
ERROR(invalid_nominal_extension,none,
20392041
"extension of type %0 must be declared as an extension of %1",
20402042
(Type, Type))
2041-
NOTE(invalid_nominal_extension_rewrite,none,
2043+
NOTE(invalid_extension_rewrite,none,
20422044
"did you mean to extend %0 instead?", (Type))
20432045
ERROR(synthesized_nominal_extension,none,
20442046
"cannot extend synthesized type %0", (Type))

include/swift/AST/Expr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3339,7 +3339,7 @@ class ErasureExpr final : public ImplicitConversionExpr,
33393339
/// this array will be empty
33403340
ArrayRef<ConversionPair> getArgumentConversions() const {
33413341
return {getTrailingObjects<ConversionPair>(),
3342-
Bits.ErasureExpr.NumArgumentConversions };
3342+
static_cast<size_t>(Bits.ErasureExpr.NumArgumentConversions) };
33433343
}
33443344

33453345
/// Retrieve the conversion expressions mapping requirements from any
@@ -3349,7 +3349,7 @@ class ErasureExpr final : public ImplicitConversionExpr,
33493349
/// this array will be empty
33503350
MutableArrayRef<ConversionPair> getArgumentConversions() {
33513351
return {getTrailingObjects<ConversionPair>(),
3352-
Bits.ErasureExpr.NumArgumentConversions };
3352+
static_cast<size_t>(Bits.ErasureExpr.NumArgumentConversions) };
33533353
}
33543354

33553355
void setArgumentConversion(unsigned i, const ConversionPair &p) {

0 commit comments

Comments
 (0)