Skip to content

Commit 171e819

Browse files
authored
Merge pull request #994 from swiftwasm/master
[pull] swiftwasm from master
2 parents d2f81e1 + 63167fa commit 171e819

Some content is hidden

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

65 files changed

+450
-403
lines changed

docs/TypeChecker.rst

+13-13
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ Locators
718718
During constraint generation and solving, numerous constraints are
719719
created, broken apart, and solved. During constraint application as
720720
well as during diagnostics emission, it is important to track the
721-
relationship between the constraints and the actual expressions from
721+
relationship between the constraints and the actual AST nodes from
722722
which they originally came. For example, consider the following type
723723
checking problem::
724724

@@ -754,16 +754,16 @@ functions was selected to perform the conversion, so that conversion
754754
function can be called by constraint application if all else succeeds.
755755

756756
*Locators* address both issues by tracking the location and derivation
757-
of constraints. Each locator is anchored at a specific expression,
758-
i.e., the function application ``f(10.5, x)``, and contains a path of
759-
zero or more derivation steps from that anchor. For example, the
760-
"``T(f)`` ==Fn ``T0 -> T1``" constraint has a locator that is
761-
anchored at the function application and a path with the "apply
762-
function" derivation step, meaning that this is the function being
763-
applied. Similarly, the "``(T2, X) <c T0`` constraint has a
764-
locator anchored at the function application and a path with the
765-
"apply argument" derivation step, meaning that this is the argument
766-
to the function.
757+
of constraints. Each locator is anchored at a specific AST node
758+
(expression, pattern, declaration etc.) i.e., the function application
759+
``f(10.5, x)``, and contains a path of zero or more derivation steps
760+
from that anchor. For example, the "``T(f)`` ==Fn ``T0 -> T1``"
761+
constraint has a locator that is anchored at the function application
762+
and a path with the "apply function" derivation step, meaning that
763+
this is the function being applied. Similarly, the "``(T2, X) <c T0``
764+
constraint has a locator anchored at the function application and a
765+
path with the "apply argument" derivation step, meaning that this is
766+
the argument to the function.
767767

768768
When constraints are simplified, the resulting constraints have
769769
locators with longer paths. For example, when a conversion constraint between two
@@ -812,15 +812,15 @@ Locators provide the derivation of location information that follows
812812
the path of the solver, and can be used to query and recover the
813813
important decisions made by the solver. However, the locators
814814
determined by the solver may not directly refer to the most specific
815-
expression for the purposes of identifying the corresponding source
815+
AST node for the purposes of identifying the corresponding source
816816
location. For example, the failed constraint "``Int`` conforms to
817817
``ExpressibleByFloatLiteral``" can most specifically by centered on the
818818
floating-point literal ``10.5``, but its locator is::
819819

820820
function application -> apply argument -> tuple element #0
821821

822822
The process of locator simplification maps a locator to its most
823-
specific expression. Essentially, it starts at the anchor of the
823+
specific AST node. Essentially, it starts at the anchor of the
824824
locator (in this case, the application ``f(10.5, x)``) and then walks
825825
the path, matching derivation steps to subexpressions. The "function
826826
application" derivation step extracts the argument (``(10.5,

