Skip to content

Commit fa38512

Browse files
authored
Merge pull request #1567 from swiftwasm/master
[pull] swiftwasm from master
2 parents bbe8e43 + c0055e7 commit fa38512

40 files changed

+1231
-374
lines changed

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ documentation, please create a thread on the Swift forums under the
117117
Provides an overview of the implementation of SIL in the compiler.
118118
- [OptimizerDesign.md](/docs/OptimizerDesign.md):
119119
Describes the design of the optimizer pipeline.
120-
- [HighLevelSILOptimizations.rst](docs/HighLevelSILOptimizations.rst):
120+
- [HighLevelSILOptimizations.rst](/docs/HighLevelSILOptimizations.rst):
121121
Describes how the optimizer understands the semantics of high-level
122122
operations on currency data types and optimizes accordingly.
123123
Includes a thorough discussion of the `@_semantics` attribute.

include/swift/AST/DiagnosticsSema.def

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ ERROR(could_not_find_subscript_member_did_you_mean,none,
8888
"did you mean to use the subscript operator?",
8989
(Type))
9090

91+
ERROR(could_not_find_subscript_member_tuple, none,
92+
"cannot access element using subscript for tuple type %0; "
93+
"use '.' notation instead", (Type))
94+
ERROR(could_not_find_subscript_member_tuple_did_you_mean_use_dot, none,
95+
"cannot access element using subscript for tuple type %0; "
96+
"did you mean to use '.%1'?", (Type, StringRef))
97+
9198
ERROR(could_not_find_enum_case,none,
9299
"enum type %0 has no case %1; did you mean %2?",
93100
(Type, DeclNameRef, DeclName))
@@ -2818,7 +2825,8 @@ NOTE(codable_extraneous_codingkey_case_here,none,
28182825
NOTE(codable_non_conforming_property_here,none,
28192826
"cannot automatically synthesize %0 because %1 does not conform to %0", (Type, TypeLoc))
28202827
NOTE(codable_non_decoded_property_here,none,
2821-
"cannot automatically synthesize %0 because %1 does not have a matching CodingKey and does not have a default value", (Type, Identifier))
2828+
"cannot automatically synthesize %0 because %1 does not have a matching "
2829+
"CodingKey and does not have a default value", (Type, Identifier))
28222830
NOTE(codable_codingkeys_type_is_not_an_enum_here,none,
28232831
"cannot automatically synthesize %0 because 'CodingKeys' is not an enum", (Type))
28242832
NOTE(codable_codingkeys_type_does_not_conform_here,none,

include/swift/AST/LocalizationFormat.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define SWIFT_LOCALIZATIONFORMAT_H
1919

2020
#include "llvm/ADT/Hashing.h"
21+
#include "llvm/ADT/Optional.h"
2122
#include "llvm/ADT/STLExtras.h"
2223
#include "llvm/ADT/StringRef.h"
2324
#include "llvm/Bitstream/BitstreamReader.h"
@@ -38,6 +39,7 @@ namespace swift {
3839
enum class DiagID : uint32_t;
3940

4041
namespace diag {
42+
4143
using namespace llvm::support;
4244

4345
class LocalizationWriterInfo {
@@ -152,6 +154,8 @@ class YAMLLocalizationProducer final : public LocalizationProducer {
152154
std::vector<std::string> diagnostics;
153155

154156
public:
157+
/// The diagnostics IDs that are no longer available in `.def`
158+
std::vector<std::string> unknownIDs;
155159
explicit YAMLLocalizationProducer(llvm::StringRef filePath);
156160
llvm::StringRef getMessageOr(swift::DiagID id,
157161
llvm::StringRef defaultMessage) const override;
@@ -185,12 +189,23 @@ class LocalizationInput : public llvm::yaml::Input {
185189
template <typename T, typename Context>
186190
friend typename std::enable_if<llvm::yaml::has_SequenceTraits<T>::value,
187191
void>::type
188-
readYAML(llvm::yaml::IO &io, T &Seq, bool, Context &Ctx);
192+
readYAML(llvm::yaml::IO &io, T &Seq, T &unknownIDs, bool, Context &Ctx);
189193

190194
template <typename T>
191195
friend typename std::enable_if<llvm::yaml::has_SequenceTraits<T>::value,
192196
LocalizationInput &>::type
193197
operator>>(LocalizationInput &yin, T &diagnostics);
198+
199+
public:
200+
/// A vector that keeps track of the diagnostics IDs that are available in
201+
/// YAML and not available in `.def` files.
202+
std::vector<std::string> unknownIDs;
203+
204+
/// A diagnostic ID might be present in YAML and not in `.def` file, if that's
205+
/// the case the `id` won't have a `DiagID` value.
206+
/// If the `id` is available in `.def` file this method will return the `id`'s
207+
/// value, otherwise this method won't return a value.
208+
static llvm::Optional<uint32_t> readID(llvm::yaml::IO &io);
194209
};
195210

196211
} // namespace diag

include/swift/AST/NameLookup.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -512,14 +512,6 @@ void recordLookupOfTopLevelName(DeclContext *topLevelContext, DeclName name,
512512

513513
} // end namespace namelookup
514514

515-
/// Retrieve the set of nominal type declarations that are directly
516-
/// referenced in the given \c typeRepr, looking through typealiases.
517-
///
518-
/// \param dc The \c DeclContext from which to perform lookup.
519-
TinyPtrVector<NominalTypeDecl *>
520-
getDirectlyReferencedNominalTypeDecls(ASTContext &ctx, TypeRepr *typeRepr,
521-
DeclContext *dc, bool &anyObject);
522-
523515
/// Retrieve the set of nominal type declarations that are directly
524516
/// "inherited" by the given declaration at a particular position in the
525517
/// list of "inherited" types.

include/swift/Basic/LangOptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,12 @@ namespace swift {
385385
/// Load swiftmodule files in memory as volatile and avoid mmap.
386386
bool EnableVolatileModules = false;
387387

388+
/// Allow deserializing implementation only dependencies. This should only
389+
/// be set true by lldb and other tooling, so that deserilization
390+
/// recovery issues won't bring down the debugger.
391+
/// TODO: remove this when @_implementationOnly modules are robust enough.
392+
bool AllowDeserializingImplementationOnly = false;
393+
388394
/// Sets the target we are building for and updates platform conditions
389395
/// to match.
390396
///

lib/AST/LocalizationFormat.cpp

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//===----------------------------------------------------------------------===//
1616

1717
#include "swift/AST/LocalizationFormat.h"
18+
#include "llvm/ADT/Optional.h"
1819
#include "llvm/ADT/SmallString.h"
1920
#include "llvm/ADT/StringRef.h"
2021
#include "llvm/Bitstream/BitstreamReader.h"
@@ -28,16 +29,13 @@
2829
#include <type_traits>
2930

3031
namespace {
32+
3133
enum LocalDiagID : uint32_t {
3234
#define DIAG(KIND, ID, Options, Text, Signature) ID,
3335
#include "swift/AST/DiagnosticsAll.def"
3436
NumDiags
3537
};
3638

37-
struct DiagnosticNode {
38-
uint32_t id;
39-
std::string msg;
40-
};
4139
} // namespace
4240

4341
namespace llvm {
@@ -55,15 +53,6 @@ template <> struct ScalarEnumerationTraits<LocalDiagID> {
5553
}
5654
};
5755

58-
template <> struct MappingTraits<DiagnosticNode> {
59-
static void mapping(IO &io, DiagnosticNode &node) {
60-
LocalDiagID diagID;
61-
io.mapRequired("id", diagID);
62-
io.mapRequired("msg", node.msg);
63-
node.id = static_cast<uint32_t>(diagID);
64-
}
65-
};
66-
6756
} // namespace yaml
6857
} // namespace llvm
6958

@@ -121,6 +110,7 @@ YAMLLocalizationProducer::YAMLLocalizationProducer(llvm::StringRef filePath) {
121110
llvm::MemoryBuffer *document = FileBufOrErr->get();
122111
diag::LocalizationInput yin(document->getBuffer());
123112
yin >> diagnostics;
113+
unknownIDs = std::move(yin.unknownIDs);
124114
}
125115

126116
llvm::StringRef
@@ -143,31 +133,45 @@ void YAMLLocalizationProducer::forEachAvailable(
143133
}
144134
}
145135

136+
llvm::Optional<uint32_t> LocalizationInput::readID(llvm::yaml::IO &io) {
137+
LocalDiagID diagID;
138+
io.mapRequired("id", diagID);
139+
if (diagID == LocalDiagID::NumDiags)
140+
return llvm::None;
141+
return static_cast<uint32_t>(diagID);
142+
}
143+
146144
template <typename T, typename Context>
147145
typename std::enable_if<llvm::yaml::has_SequenceTraits<T>::value, void>::type
148-
readYAML(llvm::yaml::IO &io, T &Seq, bool, Context &Ctx) {
146+
readYAML(llvm::yaml::IO &io, T &Seq, T &unknownIDs, bool, Context &Ctx) {
149147
unsigned count = io.beginSequence();
150-
if (count)
148+
if (count) {
151149
Seq.resize(LocalDiagID::NumDiags);
150+
}
151+
152152
for (unsigned i = 0; i < count; ++i) {
153153
void *SaveInfo;
154154
if (io.preflightElement(i, SaveInfo)) {
155-
DiagnosticNode current;
156-
yamlize(io, current, true, Ctx);
157-
io.postflightElement(SaveInfo);
155+
io.beginMapping();
158156

159-
// A diagnostic ID might be present in YAML and not in `.def` file,
160-
// if that's the case ScalarEnumerationTraits will assign the diagnostic ID
161-
// to `LocalDiagID::NumDiags`. Since the diagnostic ID isn't available
162-
// in `.def` it shouldn't be stored in the diagnostics array.
163-
if (current.id != LocalDiagID::NumDiags) {
157+
// If the current diagnostic ID is available in YAML and in `.def`, add it
158+
// to the diagnostics array. Otherwise, re-parse the current diagnnostic
159+
// id as a string and store it in `unknownIDs` array.
160+
if (auto id = LocalizationInput::readID(io)) {
164161
// YAML file isn't guaranteed to have diagnostics in order of their
165162
// declaration in `.def` files, to accommodate that we need to leave
166163
// holes in diagnostic array for diagnostics which haven't yet been
167-
// localized and for the ones that have `DiagnosticNode::id`
168-
// indicates their position.
169-
Seq[static_cast<unsigned>(current.id)] = std::move(current.msg);
164+
// localized and for the ones that have `id` indicates their position.
165+
io.mapRequired("msg", Seq[*id]);
166+
} else {
167+
std::string unknownID, message;
168+
// Read "raw" id since it doesn't exist in `.def` file.
169+
io.mapRequired("id", unknownID);
170+
io.mapRequired("msg", message);
171+
unknownIDs.push_back(unknownID);
170172
}
173+
io.endMapping();
174+
io.postflightElement(SaveInfo);
171175
}
172176
}
173177
io.endSequence();
@@ -181,7 +185,7 @@ operator>>(LocalizationInput &yin, T &diagnostics) {
181185
if (yin.setCurrentDocument()) {
182186
// If YAML file's format doesn't match the current format in
183187
// DiagnosticMessageFormat, will throw an error.
184-
readYAML(yin, diagnostics, true, Ctx);
188+
readYAML(yin, diagnostics, yin.unknownIDs, true, Ctx);
185189
}
186190
return yin;
187191
}

lib/AST/NameLookup.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -861,13 +861,18 @@ SelfBounds SelfBoundsFromWhereClauseRequest::evaluate(
861861
continue;
862862

863863
// Resolve the right-hand side.
864-
if (auto *const typeRepr = req.getConstraintRepr()) {
865-
const auto rhsNominals = getDirectlyReferencedNominalTypeDecls(
866-
ctx, typeRepr, lookupDC, result.anyObject);
867-
868-
result.decls.insert(result.decls.end(), rhsNominals.begin(),
869-
rhsNominals.end());
864+
DirectlyReferencedTypeDecls rhsDecls;
865+
if (auto typeRepr = req.getConstraintRepr()) {
866+
rhsDecls = directReferencesForTypeRepr(evaluator, ctx, typeRepr, lookupDC);
870867
}
868+
869+
SmallVector<ModuleDecl *, 2> modulesFound;
870+
auto rhsNominals = resolveTypeDeclsToNominal(evaluator, ctx, rhsDecls,
871+
modulesFound,
872+
result.anyObject);
873+
result.decls.insert(result.decls.end(),
874+
rhsNominals.begin(),
875+
rhsNominals.end());
871876
}
872877

873878
return result;
@@ -2134,17 +2139,6 @@ static DirectlyReferencedTypeDecls directReferencesForType(Type type) {
21342139
return { };
21352140
}
21362141

2137-
TinyPtrVector<NominalTypeDecl *> swift::getDirectlyReferencedNominalTypeDecls(
2138-
ASTContext &ctx, TypeRepr *typeRepr, DeclContext *dc, bool &anyObject) {
2139-
const auto referenced =
2140-
directReferencesForTypeRepr(ctx.evaluator, ctx, typeRepr, dc);
2141-
2142-
// Resolve those type declarations to nominal type declarations.
2143-
SmallVector<ModuleDecl *, 2> modulesFound;
2144-
return resolveTypeDeclsToNominal(ctx.evaluator, ctx, referenced, modulesFound,
2145-
anyObject);
2146-
}
2147-
21482142
DirectlyReferencedTypeDecls InheritedDeclsReferencedRequest::evaluate(
21492143
Evaluator &evaluator,
21502144
llvm::PointerUnion<const TypeDecl *, const ExtensionDecl *> decl,
@@ -2266,10 +2260,16 @@ ExtendedNominalRequest::evaluate(Evaluator &evaluator,
22662260
// We must've seen 'extension { ... }' during parsing.
22672261
return nullptr;
22682262

2263+
ASTContext &ctx = ext->getASTContext();
2264+
DirectlyReferencedTypeDecls referenced =
2265+
directReferencesForTypeRepr(evaluator, ctx, typeRepr, ext->getParent());
2266+
22692267
// Resolve those type declarations to nominal type declarations.
2268+
SmallVector<ModuleDecl *, 2> modulesFound;
22702269
bool anyObject = false;
2271-
const auto nominalTypes = getDirectlyReferencedNominalTypeDecls(
2272-
ext->getASTContext(), typeRepr, ext->getParent(), anyObject);
2270+
auto nominalTypes
2271+
= resolveTypeDeclsToNominal(evaluator, ctx, referenced, modulesFound,
2272+
anyObject);
22732273

22742274
// If there is more than 1 element, we will emit a warning or an error
22752275
// elsewhere, so don't handle that case here.

lib/IDE/SourceEntityWalker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ bool SemaAnnotator::
685685
passReference(ValueDecl *D, Type Ty, DeclNameLoc Loc, ReferenceMetaData Data) {
686686
SourceManager &SM = D->getASTContext().SourceMgr;
687687
SourceLoc BaseStart = Loc.getBaseNameLoc(), BaseEnd = BaseStart;
688-
if (SM.extractText({BaseStart, 1}) == "`")
688+
if (BaseStart.isValid() && SM.extractText({BaseStart, 1}) == "`")
689689
BaseEnd = Lexer::getLocForEndOfToken(SM, BaseStart.getAdvancedLoc(1));
690690
return passReference(D, Ty, BaseStart, {BaseStart, BaseEnd}, Data);
691691
}

0 commit comments

Comments
 (0)