Skip to content

Commit 8dfef80

Browse files
Merge pull request #4692 from swiftwasm/main
[pull] swiftwasm from main
2 parents b002530 + 1821b62 commit 8dfef80

File tree

76 files changed

+1798
-765
lines changed

Some content is hidden

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

76 files changed

+1798
-765
lines changed

SwiftCompilerSources/Sources/AST/DiagnosticEngine.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ public struct DiagnosticFixIt {
5050
self.text = text
5151
}
5252

53-
func withBridgedDiagnosticFixIt(_ fn: (BridgedDiagnosticFixIt) -> Void) {
53+
func withBridgedDiagnosticFixIt(_ fn: (swift.DiagnosticInfo.FixIt) -> Void) {
5454
text.withBridgedStringRef { bridgedTextRef in
55-
let bridgedDiagnosticFixIt = BridgedDiagnosticFixIt(
56-
start: start.bridged,
57-
byteLength: byteLength,
58-
text: bridgedTextRef)
55+
let bridgedDiagnosticFixIt = swift.DiagnosticInfo.FixIt(
56+
swift.CharSourceRange(start.bridged, UInt32(byteLength)),
57+
llvm.StringRef(bridgedTextRef),
58+
llvm.ArrayRef<swift.DiagnosticArgument>())
5959
fn(bridgedDiagnosticFixIt)
6060
}
6161
}
@@ -83,7 +83,7 @@ public struct DiagnosticEngine {
8383
let bridgedSourceLoc: swift.SourceLoc = position.bridged
8484
let bridgedHighlightRange: swift.CharSourceRange = highlight.bridged
8585
var bridgedArgs: [BridgedDiagnosticArgument] = []
86-
var bridgedFixIts: [BridgedDiagnosticFixIt] = []
86+
var bridgedFixIts: [swift.DiagnosticInfo.FixIt] = []
8787

8888
// Build a higher-order function to wrap every 'withBridgedXXX { ... }'
8989
// calls, so we don't escape anything from the closure. 'bridgedArgs' and

SwiftCompilerSources/Sources/Basic/Utils.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ extension BridgedStringRef {
4848
}
4949
}
5050

51+
extension llvm.StringRef {
52+
public init(_ bridged: BridgedStringRef) {
53+
self.init(bridged.data, bridged.length)
54+
}
55+
}
56+
5157
extension String {
5258
public func withBridgedStringRef<T>(_ c: (BridgedStringRef) -> T) -> T {
5359
var str = self

SwiftCompilerSources/Sources/SIL/ApplySite.swift

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,46 @@ public protocol ApplySite : Instruction {
2121
var operands: OperandArray { get }
2222
var numArguments: Int { get }
2323
var substitutionMap: SubstitutionMap { get }
24+
25+
/// Converts an argument index of the apply to the corresponding argument index of the callee.
26+
///
27+
/// For a FullApplySite this is always a 1-to-1 mapping.
28+
/// For a `partial_apply` the callee index can be higher than the caller's argument index
29+
/// because the arguments to `partial_apply` are a suffix of the callee.
30+
///
31+
/// Example:
32+
/// ```
33+
/// func callee(a, b, c, d, e) { }
34+
///
35+
/// %pa = partial_apply @callee(c, d, e)
36+
/// // caller indices: 0, 1, 2
37+
/// // callee indices: 2, 3, 4
38+
///
39+
/// %a = apply %pa (a, b)
40+
/// // caller indices: 0, 1
41+
/// // callee indices: 0, 1
42+
/// ```
2443
func calleeArgIndex(callerArgIndex: Int) -> Int
44+
45+
/// Converts an argument index of a callee to the corresponding argument index of the apply.
46+
///
47+
/// If the apply does not actually apply that argument, it returns nil.
48+
/// Otherwise, for a FullApplySite this is always a 1-to-1 mapping.
49+
/// For a `partial_apply` the caller index can be lower than the callee's argument index
50+
/// because the arguments to `partial_apply` are a suffix of the callee.
51+
///
52+
/// Example:
53+
/// ```
54+
/// func callee(a, b, c, d, e) { }
55+
/// // callee indices: 0, 1, 2, 3, 4
56+
/// // caller indices in %pa: -, -, 0, 1, 2 ("-" == nil)
57+
/// // caller indices in %a: 0, 1, -, -, -
58+
///
59+
/// %pa = partial_apply @callee(c, d, e)
60+
/// %a = apply %pa (a, b)
61+
/// ```
2562
func callerArgIndex(calleeArgIndex: Int) -> Int?
63+
2664
func getArgumentConvention(calleeArgIndex: Int) -> ArgumentConvention
2765
}
2866

@@ -66,6 +104,15 @@ public protocol FullApplySite : ApplySite {
66104
}
67105

68106
extension FullApplySite {
69-
public func calleeArgIndex(callerArgIndex: Int) -> Int { callerArgIndex }
70-
public func callerArgIndex(calleeArgIndex: Int) -> Int? { calleeArgIndex }
107+
public func calleeArgIndex(callerArgIndex: Int) -> Int {
108+
assert(callerArgIndex >= 0 && callerArgIndex < numArguments)
109+
return callerArgIndex
110+
}
111+
112+
public func callerArgIndex(calleeArgIndex: Int) -> Int? {
113+
if calleeArgIndex < numArguments {
114+
return calleeArgIndex
115+
}
116+
return nil
117+
}
71118
}

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,10 @@ final public class PartialApplyInst : SingleValueInstruction, ApplySite {
514514
public func callerArgIndex(calleeArgIndex: Int) -> Int? {
515515
let firstIdx = PartialApply_getCalleeArgIndexOfFirstAppliedArg(bridged)
516516
if calleeArgIndex >= firstIdx {
517-
return calleeArgIndex - firstIdx
517+
let callerIdx = calleeArgIndex - firstIdx
518+
if callerIdx < numArguments {
519+
return callerIdx
520+
}
518521
}
519522
return nil
520523
}

include/swift/AST/ASTBridging.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ typedef struct {
5151
} value;
5252
} BridgedDiagnosticArgument;
5353

54-
typedef struct {
55-
swift::SourceLoc start;
56-
SwiftInt byteLength;
57-
BridgedStringRef text;
58-
} BridgedDiagnosticFixIt;
59-
6054
typedef struct {
6155
void * _Nonnull object;
6256
} BridgedDiagnosticEngine;

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2919,7 +2919,8 @@ ERROR(conformance_from_implementation_only_module,none,
29192919
"in an extension with conditional conformances}2; "
29202920
"%select{%3 has been imported as implementation-only|"
29212921
"the conformance is declared as SPI in %3|"
2922-
"the conformance is declared as SPI}4",
2922+
"the conformance is declared as SPI|"
2923+
"%3 was not imported by this file}4",
29232924
(Type, Identifier, unsigned, Identifier, unsigned))
29242925
NOTE(assoc_conformance_from_implementation_only_module,none,
29252926
"in associated type %0 (inferred as %1)", (Type, Type))

include/swift/Frontend/FrontendOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ class FrontendOptions {
105105
/// If indexing system modules, don't index the stdlib.
106106
bool IndexIgnoreStdlib = false;
107107

108+
/// Include local definitions/references in the index data.
109+
bool IndexIncludeLocals = false;
110+
108111
/// The module for which we should verify all of the generic signatures.
109112
std::string VerifyGenericSignaturesInModule;
110113

include/swift/IRGen/IRABIDetailsProvider.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
#ifndef SWIFT_IRGEN_IRABIDETAILSPROVIDER_H
1414
#define SWIFT_IRGEN_IRABIDETAILSPROVIDER_H
1515

16+
#include "swift/AST/Decl.h"
1617
#include "swift/AST/Type.h"
1718
#include "clang/AST/CharUnits.h"
19+
#include "llvm/ADT/MapVector.h"
1820
#include "llvm/ADT/Optional.h"
1921
#include "llvm/ADT/STLExtras.h"
2022
#include "llvm/ADT/SmallVector.h"
@@ -93,6 +95,10 @@ class IRABIDetailsProvider {
9395
/// access function.
9496
FunctionABISignature getTypeMetadataAccessFunctionSignature();
9597

98+
/// Returns EnumElementDecls (enum cases) in their declaration order with
99+
/// their tag indices from the given EnumDecl
100+
llvm::MapVector<EnumElementDecl *, unsigned> getEnumTagMapping(EnumDecl *ED);
101+
96102
private:
97103
std::unique_ptr<IRABIDetailsProviderImpl> impl;
98104
};

include/swift/Index/IndexRecord.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ namespace index {
4343
/// \param skipStdlib If indexing system modules, don't index the standard
4444
/// library.
4545
///
46+
/// \param includeLocals If true, emit index data for local definitions and
47+
/// references.
48+
///
4649
/// \param isDebugCompilation true for non-optimized compiler invocation.
4750
///
4851
/// \param targetTriple The target for this compilation.
@@ -53,7 +56,8 @@ namespace index {
5356
bool indexAndRecord(SourceFile *primarySourceFile, StringRef indexUnitToken,
5457
StringRef indexStorePath, bool indexClangModules,
5558
bool indexSystemModules, bool skipStdlib,
56-
bool isDebugCompilation, StringRef targetTriple,
59+
bool includeLocals, bool isDebugCompilation,
60+
StringRef targetTriple,
5761
const DependencyTracker &dependencyTracker,
5862
const PathRemapper &pathRemapper);
5963

@@ -81,6 +85,9 @@ bool indexAndRecord(SourceFile *primarySourceFile, StringRef indexUnitToken,
8185
/// \param skipStdlib If indexing system modules, don't index the standard
8286
/// library.
8387
///
88+
/// \param includeLocals If true, emit index data for local definitions and
89+
/// references.
90+
///
8491
/// \param isDebugCompilation true for non-optimized compiler invocation.
8592
///
8693
/// \param targetTriple The target for this compilation.
@@ -91,8 +98,8 @@ bool indexAndRecord(SourceFile *primarySourceFile, StringRef indexUnitToken,
9198
bool indexAndRecord(ModuleDecl *module, ArrayRef<std::string> indexUnitTokens,
9299
StringRef moduleUnitToken, StringRef indexStorePath,
93100
bool indexClangModules, bool indexSystemModules,
94-
bool skipStdlib, bool isDebugCompilation,
95-
StringRef targetTriple,
101+
bool skipStdlib, bool includeLocals,
102+
bool isDebugCompilation, StringRef targetTriple,
96103
const DependencyTracker &dependencyTracker,
97104
const PathRemapper &pathRemapper);
98105
// FIXME: indexUnitTokens could be StringRef, but that creates an impedance

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,10 @@ def index_ignore_clang_modules : Flag<["-"], "index-ignore-clang-modules">,
12621262
Flags<[FrontendOption]>,
12631263
HelpText<"Avoid indexing clang modules (pcms)">;
12641264

1265+
def index_include_locals : Flag<["-"], "index-include-locals">,
1266+
Flags<[FrontendOption]>,
1267+
HelpText<"Include local definitions/references in the produced index data.">;
1268+
12651269
def index_ignore_system_modules : Flag<["-"], "index-ignore-system-modules">,
12661270
Flags<[NoInteractiveOption]>,
12671271
HelpText<"Avoid indexing system modules">;

include/swift/SIL/SILArgument.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class SILArgument : public ValueBase {
6868

6969
SILBasicBlock *parentBlock;
7070
const ValueDecl *decl;
71+
USE_SHARED_UINT8;
7172

7273
protected:
7374
SILArgument(ValueKind subClassKind, SILBasicBlock *inputParentBlock,
@@ -81,19 +82,19 @@ class SILArgument : public ValueBase {
8182
const ValueDecl *inputDecl = nullptr)
8283
: ValueBase(subClassKind, type),
8384
parentBlock(nullptr), decl(inputDecl) {
84-
Bits.SILArgument.VOKind = static_cast<unsigned>(ownershipKind);
85+
sharedUInt8().SILArgument.valueOwnershipKind = uint8_t(ownershipKind);
8586
}
8687

8788
public:
8889
void operator=(const SILArgument &) = delete;
8990
void operator delete(void *, size_t) = delete;
9091

9192
ValueOwnershipKind getOwnershipKind() const {
92-
return static_cast<ValueOwnershipKind>(Bits.SILArgument.VOKind);
93+
return ValueOwnershipKind(sharedUInt8().SILArgument.valueOwnershipKind);
9394
}
9495

9596
void setOwnershipKind(ValueOwnershipKind newKind) {
96-
Bits.SILArgument.VOKind = static_cast<unsigned>(newKind);
97+
sharedUInt8().SILArgument.valueOwnershipKind = uint8_t(newKind);
9798
}
9899

99100
SILBasicBlock *getParent() const { return parentBlock; }

0 commit comments

Comments
 (0)