include/swift/AST/ASTContext.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ class ASTContext final {
238238
UnifiedStatsReporter *Stats = nullptr;
239239

240240
/// The language options used for translation.
241-
LangOptions &LangOpts;
241+
const LangOptions &LangOpts;
242242

243243
/// The type checker options.
244-
TypeCheckerOptions &TypeCheckerOpts;
244+
const TypeCheckerOptions &TypeCheckerOpts;
245245

246246
/// The search path options used by this AST context.
247247
SearchPathOptions &SearchPathOpts;

include/swift/AST/Decl.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ class alignas(1 << DeclAlignInBits) Decl {
575575
HasAnyUnavailableValues : 1
576576
);
577577

578-
SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1+1+1+1+1,
578+
SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1+1+1+1+1+1,
579579
/// If the module was or is being compiled with `-enable-testing`.
580580
TestingEnabled : 1,
581581

@@ -601,7 +601,10 @@ class alignas(1 << DeclAlignInBits) Decl {
601601

602602
/// Whether the module was imported from Clang (or, someday, maybe another
603603
/// language).
604-
IsNonSwiftModule : 1
604+
IsNonSwiftModule : 1,
605+
606+
/// Whether this module is the main module.
607+
IsMainModule : 1
605608
);
606609

607610
SWIFT_INLINE_BITFIELD(PrecedenceGroupDecl, Decl, 1+2,

include/swift/AST/DiagnosticsFrontend.def

+5
Original file line numberDiff line numberDiff line change
@@ -375,5 +375,10 @@ ERROR(expectation_missing_opening_braces,none,
375375
ERROR(expectation_missing_closing_braces,none,
376376
"didn't find '}}' to match '{{' in expectation", ())
377377

378+
WARNING(module_incompatible_with_skip_function_bodies,none,
379+
"module '%0' cannot be built with "
380+
"-experimental-skip-non-inlinable-function-bodies; this option has "
381+
"been automatically disabled", (StringRef))
382+
378383
#define UNDEFINE_DIAGNOSTIC_MACROS
379384
#include "DefineDiagnosticMacros.h"

include/swift/AST/Module.h

+11
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,13 @@ class ModuleDecl : public DeclContext, public TypeDecl {
347347
return new (ctx) ModuleDecl(name, ctx, importInfo);
348348
}
349349

350+
static ModuleDecl *
351+
createMainModule(ASTContext &ctx, Identifier name, ImplicitImportInfo iinfo) {
352+
auto *Mod = ModuleDecl::create(name, ctx, iinfo);
353+
Mod->Bits.ModuleDecl.IsMainModule = true;
354+
return Mod;
355+
}
356+
350357
using Decl::getASTContext;
351358

352359
/// Retrieves information about which modules are implicitly imported by
@@ -542,6 +549,10 @@ class ModuleDecl : public DeclContext, public TypeDecl {
542549
Bits.ModuleDecl.IsNonSwiftModule = flag;
543550
}
544551

552+
bool isMainModule() const {
553+
return Bits.ModuleDecl.IsMainModule;
554+
}
555+
545556
/// Retrieve the top-level module. If this module is already top-level, this
546557
/// returns itself. If this is a submodule such as \c Foo.Bar.Baz, this
547558
/// returns the module \c Foo.

include/swift/AST/PlatformKind.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ StringRef prettyPlatformString(PlatformKind platform);
5454
/// If ForTargetVariant is true then for zippered builds the target-variant
5555
/// triple will be used rather than the target to determine whether the
5656
/// platform is active.
57-
bool isPlatformActive(PlatformKind Platform, LangOptions &LangOpts,
57+
bool isPlatformActive(PlatformKind Platform, const LangOptions &LangOpts,
5858
bool ForTargetVariant = false);
5959

6060
/// Returns the target platform for the given language options.
61-
PlatformKind targetPlatform(LangOptions &LangOpts);
61+
PlatformKind targetPlatform(const LangOptions &LangOpts);
6262

6363
/// Returns true when availability attributes from the "parent" platform
6464
/// should also apply to the "child" platform for declarations without

include/swift/AST/SILGenRequests.h

+4-28
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,16 @@ struct SILGenDescriptor {
8181
/// If the module or file contains SIL that needs parsing, returns the file
8282
/// to be parsed, or \c nullptr if parsing isn't required.
8383
SourceFile *getSourceFileToParse() const;
84-
85-
/// Whether the SIL is being emitted for a whole module.
86-
bool isWholeModule() const;
8784
};
8885

8986
void simple_display(llvm::raw_ostream &out, const SILGenDescriptor &d);
9087

9188
SourceLoc extractNearestSourceLoc(const SILGenDescriptor &desc);
9289

93-
class SILGenSourceFileRequest :
94-
public SimpleRequest<SILGenSourceFileRequest,
95-
std::unique_ptr<SILModule>(SILGenDescriptor),
96-
RequestFlags::Uncached|RequestFlags::DependencySource> {
90+
class SILGenerationRequest
91+
: public SimpleRequest<
92+
SILGenerationRequest, std::unique_ptr<SILModule>(SILGenDescriptor),
93+
RequestFlags::Uncached | RequestFlags::DependencySource> {
9794
public:
9895
using SimpleRequest::SimpleRequest;
9996

@@ -104,33 +101,12 @@ class SILGenSourceFileRequest :
104101
std::unique_ptr<SILModule>
105102
evaluate(Evaluator &evaluator, SILGenDescriptor desc) const;
106103

107-
public:
108-
bool isCached() const { return true; }
109-
110104
public:
111105
// Incremental dependencies.
112106
evaluator::DependencySource
113107
readDependencySource(const evaluator::DependencyCollector &) const;
114108
};
115109

116-
class SILGenWholeModuleRequest :
117-
public SimpleRequest<SILGenWholeModuleRequest,
118-
std::unique_ptr<SILModule>(SILGenDescriptor),
119-
RequestFlags::Uncached> {
120-
public:
121-
using SimpleRequest::SimpleRequest;
122-
123-
private:
124-
friend SimpleRequest;
125-
126-
// Evaluation.
127-
std::unique_ptr<SILModule>
128-
evaluate(Evaluator &evaluator, SILGenDescriptor desc) const;
129-
130-
public:
131-
bool isCached() const { return true; }
132-
};
133-
134110
/// Parses a .sil file into a SILModule.
135111
class ParseSILModuleRequest
136112
: public SimpleRequest<ParseSILModuleRequest,

include/swift/AST/SILGenTypeIDZone.def

+1-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17-
SWIFT_REQUEST(SILGen, SILGenSourceFileRequest,
18-
std::unique_ptr<SILModule>(SILGenDescriptor),
19-
Uncached, NoLocationInfo)
20-
SWIFT_REQUEST(SILGen, SILGenWholeModuleRequest,
17+
SWIFT_REQUEST(SILGen, SILGenerationRequest,
2118
std::unique_ptr<SILModule>(SILGenDescriptor),
2219
Uncached, NoLocationInfo)
2320
SWIFT_REQUEST(SILGen, ParseSILModuleRequest,

include/swift/Basic/LLVM.h

+8
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ namespace llvm {
3434
class Twine;
3535
template <typename T> class SmallPtrSetImpl;
3636
template <typename T, unsigned N> class SmallPtrSet;
37+
#if !defined(swiftCore_EXPORTS)
3738
template <typename T> class SmallVectorImpl;
39+
#endif
3840
template <typename T, unsigned N> class SmallVector;
3941
template <unsigned N> class SmallString;
4042
template <typename T, unsigned N> class SmallSetVector;
@@ -52,7 +54,9 @@ namespace llvm {
5254
class raw_ostream;
5355
class APInt;
5456
class APFloat;
57+
#if !defined(swiftCore_EXPORTS)
5558
template <typename Fn> class function_ref;
59+
#endif
5660
} // end namespace llvm
5761

5862

@@ -79,7 +83,9 @@ namespace swift {
7983
using llvm::SmallSetVector;
8084
using llvm::SmallString;
8185
using llvm::SmallVector;
86+
#if !defined(swiftCore_EXPORTS)
8287
using llvm::SmallVectorImpl;
88+
#endif
8389
using llvm::StringLiteral;
8490
using llvm::StringRef;
8591
using llvm::TinyPtrVector;
@@ -88,7 +94,9 @@ namespace swift {
8894
// Other common classes.
8995
using llvm::APFloat;
9096
using llvm::APInt;
97+
#if !defined(swiftCore_EXPORTS)
9198
using llvm::function_ref;
99+
#endif
92100
using llvm::NoneType;
93101
using llvm::raw_ostream;
94102
} // end namespace swift

include/swift/Demangling/TypeDecoder.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ class TypeDecoder {
896896
private:
897897
template <typename T>
898898
bool decodeImplFunctionPart(Demangle::NodePointer node,
899-
SmallVectorImpl<T> &results) {
899+
llvm::SmallVectorImpl<T> &results) {
900900
if (node->getNumChildren() != 2)
901901
return true;
902902

@@ -919,7 +919,7 @@ class TypeDecoder {
919919

920920
bool decodeImplFunctionParam(
921921
Demangle::NodePointer node,
922-
SmallVectorImpl<ImplFunctionParam<BuiltType>> &results) {
922+
llvm::SmallVectorImpl<ImplFunctionParam<BuiltType>> &results) {
923923
// Children: `convention, differentiability?, type`
924924
if (node->getNumChildren() != 2 && node->getNumChildren() != 3)
925925
return true;
@@ -1021,7 +1021,7 @@ class TypeDecoder {
10211021

10221022
bool decodeMangledFunctionInputType(
10231023
Demangle::NodePointer node,
1024-
SmallVectorImpl<FunctionParam<BuiltType>> &params,
1024+
llvm::SmallVectorImpl<FunctionParam<BuiltType>> &params,
10251025
bool &hasParamFlags) {
10261026
// Look through a couple of sugar nodes.
10271027
if (node->getKind() == NodeKind::Type ||

include/swift/Parse/Parser.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -1359,8 +1359,7 @@ class Parser {
13591359
ParserResult<Pattern> parsePatternTuple();
13601360

13611361
ParserResult<Pattern>
1362-
parseOptionalPatternTypeAnnotation(ParserResult<Pattern> P,
1363-
bool isOptional);
1362+
parseOptionalPatternTypeAnnotation(ParserResult<Pattern> P);
13641363
ParserResult<Pattern> parseMatchingPattern(bool isExprBasic);
13651364
ParserResult<Pattern> parseMatchingPatternAsLetOrVar(bool isLet,
13661365
SourceLoc VarLoc,

include/swift/SIL/SILModule.h

+12-30
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ enum class SILStage {
107107
/// when a Swift compilation context is lowered to SIL.
108108
class SILModule {
109109
friend class SILFunctionBuilder;
110-
friend class SILGenSourceFileRequest;
111-
friend class SILGenWholeModuleRequest;
112110

113111
public:
114112
using FunctionListType = llvm::ilist<SILFunction>;
@@ -262,10 +260,6 @@ class SILModule {
262260
/// The indexed profile data to be used for PGO, or nullptr.
263261
std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader;
264262

265-
/// True if this SILModule really contains the whole module, i.e.
266-
/// optimizations can assume that they see the whole module.
267-
bool wholeModule;
268-
269263
/// The options passed into this SILModule.
270264
const SILOptions &Options;
271265

@@ -280,11 +274,8 @@ class SILModule {
280274
/// invalidation message is sent.
281275
llvm::SetVector<DeleteNotificationHandler*> NotificationHandlers;
282276

283-
// Intentionally marked private so that we need to use 'constructSIL()'
284-
// to construct a SILModule.
285-
SILModule(ModuleDecl *M, Lowering::TypeConverter &TC,
286-
const SILOptions &Options, const DeclContext *associatedDC,
287-
bool wholeModule);
277+
SILModule(llvm::PointerUnion<FileUnit *, ModuleDecl *> context,
278+
Lowering::TypeConverter &TC, const SILOptions &Options);
288279

289280
SILModule(const SILModule&) = delete;
290281
void operator=(const SILModule&) = delete;
@@ -355,47 +346,38 @@ class SILModule {
355346
/// Erase a global SIL variable from the module.
356347
void eraseGlobalVariable(SILGlobalVariable *G);
357348

358-
/// Construct a SIL module from an AST module.
359-
///
360-
/// The module will be constructed in the Raw stage. The provided AST module
361-
/// should contain source files.
349+
/// Create and return an empty SIL module suitable for generating or parsing
350+
/// SIL into.
362351
///
363-
/// If a source file is provided, SIL will only be emitted for decls in that
364-
/// source file.
365-
static std::unique_ptr<SILModule>
366-
constructSIL(ModuleDecl *M, Lowering::TypeConverter &TC,
367-
const SILOptions &Options, FileUnit *sf = nullptr);
368-
369-
/// Create and return an empty SIL module that we can
370-
/// later parse SIL bodies directly into, without converting from an AST.
352+
/// \param context The associated decl context. This should be a FileUnit in
353+
/// single-file mode, and a ModuleDecl in whole-module mode.
371354
static std::unique_ptr<SILModule>
372-
createEmptyModule(ModuleDecl *M, Lowering::TypeConverter &TC,
373-
const SILOptions &Options,
374-
bool WholeModule = false);
355+
createEmptyModule(llvm::PointerUnion<FileUnit *, ModuleDecl *> context,
356+
Lowering::TypeConverter &TC, const SILOptions &Options);
375357

376358
/// Get the Swift module associated with this SIL module.
377359
ModuleDecl *getSwiftModule() const { return TheSwiftModule; }
378360
/// Get the AST context used for type uniquing etc. by this SIL module.
379361
ASTContext &getASTContext() const;
380362
SourceManager &getSourceManager() const { return getASTContext().SourceMgr; }
381363

382-
/// Get the Swift DeclContext associated with this SIL module.
364+
/// Get the Swift DeclContext associated with this SIL module. This is never
365+
/// null.
383366
///
384367
/// All AST declarations within this context are assumed to have been fully
385368
/// processed as part of generating this module. This allows certain passes
386369
/// to make additional assumptions about these declarations.
387370
///
388371
/// If this is the same as TheSwiftModule, the entire module is being
389-
/// compiled as a single unit. If this is null, no context-based assumptions
390-
/// can be made.
372+
/// compiled as a single unit.
391373
const DeclContext *getAssociatedContext() const {
392374
return AssociatedDeclContext;
393375
}
394376

395377
/// Returns true if this SILModule really contains the whole module, i.e.
396378
/// optimizations can assume that they see the whole module.
397379
bool isWholeModule() const {
398-
return wholeModule;
380+
return isa<ModuleDecl>(AssociatedDeclContext);
399381
}
400382

401383
bool isStdlibModule() const;

lib/AST/ASTPrinter.cpp

+2-10
Original file line numberDiff line numberDiff line change
@@ -2613,18 +2613,10 @@ void PrintAST::visitVarDecl(VarDecl *decl) {
26132613
Printer << ": ";
26142614
TypeLoc tyLoc;
26152615
if (auto *repr = decl->getTypeReprOrParentPatternTypeRepr()) {
2616-
// Workaround for if-let statements. The parser creates a `OptionalTypeRepr`
2617-
// even though the user-written declared type for the if-let variable
2618-
// is non-optional. Get the non-optional type so we can print it correctly.
2619-
if (auto *optRepr = dyn_cast<OptionalTypeRepr>(repr)) {
2620-
if (type && !isa<OptionalType>(type.getPointer())) {
2621-
repr = optRepr->getBase();
2622-
}
2623-
}
26242616
tyLoc = TypeLoc(repr, type);
2625-
} else
2617+
} else {
26262618
tyLoc = TypeLoc::withoutLoc(type);
2627-
2619+
}
26282620
Printer.printDeclResultTypePre(decl, tyLoc);
26292621

26302622
// HACK: When printing result types for vars with opaque result types,

0 commit comments

Comments
 (0)